main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // cf
bool v4; // zf
const char *v5; // r12
const char *v6; // rdi
__int64 v7; // rcx
const char *v8; // rsi
int v9; // ebx
int v10; // eax
char v11; // r13
int v12; // eax
bool v13; // r14
int v14; // ebx
int v15; // er12
int v17; // eax

openlog("angeld", 3, 8);
v3 = argc == 0;
v4 = argc == 1;
if ( argc <= 1 )
{
LABEL_8:
puts("usage: angeld (start|restart|stop)");
exit(0);
}
v5 = argv[1];
v6 = "start";
v7 = 6LL;
v8 = v5;
do
{
if ( !v7 )
break;
v3 = *v8 < (unsigned int)*v6;
v4 = *v8++ == *v6++;
--v7;
}
while ( v4 );
v9 = (char)((!v3 && !v4) - v3);
if ( (!v3 && !v4) == v3 )
{
v12 = is_alive(v6, v8);
v13 = v12 == 0;
LABEL_14:
v14 = v12 & v9;
if ( !v14 && v12 )
{
syslog(6, "angeld already alive");
LOBYTE(v9) = 1;
LABEL_24:
v15 = (unsigned __int8)v9 & v13;
v14 = 0;
goto LABEL_19;
}
v11 = 1;
goto LABEL_17;
}
if ( !strcmp(v5, "restart") )
{
v12 = is_alive(v5, "restart");
v9 = 1;
v13 = v12 == 0;
if ( !v12 )
{
LABEL_23:
syslog(6, "nothing to kill");
goto LABEL_24;
}
goto LABEL_14;
}
v10 = strcmp(v5, "stop");
v11 = v10;
if ( v10 )
goto LABEL_8;
v17 = is_alive(v5, "stop");
LOBYTE(v9) = v17;
v13 = v17 == 0;
if ( !v17 )
goto LABEL_23;
v14 = v17 & 1;
LABEL_17:
v15 = (unsigned __int8)v11 & (v13 || v14 != 0);
if ( v14 )
kill_daemon();
LABEL_19:
if ( v15 )
{
make_daemon();
init_com();
monitor();
}
closelog();
return v14 == 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // cf
bool v4; // zf
const char *v5; // r12
const char *v6; // rdi
__int64 v7; // rcx
const char *v8; // rsi
int v9; // ebx
int v10; // eax
char v11; // r13
int v12; // eax
bool v13; // r14
int v14; // ebx
int v15; // er12
int v17; // eax

openlog("angeld", 3, 8);
v3 = argc == 0;
v4 = argc == 1;
if ( argc <= 1 )
{
LABEL_8:
puts("usage: angeld (start|restart|stop)");
exit(0);
}
v5 = argv[1];
v6 = "start";
v7 = 6LL;
v8 = v5;
do
{
if ( !v7 )
break;
v3 = *v8 < (unsigned int)*v6;
v4 = *v8++ == *v6++;
--v7;
}
while ( v4 );
v9 = (char)((!v3 && !v4) - v3);
if ( (!v3 && !v4) == v3 )
{
v12 = func1(v6, v8);
v13 = v12 == 0;
LABEL_14:
v14 = v12 & v9;
if ( !v14 && v12 )
{
syslog(6, "angeld already alive");
LOBYTE(v9) = 1;
LABEL_24:
v15 = (unsigned __int8)v9 & v13;
v14 = 0;
goto LABEL_19;
}
v11 = 1;
goto LABEL_17;
}
if ( !strcmp(v5, "restart") )
{
v12 = func1(v5, "restart");
v9 = 1;
v13 = v12 == 0;
if ( !v12 )
{
LABEL_23:
syslog(6, "nothing to kill");
goto LABEL_24;
}
goto LABEL_14;
}
v10 = strcmp(v5, "stop");
v11 = v10;
if ( v10 )
goto LABEL_8;
v17 = func1(v5, "stop");
LOBYTE(v9) = v17;
v13 = v17 == 0;
if ( !v17 )
goto LABEL_23;
v14 = v17 & 1;
LABEL_17:
v15 = (unsigned __int8)v11 & (v13 || v14 != 0);
if ( v14 )
func4();
LABEL_19:
if ( v15 )
{
func5();
func6();
func13();
}
closelog();
return v14 == 0;
}

original_code:
int main(int argc, char **argv) {
 int alive, kill, live;
 openlog("angeld",0x01 | 0x02,(1<<3));
 kill = 0;
 live = 0;
 if(argc <= 1) goto help;
 if(strcmp(argv[1],"start") == 0) live = 1;
 else if(strcmp(argv[1],"restart") == 0) kill = live = 1;
 else if(strcmp(argv[1],"stop") == 0) kill = 1;
 else {
help:
  puts("usage: angeld (start|restart|stop)");
  exit(0);
 }
 if(kill || live) {
  alive = is_alive();
  if(kill && !alive) syslog(6,"nothing to kill");
  kill &= alive;
  if(!kill && live && alive)
   syslog(6,"angeld already alive");
  live &= kill || !alive;
 }
 if(kill) kill_daemon();
 if(live) {
  make_daemon();
  init_com();
  monitor();
 }
 closelog();
 return !(kill || live);
}

canonical_original_code:
int main(int argc, char **argv) {
 int alive; int kill; int live;
 openlog("angeld",0x01 | 0x02,(1<<3));
 kill = 0;
 live = 0;
 if(argc <= 1) goto help;
 if(strcmp(argv[1],"start") == 0) live = 1;
 else if(strcmp(argv[1],"restart") == 0) kill = live = 1;
 else if(strcmp(argv[1],"stop") == 0) kill = 1;
 else {
help:
  puts("usage: angeld (start|restart|stop)");
  exit(0);
 }
 if(kill || live) {
  alive = is_alive();
  if(kill && !alive) syslog(6,"nothing to kill");
  kill &= alive;
  if(!kill && live && alive)
   syslog(6,"angeld already alive");
  live &= kill || !alive;
 }
 if(kill) kill_daemon();
 if(live) {
  make_daemon();
  init_com();
  monitor();
 }
 closelog();
 return !(kill || live);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: alive int

variable_types: kill int

variable_types: live int


repo: kevinriehm/evt-black-box

canonical_decompiled_code:
void func0()
{
waitingforstart = 1;
}

original_code:
static void start_race() {
 waitingforstart = 1;
}

return_type: void


decompiled_code:
void __noreturn good_exit()
{
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
exit(0);
}

original_code:
static void good_exit() {
 exit(0);
}

canonical_original_code:
static void good_exit() {
 exit(0);
}


cmd

decompiled_code:
ssize_t cmd(char *format, ...)
{
size_t v1; // rax
int v2; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-D8h] BYREF

va_start(arg, format);
vsprintf(&buf_0, format, arg);
v1 = strlen(&buf_0);
v2 = write(auxfd, &buf_0, v1);
if ( v2 < strlen(&buf_0) )
die("cannot write to serial port");
buf_0 = 13;
byte_881 = 10;
return write(auxfd, &buf_0, 2uLL);
}

canonical_decompiled_code:
ssize_t func2(char *format, ...)
{
size_t v1; // rax
int v2; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-D8h] BYREF

va_start(arg, format);
vsprintf(&buf_0, format, arg);
v1 = strlen(&buf_0);
v2 = write(auxfd, &buf_0, v1);
if ( v2 < strlen(&buf_0) )
die("cannot write to serial port");
buf_0 = 13;
byte_881 = 10;
return write(auxfd, &buf_0, 2uLL);
}

original_code:
static void cmd(char *cmd, ...) {
 static char buf[1000];
 int nread;
 va_list ap;
 __builtin_va_start(ap,cmd);
 vsprintf(buf,cmd,ap);
 nread = write(auxfd,buf,strlen(buf));
 if(nread < strlen(buf)) die("cannot write to serial port");
 __builtin_va_end(ap);
 buf[0] = '\r';
 buf[1] = '\n';
 write(auxfd,buf,2);
}

canonical_original_code:
static void cmd(char *cmd, ...) {
 static char buf[1000];
 int nread;
 __builtin_va_list ap;
 __builtin_va_start(ap,cmd);
 vsprintf(buf,cmd,ap);
 nread = write(auxfd,buf,strlen(buf));
 if(nread < strlen(buf)) die("cannot write to serial port");
 __builtin_va_end(ap);
 buf[0] = '\r';
 buf[1] = '\n';
 write(auxfd,buf,2);
}

variable_types:
cmd
char *

variable_types:
buf
char [1000]

variable_types: nread int


decompiled_code:
ssize_t horn_off()
{
return cmd("h0");
}

canonical_decompiled_code:
ssize_t func3()
{
return func2("h0");
}

original_code:
static void horn_off() {
 cmd("h0");
}

canonical_original_code:
static void horn_off() {
 cmd("h0");
}


decompiled_code:
ssize_t horn_on()
{
return cmd("h1");
}

canonical_decompiled_code:
ssize_t func4()
{
return func2("h1");
}

original_code:
static void horn_on() {
 cmd("h1");
}

canonical_original_code:
static void horn_on() {
 cmd("h1");
}


decompiled_code:
ssize_t wiper_off()
{
return cmd("w0");
}

canonical_decompiled_code:
ssize_t func5()
{
return func2("w0");
}

original_code:
static void wiper_off() {
 cmd("w0");
}

canonical_original_code:
static void wiper_off() {
 cmd("w0");
}


decompiled_code:
ssize_t wiper_on()
{
return cmd("w255");
}

canonical_decompiled_code:
ssize_t func6()
{
return func2("w255");
}

original_code:
static void wiper_on() {
 cmd("w255");
}

canonical_original_code:
static void wiper_on() {
 cmd("w255");
}


decompiled_code:
ssize_t __fastcall set_light(int a1, unsigned int a2, float a3)
{
const char *v3; // r12

v3 = lights[a1];
cmd("l%sp%i", v3, (unsigned int)(int)(float)(a3 * 255.0));
return cmd("l%sb%i", v3, a2);
}

canonical_decompiled_code:
ssize_t __fastcall func7(int a1, unsigned int a2, float a3)
{
const char *v3; // r12

v3 = lights[a1];
func2("l%sp%i", v3, (unsigned int)(int)(float)(a3 * 255.0));
return func2("l%sb%i", v3, a2);
}

original_code:
static void set_light(enum lights light, float power, int blinking) {
 cmd("l%sp%i",lights[light],(int) (0xFF*power));
 cmd("l%sb%i",lights[light],blinking);
}

variable_types: enum lights { EL_WIRE=0, HEADLIGHTS=1, FRONT_LEFT=2, FRONT_RIGHT=3, BACK_LEFT=4, BACK_RIGHT=5 }

variable_types: power float

variable_types: blinking int


decompiled_code:
ssize_t head_low()
{
return set_light(1, 0, 0.0078431377);
}

original_code:
static void head_low() {
 set_light(HEADLIGHTS,(2.0/0xFF),0);
}


decompiled_code:
ssize_t head_high()
{
return set_light(1, 0, 1.0);
}

canonical_decompiled_code:
ssize_t func9()
{
return func7(1, 0, 1.0);
}

original_code:
static void head_high() {
 set_light(HEADLIGHTS,1,0);
}


decompiled_code:
ssize_t turn_right_stop()
{
set_light(3, 0, 0.0);
return set_light(5, 0, 0.0078431377);
}

original_code:
static void turn_right_stop() {
 set_light(FRONT_RIGHT,0,0);
 set_light(BACK_RIGHT,(2.0/0xFF),0);
}


decompiled_code:
ssize_t turn_right()
{
set_light(3, 1u, 1.0);
return set_light(5, 1u, 1.0);
}

original_code:
static void turn_right() {
 set_light(FRONT_RIGHT,1,1);
 set_light(BACK_RIGHT,1,1);
}


decompiled_code:
ssize_t turn_left_stop()
{
set_light(2, 0, 0.0);
return set_light(4, 0, 0.0078431377);
}

original_code:
static void turn_left_stop() {
 set_light(FRONT_LEFT,0,0);
 set_light(BACK_LEFT,(2.0/0xFF),0);
}


decompiled_code:
ssize_t turn_left()
{
set_light(2, 1u, 1.0);
return set_light(4, 1u, 1.0);
}

original_code:
static void turn_left() {
 set_light(FRONT_LEFT,1,1);
 set_light(BACK_LEFT,1,1);
}


decompiled_code:
void car_init()
{
logfp = fopen("angel.log", "a");
gui_bind("turn_left", turn_left);
gui_bind("turn_left_stop", turn_left_stop);
gui_bind("turn_right", turn_right);
gui_bind("turn_right_stop", turn_right_stop);
gui_bind("highbeams_on", head_high);
gui_bind("highbeams_off", head_low);
gui_bind("wiper_on", wiper_on);
gui_bind("wiper_off", wiper_off);
gui_bind("horn_on", horn_on);
gui_bind("horn_off", horn_off);
gui_bind("start_race", start_race);
gui_bind("exit", good_exit);
backdropobj = gui_find_obj("backdrop", 0LL);
gui_find_obj("map", 0LL);
needleobj = gui_find_obj("needle", 0LL);
timerobj = gui_find_obj("timer", 0LL);
speedobj = gui_find_obj("speed", 0LL);
set_light(0, 0, 1.0);
set_light(1, 0, 0.0078431377);
set_light(4, 0, 0.0078431377);
set_light(5, 0, 0.0078431377);
gui_set_value(needleobj, 0LL);
start_race();
}

canonical_decompiled_code:
void func14()
{
logfp = fopen("angel.log", "a");
gui_bind("turn_left", turn_left);
gui_bind("turn_left_stop", turn_left_stop);
gui_bind("turn_right", turn_right);
gui_bind("turn_right_stop", turn_right_stop);
gui_bind("highbeams_on", head_high);
gui_bind("highbeams_off", head_low);
gui_bind("wiper_on", wiper_on);
gui_bind("wiper_off", wiper_off);
gui_bind("horn_on", horn_on);
gui_bind("horn_off", horn_off);
gui_bind("start_race", start_race);
gui_bind("exit", good_exit);
backdropobj = gui_find_obj("backdrop", 0LL);
gui_find_obj("map", 0LL);
needleobj = gui_find_obj("needle", 0LL);
timerobj = gui_find_obj("timer", 0LL);
speedobj = gui_find_obj("speed", 0LL);
func7(0, 0, 1.0);
func7(1, 0, 0.0078431377);
func7(4, 0, 0.0078431377);
func7(5, 0, 0.0078431377);
gui_set_value(needleobj, 0LL);
func0();
}

