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51cmxfcGFyYW1fcG9zdF9saW1pdCA9IDM7IC8qIG1pbmltdW0gZXhhbXBsZTogUz0zIG9yIFxyXG5TPTYmICovCgkJfQoJfQoJZWxzZSB7CgkJc25wcmludGYoZXJyLCBlcnJsZW4sICInYmFsYW5jZScgb25seSBzdXBwb3J0cyAncm91bmRyb2JpbicsICdsZWFzdGNvbm4nLCAnc291cmNlJywgJ3VyaScgYW5kICd1cmxfcGFyYW0nIG9wdGlvbnMuIik7CgkJcmV0dXJuIC0xOwoJfQoJcmV0dXJuIDA7Cn0KCgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiAgICAgICAgICAgICBBbGwgc3VwcG9ydGVkIGtleXdvcmRzIG11c3QgYmUgZGVjbGFyZWQgaGVyZS4gICAgICAgICAgICAqLwovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKLyogc2V0IHRlc3QtPmkgdG8gdGhlIG51bWJlciBvZiBlbmFibGVkIHNlcnZlcnMgb24gdGhlIHByb3h5ICovCnN0YXRpYyBpbnQKYWNsX2ZldGNoX25ic3J2KHN0cnVjdCBwcm94eSAqcHgsIHN0cnVjdCBzZXNzaW9uICpsNCwgdm9pZCAqbDcsIGludCBkaXIsCiAgICAgICAgICAgICAgICBzdHJ1Y3QgYWNsX2V4cHIgKmV4cHIsIHN0cnVjdCBhY2xfdGVzdCAqdGVzdCkKewoJdGVzdC0+ZmxhZ3MgPSBBQ0xfVEVTVF9GX1ZPTF9URVNUOwoJaWYgKGV4cHItPmFyZ19sZW4pIHsKCQkvKiBhbm90aGVyIHByb3h5IHdhcyBkZXNpZ25hdGVkLCB3ZSBtdXN0IGxvb2sgZm9yIGl0ICovCgkJZm9yIChweCA9IHByb3h5OyBweDsgcHggPSBweC0+bmV4dCkKCQkJaWYgKChweC0+Y2FwICYgUFJfQ0FQ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