decompiled_code:
int __fastcall gpio_bb_set_pgc(char a1)
{
__int16 v1; // ax
__int16 v3; // [rsp+Ch] [rbp-Ch] BYREF
char v4; // [rsp+Eh] [rbp-Ah]
char v5; // [rsp+Fh] [rbp-9h]

v1 = *((_WORD *)&p + 1565);
v5 = a1;
v3 = v1;
v4 = 0;
return ioctl(fd, 0xC008B4CDuLL, &v3);
}

canonical_decompiled_code:
int __fastcall func6(char a1)
{
__int16 v1; // ax
__int16 v3; // [rsp+Ch] [rbp-Ch] BYREF
char v4; // [rsp+Eh] [rbp-Ah]
char v5; // [rsp+Fh] [rbp-9h]

v1 = *((_WORD *)&p + 1565);
v5 = a1;
v3 = v1;
v4 = 0;
return ioctl(fd, 0xC008B4CDuLL, &v3);
}

variable_types:
pgc
unsigned char


repo: GBert/openwrt-files

decompiled_code:
__int64 gpio_bb_get_pgd()
{
__int16 v1; // [rsp+Ch] [rbp-Ch] BYREF
__int16 v2; // [rsp+Eh] [rbp-Ah]

v1 = *((_WORD *)&p + 1567);
v2 = 1;
ioctl(fd, 0xC008B4CDuLL, &v1);
return HIBYTE(v2);
}

canonical_decompiled_code:
__int64 func7()
{
__int16 v1; // [rsp+Ch] [rbp-Ch] BYREF
__int16 v2; // [rsp+Eh] [rbp-Ah]

v1 = *((_WORD *)&p + 1567);
v2 = 1;
ioctl(fd, 0xC008B4CDuLL, &v1);
return HIBYTE(v2);
}

variable_types: struct gpio_bb_io { unsigned short pin; unsigned char dir; unsigned char bit; }

return_type: unsigned char


original_code:
void
gpio_bb_configure(void)
{
 struct gpio_bb_config config;
 config.clock_pin = p.pgc;
 config.clock_falling = p.clock_falling;
 config.msb_first = p.msb_first;
 config.data_pin_input = p.pgdi;
 config.data_pin_output = p.pgdo;
 config.clock_delay_low = p.sleep_low;
 config.clock_delay_high = p.sleep_high;
 config.lock = (p.bitrules & (0x00002000)) ? 1 : 0;
 ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((((180))) << (0 +8)) | (((206)) << 0) | ((((sizeof(struct gpio_bb_config *)))) << ((0 +8)+8))), &config);
}

canonical_original_code:
void gpio_bb_configure()
{
 struct gpio_bb_config config;
 config.clock_pin = p.pgc;
 config.clock_falling = p.clock_falling;
 config.msb_first = p.msb_first;
 config.data_pin_input = p.pgdi;
 config.data_pin_output = p.pgdo;
 config.clock_delay_low = p.sleep_low;
 config.clock_delay_high = p.sleep_high;
 config.lock = (p.bitrules & (0x00002000)) ? 1 : 0;
 ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((((180))) << (0 +8)) | (((206)) << 0) | ((((sizeof(struct gpio_bb_config *)))) << ((0 +8)+8))), &config);
}

variable_types: struct gpio_bb_config { unsigned short clock_pin; unsigned short data_pin_input; unsigned short data_pin_output; unsigned char clock_falling; unsigned char msb_first; unsigned char clock_delay_low; unsigned char clock_delay_high; unsigned char lock; }

return_type: void


decompiled_code:
__int64 __fastcall gpio_bb_shift_in(char a1)
{
char v2[2]; // [rsp+6h] [rbp-12h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h]

v2[1] = a1;
v2[0] = 1;
v3 = 0LL;
ioctl(fd, 0xC008B4CFuLL, v2);
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1)
{
char v2[2]; // [rsp+6h] [rbp-12h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h]

v2[1] = a1;
v2[0] = 1;
v3 = 0LL;
ioctl(fd, 0xC008B4CFuLL, v2);
return (unsigned int)v3;
}

canonical_original_code:
unsigned int gpio_bb_shift_in(unsigned char nbits)
{
 struct gpio_bb_shift shift = {1, nbits, 0};
 ioctl(fd, (((2U|1U) << (((0 +8)+8)+14)) | ((((180))) << (0 +8)) | (((207)) << 0) | ((((sizeof(struct gpio_bb_shift *)))) << ((0 +8)+8))), &shift);
 return (unsigned int)(shift.bits);
}

variable_types:
nbits
unsigned char

variable_types: struct gpio_bb_shift { unsigned char dir; unsigned char nbits; unsigned long bits; }

return_type: unsigned int


decompiled_code:
int __fastcall gpio_bb_shift_out(unsigned int a1, char a2)
{
char v3[2]; // [rsp+6h] [rbp-12h] BYREF
__int64 v4; // [rsp+8h] [rbp-10h]

v3[1] = a2;
v4 = a1;
v3[0] = 0;
return ioctl(fd, 0xC008B4CFuLL, v3);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, char a2)
{
char v3[2]; // [rsp+6h] [rbp-12h] BYREF
__int64 v4; // [rsp+8h] [rbp-10h]

v3[1] = a2;
v4 = a1;
v3[0] = 0;
return ioctl(fd, 0xC008B4CFuLL, v3);
}

canonical_original_code:
void gpio_bb_shift_out(unsigned int bits, unsigned char nbits)
{
 struct gpio_bb_shift shift = {0, nbits, (uint64_t)(bits)};
 ioctl(fd, (((2U|1U) << (((0 +8)+8)+14)) | ((((180))) << (0 +8)) | (((207)) << 0) | ((((sizeof(struct gpio_bb_shift *)))) << ((0 +8)+8))), &shift);
}

variable_types:
bits
unsigned int

user_defined_types: struct gpio_bb_shift { unsigned char dir; unsigned char nbits; unsigned long bits; }


decompiled_code:
__int64 gpio_bb_backend()
{
*((_QWORD *)&p + 395) = &gpio_bb_ops;
return (unsigned __int8)gpio_bb_ops;
}

canonical_decompiled_code:
__int64 func11()
{
*((_QWORD *)&p + 395) = &gpio_bb_ops;
return (unsigned __int8)gpio_bb_ops;
}

original_code:
uint8_t
gpio_bb_backend(void)
{
 p.io = &gpio_bb_ops;
 return p.io->type;
}

canonical_original_code:
unsigned char gpio_bb_backend()
{
 p.io = &gpio_bb_ops;
 return p.io->type;
}


decompiled_code:
int __fastcall gpio_bb_release_pin(__int16 a1)
{
__int16 v2[6]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
v2[1] = 1;
return ioctl(fd, 0xC008B4CDuLL, v2);
}

canonical_decompiled_code:
int __fastcall func12(__int16 a1)
{
__int16 v2[6]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
v2[1] = 1;
return ioctl(fd, 0xC008B4CDuLL, v2);
}

variable_types:
pin
unsigned short

user_defined_types: struct gpio_bb_io { unsigned short pin; unsigned char dir; unsigned char bit; }


decompiled_code:
int gpio_bb_release()
{
int result; // eax
__int16 v1; // di

result = *((_DWORD *)&p + 773);
if ( (result & 0x100) != 0 )
{
gpio_bb_release_pin(*((_WORD *)&p + 1566));
result = *((_DWORD *)&p + 773);
}
if ( (result & 0x200) != 0 )
{
gpio_bb_release_pin(*((_WORD *)&p + 1565));
result = *((_DWORD *)&p + 773);
}
if ( (result & 0x400) == 0 || (v1 = *((_WORD *)&p + 1568), v1 == -1) )
{
if ( (result & 0x800) == 0 )
return result;
return gpio_bb_release_pin(*((_WORD *)&p + 1564));
}
gpio_bb_release_pin(v1);
result = *((_DWORD *)&p + 773);
if ( (result & 0x800) != 0 )
return gpio_bb_release_pin(*((_WORD *)&p + 1564));
return result;
}

original_code:
void
gpio_bb_release(void)
{
 if (p.bitrules & (0x00000100)) {
  gpio_bb_release_pin(p.pgdo);
 }
 if (p.bitrules & (0x00000200)) {
  gpio_bb_release_pin(p.pgc);
 }
 if (p.bitrules & (0x00000400) && p.pgm != (uint16_t)(-1)) {
  gpio_bb_release_pin(p.pgm);
 }
 if (p.bitrules & (0x00000800)) {
  gpio_bb_release_pin(p.vpp);
 }
}

canonical_original_code:
void gpio_bb_release()
{
 if (p.bitrules & (0x00000100)) {
  gpio_bb_release_pin(p.pgdo);
 }
 if (p.bitrules & (0x00000200)) {
  gpio_bb_release_pin(p.pgc);
 }
 if (p.bitrules & (0x00000400) && p.pgm != (unsigned short)(-1)) {
  gpio_bb_release_pin(p.pgm);
 }
 if (p.bitrules & (0x00000800)) {
  gpio_bb_release_pin(p.vpp);
 }
}


resetuid

decompiled_code:
int resetuid()
{
__uid_t v0; // ebx
int result; // eax
__uid_t v2; // eax

v0 = getuid();
result = geteuid();
if ( v0 != result )
{
v2 = getuid();
result = setuid(v2);
if ( result < 0 )
{
printf("%s: fatal error: setuid failed\n", "resetuid");
result = io_exit(71LL);
}
}
return result;
}

canonical_decompiled_code:
int func0()
{
__uid_t v0; // ebx
int result; // eax
__uid_t v2; // eax

v0 = getuid();
result = geteuid();
if ( v0 != result )
{
v2 = getuid();
result = setuid(v2);
if ( result < 0 )
{
printf("%s: fatal error: setuid failed\n", "resetuid");
result = io_exit(71LL);
}
}
return result;
}

original_code:
static void
resetuid(void)
{
 if (getuid() != geteuid()) {
  if (setuid(getuid()) < 0) {
   printf("%s: fatal error: setuid failed\n", __func__);
   io_exit(71);
  }
 }
}

canonical_original_code:
static void resetuid()
{
 if (getuid() != geteuid()) {
  if (setuid(getuid()) < 0) {
   printf("%s: fatal error: setuid failed\n", __func__);
   io_exit(71);
  }
 }
}


decompiled_code:
int __fastcall test_pin(int a1, unsigned int a2)
{
puts("\nTEST VPP|PGD|PGC|PGM OUTPUT\n");
if ( a1 != 2 )
{
if ( a1 == 3 )
{
puts("PGM LOW [3 seconds]");
io_set_pgm(0LL);
if ( io_stop )
{
LABEL_18:
printf("PGM HIGH [%d seconds]\n", a2);
io_set_pgm(1LL);
if ( !io_stop )
sleep(a2);
puts("PGM LOW [3 seconds]");
io_set_pgm(0LL);
goto LABEL_8;
}
}
else if ( a1 == 1 )
{
puts("PGC LOW (ICSP 5) (D-SUB-9 RTS 7) [3 seconds]");
io_set_pgc(0LL);
if ( io_stop )
{
LABEL_14:
printf("PGC HIGH (ICSP 5) (D-SUB-9 RTS 7) [%d seconds]\n", a2);
io_set_pgc(1LL);
if ( !io_stop )
sleep(a2);
puts("PGC LOW (ICSP 5) (D-SUB-9 RTS 7) [3 seconds]");
io_set_pgc(0LL);
goto LABEL_8;
}
}
else
{
puts("VPP LOW (ICSP 1) (D-SUB-9 TX 3) [3 seconds]");
io_set_vpp(0LL);
if ( io_stop )
{
LABEL_5:
printf("VPP HIGH (ICSP 1) (D-SUB-9 TX 3) [%d seconds]\n", a2);
io_set_vpp(1LL);
if ( !io_stop )
sleep(a2);
puts("VPP LOW (ICSP 1) (D-SUB-9 TX 3) [3 seconds]");
io_set_vpp(0LL);
goto LABEL_8;
}
}
sleep(3u);
if ( a1 != 3 )
{
if ( a1 != 1 )
goto LABEL_5;
goto LABEL_14;
}
goto LABEL_18;
}
puts("PGD LOW (ICSP 4) (D-SUB-9 DTR 3) [3 seconds]");
io_set_pgd(0LL);
if ( !io_stop )
sleep(3u);
printf("PGD HIGH (ICSP 4) (D-SUB-9 DTR 3) [%d seconds]\n", a2);
io_set_pgd(1LL);
if ( !io_stop )
sleep(a2);
puts("PGD LOW (ICSP 4) (D-SUB-9 DTR 3) [3 seconds]");
io_set_pgd(0LL);
LABEL_8:
if ( !io_stop )
sleep(3u);
return puts("\nTEST DONE\n");
}

canonical_decompiled_code:
int __fastcall func1(int a1, unsigned int a2)
{
puts("\nTEST VPP|PGD|PGC|PGM OUTPUT\n");
if ( a1 != 2 )
{
if ( a1 == 3 )
{
puts("PGM LOW [3 seconds]");
io_set_pgm(0LL);
if ( io_stop )
{
LABEL_18:
printf("PGM HIGH [%d seconds]\n", a2);
io_set_pgm(1LL);
if ( !io_stop )
sleep(a2);
puts("PGM LOW [3 seconds]");
io_set_pgm(0LL);
goto LABEL_8;
}
}
else if ( a1 == 1 )
{
puts("PGC LOW (ICSP 5) (D-SUB-9 RTS 7) [3 seconds]");
io_set_pgc(0LL);
if ( io_stop )
{
LABEL_14:
printf("PGC HIGH (ICSP 5) (D-SUB-9 RTS 7) [%d seconds]\n", a2);
io_set_pgc(1LL);
if ( !io_stop )
sleep(a2);
puts("PGC LOW (ICSP 5) (D-SUB-9 RTS 7) [3 seconds]");
io_set_pgc(0LL);
goto LABEL_8;
}
}
else
{
puts("VPP LOW (ICSP 1) (D-SUB-9 TX 3) [3 seconds]");
io_set_vpp(0LL);
if ( io_stop )
{
LABEL_5:
printf("VPP HIGH (ICSP 1) (D-SUB-9 TX 3) [%d seconds]\n", a2);
io_set_vpp(1LL);
if ( !io_stop )
sleep(a2);
puts("VPP LOW (ICSP 1) (D-SUB-9 TX 3) [3 seconds]");
io_set_vpp(0LL);
goto LABEL_8;
}
}
sleep(3u);
if ( a1 != 3 )
{
if ( a1 != 1 )
goto LABEL_5;
goto LABEL_14;
}
goto LABEL_18;
}
puts("PGD LOW (ICSP 4) (D-SUB-9 DTR 3) [3 seconds]");
io_set_pgd(0LL);
if ( !io_stop )
sleep(3u);
printf("PGD HIGH (ICSP 4) (D-SUB-9 DTR 3) [%d seconds]\n", a2);
io_set_pgd(1LL);
if ( !io_stop )
sleep(a2);
puts("PGD LOW (ICSP 4) (D-SUB-9 DTR 3) [3 seconds]");
io_set_pgd(0LL);
LABEL_8:
if ( !io_stop )
sleep(3u);
return puts("\nTEST DONE\n");
}