original_code:
void car_init() {
 logfp = fopen("angel.log","a");
 gui_bind("turn_left",turn_left);
 gui_bind("turn_left_stop",turn_left_stop);
 gui_bind("turn_right",turn_right);
 gui_bind("turn_right_stop",turn_right_stop);
 gui_bind("highbeams_on",head_high);
 gui_bind("highbeams_off",head_low);
 gui_bind("wiper_on",wiper_on);
 gui_bind("wiper_off",wiper_off);
 gui_bind("horn_on",horn_on);
 gui_bind("horn_off",horn_off);
 gui_bind("start_race",start_race);
 gui_bind("exit",good_exit);
 backdropobj = gui_find_obj("backdrop",((void *)0));
 mapobj = gui_find_obj("map",((void *)0));
 needleobj = gui_find_obj("needle",((void *)0));
 timerobj = gui_find_obj("timer",((void *)0));
 speedobj = gui_find_obj("speed",((void *)0));
 set_light(EL_WIRE,1,0);
 set_light(HEADLIGHTS,(2.0/0xFF),0);
 set_light(BACK_LEFT,(2.0/0xFF),0);
 set_light(BACK_RIGHT,(2.0/0xFF),0);
 gui_set_value(needleobj,0.0);
 start_race();
}


decompiled_code:
int car_stop()
{
return fclose(logfp);
}

canonical_decompiled_code:
int func15()
{
return fclose(logfp);
}

original_code:
void car_stop() {
 fclose(logfp);
}

canonical_original_code:
void car_stop() {
 fclose(logfp);
}


decompiled_code:
void __fastcall car_handle_data_block(char *s)
{
char *v1; // rbx
_BOOL4 v2; // er12
char v3; // al
double v4; // r14
time_t v5; // r12
time_t v6; // rax

v1 = s;
v2 = 0;
if ( s )
{
while ( 1 )
{
v3 = *v1;
if ( !*v1 )
break;
if ( v2 )
{
switch ( v3 )
{
case 'a':
_isoc99_sscanf(v1, "a:%f;", &amperage);
break;
case 'g':
_isoc99_sscanf(v1, "g:%f,%f;", &latitude, &longitude);
break;
case 's':
_isoc99_sscanf(v1, "s:%f;", &mph);
break;
case 't':
_isoc99_sscanf(v1, "t:%li;", &gpstime);
break;
case 'v':
_isoc99_sscanf(v1, "v:%f;", &voltage);
break;
case '}':
if ( waitingforstart )
{
v4 = LC30;
if ( *(float *)&mph > 0.1 )
{
racestart = time(0LL);
waitingforstart = 0;
v4 = LC30;
}
}
else
{
v5 = racestart;
v6 = time(0LL);
v4 = difftime(v6, v5);
}
gui_set_value(backdropobj, 0LL);
gui_set_value(needleobj, 1LL);
fmod(v4, 60.0);
fmod(v4, 3600.0);
gui_set_value(timerobj, 3LL);
gui_set_value(speedobj, 1LL);
v2 = 0;
if ( logfp )
fprintf(
logfp,
"%li,%f,%f,%f,%f,%f,%f",
gpstime,
*(float *)&amperage,
*(float *)&voltage,
*(float *)&latitude,
*(float *)&longitude,
v4,
*(float *)&mph);
break;
default:
break;
}
v1 = strchr(v1, 59);
if ( !v1 )
return;
}
else
{
v2 = v3 == 123;
}
++v1;
}
}
}

canonical_decompiled_code:
void __fastcall func16(char *s)
{
char *v1; // rbx
_BOOL4 v2; // er12
char v3; // al
double v4; // r14
time_t v5; // r12
time_t v6; // rax

v1 = s;
v2 = 0;
if ( s )
{
while ( 1 )
{
v3 = *v1;
if ( !*v1 )
break;
if ( v2 )
{
switch ( v3 )
{
case 'a':
_isoc99_sscanf(v1, "a:%f;", &amperage);
break;
case 'g':
_isoc99_sscanf(v1, "g:%f,%f;", &latitude, &longitude);
break;
case 's':
_isoc99_sscanf(v1, "s:%f;", &mph);
break;
case 't':
_isoc99_sscanf(v1, "t:%li;", &gpstime);
break;
case 'v':
_isoc99_sscanf(v1, "v:%f;", &voltage);
break;
case '}':
if ( waitingforstart )
{
v4 = LC30;
if ( *(float *)&mph > 0.1 )
{
racestart = time(0LL);
waitingforstart = 0;
v4 = LC30;
}
}
else
{
v5 = racestart;
v6 = time(0LL);
v4 = difftime(v6, v5);
}
gui_set_value(backdropobj, 0LL);
gui_set_value(needleobj, 1LL);
fmod(v4, 60.0);
fmod(v4, 3600.0);
gui_set_value(timerobj, 3LL);
gui_set_value(speedobj, 1LL);
v2 = 0;
if ( logfp )
fprintf(
logfp,
"%li,%f,%f,%f,%f,%f,%f",
gpstime,
*(float *)&amperage,
*(float *)&voltage,
*(float *)&latitude,
*(float *)&longitude,
v4,
*(float *)&mph);
break;
default:
break;
}
v1 = strchr(v1, 59);
if ( !v1 )
return;
}
else
{
v2 = v3 == 123;
}
++v1;
}
}
}

original_code:
void car_handle_data_block(char *str) {
 double timersecs;
 enum { START, FIELD } state;
 for(state = START; str && *str; str++) {
  switch(state) {
  case START:
   if(*str == '{') state = FIELD;
   break;
  case FIELD:
   switch(*str) {
   case 'a': sscanf(str,"a:%f;",&amperage); break;
   case 'g': sscanf(str,"g:%f,%f;",&latitude,&longitude);
    break;
   case 's': sscanf(str,"s:%f;",&mph); break;
   case 't': sscanf(str,"t:%""l" "i"";",&gpstime); break;
   case 'v': sscanf(str,"v:%f;",&voltage); break;
   case '}':
    if(waitingforstart) {
     if(mph > 0.1) {
      racestart = time(((void *)0));
      waitingforstart = 0;
     }
     timersecs = 0;
    } else timersecs = difftime(time(((void *)0)),racestart);
    gui_set_value(backdropobj,0);
    gui_set_value(needleobj,1,mph);
    gui_set_value(timerobj,3,
     floor(timersecs / 3600),
     floor(fmod(timersecs,3600)/60),
     floor(fmod(timersecs,60)));
    gui_set_value(speedobj,1,mph);
    if(logfp)
     fprintf(logfp,"%""l" "i"",%f,%f,%f,%f,"
      "%f,%f",gpstime,amperage,
      voltage,latitude,longitude,
      timersecs,mph);
    state = START;
    break;
   default: break;
   }
   if(!(str = strchr(str,';')))
    return;
   break;
  }
 }
}

canonical_original_code:
void car_handle_data_block(char *str) {
 double timersecs;
 enum { START=0, FIELD=1 } state;
 for(state = START; str && *str; str++) {
  switch(state) {
  case START:
   if(*str == '{') state = FIELD;
   break;
  case FIELD:
   switch(*str) {
   case 'a': sscanf(str,"a:%f;",&amperage); break;
   case 'g': sscanf(str,"g:%f,%f;",&latitude,&longitude);
    break;
   case 's': sscanf(str,"s:%f;",&mph); break;
   case 't': sscanf(str,"t:%""l" "i"";",&gpstime); break;
   case 'v': sscanf(str,"v:%f;",&voltage); break;
   case '}':
    if(waitingforstart) {
     if(mph > 0.1) {
      racestart = time(((void *)0));
      waitingforstart = 0;
     }
     timersecs = 0;
    } else timersecs = difftime(time(((void *)0)),racestart);
    gui_set_value(backdropobj,0);
    gui_set_value(needleobj,1,mph);
    gui_set_value(timerobj,3,
     floor(timersecs / 3600),
     floor(fmod(timersecs,3600)/60),
     floor(fmod(timersecs,60)));
    gui_set_value(speedobj,1,mph);
    if(logfp)
     fprintf(logfp,"%""l" "i"",%f,%f,%f,%f,"
      "%f,%f",gpstime,amperage,
      voltage,latitude,longitude,
      timersecs,mph);
    state = START;
    break;
   default: break;
   }
   if(!(str = strchr(str,';')))
    return;
   break;
  }
 }
}

variable_types:
str
char *

variable_types: timersecs double

variable_types:
state
enum { START=0, FIELD=1 }


decompiled_code:
void event_redraw()
{
wantdraw = 1;
}

canonical_decompiled_code:
void func0()
{
wantdraw = 1;
}

original_code:
void event_redraw() {
 wantdraw = 1;
}

canonical_original_code:
void event_redraw() {
 wantdraw = 1;
}


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

if ( a1 < 0.0 || maxwait >= 0 && (float)maxwait <= a1 )
result = (unsigned int)(int)(float)maxwait;
else
result = (unsigned int)(int)(float)(a1 * 1000.0);
maxwait = result;
return result;
}

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

if ( a1 < 0.0 || maxwait >= 0 && (float)maxwait <= a1 )
result = (unsigned int)(int)(float)maxwait;
else
result = (unsigned int)(int)(float)(a1 * 1000.0);
maxwait = result;
return result;
}

original_code:
void event_set_max_wait(float seconds) {
 maxwait = seconds >= 0 && (maxwait < 0 || seconds < maxwait)
  ? seconds*1000 : maxwait;
}

variable_types: seconds float


decompiled_code:
void event_refresh()
{
wantrefresh = 1;
}

canonical_decompiled_code:
void func3()
{
wantrefresh = 1;
}


decompiled_code:
const char *egl_error_string()
{
const char *result; // rax

switch ( (unsigned int)eglGetError() )
{
case 0x3000u:
result = "EGL_SUCCESS";
break;
case 0x3001u:
result = "EGL_NOT_INITIALIZED";
break;
case 0x3002u:
result = "EGL_BAD_ACCESS";
break;
case 0x3003u:
result = "EGL_BAD_ALLOC";
break;
case 0x3004u:
result = "EGL_BAD_ATTRIBUTE";
break;
case 0x3005u:
result = "EGL_BAD_CONFIG";
break;
case 0x3006u:
result = "EGL_BAD_CONTEXT";
break;
case 0x3007u:
result = "EGL_BAD_CURRENT_DISPLAY";
break;
case 0x3008u:
result = "EGL_BAD_DISPLAY";
break;
case 0x3009u:
result = "EGL_BAD_MATCH";
break;
case 0x300Au:
result = "EGL_BAD_NATIVE_PIXMAP";
break;
case 0x300Bu:
result = "EGL_BAD_NATIVE_WINDOW";
break;
case 0x300Cu:
result = "EGL_BAD_PARAMETER";
break;
case 0x300Du:
result = "EGL_BAD_SURFACE";
break;
case 0x300Eu:
result = "EGL_CONTEXT_LOST";
break;
default:
result = (const char *)&unk_470;
break;
}
return result;
}

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

switch ( (unsigned int)eglGetError() )
{
case 0x3000u:
result = "EGL_SUCCESS";
break;
case 0x3001u:
result = "EGL_NOT_INITIALIZED";
break;
case 0x3002u:
result = "EGL_BAD_ACCESS";
break;
case 0x3003u:
result = "EGL_BAD_ALLOC";
break;
case 0x3004u:
result = "EGL_BAD_ATTRIBUTE";
break;
case 0x3005u:
result = "EGL_BAD_CONFIG";
break;
case 0x3006u:
result = "EGL_BAD_CONTEXT";
break;
case 0x3007u:
result = "EGL_BAD_CURRENT_DISPLAY";
break;
case 0x3008u:
result = "EGL_BAD_DISPLAY";
break;
case 0x3009u:
result = "EGL_BAD_MATCH";
break;
case 0x300Au:
result = "EGL_BAD_NATIVE_PIXMAP";
break;
case 0x300Bu:
result = "EGL_BAD_NATIVE_WINDOW";
break;
case 0x300Cu:
result = "EGL_BAD_PARAMETER";
break;
case 0x300Du:
result = "EGL_BAD_SURFACE";
break;
case 0x300Eu:
result = "EGL_CONTEXT_LOST";
break;
default:
result = (const char *)&unk_470;
break;
}
return result;
}

original_code:
const char *egl_error_string() {
 switch(eglGetError()) {
 case 0x3000: return "EGL_SUCCESS";
 case 0x3001: return "EGL_NOT_INITIALIZED";
 case 0x3002: return "EGL_BAD_ACCESS";
 case 0x3003: return "EGL_BAD_ALLOC";
 case 0x3004: return "EGL_BAD_ATTRIBUTE";
 case 0x3006: return "EGL_BAD_CONTEXT";
 case 0x3005: return "EGL_BAD_CONFIG";
 case 0x3007: return "EGL_BAD_CURRENT_DISPLAY";
 case 0x3008: return "EGL_BAD_DISPLAY";
 case 0x300D: return "EGL_BAD_SURFACE";
 case 0x3009: return "EGL_BAD_MATCH";
 case 0x300C: return "EGL_BAD_PARAMETER";
 case 0x300A: return "EGL_BAD_NATIVE_PIXMAP";
 case 0x300B: return "EGL_BAD_NATIVE_WINDOW";
 case 0x300E: return "EGL_CONTEXT_LOST";
 default: return "";
 }
}

return_type: char *


decompiled_code:
__int64 display_update()
{
return eglSwapBuffers(edisplay, surface);
}

canonical_decompiled_code:
__int64 func1()
{
return eglSwapBuffers(edisplay, surface);
}

original_code:
void display_update() {
 eglSwapBuffers(edisplay,surface);
}


decompiled_code:
int display_stop()
{
eglMakeCurrent(edisplay, 0LL, 0LL, 0LL);
eglDestroyContext(edisplay, context);
eglDestroySurface(edisplay, surface);
eglTerminate(edisplay);
XDestroyWindow(xdisplay, window);
return XCloseDisplay(xdisplay);
}

canonical_decompiled_code:
int func3()
{
eglMakeCurrent(edisplay, 0LL, 0LL, 0LL);
eglDestroyContext(edisplay, context);
eglDestroySurface(edisplay, surface);
eglTerminate(edisplay);
XDestroyWindow(xdisplay, window);
return XCloseDisplay(xdisplay);
}

original_code:
void display_stop() {
 eglMakeCurrent(edisplay,0,0,((EGLContext) (0)));
 eglDestroyContext(edisplay,context);
 eglDestroySurface(edisplay,surface);
 eglTerminate(edisplay);
 XDestroyWindow(xdisplay,window);
 XCloseDisplay(xdisplay);
}


ror

