testFrancMultiplication

decompiled_code:
int testFrancMultiplication()
{
int result; // eax
int s2; // [rsp+8h] [rbp-10h] BYREF
char s1[12]; // [rsp+Ch] [rbp-Ch] BYREF

public_franc_init(5LL);
local_franc_init(s1, 10LL);
s2 = francTimes(2LL);
result = memcmp(s1, &s2, 4uLL);
if ( result )
_assert_fail(
"!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))",
"test/test_franc.c",
0x19u,
"testFrancMultiplication");
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
int s2; // [rsp+8h] [rbp-10h] BYREF
char s1[12]; // [rsp+Ch] [rbp-Ch] BYREF

public_franc_init(5LL);
local_franc_init(s1, 10LL);
s2 = francTimes(2LL);
result = memcmp(s1, &s2, 4uLL);
if ( result )
_assert_fail(
"!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))",
"test/test_franc.c",
0x19u,
"testFrancMultiplication");
return result;
}

original_code:
void testFrancMultiplication(){
    int counter = 0;
    t_franc local_franc;
    t_franc cmp_franc;
    public_franc_init( 5 );
    for( counter = 0; counter < 1; counter ++){
        local_franc_init( &local_franc, 10 );
        cmp_franc = francTimes( 2 );
        ((void) sizeof ((!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))) ? 1 : 0), __extension__ ({ if (!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))) ; else __assert_fail ("!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))", "test/test_franc.c", 25, __extension__ __PRETTY_FUNCTION__); }));
    }
}

canonical_original_code:
void testFrancMultiplication(){
    int counter = 0;
    struct T_franc local_franc;
    struct T_franc cmp_franc;
    public_franc_init( 5 );
    for( counter = 0; counter < 1; counter ++){
        local_franc_init( &local_franc, 10 );
        cmp_franc = francTimes( 2 );
        ((void) sizeof ((!memcmp( ( struct T_franc * ) &local_franc, ( struct T_franc * ) &cmp_franc, sizeof( t_franc ))) ? 1 : 0), __extension__ ({ if (!memcmp( ( struct T_franc * ) &local_franc, ( struct T_franc * ) &cmp_franc, sizeof( t_franc ))) ; else __assert_fail ("!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))", "test/test_franc.c", 25, __extension__ __PRETTY_FUNCTION__); }));
    }
}


testFrancEquals

decompiled_code:
__int64 testFrancEquals()
{
__int64 result; // rax
char v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

public_franc_init(5LL);
local_franc_init(v1, 5LL);
result = francEquals((unsigned int)public_franc, v1);
if ( !(_DWORD)result )
_assert_fail("francEquals( public_franc, &dst_franc )", "test/test_franc.c", 0x22u, "testFrancEquals");
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
char v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

public_franc_init(5LL);
local_franc_init(v1, 5LL);
result = francEquals((unsigned int)public_franc, v1);
if ( !(_DWORD)result )
_assert_fail("francEquals( public_franc, &dst_franc )", "test/test_franc.c", 0x22u, "testFrancEquals");
return result;
}