original_code:
static void
test_pin(int pin, int t)
{
 printf("\nTEST VPP|PGD|PGC|PGM OUTPUT\n\n");
 switch (pin) {
 case 0:
  printf("VPP LOW  (ICSP 1) (D-SUB-9 TX 3) [3 seconds]\n");
  io_set_vpp((0x00));
  break;
 case 1:
  printf("PGC LOW  (ICSP 5) (D-SUB-9 RTS 7) [3 seconds]\n");
  io_set_pgc((0x00));
  break;
 case 2:
  printf("PGD LOW  (ICSP 4) (D-SUB-9 DTR 3) [3 seconds]\n");
  io_set_pgd((0x00));
  break;
 case 3:
  printf("PGM LOW  [3 seconds]\n");
  io_set_pgm((0x00));
  break;
 }
 if (!io_stop)
  sleep(3);
 switch (pin) {
 case 0:
  printf("VPP HIGH (ICSP 1) (D-SUB-9 TX 3) [%d seconds]\n", t);
  io_set_vpp((0x01));
  break;
 case 1:
  printf("PGC HIGH (ICSP 5) (D-SUB-9 RTS 7) [%d seconds]\n", t);
  io_set_pgc((0x01));
  break;
 case 2:
  printf("PGD HIGH (ICSP 4) (D-SUB-9 DTR 3) [%d seconds]\n", t);
  io_set_pgd((0x01));
  break;
 case 3:
  printf("PGM HIGH [%d seconds]\n", t);
  io_set_pgm((0x01));
  break;
 }
 if (!io_stop)
  sleep(t);
 switch (pin) {
 case 0:
  printf("VPP LOW  (ICSP 1) (D-SUB-9 TX 3) [3 seconds]\n");
  io_set_vpp((0x00));
  break;
 case 1:
  printf("PGC LOW  (ICSP 5) (D-SUB-9 RTS 7) [3 seconds]\n");
  io_set_pgc((0x00));
  break;
 case 2:
  printf("PGD LOW  (ICSP 4) (D-SUB-9 DTR 3) [3 seconds]\n");
  io_set_pgd((0x00));
  break;
 case 3:
  printf("PGM LOW  [3 seconds]\n");
  io_set_pgm((0x00));
  break;
 }
 if (!io_stop)
  sleep(3);
 printf("\nTEST DONE\n\n");
}

variable_types: pin int

variable_types: t int


decompiled_code:
int __fastcall test_in(int a1)
{
int v1; // ebx
unsigned __int8 v2; // al

v1 = a1;
puts("\nTEST PGD INPUT\n");
if ( a1 )
{
do
{
if ( io_stop )
break;
v2 = io_get_pgd();
printf("PGD IN: %d\n", v2);
sleep(1u);
--v1;
}
while ( v1 );
}
return puts("\nTEST DONE\n");
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int v1; // ebx
unsigned __int8 v2; // al

v1 = a1;
puts("\nTEST PGD INPUT\n");
if ( a1 )
{
do
{
if ( io_stop )
break;
v2 = io_get_pgd();
printf("PGD IN: %d\n", v2);
sleep(1u);
--v1;
}
while ( v1 );
}
return puts("\nTEST DONE\n");
}

original_code:
static void
test_in(int t)
{
 printf("\nTEST PGD INPUT\n\n");
 while (t-- && !io_stop) {
  printf("PGD IN: %d\n", io_get_pgd());
  sleep(1);
 }
 printf("\nTEST DONE\n\n");
}


decompiled_code:
int __fastcall test_dsub9(unsigned int seconds)
{
unsigned __int8 v1; // al
unsigned __int8 v2; // al
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al

puts("\nTEST D-SUB-9\n");
p[773] = 0;
printf("Tx SET (+VE) (D-SUB-9 3) [%d seconds] ", seconds);
fflush(stdout);
io_set_vpp(1LL);
if ( !io_stop )
sleep(seconds);
v1 = io_get_pgd();
printf("CTS IN: %d\n", v1);
printf("Tx CLR (-VE) (D-SUB-9 3) [%d seconds] ", seconds);
fflush(stdout);
io_set_vpp(0LL);
if ( !io_stop )
sleep(seconds);
v2 = io_get_pgd();
printf("CTS IN: %d\n\n", v2);
printf("DTR SET (+VE) (D-SUB-9 4) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgd(1LL);
if ( !io_stop )
sleep(seconds);
v3 = io_get_pgd();
printf("CTS IN: %d\n", v3);
printf("DTR CLR (-VE) (D-SUB-9 4) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgd(0LL);
if ( !io_stop )
sleep(seconds);
v4 = io_get_pgd();
printf("CTS IN: %d\n\n", v4);
printf("RTS SET (+VE) (D-SUB-9 7) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgc(1LL);
if ( !io_stop )
sleep(seconds);
v5 = io_get_pgd();
printf("CTS IN: %d\n", v5);
printf("RTS CLR (-VE) (D-SUB-9 7) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgc(0LL);
if ( !io_stop )
sleep(seconds);
v6 = io_get_pgd();
printf("CTS IN: %d\n\n", v6);
return puts("TEST DONE\n");
}

canonical_decompiled_code:
int __fastcall func3(unsigned int seconds)
{
unsigned __int8 v1; // al
unsigned __int8 v2; // al
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al

puts("\nTEST D-SUB-9\n");
p[773] = 0;
printf("Tx SET (+VE) (D-SUB-9 3) [%d seconds] ", seconds);
fflush(stdout);
io_set_vpp(1LL);
if ( !io_stop )
sleep(seconds);
v1 = io_get_pgd();
printf("CTS IN: %d\n", v1);
printf("Tx CLR (-VE) (D-SUB-9 3) [%d seconds] ", seconds);
fflush(stdout);
io_set_vpp(0LL);
if ( !io_stop )
sleep(seconds);
v2 = io_get_pgd();
printf("CTS IN: %d\n\n", v2);
printf("DTR SET (+VE) (D-SUB-9 4) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgd(1LL);
if ( !io_stop )
sleep(seconds);
v3 = io_get_pgd();
printf("CTS IN: %d\n", v3);
printf("DTR CLR (-VE) (D-SUB-9 4) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgd(0LL);
if ( !io_stop )
sleep(seconds);
v4 = io_get_pgd();
printf("CTS IN: %d\n\n", v4);
printf("RTS SET (+VE) (D-SUB-9 7) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgc(1LL);
if ( !io_stop )
sleep(seconds);
v5 = io_get_pgd();
printf("CTS IN: %d\n", v5);
printf("RTS CLR (-VE) (D-SUB-9 7) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgc(0LL);
if ( !io_stop )
sleep(seconds);
v6 = io_get_pgd();
printf("CTS IN: %d\n\n", v6);
return puts("TEST DONE\n");
}

original_code:
static void
test_dsub9(int t)
{
 printf("\nTEST D-SUB-9\n\n");
 p.bitrules = 0;
 printf("Tx  SET  (+VE) (D-SUB-9 3) [%d seconds] ", t);
 fflush(stdout);
 io_set_vpp((0x01));
 if (!io_stop)
  sleep(t);
 printf("CTS IN: %d\n", io_get_pgd());
 printf("Tx  CLR  (-VE) (D-SUB-9 3) [%d seconds] ", t);
 fflush(stdout);
 io_set_vpp((0x00));
 if (!io_stop)
  sleep(t);
 printf("CTS IN: %d\n\n", io_get_pgd());
 printf("DTR SET  (+VE) (D-SUB-9 4) [%d seconds] ", t);
 fflush(stdout);
 io_set_pgd((0x01));
 if (!io_stop)
  sleep(t);
 printf("CTS IN: %d\n", io_get_pgd());
 printf("DTR CLR  (-VE) (D-SUB-9 4) [%d seconds] ", t);
 fflush(stdout);
 io_set_pgd((0x00));
 if (!io_stop)
  sleep(t);
 printf("CTS IN: %d\n\n", io_get_pgd());
 printf("RTS SET  (+VE) (D-SUB-9 7) [%d seconds] ", t);
 fflush(stdout);
 io_set_pgc((0x01));
 if (!io_stop)
  sleep(t);
 printf("CTS IN: %d\n", io_get_pgd());
 printf("RTS CLR  (-VE) (D-SUB-9 7) [%d seconds] ", t);
 fflush(stdout);
 io_set_pgc((0x00));
 if (!io_stop)
  sleep(t);
 printf("CTS IN: %d\n\n", io_get_pgd());
 printf("TEST DONE\n\n");
}


decompiled_code:
int __fastcall test_icsp(unsigned int seconds)
{
unsigned __int8 v1; // al
unsigned __int8 v2; // al
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al

puts("\nTEST ICSP CONNECTOR\n");
printf("VPP LOW (0V) (ICSP 1) [%d seconds] ", seconds);
fflush(stdout);
io_set_vpp(0LL);
if ( !io_stop )
sleep(seconds);
v1 = io_get_pgd();
printf("PGD IN: %d\n", v1);
printf("VPP HIGH (12V) (ICSP 1) [%d seconds] ", seconds);
fflush(stdout);
io_set_vpp(1LL);
if ( !io_stop )
sleep(seconds);
v2 = io_get_pgd();
printf("PGD IN: %d\n\n", v2);
printf("PGD LOW (0V) (ICSP 4) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgd(0LL);
if ( !io_stop )
sleep(seconds);
v3 = io_get_pgd();
printf("PGD IN: %d\n", v3);
printf("PGD HIGH (5V) (ICSP 4) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgd(1LL);
if ( !io_stop )
sleep(seconds);
v4 = io_get_pgd();
printf("PGD IN: %d\n\n", v4);
printf("PGC LOW (0V) (ICSP 5) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgc(0LL);
if ( !io_stop )
sleep(seconds);
v5 = io_get_pgd();
printf("PGD IN: %d\n", v5);
printf("PGC HIGH (5V) (ICSP 5) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgc(1LL);
if ( !io_stop )
sleep(seconds);
v6 = io_get_pgd();
printf("PGD IN: %d\n\n", v6);
return puts("TEST DONE\n");
}

canonical_decompiled_code:
int __fastcall func4(unsigned int seconds)
{
unsigned __int8 v1; // al
unsigned __int8 v2; // al
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al

puts("\nTEST ICSP CONNECTOR\n");
printf("VPP LOW (0V) (ICSP 1) [%d seconds] ", seconds);
fflush(stdout);
io_set_vpp(0LL);
if ( !io_stop )
sleep(seconds);
v1 = io_get_pgd();
printf("PGD IN: %d\n", v1);
printf("VPP HIGH (12V) (ICSP 1) [%d seconds] ", seconds);
fflush(stdout);
io_set_vpp(1LL);
if ( !io_stop )
sleep(seconds);
v2 = io_get_pgd();
printf("PGD IN: %d\n\n", v2);
printf("PGD LOW (0V) (ICSP 4) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgd(0LL);
if ( !io_stop )
sleep(seconds);
v3 = io_get_pgd();
printf("PGD IN: %d\n", v3);
printf("PGD HIGH (5V) (ICSP 4) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgd(1LL);
if ( !io_stop )
sleep(seconds);
v4 = io_get_pgd();
printf("PGD IN: %d\n\n", v4);
printf("PGC LOW (0V) (ICSP 5) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgc(0LL);
if ( !io_stop )
sleep(seconds);
v5 = io_get_pgd();
printf("PGD IN: %d\n", v5);
printf("PGC HIGH (5V) (ICSP 5) [%d seconds] ", seconds);
fflush(stdout);
io_set_pgc(1LL);
if ( !io_stop )
sleep(seconds);
v6 = io_get_pgd();
printf("PGD IN: %d\n\n", v6);
return puts("TEST DONE\n");
}

original_code:
static void
test_icsp(int t)
{
 printf("\nTEST ICSP CONNECTOR\n\n");
 printf("VPP LOW  (0V)  (ICSP 1) [%d seconds] ", t);
 fflush(stdout);
 io_set_vpp((0x00));
 if (!io_stop)
  sleep(t);
 printf("PGD IN: %d\n", io_get_pgd());
 printf("VPP HIGH (12V) (ICSP 1) [%d seconds] ", t);
 fflush(stdout);
 io_set_vpp((0x01));
 if (!io_stop)
  sleep(t);
 printf("PGD IN: %d\n\n", io_get_pgd());
 printf("PGD LOW  (0V)  (ICSP 4) [%d seconds] ", t);
 fflush(stdout);
 io_set_pgd((0x00));
 if (!io_stop)
  sleep(t);
 printf("PGD IN: %d\n", io_get_pgd());
 printf("PGD HIGH (5V)  (ICSP 4) [%d seconds] ", t);
 fflush(stdout);
 io_set_pgd((0x01));
 if (!io_stop)
  sleep(t);
 printf("PGD IN: %d\n\n", io_get_pgd());
 printf("PGC LOW  (0V)  (ICSP 5) [%d seconds] ", t);
 fflush(stdout);
 io_set_pgc((0x00));
 if (!io_stop)
  sleep(t);
 printf("PGD IN: %d\n", io_get_pgd());
 printf("PGC HIGH (5V)  (ICSP 5) [%d seconds] ", t);
 fflush(stdout);
 io_set_pgc((0x01));
 if (!io_stop)
  sleep(t);
 printf("PGD IN: %d\n\n", io_get_pgd());
 printf("TEST DONE\n\n");
}


decompiled_code:
int __fastcall test_toggle(unsigned int a1)
{
puts("\nTEST CLOCK PGC/RTS(7) [CTRL-C TO STOP]\n");
while ( !io_stop )
{
io_set_pgc(1LL);
io_usleep(a1);
io_set_pgc(0LL);
io_usleep(a1);
}
return puts("\nTEST DONE\n");
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1)
{
puts("\nTEST CLOCK PGC/RTS(7) [CTRL-C TO STOP]\n");
while ( !io_stop )
{
io_set_pgc(1LL);
io_usleep(a1);
io_set_pgc(0LL);
io_usleep(a1);
}
return puts("\nTEST DONE\n");
}

original_code:
static void
test_toggle(int t)
{
 printf("\nTEST CLOCK PGC/RTS(7) [CTRL-C TO STOP]\n\n");
 while (!io_stop) {
  io_set_pgc((0x01));
  io_usleep(t);
  io_set_pgc((0x00));
  io_usleep(t);
 }
 printf("\nTEST DONE\n\n");
}


decompiled_code:
int __fastcall test_debug(unsigned int a1)
{
int v1; // er13
unsigned __int8 v2; // bl
int v3; // ebp
__int64 v5; // rax
__int128 v6; // [rsp+0h] [rbp-228h] BYREF
char v7[496]; // [rsp+10h] [rbp-218h] BYREF

v1 = 0;
v6 = 0LL;
memset(v7, 0, sizeof(v7));
puts("\nTEST 16F627 debug.asm [CTRL-C TO STOP]\n");
io_data_input();
if ( !io_stop )
{
while ( 1 )
{
io_set_pgc(0LL);
while ( (unsigned __int8)io_get_pgd() != 1 && !io_stop )
io_usleep(1LL);
io_set_pgc(1LL);
while ( 1 )
{
v2 = io_get_pgd();
if ( !v2 )
{
v3 = 8;
goto LABEL_11;
}
if ( io_stop )
break;
io_usleep(1LL);
}
v3 = 8;
v2 = 0;
do
{
LABEL_11:
v2 >>= 1;
io_set_pgc(0LL);
io_usleep(a1);
if ( (unsigned __int8)io_get_pgd() )
v2 |= 0x80u;
io_set_pgc(1LL);
io_usleep(a1);
--v3;
}
while ( v3 );
if ( (unsigned __int8)(v2 - 32) <= 0x5Eu )
break;
printf("%s: read byte: %02X %c\n", "test_debug", v2, 46LL);
if ( v2 != 3 )
goto LABEL_22;
if ( v1 > 1 && (_BYTE)v6 == 2 )
{
*((_BYTE *)&v6 + v1) = 0;
v1 = 0;
printf("%s: read line: %s", "test_debug", (const char *)&v6 + 1);
}
else
{
v1 = 0;
}
LABEL_19:
if ( io_stop )
return puts("\nTEST DONE\n");
}
printf("%s: read byte: %02X %c\n", "test_debug", v2, v2);
LABEL_22:
if ( v1 <= 510 )
{
v5 = v1++;
*((_BYTE *)&v6 + v5) = v2;
}
goto LABEL_19;
}
return puts("\nTEST DONE\n");
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1)
{
int v1; // er13
unsigned __int8 v2; // bl
int v3; // ebp
__int64 v5; // rax
__int128 v6; // [rsp+0h] [rbp-228h] BYREF
char v7[496]; // [rsp+10h] [rbp-218h] BYREF

v1 = 0;
v6 = 0LL;
memset(v7, 0, sizeof(v7));
puts("\nTEST 16F627 debug.asm [CTRL-C TO STOP]\n");
io_data_input();
if ( !io_stop )
{
while ( 1 )
{
io_set_pgc(0LL);
while ( (unsigned __int8)io_get_pgd() != 1 && !io_stop )
io_usleep(1LL);
io_set_pgc(1LL);
while ( 1 )
{
v2 = io_get_pgd();
if ( !v2 )
{
v3 = 8;
goto LABEL_11;
}
if ( io_stop )
break;
io_usleep(1LL);
}
v3 = 8;
v2 = 0;
do
{
LABEL_11:
v2 >>= 1;
io_set_pgc(0LL);
io_usleep(a1);
if ( (unsigned __int8)io_get_pgd() )
v2 |= 0x80u;
io_set_pgc(1LL);
io_usleep(a1);
--v3;
}
while ( v3 );
if ( (unsigned __int8)(v2 - 32) <= 0x5Eu )
break;
printf("%s: read byte: %02X %c\n", "test_debug", v2, 46LL);
if ( v2 != 3 )
goto LABEL_22;
if ( v1 > 1 && (_BYTE)v6 == 2 )
{
*((_BYTE *)&v6 + v1) = 0;
v1 = 0;
printf("%s: read line: %s", "test_debug", (const char *)&v6 + 1);
}
else
{
v1 = 0;
}
LABEL_19:
if ( io_stop )
return puts("\nTEST DONE\n");
}
printf("%s: read byte: %02X %c\n", "test_debug", v2, v2);
LABEL_22:
if ( v1 <= 510 )
{
v5 = v1++;
*((_BYTE *)&v6 + v5) = v2;
}
goto LABEL_19;
}
return puts("\nTEST DONE\n");
}

original_code:
static void
test_debug(int t)
{
 int i, j = 0;
 uint8_t c;
 uint8_t line[(512)] = {0};
 printf("\nTEST 16F627 debug.asm [CTRL-C TO STOP]\n\n");
 io_data_input();
 while (!io_stop) {
  io_set_pgc((0x00));
  while (io_get_pgd() != (0x01) && !io_stop)
   io_usleep(1);
  io_set_pgc((0x01));
  while (io_get_pgd() != (0x00) && !io_stop)
   io_usleep(1);
  c = 0;
  for (i = 0; i < 8; i++) {
   io_set_pgc((0x00));
   io_usleep(t);
   c = c >> 1;
   if (io_get_pgd())
    c |= 0x80;
   io_set_pgc((0x01));
   io_usleep(t);
  }
  printf("%s: read byte: %02X %c\n", __func__, c, ((((c) >= ' ' && (c) < 127) ? (c) : ('.'))));
  if (c == 0x03) {
   if (j > 1 && line[0] == 0x02) {
    line[j] = '\0';
    printf("%s: read line: %s", __func__,
     &line[1]);
   }
   j = 0;
  }
  else if (j < ((512) - 1))
   line[j++] = c;
 }
 printf("\nTEST DONE\n\n");
}

canonical_original_code:
static void test_debug(int t)
{
 int i; int j = 0;
 unsigned char c;
 unsigned char line[-1] = {0};
 printf("\nTEST 16F627 debug.asm [CTRL-C TO STOP]\n\n");
 io_data_input();
 while (!io_stop) {
  io_set_pgc((0x00));
  while (io_get_pgd() != (0x01) && !io_stop)
   io_usleep(1);
  io_set_pgc((0x01));
  while (io_get_pgd() != (0x00) && !io_stop)
   io_usleep(1);
  c = 0;
  for (i = 0; i < 8; i++) {
   io_set_pgc((0x00));
   io_usleep(t);
   c = c >> 1;
   if (io_get_pgd())
    c |= 0x80;
   io_set_pgc((0x01));
   io_usleep(t);
  }
  printf("%s: read byte: %02X %c\n", __func__, c, ((((c) >= ' ' && (c) < 127) ? (c) : ('.'))));
  if (c == 0x03) {
   if (j > 1 && line[0] == 0x02) {
    line[j] = '\0';
    printf("%s: read line: %s", __func__,
     &line[1]);
   }
   j = 0;
  }
  else if (j < ((512) - 1))
   line[j++] = c;
 }
 printf("\nTEST DONE\n\n");
}

variable_types: i int

variable_types: j int

variable_types:
c
unsigned char

variable_types:
line
unsigned char [-1]


decompiled_code:
int __fastcall test_icspio(unsigned int a1)
{
char v1; // r12
unsigned int v2; // ebx
const char *v4; // rax
char v5[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v1 = 0;
puts("\nTEST ICSPIO [CTRL-C TO STOP]\n");
io_set_vpp(0LL);
io_usleep(10000LL);
io_set_vpp(1LL);
io_usleep(10000LL);
while ( !io_stop )
{
v5[0] = 1;
v5[1] = v1;
v2 = icspio_command(a1, 2 * a1, v5, 1LL, 0LL, 0LL);
if ( !v2 )
{
v2 = icspio_switch(a1);
if ( !v2 )
{
++v1;
v2 = icspio_lasterror(a1);
if ( !v2 )
continue;
}
}
v4 = (const char *)icspio_err(v2);
fprintf(stderr, "%s: error: %s [0x%02X]\n", "test_icspio", v4, v2);
return puts("\nTEST DONE\n");
}
return puts("\nTEST DONE\n");
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
char v1; // r12
unsigned int v2; // ebx
const char *v4; // rax
char v5[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v1 = 0;
puts("\nTEST ICSPIO [CTRL-C TO STOP]\n");
io_set_vpp(0LL);
io_usleep(10000LL);
io_set_vpp(1LL);
io_usleep(10000LL);
while ( !io_stop )
{
v5[0] = 1;
v5[1] = v1;
v2 = icspio_command(a1, 2 * a1, v5, 1LL, 0LL, 0LL);
if ( !v2 )
{
v2 = icspio_switch(a1);
if ( !v2 )
{
++v1;
v2 = icspio_lasterror(a1);
if ( !v2 )
continue;
}
}
v4 = (const char *)icspio_err(v2);
fprintf(stderr, "%s: error: %s [0x%02X]\n", "test_icspio", v4, v2);
return puts("\nTEST DONE\n");
}
return puts("\nTEST DONE\n");
}

original_code:
static void
test_icspio(int t)
{
 int err;
 uint8_t cmd[2];
 uint32_t ld = 0;
 printf("\nTEST ICSPIO [CTRL-C TO STOP]\n\n");
 io_set_vpp((0x00));
 io_usleep(10000);
 io_set_vpp((0x01));
 io_usleep(10000);
 while (!io_stop) {
  cmd[0] = (0x01);
  cmd[1] = ld++;
  err = icspio_command(t, t << 1, cmd, 1, ((void *)0), 0);
  if (err != (0)) {
   fprintf(stderr, "%s: error: %s [0x%02X]\n",
    __func__, icspio_err(err), err);
   break;
  }
  err = icspio_switch(t);
  if (err != (0)) {
   fprintf(stderr, "%s: error: %s [0x%02X]\n",
    __func__, icspio_err(err), err);
   break;
  }
  err = icspio_lasterror(t);
  if (err != (0)) {
   fprintf(stderr, "%s: error: %s [0x%02X]\n",
    __func__, icspio_err(err), err);
   break;
  }
 }
 printf("\nTEST DONE\n\n");
}

canonical_original_code:
static void test_icspio(int t)
{
 int err;
 unsigned char cmd[2];
 unsigned int ld = 0;
 printf("\nTEST ICSPIO [CTRL-C TO STOP]\n\n");
 io_set_vpp((0x00));
 io_usleep(10000);
 io_set_vpp((0x01));
 io_usleep(10000);
 while (!io_stop) {
  cmd[0] = (0x01);
  cmd[1] = ld++;
  err = icspio_command(t, t << 1, cmd, 1, ((void *)0), 0);
  if (err != (0)) {
   fprintf(stderr, "%s: error: %s [0x%02X]\n",
    __func__, icspio_err(err), err);
   break;
  }
  err = icspio_switch(t);
  if (err != (0)) {
   fprintf(stderr, "%s: error: %s [0x%02X]\n",
    __func__, icspio_err(err), err);
   break;
  }
  err = icspio_lasterror(t);
  if (err != (0)) {
   fprintf(stderr, "%s: error: %s [0x%02X]\n",
    __func__, icspio_err(err), err);
   break;
  }
 }
 printf("\nTEST DONE\n\n");
}

variable_types: err int

variable_types:
cmd
unsigned char [2]

variable_types:
ld
unsigned int


mystrcasestr

decompiled_code:
char *__fastcall mystrcasestr(char *s, char *a2)
{
char *v2; // rbp
int v3; // ebx
int v4; // er14
__int64 v5; // r13
__int64 v6; // r15
int v7; // ebx
int v9; // eax
int v10; // [rsp+0h] [rbp-48h]
int v11; // [rsp+4h] [rbp-44h]

v2 = s;
v3 = strlen(a2);
v10 = v3;
v11 = strlen(s) - v3;
if ( v11 < 0 )
return 0LL;
v4 = 0;
v5 = (unsigned int)(v3 - 1) + 2LL;
while ( 1 )
{
v6 = 1LL;
if ( v10 > 0 )
{
while ( 1 )
{
v7 = tolower(v2[v6 - 1]);
if ( v7 != tolower(a2[v6 - 1]) )
goto LABEL_7;
v9 = v6++;
if ( v6 == v5 )
goto LABEL_9;
}
}
v9 = 0;
LABEL_9:
if ( v10 == v9 )
return &s[v4];
LABEL_7:
++v4;
++v2;
if ( v11 < v4 )
return 0LL;
}
}

canonical_decompiled_code:
char *__fastcall func0(char *s, char *a2)
{
char *v2; // rbp
int v3; // ebx
int v4; // er14
__int64 v5; // r13
__int64 v6; // r15
int v7; // ebx
int v9; // eax
int v10; // [rsp+0h] [rbp-48h]
int v11; // [rsp+4h] [rbp-44h]

v2 = s;
v3 = strlen(a2);
v10 = v3;
v11 = strlen(s) - v3;
if ( v11 < 0 )
return 0LL;
v4 = 0;
v5 = (unsigned int)(v3 - 1) + 2LL;
while ( 1 )
{
v6 = 1LL;
if ( v10 > 0 )
{
while ( 1 )
{
v7 = tolower(v2[v6 - 1]);
if ( v7 != tolower(a2[v6 - 1]) )
goto LABEL_7;
v9 = v6++;
if ( v6 == v5 )
goto LABEL_9;
}
}
v9 = 0;
LABEL_9:
if ( v10 == v9 )
return &s[v4];
LABEL_7:
++v4;
++v2;
if ( v11 < v4 )
return 0LL;
}
}

original_code:
const char *
mystrcasestr(const char *haystack, const char *needle)
{
 int i, j;
 int nlen = strlen(needle);
 int hlen = strlen(haystack) - nlen;
 for (i = 0; i <= hlen; i++) {
  for (j = 0; j < nlen; j++) {
   if (tolower((int)haystack[i + j]) != tolower((int)needle[j]))
    break;
  }
  if (j == nlen) {
   return &haystack[i];
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *mystrcasestr(char *haystack, char *needle)
{
 int i; int j;
 int nlen = strlen(needle);
 int hlen = strlen(haystack) - nlen;
 for (i = 0; i <= hlen; i++) {
  for (j = 0; j < nlen; j++) {
   if (tolower((int)haystack[i + j]) != tolower((int)needle[j]))
    break;
  }
  if (j == nlen) {
   return &haystack[i];
  }
 }
 return ((void *)0);
}

variable_types:
haystack
char *

variable_types:
needle
char *

variable_types: nlen int

variable_types: hlen int

return_type: char *


decompiled_code:
__int64 __fastcall os_semaphore_create(__int64 a1)
{
*(_DWORD *)(a1 + 88) = 0;
if ( pthread_mutex_init((pthread_mutex_t *)a1, 0LL) == -1 || pthread_cond_init((pthread_cond_t *)(a1 + 40), 0LL) == -1 )
exit(-1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
*(_DWORD *)(a1 + 88) = 0;
if ( pthread_mutex_init((pthread_mutex_t *)a1, 0LL) == -1 || pthread_cond_init((pthread_cond_t *)(a1 + 40), 0LL) == -1 )
exit(-1);
return 1LL;
}

original_code:
int
os_semaphore_create(
    os_semaphore_t* os_semaphore
)
{
   os_semaphore->v = 0;
 if (-1 == pthread_mutex_init(&(os_semaphore->mutex), ((void *)0)))
  exit(-1);
 if (-1 == pthread_cond_init(&(os_semaphore->cond), ((void *)0)))
  exit(-1);
 return 1;
}

canonical_original_code:
int os_semaphore_create(struct os_semaphore_struct *os_semaphore)
{
   os_semaphore->v = 0;
 if (-1 == pthread_mutex_init(&(os_semaphore->mutex), ((void *)0)))
  exit(-1);
 if (-1 == pthread_cond_init(&(os_semaphore->cond), ((void *)0)))
  exit(-1);
 return 1;
}

variable_types: struct os_semaphore_struct { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int v; } *

return_type: int

user_defined_types: struct os_semaphore_struct { union pthread_mutex_t mutex; union pthread_cond_t cond; int v; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall os_semaphore_free(__int64 a1)
{
if ( pthread_mutex_destroy((pthread_mutex_t *)a1) == -1 || pthread_cond_destroy((pthread_cond_t *)(a1 + 40)) == -1 )
exit(-1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( pthread_mutex_destroy((pthread_mutex_t *)a1) == -1 || pthread_cond_destroy((pthread_cond_t *)(a1 + 40)) == -1 )
exit(-1);
return 1LL;
}

original_code:
int
os_semaphore_free(
    os_semaphore_t* os_semaphore
)
{
 if (-1 == pthread_mutex_destroy(&(os_semaphore->mutex)))
  exit(-1);
 if (-1 == pthread_cond_destroy(&(os_semaphore->cond)))
  exit(-1);
 return 1;
}

canonical_original_code:
int os_semaphore_free(struct os_semaphore_struct *os_semaphore)
{
 if (-1 == pthread_mutex_destroy(&(os_semaphore->mutex)))
  exit(-1);
 if (-1 == pthread_cond_destroy(&(os_semaphore->cond)))
  exit(-1);
 return 1;
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall os_semaphore_p(pthread_mutex_t *mutex)
{
int v1; // eax

if ( pthread_mutex_lock(mutex) == -1 )
goto LABEL_7;
while ( 1 )
{
v1 = mutex[2].__owner;
if ( v1 > 0 )
break;
if ( pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex) == -1 )
goto LABEL_7;
}
mutex[2].__owner = v1 - 1;
if ( pthread_mutex_unlock(mutex) == -1 )
LABEL_7:
exit(-1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(pthread_mutex_t *mutex)
{
int v1; // eax

if ( pthread_mutex_lock(mutex) == -1 )
goto LABEL_7;
while ( 1 )
{
v1 = mutex[2].__owner;
if ( v1 > 0 )
break;
if ( pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex) == -1 )
goto LABEL_7;
}
mutex[2].__owner = v1 - 1;
if ( pthread_mutex_unlock(mutex) == -1 )
LABEL_7:
exit(-1);
return 1LL;
}

original_code:
int
os_semaphore_p(
    os_semaphore_t* os_semaphore
)
{
 if (-1 == pthread_mutex_lock(&(os_semaphore->mutex)))
  exit(-1);
    while (os_semaphore->v <= 0)
    {
  if (-1 == pthread_cond_wait(&(os_semaphore->cond), &(os_semaphore->mutex)))
    exit(-1);
    }
    (os_semaphore->v)--;
 if (-1 == pthread_mutex_unlock(&(os_semaphore->mutex)))
  exit(-1);
 return 1;
}

canonical_original_code:
int os_semaphore_p(struct os_semaphore_struct *os_semaphore)
{
 if (-1 == pthread_mutex_lock(&(os_semaphore->mutex)))
  exit(-1);
    while (os_semaphore->v <= 0)
    {
  if (-1 == pthread_cond_wait(&(os_semaphore->cond), &(os_semaphore->mutex)))
    exit(-1);
    }
    (os_semaphore->v)--;
 if (-1 == pthread_mutex_unlock(&(os_semaphore->mutex)))
  exit(-1);
 return 1;
}


decompiled_code:
__int64 __fastcall os_semaphore_v(pthread_mutex_t *mutex)
{
if ( pthread_mutex_lock(mutex) == -1
|| (++mutex[2].__owner, pthread_mutex_unlock(mutex) == -1)
|| pthread_cond_signal((pthread_cond_t *)&mutex[1]) == -1 )
{
exit(-1);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(pthread_mutex_t *mutex)
{
if ( pthread_mutex_lock(mutex) == -1
|| (++mutex[2].__owner, pthread_mutex_unlock(mutex) == -1)
|| pthread_cond_signal((pthread_cond_t *)&mutex[1]) == -1 )
{
exit(-1);
}
return 1LL;
}

original_code:
int
os_semaphore_v(
    os_semaphore_t* os_semaphore
)
{
 if (-1 == pthread_mutex_lock(&(os_semaphore->mutex)))
  exit(-1);
    (os_semaphore->v)++;
 if (-1 == pthread_mutex_unlock(&(os_semaphore->mutex)))
  exit(-1);
 if (-1 == pthread_cond_signal(&(os_semaphore->cond)))
  exit(-1);
 return 1;
}

canonical_original_code:
int os_semaphore_v(struct os_semaphore_struct *os_semaphore)
{
 if (-1 == pthread_mutex_lock(&(os_semaphore->mutex)))
  exit(-1);
    (os_semaphore->v)++;
 if (-1 == pthread_mutex_unlock(&(os_semaphore->mutex)))
  exit(-1);
 if (-1 == pthread_cond_signal(&(os_semaphore->cond)))
  exit(-1);
 return 1;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
char v5[120]; // [rsp+0h] [rbp-78h] BYREF

__isoc99_scanf();
intialize_opcodes("%s", v5);
v3 = search(v5);
printf("%d\n", v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
char v5[120]; // [rsp+0h] [rbp-78h] BYREF

__isoc99_scanf();
func7("%s", v5);
v3 = func8(v5);
printf("%d\n", v3);
return 0;
}

original_code:
int main(int argc, char *argv)
{
    char str[100];
    scanf("%s", str);
    intialize_opcodes();
    printf("%d\n", search(str));
}

variable_types: argc int

variable_types:
argv
char *

variable_types:
str
char [100]


search

decompiled_code:
__int64 __fastcall search(char *s2)
{
signed int v1; // ebp
int v2; // ebx
unsigned int v3; // er12
int v4; // eax

v1 = 0;
v2 = 28;
while ( 1 )
{
v3 = (v1 + v2) >> 1;
v4 = strcmp(&opcodes[20 * v3], s2);
if ( !v4 )
break;
if ( v4 >= 0 )
{
v2 = v3 - 1;
if ( (int)(v3 - 1) < v1 )
return (unsigned int)-1;
}
else
{
v1 = v3 + 1;
if ( v2 < (int)(v3 + 1) )
return (unsigned int)-1;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s2)
{
signed int v1; // ebp
int v2; // ebx
unsigned int v3; // er12
int v4; // eax

v1 = 0;
v2 = 28;
while ( 1 )
{
v3 = (v1 + v2) >> 1;
v4 = strcmp(&opcodes[20 * v3], s2);
if ( !v4 )
break;
if ( v4 >= 0 )
{
v2 = v3 - 1;
if ( (int)(v3 - 1) < v1 )
return (unsigned int)-1;
}
else
{
v1 = v3 + 1;
if ( v2 < (int)(v3 + 1) )
return (unsigned int)-1;
}
}
return v3;
}

original_code:
int search(char *code)
{
    int start = 0, end = 28, middle, cmp;
    while(start <= end)
    {
        middle = (start + end) / 2;
        cmp = strcmp(opcodes[middle].code, code);
        if(cmp == 0)
        {
            return middle;
        }
        if(cmp < 0)
        {
            start = middle + 1;
        }
        else
        {
            end = middle - 1;
        }
    }
    return -1;
}

canonical_original_code:
int search(char *code)
{
    int start = 0; int end = 28; int middle; int cmp;
    while(start <= end)
    {
        middle = (start + end) / 2;
        cmp = strcmp(opcodes[middle].code, code);
        if(cmp == 0)
        {
            return middle;
        }
        if(cmp < 0)
        {
            start = middle + 1;
        }
        else
        {
            end = middle - 1;
        }
    }
    return -1;
}

variable_types:
code
char *

variable_types: start int

variable_types: end int

variable_types: middle int

variable_types: cmp int


decompiled_code:
__int64 validate_format()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 0LL;
}

original_code:
int validate_format(opcode code, char *command)
{
    return 0;
}

canonical_original_code:
int validate_format(struct opcode code, char *command)
{
    return 0;
}

variable_types: struct opcode { char code[10]; char format[10]; }

variable_types:
command
char *


mystrlen

decompiled_code:
__int64 __fastcall mystrlen(__int64 a1)
{
const unsigned __int16 **v1; // rax
__int64 i; // r8
__int64 v3; // rdx

if ( !a1 )
return 0LL;
v1 = _ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v3 = *(char *)(a1 + i);
if ( ((*v1)[v3] & 0x4000) == 0 && (unsigned __int8)(v3 - 9) > 1u )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
const unsigned __int16 **v1; // rax
__int64 i; // r8
__int64 v3; // rdx

if ( !a1 )
return 0LL;
v1 = _ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v3 = *(char *)(a1 + i);
if ( ((*v1)[v3] & 0x4000) == 0 && (unsigned __int8)(v3 - 9) > 1u )
break;
}
return i;
}

original_code:
size_t mystrlen ( char const*const src)
{
    size_t dsize=0;
    if (src==((void *)0))
        return 0L;
    while(1)
    {
        char const c=src[dsize];
        if (!(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISprint)||c=='\t'||c=='\n'))
        {
            break;
        }
        dsize++;
    }
    return dsize;
}

canonical_original_code:
unsigned long mystrlen(char *src)
{
    unsigned long dsize = 0;
    if (src==((void *)0))
        return 0L;
    while(1)
    {
        char c = src[dsize];
        if (!(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISprint)||c=='\t'||c=='\n'))
        {
            break;
        }
        dsize++;
    }
    return dsize;
}

variable_types:
src
char *

variable_types:
dsize
unsigned long

variable_types: c char

return_type: unsigned long


mystrcpy

decompiled_code:
char *__fastcall mystrcpy(char *dest, char *src, size_t n)
{
char *result; // rax

if ( src == 0LL || n == 0 || !dest )
return 0LL;
if ( n - 1 > strlen(src) )
return strncpy(dest, src, n);
result = (char *)memcpy(dest, src, n - 1);
dest[n - 1] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *dest, char *src, size_t n)
{
char *result; // rax

if ( src == 0LL || n == 0 || !dest )
return 0LL;
if ( n - 1 > strlen(src) )
return strncpy(dest, src, n);
result = (char *)memcpy(dest, src, n - 1);
dest[n - 1] = 0;
return result;
}

original_code:
char *mystrcpy (char *const des
                ,char const *const src
                ,size_t const dsize)
{
    char *s_out = ((void *)0);
    if (des != ((void *)0)
        && dsize != 0
        && src != ((void *)0))
    {
        size_t const len = strlen (src);
        if (len < dsize - 1)
        {
            strncpy (des, src, dsize);
        }
        else
        {
            memcpy (des, src, dsize - 1);
            des[dsize - 1] = 0;
        }
        s_out = des;
    }
    return s_out;
}

canonical_original_code:
char *mystrcpy(char *des, char *src, unsigned long dsize)
{
    char *s_out = ((void *)0);
    if (des != ((void *)0)
        && dsize != 0
        && src != ((void *)0))
    {
        unsigned long len = strlen (src);
        if (len < dsize - 1)
        {
            strncpy (des, src, dsize);
        }
        else
        {
            memcpy (des, src, dsize - 1);
            des[dsize - 1] = 0;
        }
        s_out = des;
    }
    return s_out;
}

variable_types:
des
char *

variable_types:
len
unsigned long


changeFormat

original_code:
static int changeFormat(char *const format_dest, char const *const format_src, size_t const format_len)
{
    size_t i=0;
    int iPercent=0;
    mystrcpy(format_dest,format_src,format_len);
    i=0;
    while(i<format_len-1)
    {
        if (format_dest[i]=='%')
            iPercent=1;
        if ((format_dest[i]=='z')&&(iPercent==1))
        {
            iPercent=0;
            format_dest[i]='l';
        }
        if ((format_dest[i]>='a')&&(format_dest[i]<'z')&&(iPercent==1))
        {
            iPercent=0;
        }
        i++;
    }
    return 0;
}

canonical_original_code:
static int changeFormat(char *format_dest, char *format_src, unsigned long format_len)
{
    unsigned long i = 0;
    int iPercent = 0;
    mystrcpy(format_dest,format_src,format_len);
    i=0;
    while(i<format_len-1)
    {
        if (format_dest[i]=='%')
            iPercent=1;
        if ((format_dest[i]=='z')&&(iPercent==1))
        {
            iPercent=0;
            format_dest[i]='l';
        }
        if ((format_dest[i]>='a')&&(format_dest[i]<'z')&&(iPercent==1))
        {
            iPercent=0;
        }
        i++;
    }
    return 0;
}

variable_types:
i
unsigned long

variable_types: iPercent int


mysnprintf

decompiled_code:
__int64 mysnprintf(char *s, size_t a2, char *a3, ...)
{
size_t v4; // rbx
char *v5; // rbp
unsigned int v6; // er12
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a3);
v4 = mystrlen((__int64)a3) + 1;
v5 = (char *)allocArray1D(v4, 1LL);
changeFormat(v5, a3, v4);
if ( v4 > a2 )
{
*s = 0;
v6 = -1;
freeArray1D(v5);
}
else
{
v6 = vsprintf(s, v5, arg);
freeArray1D(v5);
}
return v6;
}

canonical_decompiled_code:
__int64 func4(char *s, size_t a2, char *a3, ...)
{
size_t v4; // rbx
char *v5; // rbp
unsigned int v6; // er12
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a3);
v4 = func0((__int64)a3) + 1;
v5 = (char *)allocArray1D(v4, 1LL);
func2(v5, a3, v4);
if ( v4 > a2 )
{
*s = 0;
v6 = -1;
freeArray1D(v5);
}
else
{
v6 = vsprintf(s, v5, arg);
freeArray1D(v5);
}
return v6;
}

original_code:
int mysnprintf (char *str, size_t size, const char *format,...)
{
    va_list ap;
    int returnval =0;
    const size_t len_format=mystrlen(format)+1;
    char *newformat = allocArray1D(len_format,sizeof(*newformat));
    __builtin_va_start(ap,format);
    changeFormat(newformat,format, len_format);
    if (len_format>size)
    {
        __builtin_va_end(ap);
        str[0]='\0';
        freeArray1D(newformat),newformat=((void *)0);
        return -1;
    }
    returnval=vsprintf(str,newformat,ap);
    freeArray1D(newformat),newformat=((void *)0);
    __builtin_va_end(ap);
    return returnval;
}

canonical_original_code:
int mysnprintf(char *str, unsigned long size, char *format, ...)
{
    __builtin_va_list ap;
    int returnval = 0;
    unsigned long len_format = mystrlen(format)+1;
    char *newformat = allocArray1D(len_format,sizeof(*newformat));
    __builtin_va_start(ap,format);
    changeFormat(newformat,format, len_format);
    if (len_format>size)
    {
        __builtin_va_end(ap);
        str[0]='\0';
        freeArray1D(newformat),newformat=((void *)0);
        return -1;
    }
    returnval=vsprintf(str,newformat,ap);
    freeArray1D(newformat),newformat=((void *)0);
    __builtin_va_end(ap);
    return returnval;
}

variable_types:
str
char *

variable_types:
size
unsigned long

variable_types:
format
char *

variable_types: returnval int

variable_types:
newformat
char *


myprintf

decompiled_code:
__int64 myprintf(char *a1, ...)
{
size_t v1; // r13
char *v2; // rbp
unsigned int v3; // er12
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a1);
v1 = mystrlen((__int64)a1) + 1;
v2 = (char *)allocArray1D(v1, 1LL);
changeFormat(v2, a1, v1);
v3 = vfprintf(stdout, v2, arg);
freeArray1D(v2);
return v3;
}

canonical_decompiled_code:
__int64 func6(char *a1, ...)
{
size_t v1; // r13
char *v2; // rbp
unsigned int v3; // er12
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a1);
v1 = func0((__int64)a1) + 1;
v2 = (char *)allocArray1D(v1, 1LL);
func2(v2, a1, v1);
v3 = vfprintf(stdout, v2, arg);
freeArray1D(v2);
return v3;
}

original_code:
int myprintf(const char *format,...)
{
    const size_t len_format=mystrlen(format)+1;
    int returnval =0;
    va_list ap;
    __builtin_va_start(ap,format);
    {
        char *newformat = allocArray1D(len_format,sizeof(*newformat));
        changeFormat(newformat,format, len_format);
        returnval=vfprintf(stdout,newformat,ap);
        freeArray1D(newformat),newformat=((void *)0);
        __builtin_va_end(ap);
        return returnval;
    }
}

canonical_original_code:
int myprintf(char *format, ...)
{
    unsigned long len_format = mystrlen(format)+1;
    int returnval = 0;
    __builtin_va_list ap;
    __builtin_va_start(ap,format);
    {
        char *newformat = allocArray1D(len_format,sizeof(*newformat));
        changeFormat(newformat,format, len_format);
        returnval=vfprintf(stdout,newformat,ap);
        freeArray1D(newformat),newformat=((void *)0);
        __builtin_va_end(ap);
        return returnval;
    }
}


decompiled_code:
// attributes: thunk
void *align_malloc(size_t size)
{
return malloc(size);
}

canonical_decompiled_code:
void *func0(size_t size)
{
return malloc(size);
}

original_code:
void *align_malloc(size_t n, size_t align)
{
     void *p;
        p = malloc(n);
     return p;
}

canonical_original_code:
void *align_malloc(unsigned long n, unsigned long align)
{
     void *p;
        p = malloc(n);
     return p;
}

variable_types:
n
unsigned long

variable_types:
align
unsigned long

variable_types:
p
void *

return_type: void *


decompiled_code:
// attributes: thunk
void align_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func1(void *ptr)
{
free(ptr);
}

original_code:
void align_free(void *p)
{
     free(p);
}

canonical_original_code:
void align_free(void *p)
{
     free(p);
}


getInt

decompiled_code:
__int64 getInt()
{
int v0; // eax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
while ( !scanf("%d%*[^\n]", v2) )
{
do
v0 = getchar();
while ( v0 != -1 && v0 != 10 );
}
getchar();
return v2[0];
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
while ( !scanf("%d%*[^\n]", v2) )
{
do
v0 = getchar();
while ( v0 != -1 && v0 != 10 );
}
getchar();
return v2[0];
}

original_code:
int getInt(void)
{
    int nombre=0;
    int isOk=0;
    int retour=0;
    while (!isOk){
        retour = scanf("%d%*[^\n]", &nombre);
        if ( !retour ){
            int c;
            while ( ((c = getchar()) != '\n') && c != (-1));
        }
        else {
            getchar();
            isOk = 1;
        }
    }
    return nombre;
}

canonical_original_code:
int getInt()
{
    int nombre = 0;
    int isOk = 0;
    int retour = 0;
    while (!isOk){
        retour = scanf("%d%*[^\n]", &nombre);
        if ( !retour ){
            int c;
            while ( ((c = getchar()) != '\n') && c != (-1));
        }
        else {
            getchar();
            isOk = 1;
        }
    }
    return nombre;
}

variable_types: nombre int

variable_types: isOk int

variable_types: retour int

variable_types: c int


mygetChar

decompiled_code:
__int64 mygetChar()
{
int v0; // eax
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

v2[0] = 0;
while ( !scanf("%c%*[^\n]", v2) )
{
do
v0 = getchar();
while ( v0 != -1 && v0 != 10 );
}
getchar();
return (unsigned __int8)v2[0];
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

v2[0] = 0;
while ( !scanf("%c%*[^\n]", v2) )
{
do
v0 = getchar();
while ( v0 != -1 && v0 != 10 );
}
getchar();
return (unsigned __int8)v2[0];
}

original_code:
char mygetChar(void)
{
    char nombre=0;
    int isOk=0;
    int retour=0;
    while (!isOk){
        retour = scanf("%c%*[^\n]", &nombre);
        if ( !retour ){
            int c;
            while ( ((c = getchar()) != '\n') && c != (-1));
        }
        else {
            getchar();
            isOk = 1;
        }
    }
    return nombre;
}

canonical_original_code:
char mygetChar()
{
    char nombre = 0;
    int isOk = 0;
    int retour = 0;
    while (!isOk){
        retour = scanf("%c%*[^\n]", &nombre);
        if ( !retour ){
            int c;
            while ( ((c = getchar()) != '\n') && c != (-1));
        }
        else {
            getchar();
            isOk = 1;
        }
    }
    return nombre;
}

variable_types: nombre char

return_type: char


getDouble

decompiled_code:
double getDouble()
{
int v0; // eax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

v2[0] = 0.0;
while ( !scanf("%lf%*[^\n]", v2) )
{
do
v0 = getchar();
while ( v0 != -1 && v0 != 10 );
}
getchar();
return v2[0];
}

canonical_decompiled_code:
double func4()
{
int v0; // eax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

v2[0] = 0.0;
while ( !scanf("%lf%*[^\n]", v2) )
{
do
v0 = getchar();
while ( v0 != -1 && v0 != 10 );
}
getchar();
return v2[0];
}

original_code:
double getDouble(void)
{
    double nombre=0;
    int isOk=0;
    int retour=0;
    while (!isOk){
        retour = scanf("%lf%*[^\n]", &nombre);
        if ( !retour ){
            int c;
            while ( ((c = getchar()) != '\n') && c != (-1));
        }
        else {
            getchar();
            isOk = 1;
        }
    }
    return nombre;
}

canonical_original_code:
double getDouble()
{
    double nombre = 0;
    int isOk = 0;
    int retour = 0;
    while (!isOk){
        retour = scanf("%lf%*[^\n]", &nombre);
        if ( !retour ){
            int c;
            while ( ((c = getchar()) != '\n') && c != (-1));
        }
        else {
            getchar();
            isOk = 1;
        }
    }
    return nombre;
}

variable_types: nombre double

return_type: double


getFloat

decompiled_code:
float getFloat()
{
int v0; // eax
float v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0.0;
while ( !scanf("%f%*[^\n]", v2) )
{
do
v0 = getchar();
while ( v0 != -1 && v0 != 10 );
}
getchar();
return v2[0];
}

canonical_decompiled_code:
float func5()
{
int v0; // eax
float v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0.0;
while ( !scanf("%f%*[^\n]", v2) )
{
do
v0 = getchar();
while ( v0 != -1 && v0 != 10 );
}
getchar();
return v2[0];
}

original_code:
float getFloat(void)
{
    float nombre=0;
    int isOk=0;
    int retour=0;
    while (!isOk){
        retour = scanf("%f%*[^\n]", &nombre);
        if ( !retour ){
            int c;
            while ( ((c = getchar()) != '\n') && c != (-1));
        }
        else {
            getchar();
            isOk = 1;
        }
    }
    return nombre;
}

canonical_original_code:
float getFloat()
{
    float nombre = 0;
    int isOk = 0;
    int retour = 0;
    while (!isOk){
        retour = scanf("%f%*[^\n]", &nombre);
        if ( !retour ){
            int c;
            while ( ((c = getchar()) != '\n') && c != (-1));
        }
        else {
            getchar();
            isOk = 1;
        }
    }
    return nombre;
}

variable_types: nombre float

return_type: float


getLong

decompiled_code:
__int64 getLong()
{
int v0; // eax
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
while ( !scanf("%ld%*[^\n]", &v2) )
{
do
v0 = getchar();
while ( v0 != -1 && v0 != 10 );
}
getchar();
return v2;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
while ( !scanf("%ld%*[^\n]", &v2) )
{
do
v0 = getchar();
while ( v0 != -1 && v0 != 10 );
}
getchar();
return v2;
}

original_code:
long getLong(void)
{
    long nombre=0L;
    int isOk=0;
    int retour=0;
    while (!isOk){
        retour = scanf("%ld%*[^\n]", &nombre);
        if ( !retour ){
            int c;
            while ( ((c = getchar()) != '\n') && c != (-1));
        }
        else {
            getchar();
            isOk = 1;
        }
    }
    return nombre;
}

canonical_original_code:
long getLong()
{
    long nombre = 0L;
    int isOk = 0;
    int retour = 0;
    while (!isOk){
        retour = scanf("%ld%*[^\n]", &nombre);
        if ( !retour ){
            int c;
            while ( ((c = getchar()) != '\n') && c != (-1));
        }
        else {
            getchar();
            isOk = 1;
        }
    }
    return nombre;
}

variable_types: nombre long

return_type: long


GenerateFileName

original_code:
int GenerateFileName(const char *const cFilePrefix, char *const cGenerateName)
{
    char buffer[256]={0};
    unsigned int i=0;
    if ((cFilePrefix==((void *)0))||(cGenerateName==((void *)0)))
        return 1;
    sprintf(buffer,"%s%04d.dat",cFilePrefix,i);
    while ((i<10000)&&(isFileExist(buffer)==1))
    {
        i++;
        sprintf(buffer,"%s%04d.dat",cFilePrefix,i);
    }
    if (i==10000)
        return 1;
    strcpy(cGenerateName,buffer);
    return 0;
}

canonical_original_code:
int GenerateFileName(char *cFilePrefix, char *cGenerateName)
{
    char buffer[256] = {0};
    unsigned int i = 0;
    if ((cFilePrefix==((void *)0))||(cGenerateName==((void *)0)))
        return 1;
    sprintf(buffer,"%s%04d.dat",cFilePrefix,i);
    while ((i<10000)&&(isFileExist(buffer)==1))
    {
        i++;
        sprintf(buffer,"%s%04d.dat",cFilePrefix,i);
    }
    if (i==10000)
        return 1;
    strcpy(cGenerateName,buffer);
    return 0;
}

variable_types:
cFilePrefix
char *

variable_types:
cGenerateName
char *

variable_types:
buffer
char [256]

variable_types:
i
unsigned int


eule

original_code:
int eule(double *const Up1, double const*const U, sConst const*const psc,pfLinearOp pfTimeStep, pfBC pfBoundary)
{
    pfTimeStep(psc->pUrhs,U,psc);
    addfields(Up1,U,psc->pUrhs,psc->dDt,psc->sSize);
    pfBoundary(Up1,psc->sSize);
    return 0;
}

canonical_original_code:
int eule(double *Up1, double *U, struct sConst *psc, int (*pfTimeStep)(double *, double *, struct sConst *), void (*pfBoundary)(double *, struct _sFieldSize *))
{
    pfTimeStep(psc->pUrhs,U,psc);
    addfields(Up1,U,psc->pUrhs,psc->dDt,psc->sSize);
    pfBoundary(Up1,psc->sSize);
    return 0;
}

variable_types:
U
double *

variable_types: struct sConst { double dDt; double dEta; long Tmax; long TIO; struct sGeomOp { double dRFactor; double dRmin; double *pdRadius; unsigned long iSize; } *sGeom; struct sLaplacianOp { double *pdCnstGradp; double *pdCnstGradm; double **ppdCnst; double dFactor; unsigned long iSizeX; unsigned long iSizeY; } *sLapTor; struct _sFieldSize { long iSize1; long iSize2; int iSizeC; } *sSize; struct _sFieldDiscret { double dDx1; double dDx2; double dKx1; double dKx2; } *sSteps; double *pdSource; double *pInit; double *pdMKy; double *pUrhs; double *pUtmp; double *pUk1; double *pUk2; double *pUk3; double *pUk4; struct _sInvLap { double *a; double *gam; double *bet; enum H2D_INV_DIRECT { _X=0, _Y=1, _XF=2, _XY=3 } dir; double *z; double *u; double beta; double gamma; } *sInvX; struct _sInvLap *sInvY; struct _sSOR { double *vecA; double *vecB; double *vecC; double *vecD; double *vecE; double rsor; } *sSorMat; enum H2D_INV_DIRECT { _X=0, _Y=1, _XF=2, _XY=3 } eDir; } *

variable_types: int (*)(double *, double *, struct sConst *)

variable_types: void (*)(double *, struct _sFieldSize *)

user_defined_types: struct sConst { double dDt; double dEta; long Tmax; long TIO; struct sGeomOp *sGeom; struct sLaplacianOp *sLapTor; struct _sFieldSize *sSize; struct _sFieldDiscret *sSteps; double *pdSource; double *pInit; double *pdMKy; double *pUrhs; double *pUtmp; double *pUk1; double *pUk2; double *pUk3; double *pUk4; struct _sInvLap *sInvX; struct _sInvLap *sInvY; struct _sSOR *sSorMat; enum H2D_INV_DIRECT eDir; }

user_defined_types: struct _sInvLap { double *a; double *gam; double *bet; enum H2D_INV_DIRECT dir; double *z; double *u; double beta; double gamma; }


original_code:
void real_bc(double *const field,sFieldSize const*const sFs)
{
    long y=0,x=0;
    for (x=0;x<sFs->iSize1;x++)
    {
        field[x] = field[sFs->iSize1*(sFs->iSize2-2)+x];
        field[sFs->iSize1*(sFs->iSize2-1)+x] = field[sFs->iSize1+x];
    }
    for (y=0;y<sFs->iSize2;y++)
    {
        field[y*sFs->iSize1] = -field[y*sFs->iSize1+2];
        field[(y+1)*sFs->iSize1-1] = -field[(y+1)*sFs->iSize1-3];
   }
}

canonical_original_code:
void real_bc(double *field, struct _sFieldSize *sFs)
{
    long y = 0; long x = 0;
    for (x=0;x<sFs->iSize1;x++)
    {
        field[x] = field[sFs->iSize1*(sFs->iSize2-2)+x];
        field[sFs->iSize1*(sFs->iSize2-1)+x] = field[sFs->iSize1+x];
    }
    for (y=0;y<sFs->iSize2;y++)
    {
        field[y*sFs->iSize1] = -field[y*sFs->iSize1+2];
        field[(y+1)*sFs->iSize1-1] = -field[(y+1)*sFs->iSize1-3];
   }
}

variable_types:
field
double *

variable_types: struct _sFieldSize { long iSize1; long iSize2; int iSizeC; } *

variable_types: y long

variable_types: x long


decompiled_code:
void null_bc()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void null_bc(double *const field,sFieldSize const*const sFs)
{
    long y=0,x=0;
}

canonical_original_code:
void null_bc(double *field, struct _sFieldSize *sFs)
{
    long y = 0; long x = 0;
}

user_defined_types: struct _sFieldSize { long iSize1; long iSize2; int iSizeC; }


source

decompiled_code:
double source()
{
return 0.0;
}

canonical_decompiled_code:
double func0()
{
return 0.0;
}

variable_types: x double

variable_types: y double

variable_types: dComplex int

variable_types:
FCNAME
char []

variable_types: resultat double


decompiled_code:
__int64 __fastcall freeArray2D(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
align_free(*a1);
result = align_free(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
align_free(*a1);
result = align_free(a1);
}
return result;
}

original_code:
void freeArray2D(void **pVec)
{
    static const char FCNAME[] = "freeArray2D";
    if (pVec!=((void *)0))
    {
        align_free(pVec[0]);
        align_free(pVec);
    }
}

canonical_original_code:
void freeArray2D(void **pVec)
{
    static char FCNAME[] = "freeArray2D";
    if (pVec!=((void *)0))
    {
        align_free(pVec[0]);
        align_free(pVec);
    }
}

variable_types:
pVec
void **


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

if ( a1 )
result = align_free(a1);
return result;
}

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

if ( a1 )
result = align_free(a1);
return result;
}

original_code:
void freeArray1D(void *pVec)
{
    static const char FCNAME[] = "freeArray1D";
    if (pVec!=((void *)0))
    {
        align_free(pVec);
    }
}

canonical_original_code:
void freeArray1D(void *pVec)
{
    static char FCNAME[] = "freeArray1D";
    if (pVec!=((void *)0))
    {
        align_free(pVec);
    }
}

variable_types:
pVec
void *


calcMatInit

original_code:
void calcMatInit(double *const pMatInit, sFieldSize const*const sFs, sFieldDiscret const*const sFd)
{
    long ix=0,iy=0;
    int ic=0;
    double x=0;
    double y=0;
    for(ic=0;ic<sFs->iSizeC;ic++)
    {
        for(iy=0;iy<sFs->iSize2;iy++)
        {
            long offset = sFs->iSize1*(iy+sFs->iSize2*ic);
            for(ix=0;ix<sFs->iSize1;ix++)
            {
                x=(double)(ix-1)*sFd->dDx1;
                if (strcmp("real","fourier")==0)
                {
                    y=(double)iy*sFd->dKx2;
                }
                else
                {
                    y=(double)iy*sFd->dDx2;
                }
                pMatInit[ix+offset]=FuncInit(x,y, ic);
            }
        }
    }
}

canonical_original_code:
void calcMatInit(double *pMatInit, struct _sFieldSize *sFs, struct _sFieldDiscret *sFd)
{
    long ix = 0; long iy = 0;
    int ic = 0;
    double x = 0;
    double y = 0;
    for(ic=0;ic<sFs->iSizeC;ic++)
    {
        for(iy=0;iy<sFs->iSize2;iy++)
        {
            long offset = sFs->iSize1*(iy+sFs->iSize2*ic);
            for(ix=0;ix<sFs->iSize1;ix++)
            {
                x=(double)(ix-1)*sFd->dDx1;
                if (strcmp("real","fourier")==0)
                {
                    y=(double)iy*sFd->dKx2;
                }
                else
                {
                    y=(double)iy*sFd->dDx2;
                }
                pMatInit[ix+offset]=FuncInit(x,y, ic);
            }
        }
    }
}

variable_types:
pMatInit
double *

variable_types: struct _sFieldDiscret { double dDx1; double dDx2; double dKx1; double dKx2; } *

variable_types: ix long

variable_types: iy long

variable_types: ic int

variable_types: offset long


getParams

original_code:
int getParams(sConst *const psc)
{
    long i=0;
    psc->Tmax = 4096*128;
    psc->TIO = psc->Tmax/20;
    psc->dDt = 0.01;
    psc->dEta = 2;
    psc->sSize = (sFieldSize *)align_malloc(sizeof(*psc->sSize),16);
    psc->sSteps = (sFieldDiscret *)align_malloc(sizeof(*psc->sSteps),16);
    psc->sSize->iSize1 = 64;
    psc->sSize->iSize2 = 64;
    psc->sSteps->dDx1 = 128*3.1415926535897932/(double)(psc->sSize->iSize1-2);
    psc->sSteps->dDx2 = 128*3.1415926535897932/(double)(psc->sSize->iSize2-2);
    psc->sSteps->dKx1 = 2.*3.1415926535897932/(double)(128*3.1415926535897932);
    psc->sSteps->dKx2 = 2.*3.1415926535897932/(double)(128*3.1415926535897932);
    if (strcmp("real","fourier")==0)
    {
        psc->sSize->iSizeC = 2;
    }
    else if (strcmp("real","real")==0)
    {
        psc->sSize->iSizeC = 1;
    }
    psc->pdSource=allocArray1D((size_t)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pdSource));
    psc->pInit=allocArray1D((size_t)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pInit));
    psc->pdMKy=allocArray1D((size_t)psc->sSize->iSize2,sizeof(*psc->pdMKy));
    psc->pUrhs= allocArray1D((size_t)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUrhs));
    psc->pUtmp= allocArray1D((size_t)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUtmp));
    psc->pUk1 = allocArray1D((size_t)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUk1));
    psc->pUk2 = allocArray1D((size_t)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUk2));
    psc->pUk3 = allocArray1D((size_t)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUk3));
    psc->pUk4 = allocArray1D((size_t)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUk4));
    psc->sInvX = allocArray1D(1,sizeof(*psc->sInvX));
    psc->sInvY = allocArray1D(1,sizeof(*psc->sInvY));
    psc->sSorMat = allocArray1D(1,sizeof(*psc->sSorMat));
    mallocInvLapStruct(psc->sInvX,psc->sSize);
    mallocInvLapStruct(psc->sInvY,psc->sSize);
    mallocSORStruct(psc->sSorMat,psc->sSize);
    for(i=0;i<psc->sSize->iSize2;i++)
    {
        psc->pdMKy[i]=(double)i*psc->sSteps->dKx2;
    }
    calcMatInit(psc->pInit,psc->sSize,psc->sSteps);
    calcSourceInit(psc->pdSource,psc->sSize,psc->sSteps);
    if (strcmp("real","fourier")==0)
    {
        initInvLapStructXF(psc->sInvX,psc->sSize,psc->sSteps->dDx1,psc->sSteps->dKx2, - psc->dEta*psc->dDt );
    }
    else
    {
        initInvLapStructX(psc->sInvX,psc->sSize,psc->sSteps->dDx1, - 0.5*psc->dEta*psc->dDt);
        initInvLapStructY(psc->sInvY,psc->sSize,psc->sSteps->dDx2, - 0.5*psc->dEta*psc->dDt);
        initSOR(psc->sSorMat,psc,-1.*psc->dEta*psc->dDt);
    }
    writeProfil("H2D_OCT_source.dat",psc->pdSource,psc->sSize,_OCT);
    writeProfil("H2D_OCT_CI.dat",psc->pInit,psc->sSize,_OCT);
    writeProfil("H2D_GPLOT_source.dat",psc->pdSource,psc->sSize,_GPLOT);
    writeProfil("H2D_GPLOT_CI.dat",psc->pInit,psc->sSize,_GPLOT);
    return 0;
}

canonical_original_code:
int getParams(struct sConst *psc)
{
    long i = 0;
    psc->Tmax = 4096*128;
    psc->TIO = psc->Tmax/20;
    psc->dDt = 0.01;
    psc->dEta = 2;
    psc->sSize = (struct _sFieldSize *)align_malloc(sizeof(*psc->sSize),16);
    psc->sSteps = (struct _sFieldDiscret *)align_malloc(sizeof(*psc->sSteps),16);
    psc->sSize->iSize1 = 64;
    psc->sSize->iSize2 = 64;
    psc->sSteps->dDx1 = 128*3.1415926535897932/(double)(psc->sSize->iSize1-2);
    psc->sSteps->dDx2 = 128*3.1415926535897932/(double)(psc->sSize->iSize2-2);
    psc->sSteps->dKx1 = 2.*3.1415926535897932/(double)(128*3.1415926535897932);
    psc->sSteps->dKx2 = 2.*3.1415926535897932/(double)(128*3.1415926535897932);
    if (strcmp("real","fourier")==0)
    {
        psc->sSize->iSizeC = 2;
    }
    else if (strcmp("real","real")==0)
    {
        psc->sSize->iSizeC = 1;
    }
    psc->pdSource=allocArray1D((unsigned long)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pdSource));
    psc->pInit=allocArray1D((unsigned long)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pInit));
    psc->pdMKy=allocArray1D((unsigned long)psc->sSize->iSize2,sizeof(*psc->pdMKy));
    psc->pUrhs= allocArray1D((unsigned long)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUrhs));
    psc->pUtmp= allocArray1D((unsigned long)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUtmp));
    psc->pUk1 = allocArray1D((unsigned long)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUk1));
    psc->pUk2 = allocArray1D((unsigned long)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUk2));
    psc->pUk3 = allocArray1D((unsigned long)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUk3));
    psc->pUk4 = allocArray1D((unsigned long)psc->sSize->iSize1*psc->sSize->iSize2*psc->sSize->iSizeC,sizeof(*psc->pUk4));
    psc->sInvX = allocArray1D(1,sizeof(*psc->sInvX));
    psc->sInvY = allocArray1D(1,sizeof(*psc->sInvY));
    psc->sSorMat = allocArray1D(1,sizeof(*psc->sSorMat));
    mallocInvLapStruct(psc->sInvX,psc->sSize);
    mallocInvLapStruct(psc->sInvY,psc->sSize);
    mallocSORStruct(psc->sSorMat,psc->sSize);
    for(i=0;i<psc->sSize->iSize2;i++)
    {
        psc->pdMKy[i]=(double)i*psc->sSteps->dKx2;
    }
    calcMatInit(psc->pInit,psc->sSize,psc->sSteps);
    calcSourceInit(psc->pdSource,psc->sSize,psc->sSteps);
    if (strcmp("real","fourier")==0)
    {
        initInvLapStructXF(psc->sInvX,psc->sSize,psc->sSteps->dDx1,psc->sSteps->dKx2, - psc->dEta*psc->dDt );
    }
    else
    {
        initInvLapStructX(psc->sInvX,psc->sSize,psc->sSteps->dDx1, - 0.5*psc->dEta*psc->dDt);
        initInvLapStructY(psc->sInvY,psc->sSize,psc->sSteps->dDx2, - 0.5*psc->dEta*psc->dDt);
        initSOR(psc->sSorMat,psc,-1.*psc->dEta*psc->dDt);
    }
    writeProfil("H2D_OCT_source.dat",psc->pdSource,psc->sSize,_OCT);
    writeProfil("H2D_OCT_CI.dat",psc->pInit,psc->sSize,_OCT);
    writeProfil("H2D_GPLOT_source.dat",psc->pdSource,psc->sSize,_GPLOT);
    writeProfil("H2D_GPLOT_CI.dat",psc->pInit,psc->sSize,_GPLOT);
    return 0;
}

variable_types: struct sConst { double dDt; double dEta; long Tmax; long TIO; struct sGeomOp { double dRFactor; double dRmin; double *pdRadius; unsigned long iSize; } *sGeom; struct sLaplacianOp { double *pdCnstGradp; double *pdCnstGradm; double **ppdCnst; double dFactor; unsigned long iSizeX; unsigned long iSizeY; } *sLapTor; struct _sFieldSize { long iSize1; long iSize2; int iSizeC; } *sSize; struct _sFieldDiscret { double dDx1; double dDx2; double dKx1; double dKx2; } *sSteps; double *pdSource; double *pInit; double *pdMKy; double *pUrhs; double *pUtmp; double *pUk1; double *pUk2; double *pUk3; double *pUk4; struct _sInvLap { double *a; double *gam; double *bet; enum H2D_INV_DIRECT { _X=0, _Y=1, _XF=2, _XY=3 } dir; double *z; double *u; double beta; double gamma; } *sInvX; struct _sInvLap *sInvY; struct _sSOR { double *vecA; double *vecB; double *vecC; double *vecD; double *vecE; double rsor; } *sSorMat; enum H2D_INV_DIRECT { _X=0, _Y=1, _XF=2, _XY=3 } eDir; } *

variable_types: i long


freeParams

decompiled_code:
__int64 __fastcall freeParams(_QWORD *a1)
{
freeInvLapStruct(a1[17]);
freeInvLapStruct(a1[18]);
freeSORStruct(a1[19]);
freeArray1D(a1[6]);
freeArray1D(a1[7]);
freeArray1D(a1[8]);
freeArray1D(a1[9]);
freeArray1D(a1[10]);
freeArray1D(a1[11]);
freeArray1D(a1[12]);
freeArray1D(a1[13]);
freeArray1D(a1[14]);
freeArray1D(a1[15]);
freeArray1D(a1[16]);
freeArray1D(a1[17]);
return freeArray1D(a1[18]);
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
freeInvLapStruct(a1[17]);
freeInvLapStruct(a1[18]);
freeSORStruct(a1[19]);
freeArray1D(a1[6]);
freeArray1D(a1[7]);
freeArray1D(a1[8]);
freeArray1D(a1[9]);
freeArray1D(a1[10]);
freeArray1D(a1[11]);
freeArray1D(a1[12]);
freeArray1D(a1[13]);
freeArray1D(a1[14]);
freeArray1D(a1[15]);
freeArray1D(a1[16]);
freeArray1D(a1[17]);
return freeArray1D(a1[18]);
}

original_code:
void freeParams(sConst *psc)
{
    freeInvLapStruct(psc->sInvX);
    freeInvLapStruct(psc->sInvY);
    freeSORStruct(psc->sSorMat);
    freeArray1D(psc->sSize);
    freeArray1D(psc->sSteps);
    freeArray1D(psc->pdSource);
    freeArray1D(psc->pInit);
    freeArray1D(psc->pdMKy);
    freeArray1D(psc->pUrhs);
    freeArray1D(psc->pUtmp);
    freeArray1D(psc->pUk1);
    freeArray1D(psc->pUk2);
    freeArray1D(psc->pUk3);
    freeArray1D(psc->pUk4);
    freeArray1D(psc->sInvX);
    freeArray1D(psc->sInvY);
}

canonical_original_code:
void freeParams(struct sConst *psc)
{
    freeInvLapStruct(psc->sInvX);
    freeInvLapStruct(psc->sInvY);
    freeSORStruct(psc->sSorMat);
    freeArray1D(psc->sSize);
    freeArray1D(psc->sSteps);
    freeArray1D(psc->pdSource);
    freeArray1D(psc->pInit);
    freeArray1D(psc->pdMKy);
    freeArray1D(psc->pUrhs);
    freeArray1D(psc->pUtmp);
    freeArray1D(psc->pUk1);
    freeArray1D(psc->pUk2);
    freeArray1D(psc->pUk3);
    freeArray1D(psc->pUk4);
    freeArray1D(psc->sInvX);
    freeArray1D(psc->sInvY);
}

user_defined_types: enum H2D_INV_DIRECT { _X=0, _Y=1, _XF=2, _XY=3 }

user_defined_types: struct sGeomOp { double dRFactor; double dRmin; double *pdRadius; unsigned long iSize; }

user_defined_types: struct sLaplacianOp { double *pdCnstGradp; double *pdCnstGradm; double **ppdCnst; double dFactor; unsigned long iSizeX; unsigned long iSizeY; }

user_defined_types: struct _sFieldDiscret { double dDx1; double dDx2; double dKx1; double dKx2; }

user_defined_types: struct _sSOR { double *vecA; double *vecB; double *vecC; double *vecD; double *vecE; double rsor; }


euli

original_code:
int euli(double *const Up1, double const*const U, sConst const*const psc,pfLinearOp pfTimeStep, pfBC pfBoundary)
{
    if (strcmp("real","real")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUrhs,psc->pUk1,psc->sSize,psc->sInvX);
        pfBoundary(psc->pUk1,psc->sSize);
        addfields(psc->pUrhs,psc->pUk1,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUrhs,Up1,psc->sSize,psc->sInvY);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,psc->dDt,psc->sSize);
        invMat(psc->pUrhs,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    return 0;
}

canonical_original_code:
int euli(double *Up1, double *U, struct sConst *psc, int (*pfTimeStep)(double *, double *, struct sConst *), void (*pfBoundary)(double *, struct _sFieldSize *))
{
    if (strcmp("real","real")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUrhs,psc->pUk1,psc->sSize,psc->sInvX);
        pfBoundary(psc->pUk1,psc->sSize);
        addfields(psc->pUrhs,psc->pUk1,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUrhs,Up1,psc->sSize,psc->sInvY);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,psc->dDt,psc->sSize);
        invMat(psc->pUrhs,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    return 0;
}

variable_types:
U
double *

variable_types: int (*)(double *, double *, struct sConst *)

variable_types: void (*)(double *, struct _sFieldSize *)


eulis

original_code:
int eulis(double *const Up1, double const*const U, sConst const*const psc,pfLinearOp pfTimeStep, pfBC pfBoundary)
{
    if (strcmp("real","real")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,psc->dDt,psc->sSize);
        sor(Up1,psc->pUrhs,psc->sSorMat,psc->sSize);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        euli(Up1,U,psc,pfTimeStep,pfBoundary);
    }
    return 0;
}

canonical_original_code:
int eulis(double *Up1, double *U, struct sConst *psc, int (*pfTimeStep)(double *, double *, struct sConst *), void (*pfBoundary)(double *, struct _sFieldSize *))
{
    if (strcmp("real","real")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,psc->dDt,psc->sSize);
        sor(Up1,psc->pUrhs,psc->sSorMat,psc->sSize);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        euli(Up1,U,psc,pfTimeStep,pfBoundary);
    }
    return 0;
}


cranck

original_code:
int cranck(double *const Up1, double const*const U, sConst *const psc,pfLinearOp pfTimeStep, pfBC pfBoundary)
{
    if (strcmp("real","real")==0)
    {
        psc->eDir =_X;
        pfTimeStep(psc->pUrhs,U,psc);
        addfields(psc->pUk1,U,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,psc->pUk2,psc->sSize,psc->sInvY);
        pfBoundary(psc->pUk2,psc->sSize);
        psc->eDir =_Y;
        pfTimeStep(psc->pUrhs,psc->pUk2,psc);
        addfields(psc->pUk1,psc->pUk2,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        psc->eDir =_XF;
        pfTimeStep(psc->pUrhs,U,psc);
        addfields(psc->pUk1,U,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        addfields(psc->pUk1,U,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    return 0;
}

canonical_original_code:
int cranck(double *Up1, double *U, struct sConst *psc, int (*pfTimeStep)(double *, double *, struct sConst *), void (*pfBoundary)(double *, struct _sFieldSize *))
{
    if (strcmp("real","real")==0)
    {
        psc->eDir =_X;
        pfTimeStep(psc->pUrhs,U,psc);
        addfields(psc->pUk1,U,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,psc->pUk2,psc->sSize,psc->sInvY);
        pfBoundary(psc->pUk2,psc->sSize);
        psc->eDir =_Y;
        pfTimeStep(psc->pUrhs,psc->pUk2,psc);
        addfields(psc->pUk1,psc->pUk2,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        psc->eDir =_XF;
        pfTimeStep(psc->pUrhs,U,psc);
        addfields(psc->pUk1,U,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        addfields(psc->pUk1,U,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    return 0;
}


mygetFileExt

decompiled_code:
_BOOL8 __fastcall mygetFileExt(const char *a1, __int64 a2, __int64 a3)
{
return sscanf(a1, "%[a-zA-Z0-9_].%[a-zA-Z0-9]", a2, a3) != 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1, __int64 a2, __int64 a3)
{
return sscanf(a1, "%[a-zA-Z0-9_].%[a-zA-Z0-9]", a2, a3) != 2;
}

original_code:
int mygetFileExt(char const*const filename, char *const name, char *const fileExt)
{
    static const char FCNAME[] = "mygetFileExt";
    int extractval=sscanf(filename,"%[a-zA-Z0-9_].%[a-zA-Z0-9]",name,fileExt);
    if (extractval!=2)
        return 1;
    return 0;
}

canonical_original_code:
int mygetFileExt(char *filename, char *name, char *fileExt)
{
    static char FCNAME[] = "mygetFileExt";
    int extractval = sscanf(filename,"%[a-zA-Z0-9_].%[a-zA-Z0-9]",name,fileExt);
    if (extractval!=2)
        return 1;
    return 0;
}

variable_types:
filename
char *

variable_types:
name
char *

variable_types:
fileExt
char *

variable_types: extractval int


main

repo: GNOME/gnome-nettool

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 1 )
{
longind[0] = 0;
opterr = 0;
v3 = getopt_long(argc, (char *const *)argv, "c:vh", &long_options_0, longind);
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'h':
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts(" -h, --help\t\tPrint this help.");
puts(" -c, --count=NUMBER\tSet limit of packets to send");
puts(" -v, --verbose\tShow the packets sent");
break;
case 'v':
verbose = 1;
break;
case 'c':
if ( atoi(optarg) <= 0 )
{
printf("%s: Bad number of packets to transmit.\n", "gnome-ping-helper");
exit(-1);
}
break;
default:
goto LABEL_5;
}
}
if ( optind < argc && argc - optind == 1 )
do_ping((char *)argv[optind]);
LABEL_5:
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts("Try 'gnome-ping-helper --help' for more information");
exit(-1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 1 )
{
longind[0] = 0;
opterr = 0;
v3 = getopt_long(argc, (char *const *)argv, "c:vh", &long_options_0, longind);
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'h':
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts(" -h, --help\t\tPrint this help.");
puts(" -c, --count=NUMBER\tSet limit of packets to send");
puts(" -v, --verbose\tShow the packets sent");
break;
case 'v':
verbose = 1;
break;
case 'c':
if ( atoi(optarg) <= 0 )
{
printf("%s: Bad number of packets to transmit.\n", "gnome-ping-helper");
exit(-1);
}
break;
default:
goto LABEL_5;
}
}
if ( optind < argc && argc - optind == 1 )
func15((char *)argv[optind]);
LABEL_5:
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts("Try 'gnome-ping-helper --help' for more information");
exit(-1);
}

original_code:
int
main (int argc, char **argv)
{
 int c;
 int count = 0;
 char *host;
 for (;;) {
  int option_index = 0;
  static struct option long_options[] = {
   {"count", 1, 0, 'c'},
   {"verbose", 0, 0, 'v'},
   {"help", 0, 0, 'h'}
  };
  opterr = 0;
  c = getopt_long (argc, argv, "c:vh",
     long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 'v':
   verbose = 1;
   break;
  case 'c':
   count = atoi (optarg);
   if (count <= 0) {
    printf ("%s: Bad number of packets to transmit.\n", "gnome-ping-helper");
    exit (-1);
   }
   break;
  case 'h':
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("  -h,  --help\t\tPrint this help.\n");
   printf ("  -c,  --count=NUMBER\tSet limit of packets to send\n");
   printf ("  -v,  --verbose\tShow the packets sent\n");
   break;
  default:
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
  }
 }
 if (optind < argc) {
  if (argc - optind != 1) {
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
  } else {
   host = argv[optind];
   do_ping (host, count);
  }
 } else {
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
 }
 return (0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int c;
 int count = 0;
 char *host;
 for (;;) {
  int option_index = 0;
  static struct option long_options[] = {
   {"count", 1, 0, 'c'},
   {"verbose", 0, 0, 'v'},
   {"help", 0, 0, 'h'}
  };
  opterr = 0;
  c = getopt_long (argc, argv, "c:vh",
     long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 'v':
   verbose = 1;
   break;
  case 'c':
   count = atoi (optarg);
   if (count <= 0) {
    printf ("%s: Bad number of packets to transmit.\n", "gnome-ping-helper");
    exit (-1);
   }
   break;
  case 'h':
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("  -h,  --help\t\tPrint this help.\n");
   printf ("  -c,  --count=NUMBER\tSet limit of packets to send\n");
   printf ("  -v,  --verbose\tShow the packets sent\n");
   break;
  default:
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
  }
 }
 if (optind < argc) {
  if (argc - optind != 1) {
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
  } else {
   host = argv[optind];
   do_ping (host, count);
  }
 } else {
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
 }
 return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: count int

variable_types:
host
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


decompiled_code:
int __fastcall process_icmp(_BYTE *a1, int a2, __int64 *a3)
{
int result; // eax
unsigned int v4; // ebp
_BYTE *v5; // r9
__int64 v7; // rcx
unsigned int v8; // ebx
__int64 v9; // r9
unsigned int v10; // er12
char *v11; // rax
double v12; // [rsp+8h] [rbp-20h]

result = 4 * (*a1 & 0xF);
v4 = a2 - result;
v5 = &a1[result];
if ( a2 - result <= 7 )
{
fprintf(stderr, "icmplen (%d) < 8", v4);
goto LABEL_8;
}
if ( !*v5 )
{
result = *((unsigned __int16 *)v5 + 2);
if ( result == pid )
{
if ( (int)v4 > 15 )
{
tv_sub(a3, (_QWORD *)v5 + 1);
v8 = *(unsigned __int8 *)(v7 + 8);
v10 = *(unsigned __int16 *)(v9 + 6);
v12 = (double)(int)*a3 * 1000.0 + (double)(int)a3[1] / 1000.0;
v11 = inet_ntoa(*(struct in_addr *)(*((_QWORD *)pr + 1) + 4LL));
return printf("%d bytes from %s: seq=%u, ttl=%d, rtt=%.3f ms\n", v4, v11, v10, v8, v12);
}
fprintf(stderr, "icmplen (%d) < 16", v4);
LABEL_8:
exit(-3);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(_BYTE *a1, int a2, __int64 *a3)
{
int result; // eax
unsigned int v4; // ebp
_BYTE *v5; // r9
__int64 v7; // rcx
unsigned int v8; // ebx
__int64 v9; // r9
unsigned int v10; // er12
char *v11; // rax
double v12; // [rsp+8h] [rbp-20h]

result = 4 * (*a1 & 0xF);
v4 = a2 - result;
v5 = &a1[result];
if ( a2 - result <= 7 )
{
fprintf(stderr, "icmplen (%d) < 8", v4);
goto LABEL_8;
}
if ( !*v5 )
{
result = *((unsigned __int16 *)v5 + 2);
if ( result == pid )
{
if ( (int)v4 > 15 )
{
func9(a3, (_QWORD *)v5 + 1);
v8 = *(unsigned __int8 *)(v7 + 8);
v10 = *(unsigned __int16 *)(v9 + 6);
v12 = (double)(int)*a3 * 1000.0 + (double)(int)a3[1] / 1000.0;
v11 = inet_ntoa(*(struct in_addr *)(*((_QWORD *)pr + 1) + 4LL));
return printf("%d bytes from %s: seq=%u, ttl=%d, rtt=%.3f ms\n", v4, v11, v10, v8, v12);
}
fprintf(stderr, "icmplen (%d) < 16", v4);
LABEL_8:
exit(-3);
}
}
return result;
}

original_code:
void
process_icmp (char *ptr, ssize_t len, struct timeval *tvrecv)
{
 int hlen1, icmplen;
 double rtt;
 struct ip *ip;
 struct icmp *icmp;
 struct timeval *tvsend;
 struct sockaddr_in *sin = ((void *)0);
 ip = (struct ip *) ptr;
 hlen1 = ip->ip_hl << 2;
 icmp = (struct icmp *) (ptr + hlen1);
 if ((icmplen = len - hlen1) < 8) {
  fprintf (stderr, "icmplen (%d) < 8", icmplen);
  exit (-3);
 }
 if (icmp->icmp_type == 0) {
  if (icmp->icmp_hun.ih_idseq.icd_id != pid)
   return;
  if (icmplen < 16) {
   fprintf (stderr, "icmplen (%d) < 16", icmplen);
   exit (-3);
  }
  tvsend = (struct timeval *) icmp->icmp_dun.id_data;
  tv_sub (tvrecv, tvsend);
  rtt = tvrecv->tv_sec * 1000.0 + tvrecv->tv_usec / 1000.0;
  sin = (struct sockaddr_in *) pr->sarecv;
  printf ("%d bytes from %s: seq=%u, ttl=%d, rtt=%.3f ms\n",
   icmplen, inet_ntoa (sin->sin_addr),
   icmp->icmp_hun.ih_idseq.icd_seq, ip->ip_ttl, rtt);
 }
}

canonical_original_code:
void process_icmp(char *ptr, long len, struct timeval *tvrecv)
{
 int hlen1; int icmplen;
 double rtt;
 struct ip *ip;
 struct icmp *icmp;
 struct timeval *tvsend;
 struct sockaddr_in *sin = ((void *)0);
 ip = (struct ip *) ptr;
 hlen1 = ip->ip_hl << 2;
 icmp = (struct icmp *) (ptr + hlen1);
 if ((icmplen = len - hlen1) < 8) {
  fprintf (stderr, "icmplen (%d) < 8", icmplen);
  exit (-3);
 }
 if (icmp->icmp_type == 0) {
  if (icmp->icmp_hun.ih_idseq.icd_id != pid)
   return;
  if (icmplen < 16) {
   fprintf (stderr, "icmplen (%d) < 16", icmplen);
   exit (-3);
  }
  tvsend = (struct timeval *) icmp->icmp_dun.id_data;
  tv_sub (tvrecv, tvsend);
  rtt = tvrecv->tv_sec * 1000.0 + tvrecv->tv_usec / 1000.0;
  sin = (struct sockaddr_in *) pr->sarecv;
  printf ("%d bytes from %s: seq=%u, ttl=%d, rtt=%.3f ms\n",
   icmplen, inet_ntoa (sin->sin_addr),
   icmp->icmp_hun.ih_idseq.icd_seq, ip->ip_ttl, rtt);
 }
}

variable_types:
ptr
char *

variable_types: len long

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

variable_types: icmplen int

variable_types: rtt double

variable_types: struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr { unsigned int s_addr; } ip_src; } *

variable_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr { unsigned int s_addr; } ih_gwaddr; struct ih_idseq { unsigned short icd_id; unsigned short icd_seq; } ih_idseq; unsigned int ih_void; struct ih_pmtu { unsigned short ipm_void; unsigned short ipm_nextmtu; } ih_pmtu; struct ih_rtradv { unsigned char irt_num_addrs; unsigned char irt_wpa; unsigned short irt_lifetime; } ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; } idi_ip; } id_ip; struct icmp_ra_addr { unsigned int ira_addr; unsigned int ira_preference; } id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; } *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

user_defined_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr ih_gwaddr; struct ih_idseq ih_idseq; unsigned int ih_void; struct ih_pmtu ih_pmtu; struct ih_rtradv ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip idi_ip; } id_ip; struct icmp_ra_addr id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


original_code:
unsigned short
in_cksum (unsigned short *addr, int len)
{
 int nleft = len;
 int sum = 0;
 unsigned short *w = addr;
 unsigned short answer = 0;
 while (nleft > 1) {
  sum += *w++;
  nleft -= 2;
 }
 if (nleft == 1) {
  *(unsigned char *) (&answer) = *(unsigned char *) w;
  sum += answer;
 }
 sum = (sum >> 16) + (sum & 0xffff);
 sum += (sum >> 16);
 answer = ~sum;
 return (answer);
}

canonical_original_code:
unsigned short in_cksum(unsigned short *addr, int len)
{
 int nleft = len;
 int sum = 0;
 unsigned short *w = addr;
 unsigned short answer = 0;
 while (nleft > 1) {
  sum += *w++;
  nleft -= 2;
 }
 if (nleft == 1) {
  *(unsigned char *) (&answer) = *(unsigned char *) w;
  sum += answer;
 }
 sum = (sum >> 16) + (sum & 0xffff);
 sum += (sum >> 16);
 answer = ~sum;
 return (answer);
}

variable_types:
addr
unsigned short *

variable_types: len int

variable_types: nleft int

variable_types: sum int

variable_types:
w
unsigned short *

variable_types:
answer
unsigned short

return_type: unsigned short


decompiled_code:
int send_icmp()
{
int v0; // ebp
int result; // eax
unsigned int v2; // ebx
unsigned int v3; // er12
char *v4; // rax

sendbuf = 8;
word_404204 = pid;
word_404206 = nsent++;
gettimeofday(&tv, 0LL);
word_404202 = 0;
v0 = datalen + 8;
word_404202 = in_cksum((unsigned __int16 *)&sendbuf, datalen + 8);
result = sendto(sockfd, &sendbuf, v0, 0, *(const struct sockaddr **)pr, *((_DWORD *)pr + 4));
if ( verbose )
{
v2 = (unsigned __int16)word_404204;
v3 = (unsigned __int16)word_404206;
v4 = inet_ntoa(*(struct in_addr *)(*(_QWORD *)pr + 4LL));
result = printf("%d bytes sent to %s: seq=%u, id=%d\n", (unsigned int)v0, v4, v3, v2);
}
return result;
}

canonical_decompiled_code:
int func12()
{
int v0; // ebp
int result; // eax
unsigned int v2; // ebx
unsigned int v3; // er12
char *v4; // rax

sendbuf = 8;
word_404204 = pid;
word_404206 = nsent++;
gettimeofday(&tv, 0LL);
word_404202 = 0;
v0 = datalen + 8;
word_404202 = func11((unsigned __int16 *)&sendbuf, datalen + 8);
result = sendto(sockfd, &sendbuf, v0, 0, *(const struct sockaddr **)pr, *((_DWORD *)pr + 4));
if ( verbose )
{
v2 = (unsigned __int16)word_404204;
v3 = (unsigned __int16)word_404206;
v4 = inet_ntoa(*(struct in_addr *)(*(_QWORD *)pr + 4LL));
result = printf("%d bytes sent to %s: seq=%u, id=%d\n", (unsigned int)v0, v4, v3, v2);
}
return result;
}

original_code:
void
send_icmp (void)
{
 int len;
 struct icmp *icmp;
 struct sockaddr_in *sin = ((void *)0);
 icmp = (struct icmp *) sendbuf;
 icmp->icmp_type = 8;
 icmp->icmp_code = 0;
 icmp->icmp_hun.ih_idseq.icd_id = pid;
 icmp->icmp_hun.ih_idseq.icd_seq = nsent++;
 gettimeofday ((struct timeval *) icmp->icmp_dun.id_data, ((void *)0));
 len = 8 + datalen;
 icmp->icmp_cksum = 0;
 icmp->icmp_cksum = in_cksum ((u_short *) icmp, len);
 sendto (sockfd, sendbuf, len, 0, pr->sasend, pr->salen);
 sin = (struct sockaddr_in *) pr->sasend;
 if (verbose) {
  printf ("%d bytes sent to %s: seq=%u, id=%d\n",
   len, inet_ntoa (sin->sin_addr),
   icmp->icmp_hun.ih_idseq.icd_seq, icmp->icmp_hun.ih_idseq.icd_id);
 }
}

canonical_original_code:
void send_icmp()
{
 int len;
 struct icmp *icmp;
 struct sockaddr_in *sin = ((void *)0);
 icmp = (struct icmp *) sendbuf;
 icmp->icmp_type = 8;
 icmp->icmp_code = 0;
 icmp->icmp_hun.ih_idseq.icd_id = pid;
 icmp->icmp_hun.ih_idseq.icd_seq = nsent++;
 gettimeofday ((struct timeval *) icmp->icmp_dun.id_data, ((void *)0));
 len = 8 + datalen;
 icmp->icmp_cksum = 0;
 icmp->icmp_cksum = in_cksum ((unsigned short *) icmp, len);
 sendto (sockfd, sendbuf, len, 0, pr->sasend, pr->salen);
 sin = (struct sockaddr_in *) pr->sasend;
 if (verbose) {
  printf ("%d bytes sent to %s: seq=%u, id=%d\n",
   len, inet_ntoa (sin->sin_addr),
   icmp->icmp_hun.ih_idseq.icd_seq, icmp->icmp_hun.ih_idseq.icd_id);
 }
}

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

user_defined_types: struct ih_idseq { unsigned short icd_id; unsigned short icd_seq; }

user_defined_types: struct ih_pmtu { unsigned short ipm_void; unsigned short ipm_nextmtu; }

user_defined_types: struct ih_rtradv { unsigned char irt_num_addrs; unsigned char irt_wpa; unsigned short irt_lifetime; }

user_defined_types: struct icmp_ra_addr { unsigned int ira_addr; unsigned int ira_preference; }

user_defined_types: struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; }


decompiled_code:
void sig_alrm()
{
send_icmp();
alarm(1u);
}

canonical_decompiled_code:
void func13()
{
func12();
alarm(1u);
}

original_code:
void
sig_alrm (int signo)
{
 send_icmp ();
 alarm (1);
 return;
}

canonical_original_code:
void sig_alrm(int signo)
{
 send_icmp ();
 alarm (1);
 return;
}

variable_types: signo int


readloop

decompiled_code:
unsigned int __fastcall readloop(int a1)
{
int v1; // ebx
__uid_t v2; // eax
struct sockaddr *v3; // r8
ssize_t v4; // rax
int v5; // ebp
int optval; // [rsp+8h] [rbp-610h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-60Ch] BYREF
struct timeval tv; // [rsp+10h] [rbp-608h] BYREF
char buf[1528]; // [rsp+20h] [rbp-5F8h] BYREF

v1 = 0;
sockfd = socket(**(unsigned __int16 **)pr, 3, *((_DWORD *)pr + 5));
v2 = getuid();
setuid(v2);
optval = 61440;
setsockopt(sockfd, 1, 8, &optval, 4u);
sig_alrm();
do
{
while ( 1 )
{
v3 = (struct sockaddr *)*((_QWORD *)pr + 1);
addr_len = *((_DWORD *)pr + 4);
v4 = recvfrom(sockfd, buf, 0x5DCuLL, 0, v3, &addr_len);
v5 = v4;
if ( v4 >= 0 )
break;
if ( *__errno_location() != 4 )
{
perror("recvfrom error");
break;
}
}
gettimeofday(&tv, 0LL);
process_icmp(buf, v5, &tv.tv_sec);
}
while ( a1 <= 0 || a1 != ++v1 );
return alarm(0);
}

canonical_decompiled_code:
unsigned int __fastcall func14(int a1)
{
int v1; // ebx
__uid_t v2; // eax
struct sockaddr *v3; // r8
ssize_t v4; // rax
int v5; // ebp
int optval; // [rsp+8h] [rbp-610h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-60Ch] BYREF
struct timeval tv; // [rsp+10h] [rbp-608h] BYREF
char buf[1528]; // [rsp+20h] [rbp-5F8h] BYREF

v1 = 0;
sockfd = socket(**(unsigned __int16 **)pr, 3, *((_DWORD *)pr + 5));
v2 = getuid();
setuid(v2);
optval = 61440;
setsockopt(sockfd, 1, 8, &optval, 4u);
func13();
do
{
while ( 1 )
{
v3 = (struct sockaddr *)*((_QWORD *)pr + 1);
addr_len = *((_DWORD *)pr + 4);
v4 = recvfrom(sockfd, buf, 0x5DCuLL, 0, v3, &addr_len);
v5 = v4;
if ( v4 >= 0 )
break;
if ( *__errno_location() != 4 )
{
perror("recvfrom error");
break;
}
}
gettimeofday(&tv, 0LL);
func10(buf, v5, &tv.tv_sec);
}
while ( a1 <= 0 || a1 != ++v1 );
return alarm(0);
}

original_code:
void
readloop (int count)
{
 int size;
 char recvbuf[1500];
 socklen_t len;
 ssize_t n;
 struct timeval tval;
 int i = 0;
 sockfd = socket (pr->sasend->sa_family, SOCK_RAW, pr->icmpproto);
 setuid (getuid ());
 size = 60 * 1024;
 setsockopt (sockfd, 1, 8, &size, sizeof (size));
 sig_alrm (14);
 for (;;) {
  len = pr->salen;
  n = recvfrom (sockfd, recvbuf, sizeof (recvbuf), 0,
         pr->sarecv, &len);
  if (n < 0) {
   if ((*__errno_location ()) == 4) {
    continue;
    i++;
   } else {
    perror ("recvfrom error");
   }
  }
  gettimeofday (&tval, ((void *)0));
  process_icmp (recvbuf, n, &tval);
  if (count > 0) {
   i++;
   if (i == count) {
    alarm (0);
    break;
   }
  }
 }
}

canonical_original_code:
void readloop(int count)
{
 int size;
 char recvbuf[1500];
 unsigned int len;
 long n;
 struct timeval tval;
 int i = 0;
 sockfd = socket (pr->sasend->sa_family, SOCK_RAW, pr->icmpproto);
 setuid (getuid ());
 size = 60 * 1024;
 setsockopt (sockfd, 1, 8, &size, sizeof (size));
 sig_alrm (14);
 for (;;) {
  len = pr->salen;
  n = recvfrom (sockfd, recvbuf, sizeof (recvbuf), 0,
         pr->sarecv, &len);
  if (n < 0) {
   if ((*__errno_location ()) == 4) {
    continue;
    i++;
   } else {
    perror ("recvfrom error");
   }
  }
  gettimeofday (&tval, ((void *)0));
  process_icmp (recvbuf, n, &tval);
  if (count > 0) {
   i++;
   if (i == count) {
    alarm (0);
    break;
   }
  }
 }
}

variable_types: count int

variable_types: size int

variable_types:
recvbuf
char [1500]

variable_types:
len
unsigned int

variable_types: n long

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

variable_types: i int