decompiled_code:
__int64 __fastcall ror(int a1, char a2)
{
return (unsigned int)__ROR4__(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, char a2)
{
return (unsigned int)__ROR4__(a1, a2);
}

original_code: static inline uint32_t ror(uint32_t a, int b) { return a >> b | a << (32 - b); }

canonical_original_code: static inline unsigned int ror(unsigned int a, int b) { return a >> b | a << (32 - b); }

variable_types:
a
unsigned int

variable_types: b int

return_type: unsigned int


decompiled_code:
int __fastcall sha256_str(char *s, unsigned __int8 *a2)
{
char *v3; // rbx
int result; // eax

v3 = s;
do
{
result = sprintf(v3, "%.2x", *a2++);
v3 += 2;
}
while ( v3 != s + 64 );
return result;
}

canonical_decompiled_code:
int __fastcall func3(char *s, unsigned __int8 *a2)
{
char *v3; // rbx
int result; // eax

v3 = s;
do
{
result = sprintf(v3, "%.2x", *a2++);
v3 += 2;
}
while ( v3 != s + 64 );
return result;
}

original_code:
void sha256_str(char *str, uint8_t hash[32])
{
 int i;
 for(i = 0; i < 32; i++)
  sprintf(str + 2*i,"%.2x",hash[i]);
}

canonical_original_code:
void sha256_str(char *str, unsigned char hash[32])
{
 int i;
 for(i = 0; i < 32; i++)
  sprintf(str + 2*i,"%.2x",hash[i]);
}

variable_types:
hash
unsigned char [32]

variable_types: i int


decompiled_code:
int aux_init()
{
unsigned int i; // er12
clock_t v1; // rbx
int v2; // edx
struct termios termios_p; // [rsp+0h] [rbp-C0h] BYREF
char buf[108]; // [rsp+40h] [rbp-80h] BYREF
int v6[5]; // [rsp+ACh] [rbp-14h] BYREF

auxfd = open("/dev/ttyACM0", 2306);
if ( auxfd < 0 )
die("cannot open serial port '/dev/ttyACM0'");
*(_QWORD *)&termios_p.c_iflag = 0LL;
*(_QWORD *)&termios_p.c_cflag = 0LL;
*(_QWORD *)&termios_p.c_line = 0LL;
*(_QWORD *)&termios_p.c_cc[7] = 0LL;
*(_QWORD *)&termios_p.c_cc[15] = 0LL;
*(_QWORD *)&termios_p.c_cc[23] = 0LL;
*(_QWORD *)&termios_p.c_cc[31] = 0LL;
termios_p.c_ospeed = 0;
cfsetospeed(&termios_p, 0x1002u);
cfsetispeed(&termios_p, 0x1002u);
*(_QWORD *)&termios_p.c_cflag |= 0x8000000030uLL;
termios_p.c_iflag |= 1u;
tcsetattr(auxfd, 0, &termios_p);
for ( i = 1; i != 11; ++i )
{
printf("connecting to auxiliary, attempt %i...\n", i);
write(auxfd, "?\r\n", 3uLL);
v1 = clock();
while ( clock() - v1 <= 999999 )
{
ioctl(auxfd, 0x541BuLL, v6);
v2 = 99;
if ( v6[0] <= 99 )
v2 = v6[0];
read(auxfd, buf, v2);
buf[99] = 0;
if ( strstr(buf, "OK") )
return puts("connected to auxiliary board");
}
}
die("cannot communciate with auxiliary board");
return puts("connected to auxiliary board");
}

canonical_decompiled_code:
int func0()
{
unsigned int i; // er12
clock_t v1; // rbx
int v2; // edx
struct termios termios_p; // [rsp+0h] [rbp-C0h] BYREF
char buf[108]; // [rsp+40h] [rbp-80h] BYREF
int v6[5]; // [rsp+ACh] [rbp-14h] BYREF

auxfd = open("/dev/ttyACM0", 2306);
if ( auxfd < 0 )
die("cannot open serial port '/dev/ttyACM0'");
*(_QWORD *)&termios_p.c_iflag = 0LL;
*(_QWORD *)&termios_p.c_cflag = 0LL;
*(_QWORD *)&termios_p.c_line = 0LL;
*(_QWORD *)&termios_p.c_cc[7] = 0LL;
*(_QWORD *)&termios_p.c_cc[15] = 0LL;
*(_QWORD *)&termios_p.c_cc[23] = 0LL;
*(_QWORD *)&termios_p.c_cc[31] = 0LL;
termios_p.c_ospeed = 0;
cfsetospeed(&termios_p, 0x1002u);
cfsetispeed(&termios_p, 0x1002u);
*(_QWORD *)&termios_p.c_cflag |= 0x8000000030uLL;
termios_p.c_iflag |= 1u;
tcsetattr(auxfd, 0, &termios_p);
for ( i = 1; i != 11; ++i )
{
printf("connecting to auxiliary, attempt %i...\n", i);
write(auxfd, "?\r\n", 3uLL);
v1 = clock();
while ( clock() - v1 <= 999999 )
{
ioctl(auxfd, 0x541BuLL, v6);
v2 = 99;
if ( v6[0] <= 99 )
v2 = v6[0];
read(auxfd, buf, v2);
buf[99] = 0;
if ( strstr(buf, "OK") )
return puts("connected to auxiliary board");
}
}
die("cannot communciate with auxiliary board");
return puts("connected to auxiliary board");
}

original_code:
void aux_init()
{
 int n;
 clock_t c;
 int retries;
 char buf[100];
 struct termios portios;
 auxfd = open("/dev/ttyACM0",02 | 0400 | 04000);
 if(auxfd < 0) die("cannot open serial port '" "/dev/ttyACM0" "'");
 memset(&portios,0,sizeof(portios));
 cfsetospeed(&portios,0010002);
 cfsetispeed(&portios,0010002);
 portios.c_cflag |= 0000060;
 portios.c_iflag |= 0000001;
 portios.c_lflag |= 0000200;
 tcsetattr(auxfd,0,&portios);
 retries = 10;
 while(retries--) {
  printf("connecting to auxiliary, attempt %i...\n",10 - retries);
  write(auxfd,"?\r\n",3);
  c = clock();
  while((clock() - c) < ((__clock_t) 1000000)) {
   ioctl(auxfd,0x541B,&n);
   read(auxfd,buf,n < 100 ? n : 100 - 1);
   buf[100 - 1] = '\0';
   if(strstr(buf,"OK")) goto connected;
  }
 };
 die("cannot communciate with auxiliary board");
connected:
 puts("connected to auxiliary board");
}

canonical_original_code:
void aux_init()
{
 int n;
 long c;
 int retries;
 char buf[100];
 struct termios portios;
 auxfd = open("/dev/ttyACM0",02 | 0400 | 04000);
 if(auxfd < 0) die("cannot open serial port '" "/dev/ttyACM0" "'");
 memset(&portios,0,sizeof(portios));
 cfsetospeed(&portios,0010002);
 cfsetispeed(&portios,0010002);
 portios.c_cflag |= 0000060;
 portios.c_iflag |= 0000001;
 portios.c_lflag |= 0000200;
 tcsetattr(auxfd,0,&portios);
 retries = 10;
 while(retries--) {
  printf("connecting to auxiliary, attempt %i...\n",10 - retries);
  write(auxfd,"?\r\n",3);
  c = clock();
  while((clock() - c) < ((long) 1000000)) {
   ioctl(auxfd,0x541B,&n);
   read(auxfd,buf,n < 100 ? n : 100 - 1);
   buf[100 - 1] = '\0';
   if(strstr(buf,"OK")) goto connected;
  }
 };
 die("cannot communciate with auxiliary board");
connected:
 puts("connected to auxiliary board");
}

variable_types: n int

variable_types: c long

variable_types: retries int

variable_types:
buf
char [100]

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


decompiled_code:
int aux_stop()
{
return close(auxfd);
}

canonical_decompiled_code:
int func1()
{
return close(auxfd);
}

original_code:
void aux_stop() {
 close(auxfd);
}

canonical_original_code:
void aux_stop() {
 close(auxfd);
}


repo: kevinwang/troll

decompiled_code:
__int64 __fastcall ftw_add(const char *filename, const struct stat *status, int flag)
{
if ( !flag )
write_blob(filename, status);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *filename, const struct stat *status, int flag)
{
if ( !flag )
write_blob(filename, status);
return 0LL;
}

original_code:
int ftw_add(const char *fpath, const struct stat *sb, int typeflag) {
    if (typeflag == FTW_F) {
        write_blob((char *) fpath);
    }
    return 0;
}

canonical_original_code:
int ftw_add(char *fpath, struct stat *sb, int typeflag) {
    if (typeflag == FTW_F) {
        write_blob((char *) fpath);
    }
    return 0;
}

variable_types:
fpath
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *

variable_types: typeflag int

return_type: int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall cmd_add(int a1, __int64 a2)
{
const char **v2; // rbx
unsigned int v3; // ebp
int *v4; // rax
char *v5; // rax
struct stat v7; // [rsp+0h] [rbp-B8h] BYREF

die_if_not_troll_repo();
if ( a1 == 1 )
{
puts("Nothing specified, nothing added.");
v3 = 0;
}
else if ( a1 <= 1 )
{
v3 = 0;
}
else
{
v2 = (const char **)(a2 + 8);
while ( 1 )
{
v3 = stat(*v2, &v7);
if ( v3 )
break;
if ( (v7.st_mode & 0xF000) == 0x4000 )
ftw(*v2, (__ftw_func_t)ftw_add, 256);
else
write_blob(*v2, &v7);
if ( ++v2 == (const char **)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) )
return v3;
}
v4 = _errno_location();
v5 = strerror(*v4);
printf("Ain't gon' work: %s\n", v5);
v3 = 128;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
const char **v2; // rbx
unsigned int v3; // ebp
int *v4; // rax
char *v5; // rax
struct stat v7; // [rsp+0h] [rbp-B8h] BYREF

die_if_not_troll_repo();
if ( a1 == 1 )
{
puts("Nothing specified, nothing added.");
v3 = 0;
}
else if ( a1 <= 1 )
{
v3 = 0;
}
else
{
v2 = (const char **)(a2 + 8);
while ( 1 )
{
v3 = stat(*v2, &v7);
if ( v3 )
break;
if ( (v7.st_mode & 0xF000) == 0x4000 )
ftw(*v2, (__ftw_func_t)ftw_add, 256);
else
write_blob(*v2, &v7);
if ( ++v2 == (const char **)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) )
return v3;
}
v4 = _errno_location();
v5 = strerror(*v4);
printf("Ain't gon' work: %s\n", v5);
v3 = 128;
}
return v3;
}

original_code:
int cmd_add(int argc, const char *argv[]) {
    die_if_not_troll_repo();
    if (argc == 1) {
        printf("Nothing specified, nothing added.\n");
        return 0;
    }
    int i;
    for (i = 1; i < argc; i++) {
        struct stat buf;
        if (stat(argv[i], &buf) != 0) {
            printf("Ain't gon' work: %s\n", strerror((*__errno_location ())));
            return 128;
        }
        if (((((buf.st_mode)) & 0170000) == (0040000))) {
            ftw(argv[i], ftw_add, 256);
        }
        else {
            write_blob((char *) argv[i]);
        }
    }
    return 0;
}

