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

*(_QWORD *)a2 = u64_unpack();
*(_DWORD *)(a2 + 8) = u32_unpack(a1 + 8);
result = u32_unpack(a1 + 12);
*(_DWORD *)(a2 + 12) = result;
return result;
}

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

*(_QWORD *)a2 = func16();
*(_DWORD *)(a2 + 8) = func14(a1 + 8);
result = func14(a1 + 12);
*(_DWORD *)(a2 + 12) = result;
return result;
}

original_code:
void taia_unpack(const uint8_t *s, struct taia *t)
{
    t->sec = u64_unpack(s);
    t->nano = u32_unpack(s + 8);
    t->atto = u32_unpack(s + 12);
}

canonical_original_code:
void taia_unpack(unsigned char *s, struct taia *t)
{
    t->sec = u64_unpack(s);
    t->nano = u32_unpack(s + 8);
    t->atto = u32_unpack(s + 12);
}

user_defined_types: struct taia { unsigned long sec; unsigned int nano; unsigned int atto; }


repo: neilalexander/sigmavpn

decompiled_code:
__time_t __fastcall taia_now(__int64 a1)
{
int v1; // edx
__time_t result; // rax
struct timespec v3; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v3);
v1 = v3.tv_nsec;
result = v3.tv_sec + 0x400000000000000ALL;
if ( *(_QWORD *)a1 == v3.tv_sec + 0x400000000000000ALL
&& (v1 = v3.tv_nsec, *(_DWORD *)(a1 + 8) == LODWORD(v3.tv_nsec)) )
{
++*(_DWORD *)(a1 + 12);
}
else
{
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 8) = v1;
*(_DWORD *)(a1 + 12) = 0;
}
return result;
}

canonical_decompiled_code:
__time_t __fastcall func19(__int64 a1)
{
int v1; // edx
__time_t result; // rax
struct timespec v3; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v3);
v1 = v3.tv_nsec;
result = v3.tv_sec + 0x400000000000000ALL;
if ( *(_QWORD *)a1 == v3.tv_sec + 0x400000000000000ALL
&& (v1 = v3.tv_nsec, *(_DWORD *)(a1 + 8) == LODWORD(v3.tv_nsec)) )
{
++*(_DWORD *)(a1 + 12);
}
else
{
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 8) = v1;
*(_DWORD *)(a1 + 12) = 0;
}
return result;
}

original_code:
void taia_now(struct taia *t)
{
    struct timespec now;
    clock_gettime(0, &now);
    uint64_t abssec = 4611686018427387914ULL + (uint64_t) now.tv_sec;
    if (t->sec == abssec && t->nano == (uint32_t) now.tv_nsec)
    {
        t->atto++;
    }
    else
    {
        t->sec = abssec;
        t->nano = now.tv_nsec;
        t->atto = 0;
    }
}

canonical_original_code:
void taia_now(struct taia *t)
{
    struct timespec now;
    clock_gettime(0, &now);
    unsigned long abssec = 4611686018427387914ULL + (uint64_t) now.tv_sec;
    if (t->sec == abssec && t->nano == (unsigned int) now.tv_nsec)
    {
        t->atto++;
    }
    else
    {
        t->sec = abssec;
        t->nano = now.tv_nsec;
        t->atto = 0;
    }
}

variable_types: struct taia { unsigned long sec; unsigned int nano; unsigned int atto; } *

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

variable_types:
abssec
unsigned long

return_type: void


loadproto

decompiled_code:
__int64 __fastcall loadproto(const char *a1)
{
void *v1; // rax
__int64 (*v2)(void); // rdx
char *v4; // rax
char v5[168]; // [rsp+0h] [rbp-A8h] BYREF

snprintf(v5, 0x8CuLL, "%s/proto_%s.o", conf, a1);
v1 = dlopen(v5, 2);
if ( !v1 || (v2 = (__int64 (*)(void))dlsym(v1, "proto_descriptor")) == 0LL )
{
v4 = dlerror();
printf("Unable to load protocol %s: %s\n", a1, v4);
exit(-1);
}
return v2();
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
void *v1; // rax
__int64 (*v2)(void); // rdx
char *v4; // rax
char v5[168]; // [rsp+0h] [rbp-A8h] BYREF

snprintf(v5, 0x8CuLL, "%s/proto_%s.o", conf, a1);
v1 = dlopen(v5, 2);
if ( !v1 || (v2 = (__int64 (*)(void))dlsym(v1, "proto_descriptor")) == 0LL )
{
v4 = dlerror();
printf("Unable to load protocol %s: %s\n", a1, v4);
exit(-1);
}
return v2();
}

original_code:
sigma_proto* loadproto(char* protoname)
{
    char path[140];
    snprintf(path, sizeof(path), "%s/proto_%s.o", conf->modulepath, protoname);
    void* proto_lib = dlopen(path, 0x00002);
    if (!proto_lib)
    {
        printf("Unable to load protocol %s: %s\n", protoname, dlerror());
        exit(-1);
    }
    void* init = dlsym(proto_lib, "proto_descriptor");
    if (!init)
    {
        printf("Unable to load protocol %s: %s\n", protoname, dlerror());
        exit(-1);
    }
    sigma_proto* proto = ((sigma_proto* (*)()) init)();
    return proto;
}

canonical_original_code:
struct sigma_proto *loadproto(char *protoname)
{
    char path[140];
    snprintf(path, sizeof(path), "%s/proto_%s.o", conf->modulepath, protoname);
    void *proto_lib = dlopen(path, 0x00002);
    if (!proto_lib)
    {
        printf("Unable to load protocol %s: %s\n", protoname, dlerror());
        exit(-1);
    }
    void *init = dlsym(proto_lib, "proto_descriptor");
    if (!init)
    {
        printf("Unable to load protocol %s: %s\n", protoname, dlerror());
        exit(-1);
    }
    struct sigma_proto *proto = ((sigma_proto* (*)()) init)();
    return proto;
}

variable_types:
protoname
char *

variable_types:
path
char [140]

variable_types:
init
void *

variable_types: struct sigma_proto { _Bool encrypted; _Bool stateful; int state; int (*init)(); int (*set)(); long (*encode)(); long (*decode)(); int (*reload)(); } *


loadinterface

decompiled_code:
__int64 __fastcall loadinterface(const char *a1)
{
void *v1; // rax
__int64 (*v2)(void); // rdx
char *v4; // rax
char v5[168]; // [rsp+0h] [rbp-A8h] BYREF

snprintf(v5, 0x8CuLL, "%s/intf_%s.o", conf, a1);
v1 = dlopen(v5, 2);
if ( !v1 || (v2 = (__int64 (*)(void))dlsym(v1, "intf_descriptor")) == 0LL )
{
v4 = dlerror();
printf("Unable to load interface %s: %s\n", a1, v4);
exit(-1);
}
return v2();
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
void *v1; // rax
__int64 (*v2)(void); // rdx
char *v4; // rax
char v5[168]; // [rsp+0h] [rbp-A8h] BYREF

snprintf(v5, 0x8CuLL, "%s/intf_%s.o", conf, a1);
v1 = dlopen(v5, 2);
if ( !v1 || (v2 = (__int64 (*)(void))dlsym(v1, "intf_descriptor")) == 0LL )
{
v4 = dlerror();
printf("Unable to load interface %s: %s\n", a1, v4);
exit(-1);
}
return v2();
}

original_code:
sigma_intf* loadinterface(char* intfname)
{
    char path[140];
    snprintf(path, sizeof(path), "%s/intf_%s.o", conf->modulepath, intfname);
    void* intf_lib = dlopen(path, 0x00002);
    if (!intf_lib)
    {
        printf("Unable to load interface %s: %s\n", intfname, dlerror());
        exit(-1);
    }
    void* init = dlsym(intf_lib, "intf_descriptor");
    if (!init)
    {
        printf("Unable to load interface %s: %s\n", intfname, dlerror());
        exit(-1);
    }
    sigma_intf* intf = ((sigma_intf* (*)()) init)();
    return intf;
}

canonical_original_code:
struct sigma_intf *loadinterface(char *intfname)
{
    char path[140];
    snprintf(path, sizeof(path), "%s/intf_%s.o", conf->modulepath, intfname);
    void *intf_lib = dlopen(path, 0x00002);
    if (!intf_lib)
    {
        printf("Unable to load interface %s: %s\n", intfname, dlerror());
        exit(-1);
    }
    void *init = dlsym(intf_lib, "intf_descriptor");
    if (!init)
    {
        printf("Unable to load interface %s: %s\n", intfname, dlerror());
        exit(-1);
    }
    struct sigma_intf *intf = ((sigma_intf* (*)()) init)();
    return intf;
}

variable_types:
intfname
char *

variable_types: struct sigma_intf { int state; int (*init)(); int (*set)(); long (*read)(); long (*write)(); void (*updateremote)(); int (*reload)(); int filedesc; } *


rstrip

