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IC0tIHJlbmFtZWQgaWRlX2Rldl9zIHRvIGlkZV9kcml2ZV90LCBlbmFibGUgaXJxIG9uIGNvbW1hbmQKICogMi4wMCAgTm92IDI3LCAxOTk0IC0tIEdlbmVyYWxpemUgcGFja2V0IGNvbW1hbmQgaW50ZXJmYWNlOwogKiAgICAgICAgICAgICAgICAgICAgICAgYWRkIGF1ZGlvIGlvY3Rscy4KICogMi4wMSAgRGVjICAzLCAxOTk0IC0tIFJld29yayBwYWNrZXQgY29tbWFuZCBpbnRlcmZhY2UgdG8gaGFuZGxlIGRldmljZXMKICogICAgICAgICAgICAgICAgICAgICAgIHdoaWNoIHNlbmQgYW4gaW50ZXJydXB0IHdoZW4gcmVhZHkgZm9yIGEgY29tbWFuZC4KICogMi4wMiAgRGVjIDExLCAxOTk0IC0tIENhY2hlIHRoZSBUT0MgaW4gdGhlIGRyaXZlci4KICogICAgICAgICAgICAgICAgICAgICAgIERvbid0IHVzZSBTQ01EX1BMQVlBVURJT19USTsgaXQncyBub3QgaW5jbHVkZWQKICogICAgICAgICAgICAgICAgICAgICAgIGluIHRoZSBjdXJyZW50IHZlcnNpb24gb2YgQVRBUEkuCiAqICAgICAgICAgICAgICAgICAgICAgICBUcnkgdG8gdXNlIExCQSBpbnN0ZWFkIG9mIHRyYWNrIG9yIE1TRiBhZGRyZXNzaW5nCiAqICAgICAgICAgICAgICAgICAgICAgICB3aGVuIHBvc3NpYmxlLgogKiAgICAgICAgICAgICAgICAgICAgICAgRG9uJ3Qgd2FpdCBmb3IgUkVBRFlfU1RBVC4KICogMi4wMyAgSmFuIDEwLCAxOTk1IC0tIFJld3JpdGUgYmxvY2sgcmVhZCByb3V0aW5lcyB0byBoYW5kbGUgYmxvY2sgc2l6ZXMKICogICAgICAgICAgICAgICAgICAgICAgIG90aGVyIHRoYW4gMmsgYW5kIHRvIG1vdmUgbXVsdGlwbGUgc2VjdG9ycyBpbiBhCiAqICAgICAgICAgICAgICAgICAgICAgICBzaW5nbGUgdHJhbnNhY3Rpb24uCiAqIDIuMDQgIEFwciAyMSwgMTk5NSAtLSBBZGQgd29yay1hcm91bmQgZm9yIENyZWF0aXZlIExhYnMgQ0QyMjBFIGRyaXZlcy4KICogICAgICAgICAgICAgICAgICAgICAgIFRoYW5rcyB0byBOaWNrIFNhdyA8Y3dzYXdAcHRzNy5wdHMubW90LmNvbT4gZm9yCiAqICAgICAgICAgICAgICAgICAgICAgICBoZWxwIGluIGZpZ3VyaW5nIHRoaXMgb3V0LiAgRGl0dG8gZm9yIEFjZXIgYW5kCiAqICAgICAgICAgICAgICAgICAgICAgICBBenRlY2ggZHJpdmVzLCB3aGljaCBzZWVtIHRvIGhhdmUgdGhlIHNhbWUgcHJvYmxlbS4KICogMi4wNGIgTWF5IDMwLCAxOTk1IC0tIEZpeCB0byBtYXRjaCBjaGFuZ2VzIGluIGlkZS5jIHZlcnNpb24gMy4xNiAtbWwKICogMi4wNSAgSnVuICA4LCAxOTk1IC0tIERvbid0IGF0dGVtcHQgdG8gcmV0cnkgYWZ0ZXIgYW4gaWxsZWdhbCByZXF1ZXN0CiAqICAgICAgICAgICAgICAgICAgICAgICAgb3IgZGF0YSBwcm90ZWN0IGVycm9yLgogKiAgICAgICAgICAgICAgICAgICAgICAgVXNlIEhXSUYgYW5kIERFVl9IV0lGIG1hY3JvcyBhcyBpbiBpZGUuYy4KICogICAgICAgICAgICAgICAgICAgICAgIEFsd2F5cyB0cnkgdG8gZG8gYSByZXF1ZXN0X3NlbnNlIGFmdGVyCiAqICAgICAgICAgICAgICAgICAgICAgICAgYSBmYWlsZWQgY29tbWFuZC4KICogICAgICAgICAgICAgICAgICAgICAgIEluY2x1ZGUgYW4gb3B0aW9uIHRvIGdpdmUgdGV4dHVhbCBkZXNjcmlwdGlvbnMKICogICAgICAgICAgICAgICAgICAgICAgICBvZiBBVEFQSSBlcnJvcnMuCiAqICAgICAgICAgICAgICAgICAgICAgICBGaXggYSBidWcgaW4gaGFuZGxpbmcgdGhlIHNlY3RvciBjYWNoZSB3aGljaAogKiAgICAgICAgICAgICAgICAgICAgICAgIHNob3dlZCB1cCBpZiB0aGUgZHJpdmUgcmV0dXJuZWQgZGF0YSBpbiA1MTIgYnl0ZQogKiAgICAgICAgICAgICAgICAgICAgICAgIGJsb2NrcyAobGlrZSBQaW9uZWVyIGRyaXZlcykuICBUaGFua3MgdG8KICogICAgICAgICAgICAgICAgICAgICAgICBSaWNoYXJkIEhpcnN0IDxzcmhAZ3B0LmNvLnVrPiBmb3IgZGlhZ25vc2luZyB0aGlzLgogKiAgICAgICAgICAgICAgICAgICAgICAgUHJvcGVybHkgc3VwcGx5IHRoZSBwYWdlIG51bWJlciBmaWVsZCBpbiB0aGUKICogICAgICAgICAgICAgICAgICAgICAgICBNT0RFX1NFTEVDVCBjb21tYW5kLgogKiAgICAgICAgICAgICAgICAgICAgICAgUExBWUFVRElPMTIgaXMgYnJva2VuIG9uIHRoZSBBenRlY2g7IHdvcmsgYXJvdW5kIGl0LgogKiAyLjA1eCBBdWcgMTEsIDE5OTUgLS0gbG90cyBvZiBkYXRhIHN0cnVjdHVyZSByZW5hbWluZy9yZXN0cnVjdHVyaW5nIGluIGlkZS5jCiAqICAgICAgICAgICAgICAgICAgICAgICAobXkgYXBvbG9naWVzIHRvIFNjb3R0LCBidXQgbm93IGlkZS1jZC5jIGlzIGluZGVwZW5kZW50KQogKiAzLjAwICBBdWcgMjIsIDE5OTUgLS0gSW1wbGVtZW50IENEUk9NTVVMVElTRVNTSU9OIGlvY3RsLgogKiAgICAgICAgICAgICAgICAgICAgICAgSW1wbGVtZW50IENEUk9NUkVBREFVRElPIGlvY3RsIChVTlRFU1RFRCkuCiAqICAgICAgICAgICAgICAgICAgICAgICBVc2UgaW5wdXRfaWRlX2RhdGEoKSBhbmQgb3V0cHV0X2lkZV9kYXRhKCkuCiAqICAgICAgICAgICAgICAgICAgICAgICBBZGQgZG9vciBsb2NraW5nLgogKiAgICAgICAgICAgICAgICAgICAgICAgRml4IHVzYWdlIGNvdW50IGxlYWsgaW4gY2Ryb21fb3Blbiwgd2hpY2ggaGFwcGVuZWQKICogICAgICAgICAgICAgICAgICAgICAgICB3aGVuIGEgcmVhZC13cml0ZSBtb3VudCB3YXMgYXR0ZW1wdGVkLgogKiAgICAgICAgICAgICAgICAgICAgICAgVHJ5IHRvIGxvYWQgdGhlIGRpc2sgb24gb3Blbi4KICogICAgICAgICAgICAgICAgICAgICAgIEltcGxlbWVudCBDRFJPTUVKRUNUX1NXIGlvY3RsIChvZmYgYnkgZGVmYXVsdCkuCiAqICAgICAgICAgICAgICAgICAgICAgICBSZWFkIHRvdGFsIGNkcm9tIGNhcGFjaXR5IGR1cmluZyBvcGVuLgogKiAgICAgICAgICAgICAgICAgICAgICAgUmVhcnJhbmdlIGxvZ2ljIGluIGNkcm9tX2RlY29kZV9zdGF0dXMuICBJc3N1ZQogKiAgICAgICAgICAgICAgICAgICAgICAgIHJlcXVlc3Qgc2Vuc2UgY29tbWFuZHMgZm9yIGZhaWxlZCBwYWNrZXQgY29tbWFuZHMKICogICAgICAgICAgICAgICAgICAgICAgICBmcm9tIGhlcmUgaW5zdGVhZCBvZiBmcm9tIGNkcm9tX3F1ZXVlX3BhY2tldF9jb21tYW5kLgogKiAgICAgICAgICAgICAgICAgICAgICAgIEZpeCBhIHJhY2UgY29uZGl0aW9uIGluIHJldHJpZXZpbmcgZXJyb3IgaW5mb3JtYXRpb24uCiAqICAgICAgICAgICAgICAgICAgICAgICBTdXBwcmVzcyBwcmludGluZyBub3JtYWwgdW5pdCBhdHRlbnRpb24gZXJyb3JzIGFuZAogKiAgICAgICAgICAgICAgICAgICAgICAgIHNvbWUgZHJpdmUgbm90IHJlYWR5IGVycm9ycy4KICogICAgICAgICAgICAgICAgICAgICAgIEltcGxlbWVudCBDRFJPTVZPTFJFQUQgaW9jdGwuCiAqICAgICAgICAgICAgICAgICAgICAgICBJbXBsZW1lbnQgQ0RST01SRUFETU9ERTEvMiBpb2N0bHMuCiAqICAgICAgICAgICAgICAgICAgICAgICBGaXggcmFjZSBjb25kaXRpb24gaW4gc2V0dGluZyB1cCBpbnRlcnJ1cHQgaGFuZGxlcnMKICogICAgICAgICAgICAgICAgICAgICAgICB3aGVuIHRoZSBgc2VyaWFsaXplJyBvcHRpb24gaXMgdXNlZC4KICogMy4wMSAgU2VwICAyLCAxOTk1IC0tIEZpeCBvcmRlcmluZyBvZiByZWVuYWJsaW5nIGludGVycnVwdHMgaW4KICogICAgICAgICAgICAgICAgICAgICAgICBjZHJvbV9xdWV1ZV9yZXF1ZXN0LgogKiAgICAgICAgICAgICAgICAgICAgICAgQW5vdGhlciB0cnkgYXQgdXNpbmcgaWRlX1tpbnB1dCxvdXRwdXRdX2RhdGEuCiAqIDMuMDIgIFNlcCAxNiwgMTk5NSAtLSBTdGljayB0b3RhbCBkaXNrIGNhcGFjaXR5IGluIHBhcnRpdGlvbiB0YWJsZSBhcyB3ZWxsLgogKiAgICAgICAgICAgICAgICAgICAgICAgTWFrZSBWRVJCT1NFX0lERV9DRF9FUlJPUlMgZHVtcCBmYWlsZWQgY29tbWFuZCBhZ2Fpbi4KICogICAgICAgICAgICAgICAgICAgICAgIER1bXAgb3V0IG1vcmUgaW5mb3JtYXRpb24gZm9yIElMTEVHQUwgUkVRVUVTVCBlcnJzLgogKiAgICAgICAgICAgICAgICAgICAgICAgRml4IGhhbmRsaW5nIG9mIGVycm9ycyBvY2N1cnJpbmcgYmVmb3JlIHRoZQogKiAgICAgICAgICAgICAgICAgICAgICAgIHBhY2tldCBjb21tYW5kIGlzIHRyYW5zZmVycmVkLgogKiAgICAgICAgICAgICAgICAgICAgICAgRml4IHRyYW5zZmVycyB3aXRoIG9kZCBieXRlbGVuZ3Rocy4KICogMy4wMyAgT2N0IDI3LCAxOTk1IC0tIFNvbWUgQ3JlYXRpdmUgZHJpdmVzIGhhdmUgYW4gaWQgb2YganVzdCBgQ0QnLgogKiAgICAgICAgICAgICAgICAgICAgICAgYERDSS0yUzEwJyBkcml2ZXMgYXJlIGJyb2tlbiB0b28uCiAqIDMuMDQgIE5vdiAyMCwgMTk5NSAtLSBTbyBhcmUgVmVydG9zIGRyaXZlcy4KICogMy4wNSAgRGVjICAxLCAxOTk1IC0tIENoYW5nZXMgdG8gZ28gd2l0aCBvdmVyaGF1bCBvZiBpZGUuYyBhbmQgaWRlLXRhcGUuYwogKiAzLjA2ICBEZWMgMTYsIDE5OTUgLS0gQWRkIHN1cHBvcnQgbmVlZGVkIGZvciBwYXJ0aXRpb25zLgogKiAgICAgICAgICAgICAgICAgICAgICAgTW9yZSB3b3JrYXJvdW5kcyBmb3IgVmVydG9zIGJ1Z3MgKGJhc2VkIG9uIHBhdGNoZXMKICogICAgICAgICAgICAgICAgICAgICAgICBmcm9tIEhvbGdlciBEaWV0emUgPGRpZXR6ZUBhaXg1MjAuaW5mb3JtYXRpay51bmktbGVpcHppZy5kZT4pLgogKiAgICAgICAgICAgICAgICAgICAgICAgVHJ5IHRvIGVsaW1pbmF0ZSBieXRlb3JkZXIgYXNzdW1wdGlvbnMuCiAqICAgICAgICAgICAgICAgICAgICAgICBVc2UgYXRhcGlfY2Ryb21fc3ViY2hubCBzdHJ1Y3QgZGVmaW5pdGlvbi4KICogICAgICAgICAgICAgICAgICAgICAgIEFkZCBTVEFOREFSRF9BVEFQSSBjb21waWxhdGlvbiBvcHRpb24uCiAqIDMuMDcgIEphbiAyOSwgMTk5NiAtLSBNb3JlIHR3aWRkbGluZyBmb3IgYnJva2VuIGRyaXZlczogU29ueSA1NUQsCiAqICAgICAgICAgICAgICAgICAgICAgICAgVmVydG9zIDMwMC4KICogICAgICAgICAgICAgICAgICAgICAgIEFkZCBOT19ET09SX0xPQ0tJTkcgY29uZmlndXJhdGlvbiBvcHRpb24uCiAqICAgICAgICAgICAgICAgICAgICAgICBIYW5kbGUgZHJpdmVfY21kIHJlcXVlc3RzIHcvTlVMTCBhcmdzIChmb3IgaGRwYXJtIC10KS4KICogICAgICAgICAgICAgICAgICAgICAgIFdvcmsgYXJvdW5kI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wb3J0LgogKiAgICAgICAgICAgICAgICAgICAgICAgCiAqICAgICAgICAgICAgICAgICAgICAgICAKICogNC4wMCAgTm92IDUsIDE5OTYgICAtLSBOZXcgaWRlLWNkIG1haW50YWluZXIsCiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRXJpayBCLiBBbmRlcnNlbiA8YW5kZXJzZWVAZGViaWFuLm9yZz4KICogICAgICAgICAgICAgICAgICAgICAtLSBOZXdlciBDcmVhdGl2ZSBkcml2ZXMgZG9uJ3QgYWx3YXlzIHNldCB0aGUgZXJyb3IKICogICAgICAgICAgICAgICAgICAgICAgICAgIHJlZ2lzdGVyIGNvcnJlY3RseS4gIE1ha2Ugc3VyZSB3ZSBzZWUgbWVkaWEgY2hhbmdlcwogKiAgICAgICAgICAgICAgICAgICAgICAgICAgcmVnYXJkbGVzcy4KICogICAgICAgICAgICAgICAgICAgICAtLSBJbnRlZ3JhdGUgd2l0aCBnZW5lcmljIGNkcm9tIGRyaXZlci4KICogICAgICAgICAgICAgICAgICAgICAtLSBDRFJPTUdFVFNQSU5ET1dOIGFuZCBDRFJPTVNFVFNQSU5ET1dOIGlvY3RscywgYmFzZWQgb24KICogICAgICAgICAgICAgICAgICAgICAgICAgIGEgcGF0Y2ggZnJvbSBDaXJvIENhdHR1dG8gPD4uCiAqICAgICAgICAgICAgICAgICAgICAgLS0gQ2FsbCBzZXRfZGV2aWNlX3JvLgogKiAgICAgICAgICAgICAgICAgICAgIC0tIEltcGxlbWVudCBDRFJPTU1FQ0hBTklTTVNUQVRVUyBhbmQgQ0RST01TTE9UVEFCTEUKICogICAgICAgICAgICAgICAgICAgICAgICAgIGlvY3RscywgYmFzZWQgb24gcGF0Y2ggYnkgRXJpayBBbmRlcnNlbgogKiAgICAgICAgICAgICAgICAgICAgIC0tIEFkZCBzb21lIHByb2JlcyBvZiBkcml2ZSBjYXBhYmlsaXR5IGR1cmluZyBzZXR1cC4KICoKICogNC4wMSAgTm92IDExLCAxOTk2ICAtL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KICogICAgICAgICAgICAgICAgICAgICAtLSBGaXhlZCBhIG1lbW9yeSBsZWFrIHdoZXJlIGluZm8tPmNoYW5nZXJfaW5mbyB3YXMKICogICAgICAgICAgICAgICAgICAgICAgICAgbWFsbG9jJ2VkIGJ1dCBuZXZlciBmcmVlJ2Qgd2hlbiBjbG9zaW5nIHRoZSBkZXZpY2UuCiAqICAgICAgICAgICAgICAgICAgICAgLS0gQ2xlYW5lZCB1cCB0aGUgZ2xvYmFsIG5hbWVzcGFjZSBhIGJpdCBieSBtYWtpbmcgbW9yZQogKiAgICAgICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbnMgc3RhdGljIHRoYXQgc2hvdWxkIGFscmVhZHkgaGF2ZSBiZWVuLgogKiA0LjExICBNYXIgMTIsIDE5OTggIC0tIEFkZGVkIHN1cHBvcnQgZm9yIHRoZSBDRFJPTV9TRUxFQ1RfU1BFRUQgaW9jdGwKICogICAgICAgICAgICAgICAgICAgICAgICAgYmFzZWQgb24gYSBwYXRjaCBmb3IgMi4wLjMzIGJ5IEplbGxlIEZva3MgCiAqICAgICAgICAgICAgICAgICAgICAgICAgIDxqZWxsZUBzY2ludGlsbGEudXR3ZW50ZS5ubD4sIGEgcGF0Y2ggZm9yIDIuMC4zMwogKiAgICAgICAgICAgICAgICAgICAgICAgICBieSBUb25pIEdpb3JnaW5vIDx0b25pQHBjYXBlMi5waS5pbmZuLml0PiwgdGhlIFNDU0kKICogICAgICAgICAgICAgICAgICAgICAgICAgdmVyc2lvbiwgYW5kIG15IG93biBlZmZvcnRzLiAgLWVyaWsKICogICAgICAgICAgICAgICAgICAgICAtLSBGaXhlZCBhIHN0dXBpZCBidWcgd2hpY2ggZWdjcyB3YXMga2luZCBlbm91Z2ggdG8KICogICAgICAgICAgICAgICAgICAgICAgICAgaW5mb3JtIG1lIG9mIHdoZXJlICJJbGxlZ2FsIG1vZGUgZm9yIHRoaXMgdHJhY2siCiAqICAgICAgICAgICAgICAgICAgICAgICAgIHdhcyBuZ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ELVJPTS9SQU0gZHJpdmVzCiAqCiAqIDQuNTMgIEZlYiAyMiwgMTk5OSAgIC0gSW5jbHVkZSBvdGhlciBtb2RlbCBTYW1zdW5nIGFuZCBvbmUgR29sZHN0YXIKICogICAgICAgICAgICAgICAgICAgICAgICAgZHJpdmUgaW4gdHJhbnNmZXIgc2l6ZSBsaW1pdC4KICogICAgICAgICAgICAgICAgICAgICAgLSBGaXggdGhlIEkvTyBlcnJvciB3aGVuIGRvaW5nIGVqZWN0IHdpdGhvdXQgYSBtZWRpdW0KICogICAgICAgICAgICAgICAgICAgICAgICAgbG9hZGVkIG9uIHNvbWUgZHJpdmVzLgogKiAgICAgICAgICAgICAgICAgICAgICAtIENEUk9NUkVBRE1PREUyIGlzIG5vdyBpbXBsZW1lbnRlZCB0aHJvdWdoCiAqICAgICAgICAgICAgICAgICAgICAgICAgIENEUk9NUkVBRFJBVywgc2luY2UgbWFueSBkcml2ZXMgZG9uJ3Qgc3VwcG9ydAogKiAgICAgICAgICAgICAgICAgICAgICAgICBNT0RFMiAoZXZlbiB0aG91Z2ggQVRBUEkgMi42IHNheXMgdGhleSBtdXN0KS4KICogICAgICAgICAgICAgICAgICAgICAgLSBBZGRlZCBpZ25vcmUgcGFyYW1ldGVyIHRvIGlkZS1jZCAoYXMgYSBtb2R1bGUpLCBlZwogKiAgICAgICAgICAgICAgICAgICAgICAgICAJaW5zbW9kIGlkZS1jZCBpZ25vcmU9J2hkYSBoZGInCiAqICAgICAgICAgICAgICAgICAgICAgICAgIFVzZWZ1bCB3aGVuIHVzaW5nIGlkZS1jZCBpbiBjb25qdW5jdGlvbiB3aXRoCiAqICAgICAgICAgICAgICAgICAgICAgICAgIGlkZS1zY3NpLiBUT0RPOiBub24tbW9kdWxhciB3YXkgb2YgZG9pbmcgdGhlCiAqICAgICAgICAgICAgICAgICAgICAgICAgIHNhbWUuCiAqCiAqIDQuNTQgIEF1ZyA1LCAxOTk5CS0gU3VwcG9ydCBmb3IgTU1DMiBjbGFzc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