canonical_original_code:
int cmd_add(int argc, char *argv[]) {
    die_if_not_troll_repo();
    if (argc == 1) {
        printf("Nothing specified, nothing added.\n");
        return 0;
    }
    int i;
    for (i = 1; i < argc; i++) {
        struct stat buf;
        if (stat(argv[i], &buf) != 0) {
            printf("Ain't gon' work: %s\n", strerror((*__errno_location ())));
            return 128;
        }
        if (((((buf.st_mode)) & 0170000) == (0040000))) {
            ftw(argv[i], ftw_add, 256);
        }
        else {
            write_blob((char *) argv[i]);
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall file_hash(const char *a1)
{
int v1; // er12
__off_t v2; // rbp
char *v3; // rbx
__int64 v4; // rbx
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

v1 = open(a1, 0);
fstat(v1, &v6);
v2 = v6.st_size;
v3 = (char *)malloc(v6.st_size + 15);
sprintf(v3, "blob %lu", v2);
LODWORD(v2) = strlen(v3) + 1;
read(v1, &v3[(int)v2], v6.st_size);
v4 = hash_object(v3, (unsigned int)(LODWORD(v6.st_size) + v2));
close(v1);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
int v1; // er12
__off_t v2; // rbp
char *v3; // rbx
__int64 v4; // rbx
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

v1 = open(a1, 0);
fstat(v1, &v6);
v2 = v6.st_size;
v3 = (char *)malloc(v6.st_size + 15);
sprintf(v3, "blob %lu", v2);
LODWORD(v2) = strlen(v3) + 1;
read(v1, &v3[(int)v2], v6.st_size);
v4 = hash_object(v3, (unsigned int)(LODWORD(v6.st_size) + v2));
close(v1);
return v4;
}

original_code:
char *file_hash(char *filename) {
    int fd;
    fd = open(filename, 00);
    struct stat buf;
    fstat(fd, &buf);
    char *data = (char *) malloc((size_t) buf.st_size + 15);
    sprintf(data, "blob %lu", (unsigned long) buf.st_size);
    int left_part_len = strlen(data) + 1;
    read(fd, data + left_part_len, buf.st_size);
    int full_len = left_part_len + buf.st_size;
    char *hash = hash_object(data, full_len);
    close(fd);
    return hash;
}

variable_types:
filename
char *

variable_types: fd int

variable_types:
data
char *

variable_types:
hash
char *

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


decompiled_code:
__int64 cmd_status()
{
const char *v0; // rbx
size_t v1; // rax
char *v2; // r12
size_t v3; // rax
char *v4; // rbp
int v5; // er14
int v6; // er13
size_t v7; // rax
char *v8; // r15
size_t v9; // rax
const char *path; // [rsp+8h] [rbp-40h]

die_if_not_troll_repo();
path = getcwd(0LL, 0LL);
v0 = (const char *)get_repo_troll_dir();
v1 = strlen(v0);
v2 = (char *)malloc(v1 + 12);
strcat(v2, v0);
strcat(v2, "unstaged.tmp");
v3 = strlen(v0);
v4 = (char *)malloc(v3 + 13);
strcat(v4, v0);
strcat(v4, "untracked.tmp");
v5 = open(v2, 66, 420LL);
v6 = open(v4, 66, 420LL);
v7 = strlen(v0);
v8 = (char *)malloc(v7 - 7);
v9 = strlen(v0);
strncat(v8, v0, v9 - 7);
free(v2);
free(v4);
search_dirs(v5, v6, v8);
puts("Changes not staged for commit: ");
puts("Untracked files: ");
chdir(path);
close(v5);
close(v6);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
const char *v0; // rbx
size_t v1; // rax
char *v2; // r12
size_t v3; // rax
char *v4; // rbp
int v5; // er14
int v6; // er13
size_t v7; // rax
char *v8; // r15
size_t v9; // rax
const char *path; // [rsp+8h] [rbp-40h]

die_if_not_troll_repo();
path = getcwd(0LL, 0LL);
v0 = (const char *)get_repo_troll_dir();
v1 = strlen(v0);
v2 = (char *)malloc(v1 + 12);
strcat(v2, v0);
strcat(v2, "unstaged.tmp");
v3 = strlen(v0);
v4 = (char *)malloc(v3 + 13);
strcat(v4, v0);
strcat(v4, "untracked.tmp");
v5 = open(v2, 66, 420LL);
v6 = open(v4, 66, 420LL);
v7 = strlen(v0);
v8 = (char *)malloc(v7 - 7);
v9 = strlen(v0);
strncat(v8, v0, v9 - 7);
free(v2);
free(v4);
func1(v5, v6, v8);
puts("Changes not staged for commit: ");
puts("Untracked files: ");
chdir(path);
close(v5);
close(v6);
return 0LL;
}

original_code:
int cmd_status(int argc, const char *argv[]) {
    die_if_not_troll_repo();
    char *currdir = getcwd(((void *)0), 0);
    char *trollpath = get_repo_troll_dir();
    char *usta = (char *)malloc(strlen(trollpath) + 12);
    strcat(usta, trollpath);
    strcat(usta, "unstaged.tmp");
    char *utra = (char *)malloc(strlen(trollpath) + 13);
    strcat(utra, trollpath);
    strcat(utra, "untracked.tmp");
    int unstaged = open(usta,02 | 0100, 0644);
    int untracked = open(utra,02 | 0100, 0644);
    char *repo_path = (char *) malloc(strlen(trollpath) - 7);
    strncat(repo_path,trollpath,strlen(trollpath) - 7);
    free(usta);
    free(utra);
    search_dirs(unstaged, untracked, repo_path);
    printf("Changes not staged for commit: \n");
    printf("Untracked files: \n");
    chdir(currdir);
    close(unstaged);
    close(untracked);
    return 0;
}

canonical_original_code:
int cmd_status(int argc, char *argv[]) {
    die_if_not_troll_repo();
    char *currdir = getcwd(((void *)0), 0);
    char *trollpath = get_repo_troll_dir();
    char *usta = (char *)malloc(strlen(trollpath) + 12);
    strcat(usta, trollpath);
    strcat(usta, "unstaged.tmp");
    char *utra = (char *)malloc(strlen(trollpath) + 13);
    strcat(utra, trollpath);
    strcat(utra, "untracked.tmp");
    int unstaged = open(usta,02 | 0100, 0644);
    int untracked = open(utra,02 | 0100, 0644);
    char *repo_path = (char *) malloc(strlen(trollpath) - 7);
    strncat(repo_path,trollpath,strlen(trollpath) - 7);
    free(usta);
    free(utra);
    search_dirs(unstaged, untracked, repo_path);
    printf("Changes not staged for commit: \n");
    printf("Untracked files: \n");
    chdir(currdir);
    close(unstaged);
    close(untracked);
    return 0;
}

variable_types:
currdir
char *

variable_types:
trollpath
char *

variable_types:
usta
char *

variable_types:
utra
char *

variable_types: unstaged int

variable_types: untracked int


decompiled_code:
const char *write_tree()
{
char *v0; // rbx
size_t v1; // rax
char *v2; // rbx
int v3; // ebp
__off_t v4; // rbx
char *v5; // r12
const char *v6; // r13
char *v7; // rbp
size_t v8; // rax
char *v9; // rbp
int v10; // eax
struct stat v12; // [rsp+0h] [rbp-B8h] BYREF

v0 = (char *)get_repo_troll_dir();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 5);
strcat(v2, "index");
v3 = open(v2, 2);
free(v2);
fstat(v3, &v12);
v4 = v12.st_size;
v5 = (char *)malloc(v12.st_size + 15);
sprintf(v5, "tree %lu", v4);
LODWORD(v4) = strlen(v5) + 1;
read(v3, &v5[(int)v4], v12.st_size);
LODWORD(v4) = LODWORD(v12.st_size) + v4;
v6 = (const char *)hash_object(v5, (unsigned int)v4);
v7 = (char *)get_repo_troll_dir();
v8 = strlen(v7);
v9 = (char *)realloc(v7, v8 + 49);
strcat(v9, "objects/");
strncat(v9, v6, 0x28uLL);
v10 = open(v9, 577, 420LL);
write(v10, v5, (int)v4);
return v6;
}

canonical_decompiled_code:
const char *func0()
{
char *v0; // rbx
size_t v1; // rax
char *v2; // rbx
int v3; // ebp
__off_t v4; // rbx
char *v5; // r12
const char *v6; // r13
char *v7; // rbp
size_t v8; // rax
char *v9; // rbp
int v10; // eax
struct stat v12; // [rsp+0h] [rbp-B8h] BYREF

v0 = (char *)get_repo_troll_dir();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 5);
strcat(v2, "index");
v3 = open(v2, 2);
free(v2);
fstat(v3, &v12);
v4 = v12.st_size;
v5 = (char *)malloc(v12.st_size + 15);
sprintf(v5, "tree %lu", v4);
LODWORD(v4) = strlen(v5) + 1;
read(v3, &v5[(int)v4], v12.st_size);
LODWORD(v4) = LODWORD(v12.st_size) + v4;
v6 = (const char *)hash_object(v5, (unsigned int)v4);
v7 = (char *)get_repo_troll_dir();
v8 = strlen(v7);
v9 = (char *)realloc(v7, v8 + 49);
strcat(v9, "objects/");
strncat(v9, v6, 0x28uLL);
v10 = open(v9, 577, 420LL);
write(v10, v5, (int)v4);
return v6;
}

original_code:
char *write_tree() {
    char *indexpath = get_repo_troll_dir();
    indexpath = (char *) realloc(indexpath, strlen(indexpath) + 5);
    strcat(indexpath, "index");
    int fd = open(indexpath, 02);
    free(indexpath);
    struct stat buf;
    fstat(fd, &buf);
    char *data = (char *) malloc((size_t) buf.st_size + 15);
    sprintf(data, "tree %lu", (unsigned long) buf.st_size);
    int left_part_len = strlen(data) + 1;
    read(fd, data + left_part_len, buf.st_size);
    int full_len = left_part_len + buf.st_size;
    char *hash = hash_object(data, full_len);
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 49);
    strcat(path, "objects/");
    strncat(path, hash, 40);
    int objectfd = open(path, 0100 | 01000 | 01, 0644);
    write(objectfd, data, full_len);
    return hash;
}

variable_types:
indexpath
char *

variable_types:
path
char *

variable_types: objectfd int


decompiled_code:
const char *write_commit()
{
char *v0; // rbx
size_t v1; // rax
char *v2; // rbx
int v3; // ebp
__off_t v4; // rbx
char *v5; // r12
const char *v6; // r13
char *v7; // rbp
size_t v8; // rax
char *v9; // rbp
int v10; // eax
struct stat v12; // [rsp+0h] [rbp-B8h] BYREF

v0 = (char *)get_repo_troll_dir();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 10);
strcat(v2, "tmpcommit");
v3 = open(v2, 0, 420LL);
free(v2);
fstat(v3, &v12);
v4 = v12.st_size;
v5 = (char *)malloc(v12.st_size + 17);
sprintf(v5, "commit %lu", v4);
LODWORD(v4) = strlen(v5) + 1;
read(v3, &v5[(int)v4], v12.st_size);
close(v3);
LODWORD(v4) = LODWORD(v12.st_size) + v4;
v6 = (const char *)hash_object(v5, (unsigned int)v4);
v7 = (char *)get_repo_troll_dir();
v8 = strlen(v7);
v9 = (char *)realloc(v7, v8 + 49);
strcat(v9, "objects/");
strncat(v9, v6, 0x28uLL);
v10 = open(v9, 577, 420LL);
write(v10, v5, (int)v4);
return v6;
}

canonical_decompiled_code:
const char *func0()
{
char *v0; // rbx
size_t v1; // rax
char *v2; // rbx
int v3; // ebp
__off_t v4; // rbx
char *v5; // r12
const char *v6; // r13
char *v7; // rbp
size_t v8; // rax
char *v9; // rbp
int v10; // eax
struct stat v12; // [rsp+0h] [rbp-B8h] BYREF

v0 = (char *)get_repo_troll_dir();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 10);
strcat(v2, "tmpcommit");
v3 = open(v2, 0, 420LL);
free(v2);
fstat(v3, &v12);
v4 = v12.st_size;
v5 = (char *)malloc(v12.st_size + 17);
sprintf(v5, "commit %lu", v4);
LODWORD(v4) = strlen(v5) + 1;
read(v3, &v5[(int)v4], v12.st_size);
close(v3);
LODWORD(v4) = LODWORD(v12.st_size) + v4;
v6 = (const char *)hash_object(v5, (unsigned int)v4);
v7 = (char *)get_repo_troll_dir();
v8 = strlen(v7);
v9 = (char *)realloc(v7, v8 + 49);
strcat(v9, "objects/");
strncat(v9, v6, 0x28uLL);
v10 = open(v9, 577, 420LL);
write(v10, v5, (int)v4);
return v6;
}

original_code:
char *write_commit() {
    char *tmpcommit_path = get_repo_troll_dir();
    tmpcommit_path = (char *) realloc(tmpcommit_path, strlen(tmpcommit_path) + 10);
    strcat(tmpcommit_path, "tmpcommit");
    int tmpcommitfd = open(tmpcommit_path, 00, 0644);
    free(tmpcommit_path);
    struct stat buf;
    fstat(tmpcommitfd, &buf);
    char *data = (char *) malloc((size_t) buf.st_size + 17);
    sprintf(data, "commit %lu", (unsigned long) buf.st_size);
    int left_part_len = strlen(data) + 1;
    read(tmpcommitfd, data + left_part_len, buf.st_size);
    close(tmpcommitfd);
    int full_len = left_part_len + buf.st_size;
    char *hash = hash_object(data, full_len);
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 49);
    strcat(path, "objects/");
    strncat(path, hash, 40);
    int objectfd = open(path, 0100 | 01000 | 01, 0644);
    write(objectfd, data, full_len);
    return hash;
}

variable_types: tmpcommitfd int


commit

decompiled_code:
int __fastcall commit(void *buf)
{
char *v1; // rbx
size_t v2; // rax
char *v3; // rbp
const void *v4; // r12
int v5; // ebx
char *v6; // rbp
size_t v7; // rax
char *v8; // rbp
int v9; // er12
char *v10; // rax
size_t v11; // r14
char *v12; // rax
size_t v13; // rax
const char *v14; // r14
void *v15; // rbx
size_t v16; // rax
char *v17; // rbx
int v18; // ebx
void *v20; // r14
struct stat v21; // [rsp+0h] [rbp-148h] BYREF
struct stat bufa; // [rsp+90h] [rbp-B8h] BYREF

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 10);
strcat(v3, "tmpcommit");
v4 = (const void *)write_tree();
v5 = open(v3, 577, 420LL);
free(v3);
write(v5, "tree ", 5uLL);
write(v5, v4, 0x28uLL);
v6 = (char *)get_repo_troll_dir();
v7 = strlen(v6);
v8 = (char *)realloc(v6, v7 + 7);
strcat(v8, "master");
v9 = open(v8, 66, 420LL);
fstat(v9, &bufa);
if ( bufa.st_size > 0 )
{
write(v5, "\nparent ", 8uLL);
v20 = malloc(0x29uLL);
read(v9, v20, 0x28uLL);
write(v5, v20, 0x28uLL);
}
write(v5, "\nauthor ", 8uLL);
v10 = getenv("USER");
v11 = strlen(v10);
v12 = getenv("USER");
write(v5, v12, v11);
write(v5, "\n\n", 2uLL);
v13 = strlen((const char *)buf);
write(v5, buf, v13);
write(v5, "\n", 1uLL);
close(v5);
v14 = write_commit();
lseek(v9, 0LL, 0);
write(v9, v14, 0x28uLL);
v15 = (void *)get_repo_troll_dir();
v16 = strlen(v8);
v17 = (char *)realloc(v15, v16 + 5);
strcat(v17, "HEAD");
v18 = open(v17, 66, 420LL);
fstat(v18, &v21);
if ( !v21.st_size )
write(v18, "master", 6uLL);
return printf("[master %.7s] %s\n", v14, (const char *)buf);
}

canonical_decompiled_code:
int __fastcall func1(void *buf)
{
char *v1; // rbx
size_t v2; // rax
char *v3; // rbp
const void *v4; // r12
int v5; // ebx
char *v6; // rbp
size_t v7; // rax
char *v8; // rbp
int v9; // er12
char *v10; // rax
size_t v11; // r14
char *v12; // rax
size_t v13; // rax
const char *v14; // r14
void *v15; // rbx
size_t v16; // rax
char *v17; // rbx
int v18; // ebx
void *v20; // r14
struct stat v21; // [rsp+0h] [rbp-148h] BYREF
struct stat bufa; // [rsp+90h] [rbp-B8h] BYREF

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 10);
strcat(v3, "tmpcommit");
v4 = (const void *)write_tree();
v5 = open(v3, 577, 420LL);
free(v3);
write(v5, "tree ", 5uLL);
write(v5, v4, 0x28uLL);
v6 = (char *)get_repo_troll_dir();
v7 = strlen(v6);
v8 = (char *)realloc(v6, v7 + 7);
strcat(v8, "master");
v9 = open(v8, 66, 420LL);
fstat(v9, &bufa);
if ( bufa.st_size > 0 )
{
write(v5, "\nparent ", 8uLL);
v20 = malloc(0x29uLL);
read(v9, v20, 0x28uLL);
write(v5, v20, 0x28uLL);
}
write(v5, "\nauthor ", 8uLL);
v10 = getenv("USER");
v11 = strlen(v10);
v12 = getenv("USER");
write(v5, v12, v11);
write(v5, "\n\n", 2uLL);
v13 = strlen((const char *)buf);
write(v5, buf, v13);
write(v5, "\n", 1uLL);
close(v5);
v14 = func0();
lseek(v9, 0LL, 0);
write(v9, v14, 0x28uLL);
v15 = (void *)get_repo_troll_dir();
v16 = strlen(v8);
v17 = (char *)realloc(v15, v16 + 5);
strcat(v17, "HEAD");
v18 = open(v17, 66, 420LL);
fstat(v18, &v21);
if ( !v21.st_size )
write(v18, "master", 6uLL);
return printf("[master %.7s] %s\n", v14, (const char *)buf);
}