decompiled_code:
const char *__fastcall rstrip(const char *a1)
{
size_t v1; // rax
const char *v2; // rbx
const unsigned __int16 **v3; // rcx
__int64 v4; // rdx

v1 = strlen(a1);
v2 = &a1[v1];
if ( a1 < &a1[v1] )
{
v3 = _ctype_b_loc();
do
{
v4 = *--v2;
if ( ((*v3)[v4] & 0x2000) == 0 )
break;
*v2 = 0;
}
while ( a1 != v2 );
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
size_t v1; // rax
const char *v2; // rbx
const unsigned __int16 **v3; // rcx
__int64 v4; // rdx

v1 = strlen(a1);
v2 = &a1[v1];
if ( a1 < &a1[v1] )
{
v3 = _ctype_b_loc();
do
{
v4 = *--v2;
if ( ((*v3)[v4] & 0x2000) == 0 )
break;
*v2 = 0;
}
while ( a1 != v2 );
}
return a1;
}

original_code:
static char* rstrip(char* s)
{
    char* p = s + strlen(s);
    while (p > s && ((*__ctype_b_loc ())[(int) ((*--p))] & (unsigned short int) _ISspace))
        *p = '\0';
    return s;
}

canonical_original_code:
static char *rstrip(char *s)
{
    char *p = s + strlen(s);
    while (p > s && ((*__ctype_b_loc ())[(int) ((*--p))] & (unsigned short) _ISspace))
        *p = '\0';
    return s;
}

variable_types:
s
char *

variable_types:
p
char *

return_type: char *


repo: neilstockbridge/dsoquad-demo

decompiled_code:
__int64 advance_cursor()
{
__int64 result; // rax

if ( (unsigned __int16)cursor_y < (unsigned __int16)block_top )
return (unsigned int)(unsigned __int16)cursor_y++ + 1;
cursor_y = block_bottom;
if ( (unsigned __int16)cursor_x < (unsigned __int16)block_right )
return (unsigned int)(unsigned __int16)cursor_x++ + 1;
result = (unsigned __int16)block_left;
cursor_x = block_left;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

if ( (unsigned __int16)cursor_y < (unsigned __int16)block_top )
return (unsigned int)(unsigned __int16)cursor_y++ + 1;
cursor_y = block_bottom;
if ( (unsigned __int16)cursor_x < (unsigned __int16)block_right )
return (unsigned int)(unsigned __int16)cursor_x++ + 1;
result = (unsigned __int16)block_left;
cursor_x = block_left;
return result;
}

original_code:
void static advance_cursor()
{
  if ( cursor_y < block_top)
    cursor_y += 1;
  else {
    cursor_y = block_bottom;
    if ( cursor_x < block_right)
      cursor_x += 1;
    else
      cursor_x = block_left;
  }
}

canonical_original_code:
static void advance_cursor()
{
  if ( cursor_y < block_top)
    cursor_y += 1;
  else {
    cursor_y = block_bottom;
    if ( cursor_x < block_right)
      cursor_x += 1;
    else
      cursor_x = block_left;
  }
}


decompiled_code:
__int64 __fastcall emu_key(int a1)
{
__int64 v1; // rax
int i; // edx

v1 = 0LL;
for ( i = 49; i != a1; i = key_map[2 * v1] )
{
if ( ++v1 == 10 )
return 0LL;
}
return (unsigned __int16)word_704[4 * (int)v1];
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rax
int i; // edx

v1 = 0LL;
for ( i = 49; i != a1; i = key_map[2 * v1] )
{
if ( ++v1 == 10 )
return 0LL;
}
return (unsigned __int16)word_704[4 * (int)v1];
}

original_code:
u16 static emu_key( SDLKey sdl_key)
{
  int i;
  for ( i = 0; i < ( sizeof(key_map) / sizeof(key_map[0]) ); i += 1)
  {
    KeyMapping *mp = &key_map[ i];
    if ( mp->sdl_key == sdl_key)
      return mp->emu_key;
  }
  return 0;
}

canonical_original_code:
static unsigned short emu_key(enum SDLKey sdl_key)
{
  int i;
  for ( i = 0; i < ( sizeof(key_map) / sizeof(key_map[0]) ); i += 1)
  {
    struct KeyMapping *mp = &key_map[ i];
    if ( mp->sdl_key == sdl_key)
      return mp->emu_key;
  }
  return 0;
}

variable_types: i int

variable_types: struct KeyMapping { enum SDLKey { SDLK_UNKNOWN=0, SDLK_FIRST=0, SDLK_BACKSPACE=8, SDLK_TAB=9, SDLK_CLEAR=12, SDLK_RETURN=13, SDLK_PAUSE=19, SDLK_ESCAPE=27, SDLK_SPACE=32, SDLK_EXCLAIM=33, SDLK_QUOTEDBL=34, SDLK_HASH=35, SDLK_DOLLAR=36, SDLK_AMPERSAND=38, SDLK_QUOTE=39, SDLK_LEFTPAREN=40, SDLK_RIGHTPAREN=41, SDLK_ASTERISK=42, SDLK_PLUS=43, SDLK_COMMA=44, SDLK_MINUS=45, SDLK_PERIOD=46, SDLK_SLASH=47, SDLK_0=48, SDLK_1=49, SDLK_2=50, SDLK_3=51, SDLK_4=52, SDLK_5=53, SDLK_6=54, SDLK_7=55, SDLK_8=56, SDLK_9=57, SDLK_COLON=58, SDLK_SEMICOLON=59, SDLK_LESS=60, SDLK_EQUALS=61, SDLK_GREATER=62, SDLK_QUESTION=63, SDLK_AT=64, SDLK_LEFTBRACKET=91, SDLK_BACKSLASH=92, SDLK_RIGHTBRACKET=93, SDLK_CARET=94, SDLK_UNDERSCORE=95, SDLK_BACKQUOTE=96, SDLK_a=97, SDLK_b=98, SDLK_c=99, SDLK_d=100, SDLK_e=101, SDLK_f=102, SDLK_g=103, SDLK_h=104, SDLK_i=105, SDLK_j=106, SDLK_k=107, SDLK_l=108, SDLK_m=109, SDLK_n=110, SDLK_o=111, SDLK_p=112, SDLK_q=113, SDLK_r=114, SDLK_s=115, SDLK_t=116, SDLK_u=117, SDLK_v=118, SDLK_w=119, SDLK_x=120, SDLK_y=121, SDLK_z=122, SDLK_DELETE=127, SDLK_WORLD_0=160, SDLK_WORLD_1=161, SDLK_WORLD_2=162, SDLK_WORLD_3=163, SDLK_WORLD_4=164, SDLK_WORLD_5=165, SDLK_WORLD_6=166, SDLK_WORLD_7=167, SDLK_WORLD_8=168, SDLK_WORLD_9=169, SDLK_WORLD_10=170, SDLK_WORLD_11=171, SDLK_WORLD_12=172, SDLK_WORLD_13=173, SDLK_WORLD_14=174, SDLK_WORLD_15=175, SDLK_WORLD_16=176, SDLK_WORLD_17=177, SDLK_WORLD_18=178, SDLK_WORLD_19=179, SDLK_WORLD_20=180, SDLK_WORLD_21=181, SDLK_WORLD_22=182, SDLK_WORLD_23=183, SDLK_WORLD_24=184, SDLK_WORLD_25=185, SDLK_WORLD_26=186, SDLK_WORLD_27=187, SDLK_WORLD_28=188, SDLK_WORLD_29=189, SDLK_WORLD_30=190, SDLK_WORLD_31=191, SDLK_WORLD_32=192, SDLK_WORLD_33=193, SDLK_WORLD_34=194, SDLK_WORLD_35=195, SDLK_WORLD_36=196, SDLK_WORLD_37=197, SDLK_WORLD_38=198, SDLK_WORLD_39=199, SDLK_WORLD_40=200, SDLK_WORLD_41=201, SDLK_WORLD_42=202, SDLK_WORLD_43=203, SDLK_WORLD_44=204, SDLK_WORLD_45=205, SDLK_WORLD_46=206, SDLK_WORLD_47=207, SDLK_WORLD_48=208, SDLK_WORLD_49=209, SDLK_WORLD_50=210, SDLK_WORLD_51=211, SDLK_WORLD_52=212, SDLK_WORLD_53=213, SDLK_WORLD_54=214, SDLK_WORLD_55=215, SDLK_WORLD_56=216, SDLK_WORLD_57=217, SDLK_WORLD_58=218, SDLK_WORLD_59=219, SDLK_WORLD_60=220, SDLK_WORLD_61=221, SDLK_WORLD_62=222, SDLK_WORLD_63=223, SDLK_WORLD_64=224, SDLK_WORLD_65=225, SDLK_WORLD_66=226, SDLK_WORLD_67=227, SDLK_WORLD_68=228, SDLK_WORLD_69=229, SDLK_WORLD_70=230, SDLK_WORLD_71=231, SDLK_WORLD_72=232, SDLK_WORLD_73=233, SDLK_WORLD_74=234, SDLK_WORLD_75=235, SDLK_WORLD_76=236, SDLK_WORLD_77=237, SDLK_WORLD_78=238, SDLK_WORLD_79=239, SDLK_WORLD_80=240, SDLK_WORLD_81=241, SDLK_WORLD_82=242, SDLK_WORLD_83=243, SDLK_WORLD_84=244, SDLK_WORLD_85=245, SDLK_WORLD_86=246, SDLK_WORLD_87=247, SDLK_WORLD_88=248, SDLK_WORLD_89=249, SDLK_WORLD_90=250, SDLK_WORLD_91=251, SDLK_WORLD_92=252, SDLK_WORLD_93=253, SDLK_WORLD_94=254, SDLK_WORLD_95=255, SDLK_KP0=256, SDLK_KP1=257, SDLK_KP2=258, SDLK_KP3=259, SDLK_KP4=260, SDLK_KP5=261, SDLK_KP6=262, SDLK_KP7=263, SDLK_KP8=264, SDLK_KP9=265, SDLK_KP_PERIOD=266, SDLK_KP_DIVIDE=267, SDLK_KP_MULTIPLY=268, SDLK_KP_MINUS=269, SDLK_KP_PLUS=270, SDLK_KP_ENTER=271, SDLK_KP_EQUALS=272, SDLK_UP=273, SDLK_DOWN=274, SDLK_RIGHT=275, SDLK_LEFT=276, SDLK_INSERT=277, SDLK_HOME=278, SDLK_END=279, SDLK_PAGEUP=280, SDLK_PAGEDOWN=281, SDLK_F1=282, SDLK_F2=283, SDLK_F3=284, SDLK_F4=285, SDLK_F5=286, SDLK_F6=287, SDLK_F7=288, SDLK_F8=289, SDLK_F9=290, SDLK_F10=291, SDLK_F11=292, SDLK_F12=293, SDLK_F13=294, SDLK_F14=295, SDLK_F15=296, SDLK_NUMLOCK=300, SDLK_CAPSLOCK=301, SDLK_SCROLLOCK=302, SDLK_RSHIFT=303, SDLK_LSHIFT=304, SDLK_RCTRL=305, SDLK_LCTRL=306, SDLK_RALT=307, SDLK_LALT=308, SDLK_RMETA=309, SDLK_LMETA=310, SDLK_LSUPER=311, SDLK_RSUPER=312, SDLK_MODE=313, SDLK_COMPOSE=314, SDLK_HELP=315, SDLK_PRINT=316, SDLK_SYSREQ=317, SDLK_BREAK=318, SDLK_MENU=319, SDLK_POWER=320, SDLK_EURO=321, SDLK_UNDO=322, SDLK_LAST=323 } sdl_key; unsigned short emu_key; } *

return_type: unsigned short

user_defined_types: struct KeyMapping { enum SDLKey sdl_key; unsigned short emu_key; }


decompiled_code:
void *__fastcall counter3_thread_main(void *a1)
{
int v1; // ebx

puts("Starting");
LABEL_2:
v1 = 10;
while ( counter3_thread_should_run )
{
usleep(0x3E8u);
TIM3_IRQHandler();
if ( !--v1 )
{
SDL_Flip(screen);
goto LABEL_2;
}
}
puts("Stopping");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
int v1; // ebx

puts("Starting");
LABEL_2:
v1 = 10;
while ( counter3_thread_should_run )
{
usleep(0x3E8u);
TIM3_IRQHandler();
if ( !--v1 )
{
SDL_Flip(screen);
goto LABEL_2;
}
}
puts("Stopping");
return 0LL;
}

original_code:
void *counter3_thread_main( void *arg)
{
  printf("Starting\n");
  int time_to_flip = 10;
  while( counter3_thread_should_run)
  {
    usleep( 1000);
    TIM3_IRQHandler();
    time_to_flip -= 1;
    if ( 0 == time_to_flip)
    {
      SDL_Flip( screen);
      time_to_flip = 10;
    }
  }
  printf("Stopping\n");
  return ((void *)0);
}

canonical_original_code:
void *counter3_thread_main(void *arg)
{
  printf("Starting\n");
  int time_to_flip = 10;
  while( counter3_thread_should_run)
  {
    usleep( 1000);
    TIM3_IRQHandler();
    time_to_flip -= 1;
    if ( 0 == time_to_flip)
    {
      SDL_Flip( screen);
      time_to_flip = 10;
    }
  }
  printf("Stopping\n");
  return ((void *)0);
}

variable_types:
arg
void *

return_type: void *


shutdown

decompiled_code:
void shutdown(void)
{
if ( pthread_self() != counter3_thread )
{
counter3_thread_should_run = 0;
puts("Waiting");
usleep(0x7D0u);
if ( pthread_join(counter3_thread, 0LL) )
{
fwrite("Could not join thread\n", 1uLL, 0x16uLL, stderr);
pthread_cancel(counter3_thread);
}
}
puts("Quitting");
SDL_Quit();
}

canonical_decompiled_code:
void func4(void)
{
if ( pthread_self() != counter3_thread )
{
counter3_thread_should_run = 0;
puts("Waiting");
usleep(0x7D0u);
if ( pthread_join(counter3_thread, 0LL) )
{
fwrite("Could not join thread\n", 1uLL, 0x16uLL, stderr);
pthread_cancel(counter3_thread);
}
}
puts("Quitting");
SDL_Quit();
}

original_code:
void static shutdown()
{
  if ( pthread_self() != counter3_thread)
  {
    counter3_thread_should_run = 0;
    printf("Waiting\n");
    usleep( 2000);
    if ( pthread_join( counter3_thread, ((void *)0)) )
    {
      fprintf( stderr, "Could not join thread\n");
      pthread_cancel( counter3_thread);
    }
  }
  printf("Quitting\n");
  SDL_Quit();
}

canonical_original_code:
static void shutdown()
{
  if ( pthread_self() != counter3_thread)
  {
    counter3_thread_should_run = 0;
    printf("Waiting\n");
    usleep( 2000);
    if ( pthread_join( counter3_thread, ((void *)0)) )
    {
      fprintf( stderr, "Could not join thread\n");
      pthread_cancel( counter3_thread);
    }
  }
  printf("Quitting\n");
  SDL_Quit();
}


decompiled_code:
void __fastcall __noreturn SDL_die(const char *a1)
{
const char *v1; // rax

v1 = (const char *)SDL_GetError();
fprintf(stderr, "%s: %s\n", a1, v1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(const char *a1)
{
const char *v1; // rax

v1 = (const char *)SDL_GetError();
fprintf(stderr, "%s: %s\n", a1, v1);
exit(1);
}

original_code:
void SDL_die( char *message)
{
  fprintf( stderr, "%s: %s\n", message, SDL_GetError() );
  exit( 1);
}

canonical_original_code:
void SDL_die(char *message)
{
  fprintf( stderr, "%s: %s\n", message, SDL_GetError() );
  exit( 1);
}

variable_types:
message
char *


initialize

decompiled_code:
__int64 initialize()
{
__int64 v0; // rax
__int64 result; // rax

if ( (int)SDL_Init(32LL) < 0 )
SDL_die("Unable to init SDL");
atexit(shutdown);
screen = SDL_SetVideoMode(400LL, 240LL, 16LL, 0LL);
if ( !screen )
SDL_die("Unable to set video mode");
SDL_ShowCursor(0LL);
counter3_thread_should_run = 1;
if ( pthread_create(&counter3_thread, 0LL, counter3_thread_main, 0LL) )
SDL_die("Unable to create thread");
v0 = SDL_RWFromFile("BIOS-glyphs.bmp", "rb");
result = SDL_LoadBMP_RW(v0, 1LL);
glyph_sheet = result;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rax
__int64 result; // rax

if ( (int)SDL_Init(32LL) < 0 )
func5("Unable to init SDL");
atexit(shutdown);
screen = SDL_SetVideoMode(400LL, 240LL, 16LL, 0LL);
if ( !screen )
func5("Unable to set video mode");
SDL_ShowCursor(0LL);
counter3_thread_should_run = 1;
if ( pthread_create(&counter3_thread, 0LL, counter3_thread_main, 0LL) )
func5("Unable to create thread");
v0 = SDL_RWFromFile("BIOS-glyphs.bmp", "rb");
result = SDL_LoadBMP_RW(v0, 1LL);
glyph_sheet = result;
return result;
}

original_code:
void static initialize()
{
  if ( SDL_Init( 0x00000020) < 0 ) SDL_die("Unable to init SDL");
  atexit( shutdown);
  screen = SDL_SetVideoMode( 400, 240, 16, 0x00000000);
  if ( ((void *)0) == screen) SDL_die("Unable to set video mode");
  SDL_ShowCursor( SDL_FALSE);
  counter3_thread_should_run = 1;
  if ( pthread_create( &counter3_thread, ((void *)0), counter3_thread_main, ((void *)0)) )
    SDL_die("Unable to create thread");
  glyph_sheet = SDL_LoadBMP_RW(SDL_RWFromFile("BIOS-glyphs.bmp", "rb"), 1);
}

canonical_original_code:
static void initialize()
{
  if ( SDL_Init( 0x00000020) < 0 ) SDL_die("Unable to init SDL");
  atexit( shutdown);
  screen = SDL_SetVideoMode( 400, 240, 16, 0x00000000);
  if ( ((void *)0) == screen) SDL_die("Unable to set video mode");
  SDL_ShowCursor( SDL_FALSE);
  counter3_thread_should_run = 1;
  if ( pthread_create( &counter3_thread, ((void *)0), counter3_thread_main, ((void *)0)) )
    SDL_die("Unable to create thread");
  glyph_sheet = SDL_LoadBMP_RW(SDL_RWFromFile("BIOS-glyphs.bmp", "rb"), 1);
}


decompiled_code:
__int64 ensure_initialized()
{
__int64 result; // rax

if ( !initialized_0 )
{
result = initialize();
initialized_0 = 1;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax

if ( !initialized_0 )
{
result = func6();
initialized_0 = 1;
}
return result;
}

original_code:
void static ensure_initialized()
{
  _Bool static initialized = 0;
  if ( ! initialized)
  {
    initialize();
    initialized = 1;
  }
}

canonical_original_code:
static void ensure_initialized()
{
  static _Bool initialized = 0;
  if ( ! initialized)
  {
    initialize();
    initialized = 1;
  }
}


decompiled_code:
__int64 __fastcall set_pixel(__int16 a1, __int16 a2, unsigned __int16 a3)
{
__int64 v3; // r12
__int64 v4; // rbx
__int16 v5; // r8
__int64 result; // rax

v3 = *(_QWORD *)(screen + 32);
v4 = *(unsigned __int16 *)(screen + 24) * (*(_DWORD *)(screen + 20) - 1 - a2);
v5 = SDL_MapRGB(
*(_QWORD *)(screen + 8),
(unsigned __int8)(8 * a3),
(unsigned __int8)(4 * (a3 >> 5)),
8 * (unsigned int)(a3 >> 11));
result = v3 + 2LL * a1;
*(_WORD *)(result + v4) = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int16 a1, __int16 a2, unsigned __int16 a3)
{
__int64 v3; // r12
__int64 v4; // rbx
__int16 v5; // r8
__int64 result; // rax

v3 = *(_QWORD *)(screen + 32);
v4 = *(unsigned __int16 *)(screen + 24) * (*(_DWORD *)(screen + 20) - 1 - a2);
v5 = SDL_MapRGB(
*(_QWORD *)(screen + 8),
(unsigned __int8)(8 * a3),
(unsigned __int8)(4 * (a3 >> 5)),
8 * (unsigned int)(a3 >> 11));
result = v3 + 2LL * a1;
*(_WORD *)(result + v4) = v5;
return result;
}

original_code:
void set_pixel( Sint16 x, Sint16 y, Uint16 color)
{
  Uint16 *pixel_row = (Uint16 *) ( screen->pixels + screen->pitch * (screen->h - 1 - y) );
  Uint16 cl = SDL_MapRGB( screen->format, ( (color >> 0 & 0x1f) << 3 ), ( (color >> 5 & 0x3f) << 2 ), ( (color >> 11 & 0x1f) << 3 ));
  pixel_row[ x] = cl;
}

canonical_original_code:
void set_pixel(short x, short y, unsigned short color)
{
  unsigned short *pixel_row = (Uint16 *) ( screen->pixels + screen->pitch * (screen->h - 1 - y) );
  unsigned short cl = SDL_MapRGB( screen->format, ( (color >> 0 & 0x1f) << 3 ), ( (color >> 5 & 0x3f) << 2 ), ( (color >> 11 & 0x1f) << 3 ));
  pixel_row[ x] = cl;
}

variable_types: x short

variable_types: y short

variable_types:
color
unsigned short

variable_types:
cl
unsigned short


outcolor

repo: neingeist/i-mandelbrot-fractals

decompiled_code:
__int64 outcolor()
{
return 0xFFFFFFLL;
}

canonical_decompiled_code:
__int64 func7()
{
return 0xFFFFFFLL;
}

original_code:
Uint32 outcolor(int it) {
  return 0x00ffffff;
}

canonical_original_code:
unsigned int outcolor(int it) {
  return 0x00ffffff;
}

variable_types: it int

return_type: unsigned int


incolor

decompiled_code:
__int64 incolor()
{
return 267386880LL;
}

original_code:
Uint32 incolor() {
  return 0x00ff00000;
}

canonical_original_code:
unsigned int incolor() {
  return 0x00ff00000;
}


repo: neleai/stylepp

decompiled_code:
void __fastcall test_indent_off(char *src)
{
char v1[1008]; // [rsp+0h] [rbp-7E8h] BYREF
char dest[1016]; // [rsp+3F0h] [rbp-3F8h] BYREF

if ( src )
{
strcpy(v1, src);
while ( strchr(v1, 47) && v1[0] && v1[1] )
{
dirname(v1);
strcpy(stpcpy(dest, v1), "/.indent.off");
if ( fopen(dest, "r") )
exit(1);
}
}
}

canonical_decompiled_code:
void __fastcall func7(char *src)
{
char v1[1008]; // [rsp+0h] [rbp-7E8h] BYREF
char dest[1016]; // [rsp+3F0h] [rbp-3F8h] BYREF

if ( src )
{
strcpy(v1, src);
while ( strchr(v1, 47) && v1[0] && v1[1] )
{
dirname(v1);
strcpy(stpcpy(dest, v1), "/.indent.off");
if ( fopen(dest, "r") )
exit(1);
}
}
}

original_code:
void
test_indent_off (char *arg)
{
  if (!arg)
    return;
  char strbuf[1000]; strcpy (strbuf, arg);
  char strbuf2[1000];
  while (strchr (strbuf, '/') && strbuf[0] && strbuf[1])
    {
      dirname (strbuf);
      strcpy (strbuf2, strbuf);
      strcat (strbuf2, "/.indent.off");
      if (fopen (strbuf2, "r"))
 exit (1);
    }
}

canonical_original_code:
void test_indent_off(char *arg)
{
  if (!arg)
    return;
  char strbuf[1000]; strcpy (strbuf, arg);
  char strbuf2[1000];
  while (strchr (strbuf, '/') && strbuf[0] && strbuf[1])
    {
      dirname (strbuf);
      strcpy (strbuf2, strbuf);
      strcat (strbuf2, "/.indent.off");
      if (fopen (strbuf2, "r"))
 exit (1);
    }
}

variable_types:
arg
char *

variable_types:
strbuf
char [1000]


decompiled_code:
__int64 __fastcall write_if_common(const void *a1, __int64 a2, const char *a3, __int64 a4)
{
size_t v4; // rsi
int v6; // er8
__int64 result; // rax

v4 = a2 - (_QWORD)a1;
if ( v4 != a4 - (_QWORD)a3 || (v6 = memcmp(a1, a3, v4), result = 1LL, v6) )
{
printf("%s", a3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const void *a1, __int64 a2, const char *a3, __int64 a4)
{
size_t v4; // rsi
int v6; // er8
__int64 result; // rax

v4 = a2 - (_QWORD)a1;
if ( v4 != a4 - (_QWORD)a3 || (v6 = memcmp(a1, a3, v4), result = 1LL, v6) )
{
printf("%s", a3);
result = 0LL;
}
return result;
}

original_code:
int
write_if_common (char *input, char *ip, char *output, char *op)
{
  if ((ip - input == op - output) && !memcmp (input, output, ip - input))
    return (1);
  else
    {
      printf ("%s", output);
      return (0);
    }
}

canonical_original_code:
int write_if_common(char *input, char *ip, char *output, char *op)
{
  if ((ip - input == op - output) && !memcmp (input, output, ip - input))
    return (1);
  else
    {
      printf ("%s", output);
      return (0);
    }
}

variable_types:
input
char *

variable_types:
ip
char *

variable_types:
output
char *

variable_types:
op
char *

return_type: int


isword

decompiled_code:
__int64 __fastcall isword(char a1)
{
const unsigned __int16 *v1; // rdx
__int64 result; // rax

v1 = *__ctype_b_loc();
result = 1LL;
if ( (v1[a1] & 0x400) == 0 )
result = (a1 == 45) | (unsigned __int8)(a1 == 39);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1)
{
const unsigned __int16 *v1; // rdx
__int64 result; // rax

v1 = *__ctype_b_loc();
result = 1LL;
if ( (v1[a1] & 0x400) == 0 )
result = (a1 == 45) | (unsigned __int8)(a1 == 39);
return result;
}

original_code:
int
isword (char c)
{
  return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha) || c == '\'' || c == '-';
}

canonical_original_code:
int isword(char c)
{
  return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha) || c == '\'' || c == '-';
}

variable_types: c char


isseparator

decompiled_code:
__int64 __fastcall isseparator(char *a1)
{
const unsigned __int16 **v1; // rax
__int64 v2; // rsi
const unsigned __int16 *v3; // rcx
__int64 result; // rax

v1 = __ctype_b_loc();
v2 = *a1;
v3 = *v1;
result = 1LL;
if ( (v3[v2] & 0x2000) == 0 )
{
if ( (v2 & 0xFD) == 44 || (result = 0LL, (_BYTE)v2 == 59) )
result = (v3[a1[1]] >> 13) & 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1)
{
const unsigned __int16 **v1; // rax
__int64 v2; // rsi
const unsigned __int16 *v3; // rcx
__int64 result; // rax

v1 = __ctype_b_loc();
v2 = *a1;
v3 = *v1;
result = 1LL;
if ( (v3[v2] & 0x2000) == 0 )
{
if ( (v2 & 0xFD) == 44 || (result = 0LL, (_BYTE)v2 == 59) )
result = (v3[a1[1]] >> 13) & 1;
}
return result;
}

original_code:
int
isseparator (char *c)
{
  return ((*__ctype_b_loc ())[(int) ((c[0]))] & (unsigned short int) _ISspace) || ((c[0] == '.' || c[0] == ',' || c[0] == ';') && ((*__ctype_b_loc ())[(int) ((c[1]))] & (unsigned short int) _ISspace));
}

canonical_original_code:
int isseparator(char *c)
{
  return ((*__ctype_b_loc ())[(int) ((c[0]))] & (unsigned short) _ISspace) || ((c[0] == '.' || c[0] == ',' || c[0] == ';') && ((*__ctype_b_loc ())[(int) ((c[1]))] & (unsigned short) _ISspace));
}

variable_types:
c
char *


word

decompiled_code:
char *__fastcall word(__int64 a1)
{
__int64 i; // rbx
char v2; // bp

for ( i = 0LL; ; ++i )
{
v2 = *(_BYTE *)(a1 + i);
if ( !(unsigned int)isword(v2) )
break;
word[i] = v2;
}
word[(int)i] = 0;
return word;
}

canonical_decompiled_code:
char *__fastcall func11(__int64 a1)
{
__int64 i; // rbx
char v2; // bp

for ( i = 0LL; ; ++i )
{
v2 = *(_BYTE *)(a1 + i);
if ( !(unsigned int)func9(v2) )
break;
word[i] = v2;
}
word[(int)i] = 0;
return word;
}

original_code:
char *
word (char *c)
{
  int i;
  for (i = 0; isword (c[i]); i++)
    _word[i] = c[i];
  _word[i] = '\0';
  return _word;
}

canonical_original_code:
char *word(char *c)
{
  int i;
  for (i = 0; isword (c[i]); i++)
    _word[i] = c[i];
  _word[i] = '\0';
  return _word;
}

variable_types: i int


hash

decompiled_code:
__int64 __fastcall hash(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

v1 = (char)*a1;
for ( result = 0LL; *a1; v1 = (char)*a1 )
{
++a1;
result = (unsigned int)(v1 + 11 * result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

v1 = (char)*a1;
for ( result = 0LL; *a1; v1 = (char)*a1 )
{
++a1;
result = (unsigned int)(v1 + 11 * result);
}
return result;
}

original_code:
unsigned int
hash (char *s)
{
  int collect = 0;
  while (*s)
    {
      collect = 11 * collect + *s;
      s++;
    }
  return collect;
}

canonical_original_code:
unsigned int hash(char *s)
{
  int collect = 0;
  while (*s)
    {
      collect = 11 * collect + *s;
      s++;
    }
  return collect;
}

variable_types:
s
char *

variable_types: collect int


decompiled_code:
int __fastcall add_word(char *s1, int a2)
{
unsigned int v2; // eax
__int64 v3; // r12
signed int v4; // eax
__int64 v5; // rbx
int result; // eax
__int64 v7; // rax

v2 = hash(s1);
v3 = names;
v4 = v2 % 0xF4240;
LABEL_2:
v5 = v4;
while ( 1 )
{
v7 = code_words[v5];
if ( !(_DWORD)v7 )
break;
result = strcmp(s1, *(const char **)(v3 + 8 * v7));
if ( !result )
return result;
++v5;
v4 = 0;
if ( (_DWORD)v5 == 1000001 )
goto LABEL_2;
}
code_words[(int)v5] = a2;
return 1;
}

canonical_decompiled_code:
int __fastcall func13(char *s1, int a2)
{
unsigned int v2; // eax
__int64 v3; // r12
signed int v4; // eax
__int64 v5; // rbx
int result; // eax
__int64 v7; // rax

v2 = func12(s1);
v3 = names;
v4 = v2 % 0xF4240;
LABEL_2:
v5 = v4;
while ( 1 )
{
v7 = code_words[v5];
if ( !(_DWORD)v7 )
break;
result = strcmp(s1, *(const char **)(v3 + 8 * v7));
if ( !result )
return result;
++v5;
v4 = 0;
if ( (_DWORD)v5 == 1000001 )
goto LABEL_2;
}
code_words[(int)v5] = a2;
return 1;
}

original_code:
static int
add_word (char *word, int value)
{
  int h = hash (word) % 1000000;
  while (code_words[h])
    {
      if (!strcmp (word, names[code_words[h]]))
 return 0;
      h++;
      if (h > 1000000)
 h = 0;
    }
  code_words[h] = value;
  return 1;
}

canonical_original_code:
static int add_word(char *word, int value)
{
  int h = hash (word) % 1000000;
  while (code_words[h])
    {
      if (!strcmp (word, names[code_words[h]]))
 return 0;
      h++;
      if (h > 1000000)
 h = 0;
    }
  code_words[h] = value;
  return 1;
}

variable_types:
word
char *

variable_types: value int

variable_types: h int


original_code:
int
find_language (char *file)
{
  if ((!memcmp (file + strlen (file) - strlen (".txt"), ".txt", strlen (".txt"))) ||
      (!memcmp (file + strlen (file) - strlen (".htm"), ".htm", strlen (".htm"))) ||
      (!memcmp (file + strlen (file) - strlen (".html"), ".html", strlen (".html"))) ||
      (!memcmp (file + strlen (file) - strlen (".texi"), ".texi", strlen (".texi"))))
    return 3;
  if ((!memcmp (file + strlen (file) - strlen (".py"), ".py", strlen (".py"))) ||
      (!memcmp (file + strlen (file) - strlen (".sh"), ".sh", strlen (".sh"))) ||
      (!memcmp (file + strlen (file) - strlen (".rb"), ".rb", strlen (".rb"))))
    return 2;
  if ((!memcmp (file + strlen (file) - strlen (".ads"), ".ads", strlen (".ads"))) ||
      (!memcmp (file + strlen (file) - strlen (".adb"), ".adb", strlen (".adb"))))
    return 4;
  if ((!memcmp (file + strlen (file) - strlen (".f"), ".f", strlen (".f"))) ||
      (!memcmp (file + strlen (file) - strlen (".f90"), ".f90", strlen (".f90"))) ||
      (!memcmp (file + strlen (file) - strlen (".f95"), ".f95", strlen (".f95"))))
    return 5;
  if ((!memcmp (file + strlen (file) - strlen (".ml"), ".ml", strlen (".ml"))) ||
      (!memcmp (file + strlen (file) - strlen (".mli"), ".mli", strlen (".mli"))))
    return 6;
  return 1;
}

canonical_original_code:
int find_language(char *file)
{
  if ((!memcmp (file + strlen (file) - strlen (".txt"), ".txt", strlen (".txt"))) ||
      (!memcmp (file + strlen (file) - strlen (".htm"), ".htm", strlen (".htm"))) ||
      (!memcmp (file + strlen (file) - strlen (".html"), ".html", strlen (".html"))) ||
      (!memcmp (file + strlen (file) - strlen (".texi"), ".texi", strlen (".texi"))))
    return 3;
  if ((!memcmp (file + strlen (file) - strlen (".py"), ".py", strlen (".py"))) ||
      (!memcmp (file + strlen (file) - strlen (".sh"), ".sh", strlen (".sh"))) ||
      (!memcmp (file + strlen (file) - strlen (".rb"), ".rb", strlen (".rb"))))
    return 2;
  if ((!memcmp (file + strlen (file) - strlen (".ads"), ".ads", strlen (".ads"))) ||
      (!memcmp (file + strlen (file) - strlen (".adb"), ".adb", strlen (".adb"))))
    return 4;
  if ((!memcmp (file + strlen (file) - strlen (".f"), ".f", strlen (".f"))) ||
      (!memcmp (file + strlen (file) - strlen (".f90"), ".f90", strlen (".f90"))) ||
      (!memcmp (file + strlen (file) - strlen (".f95"), ".f95", strlen (".f95"))))
    return 5;
  if ((!memcmp (file + strlen (file) - strlen (".ml"), ".ml", strlen (".ml"))) ||
      (!memcmp (file + strlen (file) - strlen (".mli"), ".mli", strlen (".mli"))))
    return 6;
  return 1;
}

variable_types:
file
char *


decompiled_code:
_BOOL8 __fastcall start_comment(int a1, _WORD *a2)
{
_BOOL8 result; // rax

if ( a1 == 1 )
return *a2 == 10799;
result = 0LL;
if ( (unsigned int)(a1 - 5) <= 1 )
result = *a2 == 10792;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(int a1, _WORD *a2)
{
_BOOL8 result; // rax

if ( a1 == 1 )
return *a2 == 10799;
result = 0LL;
if ( (unsigned int)(a1 - 5) <= 1 )
result = *a2 == 10792;
return result;
}

original_code:
int
start_comment (int lang, char *s)
{
  if (lang == 1 && !memcmp (s, "/*", strlen ("/*")))
    return 1;
  if (lang == 5 && !memcmp (s, "(*", strlen ("(*")))
    return 1;
  if (lang == 6 && !memcmp (s, "(*", strlen ("(*")))
    return 1;
  return 0;
}

canonical_original_code:
int start_comment(int lang, char *s)
{
  if (lang == 1 && !memcmp (s, "/*", strlen ("/*")))
    return 1;
  if (lang == 5 && !memcmp (s, "(*", strlen ("(*")))
    return 1;
  if (lang == 6 && !memcmp (s, "(*", strlen ("(*")))
    return 1;
  return 0;
}

variable_types: lang int


decompiled_code:
_BOOL8 __fastcall end_comment(int a1, _WORD *a2)
{
_BOOL8 result; // rax

if ( a1 == 1 )
return *a2 == 12074;
result = 0LL;
if ( (unsigned int)(a1 - 5) <= 1 )
result = *a2 == 10538;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(int a1, _WORD *a2)
{
_BOOL8 result; // rax

if ( a1 == 1 )
return *a2 == 12074;
result = 0LL;
if ( (unsigned int)(a1 - 5) <= 1 )
result = *a2 == 10538;
return result;
}

original_code:
int
end_comment (int lang, char *s)
{
  if (lang == 1 && !memcmp (s, "*/", strlen ("*/")))
    return 1;
  if (lang == 5 && !memcmp (s, "*)", strlen ("*)")))
    return 1;
  if (lang == 6 && !memcmp (s, "*)", strlen ("*)")))
    return 1;
  return 0;
}

canonical_original_code:
int end_comment(int lang, char *s)
{
  if (lang == 1 && !memcmp (s, "*/", strlen ("*/")))
    return 1;
  if (lang == 5 && !memcmp (s, "*)", strlen ("*)")))
    return 1;
  if (lang == 6 && !memcmp (s, "*)", strlen ("*)")))
    return 1;
  return 0;
}


decompiled_code:
_BOOL8 __fastcall start_line_comment(int a1, _WORD *a2)
{
switch ( a1 )
{
case 1:
return *a2 == 12079;
case 2:
return *(_BYTE *)a2 == 35;
case 4:
return *a2 == 11565;
case 5:
return *(_BYTE *)a2 == 33;
}
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(int a1, _WORD *a2)
{
switch ( a1 )
{
case 1:
return *a2 == 12079;
case 2:
return *(_BYTE *)a2 == 35;
case 4:
return *a2 == 11565;
case 5:
return *(_BYTE *)a2 == 33;
}
return 0LL;
}

original_code:
int
start_line_comment (int lang, char *s)
{
  if (lang == 1 && !memcmp (s, "//", strlen ("//")))
    return 1;
  if (lang == 2 && !memcmp (s, "#", strlen ("#")))
    return 1;
  if (lang == 4 && !memcmp (s, "--", strlen ("--")))
    return 1;
  if (lang == 5 && !memcmp (s, "!", strlen ("!")))
    return 1;
  return 0;
}

canonical_original_code:
int start_line_comment(int lang, char *s)
{
  if (lang == 1 && !memcmp (s, "//", strlen ("//")))
    return 1;
  if (lang == 2 && !memcmp (s, "#", strlen ("#")))
    return 1;
  if (lang == 4 && !memcmp (s, "--", strlen ("--")))
    return 1;
  if (lang == 5 && !memcmp (s, "!", strlen ("!")))
    return 1;
  return 0;
}


decompiled_code:
int __fastcall strcmp2(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func7(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
char
strcmp2 (char **a, char **b)
{
  return strcmp (*a, *b);
}

canonical_original_code:
char strcmp2(char **a, char **b)
{
  return strcmp (*a, *b);
}

variable_types:
a
char **

variable_types:
b
char **

return_type: char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
size_t v3; // r15
_QWORD *v4; // rbp
const char **v5; // rbx
char *i; // r12
__int64 v7; // r12
const char *v8; // rbp
void *base; // [rsp+8h] [rbp-40h]

v3 = 0LL;
v4 = malloc(0x2FAF0800uLL);
base = v4;
v5 = (const char **)v4;
for ( i = (char *)malloc(0x5F5E100uLL); fgets(i, 100, stdin); *(v4 - 1) = strdup(i) )
{
++v4;
++v3;
}
*v4 = malloc(1uLL);
qsort(base, v3, 8uLL, strcmp2);
if ( (_DWORD)v3 )
{
v7 = (__int64)base + 8 * (unsigned int)(v3 - 1) + 8;
do
{
while ( 1 )
{
v8 = *v5;
if ( strcmp(*v5, v5[1]) )
break;
if ( (const char **)v7 == ++v5 )
return 0;
}
++v5;
printf("%s", v8);
}
while ( (const char **)v7 != v5 );
}
return 0;
}

original_code:
int
main (int argc, char **argv)
{
  char **words = malloc (100000000 * sizeof (char *));
  char *buffer = malloc (100000000);
  int words_no = 0;
  int i, j;
  while (fgets (buffer, 100, stdin))
    {
      words[words_no++] = strdup (buffer);
    }
  words[words_no] = malloc (1);
  qsort (words, words_no, sizeof (char *), (__compar_fn_t) strcmp2);
  for (i = 0; i < words_no; i++)
    {
      if (strcmp (words[i], words[i + 1]))
 {
   printf ("%s", words[i]);
 }
    }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  char **words = malloc (100000000 * sizeof (char *));
  char *buffer = malloc (100000000);
  int words_no = 0;
  int i; int j;
  while (fgets (buffer, 100, stdin))
    {
      words[words_no++] = strdup (buffer);
    }
  words[words_no] = malloc (1);
  qsort (words, words_no, sizeof (char *), (int (*)(void *, void *)) strcmp2);
  for (i = 0; i < words_no; i++)
    {
      if (strcmp (words[i], words[i + 1]))
 {
   printf ("%s", words[i]);
 }
    }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
words
char **

variable_types:
buffer
char *

variable_types: j int


isword

variable_types: c char


isseparator

variable_types:
c
char *


decompiled_code:
__int64 __fastcall read_line(int a1)
{
__int64 v1; // rbx
char v2; // bp
const unsigned __int16 **v3; // rax
int v4; // edx
__int64 result; // rax

v1 = 10000LL * a1;
if ( !fgets(&lines[v1], 10000, *(&fp + a1)) )
return 1LL;
v2 = lines[10000 * a1];
if ( v2 )
{
v3 = __ctype_b_loc();
v4 = 0;
do
{
if ( ((*v3)[v2] & 0x2000) != 0 )
break;
word[v1] = v2;
++v4;
v2 = lines[++v1];
}
while ( v2 );
}
else
{
v4 = 0;
}
result = 0LL;
word[10000 * a1 + v4] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
__int64 v1; // rbx
char v2; // bp
const unsigned __int16 **v3; // rax
int v4; // edx
__int64 result; // rax

v1 = 10000LL * a1;
if ( !fgets(&lines[v1], 10000, *(&fp + a1)) )
return 1LL;
v2 = lines[10000 * a1];
if ( v2 )
{
v3 = __ctype_b_loc();
v4 = 0;
do
{
if ( ((*v3)[v2] & 0x2000) != 0 )
break;
word[v1] = v2;
++v4;
v2 = lines[++v1];
}
while ( v2 );
}
else
{
v4 = 0;
}
result = 0LL;
word[10000 * a1 + v4] = 0;
return result;
}

original_code:
int
read_line (int i)
{
  if (!fgets (lines[i], 10000, fp[i]))
    return 1;
  int j = 0;
  while (lines[i][j] && !((*__ctype_b_loc ())[(int) ((lines[i][j]))] & (unsigned short int) _ISspace))
    {
      word[i][j] = lines[i][j]; j++;
    }
  word[i][j] = 0;
  return 0;
}

canonical_original_code:
int read_line(int i)
{
  if (!fgets (lines[i], 10000, fp[i]))
    return 1;
  int j = 0;
  while (lines[i][j] && !((*__ctype_b_loc ())[(int) ((lines[i][j]))] & (unsigned short) _ISspace))
    {
      word[i][j] = lines[i][j]; j++;
    }
  word[i][j] = 0;
  return 0;
}

variable_types: i int


canonical_decompiled_code:
void __fastcall func8(char *src)
{
char v1[1008]; // [rsp+0h] [rbp-7E8h] BYREF
char dest[1016]; // [rsp+3F0h] [rbp-3F8h] BYREF

if ( src )
{
strcpy(v1, src);
while ( strchr(v1, 47) && v1[0] && v1[1] )
{
dirname(v1);
strcpy(stpcpy(dest, v1), "/.indent.off");
if ( fopen(dest, "r") )
exit(1);
}
}
}

variable_types:
arg
char *

variable_types:
strbuf
char [1000]


canonical_decompiled_code:
__int64 __fastcall func9(const void *a1, __int64 a2, const char *a3, __int64 a4)
{
size_t v4; // rsi
int v6; // er8
__int64 result; // rax

v4 = a2 - (_QWORD)a1;
if ( v4 != a4 - (_QWORD)a3 || (v6 = memcmp(a1, a3, v4), result = 1LL, v6) )
{
printf("%s", a3);
result = 0LL;
}
return result;
}

variable_types:
input
char *

variable_types:
ip
char *

variable_types:
output
char *

variable_types:
op
char *


isword

canonical_decompiled_code:
__int64 __fastcall func10(char a1)
{
const unsigned __int16 *v1; // rdx
__int64 result; // rax

v1 = *__ctype_b_loc();
result = 1LL;
if ( (v1[a1] & 0x400) == 0 )
result = (a1 == 45) | (unsigned __int8)(a1 == 39);
return result;
}


isseparator

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
const unsigned __int16 **v1; // rax
__int64 v2; // rsi
const unsigned __int16 *v3; // rcx
__int64 result; // rax

v1 = __ctype_b_loc();
v2 = *a1;
v3 = *v1;
result = 1LL;
if ( (v3[v2] & 0x2000) == 0 )
{
if ( (v2 & 0xFD) == 44 || (result = 0LL, (_BYTE)v2 == 59) )
result = (v3[a1[1]] >> 13) & 1;
}
return result;
}


strmove

decompiled_code:
void *__fastcall strmove(void *dest, void *src)
{
size_t v2; // rax

v2 = strlen((const char *)src);
return memmove(dest, src, v2 + 1);
}

canonical_decompiled_code:
void *__fastcall func12(void *dest, void *src)
{
size_t v2; // rax

v2 = strlen((const char *)src);
return memmove(dest, src, v2 + 1);
}

original_code:
char *
strmove (char *dest, char *src)
{
  return memmove (dest, src, strlen (src) + 1);
}

canonical_original_code:
char *strmove(char *dest, char *src)
{
  return memmove (dest, src, strlen (src) + 1);
}

variable_types:
dest
char *

variable_types:
src
char *


repo: nemomobile/mce-plugin-libhybris

decompiled_code:
__int64 __fastcall led_channel_bacon_close(__int64 a1)
{
((void (*)(void))led_util_close_file)();
led_util_close_file(a1 + 4);
led_util_close_file(a1 + 8);
led_util_close_file(a1 + 12);
return led_util_close_file(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
((void (*)(void))led_util_close_file)();
led_util_close_file(a1 + 4);
led_util_close_file(a1 + 8);
led_util_close_file(a1 + 12);
return led_util_close_file(a1 + 16);
}

original_code:
static void
led_channel_bacon_close(led_channel_bacon_t *self)
{
  led_util_close_file(&self->fd_brightness);
  led_util_close_file(&self->fd_grpfreq);
  led_util_close_file(&self->fd_grppwm);
  led_util_close_file(&self->fd_blink);
  led_util_close_file(&self->fd_ledreset);
}

canonical_original_code:
static void led_channel_bacon_close(struct led_channel_bacon_t *self)
{
  led_util_close_file(&self->fd_brightness);
  led_util_close_file(&self->fd_grpfreq);
  led_util_close_file(&self->fd_grppwm);
  led_util_close_file(&self->fd_blink);
  led_util_close_file(&self->fd_ledreset);
}

variable_types: struct led_channel_bacon_t { int fd_brightness; int fd_grpfreq; int fd_grppwm; int fd_blink; int fd_ledreset; int brightness; int freq; int pwm; int blink; int maxval; } *


decompiled_code:
__int64 __fastcall led_control_bacon_close_cb(__int64 a1)
{
led_channel_bacon_close(a1);
led_channel_bacon_close(a1 + 40);
return led_channel_bacon_close(a1 + 80);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
func1(a1);
func1(a1 + 40);
return func1(a1 + 80);
}

original_code:
static void
led_control_bacon_close_cb(void *data)
{
  led_channel_bacon_t *channel = data;
  led_channel_bacon_close(channel + 0);
  led_channel_bacon_close(channel + 1);
  led_channel_bacon_close(channel + 2);
}

canonical_original_code:
static void led_control_bacon_close_cb(void *data)
{
  struct led_channel_bacon_t *channel = data;
  led_channel_bacon_close(channel + 0);
  led_channel_bacon_close(channel + 1);
  led_channel_bacon_close(channel + 2);
}

variable_types:
data
void *

user_defined_types: struct led_channel_bacon_t { int fd_brightness; int fd_grpfreq; int fd_grppwm; int fd_blink; int fd_ledreset; int brightness; int freq; int pwm; int blink; int maxval; }


decompiled_code:
int __fastcall led_control_bacon_blink_cb(__int64 a1, int a2, int a3)
{
int v5; // edi
unsigned int v6; // ebp
int v7; // eax
__int64 v8; // rdx

mce_hybris_log(
6LL,
"sysfs-led-bacon.c",
"led_control_bacon_blink_cb",
"led_control_bacon_blink_cb(%d,%d)",
(unsigned int)a2,
(unsigned int)a3);
if ( a2 <= 0 || a3 <= 0 )
{
*(_QWORD *)(a1 + 24) = 0LL;
v8 = 0LL;
*(_DWORD *)(a1 + 32) = 0;
}
else
{
v5 = *(_DWORD *)(a1 + 4);
*(_DWORD *)(a1 + 32) = 1;
v6 = a3 + a2;
v7 = 255 * a2 / (int)v6;
*(_DWORD *)(a1 + 24) = v6 / 0x32;
if ( (unsigned int)(v7 - 1) < 0xF )
v7 = 16;
*(_DWORD *)(a1 + 28) = v7;
dprintf(v5, "%d", v6 / 0x32);
dprintf(*(_DWORD *)(a1 + 8), "%d", *(unsigned int *)(a1 + 28));
v8 = *(unsigned int *)(a1 + 32);
}
return dprintf(*(_DWORD *)(a1 + 12), "%d", v8);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, int a2, int a3)
{
int v5; // edi
unsigned int v6; // ebp
int v7; // eax
__int64 v8; // rdx

mce_hybris_log(
6LL,
"sysfs-led-bacon.c",
"led_control_bacon_blink_cb",
"led_control_bacon_blink_cb(%d,%d)",
(unsigned int)a2,
(unsigned int)a3);
if ( a2 <= 0 || a3 <= 0 )
{
*(_QWORD *)(a1 + 24) = 0LL;
v8 = 0LL;
*(_DWORD *)(a1 + 32) = 0;
}
else
{
v5 = *(_DWORD *)(a1 + 4);
*(_DWORD *)(a1 + 32) = 1;
v6 = a3 + a2;
v7 = 255 * a2 / (int)v6;
*(_DWORD *)(a1 + 24) = v6 / 0x32;
if ( (unsigned int)(v7 - 1) < 0xF )
v7 = 16;
*(_DWORD *)(a1 + 28) = v7;
dprintf(v5, "%d", v6 / 0x32);
dprintf(*(_DWORD *)(a1 + 8), "%d", *(unsigned int *)(a1 + 28));
v8 = *(unsigned int *)(a1 + 32);
}
return dprintf(*(_DWORD *)(a1 + 12), "%d", v8);
}

original_code:
static void
led_control_bacon_blink_cb(void *data, int on_ms, int off_ms)
{
  led_channel_bacon_t *channel = data;
  mce_hybris_log(LL_INFO, "sysfs-led-bacon.c", __FUNCTION__ ,"led_control_bacon_blink_cb(%d,%d)", on_ms, off_ms);
  if( on_ms > 0 && off_ms > 0 ) {
    int totalMS = on_ms + off_ms;
    channel->freq = totalMS / 50;
    channel->pwm = (on_ms * 255) / totalMS;
    if( channel->pwm > 0 && channel->pwm < 16 )
      channel->pwm = 16;
    channel->blink = 1;
  } else {
    channel->blink = 0;
    channel->freq = 0;
    channel->pwm = 0;
  }
  if( channel->blink ) {
    dprintf(channel->fd_grpfreq, "%d", channel->freq);
    dprintf(channel->fd_grppwm, "%d", channel->pwm);
  }
  dprintf(channel->fd_blink, "%d", channel->blink);
}

canonical_original_code:
static void led_control_bacon_blink_cb(void *data, int on_ms, int off_ms)
{
  struct led_channel_bacon_t *channel = data;
  mce_hybris_log(LL_INFO, "sysfs-led-bacon.c", __FUNCTION__ ,"led_control_bacon_blink_cb(%d,%d)", on_ms, off_ms);
  if( on_ms > 0 && off_ms > 0 ) {
    int totalMS = on_ms + off_ms;
    channel->freq = totalMS / 50;
    channel->pwm = (on_ms * 255) / totalMS;
    if( channel->pwm > 0 && channel->pwm < 16 )
      channel->pwm = 16;
    channel->blink = 1;
  } else {
    channel->blink = 0;
    channel->freq = 0;
    channel->pwm = 0;
  }
  if( channel->blink ) {
    dprintf(channel->fd_grpfreq, "%d", channel->freq);
    dprintf(channel->fd_grppwm, "%d", channel->pwm);
  }
  dprintf(channel->fd_blink, "%d", channel->blink);
}

variable_types: totalMS int


decompiled_code:
int __fastcall led_control_bacon_enable_cb(__int64 a1, unsigned __int8 a2)
{
int result; // eax

result = mce_hybris_log(
6LL,
"sysfs-led-bacon.c",
"led_control_bacon_enable_cb",
"led_control_bacon_enable_cb(%d)",
a2);
if ( !a2 )
result = dprintf(*(_DWORD *)(a1 + 16), "%d", 1LL);
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, unsigned __int8 a2)
{
int result; // eax

result = mce_hybris_log(
6LL,
"sysfs-led-bacon.c",
"led_control_bacon_enable_cb",
"led_control_bacon_enable_cb(%d)",
a2);
if ( !a2 )
result = dprintf(*(_DWORD *)(a1 + 16), "%d", 1LL);
return result;
}

original_code:
static void
led_control_bacon_enable_cb(void *data, _Bool enable)
{
  const led_channel_bacon_t *channel = data;
  mce_hybris_log(LL_INFO, "sysfs-led-bacon.c", __FUNCTION__ ,"led_control_bacon_enable_cb(%d)", enable);
  if(!enable)
    dprintf(channel->fd_ledreset, "%d", 1);
}

canonical_original_code:
static void led_control_bacon_enable_cb(void *data, _Bool enable)
{
  struct led_channel_bacon_t *channel = data;
  mce_hybris_log(LL_INFO, "sysfs-led-bacon.c", __FUNCTION__ ,"led_control_bacon_enable_cb(%d)", enable);
  if(!enable)
    dprintf(channel->fd_ledreset, "%d", 1);
}


decompiled_code:
int __fastcall led_control_bacon_value_cb(int *a1, unsigned int a2, unsigned int a3, __int64 a4)
{
unsigned int v5; // ebp
__int64 v7; // rdx
int v8; // eax
__int64 v9; // rsi
__int64 v10; // rdx
int v11; // eax
__int64 v12; // rsi
__int64 v13; // rdx
int v14; // eax
__int64 v15; // rdx
int v16; // edi
int v17; // edi
__int64 v18; // rdx
__int64 v20; // [rsp-10h] [rbp-38h]

v5 = a4;
mce_hybris_log(
6LL,
"sysfs-led-bacon.c",
"led_control_bacon_value_cb",
"led_control_bacon_value_cb(%d,%d,%d), blink=%d",
a2,
a3,
a4,
(unsigned int)a1[8]);
v7 = v20;
if ( a1[8] )
dprintf(a1[4], "%d", 0LL);
v8 = led_util_scale_value(a2, (unsigned int)a1[9], v7);
v9 = (unsigned int)a1[19];
a1[5] = v8;
v11 = led_util_scale_value(a3, v9, v10);
v12 = (unsigned int)a1[29];
a1[15] = v11;
v14 = led_util_scale_value(v5, v12, v13);
v15 = (unsigned int)a1[5];
v16 = *a1;
a1[25] = v14;
dprintf(v16, "%d", v15);
dprintf(a1[10], "%d", (unsigned int)a1[15]);
dprintf(a1[20], "%d", (unsigned int)a1[25]);
if ( a1[8] )
{
dprintf(a1[1], "%d", (unsigned int)a1[6]);
dprintf(a1[2], "%d", (unsigned int)a1[7]);
v17 = a1[3];
v18 = 1LL;
}
else
{
v17 = a1[3];
v18 = 0LL;
}
return dprintf(v17, "%d", v18);
}

canonical_decompiled_code:
int __fastcall func5(int *a1, unsigned int a2, unsigned int a3, __int64 a4)
{
unsigned int v5; // ebp
__int64 v7; // rdx
int v8; // eax
__int64 v9; // rsi
__int64 v10; // rdx
int v11; // eax
__int64 v12; // rsi
__int64 v13; // rdx
int v14; // eax
__int64 v15; // rdx
int v16; // edi
int v17; // edi
__int64 v18; // rdx
__int64 v20; // [rsp-10h] [rbp-38h]

v5 = a4;
mce_hybris_log(
6LL,
"sysfs-led-bacon.c",
"led_control_bacon_value_cb",
"led_control_bacon_value_cb(%d,%d,%d), blink=%d",
a2,
a3,
a4,
(unsigned int)a1[8]);
v7 = v20;
if ( a1[8] )
dprintf(a1[4], "%d", 0LL);
v8 = led_util_scale_value(a2, (unsigned int)a1[9], v7);
v9 = (unsigned int)a1[19];
a1[5] = v8;
v11 = led_util_scale_value(a3, v9, v10);
v12 = (unsigned int)a1[29];
a1[15] = v11;
v14 = led_util_scale_value(v5, v12, v13);
v15 = (unsigned int)a1[5];
v16 = *a1;
a1[25] = v14;
dprintf(v16, "%d", v15);
dprintf(a1[10], "%d", (unsigned int)a1[15]);
dprintf(a1[20], "%d", (unsigned int)a1[25]);
if ( a1[8] )
{
dprintf(a1[1], "%d", (unsigned int)a1[6]);
dprintf(a1[2], "%d", (unsigned int)a1[7]);
v17 = a1[3];
v18 = 1LL;
}
else
{
v17 = a1[3];
v18 = 0LL;
}
return dprintf(v17, "%d", v18);
}

original_code:
static void
led_control_bacon_value_cb(void *data, int r, int g, int b)
{
  led_channel_bacon_t *channel = data;
  mce_hybris_log(LL_INFO, "sysfs-led-bacon.c", __FUNCTION__ ,"led_control_bacon_value_cb(%d,%d,%d), blink=%d", r, g, b, channel->blink);
  if( channel->blink )
    dprintf(channel->fd_ledreset, "%d", 0);
  (channel+0)->brightness = led_util_scale_value(r, (channel+0)->maxval);
  (channel+1)->brightness = led_util_scale_value(g, (channel+1)->maxval);
  (channel+2)->brightness = led_util_scale_value(b, (channel+2)->maxval);
  dprintf((channel+0)->fd_brightness, "%d", (channel+0)->brightness);
  dprintf((channel+1)->fd_brightness, "%d", (channel+1)->brightness);
  dprintf((channel+2)->fd_brightness, "%d", (channel+2)->brightness);
  if( channel->blink ) {
    dprintf(channel->fd_grpfreq, "%d", channel->freq);
    dprintf(channel->fd_grppwm, "%d", channel->pwm);
    dprintf(channel->fd_blink, "%d", 1);
  } else
    dprintf(channel->fd_blink, "%d", 0);
}

canonical_original_code:
static void led_control_bacon_value_cb(void *data, int r, int g, int b)
{
  struct led_channel_bacon_t *channel = data;
  mce_hybris_log(LL_INFO, "sysfs-led-bacon.c", __FUNCTION__ ,"led_control_bacon_value_cb(%d,%d,%d), blink=%d", r, g, b, channel->blink);
  if( channel->blink )
    dprintf(channel->fd_ledreset, "%d", 0);
  (channel+0)->brightness = led_util_scale_value(r, (channel+0)->maxval);
  (channel+1)->brightness = led_util_scale_value(g, (channel+1)->maxval);
  (channel+2)->brightness = led_util_scale_value(b, (channel+2)->maxval);
  dprintf((channel+0)->fd_brightness, "%d", (channel+0)->brightness);
  dprintf((channel+1)->fd_brightness, "%d", (channel+1)->brightness);
  dprintf((channel+2)->fd_brightness, "%d", (channel+2)->brightness);
  if( channel->blink ) {
    dprintf(channel->fd_grpfreq, "%d", channel->freq);
    dprintf(channel->fd_grppwm, "%d", channel->pwm);
    dprintf(channel->fd_blink, "%d", 1);
  } else
    dprintf(channel->fd_blink, "%d", 0);
}

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall led_channel_bacon_probe(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

led_channel_bacon_close(a1);
if ( !(unsigned __int8)led_util_open_file(a1, *a2)
|| !(unsigned __int8)led_util_open_file(a1 + 4, a2[1])
|| !(unsigned __int8)led_util_open_file(a1 + 8, a2[2])
|| !(unsigned __int8)led_util_open_file(a1 + 12, a2[3])
|| (result = led_util_open_file(a1 + 16, a2[4]), !(_BYTE)result) )
{
led_channel_bacon_close(a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

func1(a1);
if ( !(unsigned __int8)led_util_open_file(a1, *a2)
|| !(unsigned __int8)led_util_open_file(a1 + 4, a2[1])
|| !(unsigned __int8)led_util_open_file(a1 + 8, a2[2])
|| !(unsigned __int8)led_util_open_file(a1 + 12, a2[3])
|| (result = led_util_open_file(a1 + 16, a2[4]), !(_BYTE)result) )
{
func1(a1);
result = 0LL;
}
return result;
}

original_code:
static _Bool
led_channel_bacon_probe(led_channel_bacon_t *self,
                        const led_paths_bacon_t *path)
{
  _Bool res = 0;
  led_channel_bacon_close(self);
  if( !led_util_open_file(&self->fd_brightness, path->brightness) ||
      !led_util_open_file(&self->fd_grpfreq, path->grpfreq) ||
      !led_util_open_file(&self->fd_grppwm, path->grppwm) ||
      !led_util_open_file(&self->fd_blink, path->blink) ||
      !led_util_open_file(&self->fd_ledreset, path->ledreset))
  {
    goto cleanup;
  }
  res = 1;
cleanup:
  if( !res ) led_channel_bacon_close(self);
  return res;
}

canonical_original_code:
static _Bool led_channel_bacon_probe(struct led_channel_bacon_t *self, struct led_paths_bacon_t *path)
{
  _Bool res = 0;
  led_channel_bacon_close(self);
  if( !led_util_open_file(&self->fd_brightness, path->brightness) ||
      !led_util_open_file(&self->fd_grpfreq, path->grpfreq) ||
      !led_util_open_file(&self->fd_grppwm, path->grppwm) ||
      !led_util_open_file(&self->fd_blink, path->blink) ||
      !led_util_open_file(&self->fd_ledreset, path->ledreset))
  {
    goto cleanup;
  }
  res = 1;
cleanup:
  if( !res ) led_channel_bacon_close(self);
  return res;
}

variable_types: struct led_paths_bacon_t { char *brightness; char *grpfreq; char *grppwm; char *blink; char *ledreset; } *


decompiled_code:
__int64 __fastcall led_control_bacon_probe(__int64 a1)
{
bool v1; // zf

led_channel_bacon_init((__int64)&channel_6);
led_channel_bacon_init((__int64)&channel_6 + 40);
led_channel_bacon_init((__int64)&channel_6 + 80);
v1 = *(_BYTE *)(a1 + 17) == 0;
*(_BYTE *)(a1 + 16) = 0;
*(_QWORD *)a1 = "bacon";
*(_QWORD *)(a1 + 8) = &channel_6;
*(_QWORD *)(a1 + 24) = led_control_bacon_enable_cb;
*(_QWORD *)(a1 + 32) = led_control_bacon_blink_cb;
*(_QWORD *)(a1 + 40) = led_control_bacon_value_cb;
*(_QWORD *)(a1 + 48) = led_control_bacon_close_cb;
if ( !v1 && (unsigned __int8)led_control_bacon_dynamic_probe_constprop_0()
|| (unsigned __int8)led_control_bacon_static_probe_constprop_0() )
{
return 1LL;
}
led_control_close(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
bool v1; // zf

func0((__int64)&channel_6);
func0((__int64)&channel_6 + 40);
func0((__int64)&channel_6 + 80);
v1 = *(_BYTE *)(a1 + 17) == 0;
*(_BYTE *)(a1 + 16) = 0;
*(_QWORD *)a1 = "bacon";
*(_QWORD *)(a1 + 8) = &channel_6;
*(_QWORD *)(a1 + 24) = led_control_bacon_enable_cb;
*(_QWORD *)(a1 + 32) = led_control_bacon_blink_cb;
*(_QWORD *)(a1 + 40) = led_control_bacon_value_cb;
*(_QWORD *)(a1 + 48) = led_control_bacon_close_cb;
if ( !v1 && (unsigned __int8)func7()
|| (unsigned __int8)func8() )
{
return 1LL;
}
led_control_close(a1);
return 0LL;
}

original_code:
_Bool
led_control_bacon_probe(led_control_t *self)
{
  static led_channel_bacon_t channel[3];
  _Bool res = 0;
  led_channel_bacon_init(channel+0);
  led_channel_bacon_init(channel+1);
  led_channel_bacon_init(channel+2);
  self->name = "bacon";
  self->data = channel;
  self->enable = led_control_bacon_enable_cb;
  self->blink = led_control_bacon_blink_cb;
  self->value = led_control_bacon_value_cb;
  self->close = led_control_bacon_close_cb;
  self->can_breathe = 0;
  if( self->use_config )
    res = led_control_bacon_dynamic_probe(channel);
  if( !res )
    res = led_control_bacon_static_probe(channel);
  if( !res )
    led_control_close(self);
  return res;
}

canonical_original_code:
_Bool led_control_bacon_probe(struct led_control_t *self)
{
  static struct led_channel_bacon_t channel[3];
  _Bool res = 0;
  led_channel_bacon_init(channel+0);
  led_channel_bacon_init(channel+1);
  led_channel_bacon_init(channel+2);
  self->name = "bacon";
  self->data = channel;
  self->enable = led_control_bacon_enable_cb;
  self->blink = led_control_bacon_blink_cb;
  self->value = led_control_bacon_value_cb;
  self->close = led_control_bacon_close_cb;
  self->can_breathe = 0;
  if( self->use_config )
    res = led_control_bacon_dynamic_probe(channel);
  if( !res )
    res = led_control_bacon_static_probe(channel);
  if( !res )
    led_control_close(self);
  return res;
}

variable_types: struct led_control_t { char *name; void *data; _Bool can_breathe; _Bool use_config; enum led_ramp_t { LED_RAMP_DISABLED=0, LED_RAMP_HALF_SINE=1, LED_RAMP_HARD_STEP=2 } breath_type; void (*enable)(void *data, _Bool enable); void (*blink)(void *data, int on_ms, int off_ms); void (*value)(void *data, int r, int g, int b); void (*close)(void *data); } *

variable_types: struct led_channel_bacon_t { int fd_brightness; int fd_grpfreq; int fd_grppwm; int fd_blink; int fd_ledreset; int brightness; int freq; int pwm; int blink; int maxval; } [3]

user_defined_types: struct led_control_t { char *name; void *data; _Bool can_breathe; _Bool use_config; enum led_ramp_t breath_type; void (*enable)(void *data, _Bool enable); void (*blink)(void *data, int on_ms, int off_ms); void (*value)(void *data, int r, int g, int b); void (*close)(void *data); }


decompiled_code:
bool __fastcall quirk_is_valid(int a1)
{
return a1 == 0;
}

canonical_decompiled_code:
bool __fastcall func0(int a1)
{
return a1 == 0;
}

original_code:
static _Bool
quirk_is_valid(quirk_t id)
{
    return id > QUIRK_INVALID && id < QUIRK_COUNT && quirk_name_lut[id];
}

canonical_original_code:
static _Bool quirk_is_valid(enum quirk_t id)
{
    return id > QUIRK_INVALID && id < QUIRK_COUNT && quirk_name_lut[id];
}

variable_types: enum quirk_t { QUIRK_INVALID=-1, QUIRK_BREATHING=0, QUIRK_COUNT=1 }


decompiled_code:
char __fastcall quirk_is_defined(int a1)
{
char result; // al

result = quirk_is_valid(a1);
if ( result )
result = quirk_defined_lut[a1];
return result;
}

canonical_decompiled_code:
char __fastcall func1(int a1)
{
char result; // al

result = func0(a1);
if ( result )
result = quirk_defined_lut[a1];
return result;
}

original_code:
static _Bool
quirk_is_defined(quirk_t id)
{
    return quirk_is_valid(id) && quirk_defined_lut[id];
}

canonical_original_code:
static _Bool quirk_is_defined(enum quirk_t id)
{
    return quirk_is_valid(id) && quirk_defined_lut[id];
}

user_defined_types: enum quirk_t { QUIRK_INVALID=-1, QUIRK_BREATHING=0, QUIRK_COUNT=1 }


decompiled_code:
__int64 __fastcall quirk_in_array(const char **a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // rdi

v2 = a1;
v3 = *a1;
if ( !v3 )
return 0LL;
while ( strcmp(v3, a2) )
{
v3 = v2[1];
++v2;
if ( !v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char **a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // rdi

v2 = a1;
v3 = *a1;
if ( !v3 )
return 0LL;
while ( strcmp(v3, a2) )
{
v3 = v2[1];
++v2;
if ( !v3 )
return 0LL;
}
return 1LL;
}

original_code:
static _Bool
quirk_in_array(const char * const *vec, const char *str)
{
    for( ; *vec; ++vec )
        if( !strcmp(*vec, str) )
            return 1;
    return 0;
}

canonical_original_code:
static _Bool quirk_in_array(char **vec, char *str)
{
    for( ; *vec; ++vec )
        if( !strcmp(*vec, str) )
            return 1;
    return 0;
}

variable_types:
vec
char **

variable_types:
str
char *


decompiled_code:
__int64 __fastcall quirk_parse_value(char *nptr)
{
unsigned int v1; // er12
__int64 result; // rax

v1 = 0;
if ( !nptr
|| (unsigned __int8)quirk_in_array((const char **)quirk_false_lut, nptr)
|| (v1 = 1, (unsigned __int8)quirk_in_array((const char **)quirk_true_lut, nptr)) )
{
result = v1;
}
else
{
result = (unsigned int)strtol(nptr, 0LL, 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *nptr)
{
unsigned int v1; // er12
__int64 result; // rax

v1 = 0;
if ( !nptr
|| (unsigned __int8)func2((const char **)quirk_false_lut, nptr)
|| (v1 = 1, (unsigned __int8)func2((const char **)quirk_true_lut, nptr)) )
{
result = v1;
}
else
{
result = (unsigned int)strtol(nptr, 0LL, 0);
}
return result;
}

original_code:
static int
quirk_parse_value(const char *str)
{
    int val = 0;
    if( !str )
        goto EXIT;
    if( quirk_in_array(quirk_false_lut, str) )
        goto EXIT;
    val = 1;
    if( quirk_in_array(quirk_true_lut, str) )
        goto EXIT;
    val = strtol(str, 0, 0);
EXIT:
    return val;
}

canonical_original_code:
static int quirk_parse_value(char *str)
{
    int val = 0;
    if( !str )
        goto EXIT;
    if( quirk_in_array(quirk_false_lut, str) )
        goto EXIT;
    val = 1;
    if( quirk_in_array(quirk_true_lut, str) )
        goto EXIT;
    val = strtol(str, 0, 0);
EXIT:
    return val;
}

variable_types: val int


decompiled_code:
char *plugin_quirk_init()
{
char *result; // rax
char *v1; // rbp

result = (char *)plugin_config_get_string("LEDConfigHybris", "QuirkBreathing", 0LL);
if ( result )
{
v1 = result;
quirk_defined_lut[0] = 1;
quirk_value_lut = quirk_parse_value(result);
mce_hybris_log(
7LL,
"plugin-quirks.c",
"plugin_quirk_init",
"set %s = %d",
"QuirkBreathing",
(unsigned int)quirk_value_lut);
result = (char *)g_free(v1);
}
return result;
}

canonical_decompiled_code:
char *func4()
{
char *result; // rax
char *v1; // rbp

result = (char *)plugin_config_get_string("LEDConfigHybris", "QuirkBreathing", 0LL);
if ( result )
{
v1 = result;
quirk_defined_lut[0] = 1;
quirk_value_lut = func3(result);
mce_hybris_log(
7LL,
"plugin-quirks.c",
"plugin_quirk_init",
"set %s = %d",
"QuirkBreathing",
(unsigned int)quirk_value_lut);
result = (char *)g_free(v1);
}
return result;
}

original_code:
static void
plugin_quirk_init(void)
{
    for( quirk_t id = 0; id < QUIRK_COUNT; ++id ) {
        gchar *val = plugin_config_get_string("LEDConfigHybris",
                                              quirk_name_lut[id], 0);
        if( !val )
            continue;
        quirk_defined_lut[id] = 1;
        quirk_value_lut[id] = quirk_parse_value(val);
        mce_hybris_log(7, "plugin-quirks.c", __FUNCTION__ ,"set %s = %d", quirk_name_lut[id], quirk_value_lut[id]);
        g_free(val);
    }
}

canonical_original_code:
static void plugin_quirk_init()
{
    for( enum quirk_t id = 0; id < QUIRK_COUNT; ++id ) {
        char *val = plugin_config_get_string("LEDConfigHybris",
                                              quirk_name_lut[id], 0);
        if( !val )
            continue;
        quirk_defined_lut[id] = 1;
        quirk_value_lut[id] = quirk_parse_value(val);
        mce_hybris_log(7, "plugin-quirks.c", __FUNCTION__ ,"set %s = %d", quirk_name_lut[id], quirk_value_lut[id]);
        g_free(val);
    }
}

variable_types:
val
char *


decompiled_code:
const char *__fastcall quirk_name(int a1)
{
bool v1; // zf
const char *result; // rax

v1 = !quirk_is_valid(a1);
result = "QuirkBreathing";
if ( v1 )
result = "QuirkInvalid";
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(int a1)
{
bool v1; // zf
const char *result; // rax

v1 = !func0(a1);
result = "QuirkBreathing";
if ( v1 )
result = "QuirkInvalid";
return result;
}

original_code:
const char *
quirk_name(quirk_t id)
{
    const char *repr = 0;
    if( quirk_is_valid(id) )
        repr = quirk_name_lut[id];
    return repr ?: "QuirkInvalid";
}

canonical_original_code:
char *quirk_name(enum quirk_t id)
{
    char *repr = 0;
    if( quirk_is_valid(id) )
        repr = quirk_name_lut[id];
    return repr ?: "QuirkInvalid";
}

variable_types:
repr
char *


decompiled_code:
__int64 __fastcall quirk_value(int a1, unsigned int a2)
{
if ( !done_1 )
{
done_1 = 1;
plugin_quirk_init();
}
if ( quirk_is_defined(a1) )
a2 = quirk_value_lut[a1];
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, unsigned int a2)
{
if ( !done_1 )
{
done_1 = 1;
func4();
}
if ( func1(a1) )
a2 = quirk_value_lut[a1];
return a2;
}

original_code:
int
quirk_value(quirk_t id, int def)
{
    static _Bool done = 0;
    if( !done ) {
        done = 1;
        plugin_quirk_init();
    }
    return quirk_is_defined(id) ? quirk_value_lut[id] : def;
}

canonical_original_code:
int quirk_value(enum quirk_t id, int def)
{
    static _Bool done = 0;
    if( !done ) {
        done = 1;
        plugin_quirk_init();
    }
    return quirk_is_defined(id) ? quirk_value_lut[id] : def;
}

variable_types: def int


decompiled_code:
void __fastcall sysfsval_ctor(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = -1LL;
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = -1LL;
}

original_code:
static void
sysfsval_ctor(sysfsval_t *self)
{
    self->sv_path = 0;
    self->sv_file = -1;
    self->sv_curr = -1;
}

canonical_original_code:
static void sysfsval_ctor(struct sysfsval_t *self)
{
    self->sv_path = 0;
    self->sv_file = -1;
    self->sv_curr = -1;
}

variable_types: struct sysfsval_t { char *sv_path; int sv_file; int sv_curr; } *


decompiled_code:
void sysfsval_create()
{
_QWORD *v0; // rax

v0 = calloc(1uLL, 0x10uLL);
sysfsval_ctor(v0);
}

canonical_decompiled_code:
void func1()
{
_QWORD *v0; // rax

v0 = calloc(1uLL, 0x10uLL);
func0(v0);
}

original_code:
sysfsval_t *
sysfsval_create(void)
{
    sysfsval_t *self = calloc(1, sizeof *self);
    sysfsval_ctor(self);
    return self;
}

canonical_original_code:
struct sysfsval_t *sysfsval_create()
{
    struct sysfsval_t *self = calloc(1, sizeof *self);
    sysfsval_ctor(self);
    return self;
}

return_type: struct sysfsval_t { char *sv_path; int sv_file; int sv_curr; } *


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

result = *a1;
if ( !*a1 )
result = "unset";
return result;
}

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

result = *a1;
if ( !*a1 )
result = "unset";
return result;
}

original_code:
const char *
sysfsval_path(const sysfsval_t *self)
{
    return self->sv_path ?: "unset";
}

canonical_original_code:
char *sysfsval_path(struct sysfsval_t *self)
{
    return self->sv_path ?: "unset";
}

user_defined_types: struct sysfsval_t { char *sv_path; int sv_file; int sv_curr; }


decompiled_code:
void __fastcall sysfsval_close(__int64 a1)
{
const char *v1; // rax

if ( *(_DWORD *)(a1 + 8) != -1 )
{
v1 = sysfsval_path((const char **)a1);
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_close", "%s: closed", v1);
close(*(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = -1;
}
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
const char *v1; // rax

if ( *(_DWORD *)(a1 + 8) != -1 )
{
v1 = func2((const char **)a1);
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_close", "%s: closed", v1);
close(*(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = -1;
}
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
}

original_code:
void
sysfsval_close(sysfsval_t *self)
{
    if( self->sv_file != -1 ) {
        mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: closed", sysfsval_path(self));
        close(self->sv_file), self->sv_file = -1;
    }
    free(self->sv_path), self->sv_path = 0;
}

canonical_original_code:
void sysfsval_close(struct sysfsval_t *self)
{
    if( self->sv_file != -1 ) {
        mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: closed", sysfsval_path(self));
        close(self->sv_file), self->sv_file = -1;
    }
    free(self->sv_path), self->sv_path = 0;
}


decompiled_code:
// attributes: thunk
void __fastcall sysfsval_dtor(__int64 a1)
{
sysfsval_close(a1);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
func3(a1);
}

original_code:
static void
sysfsval_dtor(sysfsval_t *self)
{
    sysfsval_close(self);
}

canonical_original_code:
static void sysfsval_dtor(struct sysfsval_t *self)
{
    sysfsval_close(self);
}


decompiled_code:
void __fastcall sysfsval_delete(void *ptr)
{
if ( ptr )
{
sysfsval_dtor((__int64)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( ptr )
{
func4((__int64)ptr);
free(ptr);
}
}

original_code:
void
sysfsval_delete(sysfsval_t *self)
{
    if( self ) {
        sysfsval_dtor(self);
        free(self);
    }
}

canonical_original_code:
void sysfsval_delete(struct sysfsval_t *self)
{
    if( self ) {
        sysfsval_dtor(self);
        free(self);
    }
}


decompiled_code:
__int64 __fastcall sysfsval_open_ex(__int64 a1, const char *a2, int a3)
{
char *v4; // rax
int v5; // eax
const char *v6; // rax
const char *v7; // rcx

sysfsval_close(a1);
if ( a2 )
{
v4 = strdup(a2);
*(_QWORD *)a1 = v4;
if ( v4 )
{
v5 = open64(a2, a3);
*(_DWORD *)(a1 + 8) = v5;
if ( v5 != -1 )
{
v6 = sysfsval_path((const char **)a1);
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_open_ex", v7, v6);
return 1LL;
}
if ( *_errno_location() == 2 )
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_open_ex", "%s: open: %m", a2);
else
mce_hybris_log(3LL, "sysfs-val.c", "sysfsval_open_ex", "%s: open: %m", a2);
}
}
sysfsval_close(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, int a3)
{
char *v4; // rax
int v5; // eax
const char *v6; // rax
const char *v7; // rcx

func3(a1);
if ( a2 )
{
v4 = strdup(a2);
*(_QWORD *)a1 = v4;
if ( v4 )
{
v5 = open64(a2, a3);
*(_DWORD *)(a1 + 8) = v5;
if ( v5 != -1 )
{
v6 = func2((const char **)a1);
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_open_ex", v7, v6);
return 1LL;
}
if ( *_errno_location() == 2 )
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_open_ex", "%s: open: %m", a2);
else
mce_hybris_log(3LL, "sysfs-val.c", "sysfsval_open_ex", "%s: open: %m", a2);
}
}
func3(a1);
return 0LL;
}

original_code:
static _Bool
sysfsval_open_ex(sysfsval_t *self, const char *path, mode_t mode)
{
    _Bool ack = 0;
    sysfsval_close(self);
    if( !path )
        goto EXIT;
    if( (self->sv_path = strdup(path)) == 0 )
        goto EXIT;
    if( (self->sv_file = open(path, mode)) == -1 ) {
        if( (*__errno_location ()) == 2 )
            mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: open: %m", path);
        else
            mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: open: %m", path);
        goto EXIT;
    }
    mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: opened", sysfsval_path(self));
    ack = 1;
EXIT:
    if( !ack )
        sysfsval_close(self);
    return ack;
}

canonical_original_code:
static _Bool sysfsval_open_ex(struct sysfsval_t *self, char *path, unsigned int mode)
{
    _Bool ack = 0;
    sysfsval_close(self);
    if( !path )
        goto EXIT;
    if( (self->sv_path = strdup(path)) == 0 )
        goto EXIT;
    if( (self->sv_file = open(path, mode)) == -1 ) {
        if( (*__errno_location ()) == 2 )
            mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: open: %m", path);
        else
            mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: open: %m", path);
        goto EXIT;
    }
    mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: opened", sysfsval_path(self));
    ack = 1;
EXIT:
    if( !ack )
        sysfsval_close(self);
    return ack;
}

variable_types:
path
char *

variable_types:
mode
unsigned int


decompiled_code:
__int64 __fastcall sysfsval_open_rw(__int64 a1, const char *a2)
{
return sysfsval_open_ex(a1, a2, 2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
return func6(a1, a2, 2);
}

original_code:
_Bool
sysfsval_open_rw(sysfsval_t *self, const char *path)
{
    return sysfsval_open_ex(self, path, 02);
}

canonical_original_code:
_Bool sysfsval_open_rw(struct sysfsval_t *self, char *path)
{
    return sysfsval_open_ex(self, path, 02);
}


decompiled_code:
__int64 __fastcall sysfsval_open_ro(__int64 a1, const char *a2)
{
return sysfsval_open_ex(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2)
{
return func6(a1, a2, 0);
}

original_code:
_Bool
sysfsval_open_ro(sysfsval_t *self, const char *path)
{
    return sysfsval_open_ex(self, path, 00);
}

canonical_original_code:
_Bool sysfsval_open_ro(struct sysfsval_t *self, char *path)
{
    return sysfsval_open_ex(self, path, 00);
}


decompiled_code:
__int64 __fastcall sysfsval_get(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int
sysfsval_get(const sysfsval_t *self)
{
    return self->sv_curr;
}

canonical_original_code:
int sysfsval_get(struct sysfsval_t *self)
{
    return self->sv_curr;
}


decompiled_code:
__int64 __fastcall sysfsval_set(__int64 a1, __int64 a2)
{
int v2; // er9
const char *v3; // rax
__int64 v4; // r9
size_t v5; // r12
const char *v6; // r8
int v7; // ecx
char s[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = a2;
if ( v2 == (_DWORD)a2 )
return 1LL;
if ( *(_DWORD *)(a1 + 8) == -1 )
return 1LL;
v3 = sysfsval_path((const char **)a1);
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_set", "%s: write: %d -> %d", v3, v4, a2);
v5 = snprintf(s, 0x100uLL, "%d", (unsigned int)a2);
if ( (_DWORD)v5 == (unsigned int)write(*(_DWORD *)(a1 + 8), s, v5) )
return 1LL;
v6 = sysfsval_path((const char **)a1);
if ( v7 == -1 )
mce_hybris_log(3LL, "sysfs-val.c", "sysfsval_set", "%s: write: %m", v6);
else
mce_hybris_log(3LL, "sysfs-val.c", "sysfsval_set", "%s: write: partial", v6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
int v2; // er9
const char *v3; // rax
__int64 v4; // r9
size_t v5; // r12
const char *v6; // r8
int v7; // ecx
char s[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = a2;
if ( v2 == (_DWORD)a2 )
return 1LL;
if ( *(_DWORD *)(a1 + 8) == -1 )
return 1LL;
v3 = func2((const char **)a1);
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_set", "%s: write: %d -> %d", v3, v4, a2);
v5 = snprintf(s, 0x100uLL, "%d", (unsigned int)a2);
if ( (_DWORD)v5 == (unsigned int)write(*(_DWORD *)(a1 + 8), s, v5) )
return 1LL;
v6 = func2((const char **)a1);
if ( v7 == -1 )
mce_hybris_log(3LL, "sysfs-val.c", "sysfsval_set", "%s: write: %m", v6);
else
mce_hybris_log(3LL, "sysfs-val.c", "sysfsval_set", "%s: write: partial", v6);
return 0LL;
}

original_code:
_Bool
sysfsval_set(sysfsval_t *self, int value)
{
    _Bool ack = 1;
    int prev = self->sv_curr;
    self->sv_curr = value;
    if( prev == self->sv_curr )
        goto EXIT;
    if( self->sv_file == -1 )
        goto EXIT;
    mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: write: %d -> %d", sysfsval_path(self), prev, self->sv_curr);
    char data[256];
    int todo = snprintf(data, sizeof data, "%d", value);
    int done = write(self->sv_file, data, todo);
    if( done == todo )
        goto EXIT;
    ack = 0;
    if( done == -1 )
        mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: write: %m", sysfsval_path(self));
    else
        mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: write: partial", sysfsval_path(self));
EXIT:
    return ack;
}

canonical_original_code:
_Bool sysfsval_set(struct sysfsval_t *self, int value)
{
    _Bool ack = 1;
    int prev = self->sv_curr;
    self->sv_curr = value;
    if( prev == self->sv_curr )
        goto EXIT;
    if( self->sv_file == -1 )
        goto EXIT;
    mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: write: %d -> %d", sysfsval_path(self), prev, self->sv_curr);
    char data[256];
    int todo = snprintf(data, sizeof data, "%d", value);
    int done = write(self->sv_file, data, todo);
    if( done == todo )
        goto EXIT;
    ack = 0;
    if( done == -1 )
        mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: write: %m", sysfsval_path(self));
    else
        mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: write: partial", sysfsval_path(self));
EXIT:
    return ack;
}

variable_types: value int

variable_types: prev int

variable_types:
data
char [256]

variable_types: todo int

variable_types: done int


decompiled_code:
void __fastcall sysfsval_assume(__int64 a1, int a2)
{
int v2; // er9
const char *v3; // rax
const char *v4; // rcx

v2 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = a2;
if ( v2 != a2 && *(_DWORD *)(a1 + 8) != -1 )
{
v3 = sysfsval_path((const char **)a1);
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_assume", v4, v3);
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, int a2)
{
int v2; // er9
const char *v3; // rax
const char *v4; // rcx

v2 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = a2;
if ( v2 != a2 && *(_DWORD *)(a1 + 8) != -1 )
{
v3 = func2((const char **)a1);
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_assume", v4, v3);
}
}

original_code:
void
sysfsval_assume(sysfsval_t *self, int value)
{
    int prev = self->sv_curr;
    self->sv_curr = value;
    if( prev == self->sv_curr )
        goto EXIT;
    if( self->sv_file == -1 )
        goto EXIT;
    mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: assume: %d -> %d", sysfsval_path(self), prev, self->sv_curr);
EXIT:
    return;
}

canonical_original_code:
void sysfsval_assume(struct sysfsval_t *self, int value)
{
    int prev = self->sv_curr;
    self->sv_curr = value;
    if( prev == self->sv_curr )
        goto EXIT;
    if( self->sv_file == -1 )
        goto EXIT;
    mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: assume: %d -> %d", sysfsval_path(self), prev, self->sv_curr);
EXIT:
    return;
}


decompiled_code:
__int64 __fastcall sysfsval_invalidate(__int64 a1)
{
__int64 result; // rax
const char *v2; // rax
const char *v3; // rcx

result = *(unsigned int *)(a1 + 12);
*(_DWORD *)(a1 + 12) = -1;
if ( (_DWORD)result != -1 && *(_DWORD *)(a1 + 8) != -1 )
{
v2 = sysfsval_path((const char **)a1);
result = mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_invalidate", v3, v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 result; // rax
const char *v2; // rax
const char *v3; // rcx

result = *(unsigned int *)(a1 + 12);
*(_DWORD *)(a1 + 12) = -1;
if ( (_DWORD)result != -1 && *(_DWORD *)(a1 + 8) != -1 )
{
v2 = func2((const char **)a1);
result = mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_invalidate", v3, v2);
}
return result;
}

original_code:
void
sysfsval_invalidate(sysfsval_t *self)
{
    int prev = self->sv_curr;
    self->sv_curr = -1;
    if( prev == self->sv_curr )
        goto EXIT;
    if( self->sv_file == -1 )
        goto EXIT;
    mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: invalidated", sysfsval_path(self));
EXIT:
    return;
}

canonical_original_code:
void sysfsval_invalidate(struct sysfsval_t *self)
{
    int prev = self->sv_curr;
    self->sv_curr = -1;
    if( prev == self->sv_curr )
        goto EXIT;
    if( self->sv_file == -1 )
        goto EXIT;
    mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: invalidated", sysfsval_path(self));
EXIT:
    return;
}


decompiled_code:
__int64 __fastcall sysfsval_refresh(__int64 a1)
{
int v2; // edi
int v3; // eax
__int64 v4; // rbx
const char *v5; // rax
const char *v6; // rcx
const char *v8; // rcx
const char *v9; // r8
char v10[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = *(_DWORD *)(a1 + 8);
if ( v2 != -1 )
{
if ( lseek64(v2, 0LL, 0) == -1 )
{
v9 = sysfsval_path((const char **)a1);
}
else
{
v3 = read(*(_DWORD *)(a1 + 8), v10, 0xFFuLL);
if ( v3 != -1 && v3 )
{
v10[v3] = 0;
v4 = strtol(v10, 0LL, 0);
v5 = sysfsval_path((const char **)a1);
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_refresh", v6, v5, *(unsigned int *)(a1 + 12), v4);
*(_DWORD *)(a1 + 12) = v4;
return 1LL;
}
v9 = sysfsval_path((const char **)a1);
}
mce_hybris_log(3LL, "sysfs-val.c", "sysfsval_refresh", v8, v9);
}
sysfsval_invalidate(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int v2; // edi
int v3; // eax
__int64 v4; // rbx
const char *v5; // rax
const char *v6; // rcx
const char *v8; // rcx
const char *v9; // r8
char v10[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = *(_DWORD *)(a1 + 8);
if ( v2 != -1 )
{
if ( lseek64(v2, 0LL, 0) == -1 )
{
v9 = func2((const char **)a1);
}
else
{
v3 = read(*(_DWORD *)(a1 + 8), v10, 0xFFuLL);
if ( v3 != -1 && v3 )
{
v10[v3] = 0;
v4 = strtol(v10, 0LL, 0);
v5 = func2((const char **)a1);
mce_hybris_log(7LL, "sysfs-val.c", "sysfsval_refresh", v6, v5, *(unsigned int *)(a1 + 12), v4);
*(_DWORD *)(a1 + 12) = v4;
return 1LL;
}
v9 = func2((const char **)a1);
}
mce_hybris_log(3LL, "sysfs-val.c", "sysfsval_refresh", v8, v9);
}
func12(a1);
return 0LL;
}

original_code:
_Bool
sysfsval_refresh(sysfsval_t *self)
{
    _Bool ack = 0;
    int value = -1;
    char data[256];
    if( self->sv_file == -1 )
        goto EXIT;
    if( lseek(self->sv_file, 0, 0) == -1 ) {
        mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: seek: %m", sysfsval_path(self));
        goto EXIT;
    }
    int done = read(self->sv_file, data, sizeof data - 1);
    if( done == -1 ) {
        mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: read: %m", sysfsval_path(self));
        goto EXIT;
    }
    if( done == 0 ) {
        mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: read: EOF", sysfsval_path(self));
        goto EXIT;
    }
    data[done] = 0;
    value = strtol(data, 0, 0);
    mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: read: %d -> %d", sysfsval_path(self), self->sv_curr, value);
    self->sv_curr = value;
    ack = 1;
EXIT:
    if( !ack )
        sysfsval_invalidate(self);
    return ack;
}

canonical_original_code:
_Bool sysfsval_refresh(struct sysfsval_t *self)
{
    _Bool ack = 0;
    int value = -1;
    char data[256];
    if( self->sv_file == -1 )
        goto EXIT;
    if( lseek(self->sv_file, 0, 0) == -1 ) {
        mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: seek: %m", sysfsval_path(self));
        goto EXIT;
    }
    int done = read(self->sv_file, data, sizeof data - 1);
    if( done == -1 ) {
        mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: read: %m", sysfsval_path(self));
        goto EXIT;
    }
    if( done == 0 ) {
        mce_hybris_log(3, "sysfs-val.c", __FUNCTION__ ,"%s: read: EOF", sysfsval_path(self));
        goto EXIT;
    }
    data[done] = 0;
    value = strtol(data, 0, 0);
    mce_hybris_log(7, "sysfs-val.c", __FUNCTION__ ,"%s: read: %d -> %d", sysfsval_path(self), self->sv_curr, value);
    self->sv_curr = value;
    ack = 1;
EXIT:
    if( !ack )
        sysfsval_invalidate(self);
    return ack;
}


lea

decompiled_code:
__int64 __fastcall lea(__int64 a1, int a2)
{
return a1 + a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
return a1 + a2;
}

original_code:
static inline void *lea(const void *base, int offs)
{
    return ((char *)base)+offs;
}

canonical_original_code:
static inline void *lea(void *base, int offs)
{
    return ((char *)base)+offs;
}

variable_types:
base
void *

variable_types: offs int


decompiled_code:
__int64 __fastcall plugin_config_get_string(const char *a1, const char *a2, __int64 a3)
{
__int64 v4; // r12
const char *v5; // rax

if ( (unsigned int)mce_conf_has_key() )
{
v4 = mce_conf_get_string(a1, a2, a3);
}
else
{
if ( !a3 )
{
v4 = 0LL;
v5 = "(null)";
goto LABEL_6;
}
v4 = g_strdup(a3);
}
v5 = "(null)";
if ( v4 )
v5 = (const char *)v4;
LABEL_6:
mce_hybris_log(7LL, "plugin-config.c", "plugin_config_get_string", "[%s] %s = %s", a1, a2, v5);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2, __int64 a3)
{
__int64 v4; // r12
const char *v5; // rax

if ( (unsigned int)mce_conf_has_key() )
{
v4 = mce_conf_get_string(a1, a2, a3);
}
else
{
if ( !a3 )
{
v4 = 0LL;
v5 = "(null)";
goto LABEL_6;
}
v4 = g_strdup(a3);
}
v5 = "(null)";
if ( v4 )
v5 = (const char *)v4;
LABEL_6:
mce_hybris_log(7LL, "plugin-config.c", "plugin_config_get_string", "[%s] %s = %s", a1, a2, v5);
return v4;
}

original_code:
gchar *
plugin_config_get_string(const gchar *group,
                         const gchar *key,
                         const gchar *defaultval)
{
    extern gboolean mce_conf_has_key(const gchar *group,
                                     const gchar *key);
    extern gchar *mce_conf_get_string(const gchar *group,
                                      const gchar *key,
                                      const gchar *defaultval);
    gchar *res = 0;
    if( !mce_conf_has_key(group, key) )
        res = defaultval ? g_strdup(defaultval) : 0;
    else
        res = mce_conf_get_string(group, key, defaultval);
    mce_hybris_log(7, "plugin-config.c", __FUNCTION__ ,"[%s] %s = %s", group, key, res ?: "(null)");
    return res;
}

canonical_original_code:
char *plugin_config_get_string(char *group, char *key, char *defaultval)
{
    extern int mce_conf_has_key(char *group, char *key);
    extern char *mce_conf_get_string(char *group, char *key, char *defaultval);
    char *res = 0;
    if( !mce_conf_has_key(group, key) )
        res = defaultval ? g_strdup(defaultval) : 0;
    else
        res = mce_conf_get_string(group, key, defaultval);
    mce_hybris_log(7, "plugin-config.c", __FUNCTION__ ,"[%s] %s = %s", group, key, res ?: "(null)");
    return res;
}

variable_types:
group
char *

variable_types:
key
char *

variable_types:
defaultval
char *

variable_types: char *(char *group, char *key, char *defaultval)

variable_types:
res
char *


decompiled_code:
void __fastcall objconf_init(_DWORD *a1, __int64 a2)
{
_DWORD *v3; // rdx

if ( *a1 )
{
v3 = a1 + 8;
do
*(_QWORD *)lea(a2, *(v3 - 2)) = 0LL;
while ( *(v3 - 8) );
}
}

original_code:
void
objconf_init(const objconf_t *cfg, void *obj)
{
    for( size_t i = 0; cfg[i].type != CONFTYPE_NONE; ++i ) {
        char **memb = lea(obj, cfg[i].off);
        *memb = 0;
    }
}

canonical_original_code:
void objconf_init(struct objconf_t *cfg, void *obj)
{
    for( unsigned long i = 0; cfg[i].type != CONFTYPE_NONE; ++i ) {
        char **memb = lea(obj, cfg[i].off);
        *memb = 0;
    }
}

variable_types: struct objconf_t { enum conftype_t { CONFTYPE_NONE=0, CONFTYPE_FILE=1, CONFTYPE_STRING=2 } type; char *key; char *def; long off; } *

variable_types:
obj
void *

variable_types:
i
unsigned long

variable_types:
memb
char **

user_defined_types: struct objconf_t { enum conftype_t type; char *key; char *def; long off; }


decompiled_code:
void __fastcall objconf_quit(_DWORD *a1, __int64 a2)
{
_DWORD *v3; // rbp
int v4; // esi
void **v5; // rbx
int v6; // eax

if ( *a1 )
{
v3 = a1 + 8;
do
{
v4 = *(v3 - 2);
v3 += 8;
v5 = (void **)lea(a2, v4);
free(*v5);
v6 = *(v3 - 8);
*v5 = 0LL;
}
while ( v6 );
}
}

original_code:
void
objconf_quit(const objconf_t *cfg, void *obj)
{
    for( size_t i = 0; cfg[i].type != CONFTYPE_NONE; ++i ) {
        char **memb = lea(obj, cfg[i].off);
        free(*memb), *memb = 0;
    }
}

canonical_original_code:
void objconf_quit(struct objconf_t *cfg, void *obj)
{
    for( unsigned long i = 0; cfg[i].type != CONFTYPE_NONE; ++i ) {
        char **memb = lea(obj, cfg[i].off);
        free(*memb), *memb = 0;
    }
}

user_defined_types: enum conftype_t { CONFTYPE_NONE=0, CONFTYPE_FILE=1, CONFTYPE_STRING=2 }


decompiled_code:
__int64 __fastcall objconf_parse(int *a1, __int64 a2, const char *a3)
{
const char *v3; // r12
int v5; // eax
_DWORD *v6; // rbx
const char *v7; // r8
char *v8; // rax
const char *v9; // r8
void **v10; // r15
const char *v11; // r13
__int64 v12; // r15
__int64 v13; // rdi
const char *v15; // r8
char *v16; // rax
int v17; // [rsp+4h] [rbp-154h]
const char *v18; // [rsp+10h] [rbp-148h]
const char *v19; // [rsp+18h] [rbp-140h]
const char *v20; // [rsp+18h] [rbp-140h]
char s[312]; // [rsp+20h] [rbp-138h] BYREF

snprintf(s, 0x100uLL, "%sDirectory", a3);
v18 = (const char *)plugin_config_get_string("LEDConfigHybris", s, 0LL);
v5 = *a1;
if ( !*a1 )
{
LODWORD(v3) = 0;
goto LABEL_13;
}
v17 = 0;
v6 = a1 + 8;
do
{
while ( 1 )
{
v11 = (const char *)*((_QWORD *)v6 - 3);
v12 = *((_QWORD *)v6 - 1);
if ( v5 != 1 )
{
if ( v5 == 2 )
{
snprintf(s, 0x100uLL, "%s%s", a3, *((const char **)v6 - 3));
v7 = (const char *)plugin_config_get_string("LEDConfigHybris", s, 0LL);
if ( v7
|| (snprintf(s, 0x100uLL, "%s", v11),
(v7 = (const char *)plugin_config_get_string("LEDConfigHybris", s, *((_QWORD *)v6 - 2))) != 0LL) )
{
v19 = v7;
v8 = strdup(v7);
v9 = v19;
v3 = v8;
goto LABEL_5;
}
}
goto LABEL_10;
}
snprintf(s, 0x100uLL, "%s%sFile", a3, *((const char **)v6 - 3));
v15 = (const char *)plugin_config_get_string("LEDConfigHybris", s, 0LL);
if ( v15 )
break;
if ( v18 )
{
snprintf(s, 0x100uLL, "%sFile", v11);
v15 = (const char *)plugin_config_get_string("LEDConfigHybris", s, 0LL);
}
if ( v15 )
break;
v13 = *((_QWORD *)v6 - 2);
if ( !v13 )
goto LABEL_11;
v15 = (const char *)g_strdup(v13);
if ( v15 )
break;
LABEL_10:
v13 = 0LL;
LABEL_11:
g_free(v13);
v5 = *v6;
v6 += 8;
if ( !v5 )
goto LABEL_12;
}
v20 = v15;
snprintf(s, 0x100uLL, "%s/%s", v18, v15);
v16 = strdup(s);
v9 = v20;
v3 = v16;
LABEL_5:
g_free(v9);
if ( v3 )
{
++v17;
v10 = (void **)lea(a2, v12);
free(*v10);
*v10 = (void *)v3;
mce_hybris_log(7LL, "plugin-config.c", "objconf_parse", "%s:%s = %s", a3, v11, v3);
}
v5 = *v6;
v6 += 8;
}
while ( v5 );
LABEL_12:
LOBYTE(v3) = v17 > 0;
LABEL_13:
g_free(v18);
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, __int64 a2, const char *a3)
{
const char *v3; // r12
int v5; // eax
_DWORD *v6; // rbx
const char *v7; // r8
char *v8; // rax
const char *v9; // r8
void **v10; // r15
const char *v11; // r13
__int64 v12; // r15
__int64 v13; // rdi
const char *v15; // r8
char *v16; // rax
int v17; // [rsp+4h] [rbp-154h]
const char *v18; // [rsp+10h] [rbp-148h]
const char *v19; // [rsp+18h] [rbp-140h]
const char *v20; // [rsp+18h] [rbp-140h]
char s[312]; // [rsp+20h] [rbp-138h] BYREF

snprintf(s, 0x100uLL, "%sDirectory", a3);
v18 = (const char *)func1("LEDConfigHybris", s, 0LL);
v5 = *a1;
if ( !*a1 )
{
LODWORD(v3) = 0;
goto LABEL_13;
}
v17 = 0;
v6 = a1 + 8;
do
{
while ( 1 )
{
v11 = (const char *)*((_QWORD *)v6 - 3);
v12 = *((_QWORD *)v6 - 1);
if ( v5 != 1 )
{
if ( v5 == 2 )
{
snprintf(s, 0x100uLL, "%s%s", a3, *((const char **)v6 - 3));
v7 = (const char *)func1("LEDConfigHybris", s, 0LL);
if ( v7
|| (snprintf(s, 0x100uLL, "%s", v11),
(v7 = (const char *)func1("LEDConfigHybris", s, *((_QWORD *)v6 - 2))) != 0LL) )
{
v19 = v7;
v8 = strdup(v7);
v9 = v19;
v3 = v8;
goto LABEL_5;
}
}
goto LABEL_10;
}
snprintf(s, 0x100uLL, "%s%sFile", a3, *((const char **)v6 - 3));
v15 = (const char *)func1("LEDConfigHybris", s, 0LL);
if ( v15 )
break;
if ( v18 )
{
snprintf(s, 0x100uLL, "%sFile", v11);
v15 = (const char *)func1("LEDConfigHybris", s, 0LL);
}
if ( v15 )
break;
v13 = *((_QWORD *)v6 - 2);
if ( !v13 )
goto LABEL_11;
v15 = (const char *)g_strdup(v13);
if ( v15 )
break;
LABEL_10:
v13 = 0LL;
LABEL_11:
g_free(v13);
v5 = *v6;
v6 += 8;
if ( !v5 )
goto LABEL_12;
}
v20 = v15;
snprintf(s, 0x100uLL, "%s/%s", v18, v15);
v16 = strdup(s);
v9 = v20;
v3 = v16;
LABEL_5:
g_free(v9);
if ( v3 )
{
++v17;
v10 = (void **)func0(a2, v12);
free(*v10);
*v10 = (void *)v3;
mce_hybris_log(7LL, "plugin-config.c", "objconf_parse", "%s:%s = %s", a3, v11, v3);
}
v5 = *v6;
v6 += 8;
}
while ( v5 );
LABEL_12:
LOBYTE(v3) = v17 > 0;
LABEL_13:
g_free(v18);
return (unsigned int)v3;
}

original_code:
_Bool
objconf_parse(const objconf_t *cfg, void *obj, const char *chn)
{
    int set = 0;
    gchar *dir = 0;
    char tmp[256];
    snprintf(tmp, sizeof tmp, "%sDirectory", chn);
    dir = plugin_config_get_string("LEDConfigHybris", tmp, 0);
    for( size_t i = 0; cfg[i].type != CONFTYPE_NONE; ++i ) {
        const char *ini_key = cfg[i].key;
        gchar *ini_value = 0;
        char **cfg_member = lea(obj, cfg[i].off);
        char *cfg_value = 0;
        switch( cfg[i].type ) {
        case CONFTYPE_FILE:
            snprintf(tmp, sizeof tmp, "%s%sFile", chn, ini_key);
            ini_value = plugin_config_get_string("LEDConfigHybris",
                                           tmp, 0);
            if( !ini_value && dir ) {
                snprintf(tmp, sizeof tmp, "%sFile", ini_key);
                ini_value = plugin_config_get_string("LEDConfigHybris",
                                               tmp, 0);
            }
            if( !ini_value && cfg[i].def ) {
                ini_value = g_strdup(cfg[i].def);
            }
            if( ini_value ) {
                snprintf(tmp, sizeof tmp, "%s/%s", dir, ini_value);
                cfg_value = strdup(tmp);
            }
            break;
        case CONFTYPE_STRING:
            snprintf(tmp, sizeof tmp, "%s%s", chn, ini_key);
            ini_value = plugin_config_get_string("LEDConfigHybris",
                                           tmp, 0);
            if( !ini_value ) {
                snprintf(tmp, sizeof tmp, "%s", ini_key);
                ini_value = plugin_config_get_string("LEDConfigHybris",
                                               tmp, cfg[i].def);
            }
            if( ini_value )
                cfg_value = strdup(ini_value);
            break;
        default:
            break;
        }
        g_free(ini_value);
        if( cfg_value ) {
            ++set, free(*cfg_member), *cfg_member = cfg_value;
            mce_hybris_log(7, "plugin-config.c", __FUNCTION__ ,"%s:%s = %s", chn, ini_key, *cfg_member ?: "NA");
        }
    }
    g_free(dir);
    return set > 0;
}

canonical_original_code:
_Bool objconf_parse(struct objconf_t *cfg, void *obj, char *chn)
{
    int set = 0;
    char *dir = 0;
    char tmp[256];
    snprintf(tmp, sizeof tmp, "%sDirectory", chn);
    dir = plugin_config_get_string("LEDConfigHybris", tmp, 0);
    for( unsigned long i = 0; cfg[i].type != CONFTYPE_NONE; ++i ) {
        char *ini_key = cfg[i].key;
        char *ini_value = 0;
        char **cfg_member = lea(obj, cfg[i].off);
        char *cfg_value = 0;
        switch( cfg[i].type ) {
        case CONFTYPE_FILE:
            snprintf(tmp, sizeof tmp, "%s%sFile", chn, ini_key);
            ini_value = plugin_config_get_string("LEDConfigHybris",
                                           tmp, 0);
            if( !ini_value && dir ) {
                snprintf(tmp, sizeof tmp, "%sFile", ini_key);
                ini_value = plugin_config_get_string("LEDConfigHybris",
                                               tmp, 0);
            }
            if( !ini_value && cfg[i].def ) {
                ini_value = g_strdup(cfg[i].def);
            }
            if( ini_value ) {
                snprintf(tmp, sizeof tmp, "%s/%s", dir, ini_value);
                cfg_value = strdup(tmp);
            }
            break;
        case CONFTYPE_STRING:
            snprintf(tmp, sizeof tmp, "%s%s", chn, ini_key);
            ini_value = plugin_config_get_string("LEDConfigHybris",
                                           tmp, 0);
            if( !ini_value ) {
                snprintf(tmp, sizeof tmp, "%s", ini_key);
                ini_value = plugin_config_get_string("LEDConfigHybris",
                                               tmp, cfg[i].def);
            }
            if( ini_value )
                cfg_value = strdup(ini_value);
            break;
        default:
            break;
        }
        g_free(ini_value);
        if( cfg_value ) {
            ++set, free(*cfg_member), *cfg_member = cfg_value;
            mce_hybris_log(7, "plugin-config.c", __FUNCTION__ ,"%s:%s = %s", chn, ini_key, *cfg_member ?: "NA");
        }
    }
    g_free(dir);
    return set > 0;
}

variable_types:
chn
char *

variable_types: set int

variable_types:
dir
char *

variable_types:
tmp
char [256]


decompiled_code:
__int64 __fastcall led_channel_hammerhead_close(__int64 a1)
{
led_util_close_file(a1 + 4);
led_util_close_file(a1 + 8);
return led_util_close_file(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
led_util_close_file(a1 + 4);
led_util_close_file(a1 + 8);
return led_util_close_file(a1 + 12);
}

original_code:
static void
led_channel_hammerhead_close(led_channel_hammerhead_t *self)
{
  led_util_close_file(&self->fd_brightness);
  led_util_close_file(&self->fd_on_off_ms);
  led_util_close_file(&self->fd_rgb_start);
}

canonical_original_code:
static void led_channel_hammerhead_close(struct led_channel_hammerhead_t *self)
{
  led_util_close_file(&self->fd_brightness);
  led_util_close_file(&self->fd_on_off_ms);
  led_util_close_file(&self->fd_rgb_start);
}

variable_types: struct led_channel_hammerhead_t { int cached_max_brightness; int fd_brightness; int fd_on_off_ms; int fd_rgb_start; } *