original_code:
void testFrancEquals(){
    t_franc dst_franc;
    public_franc_init( 5 );
    local_franc_init( &dst_franc, 5 );
    ((void) sizeof ((francEquals( public_franc, &dst_franc )) ? 1 : 0), __extension__ ({ if (francEquals( public_franc, &dst_franc )) ; else __assert_fail ("francEquals( public_franc, &dst_franc )", "test/test_franc.c", 34, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void testFrancEquals(){
    struct T_franc dst_franc;
    public_franc_init( 5 );
    local_franc_init( &dst_franc, 5 );
    ((void) sizeof ((francEquals( public_franc, &dst_franc )) ? 1 : 0), __extension__ ({ if (francEquals( public_franc, &dst_franc )) ; else __assert_fail ("francEquals( public_franc, &dst_franc )", "test/test_franc.c", 34, __extension__ __PRETTY_FUNCTION__); }));
}

return_type: void


setstandardspeed

repo: konkers/sconsole

decompiled_code:
int __fastcall setstandardspeed(int a1, const struct termios *a2, speed_t a3)
{
a2->c_cflag = a3 | 0x8B0;
a2->c_ispeed = a3;
a2->c_ospeed = a3;
return tcsetattr(a1, 0, a2);
}

canonical_decompiled_code:
int __fastcall func7(int a1, const struct termios *a2, speed_t a3)
{
a2->c_cflag = a3 | 0x8B0;
a2->c_ispeed = a3;
a2->c_ospeed = a3;
return tcsetattr(a1, 0, a2);
}

original_code:
static void setstandardspeed(int fd, struct termios *tio, int speed)
{
 tio->c_cflag = speed | 0000060 | 0004000 | 0000200;
 tio->c_ispeed = speed;
 tio->c_ospeed = speed;
 tcsetattr(fd, 0, tio);
}

variable_types: fd int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } *

variable_types: speed int


decompiled_code:
int stdin_raw_restore()
{
tcsetattr(0, 0, &tio_save);
return tcflush(0, 0);
}

canonical_decompiled_code:
int func8()
{
tcsetattr(0, 0, &tio_save);
return tcflush(0, 0);
}

original_code:
static void stdin_raw_restore(void)
{
 tcsetattr(0, 0, &tio_save);
 tcflush(0, 0);
}

canonical_original_code:
static void stdin_raw_restore()
{
 tcsetattr(0, 0, &tio_save);
 tcflush(0, 0);
}


oops

decompiled_code:
void __noreturn oops()
{
write(2, "\n[ killed by signal ]\n", 0x16uLL);
stdin_raw_restore();
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
write(2, "\n[ killed by signal ]\n", 0x16uLL);
func8();
exit(1);
}

original_code:
void oops(int x)
{
 char *msg = "\n[ killed by signal ]\n";
 write(2, msg, strlen(msg));
 stdin_raw_restore();
 exit(1);
}

variable_types: x int

variable_types:
msg
char *


decompiled_code:
int stdin_raw_init()
{
int result; // eax
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

result = tcgetattr(0, &v1);
if ( !result )
{
result = tcgetattr(0, &tio_save);
if ( !result )
{
v1.c_lflag = 0;
v1.c_cc[5] = 0;
v1.c_cc[6] = 1;
tcsetattr(0, 0, &v1);
result = tcflush(0, 0);
}
}
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

result = tcgetattr(0, &v1);
if ( !result )
{
result = tcgetattr(0, &tio_save);
if ( !result )
{
v1.c_lflag = 0;
v1.c_cc[5] = 0;
v1.c_cc[6] = 1;
tcsetattr(0, 0, &v1);
result = tcflush(0, 0);
}
}
return result;
}

original_code:
static void stdin_raw_init(void)
{
 struct termios tio;
 if (tcgetattr(0, &tio))
  return;
 if (tcgetattr(0, &tio_save))
  return;
 tio.c_lflag = 0;
 tio.c_cc[5] = 0;
 tio.c_cc[6] = 1;
 tcsetattr(0, 0, &tio);
 tcflush(0, 0);
}

canonical_original_code:
static void stdin_raw_init()
{
 struct termios tio;
 if (tcgetattr(0, &tio))
  return;
 if (tcgetattr(0, &tio_save))
  return;
 tio.c_lflag = 0;
 tio.c_cc[5] = 0;
 tio.c_cc[6] = 1;
 tcsetattr(0, 0, &tio);
 tcflush(0, 0);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


setcustomspeed

decompiled_code:
int __fastcall setcustomspeed(int fd, int a2)
{
_DWORD v3[18]; // [rsp+0h] [rbp-48h] BYREF

ioctl(fd, 0x802C542AuLL, v3);
v3[2] = 6320;
v3[10] = a2;
v3[9] = a2;
return ioctl(fd, 0x402C542BuLL, v3);
}

canonical_decompiled_code:
int __fastcall func11(int fd, int a2)
{
_DWORD v3[18]; // [rsp+0h] [rbp-48h] BYREF

ioctl(fd, 0x802C542AuLL, v3);
v3[2] = 6320;
v3[10] = a2;
v3[9] = a2;
return ioctl(fd, 0x402C542BuLL, v3);
}

variable_types:
speed
unsigned int

variable_types: struct termios2 { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[19]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
__int64 __fastcall speed2termios(unsigned int a1)
{
__int64 result; // rax

if ( a1 == 38400 )
return 15LL;
if ( a1 <= 0x9600 )
{
result = 13LL;
if ( a1 != 9600 )
{
result = 4096LL;
if ( a1 == 19200 )
result = 14LL;
}
}
else
{
result = 4097LL;
if ( a1 != 57600 )
result = 2 * (unsigned int)(a1 == 115200) + 4096;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
__int64 result; // rax

if ( a1 == 38400 )
return 15LL;
if ( a1 <= 0x9600 )
{
result = 13LL;
if ( a1 != 9600 )
{
result = 4096LL;
if ( a1 == 19200 )
result = 14LL;
}
}
else
{
result = 4097LL;
if ( a1 != 57600 )
result = 2 * (unsigned int)(a1 == 115200) + 4096;
}
return result;
}

original_code:
int speed2termios(speed_t speed)
{
 switch (speed) {
 case 115200:
  return 0010002;
 case 57600:
  return 0010001;
 case 38400:
  return 0000017;
 case 19200:
  return 0000016;
 case 9600:
  return 0000015;
 default:
  return 0010000;
 }
}

canonical_original_code:
int speed2termios(unsigned int speed)
{
 switch (speed) {
 case 115200:
  return 0010002;
 case 57600:
  return 0010001;
 case 38400:
  return 0000017;
 case 19200:
  return 0000016;
 case 9600:
  return 0000015;
 default:
  return 0010000;
 }
}

return_type: int


openserial

decompiled_code:
__int64 __fastcall openserial(const char *a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // ebx
int v4; // eax
speed_t v5; // eax
struct termios v7; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 2306);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
v4 = fcntl(v2, 3, 0LL);
if ( v4 < 0 || (BYTE1(v4) &= 0xF7u, fcntl(v3, 4, (unsigned int)v4) < 0) )
{
close(v3);
v3 = -1;
}
else
{
if ( tcgetattr(v3, &v7) )
{
*(_QWORD *)&v7.c_iflag = 0LL;
*(_QWORD *)&v7.c_cflag = 0LL;
*(_QWORD *)&v7.c_line = 0LL;
*(_QWORD *)&v7.c_cc[7] = 0LL;
*(_QWORD *)&v7.c_cc[15] = 0LL;
*(_QWORD *)&v7.c_cc[23] = 0LL;
*(_DWORD *)&v7.c_cc[31] = 0;
}
*(_QWORD *)&v7.c_cflag = 6321LL;
v7.c_ispeed = 4097;
v7.c_ospeed = 4097;
v7.c_iflag = 4;
v7.c_oflag &= 0xFFFFFFFB;
v7.c_cc[5] = 0;
v7.c_cc[6] = 1;
tcsetattr(v3, 0, &v7);
tcflush(v3, 0);
v5 = speed2termios(a2);
if ( v5 == 4096 )
setcustomspeed(v3, a2);
else
setstandardspeed(v3, &v7, v5);
tcflush(v3, 0);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // ebx
int v4; // eax
speed_t v5; // eax
struct termios v7; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 2306);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
v4 = fcntl(v2, 3, 0LL);
if ( v4 < 0 || (BYTE1(v4) &= 0xF7u, fcntl(v3, 4, (unsigned int)v4) < 0) )
{
close(v3);
v3 = -1;
}
else
{
if ( tcgetattr(v3, &v7) )
{
*(_QWORD *)&v7.c_iflag = 0LL;
*(_QWORD *)&v7.c_cflag = 0LL;
*(_QWORD *)&v7.c_line = 0LL;
*(_QWORD *)&v7.c_cc[7] = 0LL;
*(_QWORD *)&v7.c_cc[15] = 0LL;
*(_QWORD *)&v7.c_cc[23] = 0LL;
*(_DWORD *)&v7.c_cc[31] = 0;
}
*(_QWORD *)&v7.c_cflag = 6321LL;
v7.c_ispeed = 4097;
v7.c_ospeed = 4097;
v7.c_iflag = 4;
v7.c_oflag &= 0xFFFFFFFB;
v7.c_cc[5] = 0;
v7.c_cc[6] = 1;
tcsetattr(v3, 0, &v7);
tcflush(v3, 0);
v5 = func12(a2);
if ( v5 == 4096 )
func11(v3, a2);
else
func7(v3, &v7, v5);
tcflush(v3, 0);
}
return v3;
}

original_code:
int openserial(const char *device, speed_t speed)
{
 struct termios tio;
 int fd;
 int fl;
 fd = open(device, 02 | 0400 | 04000);
 if (fd < 0)
  return -1;
 fl = fcntl(fd, 3, 0);
 if (fl < 0) {
  close(fd);
  return -1;
 }
 fl = fcntl(fd, 4, fl & ~04000);
 if (fl < 0) {
  close(fd);
  return -1;
 }
 if (tcgetattr(fd, &tio))
  memset(&tio, 0, sizeof(tio));
 tio.c_cflag = 0010001 | 0000060 | 0004000 | 0000200;
 tio.c_ispeed = 0010001;
 tio.c_ospeed = 0010001;
 tio.c_iflag = 0000004;
 tio.c_oflag &= ~0000004;
 tio.c_lflag = 0;
 tio.c_cc[5] = 0;
 tio.c_cc[6] = 1;
 tcsetattr(fd, 0, &tio);
 tcflush(fd, 0);
 int termios_speed = speed2termios(speed);
 if (termios_speed == 0010000)
  setcustomspeed(fd, speed);
 else
  setstandardspeed(fd, &tio, termios_speed);
 tcflush(fd, 0);
 return fd;
}

canonical_original_code:
int openserial(char *device, unsigned int speed)
{
 struct termios tio;
 int fd;
 int fl;
 fd = open(device, 02 | 0400 | 04000);
 if (fd < 0)
  return -1;
 fl = fcntl(fd, 3, 0);
 if (fl < 0) {
  close(fd);
  return -1;
 }
 fl = fcntl(fd, 4, fl & ~04000);
 if (fl < 0) {
  close(fd);
  return -1;
 }
 if (tcgetattr(fd, &tio))
  memset(&tio, 0, sizeof(tio));
 tio.c_cflag = 0010001 | 0000060 | 0004000 | 0000200;
 tio.c_ispeed = 0010001;
 tio.c_ospeed = 0010001;
 tio.c_iflag = 0000004;
 tio.c_oflag &= ~0000004;
 tio.c_lflag = 0;
 tio.c_cc[5] = 0;
 tio.c_cc[6] = 1;
 tcsetattr(fd, 0, &tio);
 tcflush(fd, 0);
 int termios_speed = speed2termios(speed);
 if (termios_speed == 0010000)
  setcustomspeed(fd, speed);
 else
  setstandardspeed(fd, &tio, termios_speed);
 tcflush(fd, 0);
 return fd;
}

variable_types:
device
char *

variable_types: fl int

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
_BYTE *v5; // rax
int v6; // er13
const char *v7; // r15
const char *v8; // rbp
unsigned int v9; // ebx
int v10; // ebx
int v11; // ebp
char v12; // al
const char *v13; // rdx
char v14; // al
char *v15; // rax
const char *v17; // r14
unsigned __int64 v18; // rax
unsigned __int8 buf; // [rsp+Fh] [rbp-59h] BYREF
char *endptr; // [rsp+10h] [rbp-58h] BYREF
char v21; // [rsp+1Fh] [rbp-49h] BYREF
struct pollfd fds; // [rsp+20h] [rbp-48h] BYREF
int v23; // [rsp+28h] [rbp-40h]
__int16 v24; // [rsp+2Ch] [rbp-3Ch]
char v25; // [rsp+2Eh] [rbp-3Ah]

v3 = argc;
v21 = 27;
v5 = &unk_404100;
do
*v5++ = 1;
while ( v5 != (_BYTE *)&unk_40415F );
byte_4040E7 = -1;
byte_4040E8 = 1;
byte_4040E9 = 1;
byte_4040EA = 1;
byte_4040ED = 1;
v6 = -1;
v7 = "console.log";
if ( argc <= 1 )
goto LABEL_4;
while ( 1 )
{
v13 = argv[1];
if ( *v13 != 45 )
break;
v14 = v13[1];
if ( v14 == 108 )
{
if ( v13[2] )
v7 = v13 + 2;
v6 = open(v7, 65, 420LL);
}
else
{
if ( v14 != 116 )
{
fprintf(stderr, "unknown option %s\n", v13);
return 1;
}
v15 = valid;
do
*v15++ = 1;
while ( &valid[256] != v15 );
}
++argv;
if ( --v3 == 1 )
goto LABEL_4;
}
if ( v3 <= 1 )
{
LABEL_4:
v8 = "/dev/ttyUSB0";
v9 = 115200;
}
else
{
v17 = argv[1];
if ( ((*__ctype_b_loc())[*v17] & 0x800) != 0 )
{
v8 = "/dev/ttyUSB0";
LABEL_33:
if ( v17 )
{
v18 = strtoul(v17, &endptr, 0);
v9 = v18;
if ( v18 == -1LL || (unsigned int)v18 != v18 || *endptr )
{
fprintf(stderr, "invalid speed '%s'\n", v17);
return -1;
}
fprintf(stderr, "SPEED: %s\n", v17);
}
else
{
v9 = 115200;
}
goto LABEL_5;
}
if ( v3 > 2 )
{
v8 = v17;
v17 = argv[2];
goto LABEL_33;
}
v8 = v17;
v9 = 115200;
}
LABEL_5:
v10 = openserial(v8, v9);
if ( v10 < 0 )
{
fprintf(stderr, "stderr open '%s'\n", v8);
return -1;
}
stdin_raw_init();
signal(2, (__sighandler_t)oops);
fds.fd = 0;
fds.events = 1;
v23 = v10;
v24 = 1;
fprintf(stderr, "[ %s ]\n", v8);
v11 = 0;
while ( 1 )
{
while ( poll(&fds, 2uLL, -1) <= 0 )
;
if ( (fds.revents & 0x18) != 0 )
{
fwrite("\n[ stdin port closed ]\n", 1uLL, 0x17uLL, stderr);
goto LABEL_42;
}
if ( (v25 & 0x18) != 0 )
{
fwrite("\n[ serial port closed ]\n", 1uLL, 0x18uLL, stderr);
goto LABEL_42;
}
if ( (fds.revents & 1) == 0 || read(0, &buf, 1uLL) != 1 )
goto LABEL_11;
if ( v11 == 1 )
{
if ( buf == 27 )
{
fwrite("\n[ (b)reak? e(x)it? ]\n", 1uLL, 0x16uLL, stderr);
v11 = 2;
}
else
{
write(v10, &v21, 1uLL);
write(v10, &buf, 1uLL);
v11 = 0;
}
goto LABEL_11;
}
if ( v11 != 2 )
{
if ( buf == 27 )
v11 = 1;
else
write(v10, &buf, 1uLL);
goto LABEL_11;
}
if ( buf != 98 )
break;
fwrite("[ break ]\n", 1uLL, 0xAuLL, stderr);
tcsendbreak(v10, 0);
v11 = 0;
LABEL_11:
if ( (v25 & 1) != 0 && read(v10, &buf, 1uLL) == 1 )
{
LOBYTE(endptr) = buf;
v12 = valid[buf];
if ( v12 )
{
if ( v12 != -1 )
goto LABEL_15;
}
else
{
LOBYTE(endptr) = 46;
LABEL_15:
write(1, &endptr, 1uLL);
if ( v6 != -1 )
write(v6, &endptr, 1uLL);
}
}
}
if ( buf != 120 )
{
if ( buf == 27 )
write(v10, &buf, 1uLL);
else
fwrite("[ huh? ]\n", 1uLL, 9uLL, stderr);
v11 = 0;
goto LABEL_11;
}
fwrite("[ exit ]\n", 1uLL, 9uLL, stderr);
LABEL_42:
stdin_raw_restore();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
_BYTE *v5; // rax
int v6; // er13
const char *v7; // r15
const char *v8; // rbp
unsigned int v9; // ebx
int v10; // ebx
int v11; // ebp
char v12; // al
const char *v13; // rdx
char v14; // al
char *v15; // rax
const char *v17; // r14
unsigned __int64 v18; // rax
unsigned __int8 buf; // [rsp+Fh] [rbp-59h] BYREF
char *endptr; // [rsp+10h] [rbp-58h] BYREF
char v21; // [rsp+1Fh] [rbp-49h] BYREF
struct pollfd fds; // [rsp+20h] [rbp-48h] BYREF
int v23; // [rsp+28h] [rbp-40h]
__int16 v24; // [rsp+2Ch] [rbp-3Ch]
char v25; // [rsp+2Eh] [rbp-3Ah]

v3 = argc;
v21 = 27;
v5 = &unk_404100;
do
*v5++ = 1;
while ( v5 != (_BYTE *)&unk_40415F );
byte_4040E7 = -1;
byte_4040E8 = 1;
byte_4040E9 = 1;
byte_4040EA = 1;
byte_4040ED = 1;
v6 = -1;
v7 = "console.log";
if ( argc <= 1 )
goto LABEL_4;
while ( 1 )
{
v13 = argv[1];
if ( *v13 != 45 )
break;
v14 = v13[1];
if ( v14 == 108 )
{
if ( v13[2] )
v7 = v13 + 2;
v6 = open(v7, 65, 420LL);
}
else
{
if ( v14 != 116 )
{
fprintf(stderr, "unknown option %s\n", v13);
return 1;
}
v15 = valid;
do
*v15++ = 1;
while ( &valid[256] != v15 );
}
++argv;
if ( --v3 == 1 )
goto LABEL_4;
}
if ( v3 <= 1 )
{
LABEL_4:
v8 = "/dev/ttyUSB0";
v9 = 115200;
}
else
{
v17 = argv[1];
if ( ((*__ctype_b_loc())[*v17] & 0x800) != 0 )
{
v8 = "/dev/ttyUSB0";
LABEL_33:
if ( v17 )
{
v18 = strtoul(v17, &endptr, 0);
v9 = v18;
if ( v18 == -1LL || (unsigned int)v18 != v18 || *endptr )
{
fprintf(stderr, "invalid speed '%s'\n", v17);
return -1;
}
fprintf(stderr, "SPEED: %s\n", v17);
}
else
{
v9 = 115200;
}
goto LABEL_5;
}
if ( v3 > 2 )
{
v8 = v17;
v17 = argv[2];
goto LABEL_33;
}
v8 = v17;
v9 = 115200;
}
LABEL_5:
v10 = func13(v8, v9);
if ( v10 < 0 )
{
fprintf(stderr, "stderr open '%s'\n", v8);
return -1;
}
func10();
signal(2, (__sighandler_t)oops);
fds.fd = 0;
fds.events = 1;
v23 = v10;
v24 = 1;
fprintf(stderr, "[ %s ]\n", v8);
v11 = 0;
while ( 1 )
{
while ( poll(&fds, 2uLL, -1) <= 0 )
;
if ( (fds.revents & 0x18) != 0 )
{
fwrite("\n[ stdin port closed ]\n", 1uLL, 0x17uLL, stderr);
goto LABEL_42;
}
if ( (v25 & 0x18) != 0 )
{
fwrite("\n[ serial port closed ]\n", 1uLL, 0x18uLL, stderr);
goto LABEL_42;
}
if ( (fds.revents & 1) == 0 || read(0, &buf, 1uLL) != 1 )
goto LABEL_11;
if ( v11 == 1 )
{
if ( buf == 27 )
{
fwrite("\n[ (b)reak? e(x)it? ]\n", 1uLL, 0x16uLL, stderr);
v11 = 2;
}
else
{
write(v10, &v21, 1uLL);
write(v10, &buf, 1uLL);
v11 = 0;
}
goto LABEL_11;
}
if ( v11 != 2 )
{
if ( buf == 27 )
v11 = 1;
else
write(v10, &buf, 1uLL);
goto LABEL_11;
}
if ( buf != 98 )
break;
fwrite("[ break ]\n", 1uLL, 0xAuLL, stderr);
tcsendbreak(v10, 0);
v11 = 0;
LABEL_11:
if ( (v25 & 1) != 0 && read(v10, &buf, 1uLL) == 1 )
{
LOBYTE(endptr) = buf;
v12 = valid[buf];
if ( v12 )
{
if ( v12 != -1 )
goto LABEL_15;
}
else
{
LOBYTE(endptr) = 46;
LABEL_15:
write(1, &endptr, 1uLL);
if ( v6 != -1 )
write(v6, &endptr, 1uLL);
}
}
}
if ( buf != 120 )
{
if ( buf == 27 )
write(v10, &buf, 1uLL);
else
fwrite("[ huh? ]\n", 1uLL, 9uLL, stderr);
v11 = 0;
goto LABEL_11;
}
fwrite("[ exit ]\n", 1uLL, 9uLL, stderr);
LABEL_42:
func8();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 struct pollfd fds[2];
 speed_t speed = 115200;
 const char *device = "/dev/ttyUSB0";
 const char *logfile = "console.log";
 const char *speed_arg = ((void *)0);
 int fd, n;
 int escape = 0;
 int logfd = -1;
 unsigned char ESC = 27;
 for (n = ' '; n < 127; n++)
  valid[n] = 1;
 valid[7] = -1;
 valid[8] = 1;
 valid[9] = 1;
 valid[10] = 1;
 valid[13] = 1;
 while ((argc > 1) && (argv[1][0] == '-')) {
  switch (argv[1][1]) {
  case 't':
   for (n = 0; n < 256; n++)
    valid[n] = 1;
   break;
  case 'l':
   if (argv[1][2])
    logfile = &argv[1][2];
   logfd = open(logfile, 0100 | 01, 0644);
   break;
  default:
   fprintf(stderr, "unknown option %s\n", argv[1]);
   return 1;
  }
  argv++;
  argc--;
 }
 if (argc > 1) {
  const char* arg = argv[1];
  if (((*__ctype_b_loc ())[(int) ((arg[0]))] & (unsigned short int) _ISdigit)) {
   speed_arg = arg;
  } else {
   device = arg;
  }
  argc--;
  argv++;
 }
 if (argc > 1) {
  if (!speed_arg)
   speed_arg = argv[1];
  argc--;
  argv++;
 }
 if (speed_arg) {
  unsigned long speed_long;
  char *endptr;
  speed_long = strtoul(speed_arg, &endptr, 0);
  speed = (speed_t)speed_long;
  if (speed_long == (0x7fffffffffffffffL * 2UL + 1UL) || speed_long != speed || *endptr != '\0') {
   fprintf(stderr, "invalid speed '%s'\n", speed_arg);
   return -1;
  }
  fprintf(stderr, "SPEED: %s\n", speed_arg);
 }
 fd = openserial(device, speed);
 if (fd < 0) {
  fprintf(stderr, "stderr open '%s'\n", device);
  return -1;
 }
 stdin_raw_init();
 signal(2, oops);
 fds[0].fd = 0;
 fds[0].events = 0x001;
 fds[1].fd = fd;
 fds[1].events = 0x001;
 fprintf(stderr, "[ %s ]\n", device);
 for (;;) {
  unsigned char x, t;
  if (poll(fds, 2, -1) > 0) {
   if (fds[0].revents & (0x008 | 0x010)) {
    fprintf(stderr, "\n[ stdin port closed ]\n");
    break;
   }
   if (fds[1].revents & (0x008 | 0x010)) {
    fprintf(stderr, "\n[ serial port closed ]\n");
    break;
   }
   if ((fds[0].revents & 0x001) && (read(0, &x, 1) == 1)) {
    switch (escape) {
    case 0:
     if (x == 27) {
      escape = 1;
     } else {
      write(fd, &x, 1);
     }
     break;
    case 1:
     if (x == 27) {
      escape = 2;
      fprintf(stderr, "\n[ (b)reak? e(x)it? ]\n");
     } else {
      escape = 0;
      write(fd, &ESC, 1);
      write(fd, &x, 1);
     }
     break;
    case 2:
     escape = 0;
     switch (x) {
     case 27:
      write(fd, &x, 1);
      break;
     case 'b':
      fprintf(stderr, "[ break ]\n");
      tcsendbreak(fd, 0);
      break;
     case 'x':
      fprintf(stderr, "[ exit ]\n");
      goto done;
     default:
      fprintf(stderr, "[ huh? ]\n");
      break;
     }
     break;
    }
   }
   if ((fds[1].revents & 0x001) && (read(fd, &x, 1) == 1)) {
    unsigned char c = x;
    if (!valid[x])
     c = '.';
    if (valid[x] != -1) {
     write(1, &c, 1);
     if (logfd != -1)
      write(logfd, &c, 1);
    }
   }
  }
 }
done:
 stdin_raw_restore();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct pollfd fds[2];
 unsigned int speed = 115200;
 char *device = "/dev/ttyUSB0";
 char *logfile = "console.log";
 char *speed_arg = ((void *)0);
 int fd; int n;
 int escape = 0;
 int logfd = -1;
 unsigned char ESC = 27;
 for (n = ' '; n < 127; n++)
  valid[n] = 1;
 valid[7] = -1;
 valid[8] = 1;
 valid[9] = 1;
 valid[10] = 1;
 valid[13] = 1;
 while ((argc > 1) && (argv[1][0] == '-')) {
  switch (argv[1][1]) {
  case 't':
   for (n = 0; n < 256; n++)
    valid[n] = 1;
   break;
  case 'l':
   if (argv[1][2])
    logfile = &argv[1][2];
   logfd = open(logfile, 0100 | 01, 0644);
   break;
  default:
   fprintf(stderr, "unknown option %s\n", argv[1]);
   return 1;
  }
  argv++;
  argc--;
 }
 if (argc > 1) {
  char *arg = argv[1];
  if (((*__ctype_b_loc ())[(int) ((arg[0]))] & (unsigned short) _ISdigit)) {
   speed_arg = arg;
  } else {
   device = arg;
  }
  argc--;
  argv++;
 }
 if (argc > 1) {
  if (!speed_arg)
   speed_arg = argv[1];
  argc--;
  argv++;
 }
 if (speed_arg) {
  unsigned long speed_long;
  char *endptr;
  speed_long = strtoul(speed_arg, &endptr, 0);
  speed = (unsigned int)speed_long;
  if (speed_long == (0x7fffffffffffffffL * 2UL + 1UL) || speed_long != speed || *endptr != '\0') {
   fprintf(stderr, "invalid speed '%s'\n", speed_arg);
   return -1;
  }
  fprintf(stderr, "SPEED: %s\n", speed_arg);
 }
 fd = openserial(device, speed);
 if (fd < 0) {
  fprintf(stderr, "stderr open '%s'\n", device);
  return -1;
 }
 stdin_raw_init();
 signal(2, oops);
 fds[0].fd = 0;
 fds[0].events = 0x001;
 fds[1].fd = fd;
 fds[1].events = 0x001;
 fprintf(stderr, "[ %s ]\n", device);
 for (;;) {
  unsigned char x; unsigned char t;
  if (poll(fds, 2, -1) > 0) {
   if (fds[0].revents & (0x008 | 0x010)) {
    fprintf(stderr, "\n[ stdin port closed ]\n");
    break;
   }
   if (fds[1].revents & (0x008 | 0x010)) {
    fprintf(stderr, "\n[ serial port closed ]\n");
    break;
   }
   if ((fds[0].revents & 0x001) && (read(0, &x, 1) == 1)) {
    switch (escape) {
    case 0:
     if (x == 27) {
      escape = 1;
     } else {
      write(fd, &x, 1);
     }
     break;
    case 1:
     if (x == 27) {
      escape = 2;
      fprintf(stderr, "\n[ (b)reak? e(x)it? ]\n");
     } else {
      escape = 0;
      write(fd, &ESC, 1);
      write(fd, &x, 1);
     }
     break;
    case 2:
     escape = 0;
     switch (x) {
     case 27:
      write(fd, &x, 1);
      break;
     case 'b':
      fprintf(stderr, "[ break ]\n");
      tcsendbreak(fd, 0);
      break;
     case 'x':
      fprintf(stderr, "[ exit ]\n");
      goto done;
     default:
      fprintf(stderr, "[ huh? ]\n");
      break;
     }
     break;
    }
   }
   if ((fds[1].revents & 0x001) && (read(fd, &x, 1) == 1)) {
    unsigned char c = x;
    if (!valid[x])
     c = '.';
    if (valid[x] != -1) {
     write(1, &c, 1);
     if (logfd != -1)
      write(logfd, &c, 1);
    }
   }
  }
 }
done:
 stdin_raw_restore();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct pollfd { int fd; short events; short revents; } [2]

variable_types:
logfile
char *

variable_types: n int

variable_types: escape int

variable_types: logfd int

variable_types:
ESC
unsigned char

variable_types:
arg
char *

variable_types:
endptr
char *

variable_types:
x
unsigned char

variable_types:
t
unsigned char

variable_types:
c
unsigned char


absmod

repo: koraa/chentropy

decompiled_code:
__int64 __fastcall absmod(int a1, int a2)
{
return abs32(a1 % a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return abs32(a1 % a2);
}

original_code:
int absmod(int i, int m) {
  return abs(i%m);
}

variable_types: i int

variable_types: m int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebx
int v5; // er12
int v6; // ebp
const char *v7; // r13
char v8; // al
const char *v9; // rdi
__int64 v10; // rdx
const char *v11; // rax
int v12; // er15
_BYTE *v13; // r14
_BYTE *v14; // rbx
size_t v15; // rbx
char *format; // [rsp+0h] [rbp-58h]
_BYTE *ptr; // [rsp+8h] [rbp-50h]
int v19; // [rsp+18h] [rbp-40h] BYREF
int v20[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( argc > 0 )
{
v4 = 0;
v5 = 40;
v6 = 40;
format = (char *)&unk_402004;
v7 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
while ( 1 )
{
v10 = v4;
v11 = argv[v10];
if ( *v11 == 45 )
{
v8 = v11[1];
if ( argc <= ++v4 )
goto LABEL_13;
v9 = argv[v10 + 1];
if ( v8 == 120 )
{
v6 = atoi(v9);
v5 = v6;
}
else if ( v8 > 120 )
{
if ( v8 != 122 )
goto LABEL_18;
v5 = atoi(v9);
}
else if ( v8 == 97 )
{
v6 = atoi(v9);
}
else
{
if ( v8 != 115 )
goto LABEL_18;
format = (char *)argv[v10 + 1];
}
}
else
{
if ( !v11[1] )
{
if ( v4 + 1 >= argc )
LABEL_13:
exit(1);
LABEL_18:
exit(2);
}
v7 = argv[v4];
}
if ( argc <= ++v4 )
goto LABEL_21;
}
}
v5 = 40;
v6 = 40;
format = (char *)&unk_402004;
v7 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
LABEL_21:
v12 = strlen(v7);
ptr = malloc(v5);
v13 = &ptr[v5];
v19 = v5;
while ( 1 )
{
if ( v6 < v5 )
{
if ( !(unsigned __int8)rrandi(&v19, v6, v5) )
return 0;
v13 = &ptr[v19];
}
v14 = ptr;
if ( ptr < v13 )
break;
LABEL_26:
v15 = fwrite(ptr, 1uLL, v19, _bss_start);
printf(format);
if ( v19 != v15 )
return 0;
}
while ( (unsigned __int8)rrandi(v20, 0, v12) )
{
*v14++ = v7[v20[0]];
if ( v14 == v13 )
goto LABEL_26;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebx
int v5; // er12
int v6; // ebp
const char *v7; // r13
char v8; // al
const char *v9; // rdi
__int64 v10; // rdx
const char *v11; // rax
int v12; // er15
_BYTE *v13; // r14
_BYTE *v14; // rbx
size_t v15; // rbx
char *format; // [rsp+0h] [rbp-58h]
_BYTE *ptr; // [rsp+8h] [rbp-50h]
int v19; // [rsp+18h] [rbp-40h] BYREF
int v20[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( argc > 0 )
{
v4 = 0;
v5 = 40;
v6 = 40;
format = (char *)&unk_402004;
v7 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
while ( 1 )
{
v10 = v4;
v11 = argv[v10];
if ( *v11 == 45 )
{
v8 = v11[1];
if ( argc <= ++v4 )
goto LABEL_13;
v9 = argv[v10 + 1];
if ( v8 == 120 )
{
v6 = atoi(v9);
v5 = v6;
}
else if ( v8 > 120 )
{
if ( v8 != 122 )
goto LABEL_18;
v5 = atoi(v9);
}
else if ( v8 == 97 )
{
v6 = atoi(v9);
}
else
{
if ( v8 != 115 )
goto LABEL_18;
format = (char *)argv[v10 + 1];
}
}
else
{
if ( !v11[1] )
{
if ( v4 + 1 >= argc )
LABEL_13:
exit(1);
LABEL_18:
exit(2);
}
v7 = argv[v4];
}
if ( argc <= ++v4 )
goto LABEL_21;
}
}
v5 = 40;
v6 = 40;
format = (char *)&unk_402004;
v7 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
LABEL_21:
v12 = strlen(v7);
ptr = malloc(v5);
v13 = &ptr[v5];
v19 = v5;
while ( 1 )
{
if ( v6 < v5 )
{
if ( !(unsigned __int8)func10(&v19, v6, v5) )
return 0;
v13 = &ptr[v19];
}
v14 = ptr;
if ( ptr < v13 )
break;
LABEL_26:
v15 = fwrite(ptr, 1uLL, v19, _bss_start);
printf(format);
if ( v19 != v15 )
return 0;
}
while ( (unsigned __int8)func10(v20, 0, v12) )
{
*v14++ = v7[v20[0]];
if ( v14 == v13 )
goto LABEL_26;
}
return 0;
}

original_code:
int main(int argc, char**argv) {
  char* lib = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  int libl;
  char *sep = "\n";
  int minl = 40, maxl = 40;
  int ai;
  char* arg;
  char opt;
  for (ai=0; ai<argc; ai++) {
    arg = argv[ai];
    if (arg[0] != '-' && arg[1] != '\0') {
      lib = arg;
      continue;
    }
    opt = arg[1];
    ai++;
    if (ai >= argc)
      exit(1);
    arg = argv[ai];
    switch(opt) {
      case 'a':
        minl = atoi(arg);
        break;
      case 'z':
        maxl = atoi(arg);
        break;
      case 'x':
        minl = maxl = atoi(arg);
        break;
      case 's':
        sep = arg;
        break;
      default:
        exit(2);
    }
  }
  libl = strlen(lib);
  char *lbuf = malloc(maxl), *pt;
  char *tow = lbuf + maxl;
  int c, llen = maxl;
  while(1) {
    pt = lbuf;
    if (minl < maxl) {
      if (!rrandi( &llen, minl, maxl, stdin))
        return 0;
      tow = lbuf + llen;
    }
    while(pt < tow) {
      if (!rrandi(&c, 0, libl, stdin))
        return 0;
      *(pt++) = lib[c];
    }
    size_t wrot = fwrite(lbuf, sizeof(char), llen, stdout);
    printf(sep);
    if (wrot != llen)
      return 0;
  }
}

canonical_original_code:
int main(int argc, char **argv) {
  char *lib = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  int libl;
  char *sep = "\n";
  int minl = 40; int maxl = 40;
  int ai;
  char *arg;
  char opt;
  for (ai=0; ai<argc; ai++) {
    arg = argv[ai];
    if (arg[0] != '-' && arg[1] != '\0') {
      lib = arg;
      continue;
    }
    opt = arg[1];
    ai++;
    if (ai >= argc)
      exit(1);
    arg = argv[ai];
    switch(opt) {
      case 'a':
        minl = atoi(arg);
        break;
      case 'z':
        maxl = atoi(arg);
        break;
      case 'x':
        minl = maxl = atoi(arg);
        break;
      case 's':
        sep = arg;
        break;
      default:
        exit(2);
    }
  }
  libl = strlen(lib);
  char *lbuf = malloc(maxl); char *pt;
  char *tow = lbuf + maxl;
  int c; int llen = maxl;
  while(1) {
    pt = lbuf;
    if (minl < maxl) {
      if (!rrandi( &llen, minl, maxl, stdin))
        return 0;
      tow = lbuf + llen;
    }
    while(pt < tow) {
      if (!rrandi(&c, 0, libl, stdin))
        return 0;
      *(pt++) = lib[c];
    }
    unsigned long wrot = fwrite(lbuf, sizeof(char), llen, stdout);
    printf(sep);
    if (wrot != llen)
      return 0;
  }
}

variable_types:
argv
char **

variable_types:
lib
char *

variable_types: libl int

variable_types:
sep
char *

variable_types: minl int

variable_types: maxl int

variable_types: ai int

variable_types: opt char

variable_types:
lbuf
char *

variable_types:
pt
char *

variable_types:
tow
char *

variable_types: c int

variable_types: llen int

variable_types:
wrot
unsigned long


repo: koreyconway/school-assignments

decompiled_code:
const char *__fastcall get_signal_name(int a1)
{
const char *result; // rax

result = "SIGINT";
if ( a1 != 2 )
{
result = "UNKNOWN";
if ( a1 == 15 )
result = "SIGTERM";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

result = "SIGINT";
if ( a1 != 2 )
{
result = "UNKNOWN";
if ( a1 == 15 )
result = "SIGTERM";
}
return result;
}

original_code:
char* get_signal_name(int sigtype) {
 char *signame;
 switch(sigtype) {
  case 15:
   signame = "SIGTERM";
   break;
  case 2:
   signame = "SIGINT";
   break;
  default:
   signame = "UNKNOWN";
 }
 return signame;
}

canonical_original_code:
char *get_signal_name(int sigtype) {
 char *signame;
 switch(sigtype) {
  case 15:
   signame = "SIGTERM";
   break;
  case 2:
   signame = "SIGINT";
   break;
  default:
   signame = "UNKNOWN";
 }
 return signame;
}

variable_types: sigtype int

variable_types:
signame
char *

return_type: char *


decompiled_code:
__int64 get_parent_pid()
{
if ( parent_pid == -1 )
parent_pid = getpid();
return (unsigned int)parent_pid;
}

canonical_decompiled_code:
__int64 func1()
{
if ( parent_pid == -1 )
parent_pid = getpid();
return (unsigned int)parent_pid;
}

original_code:
pid_t get_parent_pid() {
 if (-1 == parent_pid) {
  parent_pid = getpid();
 }
 return parent_pid;
}

canonical_original_code:
int get_parent_pid() {
 if (-1 == parent_pid) {
  parent_pid = getpid();
 }
 return parent_pid;
}


decompiled_code:
bool is_parent()
{
__pid_t v0; // ebx

v0 = getpid();
return v0 == (unsigned int)get_parent_pid();
}

canonical_decompiled_code:
bool func2()
{
__pid_t v0; // ebx

v0 = getpid();
return v0 == (unsigned int)func1();
}

original_code:
_Bool is_parent() {
 return (getpid() == get_parent_pid());
}


dump

decompiled_code:
int dump(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
if ( is_parent() )
printf("[parent] ");
else
printf("[child] ");
vprintf(format, arg);
return putchar(10);
}

canonical_decompiled_code:
int func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
if ( func2() )
printf("[parent] ");
else
printf("[child] ");
vprintf(format, arg);
return putchar(10);
}

original_code:
void dump(const char * format, ...) {
 va_list args;
 __builtin_va_start(args,format);
 if (is_parent()) {
  printf("[parent] ");
 } else {
  printf("[child]  ");
 }
 vprintf(format, args);
 printf("\n");
 __builtin_va_end(args);
}

canonical_original_code:
void dump(char *format, ...) {
 __builtin_va_list args;
 __builtin_va_start(args,format);
 if (is_parent()) {
  printf("[parent] ");
 } else {
  printf("[child]  ");
 }
 vprintf(format, args);
 printf("\n");
 __builtin_va_end(args);
}

variable_types:
format
char *


decompiled_code:
int __fastcall setup_signal_handling(int sig, void (*a2)(int))
{
const char *v2; // rax
struct sigaction v4; // [rsp+0h] [rbp-B8h] BYREF

v2 = get_signal_name(sig);
dump("Setup signal handling for signal type: %s", v2);
memset(&v4.sa_mask, 0, 0x90uLL);
v4.sa_handler = a2;
sigemptyset(&v4.sa_mask);
return sigaction(sig, &v4, 0LL);
}

canonical_decompiled_code:
int __fastcall func4(int sig, void (*a2)(int))
{
const char *v2; // rax
struct sigaction v4; // [rsp+0h] [rbp-B8h] BYREF

v2 = func0(sig);
func3("Setup signal handling for signal type: %s", v2);
memset(&v4.sa_mask, 0, 0x90uLL);
v4.sa_handler = a2;
sigemptyset(&v4.sa_mask);
return sigaction(sig, &v4, 0LL);
}

original_code:
void setup_signal_handling(int sigtype, void(*handler)(int)) {
 char *signame = get_signal_name(sigtype);
 dump("Setup signal handling for signal type: %s", signame);
 struct sigaction handle_act = {
  .__sigaction_handler.sa_handler = handler,
  .sa_flags = 0
 };
 sigemptyset(&handle_act.sa_mask);
 sigaction(sigtype, &handle_act, 0);
}

canonical_original_code:
void setup_signal_handling(int sigtype, void (*handler)(int)) {
 char *signame = get_signal_name(sigtype);
 dump("Setup signal handling for signal type: %s", signame);
 struct sigaction handle_act = {
  .__sigaction_handler.sa_handler = handler,
  .sa_flags = 0
 };
 sigemptyset(&handle_act.sa_mask);
 sigaction(sigtype, &handle_act, 0);
}

variable_types:
handler
void (*)(int)

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
char __fastcall send_signal(int sig, char a2)
{
const char *v3; // rsi
__pid_t v4; // eax
char result; // al
__pid_t v6; // eax
__pid_t v7; // eax

v3 = get_signal_name(sig);
if ( a2 )
{
dump("Sending %s signal to parent process", v3);
if ( is_parent() )
{
v4 = getpid();
result = kill(v4, sig);
}
else
{
v6 = getppid();
result = kill(v6, sig);
}
}
else
{
dump("Sending %s signal to child process", v3);
result = is_parent();
if ( result )
{
if ( child_pid > 0 )
result = kill(child_pid, sig);
}
else
{
v7 = getpid();
result = kill(v7, sig);
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func5(int sig, char a2)
{
const char *v3; // rsi
__pid_t v4; // eax
char result; // al
__pid_t v6; // eax
__pid_t v7; // eax

v3 = func0(sig);
if ( a2 )
{
func3("Sending %s signal to parent process", v3);
if ( func2() )
{
v4 = getpid();
result = kill(v4, sig);
}
else
{
v6 = getppid();
result = kill(v6, sig);
}
}
else
{
func3("Sending %s signal to child process", v3);
result = func2();
if ( result )
{
if ( child_pid > 0 )
result = kill(child_pid, sig);
}
else
{
v7 = getpid();
result = kill(v7, sig);
}
}
return result;
}

original_code:
void send_signal(int sigtype, _Bool parent_is_destination) {
 char *signame = get_signal_name(sigtype);
 if (parent_is_destination) {
  dump("Sending %s signal to parent process", signame);
  if (is_parent()) {
   kill(getpid(), sigtype);
  } else {
   kill(getppid(), sigtype);
  }
 } else {
  dump("Sending %s signal to child process", signame);
  if(!is_parent()) {
   kill(getpid(), sigtype);
  } else if (child_pid > 0) {
   kill(child_pid, sigtype);
  }
 }
}


decompiled_code:
__int64 __fastcall fork_process(__int64 (*a1)(void), __int64 (*a2)(void))
{
__pid_t v2; // eax
__int64 result; // rax

get_parent_pid();
v2 = fork();
child_pid = v2;
if ( v2 == -1 )
{
dump("Fork failed");
exit(1);
}
if ( v2 )
result = a1();
else
result = a2();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 (*a1)(void), __int64 (*a2)(void))
{
__pid_t v2; // eax
__int64 result; // rax

func1();
v2 = fork();
child_pid = v2;
if ( v2 == -1 )
{
func3("Fork failed");
exit(1);
}
if ( v2 )
result = a1();
else
result = a2();
return result;
}

original_code:
void fork_process(void(*parent_main)(), void(*child_main)()) {
 get_parent_pid();
 child_pid = fork();
 switch(child_pid) {
  case -1:
   dump("Fork failed");
   exit(1);
  case 0:
   child_main();
   break;
  default:
   parent_main();
   break;
 }
}

canonical_original_code:
void fork_process(void (*parent_main)(), void (*child_main)()) {
 get_parent_pid();
 child_pid = fork();
 switch(child_pid) {
  case -1:
   dump("Fork failed");
   exit(1);
  case 0:
   child_main();
   break;
  default:
   parent_main();
   break;
 }
}


decompiled_code:
__pid_t get_child_pid()
{
__pid_t result; // eax

if ( is_parent() )
result = child_pid;
else
result = getpid();
return result;
}

canonical_decompiled_code:
__pid_t func7()
{
__pid_t result; // eax

if ( func2() )
result = child_pid;
else
result = getpid();
return result;
}

original_code:
pid_t get_child_pid() {
 if (is_parent()) {
  return child_pid;
 } else {
  return getpid();
 }
}

canonical_original_code:
int get_child_pid() {
 if (is_parent()) {
  return child_pid;
 } else {
  return getpid();
 }
}


decompiled_code:
__int64 __fastcall handle_signal(int a1)
{
__int64 result; // rax

if ( a1 == 2 )
{
dump("Received SIGINT signal");
running = 0;
result = is_parent();
if ( (_BYTE)result )
return send_signal(15LL, 0LL);
}
else
{
if ( a1 != 15 )
return dump("Received unknown signal. Ignoring it");
dump("Received SIGTERM signal");
running = 0;
result = is_parent();
if ( (_BYTE)result )
return send_signal(15LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax

if ( a1 == 2 )
{
dump("Received SIGINT signal");
running = 0;
result = is_parent();
if ( (_BYTE)result )
return send_signal(15LL, 0LL);
}
else
{
if ( a1 != 15 )
return dump("Received unknown signal. Ignoring it");
dump("Received SIGTERM signal");
running = 0;
result = is_parent();
if ( (_BYTE)result )
return send_signal(15LL, 0LL);
}
return result;
}

original_code:
void handle_signal(int sigtype) {
 if (2 == sigtype) {
  dump("Received SIGINT signal");
  running = 0;
  if (is_parent()) {
   send_signal(15, 0);
  }
 } else if (15 == sigtype) {
  dump("Received SIGTERM signal");
  running = 0;
  if (is_parent()) {
   send_signal(15, 0);
  }
 } else {
  dump("Received unknown signal. Ignoring it");
 }
}


decompiled_code:
int __fastcall close_monitor(unsigned int a1)
{
int v1; // eax
int v2; // ebx
int result; // eax
int *v4; // rax
int buf[2]; // [rsp+8h] [rbp-40h] BYREF
char s[56]; // [rsp+10h] [rbp-38h] BYREF

sprintf(s, "./fifo.monitor.%d", a1);
dump("Opening fifo %s to send terminate request.", s);
v1 = open(s, 1);
if ( v1 == -1 )
{
v4 = _errno_location();
result = dump("Failed to open fifo with error: %d", (unsigned int)*v4);
}
else
{
v2 = v1;
dump("Sending request to terminate to monitor pid: %d", a1);
buf[0] = getpid();
buf[1] = 1;
if ( write(v2, buf, 8uLL) == -1 )
dump("Failed to write to fifo");
result = close(v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1)
{
int v1; // eax
int v2; // ebx
int result; // eax
int *v4; // rax
int buf[2]; // [rsp+8h] [rbp-40h] BYREF
char s[56]; // [rsp+10h] [rbp-38h] BYREF

sprintf(s, "./fifo.monitor.%d", a1);
dump("Opening fifo %s to send terminate request.", s);
v1 = open(s, 1);
if ( v1 == -1 )
{
v4 = _errno_location();
result = dump("Failed to open fifo with error: %d", (unsigned int)*v4);
}
else
{
v2 = v1;
dump("Sending request to terminate to monitor pid: %d", a1);
buf[0] = getpid();
buf[1] = 1;
if ( write(v2, buf, 8uLL) == -1 )
dump("Failed to write to fifo");
result = close(v2);
}
return result;
}

original_code:
void close_monitor(int monitor_pid) {
 char monitor_fifo_name[sizeof("./fifo.monitor.%d") + 5];
 sprintf(monitor_fifo_name, "./fifo.monitor.%d", monitor_pid);
 dump("Opening fifo %s to send terminate request.", monitor_fifo_name);
 int monitor_fifo_fd = open(monitor_fifo_name, 01);
 if (-1 == monitor_fifo_fd) {
  dump("Failed to open fifo with error: %d", (*__errno_location ()));
  return;
 }
 dump("Sending request to terminate to monitor pid: %d", monitor_pid);
 fifo_data fdata;
 fdata.source_pid = getpid();
 fdata.request_type = STOP;
 if(-1 == write(monitor_fifo_fd, &fdata, sizeof(fdata))) {
  dump("Failed to write to fifo");
 }
 close(monitor_fifo_fd);
}

canonical_original_code:
void close_monitor(int monitor_pid) {
 char monitor_fifo_name[-1];
 sprintf(monitor_fifo_name, "./fifo.monitor.%d", monitor_pid);
 dump("Opening fifo %s to send terminate request.", monitor_fifo_name);
 int monitor_fifo_fd = open(monitor_fifo_name, 01);
 if (-1 == monitor_fifo_fd) {
  dump("Failed to open fifo with error: %d", (*__errno_location ()));
  return;
 }
 dump("Sending request to terminate to monitor pid: %d", monitor_pid);
 struct fifo_data fdata;
 fdata.source_pid = getpid();
 fdata.request_type = STOP;
 if(-1 == write(monitor_fifo_fd, &fdata, sizeof(fdata))) {
  dump("Failed to write to fifo");
 }
 close(monitor_fifo_fd);
}

variable_types: struct fifo_data { int source_pid; enum { START=0, STOP=1, CONNECT=2, STOPPING=3 } request_type; }


repo: korisk/pinc

decompiled_code:
int dumb_fini()
{
int result; // eax

result = incremented;
if ( !incremented )
result = puts("alarm! wrong result");
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

result = incremented;
if ( !incremented )
result = puts("alarm! wrong result");
return result;
}

original_code:
int dumb_fini(int nums){
 if(incremented == 0)
  printf("alarm! wrong result\n");
}

variable_types: nums int


decompiled_code:
__int64 __fastcall spin_init(unsigned int count)
{
incremented = 0LL;
pthread_spin_init(&spin, 0);
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int count)
{
incremented = 0LL;
pthread_spin_init(&spin, 0);
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

original_code:
int spin_init(int nums){
 incremented = 0;
 pthread_spin_init(&spin,0);
 pthread_barrier_init(&barrier, ((void *)0), nums);
 return 0;
}


decompiled_code:
__int64 __fastcall lock_init(unsigned int count)
{
incremented = 0LL;
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int count)
{
incremented = 0LL;
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

original_code:
int lock_init(int nums){
 incremented = 0;
 pthread_barrier_init(&barrier, ((void *)0), nums);
 return 0;
}


decompiled_code:
__int64 __fastcall lock2_init(unsigned int count)
{
incremented = 0LL;
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int count)
{
incremented = 0LL;
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

original_code:
int lock2_init(int nums){
 incremented = 0;
 pthread_barrier_init(&barrier, ((void *)0), nums);
 return 0;
}


decompiled_code:
__int64 __fastcall dumb_init(unsigned int count)
{
incremented = 0LL;
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int count)
{
incremented = 0LL;
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

original_code:
int dumb_init(int nums){
 incremented = 0;
 pthread_barrier_init(&barrier, ((void *)0), nums);
 return 0;
}


decompiled_code:
__int64 __fastcall dumb_thread(__int64 a1)
{
__int64 v1; // rcx
__int64 i; // rdx

pthread_barrier_wait(&barrier);
if ( !*(_DWORD *)(a1 + 8) )
{
v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
{
for ( i = 0LL; i != v1; ++i )
++incremented;
}
}
pthread_barrier_wait(&barrier);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rcx
__int64 i; // rdx

pthread_barrier_wait(&barrier);
if ( !*(_DWORD *)(a1 + 8) )
{
v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
{
for ( i = 0LL; i != v1; ++i )
++incremented;
}
}
pthread_barrier_wait(&barrier);
return 0LL;
}

original_code:
void *dumb_thread(void *_data){
 position *data = (position*)(_data);
 pthread_barrier_wait(&barrier);
 if(data->my_number != 0)goto ex;
 unsigned long i = 0;
  for(i=0; i< data->big_number; i++){
  incremented++;
 }
ex:
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

canonical_original_code:
void *dumb_thread(void *_data){
 struct position *data = (position*)(_data);
 pthread_barrier_wait(&barrier);
 if(data->my_number != 0)goto ex;
 unsigned long i = 0;
  for(i=0; i< data->big_number; i++){
  incremented++;
 }
ex:
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

variable_types: struct position { int nprocs; int threads; int my_number; unsigned long big_number; } *

variable_types:
i
unsigned long

return_type: void *


decompiled_code:
__int64 __fastcall spin_thread(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rbx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-98h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
pthread_spin_lock(&spin);
++incremented;
pthread_spin_unlock(&spin);
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rbx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-98h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
pthread_spin_lock(&spin);
++incremented;
pthread_spin_unlock(&spin);
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

original_code:
void *spin_thread(void *_data){
 position *data = (position*)(_data);
 cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  pthread_spin_lock(&spin);
  incremented++;
  pthread_spin_unlock(&spin);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

canonical_original_code:
void *spin_thread(void *_data){
 struct position *data = (position*)(_data);
 struct cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  pthread_spin_lock(&spin);
  incremented++;
  pthread_spin_unlock(&spin);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }

variable_types: ret int

variable_types:
N
unsigned long

user_defined_types: struct position { int nprocs; int threads; int my_number; unsigned long big_number; }


decompiled_code:
int spin_fini()
{
if ( !incremented )
puts("alarm! wrong result");
pthread_spin_destroy(&spin);
return pthread_barrier_destroy(&barrier);
}

canonical_decompiled_code:
int func7()
{
if ( !incremented )
puts("alarm! wrong result");
pthread_spin_destroy(&spin);
return pthread_barrier_destroy(&barrier);
}

original_code:
int spin_fini(int nums){
 if(incremented == 0)
  printf("alarm! wrong result\n");
 pthread_spin_destroy(&spin);
 pthread_barrier_destroy(&barrier);
}


decompiled_code:
int lock_fini()
{
if ( !incremented )
puts("alarm! wrong result");
return pthread_barrier_destroy(&barrier);
}

canonical_decompiled_code:
int func8()
{
if ( !incremented )
puts("alarm! wrong result");
return pthread_barrier_destroy(&barrier);
}

original_code:
int lock_fini(int nums){
 if(incremented == 0)
  printf("alarm! wrong result\n");
 pthread_barrier_destroy(&barrier);
}


decompiled_code:
int lock2_fini()
{
if ( !incremented )
puts("alarm! wrong result");
return pthread_barrier_destroy(&barrier);
}

canonical_decompiled_code:
int func9()
{
if ( !incremented )
puts("alarm! wrong result");
return pthread_barrier_destroy(&barrier);
}

original_code:
int lock2_fini(int nums){
 if(incremented == 0)
  printf("alarm! wrong result\n");
 pthread_barrier_destroy(&barrier);
}


decompiled_code:
__int64 __fastcall mutex_init(unsigned int count)
{
incremented = 0LL;
pthread_mutex_init(&mut, 0LL);
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int count)
{
incremented = 0LL;
pthread_mutex_init(&mut, 0LL);
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

original_code:
int mutex_init(int nums){
 incremented = 0;
 pthread_mutex_init(&mut,((void *)0));
 pthread_barrier_init(&barrier, ((void *)0), nums);
 return 0;
}


decompiled_code:
__int64 __fastcall mutex_thread(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rbx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-98h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
pthread_mutex_lock(&mut);
++incremented;
pthread_mutex_unlock(&mut);
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rbx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-98h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
pthread_mutex_lock(&mut);
++incremented;
pthread_mutex_unlock(&mut);
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

original_code:
void *mutex_thread(void *_data){
 position *data = (position*)(_data);
 cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  pthread_mutex_lock(&mut);
  incremented++;
  pthread_mutex_unlock(&mut);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

canonical_original_code:
void *mutex_thread(void *_data){
 struct position *data = (position*)(_data);
 struct cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  pthread_mutex_lock(&mut);
  incremented++;
  pthread_mutex_unlock(&mut);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

user_defined_types: struct cpu_set_t { unsigned long __bits[-1]; }


decompiled_code:
int mutex_fini()
{
if ( !incremented )
puts("alarm! wrong result");
pthread_barrier_destroy(&barrier);
return pthread_mutex_destroy(&mut);
}

canonical_decompiled_code:
int func12()
{
if ( !incremented )
puts("alarm! wrong result");
pthread_barrier_destroy(&barrier);
return pthread_mutex_destroy(&mut);
}

original_code:
int mutex_fini(int nums){
 if(incremented == 0)
  printf("alarm! wrong result\n");
 pthread_barrier_destroy(&barrier);
 pthread_mutex_destroy(&mut);
}


decompiled_code:
__int64 __fastcall lock_thread(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rax
unsigned __int64 v6; // rdx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-88h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
_InterlockedAdd64(&incremented, 1uLL);
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rax
unsigned __int64 v6; // rdx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-88h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
_InterlockedAdd64(&incremented, 1uLL);
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

original_code:
void *lock_thread(void *_data){
 position *data = (position*)(_data);
 cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  __sync_fetch_and_add(&incremented,1);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

canonical_original_code:
void *lock_thread(void *_data){
 struct position *data = (position*)(_data);
 struct cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  __sync_fetch_and_add(&incremented,1);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall lock2_thread(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rsi
unsigned __int64 v6; // rdx
__int64 v7; // rtt
char *v9; // rax
cpu_set_t v10; // [rsp+0h] [rbp-88h] BYREF

memset(&v10, 0, sizeof(v10));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v10.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v10);
if ( v3 )
{
v9 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v9);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
do
v7 = incremented;
while ( v7 != _InterlockedCompareExchange64(&incremented, incremented + 1, incremented) );
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rsi
unsigned __int64 v6; // rdx
__int64 v7; // rtt
char *v9; // rax
cpu_set_t v10; // [rsp+0h] [rbp-88h] BYREF

memset(&v10, 0, sizeof(v10));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v10.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v10);
if ( v3 )
{
v9 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v9);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
do
v7 = incremented;
while ( v7 != _InterlockedCompareExchange64(&incremented, incremented + 1, incremented) );
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

original_code:
void *lock2_thread(void *_data){
 position *data = (position*)(_data);
 cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
 unsigned long x = 0;
  for(i=0; i< N; i++){
  do{
   x = incremented;
  }while(!__sync_bool_compare_and_swap(&incremented,x , x + 1));
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

canonical_original_code:
void *lock2_thread(void *_data){
 struct position *data = (position*)(_data);
 struct cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
 unsigned long x = 0;
  for(i=0; i< N; i++){
  do{
   x = incremented;
  }while(!__sync_bool_compare_and_swap(&incremented,x , x + 1));
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

variable_types:
x
unsigned long


usage

decompiled_code:
int __fastcall usage(char *filename)
{
char *v1; // rax

puts("This test measures time spended for Parallel INCrement of one variable with using of different lock mechanism");
v1 = basename(filename);
printf("Usage: %s [-t addititional threads][-f big number factor][-h|-?]\n", v1);
puts("\t-t addititional theads - number of threads which added to number of processors");
puts("\t-f factor - factor which difine big number. Number of increments = factorial(factor)");
return puts("\t-h,-? - this help");
}

canonical_decompiled_code:
int __fastcall func15(char *filename)
{
char *v1; // rax

puts("This test measures time spended for Parallel INCrement of one variable with using of different lock mechanism");
v1 = basename(filename);
printf("Usage: %s [-t addititional threads][-f big number factor][-h|-?]\n", v1);
puts("\t-t addititional theads - number of threads which added to number of processors");
puts("\t-f factor - factor which difine big number. Number of increments = factorial(factor)");
return puts("\t-h,-? - this help");
}

original_code:
void usage(char *name){
 printf("This test measures time spended for Parallel INCrement of one variable with using of different lock mechanism\n");
 printf("Usage: %s [-t addititional threads][-f big number factor][-h|-?]\n",basename(name));
 printf("\t-t addititional theads - number of threads which added to number of processors\n");
 printf("\t-f factor - factor which difine big number. Number of increments = factorial(factor)\n");
 printf("\t-h,-? - this help\n");
}

variable_types:
name
char *


factor

decompiled_code:
__int64 __fastcall factor(__int64 a1)
{
__int64 result; // rax

result = 1LL;
if ( a1 )
result = a1 * factor(a1 - 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
__int64 result; // rax

result = 1LL;
if ( a1 )
result = a1 * func16(a1 - 1);
return result;
}

original_code:
unsigned long factor(unsigned long N){
 if(N <= 0)return 1;
 return (N*factor(N-1));
}

return_type: unsigned long


epochmsec

decompiled_code:
__time_t epochmsec()
{
int v0; // edx
__time_t result; // rax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v0 = gettimeofday(&v2, 0LL);
result = 0LL;
if ( !v0 )
result = 1000 * v2.tv_sec + v2.tv_usec / 1000;
return result;
}

canonical_decompiled_code:
__time_t func17()
{
int v0; // edx
__time_t result; // rax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v0 = gettimeofday(&v2, 0LL);
result = 0LL;
if ( !v0 )
result = 1000 * v2.tv_sec + v2.tv_usec / 1000;
return result;
}

original_code:
unsigned long epochmsec() {
  struct timeval tv;
 if (gettimeofday(&tv, 0) == 0) {
  return tv.tv_sec * 1000 + tv.tv_usec / 1000;
 }else{
  return 0L;
 }
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // ebp
int v5; // eax
__int64 v6; // r12
__int64 v7; // r13
__int64 v8; // rbp
void *v9; // r15
__int64 v10; // rbx
__int64 v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
char *v16; // rax
__time_t v17; // rax
__int64 j; // r14
_DWORD *v19; // rbx
pthread_t *v20; // r12
int v21; // ebp
__int64 v22; // rbx
int v23; // eax
__int64 v24; // rdx
void *(*start_routine)(void *); // [rsp+8h] [rbp-890h]
__time_t v27; // [rsp+10h] [rbp-888h]
__int64 i; // [rsp+28h] [rbp-870h]
void (__fastcall *v29)(_QWORD); // [rsp+30h] [rbp-868h]
__int64 n; // [rsp+38h] [rbp-860h]
_DWORD *s; // [rsp+40h] [rbp-858h]
__int64 v32; // [rsp+48h] [rbp-850h]
__int64 v33; // [rsp+50h] [rbp-848h]
int v34; // [rsp+58h] [rbp-840h]
__int64 v35[64]; // [rsp+60h] [rbp-838h] BYREF
__int64 v36[64]; // [rsp+260h] [rbp-638h] BYREF
__int64 v37[64]; // [rsp+460h] [rbp-438h] BYREF
__int64 v38[71]; // [rsp+660h] [rbp-238h] BYREF

memset(v38, 0, 0x200uLL);
memset(v37, 0, sizeof(v37));
memset(v36, 0, sizeof(v36));
memset(v35, 0, sizeof(v35));
v35[0] = (__int64)"pure increment test";
v37[0] = (__int64)dumb_init;
v38[0] = (__int64)dumb_thread;
v36[0] = (__int64)dumb_fini;
v35[1] = (__int64)"mutexed test";
v37[1] = (__int64)mutex_init;
v38[1] = (__int64)mutex_thread;
v36[1] = (__int64)mutex_fini;
v35[2] = (__int64)"lock increment test";
v37[2] = (__int64)lock_init;
v38[2] = (__int64)lock_thread;
v36[2] = (__int64)lock_fini;
v35[3] = (__int64)"lock compare&swap test";
v37[3] = (__int64)lock2_init;
v38[3] = (__int64)lock2_thread;
v36[3] = (__int64)lock2_fini;
v35[4] = (__int64)"spinlock test";
v37[4] = (__int64)spin_init;
v38[4] = (__int64)spin_thread;
v36[4] = (__int64)spin_fini;
v3 = 4;
v4 = 11;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "?hf:t:");
if ( v5 == -1 )
break;
if ( v5 == 104 )
goto LABEL_10;
if ( v5 > 104 )
{
if ( v5 == 116 )
v3 = atoi(optarg);
}
else
{
if ( v5 == 63 )
{
LABEL_10:
usage((char *)*argv);
exit(0);
}
if ( v5 == 102 )
v4 = atoi(optarg);
}
}
printf("CPU ");
fflush(stdout);
system("cat /proc/cpuinfo |grep 'model name'|head -n1");
printf("Thread libs: ");
fflush(stdout);
system("getconf GNU_LIBPTHREAD_VERSION");
v6 = sysconf(84);
if ( v6 <= 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stdout, "Could not determine number of CPUs online:\n%s\n", v13);
exit(1);
}
v7 = sysconf(83);
if ( v7 <= 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stdout, "Could not determine number of CPUs configured:\n%s\n", v15);
}
printf("%ld of %ld cores online\n", v6, v7);
v34 = v6;
v33 = factor(v4);
printf("Additition threads: %d\n", v3);
printf("Big number: %d! = 0x%lx\n", v4, v33);
v8 = v6 + v3;
v32 = v8;
n = 8 * v8;
v9 = malloc(8 * v8);
s = malloc(24 * v8);
printf("Thrds:\t");
v10 = 0LL;
do
{
printf("%d\t", (unsigned int)(v10 + 1));
v11 = v10++;
}
while ( v8 >= v11 + 2 );
putchar(10);
for ( i = 0LL; i != 64; ++i )
{
v24 = (unsigned int)i;
v29 = (void (__fastcall *)(_QWORD))v37[i];
if ( !v29 )
break;
start_routine = (void *(*)(void *))v38[i];
if ( !start_routine )
break;
fprintf(stdout, "%s \n", (const char *)v35[i]);
printf("*\t");
fflush(stdout);
for ( j = 1LL; ; ++j )
{
memset(v9, 0, n);
v19 = s;
memset(s, 0, n);
v29((unsigned int)j);
v27 = epochmsec();
if ( (int)j > 0 )
{
v20 = (pthread_t *)v9;
v21 = 0;
do
{
*v19 = v34;
v19[1] = j;
v19[2] = v21;
*((_QWORD *)v19 + 2) = v33;
pthread_create(v20, 0LL, start_routine, v19);
++v21;
v19 += 6;
++v20;
}
while ( v21 != (_DWORD)j );
v22 = 0LL;
do
{
v23 = pthread_join(*((_QWORD *)v9 + v22), 0LL);
if ( v23 )
{
v16 = strerror(v23);
fprintf(stdout, "Thread %d join error: %s\n", (unsigned int)v22, v16);
exit(1);
}
++v22;
}
while ( j != v22 );
}
((void (__fastcall *)(_QWORD))v36[i])((unsigned int)j);
v17 = epochmsec();
printf("%ld \t", v17 - v27);
fflush(stdout);
if ( v32 == j )
break;
}
putchar(10);
v24 = (unsigned int)(i + 1);
}
fprintf(stdout, "Done. %d tests at all.\n", v24);
free(v9);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // ebp
int v5; // eax
__int64 v6; // r12
__int64 v7; // r13
__int64 v8; // rbp
void *v9; // r15
__int64 v10; // rbx
__int64 v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
char *v16; // rax
__time_t v17; // rax
__int64 j; // r14
_DWORD *v19; // rbx
pthread_t *v20; // r12
int v21; // ebp
__int64 v22; // rbx
int v23; // eax
__int64 v24; // rdx
void *(*start_routine)(void *); // [rsp+8h] [rbp-890h]
__time_t v27; // [rsp+10h] [rbp-888h]
__int64 i; // [rsp+28h] [rbp-870h]
void (__fastcall *v29)(_QWORD); // [rsp+30h] [rbp-868h]
__int64 n; // [rsp+38h] [rbp-860h]
_DWORD *s; // [rsp+40h] [rbp-858h]
__int64 v32; // [rsp+48h] [rbp-850h]
__int64 v33; // [rsp+50h] [rbp-848h]
int v34; // [rsp+58h] [rbp-840h]
__int64 v35[64]; // [rsp+60h] [rbp-838h] BYREF
__int64 v36[64]; // [rsp+260h] [rbp-638h] BYREF
__int64 v37[64]; // [rsp+460h] [rbp-438h] BYREF
__int64 v38[71]; // [rsp+660h] [rbp-238h] BYREF

memset(v38, 0, 0x200uLL);
memset(v37, 0, sizeof(v37));
memset(v36, 0, sizeof(v36));
memset(v35, 0, sizeof(v35));
v35[0] = (__int64)"pure increment test";
v37[0] = (__int64)dumb_init;
v38[0] = (__int64)dumb_thread;
v36[0] = (__int64)dumb_fini;
v35[1] = (__int64)"mutexed test";
v37[1] = (__int64)mutex_init;
v38[1] = (__int64)mutex_thread;
v36[1] = (__int64)mutex_fini;
v35[2] = (__int64)"lock increment test";
v37[2] = (__int64)lock_init;
v38[2] = (__int64)lock_thread;
v36[2] = (__int64)lock_fini;
v35[3] = (__int64)"lock compare&swap test";
v37[3] = (__int64)lock2_init;
v38[3] = (__int64)lock2_thread;
v36[3] = (__int64)lock2_fini;
v35[4] = (__int64)"spinlock test";
v37[4] = (__int64)spin_init;
v38[4] = (__int64)spin_thread;
v36[4] = (__int64)spin_fini;
v3 = 4;
v4 = 11;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "?hf:t:");
if ( v5 == -1 )
break;
if ( v5 == 104 )
goto LABEL_10;
if ( v5 > 104 )
{
if ( v5 == 116 )
v3 = atoi(optarg);
}
else
{
if ( v5 == 63 )
{
LABEL_10:
func15((char *)*argv);
exit(0);
}
if ( v5 == 102 )
v4 = atoi(optarg);
}
}
printf("CPU ");
fflush(stdout);
system("cat /proc/cpuinfo |grep 'model name'|head -n1");
printf("Thread libs: ");
fflush(stdout);
system("getconf GNU_LIBPTHREAD_VERSION");
v6 = sysconf(84);
if ( v6 <= 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stdout, "Could not determine number of CPUs online:\n%s\n", v13);
exit(1);
}
v7 = sysconf(83);
if ( v7 <= 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stdout, "Could not determine number of CPUs configured:\n%s\n", v15);
}
printf("%ld of %ld cores online\n", v6, v7);
v34 = v6;
v33 = func16(v4);
printf("Additition threads: %d\n", v3);
printf("Big number: %d! = 0x%lx\n", v4, v33);
v8 = v6 + v3;
v32 = v8;
n = 8 * v8;
v9 = malloc(8 * v8);
s = malloc(24 * v8);
printf("Thrds:\t");
v10 = 0LL;
do
{
printf("%d\t", (unsigned int)(v10 + 1));
v11 = v10++;
}
while ( v8 >= v11 + 2 );
putchar(10);
for ( i = 0LL; i != 64; ++i )
{
v24 = (unsigned int)i;
v29 = (void (__fastcall *)(_QWORD))v37[i];
if ( !v29 )
break;
start_routine = (void *(*)(void *))v38[i];
if ( !start_routine )
break;
fprintf(stdout, "%s \n", (const char *)v35[i]);
printf("*\t");
fflush(stdout);
for ( j = 1LL; ; ++j )
{
memset(v9, 0, n);
v19 = s;
memset(s, 0, n);
v29((unsigned int)j);
v27 = func17();
if ( (int)j > 0 )
{
v20 = (pthread_t *)v9;
v21 = 0;
do
{
*v19 = v34;
v19[1] = j;
v19[2] = v21;
*((_QWORD *)v19 + 2) = v33;
pthread_create(v20, 0LL, start_routine, v19);
++v21;
v19 += 6;
++v20;
}
while ( v21 != (_DWORD)j );
v22 = 0LL;
do
{
v23 = pthread_join(*((_QWORD *)v9 + v22), 0LL);
if ( v23 )
{
v16 = strerror(v23);
fprintf(stdout, "Thread %d join error: %s\n", (unsigned int)v22, v16);
exit(1);
}
++v22;
}
while ( j != v22 );
}
((void (__fastcall *)(_QWORD))v36[i])((unsigned int)j);
v17 = func17();
printf("%ld \t", v17 - v27);
fflush(stdout);
if ( v32 == j )
break;
}
putchar(10);
v24 = (unsigned int)(i + 1);
}
fprintf(stdout, "Done. %d tests at all.\n", v24);
free(v9);
return 0;
}

original_code:
int main(int argc, char** argv, char **env){
 void * (*per_thread[0x40])(void *) = {0};
 int (*init_test[0x40])(int) = {0};
 int (*fini_test[0x40])(int) = {0};
 char *titles[0x40] = {0};
 int tests = 0;
 titles[tests] = "pure increment test";
 init_test[tests] = &dumb_init;
 per_thread[tests] = &dumb_thread;
 fini_test[tests] = &dumb_fini;
 tests++;
 titles[tests] = "mutexed test";
 init_test[tests] = &mutex_init;
 per_thread[tests] = &mutex_thread;
 fini_test[tests] = &mutex_fini;
 tests++;
 titles[tests] = "lock increment test";
 init_test[tests] = &lock_init;
 per_thread[tests] = &lock_thread;
 fini_test[tests] = &lock_fini;
 tests++;
 titles[tests] = "lock compare&swap test";
 init_test[tests] = &lock2_init;
 per_thread[tests] = &lock2_thread;
 fini_test[tests] = &lock2_fini;
 tests++;
 titles[tests] = "spinlock test";
 init_test[tests] = &spin_init;
 per_thread[tests] = &spin_thread;
 fini_test[tests] = &spin_fini;
 tests++;
 unsigned int big_factor = 11;
 unsigned int additition_threads = 4;
 int opt = 0;
 while ((opt = getopt(argc, argv, "?hf:t:")) != -1) {
  switch (opt) {
   case '?':
   case 'h':
    usage(argv[0]);
    exit(0);
    break;
   case 't':
    additition_threads = atoi(optarg);
    break;
   case 'f':
    big_factor = atoi(optarg);
    break;
   default:
    break;
  }
 }
 printf("CPU ");
 fflush(stdout);
 int sys = system("cat /proc/cpuinfo |grep 'model name'|head -n1");
 printf("Thread libs: ");
 fflush(stdout);
 sys = system("getconf GNU_LIBPTHREAD_VERSION");
 long nprocs = -1, nprocs_max = -1;
 nprocs = sysconf(_SC_NPROCESSORS_ONLN);
 if (nprocs < 1)
 {
  fprintf(stdout, "Could not determine number of CPUs online:\n%s\n", strerror ((*__errno_location ())));
  exit (1);
 }
 nprocs_max = sysconf(_SC_NPROCESSORS_CONF);
 if (nprocs_max < 1)
 {
  fprintf(stdout, "Could not determine number of CPUs configured:\n%s\n", strerror ((*__errno_location ())));
 }
 printf ("%ld of %ld cores online\n",nprocs, nprocs_max);
 int test_number = 0;
 position *positions = ((void *)0);
 position next;
 next.nprocs = nprocs;
 next.my_number = 0;
 next.big_number = factor(big_factor);
 printf("Additition threads: %d\n",additition_threads);
 printf("Big number: %d! = 0x%lx\n", big_factor, next.big_number);
 nprocs += additition_threads;
 int thread_number = 0;
 int threads_number = 0;
 int ret = 0;
 int my_number = 0;
 pthread_t *threads = ((void *)0);
 unsigned long before = 0;
 unsigned long after = 0;
 threads = malloc(nprocs * sizeof(pthread_t));
 positions = malloc(nprocs * sizeof(position));
 printf("Thrds:\t");
 for(threads_number = 1; threads_number <= nprocs; threads_number++){
  printf("%d\t",threads_number);
 }
 printf("\n");
 while( 0x40 > test_number && ((void *)0) != init_test[test_number] && ((void *)0) != per_thread[test_number] ){
  fprintf(stdout,"%s \n",titles[test_number]);
  printf("*\t");
  fflush(stdout);
  for(threads_number = 1; threads_number <= nprocs; threads_number++){
   next.my_number = 0;
   next.threads = threads_number;
   my_number = 0;
   memset(threads, 0, nprocs*sizeof(pthread_t));
   memset(positions,0,nprocs*sizeof(positions));
   (*init_test[test_number])(threads_number);
   before = epochmsec();
   for(thread_number = 0; thread_number < threads_number; thread_number++){
    next.my_number = my_number;
    positions[thread_number] = next;
    pthread_create(threads+thread_number,((void *)0),per_thread[test_number],positions+thread_number);
    if(ret != 0){
     fprintf(stdout,"Thread %d create error: %s\n",thread_number, strerror(ret));
     exit (1);
    }
    my_number++;
   }
   for(thread_number = 0; thread_number < threads_number; thread_number++){
    ret = pthread_join(*(threads+thread_number),((void *)0));
    if(ret != 0){
     fprintf(stdout,"Thread %d join error: %s\n",thread_number, strerror(ret));
     exit (1);
    }
   }
   (*fini_test[test_number])(threads_number);
   after = epochmsec();
   printf("%ld \t", after - before);
   fflush(stdout);
  }
  printf("\n");
  test_number++;
 }
 fprintf(stdout, "Done. %d tests at all.\n", test_number);
 free(threads);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv, char **env){
 void *(*per_thread[64])(void *) = {0};
 int (*init_test[64])(int) = {0};
 int (*fini_test[64])(int) = {0};
 char *titles[64] = {0};
 int tests = 0;
 titles[tests] = "pure increment test";
 init_test[tests] = &dumb_init;
 per_thread[tests] = &dumb_thread;
 fini_test[tests] = &dumb_fini;
 tests++;
 titles[tests] = "mutexed test";
 init_test[tests] = &mutex_init;
 per_thread[tests] = &mutex_thread;
 fini_test[tests] = &mutex_fini;
 tests++;
 titles[tests] = "lock increment test";
 init_test[tests] = &lock_init;
 per_thread[tests] = &lock_thread;
 fini_test[tests] = &lock_fini;
 tests++;
 titles[tests] = "lock compare&swap test";
 init_test[tests] = &lock2_init;
 per_thread[tests] = &lock2_thread;
 fini_test[tests] = &lock2_fini;
 tests++;
 titles[tests] = "spinlock test";
 init_test[tests] = &spin_init;
 per_thread[tests] = &spin_thread;
 fini_test[tests] = &spin_fini;
 tests++;
 unsigned int big_factor = 11;
 unsigned int additition_threads = 4;
 int opt = 0;
 while ((opt = getopt(argc, argv, "?hf:t:")) != -1) {
  switch (opt) {
   case '?':
   case 'h':
    usage(argv[0]);
    exit(0);
    break;
   case 't':
    additition_threads = atoi(optarg);
    break;
   case 'f':
    big_factor = atoi(optarg);
    break;
   default:
    break;
  }
 }
 printf("CPU ");
 fflush(stdout);
 int sys = system("cat /proc/cpuinfo |grep 'model name'|head -n1");
 printf("Thread libs: ");
 fflush(stdout);
 sys = system("getconf GNU_LIBPTHREAD_VERSION");
 long nprocs = -1; long nprocs_max = -1;
 nprocs = sysconf(_SC_NPROCESSORS_ONLN);
 if (nprocs < 1)
 {
  fprintf(stdout, "Could not determine number of CPUs online:\n%s\n", strerror ((*__errno_location ())));
  exit (1);
 }
 nprocs_max = sysconf(_SC_NPROCESSORS_CONF);
 if (nprocs_max < 1)
 {
  fprintf(stdout, "Could not determine number of CPUs configured:\n%s\n", strerror ((*__errno_location ())));
 }
 printf ("%ld of %ld cores online\n",nprocs, nprocs_max);
 int test_number = 0;
 struct position *positions = ((void *)0);
 struct position next;
 next.nprocs = nprocs;
 next.my_number = 0;
 next.big_number = factor(big_factor);
 printf("Additition threads: %d\n",additition_threads);
 printf("Big number: %d! = 0x%lx\n", big_factor, next.big_number);
 nprocs += additition_threads;
 int thread_number = 0;
 int threads_number = 0;
 int ret = 0;
 int my_number = 0;
 unsigned long *threads = ((void *)0);
 unsigned long before = 0;
 unsigned long after = 0;
 threads = malloc(nprocs * sizeof(pthread_t));
 positions = malloc(nprocs * sizeof(position));
 printf("Thrds:\t");
 for(threads_number = 1; threads_number <= nprocs; threads_number++){
  printf("%d\t",threads_number);
 }
 printf("\n");
 while( 0x40 > test_number && ((void *)0) != init_test[test_number] && ((void *)0) != per_thread[test_number] ){
  fprintf(stdout,"%s \n",titles[test_number]);
  printf("*\t");
  fflush(stdout);
  for(threads_number = 1; threads_number <= nprocs; threads_number++){
   next.my_number = 0;
   next.threads = threads_number;
   my_number = 0;
   memset(threads, 0, nprocs*sizeof(pthread_t));
   memset(positions,0,nprocs*sizeof(positions));
   (*init_test[test_number])(threads_number);
   before = epochmsec();
   for(thread_number = 0; thread_number < threads_number; thread_number++){
    next.my_number = my_number;
    positions[thread_number] = next;
    pthread_create(threads+thread_number,((void *)0),per_thread[test_number],positions+thread_number);
    if(ret != 0){
     fprintf(stdout,"Thread %d create error: %s\n",thread_number, strerror(ret));
     exit (1);
    }
    my_number++;
   }
   for(thread_number = 0; thread_number < threads_number; thread_number++){
    ret = pthread_join(*(threads+thread_number),((void *)0));
    if(ret != 0){
     fprintf(stdout,"Thread %d join error: %s\n",thread_number, strerror(ret));
     exit (1);
    }
   }
   (*fini_test[test_number])(threads_number);
   after = epochmsec();
   printf("%ld \t", after - before);
   fflush(stdout);
  }
  printf("\n");
  test_number++;
 }
 fprintf(stdout, "Done. %d tests at all.\n", test_number);
 free(threads);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
env
char **

variable_types:
titles
char *[64]

variable_types: tests int

variable_types: opt int

variable_types: sys int

variable_types: nprocs long

variable_types: struct position { int nprocs; int threads; int my_number; unsigned long big_number; }

variable_types:
threads
unsigned long *

variable_types:
before
unsigned long

variable_types:
after
unsigned long


ComputerMove

decompiled_code:
__int64 __fastcall ComputerMove(__int64 a1, _DWORD *a2, int a3, int a4)
{
__int64 result; // rax

result = a1 + 12LL * a3;
*(_DWORD *)(result + 4LL * a4) = *a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2, int a3, int a4)
{
__int64 result; // rax

result = a1 + 12LL * a3;
*(_DWORD *)(result + 4LL * a4) = *a2;
return result;
}

original_code:
void ComputerMove(int gField[3][3], int *computerAnswer, int i, int j)
{
 gField[i][j] = *computerAnswer;
}

variable_types:
gField
int [3][3]

variable_types:
computerAnswer
int *

variable_types: i int

variable_types: j int


ChekingPlayerCanWin

original_code:
void ChekingPlayerCanWin(int gField[3][3], gboolean *gfoundDanger, int *playerAnswer, int *computerAnswer)
{
 *gfoundDanger = (0);
 int i;
 for (i = 0; i < 3; i++)
 {
  if (*gfoundDanger) break;
  int j;
  int free = -1;
  int filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gfoundDanger) break;
   if (gField[i][j] == *playerAnswer)
    filling++;
   if (gField[i][j] == 0)
    free = j;
   if ((filling == 3 -1 )&&(free >= 0))
   {
    *gfoundDanger = (!(0));
    ComputerMove(gField, computerAnswer, i, free);
   }
  }
  free = -1;
  filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gfoundDanger) break;
   if (gField[j][i] == *playerAnswer)
    filling++;
   if (gField[j][i] == 0)
    free = j;
   if ((filling == 3 - 1)&&(free >= 0))
   {
    *gfoundDanger = (!(0));
    ComputerMove(gField, computerAnswer, free, i);
   }
  }
  if (i == 0)
  {
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gfoundDanger) break;
    if (gField[j][j] == *playerAnswer)
     filling++;
    if (gField[j][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gfoundDanger = (!(0));
     ComputerMove(gField, computerAnswer, free, free);
    }
   }
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gfoundDanger) break;
    if (gField[3 - j-1][j] == *playerAnswer)
     filling++;
    if (gField[3 - j-1][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gfoundDanger = (!(0));
     ComputerMove(gField, computerAnswer, 3 - free - 1, free);
    }
   }
  }
 }
}

canonical_original_code:
void ChekingPlayerCanWin(int gField[3][3], int *gfoundDanger, int *playerAnswer, int *computerAnswer)
{
 *gfoundDanger = (0);
 int i;
 for (i = 0; i < 3; i++)
 {
  if (*gfoundDanger) break;
  int j;
  int free = -1;
  int filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gfoundDanger) break;
   if (gField[i][j] == *playerAnswer)
    filling++;
   if (gField[i][j] == 0)
    free = j;
   if ((filling == 3 -1 )&&(free >= 0))
   {
    *gfoundDanger = (!(0));
    ComputerMove(gField, computerAnswer, i, free);
   }
  }
  free = -1;
  filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gfoundDanger) break;
   if (gField[j][i] == *playerAnswer)
    filling++;
   if (gField[j][i] == 0)
    free = j;
   if ((filling == 3 - 1)&&(free >= 0))
   {
    *gfoundDanger = (!(0));
    ComputerMove(gField, computerAnswer, free, i);
   }
  }
  if (i == 0)
  {
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gfoundDanger) break;
    if (gField[j][j] == *playerAnswer)
     filling++;
    if (gField[j][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gfoundDanger = (!(0));
     ComputerMove(gField, computerAnswer, free, free);
    }
   }
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gfoundDanger) break;
    if (gField[3 - j-1][j] == *playerAnswer)
     filling++;
    if (gField[3 - j-1][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gfoundDanger = (!(0));
     ComputerMove(gField, computerAnswer, 3 - free - 1, free);
    }
   }
  }
 }
}

variable_types:
gfoundDanger
int *

variable_types:
playerAnswer
int *

variable_types: free int

variable_types: filling int


ChekingComputerWin

original_code:
void ChekingComputerWin(int gField[3][3], gboolean *gcomputerWin, int *playerAnswer, int *computerAnswer)
{
 *gcomputerWin = (0);
 int i;
 for (i = 0; i < 3; i++)
 {
  if (*gcomputerWin) break;
  int j;
  int free = -1;
  int filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gcomputerWin) break;
   if (gField[i][j] == *computerAnswer)
    filling++;
   if (gField[i][j] == 0)
    free = j;
   if ((filling == 3 -1 )&&(free >= 0))
   {
    *gcomputerWin = (!(0));
    ComputerMove(gField, computerAnswer, i, free);
   }
  }
  free = -1;
  filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gcomputerWin) break;
   if (gField[j][i] == *computerAnswer)
    filling++;
   if (gField[j][i] == 0)
    free = j;
   if ((filling == 3 - 1)&&(free >= 0))
   {
    (*gcomputerWin) = (!(0));
    ComputerMove(gField, computerAnswer, free, i);
   }
  }
  if (i == 0)
  {
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gcomputerWin) break;
    if (gField[j][j] == *computerAnswer)
     filling++;
    if (gField[j][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gcomputerWin = (!(0));
     ComputerMove(gField, computerAnswer, free, free);
    }
   }
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gcomputerWin) break;
    if (gField[3 - j-1][j] == *computerAnswer)
     filling++;
    if (gField[3 - j-1][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gcomputerWin = (!(0));
     ComputerMove(gField, computerAnswer, 3 - free - 1, free);
    }
   }
  }
 }
}

canonical_original_code:
void ChekingComputerWin(int gField[3][3], int *gcomputerWin, int *playerAnswer, int *computerAnswer)
{
 *gcomputerWin = (0);
 int i;
 for (i = 0; i < 3; i++)
 {
  if (*gcomputerWin) break;
  int j;
  int free = -1;
  int filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gcomputerWin) break;
   if (gField[i][j] == *computerAnswer)
    filling++;
   if (gField[i][j] == 0)
    free = j;
   if ((filling == 3 -1 )&&(free >= 0))
   {
    *gcomputerWin = (!(0));
    ComputerMove(gField, computerAnswer, i, free);
   }
  }
  free = -1;
  filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gcomputerWin) break;
   if (gField[j][i] == *computerAnswer)
    filling++;
   if (gField[j][i] == 0)
    free = j;
   if ((filling == 3 - 1)&&(free >= 0))
   {
    (*gcomputerWin) = (!(0));
    ComputerMove(gField, computerAnswer, free, i);
   }
  }
  if (i == 0)
  {
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gcomputerWin) break;
    if (gField[j][j] == *computerAnswer)
     filling++;
    if (gField[j][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gcomputerWin = (!(0));
     ComputerMove(gField, computerAnswer, free, free);
    }
   }
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gcomputerWin) break;
    if (gField[3 - j-1][j] == *computerAnswer)
     filling++;
    if (gField[3 - j-1][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gcomputerWin = (!(0));
     ComputerMove(gField, computerAnswer, 3 - free - 1, free);
    }
   }
  }
 }
}

variable_types:
gcomputerWin
int *


ClearField

decompiled_code:
void ClearField()
{
gField[0] = 0;
gField[1] = 0;
gField[2] = 0;
gField[3] = 0;
gField[4] = 0;
gField[5] = 0;
gField[6] = 0;
gField[7] = 0;
gField[8] = 0;
}

canonical_decompiled_code:
void func0()
{
gField[0] = 0;
gField[1] = 0;
gField[2] = 0;
gField[3] = 0;
gField[4] = 0;
gField[5] = 0;
gField[6] = 0;
gField[7] = 0;
gField[8] = 0;
}

original_code:
static void ClearField()
{
 int i,j;
 for(i = 0; i < 3; i++)
 {
  for(j = 0; j < 3; j++)
  {
   gField[i][j] = 0;
  }
 }
}

canonical_original_code:
static void ClearField()
{
 int i; int j;
 for(i = 0; i < 3; i++)
 {
  for(j = 0; j < 3; j++)
  {
   gField[i][j] = 0;
  }
 }
}


CellDenermination

decompiled_code:
__int64 __fastcall CellDenermination(int a1, int a2)
{
__int64 v2; // rcx
unsigned int v3; // esi

v2 = a2 / 100 + 3LL * (a1 / 100);
v3 = 0;
if ( !gField[v2] )
{
gField[v2] = playerAnswer;
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 v2; // rcx
unsigned int v3; // esi

v2 = a2 / 100 + 3LL * (a1 / 100);
v3 = 0;
if ( !gField[v2] )
{
gField[v2] = playerAnswer;
v3 = 1;
}
return v3;
}

original_code:
static gboolean CellDenermination(int x, int y)
{
 x /= 100;
 y /= 100;
 if (gField[x][y] == 0)
 {
  gField[x][y] = playerAnswer;
  return (!(0));
 }
 return (0);
}

canonical_original_code:
static int CellDenermination(int x, int y)
{
 x /= 100;
 y /= 100;
 if (gField[x][y] == 0)
 {
  gField[x][y] = playerAnswer;
  return (!(0));
 }
 return (0);
}

variable_types: x int

variable_types: y int


DeadHeat

decompiled_code:
_BOOL8 DeadHeat()
{
int *v0; // rdx
int v1; // eax
_BOOL8 result; // rax

v0 = gField;
v1 = 0;
do
{
v1 = v1 - ((*v0 == 0) - 1) - ((v0[1] == 0) - 1) - ((v0[2] == 0) - 1);
v0 += 3;
}
while ( v0 != (int *)(unsigned int)((_DWORD)gField + 36) );
result = v1 == 9;
gdeadHeat = result;
return result;
}

canonical_decompiled_code:
_BOOL8 func2()
{
int *v0; // rdx
int v1; // eax
_BOOL8 result; // rax

v0 = gField;
v1 = 0;
do
{
v1 = v1 - ((*v0 == 0) - 1) - ((v0[1] == 0) - 1) - ((v0[2] == 0) - 1);
v0 += 3;
}
while ( v0 != (int *)(unsigned int)((_DWORD)gField + 36) );
result = v1 == 9;
gdeadHeat = result;
return result;
}

original_code:
static void DeadHeat()
{
 int i,j;
 int filled = 0;
 for (i = 0; i < 3; i++)
 {
  for (j = 0; j < 3; j++)
  {
   if (gField[i][j] != 0)
    filled++;
  }
 }
 if (filled == (3*3))
  gdeadHeat = (!(0));
 else
  gdeadHeat = (0);
}

canonical_original_code:
static void DeadHeat()
{
 int i; int j;
 int filled = 0;
 for (i = 0; i < 3; i++)
 {
  for (j = 0; j < 3; j++)
  {
   if (gField[i][j] != 0)
    filled++;
  }
 }
 if (filled == (3*3))
  gdeadHeat = (!(0));
 else
  gdeadHeat = (0);
}

variable_types: filled int


ComputerStupidMove

decompiled_code:
__int64 ComputerStupidMove()
{
int v0; // ebx
int v1; // eax
__int64 result; // rax

do
{
v0 = rand() % 3;
v1 = rand() % 3;
}
while ( gField[3 * v0 + v1] );
result = 3LL * v0 + v1;
gField[result] = computerAnswer;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // ebx
int v1; // eax
__int64 result; // rax

do
{
v0 = rand() % 3;
v1 = rand() % 3;
}
while ( gField[3 * v0 + v1] );
result = 3LL * v0 + v1;
gField[result] = computerAnswer;
return result;
}

original_code:
static void ComputerStupidMove()
{
 int m,k;
 do
 {
  k = (rand()%3);
  m = (rand()%3);
 }
 while (gField[k][m] != 0);
 gField[k][m] = computerAnswer;
}

canonical_original_code:
static void ComputerStupidMove()
{
 int m; int k;
 do
 {
  k = (rand()%3);
  m = (rand()%3);
 }
 while (gField[k][m] != 0);
 gField[k][m] = computerAnswer;
}

variable_types: m int

variable_types: k int


usage

repo: kostelnik/jwmtools

decompiled_code:
void __noreturn usage()
{
fwrite("usage: slock [-v]\n", 1uLL, 0x12uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("usage: slock [-v]\n", 1uLL, 0x12uLL, stderr);
exit(1);
}

original_code:
static void
usage(void) {
 fprintf(stderr, "usage: slock [-v]\n");
 exit(1);
}

canonical_original_code:
static void usage() {
 fprintf(stderr, "usage: slock [-v]\n");
 exit(1);
}


die

decompiled_code:
void __noreturn die(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
exit(1);
}

original_code:
static void
die(const char *errstr, ...) {
 va_list ap;
 __builtin_va_start(ap,errstr);
 vfprintf(stderr, errstr, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
static void die(char *errstr, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,errstr);
 vfprintf(stderr, errstr, ap);
 __builtin_va_end(ap);
 exit(1);
}

variable_types:
errstr
char *