decompiled_code:
void __fastcall io_usleep(__useconds_t useconds)
{
unsigned int v1; // eax
__int64 v2; // rax
void (*v3)(void); // rax
__int64 v4; // rax
struct timeval v5; // [rsp-8h] [rbp-28h] BYREF
struct timeval tv; // [rsp+8h] [rbp-18h] BYREF

if ( useconds )
{
v1 = *(_DWORD *)&p[3108];
if ( v1 == 2 )
{
gettimeofday(&tv, 0LL);
do
gettimeofday(&v5, 0LL);
while ( LODWORD(v5.tv_usec) - LODWORD(tv.tv_usec) + (LODWORD(v5.tv_usec) - LODWORD(tv.tv_usec) < 0 ? 0xF4240 : 0) < useconds );
}
else
{
if ( v1 > 2 )
{
if ( v1 != 3 )
return;
goto LABEL_9;
}
if ( v1 )
{
v2 = *(_QWORD *)&p[3160];
if ( v2 )
{
v3 = *(void (**)(void))(v2 + 40);
if ( v3 )
{
LABEL_7:
v3();
return;
}
}
goto LABEL_9;
}
if ( useconds > 9 )
{
if ( useconds > 0x63 )
{
LABEL_9:
usleep(useconds);
return;
}
}
else
{
v4 = *(_QWORD *)&p[3160];
if ( v4 )
{
v3 = *(void (**)(void))(v4 + 40);
if ( v3 )
goto LABEL_7;
}
}
gettimeofday(&tv, 0LL);
do
gettimeofday(&v5, 0LL);
while ( LODWORD(v5.tv_usec) - LODWORD(tv.tv_usec) + (LODWORD(v5.tv_usec) - LODWORD(tv.tv_usec) < 0 ? 0xF4240 : 0) < useconds );
}
}
}

canonical_decompiled_code:
void __fastcall func9(__useconds_t useconds)
{
unsigned int v1; // eax
__int64 v2; // rax
void (*v3)(void); // rax
__int64 v4; // rax
struct timeval v5; // [rsp-8h] [rbp-28h] BYREF
struct timeval tv; // [rsp+8h] [rbp-18h] BYREF

if ( useconds )
{
v1 = *(_DWORD *)&p[3108];
if ( v1 == 2 )
{
gettimeofday(&tv, 0LL);
do
gettimeofday(&v5, 0LL);
while ( LODWORD(v5.tv_usec) - LODWORD(tv.tv_usec) + (LODWORD(v5.tv_usec) - LODWORD(tv.tv_usec) < 0 ? 0xF4240 : 0) < useconds );
}
else
{
if ( v1 > 2 )
{
if ( v1 != 3 )
return;
goto LABEL_9;
}
if ( v1 )
{
v2 = *(_QWORD *)&p[3160];
if ( v2 )
{
v3 = *(void (**)(void))(v2 + 40);
if ( v3 )
{
LABEL_7:
v3();
return;
}
}
goto LABEL_9;
}
if ( useconds > 9 )
{
if ( useconds > 0x63 )
{
LABEL_9:
usleep(useconds);
return;
}
}
else
{
v4 = *(_QWORD *)&p[3160];
if ( v4 )
{
v3 = *(void (**)(void))(v4 + 40);
if ( v3 )
goto LABEL_7;
}
}
gettimeofday(&tv, 0LL);
do
gettimeofday(&v5, 0LL);
while ( LODWORD(v5.tv_usec) - LODWORD(tv.tv_usec) + (LODWORD(v5.tv_usec) - LODWORD(tv.tv_usec) < 0 ? 0xF4240 : 0) < useconds );
}
}
}

original_code:
void
io_usleep(uint32_t n)
{
 struct timeval tv1, tv2;
 int diff;
 if (n == 0)
  return;
 switch (p.sleep_algo) {
 case (0):
  if (n < 10 && p.io && p.io->usleep) {
   p.io->usleep(n);
   return;
  }
  if (n < 100) {
   gettimeofday(&tv1, ((void *)0));
   do {
    gettimeofday(&tv2, ((void *)0));
    diff = tv2.tv_usec - tv1.tv_usec;
    if (diff < 0)
     diff += 1000000;
   }
   while (diff < n);
   return;
  }
  usleep(n);
  break;
 case (1):
  if (p.io && p.io->usleep) {
   p.io->usleep(n);
   return;
  }
 case (3):
  usleep(n);
  break;
 case (2):
  gettimeofday(&tv1, ((void *)0));
  do {
   gettimeofday(&tv2, ((void *)0));
   diff = tv2.tv_usec - tv1.tv_usec;
   if (diff < 0)
    diff += 1000000;
  }
  while (diff < n);
  break;
 }
}

canonical_original_code:
void io_usleep(unsigned int n)
{
 struct timeval tv1; struct timeval tv2;
 int diff;
 if (n == 0)
  return;
 switch (p.sleep_algo) {
 case (0):
  if (n < 10 && p.io && p.io->usleep) {
   p.io->usleep(n);
   return;
  }
  if (n < 100) {
   gettimeofday(&tv1, ((void *)0));
   do {
    gettimeofday(&tv2, ((void *)0));
    diff = tv2.tv_usec - tv1.tv_usec;
    if (diff < 0)
     diff += 1000000;
   }
   while (diff < n);
   return;
  }
  usleep(n);
  break;
 case (1):
  if (p.io && p.io->usleep) {
   p.io->usleep(n);
   return;
  }
 case (3):
  usleep(n);
  break;
 case (2):
  gettimeofday(&tv1, ((void *)0));
  do {
   gettimeofday(&tv2, ((void *)0));
   diff = tv2.tv_usec - tv1.tv_usec;
   if (diff < 0)
    diff += 1000000;
  }
  while (diff < n);
  break;
 }
}

variable_types:
n
unsigned int

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

variable_types: diff int


repo: GBert/openwrt-files

original_code:
void
io_set_pgm(uint8_t pgm)
{
 if (p.io && p.io->set_pgm) {
  if (p.bitrules & (0x00000020))
   pgm = (0x01) - pgm;
  p.io->set_pgm(pgm);
 }
}

