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uICgtMSk7CiAgICB9CgogICAgLyogcmVhZCBib290IHNlY3RvciAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCiAgICBpZiAoZGV2X3JlYWQgKGJvb3QsIDAsIDEpKXsKCVBSSU5URiAoIkVycm9yIGR1cmluZyBib290IHNlY3RvciByZWFkXG4iKTsKCWZyZWUgKGJvb3QpOwoJcmV0dXJuICgtMSk7CiAgICB9CgogICAgLyogd2UgdmVyaWZ5IGl0J2EgYSBET1MgZGlza2V0dGUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCiAgICBpZiAoYm9vdCAtPiBqdW1wIFswXSAhPSAgSlVNUF8wXzEgJiYgYm9vdCAtPiBqdW1wIFswXSAhPSAgSlVNUF8wXzIpIHsKCVBSSU5URiAoIk5vdCBhIERPUyBkaXNrZXR0ZVxuIik7CglmcmVlIChib290KTsKCXJldHVybiAoLTEpOwogICAgfQoKICAgIGlmIChib290IC0+IGRlc2NyIDwgTUVESUFfU1REKSB7CgkvKiBXZSBoYW5kbGUgb25seSByZWNlbnQgbWVkaWFzICh0eXBlIEYwKSAgICAgICAgICAgICAgICAgICAgICAgICAgICAqLwoJUFJJTlRGICgidW5yZWNvZ25pemVkIGRpc2tldHRlIHR5cGVcbiIpOwoJZnJlZSAoYm9vdCk7CglyZXR1cm4gKC0xKTsKICAgIH0KCiAgICBpZiAoY2hlY2tfZGV2IChib290LCBmcykgPCAwKSB7CglQUklOVEYgKCJCYWQgZGlza2V0dGVcbiIpOwoJZnJlZSAoYm9vdCk7CglyZXR1cm4gKC0xKTsKICAgIH0KCiAgICBpZiAoZmlsbF9mcyAoYm9vdCwgZnMpIDwgMCkgewoJZnJlZSAoYm9vdCk7CgoJcmV0dXJuICgtMSk7CiAgICB9CgogICAgLyogUmVhZCBGQVQgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCiAgICBpZiAocmVhZF9mYXQgKGJvb3QsIGZzKSA8IDApIHsKCWZyZWUgKGJvb3QpOwoJcmV0dXJuICgtMSk7CiAgICB9CgogICAgZnJlZSAoYm9vdCk7CiAgICByZXR1cm4gKDApOwp9CgojZW5kaWYK