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KioqKiovCnN0YXRpYyB2b2lkCmhmY3BjaV9UaW1lcihzdHJ1Y3QgSXNkbkNhcmRTdGF0ZSAqY3MpCnsKCWNzLT5ody5oZmNwY2kudGltZXIuZXhwaXJlcyA9IGppZmZpZXMgKyA3NTsKCS8qIFdEIFJFU0VUICovCi8qICAgICAgV3JpdGVSZWcoY3MsIEhGQ0RfREFUQSwgSEZDRF9DVE1ULCBjcy0+aHcuaGZjcGNpLmN0bXQgfCAweDgwKTsKICAgYWRkX3RpbWVyKCZjcy0+aHcuaGZjcGNpLnRpbWVyKTsKICovCn0KCgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiBzY2hlZHVsZSBhIG5ldyBELWNoYW5uZWwgdGFzayAqLwovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpzdGF0aWMgdm9pZApzY2hlZF9ldmVudF9EX3BjaShzdHJ1Y3QgSXNkbkNhcmRTdGF0ZSAqY3MsIGludCBldmVudCkKewoJdGVzdF9hbmRfc2V0X2JpdChldmVudCwgJmNzLT5ldmVudCk7CglzY2hlZHVsZV93b3JrKCZjcy0+dHF1ZXVlKTsKfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KLyogc2NoZWR1bGUgYSBuZXcgYl9jaGFubmVsIHRhc2sgKi8KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8Kc3RhdGljIHZvaWQKaGZjcGNpX3NjaGVkX2V2ZW50KHN0cnVjdCBCQ1N0YXRlICpiY3MsIGludCBldmVudCkKewoJdGVzdF9hbmRfc2V0X2JpdChldmVudCwgJmJjcy0+ZXZlbnQpOwoJc2NoZWR1bGVfd29yaygmYmNzLT50cXVldWUpOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiBzZWxlY3QgYSBiLWNoYW5uZWwgZW50cnkgbWF0Y2hpbmcgYW5kIGFjdGl2ZSAqLwovKioqKioqKioqKioqKioqK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