canonical_original_code:
void io_set_pgm(unsigned char pgm)
{
 if (p.io && p.io->set_pgm) {
  if (p.bitrules & (0x00000020))
   pgm = (0x01) - pgm;
  p.io->set_pgm(pgm);
 }
}

variable_types:
pgm
unsigned char

return_type: void


decompiled_code:
void __fastcall io_set_vpp(unsigned __int8 a1)
{
__int64 v1; // rdx
unsigned __int8 v2; // al
void (__fastcall *v3)(_QWORD); // rcx

v1 = *(_QWORD *)&p[3160];
if ( v1 )
{
v2 = a1;
v3 = *(void (__fastcall **)(_QWORD))(v1 + 56);
if ( v3 )
{
if ( (p[3092] & 4) != 0 )
v2 = 1 - a1;
v3(v2);
}
}
}

original_code:
void
io_set_vpp(uint8_t vpp)
{
 if (p.io && p.io->set_vpp) {
  if (p.bitrules & (0x00000004))
   vpp = (0x01) - vpp;
  p.io->set_vpp(vpp);
 }
}

canonical_original_code:
void io_set_vpp(unsigned char vpp)
{
 if (p.io && p.io->set_vpp) {
  if (p.bitrules & (0x00000004))
   vpp = (0x01) - vpp;
  p.io->set_vpp(vpp);
 }
}

variable_types:
vpp
unsigned char


original_code:
void
io_close(int run)
{
 if (p.iot == (0))
  return;
 if (p.io != ((void *)0)) {
  if (p.io->release) {
   p.io->release();
  }
  if (p.io->run) {
   if ((p.bitrules & (0x00000800)) == 0) {
    io_usleep(10);
    if (run)
     io_set_vpp((0x01));
    else
     io_set_vpp((0x00));
   }
  }
  if (p.io->close) {
   p.io->close();
  }
  p.io = ((void *)0);
 }
 p.iot = (0);
 io_signal_off();
}

variable_types: run int