original_code:
void commit(const char *message) {
    char *tmpcommit_path = get_repo_troll_dir();
    tmpcommit_path = (char *) realloc(tmpcommit_path, strlen(tmpcommit_path) + 10);
    strcat(tmpcommit_path, "tmpcommit");
    char *treehash = write_tree();
    int tmpcommitfd = open(tmpcommit_path, 0100 | 01000 | 01, 0644);
    free(tmpcommit_path);
    write(tmpcommitfd, "tree ", 5);
    write(tmpcommitfd, treehash, 40);
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 7);
    strcat(path, "master");
    int masterfd = open(path, 0100 | 02, 0644);
    struct stat buf;
    fstat(masterfd, &buf);
    if (buf.st_size > 0) {
        write(tmpcommitfd, "\nparent ", 8);
        char *parenthash = (char *) malloc(41 * sizeof(char));
        read(masterfd, parenthash, 40);
        write(tmpcommitfd, parenthash, 40);
    }
    write(tmpcommitfd, "\nauthor ", 8);
    write(tmpcommitfd, getenv("USER"), strlen(getenv("USER")));
    write(tmpcommitfd, "\n\n", 2);
    write(tmpcommitfd, message, strlen(message));
    write(tmpcommitfd, "\n", 1);
    close(tmpcommitfd);
    char *hash = write_commit();
    lseek(masterfd, 0, 0);
    write(masterfd, hash, 40);
    char *headpath = get_repo_troll_dir();
    headpath = (char *) realloc(headpath, strlen(path) + 5);
    strcat(headpath, "HEAD");
    int headfd = open(headpath, 0100 | 02, 0644);
    struct stat headbuf;
    fstat(headfd, &headbuf);
    if (headbuf.st_size == 0) {
        write(headfd, "master", 6);
    }
    printf("[master %.7s] %s\n", hash, message);
}

canonical_original_code:
void commit(char *message) {
    char *tmpcommit_path = get_repo_troll_dir();
    tmpcommit_path = (char *) realloc(tmpcommit_path, strlen(tmpcommit_path) + 10);
    strcat(tmpcommit_path, "tmpcommit");
    char *treehash = write_tree();
    int tmpcommitfd = open(tmpcommit_path, 0100 | 01000 | 01, 0644);
    free(tmpcommit_path);
    write(tmpcommitfd, "tree ", 5);
    write(tmpcommitfd, treehash, 40);
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 7);
    strcat(path, "master");
    int masterfd = open(path, 0100 | 02, 0644);
    struct stat buf;
    fstat(masterfd, &buf);
    if (buf.st_size > 0) {
        write(tmpcommitfd, "\nparent ", 8);
        char *parenthash = (char *) malloc(41 * sizeof(char));
        read(masterfd, parenthash, 40);
        write(tmpcommitfd, parenthash, 40);
    }
    write(tmpcommitfd, "\nauthor ", 8);
    write(tmpcommitfd, getenv("USER"), strlen(getenv("USER")));
    write(tmpcommitfd, "\n\n", 2);
    write(tmpcommitfd, message, strlen(message));
    write(tmpcommitfd, "\n", 1);
    close(tmpcommitfd);
    char *hash = write_commit();
    lseek(masterfd, 0, 0);
    write(masterfd, hash, 40);
    char *headpath = get_repo_troll_dir();
    headpath = (char *) realloc(headpath, strlen(path) + 5);
    strcat(headpath, "HEAD");
    int headfd = open(headpath, 0100 | 02, 0644);
    struct stat headbuf;
    fstat(headfd, &headbuf);
    if (headbuf.st_size == 0) {
        write(headfd, "master", 6);
    }
    printf("[master %.7s] %s\n", hash, message);
}

variable_types:
message
char *

variable_types:
treehash
char *

variable_types: masterfd int

variable_types:
parenthash
char *

variable_types:
headpath
char *

variable_types: headfd int


decompiled_code:
char *__fastcall get_parent(char *src)
{
char *v1; // rbx
size_t v2; // rax
char *v3; // rbx
int v4; // ebx
__off_t v5; // r12
void *v6; // rbp
size_t v7; // rax
char *v8; // rax
char *v9; // rbx
const char *v10; // r12
struct stat v12; // [rsp+0h] [rbp-A8h] BYREF

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 49);
strcat(v3, "objects/");
strncat(v3, src, 0x28uLL);
v4 = open(v3, 0);
if ( *_errno_location() == 2 )
{
puts("fatal: Object does not exist.");
exit(128);
}
fstat(v4, &v12);
v5 = v12.st_size;
v6 = malloc(v12.st_size + 1);
read(v4, v6, v5);
v7 = strlen((const char *)v6);
v8 = strstr((const char *)v6 + v7 + 1, "parent");
v9 = v8;
if ( v8 )
{
v10 = v8 + 7;
v9 = (char *)malloc(0x29uLL);
strncpy(v9, v10, 0x28uLL);
}
free(v6);
return v9;
}

canonical_decompiled_code:
char *__fastcall func2(char *src)
{
char *v1; // rbx
size_t v2; // rax
char *v3; // rbx
int v4; // ebx
__off_t v5; // r12
void *v6; // rbp
size_t v7; // rax
char *v8; // rax
char *v9; // rbx
const char *v10; // r12
struct stat v12; // [rsp+0h] [rbp-A8h] BYREF

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 49);
strcat(v3, "objects/");
strncat(v3, src, 0x28uLL);
v4 = open(v3, 0);
if ( *_errno_location() == 2 )
{
puts("fatal: Object does not exist.");
exit(128);
}
fstat(v4, &v12);
v5 = v12.st_size;
v6 = malloc(v12.st_size + 1);
read(v4, v6, v5);
v7 = strlen((const char *)v6);
v8 = strstr((const char *)v6 + v7 + 1, "parent");
v9 = v8;
if ( v8 )
{
v10 = v8 + 7;
v9 = (char *)malloc(0x29uLL);
strncpy(v9, v10, 0x28uLL);
}
free(v6);
return v9;
}

original_code:
char *get_parent(char *hash) {
    char *obj_path = get_repo_troll_dir();
    obj_path = (char *) realloc(obj_path, strlen(obj_path) + 49);
    strcat(obj_path, "objects/");
    strncat(obj_path, hash, 40);
    int objectfd = open(obj_path, 00);
    if ((*__errno_location ()) == 2) {
        printf("fatal: Object does not exist.\n");
        exit(128);
    }
    struct stat buf;
    fstat(objectfd, &buf);
    char *data = (char *) malloc((size_t) buf.st_size + 1);
    read(objectfd, data, buf.st_size);
    char *data_right = data + strlen(data) + 1;
    char *parent_hash = strstr(data_right, "parent");
    if (parent_hash) {
        parent_hash += 7;
        char *hashcpy = (char *) malloc(41 * sizeof(char));
        strncpy(hashcpy, parent_hash, 40);
        free(data);
        return hashcpy;
    }
    free(data);
    return ((void *)0);
}

variable_types:
hash
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
data
char *

variable_types:
hashcpy
char *


decompiled_code:
void *__fastcall init_troll_dir(char *path)
{
char *v1; // rax
char *v2; // rbx
size_t v3; // r12
size_t v4; // rax
char *v5; // rbx
size_t v6; // rax
size_t v7; // rax
void *v8; // rbp
size_t v9; // rax
size_t v10; // rax
char *v11; // rbx
size_t v12; // rax
void *v13; // r12
size_t v14; // rax
int v15; // eax
size_t v16; // rax
void *v17; // r12
size_t v18; // rax
int v19; // eax
size_t v21; // rax

v1 = getcwd(0LL, 0LL);
v2 = v1;
if ( path )
{
v3 = strlen(v1);
v4 = strlen(path);
v5 = (char *)realloc(v2, v3 + v4 + 9);
*(_WORD *)&v5[strlen(v5)] = 47;
v6 = strlen(v5);
strncat(v5, path, v6);
*(_WORD *)&v5[strlen(v5)] = 47;
mkdir(path, 0x1EDu);
}
else
{
v21 = strlen(v1);
v5 = (char *)realloc(v2, v21 + 9);
*(_WORD *)&v5[strlen(v5)] = 47;
}
strcat(v5, ".troll");
*(_WORD *)&v5[strlen(v5)] = 47;
mkdir(v5, 0x1EDu);
v7 = strlen(v5);
v8 = malloc(v7 + 1);
v9 = strlen(v5);
memcpy(v8, v5, v9 + 1);
v10 = strlen(v5);
v11 = (char *)realloc(v5, v10 + 7);
*(_QWORD *)&v11[strlen(v11)] = 0x737463656A626FLL;
mkdir(v11, 0x1EDu);
v12 = strlen(v11);
v13 = malloc(v12 + 6);
v14 = strlen((const char *)v8);
memcpy(v13, v8, v14 + 1);
strcat((char *)v13, "index");
v15 = open((const char *)v13, 64, 420LL);
close(v15);
v16 = strlen(v11);
v17 = malloc(v16 + 5);
v18 = strlen((const char *)v8);
memcpy(v17, v8, v18 + 1);
strcat((char *)v17, "HEAD");
v19 = open((const char *)v17, 64, 420LL);
close(v19);
free(v11);
return v8;
}

canonical_decompiled_code:
void *__fastcall func0(char *path)
{
char *v1; // rax
char *v2; // rbx
size_t v3; // r12
size_t v4; // rax
char *v5; // rbx
size_t v6; // rax
size_t v7; // rax
void *v8; // rbp
size_t v9; // rax
size_t v10; // rax
char *v11; // rbx
size_t v12; // rax
void *v13; // r12
size_t v14; // rax
int v15; // eax
size_t v16; // rax
void *v17; // r12
size_t v18; // rax
int v19; // eax
size_t v21; // rax

v1 = getcwd(0LL, 0LL);
v2 = v1;
if ( path )
{
v3 = strlen(v1);
v4 = strlen(path);
v5 = (char *)realloc(v2, v3 + v4 + 9);
*(_WORD *)&v5[strlen(v5)] = 47;
v6 = strlen(v5);
strncat(v5, path, v6);
*(_WORD *)&v5[strlen(v5)] = 47;
mkdir(path, 0x1EDu);
}
else
{
v21 = strlen(v1);
v5 = (char *)realloc(v2, v21 + 9);
*(_WORD *)&v5[strlen(v5)] = 47;
}
strcat(v5, ".troll");
*(_WORD *)&v5[strlen(v5)] = 47;
mkdir(v5, 0x1EDu);
v7 = strlen(v5);
v8 = malloc(v7 + 1);
v9 = strlen(v5);
memcpy(v8, v5, v9 + 1);
v10 = strlen(v5);
v11 = (char *)realloc(v5, v10 + 7);
*(_QWORD *)&v11[strlen(v11)] = 0x737463656A626FLL;
mkdir(v11, 0x1EDu);
v12 = strlen(v11);
v13 = malloc(v12 + 6);
v14 = strlen((const char *)v8);
memcpy(v13, v8, v14 + 1);
strcat((char *)v13, "index");
v15 = open((const char *)v13, 64, 420LL);
close(v15);
v16 = strlen(v11);
v17 = malloc(v16 + 5);
v18 = strlen((const char *)v8);
memcpy(v17, v8, v18 + 1);
strcat((char *)v17, "HEAD");
v19 = open((const char *)v17, 64, 420LL);
close(v19);
free(v11);
return v8;
}

original_code:
char *init_troll_dir(const char *base) {
    char *dir = getcwd(((void *)0), 0);
    if (base) {
        dir = (char *) realloc(dir, strlen(dir) + strlen(base) + 9);
    }
    else {
        dir = (char *) realloc(dir, strlen(dir) + 9);
    }
    strcat(dir, "/");
    if (base) {
        strncat(dir, base, strlen(dir));
        strcat(dir, "/");
        mkdir(base, 0755);
    }
    strcat(dir, ".troll");
    strcat(dir, "/");
    mkdir(dir, 0755);
    char *trolldir = (char *) malloc(strlen(dir) + 1);
    memcpy(trolldir, dir, strlen(dir) + 1);
    dir = (char *) realloc(dir, strlen(dir) + 7);
    strcat(dir, "objects");
    mkdir(dir, 0755);
    char *indexpath = (char *) malloc(strlen(dir) + 6);
    memcpy(indexpath, trolldir, strlen(trolldir) + 1);
    strcat(indexpath, "index");
    int fd = open(indexpath, 0100, 0644);
    close(fd);
    char *headpath = (char *) malloc(strlen(dir) + 5);
    memcpy(headpath, trolldir, strlen(trolldir) + 1);
    strcat(headpath, "HEAD");
    int headfd = open(headpath, 0100, 0644);
    close(headfd);
    free(dir);
    return trolldir;
}

canonical_original_code:
char *init_troll_dir(char *base) {
    char *dir = getcwd(((void *)0), 0);
    if (base) {
        dir = (char *) realloc(dir, strlen(dir) + strlen(base) + 9);
    }
    else {
        dir = (char *) realloc(dir, strlen(dir) + 9);
    }
    strcat(dir, "/");
    if (base) {
        strncat(dir, base, strlen(dir));
        strcat(dir, "/");
        mkdir(base, 0755);
    }
    strcat(dir, ".troll");
    strcat(dir, "/");
    mkdir(dir, 0755);
    char *trolldir = (char *) malloc(strlen(dir) + 1);
    memcpy(trolldir, dir, strlen(dir) + 1);
    dir = (char *) realloc(dir, strlen(dir) + 7);
    strcat(dir, "objects");
    mkdir(dir, 0755);
    char *indexpath = (char *) malloc(strlen(dir) + 6);
    memcpy(indexpath, trolldir, strlen(trolldir) + 1);
    strcat(indexpath, "index");
    int fd = open(indexpath, 0100, 0644);
    close(fd);
    char *headpath = (char *) malloc(strlen(dir) + 5);
    memcpy(headpath, trolldir, strlen(trolldir) + 1);
    strcat(headpath, "HEAD");
    int headfd = open(headpath, 0100, 0644);
    close(headfd);
    free(dir);
    return trolldir;
}

variable_types:
base
char *

variable_types:
dir
char *

variable_types:
trolldir
char *

variable_types: fd int


