ttykeymapinit

decompiled_code:
int ttykeymapinit()
{
char **v0; // rax
char *v1; // rax
__int64 v2; // rax
char **v3; // rax
const char *v4; // rdi

if ( *((_QWORD *)cur_term->type.Strings + 79) )
dobindkey(fundamental_mode, "backward-char");
if ( *((_QWORD *)cur_term->type.Strings + 83) )
dobindkey(fundamental_mode, "forward-char");
if ( *((_QWORD *)cur_term->type.Strings + 87) )
dobindkey(fundamental_mode, "previous-line");
if ( *((_QWORD *)cur_term->type.Strings + 61) )
dobindkey(fundamental_mode, "next-line");
v0 = cur_term->type.Strings;
if ( v0[158] || v0[76] )
dobindkey(fundamental_mode, "beginning-of-line");
if ( *((_QWORD *)cur_term->type.Strings + 164) )
dobindkey(fundamental_mode, "end-of-line");
if ( *((_QWORD *)cur_term->type.Strings + 81) )
dobindkey(fundamental_mode, "scroll-up");
if ( *((_QWORD *)cur_term->type.Strings + 82) )
dobindkey(fundamental_mode, "scroll-down");
if ( *((_QWORD *)cur_term->type.Strings + 59) )
dobindkey(fundamental_mode, "delete-char");
v1 = getenv("TERM");
if ( v1 )
{
v2 = startupfile(v1);
if ( v2 )
{
if ( (unsigned int)load(v2) != 1 )
ewprintf("Error reading key initialization file");
}
}
v3 = cur_term->type.Strings;
v4 = v3[89];
if ( v4 )
LODWORD(v3) = tputs(v4, 1, (int (*)(int))&ttputc);
return (int)v3;
}

canonical_decompiled_code:
int func0()
{
char **v0; // rax
char *v1; // rax
__int64 v2; // rax
char **v3; // rax
const char *v4; // rdi

if ( *((_QWORD *)cur_term->type.Strings + 79) )
dobindkey(fundamental_mode, "backward-char");
if ( *((_QWORD *)cur_term->type.Strings + 83) )
dobindkey(fundamental_mode, "forward-char");
if ( *((_QWORD *)cur_term->type.Strings + 87) )
dobindkey(fundamental_mode, "previous-line");
if ( *((_QWORD *)cur_term->type.Strings + 61) )
dobindkey(fundamental_mode, "next-line");
v0 = cur_term->type.Strings;
if ( v0[158] || v0[76] )
dobindkey(fundamental_mode, "beginning-of-line");
if ( *((_QWORD *)cur_term->type.Strings + 164) )
dobindkey(fundamental_mode, "end-of-line");
if ( *((_QWORD *)cur_term->type.Strings + 81) )
dobindkey(fundamental_mode, "scroll-up");
if ( *((_QWORD *)cur_term->type.Strings + 82) )
dobindkey(fundamental_mode, "scroll-down");
if ( *((_QWORD *)cur_term->type.Strings + 59) )
dobindkey(fundamental_mode, "delete-char");
v1 = getenv("TERM");
if ( v1 )
{
v2 = startupfile(v1);
if ( v2 )
{
if ( (unsigned int)load(v2) != 1 )
ewprintf("Error reading key initialization file");
}
}
v3 = cur_term->type.Strings;
v4 = v3[89];
if ( v4 )
LODWORD(v3) = tputs(v4, 1, (int (*)(int))&ttputc);
return (int)v3;
}

original_code:
void
ttykeymapinit(void)
{
 char *cp;
 if (((TERMTYPE *)(cur_term))-> Strings[79])
  dobindkey((fundamental_mode.p_map), "backward-char", ((TERMTYPE *)(cur_term))-> Strings[79]);
 if (((TERMTYPE *)(cur_term))-> Strings[83])
  dobindkey((fundamental_mode.p_map), "forward-char", ((TERMTYPE *)(cur_term))-> Strings[83]);
 if (((TERMTYPE *)(cur_term))-> Strings[87])
  dobindkey((fundamental_mode.p_map), "previous-line", ((TERMTYPE *)(cur_term))-> Strings[87]);
 if (((TERMTYPE *)(cur_term))-> Strings[61])
  dobindkey((fundamental_mode.p_map), "next-line", ((TERMTYPE *)(cur_term))-> Strings[61]);
 if (((TERMTYPE *)(cur_term))-> Strings[158])
  dobindkey((fundamental_mode.p_map), "beginning-of-line", ((TERMTYPE *)(cur_term))-> Strings[158]);
 else if (((TERMTYPE *)(cur_term))-> Strings[76])
  dobindkey((fundamental_mode.p_map), "beginning-of-line", ((TERMTYPE *)(cur_term))-> Strings[76]);
 if (((TERMTYPE *)(cur_term))-> Strings[164])
  dobindkey((fundamental_mode.p_map), "end-of-line", ((TERMTYPE *)(cur_term))-> Strings[164]);
 if (((TERMTYPE *)(cur_term))-> Strings[81])
  dobindkey((fundamental_mode.p_map), "scroll-up", ((TERMTYPE *)(cur_term))-> Strings[81]);
 if (((TERMTYPE *)(cur_term))-> Strings[82])
  dobindkey((fundamental_mode.p_map), "scroll-down", ((TERMTYPE *)(cur_term))-> Strings[82]);
 if (((TERMTYPE *)(cur_term))-> Strings[59])
  dobindkey((fundamental_mode.p_map), "delete-char", ((TERMTYPE *)(cur_term))-> Strings[59]);
 if ((cp = getenv("TERM"))) {
  if (((cp = startupfile(cp)) != ((void *)0)) && (load(cp) != 1))
   ewprintf("Error reading key initialization file");
 }
 if (((TERMTYPE *)(cur_term))-> Strings[89])
  tputs(((TERMTYPE *)(cur_term))-> Strings[89], 1, ttputc);
}

canonical_original_code:
void ttykeymapinit()
{
 char *cp;
 if (((struct termtype *)(cur_term))-> Strings[79])
  dobindkey((fundamental_mode.p_map), "backward-char", ((struct termtype *)(cur_term))-> Strings[79]);
 if (((struct termtype *)(cur_term))-> Strings[83])
  dobindkey((fundamental_mode.p_map), "forward-char", ((struct termtype *)(cur_term))-> Strings[83]);
 if (((struct termtype *)(cur_term))-> Strings[87])
  dobindkey((fundamental_mode.p_map), "previous-line", ((struct termtype *)(cur_term))-> Strings[87]);
 if (((struct termtype *)(cur_term))-> Strings[61])
  dobindkey((fundamental_mode.p_map), "next-line", ((struct termtype *)(cur_term))-> Strings[61]);
 if (((struct termtype *)(cur_term))-> Strings[158])
  dobindkey((fundamental_mode.p_map), "beginning-of-line", ((struct termtype *)(cur_term))-> Strings[158]);
 else if (((struct termtype *)(cur_term))-> Strings[76])
  dobindkey((fundamental_mode.p_map), "beginning-of-line", ((struct termtype *)(cur_term))-> Strings[76]);
 if (((struct termtype *)(cur_term))-> Strings[164])
  dobindkey((fundamental_mode.p_map), "end-of-line", ((struct termtype *)(cur_term))-> Strings[164]);
 if (((struct termtype *)(cur_term))-> Strings[81])
  dobindkey((fundamental_mode.p_map), "scroll-up", ((struct termtype *)(cur_term))-> Strings[81]);
 if (((struct termtype *)(cur_term))-> Strings[82])
  dobindkey((fundamental_mode.p_map), "scroll-down", ((struct termtype *)(cur_term))-> Strings[82]);
 if (((struct termtype *)(cur_term))-> Strings[59])
  dobindkey((fundamental_mode.p_map), "delete-char", ((struct termtype *)(cur_term))-> Strings[59]);
 if ((cp = getenv("TERM"))) {
  if (((cp = startupfile(cp)) != ((void *)0)) && (load(cp) != 1))
   ewprintf("Error reading key initialization file");
 }
 if (((struct termtype *)(cur_term))-> Strings[89])
  tputs(((struct termtype *)(cur_term))-> Strings[89], 1, ttputc);
}

variable_types:
cp
char *

user_defined_types: struct termtype { char *term_names; char *str_table; char *Booleans; short *Numbers; char **Strings; char *ext_str_table; char **ext_Names; unsigned short num_Booleans; unsigned short num_Numbers; unsigned short num_Strings; unsigned short ext_Booleans; unsigned short ext_Numbers; unsigned short ext_Strings; }


ttykeymaptidy

repo: scott-parker/mg-openbsd

decompiled_code:
int ttykeymaptidy()
{
char **v0; // rax
const char *v1; // rdi

v0 = cur_term->type.Strings;
v1 = v0[88];
if ( v1 )
LODWORD(v0) = tputs(v1, 1, (int (*)(int))&ttputc);
return (int)v0;
}

canonical_decompiled_code:
int func1()
{
char **v0; // rax
const char *v1; // rdi

v0 = cur_term->type.Strings;
v1 = v0[88];
if ( v1 )
LODWORD(v0) = tputs(v1, 1, (int (*)(int))&ttputc);
return (int)v0;
}

original_code:
void
ttykeymaptidy(void)
{
 if (((TERMTYPE *)(cur_term))-> Strings[88])
  tputs(((TERMTYPE *)(cur_term))-> Strings[88], 1, ttputc);
}

canonical_original_code:
void ttykeymaptidy()
{
 if (((struct termtype *)(cur_term))-> Strings[88])
  tputs(((struct termtype *)(cur_term))-> Strings[88], 1, ttputc);
}

return_type: void


usage

decompiled_code:
void __noreturn usage()
{
fprintf(stderr, "usage: %s [-n] [-f mode] [+number] [file ...]\n", _progname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fprintf(stderr, "usage: %s [-n] [-f mode] [+number] [file ...]\n", _progname);
exit(1);
}

original_code:
static __attribute__((__noreturn__)) void
usage()
{
 fprintf(stderr, "usage: %s [-n] [-f mode] [+number] [file ...]\n",
     __progname);
 exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr, "usage: %s [-n] [-f mode] [+number] [file ...]\n",
     __progname);
 exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v4; // ebx
char *v5; // rbp
int v6; // eax
int v7; // er12
__int64 v8; // r14
__int64 v9; // rax
__int64 v10; // rdx
char v11; // di
int v12; // esi
__int64 v13; // rax
const char **v14; // rbx
const char **v15; // r15
int v16; // er14
int v17; // eax
const char *v18; // r12
__int64 v19; // r12
__int64 v20; // rdi
int v21; // eax
void (__fastcall *v22)(__int64, __int64); // [rsp+8h] [rbp-50h]
__int64 v23[8]; // [rsp+18h] [rbp-40h] BYREF

v4 = 0;
v5 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "nf:");
if ( v6 == -1 )
break;
if ( v6 == 102 )
{
if ( v5 )
errx(1, "cannot specify more than one initial function");
v5 = optarg;
}
else
{
if ( v6 != 110 )
usage();
v4 = 1;
}
}
v7 = argc - optind;
v8 = optind;
setlocale(0, &locale);
maps_init();
funmap_init();
dired_init();
grep_init();
theo_init();
cmode_init();
if ( v5 )
{
v22 = (void (__fastcall *)(__int64, __int64))name_function(v5);
if ( !v22 )
errx(1, "Unknown function `%s'", v5);
}
else
{
v22 = 0LL;
}
vtinit();
dirinit();
edinit(0LL);
ttykeymapinit();
bellinit();
update(2LL);
v9 = startupfile(0LL);
if ( v9 )
load(v9);
v10 = bheadp;
if ( bheadp )
{
v11 = defb_flag;
v12 = defb_nmodes;
do
{
*(_BYTE *)(v10 + 91) = v11;
if ( v12 >= 0 )
{
v13 = 0LL;
do
{
*(_QWORD *)(v10 + 8 * v13 + 48) = *((_QWORD *)&defb_modes + v13);
++v13;
}
while ( v12 >= (int)v13 );
}
v10 = *(_QWORD *)v10;
}
while ( v10 );
}
if ( v22 )
v22(4LL, 1LL);
if ( v4 )
makebkfile(7LL, 0LL);
if ( v7 > 0 )
{
v14 = &argv[v8];
v15 = &(&argv[v7 - 1])[v8 + 1];
v16 = 0;
do
{
v18 = *v14;
if ( **v14 == 43
&& strlen(*v14) > 1
&& (v17 = strtonum(v18 + 1, 0xFFFFFFFF80000000LL, 0x7FFFFFFFLL, v23), (*v14)[1])
&& !v23[0] )
{
startrow = v17;
}
else
{
v19 = adjustname(*v14, 0LL);
if ( v19 )
{
if ( v16 == 1 )
splitwind(0LL, 1LL);
v20 = findbuffer(v19);
curbp = v20;
if ( !v20 )
{
vttidy();
errx(1, "Can't find current buffer!");
}
showbuffer(v20, curwp, 0LL);
if ( (unsigned int)readin(v19) == 1 )
{
if ( v5 )
v22(4LL, 1LL);
++v16;
}
else
{
killbuffer(curbp);
}
}
}
++v14;
}
while ( v14 != v15 );
if ( v16 > 2 )
listbuffers(0LL, 1LL);
}
thisflag = 0;
while ( 1 )
{
if ( epresf == 2 )
eerase();
if ( epresf == 1 )
epresf = 2;
if ( winch_flag )
{
do_redraw(0LL, 0LL, 1LL);
winch_flag = 0;
}
update(2LL);
lastflag = thisflag;
thisflag = 0;
v21 = doin();
if ( v21 != 1 )
{
if ( v21 == 2 )
ewprintf("Quit");
macrodef = 0;
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v4; // ebx
char *v5; // rbp
int v6; // eax
int v7; // er12
__int64 v8; // r14
__int64 v9; // rax
__int64 v10; // rdx
char v11; // di
int v12; // esi
__int64 v13; // rax
const char **v14; // rbx
const char **v15; // r15
int v16; // er14
int v17; // eax
const char *v18; // r12
__int64 v19; // r12
__int64 v20; // rdi
int v21; // eax
void (__fastcall *v22)(__int64, __int64); // [rsp+8h] [rbp-50h]
__int64 v23[8]; // [rsp+18h] [rbp-40h] BYREF

v4 = 0;
v5 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "nf:");
if ( v6 == -1 )
break;
if ( v6 == 102 )
{
if ( v5 )
errx(1, "cannot specify more than one initial function");
v5 = optarg;
}
else
{
if ( v6 != 110 )
func0();
v4 = 1;
}
}
v7 = argc - optind;
v8 = optind;
setlocale(0, &locale);
maps_init();
funmap_init();
dired_init();
grep_init();
theo_init();
cmode_init();
if ( v5 )
{
v22 = (void (__fastcall *)(__int64, __int64))name_function(v5);
if ( !v22 )
errx(1, "Unknown function `%s'", v5);
}
else
{
v22 = 0LL;
}
vtinit();
dirinit();
func1(0LL);
ttykeymapinit();
bellinit();
update(2LL);
v9 = startupfile(0LL);
if ( v9 )
load(v9);
v10 = bheadp;
if ( bheadp )
{
v11 = defb_flag;
v12 = defb_nmodes;
do
{
*(_BYTE *)(v10 + 91) = v11;
if ( v12 >= 0 )
{
v13 = 0LL;
do
{
*(_QWORD *)(v10 + 8 * v13 + 48) = *((_QWORD *)&defb_modes + v13);
++v13;
}
while ( v12 >= (int)v13 );
}
v10 = *(_QWORD *)v10;
}
while ( v10 );
}
if ( v22 )
v22(4LL, 1LL);
if ( v4 )
makebkfile(7LL, 0LL);
if ( v7 > 0 )
{
v14 = &argv[v8];
v15 = &(&argv[v7 - 1])[v8 + 1];
v16 = 0;
do
{
v18 = *v14;
if ( **v14 == 43
&& strlen(*v14) > 1
&& (v17 = strtonum(v18 + 1, 0xFFFFFFFF80000000LL, 0x7FFFFFFFLL, v23), (*v14)[1])
&& !v23[0] )
{
startrow = v17;
}
else
{
v19 = adjustname(*v14, 0LL);
if ( v19 )
{
if ( v16 == 1 )
splitwind(0LL, 1LL);
v20 = findbuffer(v19);
curbp = v20;
if ( !v20 )
{
vttidy();
errx(1, "Can't find current buffer!");
}
showbuffer(v20, curwp, 0LL);
if ( (unsigned int)readin(v19) == 1 )
{
if ( v5 )
v22(4LL, 1LL);
++v16;
}
else
{
killbuffer(curbp);
}
}
}
++v14;
}
while ( v14 != v15 );
if ( v16 > 2 )
listbuffers(0LL, 1LL);
}
thisflag = 0;
while ( 1 )
{
if ( epresf == 2 )
eerase();
if ( epresf == 1 )
epresf = 2;
if ( winch_flag )
{
do_redraw(0LL, 0LL, 1LL);
winch_flag = 0;
}
update(2LL);
lastflag = thisflag;
thisflag = 0;
v21 = doin();
if ( v21 != 1 )
{
if ( v21 == 2 )
ewprintf("Quit");
macrodef = 0;
}
}
}

