#include <array>
#include <cstring>
#include <iostream>
struct Oops {
char a;
int b;
};
void foo(std::array<char, 8>&) {
}
void (*foo_ptr)(std::array<char, 8>&) = foo;
bool __attribute__((noinline)) bar(Oops& o, char a, int b) {
union {
std::array<char, 8> x;
Oops y;
};
x = {'P', 'o', 'p', 'a', 'p', 'o', 'p', 'a'};
foo_ptr(x);
y = {a, b};
return std::memcmp(&o, &y, sizeof y) == 0;
}
int main() {
Oops a = {1, 2};
if (bar(a, 1, 2)) {
std::cout << "Everything's fine" << std::endl;
} else {
std::cout << "Someone's an idiot" << std::endl;
}
}
I2luY2x1ZGUgPGFycmF5PgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IE9vcHMgewogICAgY2hhciBhOwogICAgaW50IGI7Cn07Cgp2b2lkIGZvbyhzdGQ6OmFycmF5PGNoYXIsIDg+Jikgewp9CnZvaWQgKCpmb29fcHRyKShzdGQ6OmFycmF5PGNoYXIsIDg+JikgPSBmb287Cgpib29sIF9fYXR0cmlidXRlX18oKG5vaW5saW5lKSkgYmFyKE9vcHMmIG8sIGNoYXIgYSwgaW50IGIpIHsKICAgIHVuaW9uIHsKICAgICAgICBzdGQ6OmFycmF5PGNoYXIsIDg+IHg7CiAgICAgICAgT29wcyB5OwogICAgfTsKICAgIHggPSB7J1AnLCAnbycsICdwJywgJ2EnLCAncCcsICdvJywgJ3AnLCAnYSd9OwogICAgZm9vX3B0cih4KTsKICAgIHkgPSB7YSwgYn07CiAgICByZXR1cm4gc3RkOjptZW1jbXAoJm8sICZ5LCBzaXplb2YgeSkgPT0gMDsKfQoKaW50IG1haW4oKSB7CiAgICBPb3BzIGEgPSB7MSwgMn07CiAgICBpZiAoYmFyKGEsIDEsIDIpKSB7CiAgICAgICAgc3RkOjpjb3V0IDw8ICJFdmVyeXRoaW5nJ3MgZmluZSIgPDwgc3RkOjplbmRsOwogICAgfSBlbHNlIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIlNvbWVvbmUncyBhbiBpZGlvdCIgPDwgc3RkOjplbmRsOwogICAgfQp9