decompiled_code:
char *recursive_get_repo_troll_dir()
{
char *v0; // rbx
int v1; // eax
bool v2; // cf
bool v3; // zf
const char *v4; // rdi
__int64 v5; // rcx
char *v6; // rsi
char *v7; // rbx
size_t v9; // rax

v0 = getcwd(0LL, 0LL);
v1 = chdir(".troll");
v2 = 0;
v3 = v1 == 0;
if ( v1 )
{
v4 = "/";
v5 = 2LL;
v6 = v0;
do
{
if ( !v5 )
break;
v2 = (unsigned __int8)*v6 < (unsigned int)*v4;
v3 = *v6++ == *v4++;
--v5;
}
while ( v3 );
v7 = 0LL;
if ( (!v2 && !v3) != v2 )
{
chdir("..");
v7 = (char *)recursive_get_repo_troll_dir("..", v6);
}
}
else
{
v9 = strlen(v0);
v7 = (char *)realloc(v0, v9 + 9);
strcat(v7, "/.troll/");
}
return v7;
}

canonical_decompiled_code:
char *func1()
{
char *v0; // rbx
int v1; // eax
bool v2; // cf
bool v3; // zf
const char *v4; // rdi
__int64 v5; // rcx
char *v6; // rsi
char *v7; // rbx
size_t v9; // rax

v0 = getcwd(0LL, 0LL);
v1 = chdir(".troll");
v2 = 0;
v3 = v1 == 0;
if ( v1 )
{
v4 = "/";
v5 = 2LL;
v6 = v0;
do
{
if ( !v5 )
break;
v2 = (unsigned __int8)*v6 < (unsigned int)*v4;
v3 = *v6++ == *v4++;
--v5;
}
while ( v3 );
v7 = 0LL;
if ( (!v2 && !v3) != v2 )
{
chdir("..");
v7 = (char *)func1("..", v6);
}
}
else
{
v9 = strlen(v0);
v7 = (char *)realloc(v0, v9 + 9);
strcat(v7, "/.troll/");
}
return v7;
}

original_code:
char *recursive_get_repo_troll_dir() {
  char *cwd = getcwd(((void *)0), 0);
  int ret;
  ret = chdir(".troll");
  if (ret == 0 ) {
    cwd = (char *) realloc(cwd, strlen(cwd) + 9);
    strcat(cwd, "/.troll/");
    return cwd;
  }
  if (!strcmp(cwd, "/")) {
    return ((void *)0);
  }
  ret = chdir("..");
  return recursive_get_repo_troll_dir();
}

variable_types:
cwd
char *

variable_types: ret int


decompiled_code:
char *get_repo_troll_dir()
{
char *v0; // rbx
char *v1; // rbp

v0 = getcwd(0LL, 0LL);
v1 = recursive_get_repo_troll_dir();
chdir(v0);
free(v0);
return v1;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // rbx
char *v1; // rbp

v0 = getcwd(0LL, 0LL);
v1 = func1();
chdir(v0);
free(v0);
return v1;
}

original_code:
char *get_repo_troll_dir() {
    char *cwd = getcwd(((void *)0), 0);
    char *trolldir = recursive_get_repo_troll_dir();
    chdir(cwd);
    free(cwd);
    return trolldir;
}


decompiled_code:
void die_if_not_troll_repo()
{
char *v0; // rax

v0 = get_repo_troll_dir();
if ( !v0 )
{
puts("Not a troll repository.");
exit(128);
}
free(v0);
}

canonical_decompiled_code:
void func3()
{
char *v0; // rax

v0 = func2();
if ( !v0 )
{
puts("Not a troll repository.");
exit(128);
}
free(v0);
}

original_code:
void die_if_not_troll_repo() {
    char *trolldir = get_repo_troll_dir();
    if (trolldir) {
        free(trolldir);
    }
    else {
        free(trolldir);
        printf("Not a troll repository.\n");
        exit(128);
    }
}


decompiled_code:
__int64 __fastcall cmd_help(int a1, __int64 a2)
{
const char *v2; // rdx

if ( a1 == 1 )
{
puts(help_text);
}
else
{
v2 = *(const char **)(a2 + 8);
if ( !strcmp(v2, "help") )
{
puts(h_help);
}
else if ( !strcmp(v2, "init") )
{
puts(h_init);
}
else if ( !strcmp(v2, "add") )
{
puts(h_add);
}
else if ( !strcmp(v2, "commit") )
{
puts(h_commit);
}
else if ( !strcmp(v2, "ls-files") )
{
puts(h_ls_files);
}
else if ( !strcmp(v2, "log") )
{
puts(h_log);
}
else if ( !strcmp(v2, "checkout") )
{
puts(h_checkout);
}
else if ( !strcmp(v2, "status") )
{
puts(h_status);
}
else if ( !strcmp(v2, "face") )
{
puts(h_face);
}
else
{
printf("No manual entry for troll%s\n", v2);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
const char *v2; // rdx

if ( a1 == 1 )
{
puts(help_text);
}
else
{
v2 = *(const char **)(a2 + 8);
if ( !strcmp(v2, "help") )
{
puts(h_help);
}
else if ( !strcmp(v2, "init") )
{
puts(h_init);
}
else if ( !strcmp(v2, "add") )
{
puts(h_add);
}
else if ( !strcmp(v2, "commit") )
{
puts(h_commit);
}
else if ( !strcmp(v2, "ls-files") )
{
puts(h_ls_files);
}
else if ( !strcmp(v2, "log") )
{
puts(h_log);
}
else if ( !strcmp(v2, "checkout") )
{
puts(h_checkout);
}
else if ( !strcmp(v2, "status") )
{
puts(h_status);
}
else if ( !strcmp(v2, "face") )
{
puts(h_face);
}
else
{
printf("No manual entry for troll%s\n", v2);
}
}
return 0LL;
}

original_code:
int cmd_help(int argc, const char *argv[]) {
    if (argc == 1) {
        printf("%s\n", help_text);
    }
    else {
      if(!strcmp(argv[1],"help")) {
 printf("%s\n", h_help);
      }
      else if(!strcmp(argv[1],"init")) {
 printf("%s\n", h_init);
      }
      else if(!strcmp(argv[1],"add")) {
 printf("%s\n", h_add);
      }
      else if(!strcmp(argv[1],"commit")) {
 printf("%s\n", h_commit);
      }
      else if(!strcmp(argv[1],"ls-files")) {
 printf("%s\n", h_ls_files);
      }
      else if(!strcmp(argv[1],"log")) {
 printf("%s\n", h_log);
      }
      else if(!strcmp(argv[1],"checkout")) {
 printf("%s\n", h_checkout);
      }
      else if(!strcmp(argv[1],"status")) {
 printf("%s\n", h_status);
      }
      else if(!strcmp(argv[1],"face")) {
 printf("%s\n", h_face);
      }
      else {
 printf("No manual entry for troll%s\n", argv[1]);
      }
    }
    return 0;
}

canonical_original_code:
int cmd_help(int argc, char *argv[]) {
    if (argc == 1) {
        printf("%s\n", help_text);
    }
    else {
      if(!strcmp(argv[1],"help")) {
 printf("%s\n", h_help);
      }
      else if(!strcmp(argv[1],"init")) {
 printf("%s\n", h_init);
      }
      else if(!strcmp(argv[1],"add")) {
 printf("%s\n", h_add);
      }
      else if(!strcmp(argv[1],"commit")) {
 printf("%s\n", h_commit);
      }
      else if(!strcmp(argv[1],"ls-files")) {
 printf("%s\n", h_ls_files);
      }
      else if(!strcmp(argv[1],"log")) {
 printf("%s\n", h_log);
      }
      else if(!strcmp(argv[1],"checkout")) {
 printf("%s\n", h_checkout);
      }
      else if(!strcmp(argv[1],"status")) {
 printf("%s\n", h_status);
      }
      else if(!strcmp(argv[1],"face")) {
 printf("%s\n", h_face);
      }
      else {
 printf("No manual entry for troll%s\n", argv[1]);
      }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __fastcall new_index(__int64 a1)
{
char *v1; // rbx
size_t v2; // rax
char *v3; // rbx
int v4; // ebp

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 5);
strcat(v3, "index");
printf("New index at %s\n", v3);
v4 = open(v3, 513, 420LL);
free(v3);
lseek(v4, 0LL, 0);
LODWORD(v3) = dup(1);
dup2(v4, 1);
print_object(a1);
return dup2((int)v3, 1);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
char *v1; // rbx
size_t v2; // rax
char *v3; // rbx
int v4; // ebp

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 5);
strcat(v3, "index");
printf("New index at %s\n", v3);
v4 = open(v3, 513, 420LL);
free(v3);
lseek(v4, 0LL, 0);
LODWORD(v3) = dup(1);
dup2(v4, 1);
print_object(a1);
return dup2((int)v3, 1);
}

original_code:
void new_index(char *hash) {
    char *indexpath = get_repo_troll_dir();
    indexpath = (char *) realloc(indexpath, strlen(indexpath) + 5);
    strcat(indexpath, "index");
    printf("New index at %s\n",indexpath);
    int index = open(indexpath, 01 | 01000, 0644);
    free(indexpath);
    lseek(index, 0, 0);
    int sout = dup(1);
    dup2(index,1);
    print_object(hash);
    dup2(sout,1);
}

variable_types:
indexpath
char *

variable_types: index int

variable_types: sout int


decompiled_code:
__int64 __fastcall cmd_checkout(__int64 a1, __int64 a2)
{
new_index(*(_QWORD *)(a2 + 8));
copy_out();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
func0(*(_QWORD *)(a2 + 8));
func1();
return 0LL;
}

original_code:
int cmd_checkout(int argc, const char *argv[]) {
    new_index((char *)(argv[1]));
    copy_out();
    return 0;
}

canonical_original_code:
int cmd_checkout(int argc, char *argv[]) {
    new_index((char *)(argv[1]));
    copy_out();
    return 0;
}


decompiled_code:
void __fastcall print_log(__int64 a1)
{
__int64 v1; // rax

if ( a1 )
{
print_object();
putchar(10);
v1 = get_parent(a1);
print_log(v1);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
__int64 v1; // rax

if ( a1 )
{
print_object();
putchar(10);
v1 = get_parent(a1);
func0(v1);
}
}

original_code:
void print_log(char *hash) {
    if (!hash) {
        return;
    }
    print_object(hash);
    printf("\n");
    print_log(get_parent(hash));
}


decompiled_code:
__int64 cmd_log()
{
char *v0; // rbx
size_t v1; // rax
char *v2; // rbx
int v3; // ebp
void *v4; // rbx
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi
char *v11; // r12
size_t v12; // rax
char *v13; // r12
int v14; // eax

die_if_not_troll_repo();
v0 = (char *)((__int64 (*)(void))get_repo_troll_dir)();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 5);
strcat(v2, "HEAD");
v3 = open(v2, 0);
v4 = malloc(0x29uLL);
if ( !(unsigned int)read(v3, v4, 0x28uLL) )
return 0xFFFFFFFFLL;
puts((const char *)v4);
v7 = "master";
v8 = 7LL;
v9 = (const char *)v4;
do
{
if ( !v8 )
break;
v5 = *v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
v11 = (char *)get_repo_troll_dir(v7, v9);
v12 = strlen(v11);
v13 = (char *)realloc(v11, v12 + 7);
strcat(v13, "master");
v14 = open(v13, 0);
read(v14, v4, 0x28uLL);
}
print_log((__int64)v4);
free(v4);
close(v3);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
char *v0; // rbx
size_t v1; // rax
char *v2; // rbx
int v3; // ebp
void *v4; // rbx
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi
char *v11; // r12
size_t v12; // rax
char *v13; // r12
int v14; // eax

die_if_not_troll_repo();
v0 = (char *)((__int64 (*)(void))get_repo_troll_dir)();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 5);
strcat(v2, "HEAD");
v3 = open(v2, 0);
v4 = malloc(0x29uLL);
if ( !(unsigned int)read(v3, v4, 0x28uLL) )
return 0xFFFFFFFFLL;
puts((const char *)v4);
v7 = "master";
v8 = 7LL;
v9 = (const char *)v4;
do
{
if ( !v8 )
break;
v5 = *v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
v11 = (char *)get_repo_troll_dir(v7, v9);
v12 = strlen(v11);
v13 = (char *)realloc(v11, v12 + 7);
strcat(v13, "master");
v14 = open(v13, 0);
read(v14, v4, 0x28uLL);
}
func0((__int64)v4);
free(v4);
close(v3);
return 0LL;
}

original_code:
int cmd_log(int argc, const char *argv[]) {
    die_if_not_troll_repo();
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 5);
    strcat(path, "HEAD");
    int fd = open(path, 00);
    char *hash = (char *) malloc(41 * sizeof(char));
    int test;
    test = read(fd, hash, 40);
    if(!test)
      return -1;
    printf("%s\n", hash);
    if (strcmp(hash, "master") == 0) {
        char *path2 = get_repo_troll_dir();
        path2 = (char *) realloc(path2, strlen(path2) + 7);
        strcat(path2, "master");
        int fd = open(path2, 00);
        read(fd, hash, 40);
    }
    print_log(hash);
    free(hash);
    close(fd);
    return 0;
}

canonical_original_code:
int cmd_log(int argc, char *argv[]) {
    die_if_not_troll_repo();
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 5);
    strcat(path, "HEAD");
    int fd = open(path, 00);
    char *hash = (char *) malloc(41 * sizeof(char));
    int test;
    test = read(fd, hash, 40);
    if(!test)
      return -1;
    printf("%s\n", hash);
    if (strcmp(hash, "master") == 0) {
        char *path2 = get_repo_troll_dir();
        path2 = (char *) realloc(path2, strlen(path2) + 7);
        strcat(path2, "master");
        int fd = open(path2, 00);
        read(fd, hash, 40);
    }
    print_log(hash);
    free(hash);
    close(fd);
    return 0;
}

variable_types:
path
char *

variable_types: test int


decompiled_code:
char *__fastcall sha1tohex(unsigned __int8 *a1)
{
char *v2; // r13
char *v3; // rbx

v2 = (char *)malloc(0x29uLL);
v3 = v2;
do
{
sprintf(v3, "%02x", *a1++);
v3 += 2;
}
while ( v3 != v2 + 40 );
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int8 *a1)
{
char *v2; // r13
char *v3; // rbx

v2 = (char *)malloc(0x29uLL);
v3 = v2;
do
{
sprintf(v3, "%02x", *a1++);
v3 += 2;
}
while ( v3 != v2 + 40 );
return v2;
}

original_code:
char *sha1tohex(unsigned char *hash) {
    char *hex = (char *) malloc(41 * sizeof(char));
    int i;
    for (i = 0; i < 20; i++) {
        sprintf(hex + i * 2, "%02x", hash[i]);
    }
    return hex;
}

variable_types:
hash
unsigned char *

variable_types:
hex
char *

variable_types: i int


decompiled_code:
char *__fastcall hash_object(__int64 a1, int a2)
{
unsigned __int8 *v2; // rax

v2 = (unsigned __int8 *)SHA1(a1, a2, 0LL);
return sha1tohex(v2);
}

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

v2 = (unsigned __int8 *)SHA1(a1, a2, 0LL);
return func0(v2);
}

original_code:
char *hash_object(char *data, int len) {
    unsigned char *hash = SHA1((unsigned char *) data, len, ((void *)0));
    char *hex = sha1tohex(hash);
    return hex;
}

variable_types:
data
char *

variable_types: len int


decompiled_code:
__int64 cmd_face()
{
puts(&s);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
puts(&s);
return 0LL;
}

original_code: int cmd_face(int b, const char *e[]){printf("░░░░░░▄▄▄▄▀▀▀▀▀▀▀▀▄▄▄▄▄▄░░░░░░░\n░░░░░█░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░▀▀▄░░░░\n░░░░█░░░▒▒▒▒▒▒░░░░░░░░▒▒▒░░█░░░\n░░░█░░░░░░▄██▀▄▄░░░░░▄▄▄░░░░█░░\n░▄▀▒▄▄▄▒░█▀▀▀▀▄▄█░░░██▄▄█░░░░█░\n█░▒█▒▄░▀▄▄▄▀░░░░░░░░█░░░▒▒▒▒▒░█\n█░▒█░█▀▄▄░░░░░█▀░░░░▀▄░░▄▀▀▀▄▒█\n░█░▀▄░█▄░█▀▄▄░▀░▀▀░▄▄▀░░░░█░░█░\n░░█░░░▀▄▀█▄▄░█▀▀▀▄▄▄▄▀▀█▀██░█░░\n░░░█░░░░██░░▀█▄▄▄█▄▄█▄████░█░░░\n░░░░█░░░░▀▀▄░█░░░█░█▀██████░█░░\n░░░░░▀▄░░░░░▀▀▄▄▄█▄█▄█▄█▄▀░░█░░\n░░░░░░░▀▄▄░▒▒▒▒░░░░░░░░░░▒░░░█░\n░░░░░░░░░░▀▀▄▄░▒▒▒▒▒▒▒▒▒▒░░░░█░\n░░░░░░░░░░░░░░▀▄▄▄▄▄░░░░░░░░█░░\nUMAD?\n");return 0;}

canonical_original_code: int cmd_face(int b, char *e[]){printf("░░░░░░▄▄▄▄▀▀▀▀▀▀▀▀▄▄▄▄▄▄░░░░░░░\n░░░░░█░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░▀▀▄░░░░\n░░░░█░░░▒▒▒▒▒▒░░░░░░░░▒▒▒░░█░░░\n░░░█░░░░░░▄██▀▄▄░░░░░▄▄▄░░░░█░░\n░▄▀▒▄▄▄▒░█▀▀▀▀▄▄█░░░██▄▄█░░░░█░\n█░▒█▒▄░▀▄▄▄▀░░░░░░░░█░░░▒▒▒▒▒░█\n█░▒█░█▀▄▄░░░░░█▀░░░░▀▄░░▄▀▀▀▄▒█\n░█░▀▄░█▄░█▀▄▄░▀░▀▀░▄▄▀░░░░█░░█░\n░░█░░░▀▄▀█▄▄░█▀▀▀▄▄▄▄▀▀█▀██░█░░\n░░░█░░░░██░░▀█▄▄▄█▄▄█▄████░█░░░\n░░░░█░░░░▀▀▄░█░░░█░█▀██████░█░░\n░░░░░▀▄░░░░░▀▀▄▄▄█▄█▄█▄█▄▀░░█░░\n░░░░░░░▀▄▄░▒▒▒▒░░░░░░░░░░▒░░░█░\n░░░░░░░░░░▀▀▄▄░▒▒▒▒▒▒▒▒▒▒░░░░█░\n░░░░░░░░░░░░░░▀▄▄▄▄▄░░░░░░░░█░░\nUMAD?\n");return 0;}

variable_types: b int

variable_types:
e
char *[]


decompiled_code:
__int64 __fastcall cmd_commit(int a1, __int64 a2)
{
bool v3; // cf
bool v4; // zf
_BYTE *v5; // rsi
_BYTE *v6; // rdi
__int64 v7; // rcx

die_if_not_troll_repo();
v3 = (unsigned int)a1 < 2;
v4 = a1 == 2;
if ( a1 <= 2 )
goto LABEL_6;
v5 = *(_BYTE **)(a2 + 8);
v6 = &unk_56;
v7 = 3LL;
do
{
if ( !v7 )
break;
v3 = *v5 < *v6;
v4 = *v5++ == *v6++;
--v7;
}
while ( v4 );
if ( (!v3 && !v4) == v3 )
commit(*(_QWORD *)(a2 + 16), v5);
else
LABEL_6:
puts("Please run 'troll commit -m \"your commit message here\".");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
bool v3; // cf
bool v4; // zf
_BYTE *v5; // rsi
_BYTE *v6; // rdi
__int64 v7; // rcx

die_if_not_troll_repo();
v3 = (unsigned int)a1 < 2;
v4 = a1 == 2;
if ( a1 <= 2 )
goto LABEL_6;
v5 = *(_BYTE **)(a2 + 8);
v6 = &unk_56;
v7 = 3LL;
do
{
if ( !v7 )
break;
v3 = *v5 < *v6;
v4 = *v5++ == *v6++;
--v7;
}
while ( v4 );
if ( (!v3 && !v4) == v3 )
commit(*(_QWORD *)(a2 + 16), v5);
else
LABEL_6:
puts("Please run 'troll commit -m \"your commit message here\".");
return 0LL;
}

original_code:
int cmd_commit(int argc, const char *argv[]) {
    die_if_not_troll_repo();
    if (argc < 3 || strcmp(argv[1], "-m") != 0) {
        printf("Please run 'troll commit -m \"your commit message here\".\n");
        return 0;
    }
    commit(argv[2]);
    return 0;
}

canonical_original_code:
int cmd_commit(int argc, char *argv[]) {
    die_if_not_troll_repo();
    if (argc < 3 || strcmp(argv[1], "-m") != 0) {
        printf("Please run 'troll commit -m \"your commit message here\".\n");
        return 0;
    }
    commit(argv[2]);
    return 0;
}


decompiled_code:
__int64 __fastcall write_blob(const char *a1)
{
int v1; // er12
__off_t v2; // rbx
char *v3; // rbp
const char *v4; // r13
char *v5; // r12
size_t v6; // rax
char *v7; // r12
int v8; // eax
struct stat v10; // [rsp+0h] [rbp-B8h] BYREF

v1 = open(a1, 0);
fstat(v1, &v10);
v2 = v10.st_size;
v3 = (char *)malloc(v10.st_size + 15);
sprintf(v3, "blob %lu", v2);
LODWORD(v2) = strlen(v3) + 1;
read(v1, &v3[(int)v2], v10.st_size);
LODWORD(v2) = LODWORD(v10.st_size) + v2;
v4 = (const char *)hash_object(v3, (unsigned int)v2);
v5 = (char *)get_repo_troll_dir();
v6 = strlen(v5);
v7 = (char *)realloc(v5, v6 + 49);
strcat(v7, "objects/");
strncat(v7, v4, 0x28uLL);
v8 = open(v7, 577, 420LL);
write(v8, v3, (int)v2);
return add_to_index(v4, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
int v1; // er12
__off_t v2; // rbx
char *v3; // rbp
const char *v4; // r13
char *v5; // r12
size_t v6; // rax
char *v7; // r12
int v8; // eax
struct stat v10; // [rsp+0h] [rbp-B8h] BYREF

v1 = open(a1, 0);
fstat(v1, &v10);
v2 = v10.st_size;
v3 = (char *)malloc(v10.st_size + 15);
sprintf(v3, "blob %lu", v2);
LODWORD(v2) = strlen(v3) + 1;
read(v1, &v3[(int)v2], v10.st_size);
LODWORD(v2) = LODWORD(v10.st_size) + v2;
v4 = (const char *)hash_object(v3, (unsigned int)v2);
v5 = (char *)get_repo_troll_dir();
v6 = strlen(v5);
v7 = (char *)realloc(v5, v6 + 49);
strcat(v7, "objects/");
strncat(v7, v4, 0x28uLL);
v8 = open(v7, 577, 420LL);
write(v8, v3, (int)v2);
return add_to_index(v4, a1);
}

original_code:
void write_blob(char *filename) {
    int fd;
    fd = open(filename, 00);
    struct stat buf;
    fstat(fd, &buf);
    char *data = (char *) malloc((size_t) buf.st_size + 15);
    sprintf(data, "blob %lu", (unsigned long) buf.st_size);
    int left_part_len = strlen(data) + 1;
    read(fd, data + left_part_len, buf.st_size);
    int full_len = left_part_len + buf.st_size;
    char *hash = hash_object(data, full_len);
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 49);
    strcat(path, "objects/");
    strncat(path, hash, 40);
    int objectfd = open(path, 0100 | 01000 | 01, 0644);
    write(objectfd, data, full_len);
    add_to_index(hash, filename);
}

variable_types:
filename
char *

variable_types: fd int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
hash
char *

variable_types: objectfd int


decompiled_code:
__int64 __fastcall cmd_init(int a1, __int64 a2)
{
__int64 v3; // rdi
char *v4; // rbx

v3 = 0LL;
if ( a1 > 1 )
v3 = *(_QWORD *)(a2 + 8);
v4 = (char *)init_troll_dir(v3);
printf("Initialized empty troll repository in %s\n", v4);
free(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
__int64 v3; // rdi
char *v4; // rbx

v3 = 0LL;
if ( a1 > 1 )
v3 = *(_QWORD *)(a2 + 8);
v4 = (char *)init_troll_dir(v3);
printf("Initialized empty troll repository in %s\n", v4);
free(v4);
return 0LL;
}

original_code:
int cmd_init(int argc, const char *argv[]) {
    char *dir = init_troll_dir(argc > 1 ? argv[1] : ((void *)0));
    printf("Initialized empty troll repository in %s\n", dir);
    free(dir);
    return 0;
}

canonical_original_code:
int cmd_init(int argc, char *argv[]) {
    char *dir = init_troll_dir(argc > 1 ? argv[1] : ((void *)0));
    printf("Initialized empty troll repository in %s\n", dir);
    free(dir);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
dir
char *


queueListen

decompiled_code:
void *__fastcall queueListen(void *a1)
{
const char *v1; // rsi
int *v2; // rax
char *v3; // rax
int v5; // [rsp+0h] [rbp-808h] BYREF
int v6; // [rsp+8h] [rbp-800h] BYREF
char v7[46]; // [rsp+Ch] [rbp-7FCh] BYREF
char v8[1998]; // [rsp+3Ah] [rbp-7CEh] BYREF

LABEL_5:
while ( mq_receive((unsigned int)ClientQueue, &v5, 2048LL, 0LL) >= 0 )
{
switch ( v5 )
{
case 3:
safePrintf("info: %s\n", (const char *)&v6);
break;
case 4:
safePrintf("server message: %s\n", (const char *)&v6);
break;
case 5:
v1 = "success";
if ( !v6 )
v1 = "fail";
safePrintf("confirm message (%s): %s\n", v1, v7);
break;
case 8:
safePrintf("private msg from %s: %s\n", (const char *)&v6, v8);
break;
case 9:
safePrintf("channel msg from %s: %s\n", (const char *)&v6, v8);
break;
case 10:
safePrintf("on-line users:\n%s\n", (const char *)&v6);
break;
case 11:
safePrintf("all channels:\n%s\n", (const char *)&v6);
break;
default:
goto LABEL_5;
}
}
v2 = _errno_location();
v3 = strerror(*v2);
safePrintf("error receving from client queue: %s\n", v3);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
const char *v1; // rsi
int *v2; // rax
char *v3; // rax
int v5; // [rsp+0h] [rbp-808h] BYREF
int v6; // [rsp+8h] [rbp-800h] BYREF
char v7[46]; // [rsp+Ch] [rbp-7FCh] BYREF
char v8[1998]; // [rsp+3Ah] [rbp-7CEh] BYREF

LABEL_5:
while ( mq_receive((unsigned int)ClientQueue, &v5, 2048LL, 0LL) >= 0 )
{
switch ( v5 )
{
case 3:
safePrintf("info: %s\n", (const char *)&v6);
break;
case 4:
safePrintf("server message: %s\n", (const char *)&v6);
break;
case 5:
v1 = "success";
if ( !v6 )
v1 = "fail";
safePrintf("confirm message (%s): %s\n", v1, v7);
break;
case 8:
safePrintf("private msg from %s: %s\n", (const char *)&v6, v8);
break;
case 9:
safePrintf("channel msg from %s: %s\n", (const char *)&v6, v8);
break;
case 10:
safePrintf("on-line users:\n%s\n", (const char *)&v6);
break;
case 11:
safePrintf("all channels:\n%s\n", (const char *)&v6);
break;
default:
goto LABEL_5;
}
}
v2 = _errno_location();
v3 = strerror(*v2);
safePrintf("error receving from client queue: %s\n", v3);
return 0LL;
}

original_code:
static void *queueListen(void *arg)
{
    while (1)
    {
        Message message;
        if (mq_receive(ClientQueue, (char *)&message, 2048, ((void *)0)) < 0)
        {
            safePrintf("error receving from client queue: %s\n", strerror((*__errno_location ())));
            return ((void *)0);
        }
        switch (message.type)
        {
            case CONFIRM_MSG:
                safePrintf("confirm message (%s): %s\n",
                           message.data.confmsg.confirmed ? "success" : "fail",
                           message.data.confmsg.text);
                break;
            case SRV_MSG:
                safePrintf("server message: %s\n", message.data.srvmsg.text);
                break;
            case SHOW_USERS:
                safePrintf("on-line users:\n%s\n", message.data.srvmsg.text);
                break;
            case SHOW_CHANNELS:
                safePrintf("all channels:\n%s\n", message.data.srvmsg.text);
                break;
            case INFO_MSG:
                safePrintf("info: %s\n", message.data.srvmsg.text);
                break;
            case SEND_CHANNEL_MSG:
                safePrintf("channel msg from %s: %s\n", message.data.textmsg.name,
                           message.data.textmsg.text);
                break;
            case SEND_USER_MSG:
                safePrintf("private msg from %s: %s\n", message.data.textmsg.name,
                           message.data.textmsg.text);
        }
    }
}

canonical_original_code:
static void *queueListen(void *arg)
{
    while (1)
    {
        struct Message message;
        if (mq_receive(ClientQueue, (char *)&message, 2048, ((void *)0)) < 0)
        {
            safePrintf("error receving from client queue: %s\n", strerror((*__errno_location ())));
            return ((void *)0);
        }
        switch (message.type)
        {
            case CONFIRM_MSG:
                safePrintf("confirm message (%s): %s\n",
                           message.data.confmsg.confirmed ? "success" : "fail",
                           message.data.confmsg.text);
                break;
            case SRV_MSG:
                safePrintf("server message: %s\n", message.data.srvmsg.text);
                break;
            case SHOW_USERS:
                safePrintf("on-line users:\n%s\n", message.data.srvmsg.text);
                break;
            case SHOW_CHANNELS:
                safePrintf("all channels:\n%s\n", message.data.srvmsg.text);
                break;
            case INFO_MSG:
                safePrintf("info: %s\n", message.data.srvmsg.text);
                break;
            case SEND_CHANNEL_MSG:
                safePrintf("channel msg from %s: %s\n", message.data.textmsg.name,
                           message.data.textmsg.text);
                break;
            case SEND_USER_MSG:
                safePrintf("private msg from %s: %s\n", message.data.textmsg.name,
                           message.data.textmsg.text);
        }
    }
}

variable_types:
arg
void *

variable_types: struct Message { enum MessageType { LOGIN_MSG=1, DISCONNECT_MSG=2, INFO_MSG=3, SRV_MSG=4, CONFIRM_MSG=5, JOIN_CHANNEL_MSG=6, LEAVE_CHANNEL_MSG=7, SEND_USER_MSG=8, SEND_CHANNEL_MSG=9, SHOW_USERS=10, SHOW_CHANNELS=11 } type; union { struct LoginMessage { int cid; char name[50]; char queueName[255]; } loginmsg; struct TextMessage { int cid; char name[50]; char text[-1]; } textmsg; struct DisconnectMessage { int cid; } discmsg; struct ServerMessage { int cid; char text[-1]; } srvmsg; struct ConfirmationMessage { int cid; int confirmed; char text[-1]; } confmsg; struct ChannelMessage { int cid; char channel_name[50]; } chmsg; } data; }

return_type: void *

user_defined_types: struct Message { enum MessageType type; union { struct LoginMessage loginmsg; struct TextMessage textmsg; struct DisconnectMessage discmsg; struct ServerMessage srvmsg; struct ConfirmationMessage confmsg; struct ChannelMessage chmsg; } data; }


showUsers

decompiled_code:
void __fastcall showUsers(_DWORD *a1)
{
*a1 = 10;
a1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send show users");
else
safePrintf("successfully sent show users request\n");
}

canonical_decompiled_code:
void __fastcall func1(_DWORD *a1)
{
*a1 = 10;
a1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send show users");
else
safePrintf("successfully sent show users request\n");
}

original_code:
static void showUsers(Message *msgbuf)
{
    msgbuf->type = SHOW_USERS;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send show users");
        return;
    }
    safePrintf("successfully sent show users request\n");
}

canonical_original_code:
static void showUsers(struct Message *msgbuf)
{
    msgbuf->type = SHOW_USERS;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send show users");
        return;
    }
    safePrintf("successfully sent show users request\n");
}

variable_types: struct Message { enum MessageType { LOGIN_MSG=1, DISCONNECT_MSG=2, INFO_MSG=3, SRV_MSG=4, CONFIRM_MSG=5, JOIN_CHANNEL_MSG=6, LEAVE_CHANNEL_MSG=7, SEND_USER_MSG=8, SEND_CHANNEL_MSG=9, SHOW_USERS=10, SHOW_CHANNELS=11 } type; union { struct LoginMessage { int cid; char name[50]; char queueName[255]; } loginmsg; struct TextMessage { int cid; char name[50]; char text[-1]; } textmsg; struct DisconnectMessage { int cid; } discmsg; struct ServerMessage { int cid; char text[-1]; } srvmsg; struct ConfirmationMessage { int cid; int confirmed; char text[-1]; } confmsg; struct ChannelMessage { int cid; char channel_name[50]; } chmsg; } data; } *


showChannels

decompiled_code:
void __fastcall showChannels(_DWORD *a1)
{
*a1 = 11;
a1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send show channels");
else
safePrintf("successfully sent show channels request\n");
}

canonical_decompiled_code:
void __fastcall func2(_DWORD *a1)
{
*a1 = 11;
a1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send show channels");
else
safePrintf("successfully sent show channels request\n");
}

original_code:
static void showChannels(Message *msgbuf)
{
    msgbuf->type = SHOW_CHANNELS;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send show channels");
        return;
    }
    safePrintf("successfully sent show channels request\n");
}

canonical_original_code:
static void showChannels(struct Message *msgbuf)
{
    msgbuf->type = SHOW_CHANNELS;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send show channels");
        return;
    }
    safePrintf("successfully sent show channels request\n");
}

user_defined_types: enum MessageType { LOGIN_MSG=1, DISCONNECT_MSG=2, INFO_MSG=3, SRV_MSG=4, CONFIRM_MSG=5, JOIN_CHANNEL_MSG=6, LEAVE_CHANNEL_MSG=7, SEND_USER_MSG=8, SEND_CHANNEL_MSG=9, SHOW_USERS=10, SHOW_CHANNELS=11 }

user_defined_types: struct LoginMessage { int cid; char name[50]; char queueName[255]; }

user_defined_types: struct TextMessage { int cid; char name[50]; char text[-1]; }

user_defined_types: struct ServerMessage { int cid; char text[-1]; }

user_defined_types: struct ConfirmationMessage { int cid; int confirmed; char text[-1]; }

user_defined_types: struct ChannelMessage { int cid; char channel_name[50]; }


requestInfo

decompiled_code:
void __fastcall requestInfo(_DWORD *a1)
{
*a1 = 3;
a1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send info request");
else
safePrintf("successfully sent info request\n");
}

canonical_decompiled_code:
void __fastcall func3(_DWORD *a1)
{
*a1 = 3;
a1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send info request");
else
safePrintf("successfully sent info request\n");
}

original_code:
static void requestInfo(Message *msgbuf)
{
    msgbuf->type = INFO_MSG;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send info request");
        return;
    }
    safePrintf("successfully sent info request\n");
}

canonical_original_code:
static void requestInfo(struct Message *msgbuf)
{
    msgbuf->type = INFO_MSG;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send info request");
        return;
    }
    safePrintf("successfully sent info request\n");
}


leaveChannel

decompiled_code:
void __fastcall leaveChannel(_DWORD *a1)
{
*a1 = 7;
a1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send leave channel message");
else
puts("leave channel message sent successfully");
}

canonical_decompiled_code:
void __fastcall func4(_DWORD *a1)
{
*a1 = 7;
a1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send leave channel message");
else
puts("leave channel message sent successfully");
}

original_code:
static void leaveChannel(Message *msgbuf)
{
    msgbuf->type = LEAVE_CHANNEL_MSG;
    msgbuf->data.chmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
        perror("send leave channel message");
    else
        printf("leave channel message sent successfully\n");
}

canonical_original_code:
static void leaveChannel(struct Message *msgbuf)
{
    msgbuf->type = LEAVE_CHANNEL_MSG;
    msgbuf->data.chmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
        perror("send leave channel message");
    else
        printf("leave channel message sent successfully\n");
}


showHelp

decompiled_code:
int showHelp()
{
puts("quit, exit");
puts("chmsg <msg> - send msg to channel");
puts("privmsg <user> <msg> - send private msg to <user>");
puts("join <channel>");
puts("leave - leave current channel");
puts("users - show users currently logged in");
puts("channels - show all channels");
puts("info - show additional commands which server can handle");
return puts("help - shows this help");
}

canonical_decompiled_code:
int func5()
{
puts("quit, exit");
puts("chmsg <msg> - send msg to channel");
puts("privmsg <user> <msg> - send private msg to <user>");
puts("join <channel>");
puts("leave - leave current channel");
puts("users - show users currently logged in");
puts("channels - show all channels");
puts("info - show additional commands which server can handle");
return puts("help - shows this help");
}

original_code:
static void showHelp()
{
    printf("quit, exit\n");
    printf("chmsg <msg> - send msg to channel\n");
    printf("privmsg <user> <msg> - send private msg to <user>\n");
    printf("join <channel>\n");
    printf("leave - leave current channel\n");
    printf("users - show users currently logged in\n");
    printf("channels - show all channels\n");
    printf("info - show additional commands which server can handle\n");
    printf("help - shows this help\n");
}


sendChannelMessage

decompiled_code:
void __fastcall sendChannelMessage(__int64 a1, char *a2)
{
char *v2; // rax
const char *v3; // rbp

*(_DWORD *)a1 = 9;
*(_DWORD *)(a1 + 4) = getpid();
v2 = strtok(a2, delim);
if ( v2 )
{
v3 = v2;
if ( strlen(v2) <= 0x7C5 )
{
strcpy((char *)(a1 + 58), v3);
}
else
{
safePrintf("message is too long, cutting...\n");
strncpy((char *)(a1 + 58), v3, 0x7C5uLL);
*(_BYTE *)(a1 + 2047) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send channel message");
else
safePrintf("channel msg sent successfully\n");
}
else
{
safePrintf("no message to send to channel\n");
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, char *a2)
{
char *v2; // rax
const char *v3; // rbp

*(_DWORD *)a1 = 9;
*(_DWORD *)(a1 + 4) = getpid();
v2 = strtok(a2, delim);
if ( v2 )
{
v3 = v2;
if ( strlen(v2) <= 0x7C5 )
{
strcpy((char *)(a1 + 58), v3);
}
else
{
safePrintf("message is too long, cutting...\n");
strncpy((char *)(a1 + 58), v3, 0x7C5uLL);
*(_BYTE *)(a1 + 2047) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send channel message");
else
safePrintf("channel msg sent successfully\n");
}
else
{
safePrintf("no message to send to channel\n");
}
}

original_code:
static void sendChannelMessage(Message *msgbuf, char *msg)
{
    msgbuf->type = SEND_CHANNEL_MSG;
    msgbuf->data.textmsg.cid = getpid();
    char *text = strtok(msg, "\0");
    if (! text)
    {
        safePrintf("no message to send to channel\n");
        return;
    }
    if (strlen(text) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("message is too long, cutting...\n");
        strncpy(msgbuf->data.textmsg.text, text, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.textmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.textmsg.text, text);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send channel message");
        return;
    }
    safePrintf("channel msg sent successfully\n");
}

canonical_original_code:
static void sendChannelMessage(struct Message *msgbuf, char *msg)
{
    msgbuf->type = SEND_CHANNEL_MSG;
    msgbuf->data.textmsg.cid = getpid();
    char *text = strtok(msg, "\0");
    if (! text)
    {
        safePrintf("no message to send to channel\n");
        return;
    }
    if (strlen(text) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("message is too long, cutting...\n");
        strncpy(msgbuf->data.textmsg.text, text, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.textmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.textmsg.text, text);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send channel message");
        return;
    }
    safePrintf("channel msg sent successfully\n");
}

variable_types:
msg
char *

variable_types:
text
char *


sendPrivateMessage

decompiled_code:
void __fastcall sendPrivateMessage(__int64 a1, char *a2)
{
char *v2; // rax
const char *v3; // rbp
char *v4; // rax
const char *v5; // r12

*(_DWORD *)a1 = 8;
*(_DWORD *)(a1 + 4) = getpid();
v2 = strtok(a2, " \t");
if ( v2 )
{
v3 = v2;
v4 = strtok(0LL, delim);
v5 = v4;
if ( v4 )
{
safePrintf("args to sendusr: \"%s\" \"%s\"\n", v3, v4);
strcpy((char *)(a1 + 8), v3);
if ( strlen(v5) <= 0x7C5 )
{
strcpy((char *)(a1 + 58), v5);
}
else
{
safePrintf("message is too long, cutting...\n");
strncpy((char *)(a1 + 58), v5, 0x7C5uLL);
*(_BYTE *)(a1 + 2047) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send private message");
else
safePrintf("private msg sent successfully\n");
}
else
{
safePrintf("no text to user\n");
}
}
else
{
safePrintf("no user name\n");
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, char *a2)
{
char *v2; // rax
const char *v3; // rbp
char *v4; // rax
const char *v5; // r12

*(_DWORD *)a1 = 8;
*(_DWORD *)(a1 + 4) = getpid();
v2 = strtok(a2, " \t");
if ( v2 )
{
v3 = v2;
v4 = strtok(0LL, delim);
v5 = v4;
if ( v4 )
{
safePrintf("args to sendusr: \"%s\" \"%s\"\n", v3, v4);
strcpy((char *)(a1 + 8), v3);
if ( strlen(v5) <= 0x7C5 )
{
strcpy((char *)(a1 + 58), v5);
}
else
{
safePrintf("message is too long, cutting...\n");
strncpy((char *)(a1 + 58), v5, 0x7C5uLL);
*(_BYTE *)(a1 + 2047) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send private message");
else
safePrintf("private msg sent successfully\n");
}
else
{
safePrintf("no text to user\n");
}
}
else
{
safePrintf("no user name\n");
}
}

original_code:
static void sendPrivateMessage(Message *msgbuf, char *msg)
{
    msgbuf->type = SEND_USER_MSG;
    msgbuf->data.textmsg.cid = getpid();
    char *username = strtok(msg, " 	");
    if (! username)
    {
        safePrintf("no user name\n");
        return;
    }
    char *text = strtok(((void *)0), "\0");
    if (! text)
    {
        safePrintf("no text to user\n");
        return;
    }
    safePrintf("args to sendusr: \"%s\" \"%s\"\n", username, text);
    strcpy(msgbuf->data.textmsg.name, username);
    if (strlen(text) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("message is too long, cutting...\n");
        strncpy(msgbuf->data.textmsg.text, text, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.textmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.textmsg.text, text);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send private message");
        return;
    }
    safePrintf("private msg sent successfully\n");
}

canonical_original_code:
static void sendPrivateMessage(struct Message *msgbuf, char *msg)
{
    msgbuf->type = SEND_USER_MSG;
    msgbuf->data.textmsg.cid = getpid();
    char *username = strtok(msg, " 	");
    if (! username)
    {
        safePrintf("no user name\n");
        return;
    }
    char *text = strtok(((void *)0), "\0");
    if (! text)
    {
        safePrintf("no text to user\n");
        return;
    }
    safePrintf("args to sendusr: \"%s\" \"%s\"\n", username, text);
    strcpy(msgbuf->data.textmsg.name, username);
    if (strlen(text) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("message is too long, cutting...\n");
        strncpy(msgbuf->data.textmsg.text, text, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.textmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.textmsg.text, text);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send private message");
        return;
    }
    safePrintf("private msg sent successfully\n");
}

variable_types:
username
char *