decompiled_code:
void __fastcall __noreturn io_exit(int status)
{
fflush(stdout);
if ( p[3168] )
io_close(*(_DWORD *)&p[3092] & 0x1000);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func13(int status)
{
fflush(stdout);
if ( p[3168] )
func12(*(_DWORD *)&p[3092] & 0x1000);
exit(status);
}

original_code:
void
io_exit(int err)
{
 fflush(stdout);
 if (p.iot != (0))
  io_close(p.bitrules & (0x00001000));
 exit(err);
}

variable_types: err int


decompiled_code:
char *io_error()
{
__int64 v0; // rax
__int64 (*v1)(void); // rax
const char *v2; // rax
int v3; // eax

v0 = *(_QWORD *)&p[3160];
if ( v0 && (v1 = *(__int64 (**)(void))(v0 + 32)) != 0LL )
{
v2 = (const char *)v1();
v3 = snprintf(
msg_6,
0x200uLL,
"%s [DEVICE=%s] [IFACE=%s]",
v2,
(const char *)(unsigned int)((_DWORD)p + 1040),
(const char *)(unsigned int)((_DWORD)p + 2576));
}
else
{
v3 = snprintf(
msg_6,
0x200uLL,
"Can't open unsupported I/O [DEVICE=%s] [IFACE=%s].\n\n\tRun `pickle` to list supported backend I/O",
(const char *)(unsigned int)((_DWORD)p + 1040),
(const char *)(unsigned int)((_DWORD)p + 2576));
}
if ( v3 < 0 )
{
printf("%s: fatal error: snprintf failed\n", "io_error");
io_exit(71);
}
if ( v3 > 511 )
{
printf("%s: fatal error: snprintf overrun\n", "io_error");
io_exit(70);
}
return msg_6;
}

canonical_decompiled_code:
char *func14()
{
__int64 v0; // rax
__int64 (*v1)(void); // rax
const char *v2; // rax
int v3; // eax

v0 = *(_QWORD *)&p[3160];
if ( v0 && (v1 = *(__int64 (**)(void))(v0 + 32)) != 0LL )
{
v2 = (const char *)v1();
v3 = snprintf(
msg_6,
0x200uLL,
"%s [DEVICE=%s] [IFACE=%s]",
v2,
(const char *)(unsigned int)((_DWORD)p + 1040),
(const char *)(unsigned int)((_DWORD)p + 2576));
}
else
{
v3 = snprintf(
msg_6,
0x200uLL,
"Can't open unsupported I/O [DEVICE=%s] [IFACE=%s].\n\n\tRun `pickle` to list supported backend I/O",
(const char *)(unsigned int)((_DWORD)p + 1040),
(const char *)(unsigned int)((_DWORD)p + 2576));
}
if ( v3 < 0 )
{
printf("%s: fatal error: snprintf failed\n", "io_error");
func13(71);
}
if ( v3 > 511 )
{
printf("%s: fatal error: snprintf overrun\n", "io_error");
func13(70);
}
return msg_6;
}

original_code:
char *
io_error(void)
{
 static char msg[(512)] = {0};
 int rc;
 if (p.io && p.io->error)
  rc = snprintf(msg, (512), "%s [DEVICE=%s] [IFACE=%s]",
   p.io->error(), p.device, p.iface);
 else
  rc = snprintf(msg, (512), "Can't open unsupported I/O [DEVICE=%s] [IFACE=%s].\n\n"
   "	Run `pickle` to list supported backend I/O", p.device, p.iface);
 if (rc < 0) {
  printf("%s: fatal error: snprintf failed\n", __func__);
  io_exit(71);
 } else if (rc >= (512)) {
  printf("%s: fatal error: snprintf overrun\n", __func__);
  io_exit(70);
 }
 return msg;
}

canonical_original_code:
char *io_error()
{
 static char msg[-1] = {0};
 int rc;
 if (p.io && p.io->error)
  rc = snprintf(msg, (512), "%s [DEVICE=%s] [IFACE=%s]",
   p.io->error(), p.device, p.iface);
 else
  rc = snprintf(msg, (512), "Can't open unsupported I/O [DEVICE=%s] [IFACE=%s].\n\n"
   "	Run `pickle` to list supported backend I/O", p.device, p.iface);
 if (rc < 0) {
  printf("%s: fatal error: snprintf failed\n", __func__);
  io_exit(71);
 } else if (rc >= (512)) {
  printf("%s: fatal error: snprintf overrun\n", __func__);
  io_exit(70);
 }
 return msg;
}

variable_types:
msg
char [-1]

variable_types: rc int

return_type: char *


decompiled_code:
void __fastcall io_set_pgd(unsigned __int8 a1)
{
__int64 v1; // rdx
unsigned __int8 v2; // al
void (__fastcall *v3)(_QWORD); // rcx

v1 = *(_QWORD *)&p[3160];
if ( v1 )
{
v2 = a1;
v3 = *(void (__fastcall **)(_QWORD))(v1 + 64);
if ( v3 )
{
if ( (p[3092] & 1) != 0 )
v2 = 1 - a1;
v3(v2);
}
}
}

original_code:
void
io_set_pgd(uint8_t pgd)
{
 if (p.io && p.io->set_pgd) {
  if (p.bitrules & (0x00000001))
   pgd = (0x01) - pgd;
  p.io->set_pgd(pgd);
 }
}

canonical_original_code:
void io_set_pgd(unsigned char pgd)
{
 if (p.io && p.io->set_pgd) {
  if (p.bitrules & (0x00000001))
   pgd = (0x01) - pgd;
  p.io->set_pgd(pgd);
 }
}

variable_types:
pgd
unsigned char


decompiled_code:
void __fastcall io_set_pgc(unsigned __int8 a1)
{
__int64 v1; // rdx
unsigned __int8 v2; // al
void (__fastcall *v3)(_QWORD); // rcx

v1 = *(_QWORD *)&p[3160];
if ( v1 )
{
v2 = a1;
v3 = *(void (__fastcall **)(_QWORD))(v1 + 72);
if ( v3 )
{
if ( (p[3092] & 2) != 0 )
v2 = 1 - a1;
v3(v2);
}
}
}

original_code:
void
io_set_pgc(uint8_t pgc)
{
 if (p.io && p.io->set_pgc) {
  if (p.bitrules & (0x00000002))
   pgc = (0x01) - pgc;
  p.io->set_pgc(pgc);
 }
}

canonical_original_code:
void io_set_pgc(unsigned char pgc)
{
 if (p.io && p.io->set_pgc) {
  if (p.bitrules & (0x00000002))
   pgc = (0x01) - pgc;
  p.io->set_pgc(pgc);
 }
}

variable_types:
pgc
unsigned char


decompiled_code:
void __fastcall io_clock_bit(__useconds_t useconds, __useconds_t a2)
{
io_set_pgc(1u);
io_usleep(a2);
io_set_pgc(0);
io_usleep(useconds);
}

canonical_decompiled_code:
void __fastcall func17(__useconds_t useconds, __useconds_t a2)
{
func16(1u);
func9(a2);
func16(0);
func9(useconds);
}

original_code:
static inline void
io_clock_bit(uint32_t ldly, uint32_t hdly)
{
 io_set_pgc((0x01));
 io_usleep(hdly);
 io_set_pgc((0x00));
 io_usleep(ldly);
}

canonical_original_code:
static inline void io_clock_bit(unsigned int ldly, unsigned int hdly)
{
 io_set_pgc((0x01));
 io_usleep(hdly);
 io_set_pgc((0x00));
 io_usleep(ldly);
}

variable_types:
ldly
unsigned int

variable_types:
hdly
unsigned int


original_code:
uint8_t
io_get_pgd(void)
{
 uint8_t pgd = 0;
 if (p.io && p.io->get_pgd) {
  pgd = p.io->get_pgd();
  if (p.bitrules & (0x00000008))
   pgd = (0x01) - pgd;
 }
 return pgd;
}

canonical_original_code:
unsigned char io_get_pgd()
{
 unsigned char pgd = 0;
 if (p.io && p.io->get_pgd) {
  pgd = p.io->get_pgd();
  if (p.bitrules & (0x00000008))
   pgd = (0x01) - pgd;
 }
 return pgd;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall io_configure(char a1, char a2)
{
__int64 result; // rax

p[3144] = a1;
p[3145] = a2;
result = *(_QWORD *)&p[3160];
if ( result )
{
result = *(_QWORD *)(result + 88);
if ( result )
result = ((__int64 (*)(void))result)();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(char a1, char a2)
{
__int64 result; // rax

p[3144] = a1;
p[3145] = a2;
result = *(_QWORD *)&p[3160];
if ( result )
{
result = *(_QWORD *)(result + 88);
if ( result )
result = ((__int64 (*)(void))result)();
}
return result;
}

original_code:
void
io_configure(uint8_t clock_falling, uint8_t msb_first)
{
 p.clock_falling = clock_falling;
 p.msb_first = msb_first;
 if (p.io && p.io->configure)
  p.io->configure();
}

canonical_original_code:
void io_configure(unsigned char clock_falling, unsigned char msb_first)
{
 p.clock_falling = clock_falling;
 p.msb_first = msb_first;
 if (p.io && p.io->configure)
  p.io->configure();
}


original_code:
void
io_data_input(void)
{
 if (p.bitrules & (0x00000010)) {
  io_set_pgd((0x01));
 }
 else if (p.bitrules & (0x00000080)) {
  io_set_pgd((0x00));
 }
}

canonical_original_code:
void io_data_input()
{
 if (p.bitrules & (0x00000010)) {
  io_set_pgd((0x01));
 }
 else if (p.bitrules & (0x00000080)) {
  io_set_pgd((0x00));
 }
}


decompiled_code:
__int64 __fastcall io_clock_in_bits(__useconds_t useconds, __useconds_t a2, int a3)
{
unsigned int v4; // ebx
int v5; // er12
unsigned int v6; // ebp

v4 = io_first_mask(a3);
io_data_input();
if ( !(_BYTE)a3 )
return 0;
v5 = a3 - 1;
v6 = 0;
do
{
if ( !p[3144] )
io_clock_bit(useconds, a2);
if ( (unsigned __int8)io_get_pgd() )
v6 |= v4;
if ( p[3144] )
io_clock_bit(useconds, a2);
v4 = io_next_mask(v4);
--v5;
}
while ( (_BYTE)v5 != 0xFF );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func21(__useconds_t useconds, __useconds_t a2, int a3)
{
unsigned int v4; // ebx
int v5; // er12
unsigned int v6; // ebp

v4 = func1(a3);
func20();
if ( !(_BYTE)a3 )
return 0;
v5 = a3 - 1;
v6 = 0;
do
{
if ( !p[3144] )
func17(useconds, a2);
if ( (unsigned __int8)func18() )
v6 |= v4;
if ( p[3144] )
func17(useconds, a2);
v4 = func2(v4);
--v5;
}
while ( (_BYTE)v5 != 0xFF );
return v6;
}

original_code:
uint32_t
io_clock_in_bits(uint32_t ldly, uint32_t hdly, uint8_t nbits)
{
 uint32_t bits = 0, mask = io_first_mask(nbits);
 io_data_input();
 while (nbits--) {
  if (!p.clock_falling)
   io_clock_bit(ldly, hdly);
  if (io_get_pgd())
   bits |= mask;
  if (p.clock_falling)
   io_clock_bit(ldly, hdly);
  mask = io_next_mask(mask);
 }
 return bits;
}

canonical_original_code:
unsigned int io_clock_in_bits(unsigned int ldly, unsigned int hdly, unsigned char nbits)
{
 unsigned int bits = 0; unsigned int mask = io_first_mask(nbits);
 io_data_input();
 while (nbits--) {
  if (!p.clock_falling)
   io_clock_bit(ldly, hdly);
  if (io_get_pgd())
   bits |= mask;
  if (p.clock_falling)
   io_clock_bit(ldly, hdly);
  mask = io_next_mask(mask);
 }
 return bits;
}

variable_types:
nbits
unsigned char

variable_types:
bits
unsigned int

variable_types:
mask
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall io_clock_out_bits(__useconds_t useconds, __useconds_t a2, int a3, int a4)
{
__int64 result; // rax
unsigned int v7; // ebx
int v8; // ebp

result = io_first_mask(a4);
v7 = result;
v8 = a4 - 1;
if ( (_BYTE)a4 )
{
do
{
io_set_pgd((v7 & a3) != 0);
io_clock_bit(useconds, a2);
result = io_next_mask(v7);
v7 = result;
--v8;
}
while ( (_BYTE)v8 != 0xFF );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(__useconds_t useconds, __useconds_t a2, int a3, int a4)
{
__int64 result; // rax
unsigned int v7; // ebx
int v8; // ebp

result = func1(a4);
v7 = result;
v8 = a4 - 1;
if ( (_BYTE)a4 )
{
do
{
func15((v7 & a3) != 0);
func17(useconds, a2);
result = func2(v7);
v7 = result;
--v8;
}
while ( (_BYTE)v8 != 0xFF );
}
return result;
}

original_code:
void
io_clock_out_bits(uint32_t ldly, uint32_t hdly, uint32_t bits, uint8_t nbits)
{
 uint32_t mask = io_first_mask(nbits);
 while (nbits--) {
  io_set_pgd((bits & mask) != 0);
  io_clock_bit(ldly, hdly);
  mask = io_next_mask(mask);
 }
}

canonical_original_code:
void io_clock_out_bits(unsigned int ldly, unsigned int hdly, unsigned int bits, unsigned char nbits)
{
 unsigned int mask = io_first_mask(nbits);
 while (nbits--) {
  io_set_pgd((bits & mask) != 0);
  io_clock_bit(ldly, hdly);
  mask = io_next_mask(mask);
 }
}


decompiled_code:
__int64 __fastcall io_clock_bit_4phase(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned int v2; // ebx

io_set_pgd(a2);
io_clock_bit(*(_DWORD *)&p[3100], *(_DWORD *)&p[3104]);
io_set_pgd(a1);
io_clock_bit(*(_DWORD *)&p[3100], *(_DWORD *)&p[3104]);
io_data_input();
io_get_pgd();
io_clock_bit(*(_DWORD *)&p[3100], *(_DWORD *)&p[3104]);
v2 = io_get_pgd();
io_clock_bit(*(_DWORD *)&p[3100], *(_DWORD *)&p[3104]);
return v2;
}

original_code:
uint8_t
io_clock_bit_4phase(uint8_t tms, uint8_t tdi)
{
 uint8_t tdo;
 io_set_pgd(tdi);
 io_clock_bit(p.sleep_low, p.sleep_high);
 io_set_pgd(tms);
 io_clock_bit(p.sleep_low, p.sleep_high);
 io_data_input();
 io_get_pgd();
 io_clock_bit(p.sleep_low, p.sleep_high);
 tdo = io_get_pgd();
 io_clock_bit(p.sleep_low, p.sleep_high);
 return tdo;
}

canonical_original_code:
unsigned char io_clock_bit_4phase(unsigned char tms, unsigned char tdi)
{
 unsigned char tdo;
 io_set_pgd(tdi);
 io_clock_bit(p.sleep_low, p.sleep_high);
 io_set_pgd(tms);
 io_clock_bit(p.sleep_low, p.sleep_high);
 io_data_input();
 io_get_pgd();
 io_clock_bit(p.sleep_low, p.sleep_high);
 tdo = io_get_pgd();
 io_clock_bit(p.sleep_low, p.sleep_high);
 return tdo;
}

variable_types:
tms
unsigned char

variable_types:
tdi
unsigned char

variable_types:
tdo
unsigned char


decompiled_code:
unsigned int __fastcall io_program_feedback(char a1)
{
unsigned int result; // eax
char v2; // al

if ( c_last_3 != a1 || (result = c_count_2, ++c_count_2, result > *(_DWORD *)&p[3096]) )
{
v2 = a_count_1++;
result = fprintf(stderr, "%c[%c]\r", (unsigned int)arrow_0[v2 & 3], (unsigned int)a1);
c_last_3 = a1;
c_count_2 = 0;
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func24(char a1)
{
unsigned int result; // eax
char v2; // al

if ( c_last_3 != a1 || (result = c_count_2, ++c_count_2, result > *(_DWORD *)&p[3096]) )
{
v2 = a_count_1++;
result = fprintf(stderr, "%c[%c]\r", (unsigned int)arrow_0[v2 & 3], (unsigned int)a1);
c_last_3 = a1;
c_count_2 = 0;
}
return result;
}

original_code:
void
io_program_feedback(char c)
{
 static int c_count = 0, a_count = 0;
 static const char arrow[] = "|/-\\";
 static char c_last = 0;
 if ((c_last != c) || (c_count++ > p.busy)) {
  fprintf(stderr, "%c[%c]\r", arrow[a_count++ % strlen(arrow)], c);
  c_last = c;
  c_count = 0;
 }
}

canonical_original_code:
void io_program_feedback(char c)
{
 static int c_count = 0; static int a_count = 0;
 static char arrow[] = "|/-\\";
 static char c_last = 0;
 if ((c_last != c) || (c_count++ > p.busy)) {
  fprintf(stderr, "%c[%c]\r", arrow[a_count++ % strlen(arrow)], c);
  c_last = c;
  c_count = 0;
 }
}

variable_types: c char

variable_types:
arrow
char []


decompiled_code:
__int64 __fastcall io_clock_bits_4phase(unsigned __int8 a1, unsigned int a2, unsigned int a3)
{
int v4; // ebx
unsigned int v5; // ebp

if ( *(_DWORD *)&p[3096] )
io_program_feedback(43);
if ( !a1 )
return 0;
v4 = 0;
v5 = 0;
do
{
v5 |= (unsigned __int8)io_clock_bit_4phase((a2 >> v4) & 1, (a3 >> v4) & 1) << v4;
++v4;
}
while ( v4 != a1 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func25(unsigned __int8 a1, unsigned int a2, unsigned int a3)
{
int v4; // ebx
unsigned int v5; // ebp

if ( *(_DWORD *)&p[3096] )
func24(43);
if ( !a1 )
return 0;
v4 = 0;
v5 = 0;
do
{
v5 |= (unsigned __int8)func23((a2 >> v4) & 1, (a3 >> v4) & 1) << v4;
++v4;
}
while ( v4 != a1 );
return v5;
}

original_code:
uint32_t
io_clock_bits_4phase(uint8_t nbits, uint32_t tms, uint32_t tdi)
{
 uint32_t tdo = 0;
 if (p.busy)
  io_program_feedback('+');
 for (uint32_t i = 0; i < nbits; ++i)
  tdo |= io_clock_bit_4phase((tms >> i) & 1, (tdi >> i) & 1) << i;
 return tdo;
}

canonical_original_code:
unsigned int io_clock_bits_4phase(unsigned char nbits, unsigned int tms, unsigned int tdi)
{
 unsigned int tdo = 0;
 if (p.busy)
  io_program_feedback('+');
 for (unsigned int i = 0; i < nbits; ++i)
  tdo |= io_clock_bit_4phase((tms >> i) & 1, (tdi >> i) & 1) << i;
 return tdo;
}

variable_types:
tms
unsigned int

variable_types:
tdi
unsigned int

variable_types:
tdo
unsigned int

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall io_program_in(unsigned __int8 a1)
{
__int64 v1; // rax
__int64 (__fastcall *v2)(_QWORD); // rax
__int64 result; // rax

if ( *(_DWORD *)&p[3096] )
io_program_feedback(105);
v1 = *(_QWORD *)&p[3160];
if ( v1 && (v2 = *(__int64 (__fastcall **)(_QWORD))(v1 + 96)) != 0LL )
result = v2(a1);
else
result = io_clock_in_bits(*(_DWORD *)&p[3100], *(_DWORD *)&p[3104], a1);
return result;
}

original_code:
uint32_t
io_program_in(uint8_t nbits)
{
 if (p.busy)
  io_program_feedback('i');
 if (p.io && p.io->shift_in)
  return p.io->shift_in(nbits);
 return io_clock_in_bits(p.sleep_low, p.sleep_high, nbits);
}

canonical_original_code:
unsigned int io_program_in(unsigned char nbits)
{
 if (p.busy)
  io_program_feedback('i');
 if (p.io && p.io->shift_in)
  return p.io->shift_in(nbits);
 return io_clock_in_bits(p.sleep_low, p.sleep_high, nbits);
}


decompiled_code:
__int64 __fastcall io_program_out(unsigned int a1, unsigned __int8 a2)
{
__int64 v2; // rax
__int64 (__fastcall *v3)(_QWORD, _QWORD); // rax
__int64 result; // rax

if ( *(_DWORD *)&p[3096] )
io_program_feedback(111);
v2 = *(_QWORD *)&p[3160];
if ( v2 && (v3 = *(__int64 (__fastcall **)(_QWORD, _QWORD))(v2 + 104)) != 0LL )
result = v3(a1, a2);
else
result = io_clock_out_bits(*(_DWORD *)&p[3100], *(_DWORD *)&p[3104], a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func27(unsigned int a1, unsigned __int8 a2)
{
__int64 v2; // rax
__int64 (__fastcall *v3)(_QWORD, _QWORD); // rax
__int64 result; // rax

if ( *(_DWORD *)&p[3096] )
func24(111);
v2 = *(_QWORD *)&p[3160];
if ( v2 && (v3 = *(__int64 (__fastcall **)(_QWORD, _QWORD))(v2 + 104)) != 0LL )
result = v3(a1, a2);
else
result = func22(*(_DWORD *)&p[3100], *(_DWORD *)&p[3104], a1, a2);
return result;
}

original_code:
void
io_program_out(uint32_t bits, uint8_t nbits)
{
 if (p.busy)
  io_program_feedback('o');
 if (p.io && p.io->shift_out)
  p.io->shift_out(bits, nbits);
 else
  io_clock_out_bits(p.sleep_low, p.sleep_high, bits, nbits);
}

canonical_original_code:
void io_program_out(unsigned int bits, unsigned char nbits)
{
 if (p.busy)
  io_program_feedback('o');
 if (p.io && p.io->shift_out)
  p.io->shift_out(bits, nbits);
 else
  io_clock_out_bits(p.sleep_low, p.sleep_high, bits, nbits);
}


decompiled_code:
const char *gpio_bb_error()
{
return "Can't open GPIO BIT-BANG I/O";
}

canonical_decompiled_code:
const char *func0()
{
return "Can't open GPIO BIT-BANG I/O";
}

original_code:
char *
gpio_bb_error(void)
{
 return "Can't open GPIO BIT-BANG I/O";
}


decompiled_code:
__int64 gpio_bb_open()
{
fd = open((const char *)(unsigned int)((_DWORD)&p + 2576), 2);
if ( fd >= 0 )
return 0LL;
fd = -1;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
fd = open((const char *)(unsigned int)((_DWORD)&p + 2576), 2);
if ( fd >= 0 )
return 0LL;
fd = -1;
return 0xFFFFFFFFLL;
}

original_code:
int
gpio_bb_open(void)
{
 fd = open(p.iface, 02);
 if (fd < 0) {
  fd = -1;
  return -1;
 }
 return 0;
}

canonical_original_code:
int gpio_bb_open()
{
 fd = open(p.iface, 02);
 if (fd < 0) {
  fd = -1;
  return -1;
 }
 return 0;
}

return_type: int


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

result = close(fd);
fd = -1;
return result;
}

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

result = close(fd);
fd = -1;
return result;
}

original_code:
void
gpio_bb_close(void)
{
 close(fd);
 fd = -1;
}

canonical_original_code:
void gpio_bb_close()
{
 close(fd);
 fd = -1;
}


decompiled_code:
int __fastcall gpio_bb_set_pgm(char a1)
{
int result; // eax
__int16 v2; // [rsp+0h] [rbp-Ch] BYREF
char v3; // [rsp+2h] [rbp-Ah]
char v4; // [rsp+3h] [rbp-9h]

result = *((unsigned __int16 *)&p + 1568);
if ( (_WORD)result != 0xFFFF )
{
v2 = *((_WORD *)&p + 1568);
v3 = 0;
v4 = a1;
result = ioctl(fd, 0xC008B4CDuLL, &v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(char a1)
{
int result; // eax
__int16 v2; // [rsp+0h] [rbp-Ch] BYREF
char v3; // [rsp+2h] [rbp-Ah]
char v4; // [rsp+3h] [rbp-9h]

result = *((unsigned __int16 *)&p + 1568);
if ( (_WORD)result != 0xFFFF )
{
v2 = *((_WORD *)&p + 1568);
v3 = 0;
v4 = a1;
result = ioctl(fd, 0xC008B4CDuLL, &v2);
}
return result;
}

variable_types:
pgm
unsigned char

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


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

v2 = *((_WORD *)&p + 1564);
v3 = 0;
v4 = a1;
return ioctl(fd, 0xC008B4CDuLL, &v2);
}

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

v2 = *((_WORD *)&p + 1564);
v3 = 0;
v4 = a1;
return ioctl(fd, 0xC008B4CDuLL, &v2);
}

variable_types:
vpp
unsigned char

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


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

v2 = *((_WORD *)&p + 1566);
v3 = 0;
v4 = a1;
return ioctl(fd, 0xC008B4CDuLL, &v2);
}

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

v2 = *((_WORD *)&p + 1566);
v3 = 0;
v4 = a1;
return ioctl(fd, 0xC008B4CDuLL, &v2);
}

variable_types:
pgd
unsigned char


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

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

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

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

variable_types:
pgc
unsigned char


decompiled_code:
__int64 gpio_bb_get_pgd()
{
__int16 v1; // [rsp+Ch] [rbp-Ch] BYREF
char v2; // [rsp+Eh] [rbp-Ah]
unsigned __int8 v3; // [rsp+Fh] [rbp-9h]

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

canonical_decompiled_code:
__int64 func7()
{
__int16 v1; // [rsp+Ch] [rbp-Ch] BYREF
char v2; // [rsp+Eh] [rbp-Ah]
unsigned __int8 v3; // [rsp+Fh] [rbp-9h]

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


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; }


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[0] = 1;
v2[1] = a1;
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[0] = 1;
v2[1] = a1;
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; }


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[0] = 0;
v3[1] = a2;
v4 = a1;
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[0] = 0;
v3[1] = a2;
v4 = a1;
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; // [rsp+Ch] [rbp-Ch] BYREF
char v3; // [rsp+Eh] [rbp-Ah]
char v4; // [rsp+Fh] [rbp-9h]

v2 = a1;
v3 = 1;
v4 = 0;
return ioctl(fd, 0xC008B4CDuLL, &v2);
}

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

v2 = a1;
v3 = 1;
v4 = 0;
return ioctl(fd, 0xC008B4CDuLL, &v2);
}

variable_types:
pin
unsigned short


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 )
{
puts("PGD LOW (ICSP 4) (D-SUB-9 DTR 3) [3 seconds]");
io_set_pgd(0LL);
if ( io_stop )
{
LABEL_21:
printf("PGD HIGH (ICSP 4) (D-SUB-9 DTR 3) [%d seconds]\n", a2);
io_set_pgd(1LL);
goto LABEL_15;
}
goto LABEL_9;
}
if ( a1 > 2 )
{
if ( a1 == 3 )
{
puts("PGM LOW [3 seconds]");
io_set_pgm(0LL);
if ( io_stop )
goto LABEL_11;
}
else if ( io_stop )
{
goto LABEL_33;
}
goto LABEL_9;
}
if ( !a1 )
{
puts("VPP LOW (ICSP 1) (D-SUB-9 TX 3) [3 seconds]");
io_set_vpp(0LL);
if ( io_stop )
{
LABEL_14:
printf("VPP HIGH (ICSP 1) (D-SUB-9 TX 3) [%d seconds]\n", a2);
io_set_vpp(1LL);
goto LABEL_15;
}
goto LABEL_9;
}
if ( a1 == 1 )
{
puts("PGC LOW (ICSP 5) (D-SUB-9 RTS 7) [3 seconds]");
io_set_pgc(0LL);
if ( io_stop )
{
LABEL_6:
printf("PGC HIGH (ICSP 5) (D-SUB-9 RTS 7) [%d seconds]\n", a2);
io_set_pgc(1LL);
goto LABEL_15;
}
goto LABEL_9;
}
if ( !io_stop )
LABEL_9:
sleep(3u);
if ( a1 == 3 )
{
LABEL_11:
printf("PGM HIGH [%d seconds]\n", a2);
io_set_pgm(1LL);
if ( !io_stop )
{
sleep(a2);
LABEL_31:
puts("PGM LOW [3 seconds]");
io_set_pgm(0LL);
goto LABEL_26;
}
goto LABEL_16;
}
LABEL_33:
if ( a1 <= 3 )
{
if ( a1 == 1 )
goto LABEL_6;
if ( a1 != 2 )
{
if ( a1 )
{
if ( io_stop )
return puts("\nTEST DONE\n");
goto LABEL_38;
}
goto LABEL_14;
}
goto LABEL_21;
}
LABEL_15:
if ( io_stop )
{
LABEL_16:
if ( a1 != 2 )
{
if ( a1 <= 2 )
{
if ( a1 )
{
LABEL_19:
puts("PGC LOW (ICSP 5) (D-SUB-9 RTS 7) [3 seconds]");
io_set_pgc(0LL);
goto LABEL_26;
}
goto LABEL_25;
}
if ( a1 != 3 )
return puts("\nTEST DONE\n");
goto LABEL_31;
}
LABEL_29:
puts("PGD LOW (ICSP 4) (D-SUB-9 DTR 3) [3 seconds]");
io_set_pgd(0LL);
goto LABEL_26;
}
LABEL_38:
sleep(a2);
if ( a1 == 2 )
goto LABEL_29;
if ( a1 <= 2 )
{
if ( !a1 )
{
LABEL_25:
puts("VPP LOW (ICSP 1) (D-SUB-9 TX 3) [3 seconds]");
io_set_vpp(0LL);
goto LABEL_26;
}
if ( a1 == 1 )
goto LABEL_19;
}
LABEL_26:
if ( !io_stop )
sleep(3u);
return puts("\nTEST DONE\n");
}

canonical_decompiled_code:
int __fastcall func2(int a1, unsigned int a2)
{
puts("\nTEST VPP|PGD|PGC|PGM OUTPUT\n");
if ( a1 == 2 )
{
puts("PGD LOW (ICSP 4) (D-SUB-9 DTR 3) [3 seconds]");
io_set_pgd(0LL);
if ( io_stop )
{
LABEL_21:
printf("PGD HIGH (ICSP 4) (D-SUB-9 DTR 3) [%d seconds]\n", a2);
io_set_pgd(1LL);
goto LABEL_15;
}
goto LABEL_9;
}
if ( a1 > 2 )
{
if ( a1 == 3 )
{
puts("PGM LOW [3 seconds]");
io_set_pgm(0LL);
if ( io_stop )
goto LABEL_11;
}
else if ( io_stop )
{
goto LABEL_33;
}
goto LABEL_9;
}
if ( !a1 )
{
puts("VPP LOW (ICSP 1) (D-SUB-9 TX 3) [3 seconds]");
io_set_vpp(0LL);
if ( io_stop )
{
LABEL_14:
printf("VPP HIGH (ICSP 1) (D-SUB-9 TX 3) [%d seconds]\n", a2);
io_set_vpp(1LL);
goto LABEL_15;
}
goto LABEL_9;
}
if ( a1 == 1 )
{
puts("PGC LOW (ICSP 5) (D-SUB-9 RTS 7) [3 seconds]");
io_set_pgc(0LL);
if ( io_stop )
{
LABEL_6:
printf("PGC HIGH (ICSP 5) (D-SUB-9 RTS 7) [%d seconds]\n", a2);
io_set_pgc(1LL);
goto LABEL_15;
}
goto LABEL_9;
}
if ( !io_stop )
LABEL_9:
sleep(3u);
if ( a1 == 3 )
{
LABEL_11:
printf("PGM HIGH [%d seconds]\n", a2);
io_set_pgm(1LL);
if ( !io_stop )
{
sleep(a2);
LABEL_31:
puts("PGM LOW [3 seconds]");
io_set_pgm(0LL);
goto LABEL_26;
}
goto LABEL_16;
}
LABEL_33:
if ( a1 <= 3 )
{
if ( a1 == 1 )
goto LABEL_6;
if ( a1 != 2 )
{
if ( a1 )
{
if ( io_stop )
return puts("\nTEST DONE\n");
goto LABEL_38;
}
goto LABEL_14;
}
goto LABEL_21;
}
LABEL_15:
if ( io_stop )
{
LABEL_16:
if ( a1 != 2 )
{
if ( a1 <= 2 )
{
if ( a1 )
{
LABEL_19:
puts("PGC LOW (ICSP 5) (D-SUB-9 RTS 7) [3 seconds]");
io_set_pgc(0LL);
goto LABEL_26;
}
goto LABEL_25;
}
if ( a1 != 3 )
return puts("\nTEST DONE\n");
goto LABEL_31;
}
LABEL_29:
puts("PGD LOW (ICSP 4) (D-SUB-9 DTR 3) [3 seconds]");
io_set_pgd(0LL);
goto LABEL_26;
}
LABEL_38:
sleep(a2);
if ( a1 == 2 )
goto LABEL_29;
if ( a1 <= 2 )
{
if ( !a1 )
{
LABEL_25:
puts("VPP LOW (ICSP 1) (D-SUB-9 TX 3) [3 seconds]");
io_set_vpp(0LL);
goto LABEL_26;
}
if ( a1 == 1 )
goto LABEL_19;
}
LABEL_26:
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 func3(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 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 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 func5(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 func6(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; // er14
int v2; // er13
int v3; // ebp
unsigned __int8 v4; // bl
__int64 v6[2]; // [rsp+0h] [rbp-228h] BYREF
char v7[496]; // [rsp+10h] [rbp-218h] BYREF

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

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

v6[0] = 0LL;
v6[1] = 0LL;
memset(v7, 0, sizeof(v7));
puts("\nTEST 16F627 debug.asm [CTRL-C TO STOP]\n");
io_data_input();
v1 = io_stop;
if ( !io_stop )
{
v2 = 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 ( (unsigned __int8)io_get_pgd() )
{
if ( io_stop )
{
v3 = 8;
v4 = 0;
goto LABEL_12;
}
io_usleep(1LL);
}
v3 = 8;
v4 = 0;
do
{
LABEL_12:
io_set_pgc(0LL);
io_usleep(a1);
v4 >>= 1;
if ( (unsigned __int8)io_get_pgd() )
v4 |= 0x80u;
io_set_pgc(1LL);
io_usleep(a1);
--v3;
}
while ( v3 );
if ( (unsigned __int8)(v4 - 32) <= 0x5Eu )
break;
printf("%s: read byte: %02X %c\n", "test_debug", v4, 46LL);
if ( v4 != 3 )
goto LABEL_24;
if ( v2 <= 1 )
{
v2 = v1;
}
else
{
if ( LOBYTE(v6[0]) == 2 )
{
*((_BYTE *)v6 + v2) = 0;
printf("%s: read line: %s", "test_debug", (const char *)v6 + 1);
}
v2 = v1;
}
LABEL_26:
if ( io_stop )
return puts("\nTEST DONE\n");
}
printf("%s: read byte: %02X %c\n", "test_debug", v4, v4);
LABEL_24:
if ( v2 <= 510 )
*((_BYTE *)v6 + v2++) = v4;
goto LABEL_26;
}
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; // eax
unsigned int v3; // ebx
const char *v4; // rax
char v6[42]; // [rsp+Eh] [rbp-2Ah] BYREF

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

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

puts("\nTEST ICSPIO [CTRL-C TO STOP]\n");
io_set_vpp(0LL);
io_usleep(10000LL);
io_set_vpp(1LL);
io_usleep(10000LL);
v1 = 0;
while ( !io_stop )
{
v6[0] = 1;
v6[1] = v1;
v2 = icspio_command(a1, 2 * a1, v6, 1LL, 0LL, 0LL);
v3 = v2;
if ( !v2 )
{
v2 = icspio_switch(a1);
v3 = v2;
if ( !v2 )
{
v2 = icspio_lasterror(a1);
v3 = v2;
++v1;
if ( !v2 )
continue;
}
}
v4 = (const char *)icspio_err(v2);
fprintf(stderr, "%s: error: %s [0x%02X]\n", "test_icspio", v4, v3);
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; // r13
int v3; // ebx
__int64 v4; // r15
__int64 v5; // rbx
int v6; // er12
int v7; // ebp
int v9; // [rsp+Ch] [rbp-4Ch]
int v10; // [rsp+10h] [rbp-48h]
int v11; // [rsp+14h] [rbp-44h]

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

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

v2 = s;
v3 = strlen(a2);
v10 = v3;
v11 = strlen(s) - v3;
if ( v11 < 0 )
return 0LL;
v9 = 0;
v4 = (unsigned int)(v3 - 1);
do
{
v5 = 0LL;
v6 = 0;
if ( v10 > 0 )
{
while ( 1 )
{
v6 = v5;
v7 = tolower(v2[v5]);
if ( v7 != tolower(a2[v5]) )
break;
v6 = v5 + 1;
if ( v4 == v5 )
break;
++v5;
}
}
if ( v10 == v6 )
return &s[v9];
++v9;
++v2;
}
while ( v11 >= v9 );
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


decompiled_code:
__int64 __fastcall os_semaphore_create(__int64 a1)
{
*(_DWORD *)(a1 + 88) = 0;
if ( pthread_mutex_init((pthread_mutex_t *)a1, 0LL) == -1 )
exit(-1);
if ( 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 )
exit(-1);
if ( 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; } *

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 )
exit(-1);
if ( 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 )
exit(-1);
if ( 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 )
exit(-1);
while ( 1 )
{
v1 = mutex[2].__owner;
if ( v1 > 0 )
break;
if ( pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex) == -1 )
exit(-1);
}
mutex[2].__owner = v1 - 1;
if ( pthread_mutex_unlock(mutex) == -1 )
exit(-1);
return 1LL;
}

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

if ( pthread_mutex_lock(mutex) == -1 )
exit(-1);
while ( 1 )
{
v1 = mutex[2].__owner;
if ( v1 > 0 )
break;
if ( pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex) == -1 )
exit(-1);
}
mutex[2].__owner = v1 - 1;
if ( pthread_mutex_unlock(mutex) == -1 )
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 )
exit(-1);
++mutex[2].__owner;
if ( pthread_mutex_unlock(mutex) == -1 )
exit(-1);
if ( 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 )
exit(-1);
++mutex[2].__owner;
if ( pthread_mutex_unlock(mutex) == -1 )
exit(-1);
if ( 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;
}


search

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

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

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

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

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 *


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]


mystrlen

decompiled_code:
__int64 __fastcall mystrlen(__int64 a1)
{
const unsigned __int16 *v1; // rsi
__int64 i; // rdx
char v3; // al

if ( !a1 )
return 0LL;
v1 = *_ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v3 = *(_BYTE *)(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; // rsi
__int64 i; // rdx
char v3; // al

if ( !a1 )
return 0LL;
v1 = *_ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v3 = *(_BYTE *)(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(void *dest, void *src, size_t n)
{
char *result; // rax

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

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

if ( src == 0LL || n == 0 || !dest )
return 0LL;
if ( n - 1 > strlen((const char *)src) )
return strncpy((char *)dest, (const char *)src, n);
result = (char *)memcpy(dest, src, n - 1);
*((char *)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, void *a3, ...)
{
size_t v4; // rbx
char *v5; // rbp
unsigned int v6; // ebx
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;
freeArray1D(v5);
v6 = -1;
}
else
{
v6 = vsprintf(s, v5, arg);
freeArray1D(v5);
}
return v6;
}

canonical_decompiled_code:
__int64 func4(char *s, size_t a2, void *a3, ...)
{
size_t v4; // rbx
char *v5; // rbp
unsigned int v6; // ebx
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;
freeArray1D(v5);
v6 = -1;
}
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(void *a1, ...)
{
size_t v1; // r12
char *v2; // rbx
unsigned int v3; // ebp
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(void *a1, ...)
{
size_t v1; // r12
char *v2; // rbx
unsigned int v3; // ebp
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:
void *__fastcall align_malloc(size_t a1)
{
return malloc(a1);
}

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

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:
void __fastcall align_free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

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 func0(_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 func1(__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; }