original_code:
int
main(int argc, char **argv)
{
 char *cp, *init_fcn_name = ((void *)0);
 PF init_fcn = ((void *)0);
 int o, i, nfiles;
 int nobackups = 0;
 struct buffer *bp = ((void *)0);
 while ((o = getopt(argc, argv, "nf:")) != -1)
  switch (o) {
  case 'n':
   nobackups = 1;
   break;
  case 'f':
   if (init_fcn_name != ((void *)0))
    errx(1, "cannot specify more than one "
        "initial function");
   init_fcn_name = optarg;
   break;
  default:
   usage();
  }
 argc -= optind;
 argv += optind;
 setlocale(0, "");
 maps_init();
 funmap_init();
 {
  extern void grep_init(void);
  extern void theo_init(void);
  extern void cmode_init(void);
  extern void dired_init(void);
  dired_init();
  grep_init();
  theo_init();
  cmode_init();
 }
 if (init_fcn_name &&
     (init_fcn = name_function(init_fcn_name)) == ((void *)0))
  errx(1, "Unknown function `%s'", init_fcn_name);
 vtinit();
 dirinit();
 edinit(bp);
 ttykeymapinit();
 bellinit();
 update(2);
 if ((cp = startupfile(((void *)0))) != ((void *)0))
  (void)load(cp);
 for (bp = bheadp; bp != ((void *)0); bp = bp->b_list.l_p.x_bp) {
  bp->b_flag = defb_flag;
  for (i = 0; i <= defb_nmodes; i++) {
                 bp->b_modes[i] = defb_modes[i];
         }
 }
 if (init_fcn)
  init_fcn(4, 1);
 if (nobackups)
  makebkfile(7, 0);
 for (nfiles = 0, i = 0; i < argc; i++) {
  if (argv[i][0] == '+' && strlen(argv[i]) >= 2) {
   long long lval;
   const char *errstr;
   lval = strtonum(&argv[i][1], (-0x7fffffff - 1), 0x7fffffff, &errstr);
   if (argv[i][1] == '\0' || errstr != ((void *)0))
    goto notnum;
   startrow = lval;
  } else {
notnum:
   cp = adjustname(argv[i], 0);
   if (cp != ((void *)0)) {
    if (nfiles == 1)
     splitwind(0, 1);
    if ((curbp = findbuffer(cp)) == ((void *)0)) {
     vttidy();
     errx(1, "Can't find current buffer!");
    }
    (void)showbuffer(curbp, curwp, 0);
    if (readin(cp) != 1)
     killbuffer(curbp);
    else {
     if (init_fcn_name)
      init_fcn(4, 1);
     nfiles++;
    }
   }
  }
 }
 if (nfiles > 2)
  listbuffers(0, 1);
 thisflag = 0;
 for (;;) {
  if (epresf == 2)
   eerase();
  if (epresf == 1)
   epresf = 2;
  if (winch_flag) {
   do_redraw(0, 0, 1);
   winch_flag = 0;
  }
  update(2);
  lastflag = thisflag;
  thisflag = 0;
  switch (doin()) {
  case 1:
   break;
  case 2:
   ewprintf("Quit");
  case 0:
  default:
   macrodef = 0;
  }
 }
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *cp; char *init_fcn_name = ((void *)0);
 int (*init_fcn)(int, int) = ((void *)0);
 int o; int i; int nfiles;
 int nobackups = 0;
 struct buffer *bp = ((void *)0);
 while ((o = getopt(argc, argv, "nf:")) != -1)
  switch (o) {
  case 'n':
   nobackups = 1;
   break;
  case 'f':
   if (init_fcn_name != ((void *)0))
    errx(1, "cannot specify more than one "
        "initial function");
   init_fcn_name = optarg;
   break;
  default:
   usage();
  }
 argc -= optind;
 argv += optind;
 setlocale(0, "");
 maps_init();
 funmap_init();
 {
  extern void grep_init();
  extern void theo_init();
  extern void cmode_init();
  extern void dired_init();
  dired_init();
  grep_init();
  theo_init();
  cmode_init();
 }
 if (init_fcn_name &&
     (init_fcn = name_function(init_fcn_name)) == ((void *)0))
  errx(1, "Unknown function `%s'", init_fcn_name);
 vtinit();
 dirinit();
 edinit(bp);
 ttykeymapinit();
 bellinit();
 update(2);
 if ((cp = startupfile(((void *)0))) != ((void *)0))
  (void)load(cp);
 for (bp = bheadp; bp != ((void *)0); bp = bp->b_list.l_p.x_bp) {
  bp->b_flag = defb_flag;
  for (i = 0; i <= defb_nmodes; i++) {
                 bp->b_modes[i] = defb_modes[i];
         }
 }
 if (init_fcn)
  init_fcn(4, 1);
 if (nobackups)
  makebkfile(7, 0);
 for (nfiles = 0, i = 0; i < argc; i++) {
  if (argv[i][0] == '+' && strlen(argv[i]) >= 2) {
   long long lval;
   char *errstr;
   lval = strtonum(&argv[i][1], (-0x7fffffff - 1), 0x7fffffff, &errstr);
   if (argv[i][1] == '\0' || errstr != ((void *)0))
    goto notnum;
   startrow = lval;
  } else {
notnum:
   cp = adjustname(argv[i], 0);
   if (cp != ((void *)0)) {
    if (nfiles == 1)
     splitwind(0, 1);
    if ((curbp = findbuffer(cp)) == ((void *)0)) {
     vttidy();
     errx(1, "Can't find current buffer!");
    }
    (void)showbuffer(curbp, curwp, 0);
    if (readin(cp) != 1)
     killbuffer(curbp);
    else {
     if (init_fcn_name)
      init_fcn(4, 1);
     nfiles++;
    }
   }
  }
 }
 if (nfiles > 2)
  listbuffers(0, 1);
 thisflag = 0;
 for (;;) {
  if (epresf == 2)
   eerase();
  if (epresf == 1)
   epresf = 2;
  if (winch_flag) {
   do_redraw(0, 0, 1);
   winch_flag = 0;
  }
  update(2);
  lastflag = thisflag;
  thisflag = 0;
  switch (doin()) {
  case 1:
   break;
  case 2:
   ewprintf("Quit");
  case 0:
  default:
   macrodef = 0;
  }
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: o int

variable_types: i int

variable_types: nfiles int

variable_types: nobackups int

variable_types: struct buffer { struct list { union { struct mgwin { struct list w_list; struct buffer *w_bufp; struct line { struct line *l_fp; struct line *l_bp; int l_size; int l_used; char *l_text; } *w_linep; struct line *w_dotp; struct line *w_markp; int w_doto; int w_marko; int w_toprow; int w_ntrows; int w_frame; char w_rflag; char w_flag; struct line *w_wrapline; int w_dotline; int w_markline; } *l_wp; struct buffer *x_bp; struct list *l_nxt; } l_p; char *l_name; } b_list; struct buffer *b_altb; struct line *b_dotp; struct line *b_markp; struct line *b_headp; struct maps_s { struct keymap_s { short map_num; short map_max; int (*map_default)(int, int); struct map_element { short k_base; short k_num; int (**k_funcp)(int, int); struct keymap_s *k_prefmap; } map_element[1]; } *p_map; char *p_name; struct maps_s *p_next; } *b_modes[4]; int b_doto; int b_marko; short b_nmodes; char b_nwnd; char b_flag; char b_fname[1024]; char b_cwd[1024]; struct fileinfo { unsigned int fi_uid; unsigned int fi_gid; unsigned int fi_mode; struct timespec { long tv_sec; long tv_nsec; } fi_mtime; } b_fi; struct undoq { struct undo_rec { struct { struct undo_rec *tqe_next; struct undo_rec **tqe_prev; } next; enum { INSERT=1, DELETE=2, BOUNDARY=3, MODIFIED=4, DELREG=5 } type; struct region { struct line *r_linep; int r_offset; int r_lineno; int r_size; } region; int pos; char *content; } *tqh_first; struct undo_rec **tqh_last; } b_undo; struct undo_rec *b_undoptr; int b_dotline; int b_markline; int b_lines; } *

variable_types:
lval
long long

variable_types:
errstr
char *

return_type: int

user_defined_types: struct buffer { struct list b_list; struct buffer *b_altb; struct line *b_dotp; struct line *b_markp; struct line *b_headp; struct maps_s *b_modes[4]; int b_doto; int b_marko; short b_nmodes; char b_nwnd; char b_flag; char b_fname[1024]; char b_cwd[1024]; struct fileinfo b_fi; struct undoq b_undo; struct undo_rec *b_undoptr; int b_dotline; int b_markline; int b_lines; }

user_defined_types: struct list { union { struct mgwin *l_wp; struct buffer *x_bp; struct list *l_nxt; } l_p; char *l_name; }

user_defined_types: struct fileinfo { unsigned int fi_uid; unsigned int fi_gid; unsigned int fi_mode; struct timespec fi_mtime; }

user_defined_types: struct undoq { struct undo_rec *tqh_first; struct undo_rec **tqh_last; }

user_defined_types: struct maps_s { struct keymap_s *p_map; char *p_name; struct maps_s *p_next; }

user_defined_types: struct undo_rec { struct { struct undo_rec *tqe_next; struct undo_rec **tqe_prev; } next; enum { INSERT=1, DELETE=2, BOUNDARY=3, MODIFIED=4, DELREG=5 } type; struct region region; int pos; char *content; }

user_defined_types: struct mgwin { struct list w_list; struct buffer *w_bufp; struct line *w_linep; struct line *w_dotp; struct line *w_markp; int w_doto; int w_marko; int w_toprow; int w_ntrows; int w_frame; char w_rflag; char w_flag; struct line *w_wrapline; int w_dotline; int w_markline; }

user_defined_types: struct keymap_s { short map_num; short map_max; int (*map_default)(int, int); struct map_element map_element[1]; }


quit

decompiled_code:
__int64 quit()
{
__int64 result; // rax
int v1; // edx

result = anycb(0LL);
if ( (_DWORD)result != 2 )
{
if ( (_DWORD)result == 3 )
{
result = 0LL;
}
else if ( !(_DWORD)result || (v1 = eyesno("Modified buffers exist; really exit"), result = 1LL, v1 == 1) )
{
vttidy();
closetags();
exit(0);
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
int v1; // edx

result = anycb(0LL);
if ( (_DWORD)result != 2 )
{
if ( (_DWORD)result == 3 )
{
result = 0LL;
}
else if ( !(_DWORD)result || (v1 = eyesno("Modified buffers exist; really exit"), result = 1LL, v1 == 1) )
{
vttidy();
closetags();
exit(0);
}
}
return result;
}

original_code:
int
quit(int f, int n)
{
 int s;
 if ((s = anycb(0)) == 2)
  return (2);
 if (s == 3 || s == 3)
  return (0);
 if (s == 0
     || eyesno("Modified buffers exist; really exit") == 1) {
  vttidy();
  closetags();
  exit(0);
 }
 return (1);
}

variable_types: f int

variable_types: n int

variable_types: s int


ctrlg

decompiled_code:
__int64 ctrlg()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 2LL;
}

original_code:
int
ctrlg(int f, int n)
{
 return (2);
}

canonical_original_code:
int ctrlg(int f, int n)
{
 return (2);
}


reposition

decompiled_code:
__int64 __fastcall reposition(char a1, unsigned int a2)
{
int v2; // edi
_BYTE *v3; // rax

v2 = a1 & 7;
if ( v2 )
v2 = (a2 < 0x80000000) + a2;
v3 = curwp;
*((_DWORD *)curwp + 16) = v2;
v3[68] |= 1u;
sgarbf = 1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, unsigned int a2)
{
int v2; // edi
_BYTE *v3; // rax

v2 = a1 & 7;
if ( v2 )
v2 = (a2 < 0x80000000) + a2;
v3 = curwp;
*((_DWORD *)curwp + 16) = v2;
v3[68] |= 1u;
sgarbf = 1;
return 1LL;
}

original_code:
int
reposition(int f, int n)
{
 curwp->w_frame = (f & 7) ? (n >= 0 ? n + 1 : n) : 0;
 curwp->w_rflag |= 0x01;
 sgarbf = 1;
 return (1);
}


redraw

decompiled_code:
__int64 __fastcall redraw(__int64 a1, __int64 a2)
{
return do_redraw(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return func1(a1, a2, 0);
}

original_code:
int
redraw(int f, int n)
{
 return (do_redraw(f, n, 0));
}


showversion

decompiled_code:
__int64 showversion()
{
ewprintf(&unk_38, "Mg 2a");
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
ewprintf(&unk_38, "Mg 2a");
return 1LL;
}

original_code:
int
showversion(int f, int n)
{
 ewprintf("%s", version);
 return (1);
}


decompiled_code:
void funmap_init()
{
__int64 v0; // rdx
void **i; // rax

if ( off_188 )
{
v0 = funs;
for ( i = &functnames; ; i += 3 )
{
i[2] = (void *)v0;
v0 = (__int64)i;
if ( !i[4] )
break;
}
funs = (__int64)i;
}
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // rdx
void **i; // rax

if ( off_188 )
{
v0 = funs;
for ( i = &functnames; ; i += 3 )
{
i[2] = (void *)v0;
v0 = (__int64)i;
if ( !i[4] )
break;
}
funs = (__int64)i;
}
}

original_code:
void
funmap_init(void)
{
 struct funmap *fn;
 for (fn = functnames; fn->fn_name != ((void *)0); fn++) {
  fn->fn_next = funs;
  funs = fn;
 }
}

canonical_original_code:
void funmap_init()
{
 struct funmap *fn;
 for (fn = functnames; fn->fn_name != ((void *)0); fn++) {
  fn->fn_next = funs;
  funs = fn;
 }
}

variable_types: struct funmap { int (*fn_funct)(int, int); char *fn_name; struct funmap *fn_next; } *


decompiled_code:
__int64 __fastcall funmap_add(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x18uLL);
if ( !v2 )
return 0LL;
*v2 = a1;
v2[1] = a2;
v2[2] = funs;
funs = (__int64)v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x18uLL);
if ( !v2 )
return 0LL;
*v2 = a1;
v2[1] = a2;
v2[2] = funs;
funs = (__int64)v2;
return 1LL;
}

original_code:
int
funmap_add(PF fun, const char *fname)
{
 struct funmap *fn;
 if ((fn = malloc(sizeof(*fn))) == ((void *)0))
  return (0);
 fn->fn_funct = fun;
 fn->fn_name = fname;
 fn->fn_next = funs;
 funs = fn;
 return (1);
}

canonical_original_code:
int funmap_add(int (*fun)(int, int), char *fname)
{
 struct funmap *fn;
 if ((fn = malloc(sizeof(*fn))) == ((void *)0))
  return (0);
 fn->fn_funct = fun;
 fn->fn_name = fname;
 fn->fn_next = funs;
 funs = fn;
 return (1);
}

variable_types:
fun
int (*)(int, int)

variable_types:
fname
char *

user_defined_types: struct funmap { int (*fn_funct)(int, int); char *fn_name; struct funmap *fn_next; }


decompiled_code:
__int64 __fastcall name_function(char *s2)
{
__int64 v1; // rbx

v1 = funs;
if ( !funs )
return 0LL;
while ( strcmp(*(const char **)(v1 + 8), s2) )
{
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return 0LL;
}
return *(_QWORD *)v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
__int64 v1; // rbx

v1 = funs;
if ( !funs )
return 0LL;
while ( strcmp(*(const char **)(v1 + 8), s2) )
{
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return 0LL;
}
return *(_QWORD *)v1;
}

original_code:
PF
name_function(const char *fname)
{
 struct funmap *fn;
 for (fn = funs; fn != ((void *)0); fn = fn->fn_next) {
  if (strcmp(fn->fn_name, fname) == 0)
   return (fn->fn_funct);
 }
 return (((void *)0));
}

canonical_original_code:
int (*name_function(char *fname))(int, int)
{
 struct funmap *fn;
 for (fn = funs; fn != ((void *)0); fn = fn->fn_next) {
  if (strcmp(fn->fn_name, fname) == 0)
   return (fn->fn_funct);
 }
 return (((void *)0));
}

return_type: int (*)(int, int)


displaymatch

original_code:
static void
displaymatch(struct line *clp, int cbo)
{
 struct line *tlp;
 int tbo;
 int cp;
 int bufo;
 int c;
 int inwindow;
 char buf[256];
 inwindow = 0;
 for (tlp = curwp->w_linep; tlp != ((curwp->w_dotp)->l_fp);
     tlp = ((tlp)->l_fp))
  if (tlp == clp)
   inwindow = 1;
 if (inwindow == 1) {
  tlp = curwp->w_dotp;
  tbo = curwp->w_doto;
  curwp->w_dotp = clp;
  curwp->w_doto = cbo;
  curwp->w_rflag |= 0x02;
  update(2);
  ttwait(1000);
  curwp->w_dotp = tlp;
  curwp->w_doto = tbo;
  curwp->w_rflag |= 0x02;
  update(2);
 } else {
  bufo = 0;
  for (cp = 0; cp < ((clp)->l_used); cp++) {
   c = (((unsigned char) ((clp)->l_text[(cp)])));
   if (c != '\t'
    )
    if (((cinfo[((unsigned char) (c))]&0x08)!=0)) {
     buf[bufo++] = '^';
     buf[bufo++] = ((c) ^ 0x40);
    } else
     buf[bufo++] = c;
   else
    do {
     buf[bufo++] = ' ';
    } while (bufo & 7);
  }
  buf[bufo++] = '\0';
  ewprintf("Matches %s", buf);
 }
}

variable_types: struct line { struct line *l_fp; struct line *l_bp; int l_size; int l_used; char *l_text; } *

variable_types: cbo int

variable_types: tbo int

variable_types: cp int

variable_types: bufo int

variable_types: c int

variable_types: inwindow int

variable_types:
buf
char [256]


balance

decompiled_code:
__int64 balance()
{
int v0; // er8
__int64 v1; // rdx
char v2; // al
int v3; // er10
__int64 v4; // rdi
__int64 result; // rax
int i; // ecx
int v7; // edx

v0 = *((__int16 *)&key + key + 1);
v1 = 0LL;
v2 = 41;
while ( v2 != v0 )
{
++v1;
v2 = byte_259[2 * v1];
if ( !v2 )
{
v3 = *((__int16 *)&key + key + 1);
goto LABEL_6;
}
}
v3 = bal[2 * (int)v1];
LABEL_6:
v4 = *(_QWORD *)(curwp + 32LL);
result = (unsigned int)(*(_DWORD *)(curwp + 48LL) - 1);
for ( i = 0; ; i += v7 == v0 )
{
if ( !(_DWORD)result )
{
v4 = *(_QWORD *)(v4 + 8);
if ( *(_QWORD *)(curbp + 40LL) == v4 )
return result;
LODWORD(result) = *(_DWORD *)(v4 + 20) + 1;
}
result = (unsigned int)(result - 1);
v7 = 10;
if ( *(_DWORD *)(v4 + 20) != (_DWORD)result )
v7 = *(unsigned __int8 *)(*(_QWORD *)(v4 + 24) + (int)result);
if ( v7 == v3 )
break;
LABEL_10:
;
}
if ( i )
{
--i;
goto LABEL_10;
}
displaymatch(v4, result);
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // er8
__int64 v1; // rdx
char v2; // al
int v3; // er10
__int64 v4; // rdi
__int64 result; // rax
int i; // ecx
int v7; // edx

v0 = *((__int16 *)&key + key + 1);
v1 = 0LL;
v2 = 41;
while ( v2 != v0 )
{
++v1;
v2 = byte_259[2 * v1];
if ( !v2 )
{
v3 = *((__int16 *)&key + key + 1);
goto LABEL_6;
}
}
v3 = bal[2 * (int)v1];
LABEL_6:
v4 = *(_QWORD *)(curwp + 32LL);
result = (unsigned int)(*(_DWORD *)(curwp + 48LL) - 1);
for ( i = 0; ; i += v7 == v0 )
{
if ( !(_DWORD)result )
{
v4 = *(_QWORD *)(v4 + 8);
if ( *(_QWORD *)(curbp + 40LL) == v4 )
return result;
LODWORD(result) = *(_DWORD *)(v4 + 20) + 1;
}
result = (unsigned int)(result - 1);
v7 = 10;
if ( *(_DWORD *)(v4 + 20) != (_DWORD)result )
v7 = *(unsigned __int8 *)(*(_QWORD *)(v4 + 24) + (int)result);
if ( v7 == v3 )
break;
LABEL_10:
;
}
if ( i )
{
--i;
goto LABEL_10;
}
func0(v4, result);
return 1LL;
}

original_code:
static int
balance(void)
{
 struct line *clp;
 int cbo;
 int c, i, depth;
 int rbal, lbal;
 rbal = key.k_chars[key.k_count - 1];
 lbal = rbal;
 for (i = 0; bal[i].right != '\0'; i++)
  if (bal[i].right == rbal) {
   lbal = bal[i].left;
   break;
  }
 clp = curwp->w_dotp;
 cbo = curwp->w_doto - 1;
 depth = 0;
 for (;;) {
  if (cbo == 0) {
   clp = ((clp)->l_bp);
   if (clp == curbp->b_headp)
    return (0);
   cbo = ((clp)->l_used) + 1;
  }
  if (--cbo == ((clp)->l_used))
   c = '\n';
  else
   c = (((unsigned char) ((clp)->l_text[(cbo)])));
  if (c == lbal) {
   if (depth == 0) {
    displaymatch(clp, cbo);
    return (1);
   } else
    depth--;
  }
  if (c == rbal)
   depth++;
 }
}

canonical_original_code:
static int balance()
{
 struct line *clp;
 int cbo;
 int c; int i; int depth;
 int rbal; int lbal;
 rbal = key.k_chars[key.k_count - 1];
 lbal = rbal;
 for (i = 0; bal[i].right != '\0'; i++)
  if (bal[i].right == rbal) {
   lbal = bal[i].left;
   break;
  }
 clp = curwp->w_dotp;
 cbo = curwp->w_doto - 1;
 depth = 0;
 for (;;) {
  if (cbo == 0) {
   clp = ((clp)->l_bp);
   if (clp == curbp->b_headp)
    return (0);
   cbo = ((clp)->l_used) + 1;
  }
  if (--cbo == ((clp)->l_used))
   c = '\n';
  else
   c = (((unsigned char) ((clp)->l_text[(cbo)])));
  if (c == lbal) {
   if (depth == 0) {
    displaymatch(clp, cbo);
    return (1);
   } else
    depth--;
  }
  if (c == rbal)
   depth++;
 }
}

variable_types: i int

variable_types: depth int

variable_types: rbal int

variable_types: lbal int

user_defined_types: struct line { struct line *l_fp; struct line *l_bp; int l_size; int l_used; char *l_text; }


showmatch

decompiled_code:
__int64 __fastcall showmatch(__int64 a1, int a2)
{
int i; // ebp
unsigned int v3; // ebx

if ( a2 <= 0 )
return 1;
for ( i = 0; i != a2; ++i )
{
v3 = selfinsert(8LL, 1LL);
if ( v3 != 1 )
break;
if ( (unsigned int)balance() != 1 )
dobeep();
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
int i; // ebp
unsigned int v3; // ebx

if ( a2 <= 0 )
return 1;
for ( i = 0; i != a2; ++i )
{
v3 = selfinsert(8LL, 1LL);
if ( v3 != 1 )
break;
if ( (unsigned int)func1() != 1 )
dobeep();
}
return v3;
}

original_code:
int
showmatch(int f, int n)
{
 int i, s;
 for (i = 0; i < n; i++) {
  if ((s = selfinsert(8, 1)) != 1)
   return (s);
  if (balance() != 1)
   dobeep();
 }
 return (1);
}

canonical_original_code:
int showmatch(int f, int n)
{
 int i; int s;
 for (i = 0; i < n; i++) {
  if ((s = selfinsert(8, 1)) != 1)
   return (s);
  if (balance() != 1)
   dobeep();
 }
 return (1);
}

variable_types: f int

variable_types: n int


spawncli

decompiled_code:
__int64 spawncli()
{
__int64 result; // rax
sigset_t v1; // [rsp+0h] [rbp-88h] BYREF

ttcolor(1LL);
ttnowindow();
ttmove((unsigned int)(nrow - 1), 0LL);
if ( epresf )
{
tteeol();
epresf = 0;
}
result = ttcooked();
if ( (_DWORD)result )
{
tttidy();
ttflush();
sigprocmask(2, 0LL, &v1);
kill(0, 20);
sigprocmask(2, &v1, 0LL);
ttreinit();
sgarbf = 1;
result = ttraw();
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
sigset_t v1; // [rsp+0h] [rbp-88h] BYREF

ttcolor(1LL);
ttnowindow();
ttmove((unsigned int)(nrow - 1), 0LL);
if ( epresf )
{
tteeol();
epresf = 0;
}
result = ttcooked();
if ( (_DWORD)result )
{
tttidy();
ttflush();
sigprocmask(2, 0LL, &v1);
kill(0, 20);
sigprocmask(2, &v1, 0LL);
ttreinit();
sgarbf = 1;
result = ttraw();
}
return result;
}

original_code:
int
spawncli(int f, int n)
{
 sigset_t oset;
 ttcolor(1);
 ttnowindow();
 ttmove(nrow - 1, 0);
 if (epresf != 0) {
  tteeol();
  epresf = 0;
 }
 if (ttcooked() == 0)
  return (0);
 tttidy();
 ttflush();
 (void)sigprocmask(2, ((void *)0), &oset);
 (void)kill(0, 20);
 (void)sigprocmask(2, &oset, ((void *)0));
 ttreinit();
 sgarbf = 1;
 return (ttraw());
}

canonical_original_code:
int spawncli(int f, int n)
{
 struct __sigset_t oset;
 ttcolor(1);
 ttnowindow();
 ttmove(nrow - 1, 0);
 if (epresf != 0) {
  tteeol();
  epresf = 0;
 }
 if (ttcooked() == 0)
  return (0);
 tttidy();
 ttflush();
 (void)sigprocmask(2, ((void *)0), &oset);
 (void)kill(0, 20);
 (void)sigprocmask(2, &oset, ((void *)0));
 ttreinit();
 sgarbf = 1;
 return (ttraw());
}

variable_types: struct __sigset_t { unsigned long __val[-1]; }


decompiled_code:
__int64 theo_analyze()
{
const char *v0; // rbx
int v1; // ebp
__int64 v2; // rbp

v0 = (&talk)[(unsigned int)arc4random_uniform(109LL)];
v1 = strlen(v0);
newline(8LL, 2LL);
if ( v1 )
{
v2 = (__int64)&v0[v1 - 1 + 1];
do
linsert(1LL, (unsigned int)*v0++);
while ( v0 != (const char *)v2 );
}
newline(8LL, 2LL);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
const char *v0; // rbx
int v1; // ebp
__int64 v2; // rbp

v0 = (&talk)[(unsigned int)arc4random_uniform(109LL)];
v1 = strlen(v0);
newline(8LL, 2LL);
if ( v1 )
{
v2 = (__int64)&v0[v1 - 1 + 1];
do
linsert(1LL, (unsigned int)*v0++);
while ( v0 != (const char *)v2 );
}
newline(8LL, 2LL);
return 1LL;
}

original_code:
static int
theo_analyze(int f, int n)
{
 const char *str;
 int len;
 str = talk[arc4random_uniform(ntalk)];
 len = strlen(str);
 newline(8, 2);
 while (len--)
  linsert(1, *str++);
 newline(8, 2);
 return (1);
}

canonical_original_code:
static int theo_analyze(int f, int n)
{
 char *str;
 int len;
 str = talk[arc4random_uniform(ntalk)];
 len = strlen(str);
 newline(8, 2);
 while (len--)
  linsert(1, *str++);
 newline(8, 2);
 return (1);
}

variable_types:
str
char *

variable_types: len int


theo

decompiled_code:
__int64 __fastcall theo(unsigned int a1, unsigned int a2)
{
__int64 v2; // rbp
unsigned int v3; // ebx
__int64 v5; // rax

v2 = bfind("theo", 1LL);
v3 = 0;
if ( (unsigned int)bclear(v2) == 1 )
{
v3 = 1;
*(_QWORD *)(v2 + 48) = name_mode("fundamental");
*(_QWORD *)(v2 + 56) = name_mode("theo");
*(_WORD *)(v2 + 88) = 1;
v5 = popbuf(v2, 0LL);
if ( v5 )
{
curbp = v2;
curwp = v5;
onlywind(a1, a2);
}
else
{
v3 = 0;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
__int64 v2; // rbp
unsigned int v3; // ebx
__int64 v5; // rax

v2 = bfind("theo", 1LL);
v3 = 0;
if ( (unsigned int)bclear(v2) == 1 )
{
v3 = 1;
*(_QWORD *)(v2 + 48) = name_mode("fundamental");
*(_QWORD *)(v2 + 56) = name_mode("theo");
*(_WORD *)(v2 + 88) = 1;
v5 = popbuf(v2, 0LL);
if ( v5 )
{
curbp = v2;
curwp = v5;
onlywind(a1, a2);
}
else
{
v3 = 0;
}
}
return v3;
}

original_code:
static int
theo(int f, int n)
{
 struct buffer *bp;
 struct mgwin *wp;
 bp = bfind("theo", 1);
 if (bclear(bp) != 1)
  return (0);
 bp->b_modes[0] = name_mode("fundamental");
 bp->b_modes[1] = name_mode("theo");
 bp->b_nmodes = 1;
 if ((wp = popbuf(bp, 0x00)) == ((void *)0))
  return (0);
 curbp = bp;
 curwp = wp;
 onlywind(f, n);
 return (1);
}

variable_types: struct buffer { struct list { union { struct mgwin { struct list w_list; struct buffer *w_bufp; struct line { struct line *l_fp; struct line *l_bp; int l_size; int l_used; char *l_text; } *w_linep; struct line *w_dotp; struct line *w_markp; int w_doto; int w_marko; int w_toprow; int w_ntrows; int w_frame; char w_rflag; char w_flag; struct line *w_wrapline; int w_dotline; int w_markline; } *l_wp; struct buffer *x_bp; struct list *l_nxt; } l_p; char *l_name; } b_list; struct buffer *b_altb; struct line *b_dotp; struct line *b_markp; struct line *b_headp; struct maps_s { struct keymap_s { short map_num; short map_max; int (*map_default)(int, int); struct map_element { short k_base; short k_num; int (**k_funcp)(int, int); struct keymap_s *k_prefmap; } map_element[1]; } *p_map; char *p_name; struct maps_s *p_next; } *b_modes[4]; int b_doto; int b_marko; short b_nmodes; char b_nwnd; char b_flag; char b_fname[1024]; char b_cwd[1024]; struct fileinfo { unsigned int fi_uid; unsigned int fi_gid; unsigned int fi_mode; struct timespec { long tv_sec; long tv_nsec; } fi_mtime; } b_fi; struct undoq { struct undo_rec { struct { struct undo_rec *tqe_next; struct undo_rec **tqe_prev; } next; enum { INSERT=1, DELETE=2, BOUNDARY=3, MODIFIED=4, DELREG=5 } type; struct region { struct line *r_linep; int r_offset; int r_lineno; int r_size; } region; int pos; char *content; } *tqh_first; struct undo_rec **tqh_last; } b_undo; struct undo_rec *b_undoptr; int b_dotline; int b_markline; int b_lines; } *

variable_types: struct mgwin { struct list { union { struct mgwin *l_wp; struct buffer { struct list b_list; struct buffer *b_altb; struct line { struct line *l_fp; struct line *l_bp; int l_size; int l_used; char *l_text; } *b_dotp; struct line *b_markp; struct line *b_headp; struct maps_s { struct keymap_s { short map_num; short map_max; int (*map_default)(int, int); struct map_element { short k_base; short k_num; int (**k_funcp)(int, int); struct keymap_s *k_prefmap; } map_element[1]; } *p_map; char *p_name; struct maps_s *p_next; } *b_modes[4]; int b_doto; int b_marko; short b_nmodes; char b_nwnd; char b_flag; char b_fname[1024]; char b_cwd[1024]; struct fileinfo { unsigned int fi_uid; unsigned int fi_gid; unsigned int fi_mode; struct timespec { long tv_sec; long tv_nsec; } fi_mtime; } b_fi; struct undoq { struct undo_rec { struct { struct undo_rec *tqe_next; struct undo_rec **tqe_prev; } next; enum { INSERT=1, DELETE=2, BOUNDARY=3, MODIFIED=4, DELREG=5 } type; struct region { struct line *r_linep; int r_offset; int r_lineno; int r_size; } region; int pos; char *content; } *tqh_first; struct undo_rec **tqh_last; } b_undo; struct undo_rec *b_undoptr; int b_dotline; int b_markline; int b_lines; } *x_bp; struct list *l_nxt; } l_p; char *l_name; } w_list; struct buffer *w_bufp; struct line *w_linep; struct line *w_dotp; struct line *w_markp; int w_doto; int w_marko; int w_toprow; int w_ntrows; int w_frame; char w_rflag; char w_flag; struct line *w_wrapline; int w_dotline; int w_markline; } *


decompiled_code:
__int64 theo_init()
{
funmap_add(theo, "theo");
return maps_add(&theomap, "theo");
}

canonical_decompiled_code:
__int64 func2()
{
funmap_add(theo, "theo");
return maps_add(&theomap, "theo");
}

original_code:
void
theo_init(void)
{
 funmap_add(theo, "theo");
 maps_add((KEYMAP *)&theomap, "theo");
}

canonical_original_code:
void theo_init()
{
 funmap_add(theo, "theo");
 maps_add((struct keymap_s *)&theomap, "theo");
}

user_defined_types: struct map_element { short k_base; short k_num; int (**k_funcp)(int, int); struct keymap_s *k_prefmap; }


strtonum

original_code:
long long
strtonum(const char *numstr, long long minval, long long maxval,
    const char **errstrp)
{
 long long ll = 0;
 int error = 0;
 char *ep;
 struct errval {
  const char *errstr;
  int err;
 } ev[4] = {
  { ((void *)0), 0 },
  { "invalid", 22 },
  { "too small", 34 },
  { "too large", 34 },
 };
 ev[0].err = (*__errno_location ());
 (*__errno_location ()) = 0;
 if (minval > maxval) {
  error = 1;
 } else {
  ll = strtoll(numstr, &ep, 10);
  if (numstr == ep || *ep != '\0')
   error = 1;
  else if ((ll == (-0x7fffffffffffffffLL - 1LL) && (*__errno_location ()) == 34) || ll < minval)
   error = 2;
  else if ((ll == 0x7fffffffffffffffLL && (*__errno_location ()) == 34) || ll > maxval)
   error = 3;
 }
 if (errstrp != ((void *)0))
  *errstrp = ev[error].errstr;
 (*__errno_location ()) = ev[error].err;
 if (error)
  ll = 0;
 return (ll);
}

canonical_original_code:
long long strtonum(char *numstr, long long minval, long long maxval, char **errstrp)
{
 long long ll = 0;
 int error = 0;
 char *ep;
 struct errval ev[4] = {
  { ((void *)0), 0 },
  { "invalid", 22 },
  { "too small", 34 },
  { "too large", 34 },
 };
 ev[0].err = (*__errno_location ());
 (*__errno_location ()) = 0;
 if (minval > maxval) {
  error = 1;
 } else {
  ll = strtoll(numstr, &ep, 10);
  if (numstr == ep || *ep != '\0')
   error = 1;
  else if ((ll == (-0x7fffffffffffffffLL - 1LL) && (*__errno_location ()) == 34) || ll < minval)
   error = 2;
  else if ((ll == 0x7fffffffffffffffLL && (*__errno_location ()) == 34) || ll > maxval)
   error = 3;
 }
 if (errstrp != ((void *)0))
  *errstrp = ev[error].errstr;
 (*__errno_location ()) = ev[error].err;
 if (error)
  ll = 0;
 return (ll);
}

variable_types:
numstr
char *

variable_types:
minval
long long

variable_types:
maxval
long long

variable_types:
errstrp
char **

variable_types:
ll
long long

variable_types: error int

variable_types:
ep
char *

variable_types: struct errval { char *errstr; int err; } [4]

return_type: long long


isescaped

decompiled_code:
__int64 __fastcall isescaped(unsigned __int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
char *v4; // rcx
__int64 v5; // rsi
__int64 v6; // rax

result = 1LL;
if ( a3 )
{
v4 = (char *)(a2 - 1);
if ( a1 > a2 - 1 )
{
LOBYTE(v6) = 0;
}
else
{
v5 = a2 - a1;
v6 = 0LL;
while ( *v4 == a3 )
{
++v6;
--v4;
if ( v6 == v5 )
{
LOBYTE(v6) = v5;
break;
}
}
}
result = v6 & 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
char *v4; // rcx
__int64 v5; // rsi
__int64 v6; // rax

result = 1LL;
if ( a3 )
{
v4 = (char *)(a2 - 1);
if ( a1 > a2 - 1 )
{
LOBYTE(v6) = 0;
}
else
{
v5 = a2 - a1;
v6 = 0LL;
while ( *v4 == a3 )
{
++v6;
--v4;
if ( v6 == v5 )
{
LOBYTE(v6) = v5;
break;
}
}
}
result = v6 & 1;
}
return result;
}

original_code:
static int
isescaped(const char *sp, const char *p, int esc)
{
 const char *cp;
 size_t ne;
 if (esc == '\0')
  return 1;
 for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++)
  continue;
 return (ne & 1) != 0;
}

canonical_original_code:
static int isescaped(char *sp, char *p, int esc)
{
 char *cp;
 unsigned long ne;
 if (esc == '\0')
  return 1;
 for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++)
  continue;
 return (ne & 1) != 0;
}

variable_types:
sp
char *

variable_types:
p
char *

variable_types: esc int

variable_types:
cp
char *

variable_types:
ne
unsigned long


reallocarray

decompiled_code:
void *__fastcall reallocarray(void *a1, unsigned __int64 a2, unsigned __int64 a3)
{
if ( a3 <= 0xFFFFFFFF && a2 <= 0xFFFFFFFF || !a2 || is_mul_ok(a2, a3) )
return realloc(a1, a3 * a2);
*_errno_location() = 12;
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1, unsigned __int64 a2, unsigned __int64 a3)
{
if ( a3 <= 0xFFFFFFFF && a2 <= 0xFFFFFFFF || !a2 || is_mul_ok(a2, a3) )
return realloc(a1, a3 * a2);
*_errno_location() = 12;
return 0LL;
}

original_code:
void *
reallocarray(void *optr, size_t nmemb, size_t size)
{
 if ((nmemb >= ((size_t)1 << (sizeof(size_t) * 4)) || size >= ((size_t)1 << (sizeof(size_t) * 4))) &&
     nmemb > 0 && (18446744073709551615UL) / nmemb < size) {
  (*__errno_location ()) = 12;
  return ((void *)0);
 }
 return realloc(optr, size * nmemb);
}

canonical_original_code:
void *reallocarray(void *optr, unsigned long nmemb, unsigned long size)
{
 if ((nmemb >= ((unsigned long)1 << (sizeof(unsigned long) * 4)) || size >= ((unsigned long)1 << (sizeof(unsigned long) * 4))) &&
     nmemb > 0 && (18446744073709551615UL) / nmemb < size) {
  (*__errno_location ()) = 12;
  return ((void *)0);
 }
 return realloc(optr, size * nmemb);
}

variable_types:
optr
void *

variable_types:
nmemb
unsigned long

variable_types:
size
unsigned long

return_type: void *


decompiled_code:
void maps_init()
{
void **v0; // rax
__int16 **v1; // rdx
__int16 **v2; // rcx

maps = (__int64)&fundamental_mode;
if ( off_E8 )
{
v0 = &map_table;
v1 = &fundamental_mode;
do
{
v2 = v1;
v1 = (__int16 **)v0;
v0[2] = v2;
v0 += 3;
}
while ( v0[1] );
maps = (__int64)v1;
}
}

canonical_decompiled_code:
void func0()
{
void **v0; // rax
__int16 **v1; // rdx
__int16 **v2; // rcx

maps = (__int64)&fundamental_mode;
if ( off_E8 )
{
v0 = &map_table;
v1 = &fundamental_mode;
do
{
v2 = v1;
v1 = (__int16 **)v0;
v0[2] = v2;
v0 += 3;
}
while ( v0[1] );
maps = (__int64)v1;
}
}

original_code:
void
maps_init(void)
{
 int i;
 struct maps_s *mp;
 maps = &fundamental_mode;
 for (i = 0; map_table[i].p_name != ((void *)0); i++) {
  mp = &map_table[i];
  mp->p_next = maps;
  maps = mp;
 }
}

canonical_original_code:
void maps_init()
{
 int i;
 struct maps_s *mp;
 maps = &fundamental_mode;
 for (i = 0; map_table[i].p_name != ((void *)0); i++) {
  mp = &map_table[i];
  mp->p_next = maps;
  maps = mp;
 }
}

variable_types: i int

variable_types: struct maps_s { struct keymap_s { short map_num; short map_max; int (*map_default)(int, int); struct map_element { short k_base; short k_num; int (**k_funcp)(int, int); struct keymap_s *k_prefmap; } map_element[1]; } *p_map; char *p_name; struct maps_s *p_next; } *


decompiled_code:
__int64 __fastcall maps_add(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x18uLL);
if ( !v2 )
return 0LL;
v2[1] = a2;
*v2 = a1;
v2[2] = maps;
maps = (__int64)v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x18uLL);
if ( !v2 )
return 0LL;
v2[1] = a2;
*v2 = a1;
v2[2] = maps;
maps = (__int64)v2;
return 1LL;
}

original_code:
int
maps_add(KEYMAP *map, const char *name)
{
 struct maps_s *mp;
 if ((mp = malloc(sizeof(*mp))) == ((void *)0))
  return (0);
 mp->p_name = name;
 mp->p_map = map;
 mp->p_next = maps;
 maps = mp;
 return (1);
}

canonical_original_code:
int maps_add(struct keymap_s *map, char *name)
{
 struct maps_s *mp;
 if ((mp = malloc(sizeof(*mp))) == ((void *)0))
  return (0);
 mp->p_name = name;
 mp->p_map = map;
 mp->p_next = maps;
 maps = mp;
 return (1);
}

variable_types: struct keymap_s { short map_num; short map_max; int (*map_default)(int, int); struct map_element { short k_base; short k_num; int (**k_funcp)(int, int); struct keymap_s *k_prefmap; } map_element[1]; } *

variable_types:
name
char *


decompiled_code:
__int64 __fastcall name_mode(char *s2)
{
__int64 i; // rbx

for ( i = maps; i; i = *(_QWORD *)(i + 16) )
{
if ( !strcmp(*(const char **)(i + 8), s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
__int64 i; // rbx

for ( i = maps; i; i = *(_QWORD *)(i + 16) )
{
if ( !strcmp(*(const char **)(i + 8), s2) )
break;
}
return i;
}

original_code:
struct maps_s *
name_mode(const char *name)
{
 struct maps_s *mp;
 for (mp = maps; mp != ((void *)0); mp = mp->p_next)
  if (strcmp(mp->p_name, name) == 0)
   return (mp);
 return (((void *)0));
}

canonical_original_code:
struct maps_s *name_mode(char *name)
{
 struct maps_s *mp;
 for (mp = maps; mp != ((void *)0); mp = mp->p_next)
  if (strcmp(mp->p_name, name) == 0)
   return (mp);
 return (((void *)0));
}

return_type: struct maps_s { struct keymap_s { short map_num; short map_max; int (*map_default)(int, int); struct map_element { short k_base; short k_num; int (**k_funcp)(int, int); struct keymap_s *k_prefmap; } map_element[1]; } *p_map; char *p_name; struct maps_s *p_next; } *


decompiled_code:
void __fastcall explicit_bzero(void *a1, size_t a2)
{
memset(a1, 0, a2);
_explicit_bzero_hook();
}

canonical_decompiled_code:
void __fastcall func1(void *a1, size_t a2)
{
memset(a1, 0, a2);
func0();
}

original_code:
void
explicit_bzero(void *buf, size_t len)
{
 memset(buf, 0, len);
 __explicit_bzero_hook(buf, len);
}

canonical_original_code:
void explicit_bzero(void *buf, unsigned long len)
{
 memset(buf, 0, len);
 __explicit_bzero_hook(buf, len);
}

variable_types:
buf
void *

variable_types:
len
unsigned long


strlcpy

original_code:
size_t
strlcpy(char *dst, const char *src, size_t dsize)
{
 const char *osrc = src;
 size_t nleft = dsize;
 if (nleft != 0) {
  while (--nleft != 0) {
   if ((*dst++ = *src++) == '\0')
    break;
  }
 }
 if (nleft == 0) {
  if (dsize != 0)
   *dst = '\0';
  while (*src++)
   ;
 }
 return(src - osrc - 1);
}

canonical_original_code:
unsigned long strlcpy(char *dst, char *src, unsigned long dsize)
{
 char *osrc = src;
 unsigned long nleft = dsize;
 if (nleft != 0) {
  while (--nleft != 0) {
   if ((*dst++ = *src++) == '\0')
    break;
  }
 }
 if (nleft == 0) {
  if (dsize != 0)
   *dst = '\0';
  while (*src++)
   ;
 }
 return(src - osrc - 1);
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types:
dsize
unsigned long

variable_types:
osrc
char *

variable_types:
nleft
unsigned long

return_type: unsigned long


repo: scottellis/overo-blinkm

decompiled_code:
int __fastcall read_error(unsigned __int8 a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return fprintf(stderr, "Read failed for device 0x%02X: %s\n", a1, v2);
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int8 a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return fprintf(stderr, "Read failed for device 0x%02X: %s\n", a1, v2);
}

original_code:
void read_error(uint8_t led)
{
 fprintf(stderr, "Read failed for device 0x%02X: %s\n", led, strerror((*__errno_location ())));
}

canonical_original_code:
void read_error(unsigned char led)
{
 fprintf(stderr, "Read failed for device 0x%02X: %s\n", led, strerror((*__errno_location ())));
}

variable_types:
led
unsigned char


decompiled_code:
int __fastcall write_error(unsigned __int8 a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return fprintf(stderr, "Write failed for device 0x%02X: %s\n", a1, v2);
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int8 a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return fprintf(stderr, "Write failed for device 0x%02X: %s\n", a1, v2);
}

original_code:
void write_error(uint8_t led)
{
 fprintf(stderr, "Write failed for device 0x%02X: %s\n", led, strerror((*__errno_location ())));
}

canonical_original_code:
void write_error(unsigned char led)
{
 fprintf(stderr, "Write failed for device 0x%02X: %s\n", led, strerror((*__errno_location ())));
}


decompiled_code:
__int64 __fastcall blinkm_get_address(unsigned __int8 a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // er12
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = i2c_start_transaction(a1);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
buf[0] = 97;
if ( (unsigned int)write(v1, buf, 1uLL) == 1 )
{
buf[0] = 0;
v3 = read(v2, buf, 1uLL);
if ( v3 != 1 )
{
read_error(a1);
v3 = -1;
}
}
else
{
write_error(a1);
v3 = -1;
}
i2c_end_transaction(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // er12
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = i2c_start_transaction(a1);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
buf[0] = 97;
if ( (unsigned int)write(v1, buf, 1uLL) == 1 )
{
buf[0] = 0;
v3 = read(v2, buf, 1uLL);
if ( v3 != 1 )
{
func0(a1);
v3 = -1;
}
}
else
{
func1(a1);
v3 = -1;
}
i2c_end_transaction(v2);
return v3;
}

original_code:
int blinkm_get_address(uint8_t led)
{
 int fh, result;
 uint8_t data;
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data = 0x61;
 result = write(fh, &data, 1);
 if (result == 1) {
  data = 0;
  result = read(fh, &data, 1);
  if (result != 1) {
   read_error(led);
   result = -1;
  }
 } else {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

canonical_original_code:
int blinkm_get_address(unsigned char led)
{
 int fh; int result;
 unsigned char data;
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data = 0x61;
 result = write(fh, &data, 1);
 if (result == 1) {
  data = 0;
  result = read(fh, &data, 1);
  if (result != 1) {
   read_error(led);
   result = -1;
  }
 } else {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

variable_types: fh int

variable_types: result int

variable_types:
data
unsigned char


decompiled_code:
__int64 __fastcall blinkm_set_address(unsigned __int8 a1)
{
int v1; // eax
unsigned int v2; // ebp
unsigned int v3; // ebx
char buf[32]; // [rsp+8h] [rbp-20h] BYREF

v1 = i2c_start_transaction(0LL);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
buf[0] = 65;
buf[1] = a1;
buf[2] = -48;
buf[3] = 13;
buf[4] = a1;
if ( (unsigned int)write(v1, buf, 5uLL) == 5 )
{
v3 = a1;
fprintf(stdout, "Set new blinkm address to 0x%02X\n", a1);
}
else
{
write_error(0);
v3 = -1;
}
i2c_end_transaction(v2);
msleep(100LL);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1)
{
int v1; // eax
unsigned int v2; // ebp
unsigned int v3; // ebx
char buf[32]; // [rsp+8h] [rbp-20h] BYREF

v1 = i2c_start_transaction(0LL);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
buf[0] = 65;
buf[1] = a1;
buf[2] = -48;
buf[3] = 13;
buf[4] = a1;
if ( (unsigned int)write(v1, buf, 5uLL) == 5 )
{
v3 = a1;
fprintf(stdout, "Set new blinkm address to 0x%02X\n", a1);
}
else
{
func1(0);
v3 = -1;
}
i2c_end_transaction(v2);
msleep(100LL);
return v3;
}

original_code:
int blinkm_set_address(uint8_t new_addr)
{
 int fh, result;
 uint8_t data[8];
 fh = i2c_start_transaction(0x00);
 if (fh < 0)
  return -1;
 data[0] = 0x41;
 data[1] = new_addr;
 data[2] = 0xd0;
 data[3] = 0x0d;
 data[4] = new_addr;
 result = write(fh, &data, 5);
 if (result == 5) {
  fprintf(stdout, "Set new blinkm address to 0x%02X\n", new_addr);
  result = new_addr;
 } else {
  write_error(0x00);
  result = -1;
 }
 i2c_end_transaction(fh);
 msleep(100);
 return result;
}

canonical_original_code:
int blinkm_set_address(unsigned char new_addr)
{
 int fh; int result;
 unsigned char data[8];
 fh = i2c_start_transaction(0x00);
 if (fh < 0)
  return -1;
 data[0] = 0x41;
 data[1] = new_addr;
 data[2] = 0xd0;
 data[3] = 0x0d;
 data[4] = new_addr;
 result = write(fh, &data, 5);
 if (result == 5) {
  fprintf(stdout, "Set new blinkm address to 0x%02X\n", new_addr);
  result = new_addr;
 } else {
  write_error(0x00);
  result = -1;
 }
 i2c_end_transaction(fh);
 msleep(100);
 return result;
}

variable_types:
data
unsigned char [8]


decompiled_code:
__int64 __fastcall blinkm_set_rgb_color_now(unsigned __int8 a1, char a2, char a3, char a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
return (unsigned int)-1;
v7 = v6;
buf[0] = 110;
buf[1] = a2;
buf[2] = a3;
buf[3] = a4;
v8 = write(v6, buf, 4uLL);
if ( v8 != 4 )
{
write_error(a1);
v8 = -1;
}
i2c_end_transaction(v7);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1, char a2, char a3, char a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
return (unsigned int)-1;
v7 = v6;
buf[0] = 110;
buf[1] = a2;
buf[2] = a3;
buf[3] = a4;
v8 = write(v6, buf, 4uLL);
if ( v8 != 4 )
{
func1(a1);
v8 = -1;
}
i2c_end_transaction(v7);
return v8;
}

original_code:
int blinkm_set_rgb_color_now(uint8_t led, uint8_t r, uint8_t g, uint8_t b)
{
 int fh, result;
 uint8_t data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x6E;
 data[1] = r;
 data[2] = g;
 data[3] = b;
 result = write(fh, data, 4);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

canonical_original_code:
int blinkm_set_rgb_color_now(unsigned char led, unsigned char r, unsigned char g, unsigned char b)
{
 int fh; int result;
 unsigned char data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x6E;
 data[1] = r;
 data[2] = g;
 data[3] = b;
 result = write(fh, data, 4);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

variable_types:
r
unsigned char

variable_types:
g
unsigned char

variable_types:
b
unsigned char

variable_types:
data
unsigned char [4]


decompiled_code:
__int64 __fastcall blinkm_fade_to_rgb_color(unsigned __int8 a1, char a2, char a3, char a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
return (unsigned int)-1;
v7 = v6;
buf[0] = 99;
buf[1] = a2;
buf[2] = a3;
buf[3] = a4;
v8 = write(v6, buf, 4uLL);
if ( v8 != 4 )
{
write_error(a1);
v8 = -1;
}
i2c_end_transaction(v7);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1, char a2, char a3, char a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
return (unsigned int)-1;
v7 = v6;
buf[0] = 99;
buf[1] = a2;
buf[2] = a3;
buf[3] = a4;
v8 = write(v6, buf, 4uLL);
if ( v8 != 4 )
{
func1(a1);
v8 = -1;
}
i2c_end_transaction(v7);
return v8;
}

original_code:
int blinkm_fade_to_rgb_color(uint8_t led, uint8_t r, uint8_t g, uint8_t b)
{
 int fh, result;
 uint8_t data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x63;
 data[1] = r;
 data[2] = g;
 data[3] = b;
 result = write(fh, data, 4);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

canonical_original_code:
int blinkm_fade_to_rgb_color(unsigned char led, unsigned char r, unsigned char g, unsigned char b)
{
 int fh; int result;
 unsigned char data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x63;
 data[1] = r;
 data[2] = g;
 data[3] = b;
 result = write(fh, data, 4);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}


decompiled_code:
__int64 __fastcall blinkm_fade_to_hsb_color(unsigned __int8 a1, char a2, char a3, char a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
return (unsigned int)-1;
v7 = v6;
buf[0] = 104;
buf[1] = a2;
buf[2] = a3;
buf[3] = a4;
v8 = write(v6, buf, 4uLL);
if ( v8 != 4 )
{
write_error(a1);
v8 = -1;
}
i2c_end_transaction(v7);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1, char a2, char a3, char a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
return (unsigned int)-1;
v7 = v6;
buf[0] = 104;
buf[1] = a2;
buf[2] = a3;
buf[3] = a4;
v8 = write(v6, buf, 4uLL);
if ( v8 != 4 )
{
func1(a1);
v8 = -1;
}
i2c_end_transaction(v7);
return v8;
}

original_code:
int blinkm_fade_to_hsb_color(uint8_t led, uint8_t h, uint8_t s, uint8_t b)
{
 int fh, result;
 uint8_t data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x68;
 data[1] = h;
 data[2] = s;
 data[3] = b;
 result = write(fh, data, 4);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

canonical_original_code:
int blinkm_fade_to_hsb_color(unsigned char led, unsigned char h, unsigned char s, unsigned char b)
{
 int fh; int result;
 unsigned char data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x68;
 data[1] = h;
 data[2] = s;
 data[3] = b;
 result = write(fh, data, 4);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

variable_types:
h
unsigned char

variable_types:
s
unsigned char


decompiled_code:
__int64 __fastcall blinkm_fade_to_random_rgb_color(unsigned __int8 a1, char a2, char a3, char a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
return (unsigned int)-1;
v7 = v6;
buf[0] = 67;
buf[1] = a2;
buf[2] = a3;
buf[3] = a4;
v8 = write(v6, buf, 4uLL);
if ( v8 != 4 )
{
write_error(a1);
v8 = -1;
}
i2c_end_transaction(v7);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 a1, char a2, char a3, char a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
return (unsigned int)-1;
v7 = v6;
buf[0] = 67;
buf[1] = a2;
buf[2] = a3;
buf[3] = a4;
v8 = write(v6, buf, 4uLL);
if ( v8 != 4 )
{
func1(a1);
v8 = -1;
}
i2c_end_transaction(v7);
return v8;
}

original_code:
int blinkm_fade_to_random_rgb_color(uint8_t led, uint8_t r, uint8_t g, uint8_t b)
{
 int fh, result;
 uint8_t data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x43;
 data[1] = r;
 data[2] = g;
 data[3] = b;
 result = write(fh, data, 4);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

canonical_original_code:
int blinkm_fade_to_random_rgb_color(unsigned char led, unsigned char r, unsigned char g, unsigned char b)
{
 int fh; int result;
 unsigned char data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x43;
 data[1] = r;
 data[2] = g;
 data[3] = b;
 result = write(fh, data, 4);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}


decompiled_code:
__int64 __fastcall blinkm_fade_to_random_hsb_color(unsigned __int8 a1, char a2, char a3, char a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
return (unsigned int)-1;
v7 = v6;
buf[0] = 72;
buf[1] = a2;
buf[2] = a3;
buf[3] = a4;
v8 = write(v6, buf, 4uLL);
if ( v8 != 4 )
{
write_error(a1);
v8 = -1;
}
i2c_end_transaction(v7);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 a1, char a2, char a3, char a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
return (unsigned int)-1;
v7 = v6;
buf[0] = 72;
buf[1] = a2;
buf[2] = a3;
buf[3] = a4;
v8 = write(v6, buf, 4uLL);
if ( v8 != 4 )
{
func1(a1);
v8 = -1;
}
i2c_end_transaction(v7);
return v8;
}

original_code:
int blinkm_fade_to_random_hsb_color(uint8_t led, uint8_t h, uint8_t s, uint8_t b)
{
 int fh, result;
 uint8_t data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x48;
 data[1] = h;
 data[2] = s;
 data[3] = b;
 result = write(fh, data, 4);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

canonical_original_code:
int blinkm_fade_to_random_hsb_color(unsigned char led, unsigned char h, unsigned char s, unsigned char b)
{
 int fh; int result;
 unsigned char data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x48;
 data[1] = h;
 data[2] = s;
 data[3] = b;
 result = write(fh, data, 4);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}


decompiled_code:
__int64 __fastcall blinkm_get_current_rgb_color(unsigned __int8 a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // ebp
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = i2c_start_transaction(a1);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
LOBYTE(buf[0]) = 103;
if ( (unsigned int)write(v1, buf, 1uLL) == 1 )
{
buf[0] = 0;
if ( (unsigned int)read(v2, buf, 3uLL) == 3 )
{
v3 = BYTE2(buf[0]) + (LOBYTE(buf[0]) << 16) + (BYTE1(buf[0]) << 8);
}
else
{
read_error(a1);
v3 = -1;
}
}
else
{
write_error(a1);
v3 = -1;
}
i2c_end_transaction(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // ebp
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = i2c_start_transaction(a1);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
LOBYTE(buf[0]) = 103;
if ( (unsigned int)write(v1, buf, 1uLL) == 1 )
{
buf[0] = 0;
if ( (unsigned int)read(v2, buf, 3uLL) == 3 )
{
v3 = BYTE2(buf[0]) + (LOBYTE(buf[0]) << 16) + (BYTE1(buf[0]) << 8);
}
else
{
func0(a1);
v3 = -1;
}
}
else
{
func1(a1);
v3 = -1;
}
i2c_end_transaction(v2);
return v3;
}

original_code:
int blinkm_get_current_rgb_color(uint8_t led)
{
 int fh, result;
 uint8_t data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x67;
 result = write(fh, data, 1);
 if (result == 1) {
  bzero(data, sizeof(data));
  result = read(fh, data, 3);
  if (result == 3) {
   result = (data[0] << 16) + (data[1] << 8) + data[2];
  } else {
   read_error(led);
   result = -1;
  }
 } else {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

canonical_original_code:
int blinkm_get_current_rgb_color(unsigned char led)
{
 int fh; int result;
 unsigned char data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x67;
 result = write(fh, data, 1);
 if (result == 1) {
  bzero(data, sizeof(data));
  result = read(fh, data, 3);
  if (result == 3) {
   result = (data[0] << 16) + (data[1] << 8) + data[2];
  } else {
   read_error(led);
   result = -1;
  }
 } else {
  write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}


decompiled_code:
__int64 __fastcall blinkm_stop_script(unsigned __int8 a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // er13
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

v1 = i2c_start_transaction(a1);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
buf[0] = 111;
v3 = write(v1, buf, 1uLL);
i2c_end_transaction(v2);
if ( v3 != 1 )
{
write_error(a1);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // er13
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

v1 = i2c_start_transaction(a1);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
buf[0] = 111;
v3 = write(v1, buf, 1uLL);
i2c_end_transaction(v2);
if ( v3 != 1 )
{
func1(a1);
v3 = -1;
}
return v3;
}

original_code:
int blinkm_stop_script(uint8_t led)
{
 int fh, result;
 uint8_t data;
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data = 0x6F;
 result = write(fh, &data, 1);
 i2c_end_transaction(fh);
 if (result != 1) {
  write_error(led);
  result = -1;
 }
 return result;
}

canonical_original_code:
int blinkm_stop_script(unsigned char led)
{
 int fh; int result;
 unsigned char data;
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data = 0x6F;
 result = write(fh, &data, 1);
 i2c_end_transaction(fh);
 if (result != 1) {
  write_error(led);
  result = -1;
 }
 return result;
}


decompiled_code:
__int64 __fastcall blinkm_play_script(unsigned __int8 a1, char a2, char a3)
{
int v4; // eax
unsigned int v5; // ebx
unsigned int v6; // er13
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = i2c_start_transaction(a1);
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
buf[0] = 112;
buf[1] = a2;
buf[2] = a3;
buf[3] = 0;
v6 = write(v4, buf, 4uLL);
i2c_end_transaction(v5);
if ( v6 != 4 )
{
write_error(a1);
v6 = -1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 a1, char a2, char a3)
{
int v4; // eax
unsigned int v5; // ebx
unsigned int v6; // er13
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = i2c_start_transaction(a1);
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
buf[0] = 112;
buf[1] = a2;
buf[2] = a3;
buf[3] = 0;
v6 = write(v4, buf, 4uLL);
i2c_end_transaction(v5);
if ( v6 != 4 )
{
func1(a1);
v6 = -1;
}
return v6;
}

original_code:
int blinkm_play_script(uint8_t led, uint8_t script_id, uint8_t num_repeats)
{
 int fh, result;
 uint8_t data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x70;
 data[1] = script_id;
 data[2] = num_repeats;
 data[3] = 0;
 result = write(fh, data, 4);
 i2c_end_transaction(fh);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 return result;
}

canonical_original_code:
int blinkm_play_script(unsigned char led, unsigned char script_id, unsigned char num_repeats)
{
 int fh; int result;
 unsigned char data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x70;
 data[1] = script_id;
 data[2] = num_repeats;
 data[3] = 0;
 result = write(fh, data, 4);
 i2c_end_transaction(fh);
 if (result != 4) {
  write_error(led);
  result = -1;
 }
 return result;
}


decompiled_code:
__int64 __fastcall blinkm_set_fade_speed(unsigned __int8 a1, char a2)
{
int v2; // eax
unsigned int v3; // ebx
unsigned int v4; // er13
char buf[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v2 = i2c_start_transaction(a1);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
buf[0] = 102;
buf[1] = a2;
v4 = write(v2, buf, 2uLL);
i2c_end_transaction(v3);
if ( v4 != 2 )
{
write_error(a1);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int8 a1, char a2)
{
int v2; // eax
unsigned int v3; // ebx
unsigned int v4; // er13
char buf[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v2 = i2c_start_transaction(a1);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
buf[0] = 102;
buf[1] = a2;
v4 = write(v2, buf, 2uLL);
i2c_end_transaction(v3);
if ( v4 != 2 )
{
func1(a1);
v4 = -1;
}
return v4;
}

original_code:
int blinkm_set_fade_speed(uint8_t led, uint8_t speed)
{
 int fh, result;
 uint8_t data[2];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x66;
 data[1] = speed;
 result = write(fh, data, 2);
 i2c_end_transaction(fh);
 if (result != 2) {
  write_error(led);
  result = -1;
 }
 return result;
}

canonical_original_code:
int blinkm_set_fade_speed(unsigned char led, unsigned char speed)
{
 int fh; int result;
 unsigned char data[2];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x66;
 data[1] = speed;
 result = write(fh, data, 2);
 i2c_end_transaction(fh);
 if (result != 2) {
  write_error(led);
  result = -1;
 }
 return result;
}

variable_types:
speed
unsigned char

variable_types:
data
unsigned char [2]


decompiled_code:
__int64 __fastcall blinkm_set_time_adjust(unsigned __int8 a1, char a2)
{
int v2; // eax
unsigned int v3; // ebx
unsigned int v4; // er13
char buf[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v2 = i2c_start_transaction(a1);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
buf[0] = 116;
buf[1] = a2;
v4 = write(v2, buf, 2uLL);
i2c_end_transaction(v3);
if ( v4 != 2 )
{
write_error(a1);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 a1, char a2)
{
int v2; // eax
unsigned int v3; // ebx
unsigned int v4; // er13
char buf[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v2 = i2c_start_transaction(a1);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
buf[0] = 116;
buf[1] = a2;
v4 = write(v2, buf, 2uLL);
i2c_end_transaction(v3);
if ( v4 != 2 )
{
func1(a1);
v4 = -1;
}
return v4;
}

original_code:
int blinkm_set_time_adjust(uint8_t led, int8_t adjust)
{
 int fh, result;
 uint8_t data[2];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x74;
 data[1] = adjust;
 result = write(fh, data, 2);
 i2c_end_transaction(fh);
 if (result != 2) {
  write_error(led);
  result = -1;
 }
 return result;
}

canonical_original_code:
int blinkm_set_time_adjust(unsigned char led, char adjust)
{
 int fh; int result;
 unsigned char data[2];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x74;
 data[1] = adjust;
 result = write(fh, data, 2);
 i2c_end_transaction(fh);
 if (result != 2) {
  write_error(led);
  result = -1;
 }
 return result;
}

variable_types: adjust char


decompiled_code:
__int64 __fastcall blinkm_read_script_line(unsigned __int8 a1, char a2, __int64 a3)
{
int v4; // eax
unsigned int v5; // ebp
unsigned int v6; // er13
__int64 buf[6]; // [rsp+8h] [rbp-30h] BYREF

if ( !a3 )
return (unsigned int)-1;
v4 = i2c_start_transaction(a1);
v5 = v4;
if ( v4 < 0 )
return (unsigned int)-1;
LOWORD(buf[0]) = 82;
BYTE2(buf[0]) = a2;
if ( (unsigned int)write(v4, buf, 3uLL) == 3 )
{
buf[0] = 0LL;
v6 = read(v5, buf, 5uLL);
if ( v6 == 5 )
{
*(_DWORD *)a3 = buf[0];
*(_BYTE *)(a3 + 4) = BYTE4(buf[0]);
}
else
{
read_error(a1);
v6 = -1;
}
}
else
{
write_error(a1);
v6 = -1;
}
i2c_end_transaction(v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int8 a1, char a2, __int64 a3)
{
int v4; // eax
unsigned int v5; // ebp
unsigned int v6; // er13
__int64 buf[6]; // [rsp+8h] [rbp-30h] BYREF

if ( !a3 )
return (unsigned int)-1;
v4 = i2c_start_transaction(a1);
v5 = v4;
if ( v4 < 0 )
return (unsigned int)-1;
LOWORD(buf[0]) = 82;
BYTE2(buf[0]) = a2;
if ( (unsigned int)write(v4, buf, 3uLL) == 3 )
{
buf[0] = 0LL;
v6 = read(v5, buf, 5uLL);
if ( v6 == 5 )
{
*(_DWORD *)a3 = buf[0];
*(_BYTE *)(a3 + 4) = BYTE4(buf[0]);
}
else
{
func0(a1);
v6 = -1;
}
}
else
{
func1(a1);
v6 = -1;
}
i2c_end_transaction(v5);
return v6;
}

original_code:
int blinkm_read_script_line(uint8_t led, uint8_t line_no, struct script_line *s)
{
 int fh, result;
 uint8_t data[8];
 if (!s)
  return -1;
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x52;
 data[1] = 0x00;
 data[2] = line_no;
 result = write(fh, data, 3);
 if (result != 3) {
  write_error(led);
  result = -1;
 } else {
  bzero(data, sizeof(data));
  result = read(fh, data, 5);
  if (result != 5) {
   read_error(led);
   result = -1;
  } else {
   s->_ticks = data[0];
   s->_cmd = data[1];
   s->_arg[0] = data[2];
   s->_arg[1] = data[3];
   s->_arg[2] = data[4];
  }
 }
 i2c_end_transaction(fh);
 return result;
}

canonical_original_code:
int blinkm_read_script_line(unsigned char led, unsigned char line_no, struct script_line *s)
{
 int fh; int result;
 unsigned char data[8];
 if (!s)
  return -1;
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x52;
 data[1] = 0x00;
 data[2] = line_no;
 result = write(fh, data, 3);
 if (result != 3) {
  write_error(led);
  result = -1;
 } else {
  bzero(data, sizeof(data));
  result = read(fh, data, 5);
  if (result != 5) {
   read_error(led);
   result = -1;
  } else {
   s->_ticks = data[0];
   s->_cmd = data[1];
   s->_arg[0] = data[2];
   s->_arg[1] = data[3];
   s->_arg[2] = data[4];
  }
 }
 i2c_end_transaction(fh);
 return result;
}

variable_types: struct script_line { unsigned char _ticks; unsigned char _cmd; unsigned char _arg[3]; } *


decompiled_code:
__int64 __fastcall blinkm_write_script_line(unsigned __int8 a1, unsigned __int8 a2, char *a3)
{
unsigned __int8 v4; // dl
unsigned int v5; // ebx
int v6; // er12
char buf[48]; // [rsp+8h] [rbp-30h] BYREF

if ( !a3 )
return (unsigned int)-1;
if ( a2 > 0x31u )
{
fprintf(stderr, "Invalid script line number %d\n", a2);
v5 = -1;
}
else
{
v4 = a3[1];
switch ( v4 )
{
case 'C':
case 'H':
case 'c':
case 'f':
case 'h':
case 'n':
case 't':
v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
{
v5 = -1;
}
else
{
buf[0] = 87;
buf[1] = 0;
buf[2] = a2;
buf[3] = *a3;
buf[4] = a3[1];
buf[5] = a3[2];
buf[6] = a3[3];
buf[7] = a3[4];
v5 = write(v6, buf, 8uLL);
if ( v5 != 8 )
{
write_error(a1);
v5 = -1;
}
msleep(100LL);
i2c_end_transaction((unsigned int)v6);
}
break;
default:
fprintf(stderr, "Invalid script command 0x%02X\n", v4);
v5 = -1;
break;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int8 a1, unsigned __int8 a2, char *a3)
{
unsigned __int8 v4; // dl
unsigned int v5; // ebx
int v6; // er12
char buf[48]; // [rsp+8h] [rbp-30h] BYREF

if ( !a3 )
return (unsigned int)-1;
if ( a2 > 0x31u )
{
fprintf(stderr, "Invalid script line number %d\n", a2);
v5 = -1;
}
else
{
v4 = a3[1];
switch ( v4 )
{
case 'C':
case 'H':
case 'c':
case 'f':
case 'h':
case 'n':
case 't':
v6 = i2c_start_transaction(a1);
if ( v6 < 0 )
{
v5 = -1;
}
else
{
buf[0] = 87;
buf[1] = 0;
buf[2] = a2;
buf[3] = *a3;
buf[4] = a3[1];
buf[5] = a3[2];
buf[6] = a3[3];
buf[7] = a3[4];
v5 = write(v6, buf, 8uLL);
if ( v5 != 8 )
{
func1(a1);
v5 = -1;
}
msleep(100LL);
i2c_end_transaction((unsigned int)v6);
}
break;
default:
fprintf(stderr, "Invalid script command 0x%02X\n", v4);
v5 = -1;
break;
}
}
return v5;
}

original_code:
int blinkm_write_script_line(uint8_t led, uint8_t line_no, struct script_line *s)
{
 int fh, result;
 uint8_t data[8];
 if (!s)
  return -1;
 if (line_no > 49) {
  fprintf(stderr, "Invalid script line number %d\n", line_no);
  return -1;
 }
 switch (s->_cmd) {
 case 0x6E:
 case 0x63:
 case 0x68:
 case 0x43:
 case 0x48:
 case 0x66:
 case 0x74:
  break;
 default:
  fprintf(stderr, "Invalid script command 0x%02X\n", s->_cmd);
  return -1;
 }
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x57;
 data[1] = 0x00;
 data[2] = line_no;
 data[3] = s->_ticks;
 data[4] = s->_cmd;
 data[5] = s->_arg[0];
 data[6] = s->_arg[1];
 data[7] = s->_arg[2];
 result = write(fh, data, 8);
 if (result != 8) {
  write_error(led);
  result = -1;
 }
 msleep(100);
 i2c_end_transaction(fh);
 return result;
}

canonical_original_code:
int blinkm_write_script_line(unsigned char led, unsigned char line_no, struct script_line *s)
{
 int fh; int result;
 unsigned char data[8];
 if (!s)
  return -1;
 if (line_no > 49) {
  fprintf(stderr, "Invalid script line number %d\n", line_no);
  return -1;
 }
 switch (s->_cmd) {
 case 0x6E:
 case 0x63:
 case 0x68:
 case 0x43:
 case 0x48:
 case 0x66:
 case 0x74:
  break;
 default:
  fprintf(stderr, "Invalid script command 0x%02X\n", s->_cmd);
  return -1;
 }
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x57;
 data[1] = 0x00;
 data[2] = line_no;
 data[3] = s->_ticks;
 data[4] = s->_cmd;
 data[5] = s->_arg[0];
 data[6] = s->_arg[1];
 data[7] = s->_arg[2];
 result = write(fh, data, 8);
 if (result != 8) {
  write_error(led);
  result = -1;
 }
 msleep(100);
 i2c_end_transaction(fh);
 return result;
}

user_defined_types: struct script_line { unsigned char _ticks; unsigned char _cmd; unsigned char _arg[3]; }


decompiled_code:
__int64 __fastcall blinkm_set_script_length_and_repeats(unsigned __int8 a1, char a2, char a3)
{
int v4; // eax
unsigned int v5; // ebx
unsigned int v6; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = i2c_start_transaction(a1);
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
buf[0] = 76;
buf[1] = a2;
buf[2] = a3;
v6 = write(v4, buf, 3uLL);
if ( v6 != 3 )
{
write_error(a1);
v6 = -1;
}
msleep(50LL);
i2c_end_transaction(v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned __int8 a1, char a2, char a3)
{
int v4; // eax
unsigned int v5; // ebx
unsigned int v6; // er12
char buf[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = i2c_start_transaction(a1);
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
buf[0] = 76;
buf[1] = a2;
buf[2] = a3;
v6 = write(v4, buf, 3uLL);
if ( v6 != 3 )
{
func1(a1);
v6 = -1;
}
msleep(50LL);
i2c_end_transaction(v5);
return v6;
}

original_code:
int blinkm_set_script_length_and_repeats(uint8_t led, uint8_t length, uint8_t repeats)
{
 int fh, result;
 uint8_t data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x4C;
 data[1] = length;
 data[2] = repeats;
 result = write(fh, data, 3);
 if (result != 3) {
  write_error(led);
  result = -1;
 }
 msleep(50);
 i2c_end_transaction(fh);
 return result;
}

canonical_original_code:
int blinkm_set_script_length_and_repeats(unsigned char led, unsigned char length, unsigned char repeats)
{
 int fh; int result;
 unsigned char data[4];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x4C;
 data[1] = length;
 data[2] = repeats;
 result = write(fh, data, 3);
 if (result != 3) {
  write_error(led);
  result = -1;
 }
 msleep(50);
 i2c_end_transaction(fh);
 return result;
}

variable_types:
length
unsigned char

variable_types:
repeats
unsigned char


decompiled_code:
__int64 __fastcall blinkm_get_firmware_version(unsigned __int8 a1, int a2)
{
int v2; // eax
unsigned int v3; // ebx
unsigned int v4; // ebp
unsigned __int8 buf; // [rsp+Eh] [rbp-2Ah] BYREF
unsigned __int8 v7; // [rsp+Fh] [rbp-29h]

v2 = i2c_start_transaction(a1);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
buf = 90;
if ( (unsigned int)write(v2, &buf, 1uLL) == 1 )
{
buf = 0;
v7 = 0;
if ( (unsigned int)read(v3, &buf, 2uLL) == 2 )
{
v4 = (buf << 8) | v7;
}
else
{
v4 = -1;
if ( a2 )
read_error(a1);
}
}
else
{
v4 = -1;
if ( a2 )
write_error(a1);
}
i2c_end_transaction(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned __int8 a1, int a2)
{
int v2; // eax
unsigned int v3; // ebx
unsigned int v4; // ebp
unsigned __int8 buf; // [rsp+Eh] [rbp-2Ah] BYREF
unsigned __int8 v7; // [rsp+Fh] [rbp-29h]

v2 = i2c_start_transaction(a1);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
buf = 90;
if ( (unsigned int)write(v2, &buf, 1uLL) == 1 )
{
buf = 0;
v7 = 0;
if ( (unsigned int)read(v3, &buf, 2uLL) == 2 )
{
v4 = (buf << 8) | v7;
}
else
{
v4 = -1;
if ( a2 )
func0(a1);
}
}
else
{
v4 = -1;
if ( a2 )
func1(a1);
}
i2c_end_transaction(v3);
return v4;
}

original_code:
int blinkm_get_firmware_version(uint8_t led, int verbose)
{
 int fh, result;
 uint8_t data[2];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x5A;
 result = write(fh, data, 1);
 if (result == 1) {
  data[0] = 0;
  data[1] = 0;
  result = read(fh, data, 2);
  if (result != 2) {
   if (verbose)
    read_error(led);
   result = -1;
  } else {
   result = data[0];
   result <<= 8;
   result |= data[1];
  }
 } else {
  if (verbose)
   write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

canonical_original_code:
int blinkm_get_firmware_version(unsigned char led, int verbose)
{
 int fh; int result;
 unsigned char data[2];
 fh = i2c_start_transaction(led);
 if (fh < 0)
  return -1;
 data[0] = 0x5A;
 result = write(fh, data, 1);
 if (result == 1) {
  data[0] = 0;
  data[1] = 0;
  result = read(fh, data, 2);
  if (result != 2) {
   if (verbose)
    read_error(led);
   result = -1;
  } else {
   result = data[0];
   result <<= 8;
   result |= data[1];
  }
 } else {
  if (verbose)
   write_error(led);
  result = -1;
 }
 i2c_end_transaction(fh);
 return result;
}

variable_types:
led
unsigned char

variable_types: verbose int


decompiled_code:
__int64 i2c_open_device()
{
int v0; // ebx
int *v2; // rax
char *v3; // rax

v0 = open(i2c_bus, 2);
if ( v0 < 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "Error: Could not open file %s: %s\n", i2c_bus, v3);
}
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebx
int *v2; // rax
char *v3; // rax

v0 = open(i2c_bus, 2);
if ( v0 < 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "Error: Could not open file %s: %s\n", i2c_bus, v3);
}
return (unsigned int)v0;
}

original_code:
int i2c_open_device()
{
 int fh = -1;
 fh = open(i2c_bus, 02);
 if (fh < 0) {
  fprintf(stderr, "Error: Could not open file %s: %s\n",
    i2c_bus, strerror((*__errno_location ())));
 }
 return fh;
}

variable_types: fh int


decompiled_code:
__int64 __fastcall i2c_set_slave_address(int a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3; // edx
int v4; // edi
char *v5; // rax

result = 0xFFFFFFFFLL;
if ( a1 >= 0 )
{
v3 = ioctl(a1, 0x703uLL, a2);
result = 1LL;
if ( v3 < 0 )
{
v4 = *_errno_location();
if ( v4 == 16 )
{
fprintf(stderr, "Device %d is busy!\n", a2);
}
else
{
v5 = strerror(v4);
fprintf(stderr, "Could not set slave address to 0x%02x: %s\n", a2, v5);
}
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3; // edx
int v4; // edi
char *v5; // rax

result = 0xFFFFFFFFLL;
if ( a1 >= 0 )
{
v3 = ioctl(a1, 0x703uLL, a2);
result = 1LL;
if ( v3 < 0 )
{
v4 = *_errno_location();
if ( v4 == 16 )
{
fprintf(stderr, "Device %d is busy!\n", a2);
}
else
{
v5 = strerror(v4);
fprintf(stderr, "Could not set slave address to 0x%02x: %s\n", a2, v5);
}
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int i2c_set_slave_address(int fh, uint8_t address)
{
 if (fh < 0)
  return -1;
 if (ioctl(fh, 0x0703, address) < 0) {
  if ((*__errno_location ()) == 16)
   fprintf(stderr, "Device %d is busy!\n", address);
  else
   fprintf(stderr, "Could not set slave address to 0x%02x: %s\n",
    address, strerror((*__errno_location ())));
  return -1;
 }
 return 1;
}

canonical_original_code:
int i2c_set_slave_address(int fh, unsigned char address)
{
 if (fh < 0)
  return -1;
 if (ioctl(fh, 0x0703, address) < 0) {
  if ((*__errno_location ()) == 16)
   fprintf(stderr, "Device %d is busy!\n", address);
  else
   fprintf(stderr, "Could not set slave address to 0x%02x: %s\n",
    address, strerror((*__errno_location ())));
  return -1;
 }
 return 1;
}

variable_types:
address
unsigned char


decompiled_code:
__int64 __fastcall i2c_start_transaction(unsigned __int8 a1)
{
int v1; // eax
unsigned int v2; // ebx
int v3; // ebp

v1 = i2c_open_device();
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
v3 = i2c_set_slave_address(v1, a1);
if ( v3 < 0 )
{
close(v2);
v2 = v3;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1)
{
int v1; // eax
unsigned int v2; // ebx
int v3; // ebp

v1 = func0();
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
v3 = func1(v1, a1);
if ( v3 < 0 )
{
close(v2);
v2 = v3;
}
return v2;
}

original_code:
int i2c_start_transaction(uint8_t slave_address)
{
 int fh, result;
 fh = i2c_open_device();
 if (fh < 0)
  return -1;
 result = i2c_set_slave_address(fh, slave_address);
 if (result < 0) {
  close(fh);
  return result;
 }
 return fh;
}

canonical_original_code:
int i2c_start_transaction(unsigned char slave_address)
{
 int fh; int result;
 fh = i2c_open_device();
 if (fh < 0)
  return -1;
 result = i2c_set_slave_address(fh, slave_address);
 if (result < 0) {
  close(fh);
  return result;
 }
 return fh;
}

variable_types: result int


decompiled_code:
__int64 __fastcall i2c_end_transaction(int a1)
{
if ( a1 > 0 )
close(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( a1 > 0 )
close(a1);
return 1LL;
}

original_code:
int i2c_end_transaction(int fh)
{
 if (fh > 0)
  close(fh);
 return 1;
}


msleep

decompiled_code:
int __fastcall msleep(int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

if ( a1 <= 0 )
return -2;
v2.tv_sec = a1 / 1000;
v2.tv_nsec = 1000000 * (a1 % 1000);
return nanosleep(&v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

if ( a1 <= 0 )
return -2;
v2.tv_sec = a1 / 1000;
v2.tv_nsec = 1000000 * (a1 % 1000);
return nanosleep(&v2, 0LL);
}

original_code:
int msleep(int milliseconds)
{
 struct timespec ts;
 if (milliseconds < 1) {
  return -2;
 }
 ts.tv_sec = milliseconds / 1000;
 ts.tv_nsec = 1000000 * (milliseconds % 1000);
 return nanosleep(&ts, ((void *)0));
}

variable_types: milliseconds int

variable_types: struct timespec { long tv_sec; long tv_nsec; }


repo: scottellis/polladc

decompiled_code:
void sigint_handler()
{
abort_read = 1;
}

canonical_decompiled_code:
void func7()
{
abort_read = 1;
}

original_code:
void sigint_handler(int sig)
{
    abort_read = 1;
}

variable_types: sig int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("\nUsage: %s <options> [adc-list]\n", a1);
puts(" -d<delay-ms> Delay between reads, default 50, min 1");
puts(" adc-list Space separated list of ADCs to monitor, 2-7");
printf("\nExample:\n\t%s -d100 2 3 5\n", a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
printf("\nUsage: %s <options> [adc-list]\n", a1);
puts(" -d<delay-ms> Delay between reads, default 50, min 1");
puts(" adc-list Space separated list of ADCs to monitor, 2-7");
printf("\nExample:\n\t%s -d100 2 3 5\n", a1);
exit(0);
}

original_code:
void usage(char *argv_0)
{
    printf("\nUsage: %s <options> [adc-list]\n", argv_0);
    printf("  -d<delay-ms>       Delay between reads, default 50, min 1\n");
    printf("  adc-list           Space separated list of ADCs to monitor, 2-7\n");
    printf("\nExample:\n\t%s -d100 2 3 5\n", argv_0);
    exit(0);
}


decompiled_code:
int __fastcall show_elapsed(__int64 a1, _QWORD *a2, int a3)
{
__int64 v3; // rax
__int64 v4; // rcx
double v5; // xmm1_8
double v6; // xmm0_8
double v7; // xmm1_8

v3 = a2[1];
v4 = *(_QWORD *)(a1 + 8);
if ( v3 <= v4 )
{
v5 = (double)((int)v3 + 1000000 - (int)v4);
--*a2;
}
else
{
v5 = (double)((int)v3 - (int)v4);
}
v6 = (double)(*(_DWORD *)a2 - *(_DWORD *)a1) + v5 / 1000000.0;
v7 = 0.0;
if ( v6 > 0.0 )
v7 = (double)a3 / v6;
return printf("Summary\n Elapsed: %0.2lf seconds\n Reads: %d\n Rate: %0.2lf Hz\n\n", v6, (unsigned int)a3, v7);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, _QWORD *a2, int a3)
{
__int64 v3; // rax
__int64 v4; // rcx
double v5; // xmm1_8
double v6; // xmm0_8
double v7; // xmm1_8

v3 = a2[1];
v4 = *(_QWORD *)(a1 + 8);
if ( v3 <= v4 )
{
v5 = (double)((int)v3 + 1000000 - (int)v4);
--*a2;
}
else
{
v5 = (double)((int)v3 - (int)v4);
}
v6 = (double)(*(_DWORD *)a2 - *(_DWORD *)a1) + v5 / 1000000.0;
v7 = 0.0;
if ( v6 > 0.0 )
v7 = (double)a3 / v6;
return printf("Summary\n Elapsed: %0.2lf seconds\n Reads: %d\n Rate: %0.2lf Hz\n\n", v6, (unsigned int)a3, v7);
}

original_code:
void show_elapsed(struct timeval *start, struct timeval *end, int count)
{
    double diff;
    double rate;
    if (end->tv_usec > start->tv_usec) {
        diff = (double) (end->tv_usec - start->tv_usec);
    }
    else {
        diff = (double) ((1000000 + end->tv_usec) - start->tv_usec);
        end->tv_sec--;
    }
    diff /= 1000000.0;
    diff += (double)(end->tv_sec - start->tv_sec);
    if (diff > 0.0)
        rate = count / diff;
    else
        rate = 0.0;
    printf("Summary\n  Elapsed: %0.2lf seconds\n    Reads: %d\n     Rate: %0.2lf Hz\n\n",
        diff, count, rate);
}

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

variable_types:
end
struct timeval *

variable_types: count int

variable_types: diff double

variable_types: rate double


decompiled_code:
int __fastcall read_adc(int a1)
{
__int64 buf[2]; // [rsp+8h] [rbp-10h] BYREF

buf[0] = 0LL;
if ( read(a1, buf, 8uLL) >= 0 )
return atoi((const char *)buf);
perror("read()");
return -100000;
}

canonical_decompiled_code:
int __fastcall func10(int a1)
{
__int64 buf[2]; // [rsp+8h] [rbp-10h] BYREF

buf[0] = 0LL;
if ( read(a1, buf, 8uLL) >= 0 )
return atoi((const char *)buf);
perror("read()");
return -100000;
}

original_code:
int read_adc(int fd)
{
    char buff[8];
    int val = -100000;
    memset(buff, 0, sizeof(buff));
    if (read(fd, buff, 8) < 0)
        perror("read()");
    else
        val = atoi(buff);
    return val;
}

variable_types: fd int

variable_types:
buff
char [8]

variable_types: val int


decompiled_code:
__int64 __fastcall open_adc(unsigned int a1)
{
int v1; // ebx
char v3[136]; // [rsp+0h] [rbp-88h] BYREF

sprintf(v3, "%sin%d_input", hwmonsyspath, a1);
v1 = open(v3, 0);
if ( v1 < 0 )
{
perror("open()");
puts(v3);
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
int v1; // ebx
char v3[136]; // [rsp+0h] [rbp-88h] BYREF

sprintf(v3, "%sin%d_input", hwmonsyspath, a1);
v1 = open(v3, 0);
if ( v1 < 0 )
{
perror("open()");
puts(v3);
}
return (unsigned int)v1;
}

original_code:
int open_adc(int adc)
{
    char path[128];
    sprintf(path, "%sin%d_input", hwmonsyspath, adc);
    int fd = open(path, 00);
    if (fd < 0) {
        perror("open()");
        printf("%s\n", path);
    }
    return fd;
}

variable_types: adc int

variable_types:
path
char [128]


decompiled_code:
int register_sig_handler()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_handler = (__sighandler_t)sigint_handler;
result = sigaction(2, &v1, 0LL);
if ( result < 0 )
{
perror("sigaction(SIGINT)");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func12()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_handler = (__sighandler_t)sigint_handler;
result = sigaction(2, &v1, 0LL);
if ( result < 0 )
{
perror("sigaction(SIGINT)");
exit(1);
}
return result;
}

original_code:
void register_sig_handler()
{
    struct sigaction sia;
    bzero(&sia, sizeof sia);
    sia.__sigaction_handler.sa_handler = sigint_handler;
    if (sigaction(2, &sia, ((void *)0)) < 0) {
        perror("sigaction(SIGINT)");
        exit(1);
    }
}

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

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

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


msleep

decompiled_code:
int __fastcall msleep(int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 1000;
v2.tv_nsec = 1000000 * (a1 % 1000);
return nanosleep(&v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 1000;
v2.tv_nsec = 1000000 * (a1 % 1000);
return nanosleep(&v2, 0LL);
}

original_code:
void msleep(int ms)
{
    struct timespec ts;
    ts.tv_sec = ms / 1000;
    ts.tv_nsec = (ms % 1000) * 1000000;
    nanosleep(&ts, ((void *)0));
}

variable_types: ms int

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }