decompiled_code:
__int64 __fastcall config_get_int(__int64 a1, const char *a2, const char *a3, unsigned int a4)
{
const char *v5; // rax
__int64 result; // rax
unsigned int v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5 = (const char *)config_get(a1, a2, a3, 0LL);
if ( !v5 || (unsigned int)string_to_int(v5, v7) )
result = a4;
else
result = v7[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2, const char *a3, unsigned int a4)
{
const char *v5; // rax
__int64 result; // rax
unsigned int v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5 = (const char *)func6(a1, a2, a3, 0LL);
if ( !v5 || (unsigned int)func1(v5, v7) )
result = a4;
else
result = v7[0];
return result;
}

original_code:
int config_get_int(struct config_file *f,
     const char *section,
     const char *item,
     int _default)
{
 const char *value;
 int i;
 value = config_get(f, section, item, ((void *)0));
 if (!value)
  return _default;
 if (string_to_int(value, &i))
  return _default;
 return i;
}

canonical_original_code:
int config_get_int(struct config_file *f, char *section, char *item, int _default)
{
 char *value;
 int i;
 value = config_get(f, section, item, ((void *)0));
 if (!value)
  return _default;
 if (string_to_int(value, &i))
  return _default;
 return i;
}

variable_types:
value
char *

variable_types: i int


repo: mbuesch/pwrtray

decompiled_code:
__int64 __fastcall config_get_bool(__int64 a1, const char *a2, const char *a3, unsigned int a4)
{
const char *v5; // rax
const char *v6; // rbp
unsigned int v7; // er12
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5 = (const char *)config_get(a1, a2, a3, 0LL);
if ( !v5 )
return a4;
v6 = v5;
if ( !(unsigned int)string_to_int(v5, v9) )
return v9[0] != 0;
v7 = 1;
if ( strcasecmp(v6, "yes") )
{
if ( strcasecmp(v6, "true") )
{
if ( strcasecmp(v6, "on") )
{
v7 = strcasecmp(v6, "no");
if ( v7 )
{
v7 = strcasecmp(v6, "false");
if ( v7 )
{
v7 = strcasecmp(v6, "off");
if ( v7 )
return a4;
}
}
}
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2, const char *a3, unsigned int a4)
{
const char *v5; // rax
const char *v6; // rbp
unsigned int v7; // er12
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5 = (const char *)func6(a1, a2, a3, 0LL);
if ( !v5 )
return a4;
v6 = v5;
if ( !(unsigned int)func1(v5, v9) )
return v9[0] != 0;
v7 = 1;
if ( strcasecmp(v6, "yes") )
{
if ( strcasecmp(v6, "true") )
{
if ( strcasecmp(v6, "on") )
{
v7 = strcasecmp(v6, "no");
if ( v7 )
{
v7 = strcasecmp(v6, "false");
if ( v7 )
{
v7 = strcasecmp(v6, "off");
if ( v7 )
return a4;
}
}
}
}
}
return v7;
}

original_code:
int config_get_bool(struct config_file *f,
      const char *section,
      const char *item,
      int _default)
{
 const char *value;
 int i;
 value = config_get(f, section, item, ((void *)0));
 if (!value)
  return _default;
 if (!string_to_int(value, &i))
  return !!i;
 if (strcasecmp(value, "yes") == 0 ||
     strcasecmp(value, "true") == 0 ||
     strcasecmp(value, "on") == 0)
  return 1;
 if (strcasecmp(value, "no") == 0 ||
     strcasecmp(value, "false") == 0 ||
     strcasecmp(value, "off") == 0)
  return 0;
 return _default;
}

canonical_original_code:
int config_get_bool(struct config_file *f, char *section, char *item, int _default)
{
 char *value;
 int i;
 value = config_get(f, section, item, ((void *)0));
 if (!value)
  return _default;
 if (!string_to_int(value, &i))
  return !!i;
 if (strcasecmp(value, "yes") == 0 ||
     strcasecmp(value, "true") == 0 ||
     strcasecmp(value, "on") == 0)
  return 1;
 if (strcasecmp(value, "no") == 0 ||
     strcasecmp(value, "false") == 0 ||
     strcasecmp(value, "off") == 0)
  return 0;
 return _default;
}

variable_types: struct config_file { struct config_section { struct config_file *file; char *name; struct config_item { struct config_section *section; char *name; char *value; struct config_item *next; } *item_hashtab[-1]; struct config_section *next; } *section_hashtab[-1]; } *

variable_types:
section
char *

variable_types:
item
char *

return_type: int

user_defined_types: struct config_file { struct config_section *section_hashtab[-1]; }

user_defined_types: struct config_section { struct config_file *file; char *name; struct config_item *item_hashtab[-1]; struct config_section *next; }


decompiled_code:
void __fastcall config_file_free(void *ptr)
{
void *v1; // r13
char *v2; // r12
char *v3; // rbp
_QWORD *v4; // rbx
void *v5; // rdi

if ( ptr )
{
v1 = ptr;
v2 = (char *)ptr + 256;
v3 = (char *)ptr;
do
{
v4 = *(_QWORD **)v3;
if ( *(_QWORD *)v3 )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[34];
free_section(v5);
}
while ( v4 );
}
v3 += 8;
}
while ( v3 != v2 );
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
void *v1; // r13
char *v2; // r12
char *v3; // rbp
_QWORD *v4; // rbx
void *v5; // rdi

if ( ptr )
{
v1 = ptr;
v2 = (char *)ptr + 256;
v3 = (char *)ptr;
do
{
v4 = *(_QWORD **)v3;
if ( *(_QWORD *)v3 )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[34];
func3(v5);
}
while ( v4 );
}
v3 += 8;
}
while ( v3 != v2 );
free(v1);
}
}

original_code:
void config_file_free(struct config_file *f)
{
 unsigned int i;
 struct config_section *s, *next;
 if (f) {
  for (i = 0; i < (1 << 5); i++) {
   for (s = f->section_hashtab[i]; s; s = next) {
    next = s->next;
    free_section(s);
   }
  }
  free(f);
 }
}

canonical_original_code:
void config_file_free(struct config_file *f)
{
 unsigned int i;
 struct config_section *s; struct config_section *next;
 if (f) {
  for (i = 0; i < (1 << 5); i++) {
   for (s = f->section_hashtab[i]; s; s = next) {
    next = s->next;
    free_section(s);
   }
  }
  free(f);
 }
}

variable_types:
i
unsigned int

variable_types: struct config_section { struct config_file { struct config_section *section_hashtab[-1]; } *file; char *name; struct config_item { struct config_section *section; char *name; char *value; struct config_item *next; } *item_hashtab[-1]; struct config_section *next; } *

return_type: void


decompiled_code:
void default_event()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void default_event(struct devicelock *s)
{
}

variable_types: struct devicelock { char *name; void (*destroy)(struct devicelock *s); void (*event)(struct devicelock *s); } *


decompiled_code:
const char **devicelock_probe()
{
__int64 (**v0)(void); // rbx
const char **v1; // rax
const char **v2; // r12

v0 = (__int64 (**)(void))&_start_probe_devicelock;
if ( &_start_probe_devicelock < (_UNKNOWN *)&_stop_probe_devicelock )
{
while ( 1 )
{
print_probe_message(v0);
v1 = (const char **)v0[1]();
v2 = v1;
if ( v1 )
break;
v0 += 4;
if ( v0 >= &_stop_probe_devicelock )
goto LABEL_7;
}
if ( *((int *)&cmdargs + 1) > 1 )
{
logdebug("Initialized devicelock driver \"%s\"\n", *v1);
return v2;
}
}
else
{
LABEL_7:
v2 = 0LL;
logerr("Failed to find any devicelock controls.\n");
}
return v2;
}

canonical_decompiled_code:
const char **func1()
{
__int64 (**v0)(void); // rbx
const char **v1; // rax
const char **v2; // r12

v0 = (__int64 (**)(void))&_start_probe_devicelock;
if ( &_start_probe_devicelock < (_UNKNOWN *)&_stop_probe_devicelock )
{
while ( 1 )
{
print_probe_message(v0);
v1 = (const char **)v0[1]();
v2 = v1;
if ( v1 )
break;
v0 += 4;
if ( v0 >= &_stop_probe_devicelock )
goto LABEL_7;
}
if ( *((int *)&cmdargs + 1) > 1 )
{
logdebug("Initialized devicelock driver \"%s\"\n", *v1);
return v2;
}
}
else
{
LABEL_7:
v2 = 0LL;
logerr("Failed to find any devicelock controls.\n");
}
return v2;
}

original_code:
struct devicelock * devicelock_probe(void)
{
 struct devicelock *s;
 const struct probe *probe;
 for (probe = &__start_probe_devicelock; probe < &__stop_probe_devicelock && ({ print_probe_message(probe); 1; }); probe++) {
  s = probe->func();
  if (s) {
   do { if ((cmdargs.loglevel >= LOGLEVEL_DEBUG)) _logdebug("Initialized devicelock driver \"%s\"\n", s->name); } while (0);
   return s;
  }
 }
 logerr("Failed to find any devicelock controls.\n");
 return ((void *)0);
}

canonical_original_code:
struct devicelock *devicelock_probe()
{
 struct devicelock *s;
 struct probe *probe;
 for (probe = &__start_probe_devicelock; probe < &__stop_probe_devicelock && ({ print_probe_message(probe); 1; }); probe++) {
  s = probe->func();
  if (s) {
   do { if ((cmdargs.loglevel >= LOGLEVEL_DEBUG)) _logdebug("Initialized devicelock driver \"%s\"\n", s->name); } while (0);
   return s;
  }
 }
 logerr("Failed to find any devicelock controls.\n");
 return ((void *)0);
}

variable_types: struct probe { char *name; void *(*func)(); char *func_name; int __end[]; } *

return_type: struct devicelock { char *name; void (*destroy)(struct devicelock *s); void (*event)(struct devicelock *s); } *


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

if ( a1 )
result = (*(__int64 (**)(void))(a1 + 8))();
return result;
}

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

if ( a1 )
result = (*(__int64 (**)(void))(a1 + 8))();
return result;
}

original_code:
void devicelock_destroy(struct devicelock *s)
{
 if (s)
  s->destroy(s);
}

user_defined_types: struct devicelock { char *name; void (*destroy)(struct devicelock *s); void (*event)(struct devicelock *s); }


strempty

decompiled_code:
_BOOL8 __fastcall strempty(_BYTE *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1 )
result = *a1 == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_BYTE *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1 )
result = *a1 == 0;
return result;
}

original_code:
static inline int strempty(const char *s)
{
 return (s == ((void *)0)) || (s[0] == '\0');
}

canonical_original_code:
static inline int strempty(char *s)
{
 return (s == ((void *)0)) || (s[0] == '\0');
}

variable_types:
s
char *


msleep

decompiled_code:
int __fastcall msleep(unsigned int a1)
{
__int64 v1; // rax
__time_t v2; // rdx
int v3; // edi
int result; // eax
char *v5; // rax
struct timespec v6; // [rsp+0h] [rbp-18h] BYREF

v6.tv_sec = 0LL;
if ( a1 > 0x3E7 )
{
v1 = 1LL;
do
{
a1 -= 1000;
v2 = v1++;
}
while ( a1 > 0x3E7 );
v6.tv_sec = v2;
}
v6.tv_nsec = 1000000LL * a1;
while ( 1 )
{
result = nanosleep(&v6, &v6);
if ( !result )
break;
v3 = *_errno_location();
if ( v3 != 4 )
{
v5 = strerror(v3);
return fprintf(stderr, "nanosleep() failed with: %s\n", v5);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
__int64 v1; // rax
__time_t v2; // rdx
int v3; // edi
int result; // eax
char *v5; // rax
struct timespec v6; // [rsp+0h] [rbp-18h] BYREF

v6.tv_sec = 0LL;
if ( a1 > 0x3E7 )
{
v1 = 1LL;
do
{
a1 -= 1000;
v2 = v1++;
}
while ( a1 > 0x3E7 );
v6.tv_sec = v2;
}
v6.tv_nsec = 1000000LL * a1;
while ( 1 )
{
result = nanosleep(&v6, &v6);
if ( !result )
break;
v3 = *_errno_location();
if ( v3 != 4 )
{
v5 = strerror(v3);
return fprintf(stderr, "nanosleep() failed with: %s\n", v5);
}
}
return result;
}

original_code:
void msleep(unsigned int msecs)
{
 int err;
 struct timespec time;
 time.tv_sec = 0;
 while (msecs >= 1000) {
  time.tv_sec++;
  msecs -= 1000;
 }
 time.tv_nsec = msecs;
 time.tv_nsec *= 1000000;
 do {
  err = nanosleep(&time, &time);
 } while (err && (*__errno_location ()) == 4);
 if (err) {
  fprintf(stderr, "nanosleep() failed with: %s\n",
   strerror((*__errno_location ())));
 }
}

variable_types:
msecs
unsigned int

variable_types: err int

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


decompiled_code:
char *__fastcall string_strip(char *s)
{
__int64 v1; // rbx
char *v2; // r12
const unsigned __int16 *v3; // rax
size_t v4; // rbx
const unsigned __int16 **v5; // rcx

if ( !s )
return 0LL;
v1 = *s;
v2 = s;
if ( (_BYTE)v1 )
{
v3 = *_ctype_b_loc();
do
{
if ( (v3[v1] & 0x2000) == 0 )
break;
v1 = *++v2;
}
while ( (_BYTE)v1 );
}
v4 = strlen(v2);
if ( v4 )
{
v5 = _ctype_b_loc();
do
{
if ( ((*v5)[v2[--v4]] & 0x2000) == 0 )
break;
v2[v4] = 0;
}
while ( v4 );
}
return v2;
}

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

if ( !s )
return 0LL;
v1 = *s;
v2 = s;
if ( (_BYTE)v1 )
{
v3 = *_ctype_b_loc();
do
{
if ( (v3[v1] & 0x2000) == 0 )
break;
v1 = *++v2;
}
while ( (_BYTE)v1 );
}
v4 = strlen(v2);
if ( v4 )
{
v5 = _ctype_b_loc();
do
{
if ( ((*v5)[v2[--v4]] & 0x2000) == 0 )
break;
v2[v4] = 0;
}
while ( v4 );
}
return v2;
}

original_code:
char * string_strip(char *str)
{
 char *start = str;
 size_t len;
 if (!str)
  return ((void *)0);
 while (*start != '\0' && ((*__ctype_b_loc ())[(int) ((*start))] & (unsigned short int) _ISspace))
  start++;
 len = strlen(start);
 while (len && ((*__ctype_b_loc ())[(int) ((start[len - 1]))] & (unsigned short int) _ISspace)) {
  start[len - 1] = '\0';
  len--;
 }
 return start;
}

canonical_original_code:
char *string_strip(char *str)
{
 char *start = str;
 unsigned long len;
 if (!str)
  return ((void *)0);
 while (*start != '\0' && ((*__ctype_b_loc ())[(int) ((*start))] & (unsigned short) _ISspace))
  start++;
 len = strlen(start);
 while (len && ((*__ctype_b_loc ())[(int) ((start[len - 1]))] & (unsigned short) _ISspace)) {
  start[len - 1] = '\0';
  len--;
 }
 return start;
}

variable_types:
str
char *

variable_types:
start
char *

variable_types:
len
unsigned long

return_type: char *


decompiled_code:
__int64 __fastcall tiny_hash(unsigned __int8 *a1)
{
int v1; // eax
unsigned __int8 *v2; // rdx
unsigned int i; // er8

v1 = *a1;
v2 = a1 + 1;
for ( i = 21; (_BYTE)v1; v1 = *(v2 - 1) )
{
++v2;
i += v1 + 8 * i;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1)
{
int v1; // eax
unsigned __int8 *v2; // rdx
unsigned int i; // er8

v1 = *a1;
v2 = a1 + 1;
for ( i = 21; (_BYTE)v1; v1 = *(v2 - 1) )
{
++v2;
i += v1 + 8 * i;
}
return i;
}

original_code:
uint_fast8_t tiny_hash(const char *str)
{
 uint8_t c, hash = 21;
 while ((c = *str++) != '\0')
  hash = ((hash << 3) + hash) + c;
 return hash;
}

canonical_original_code:
unsigned char tiny_hash(char *str)
{
 unsigned char c; unsigned char hash = 21;
 while ((c = *str++) != '\0')
  hash = ((hash << 3) + hash) + c;
 return hash;
}

variable_types:
c
unsigned char

variable_types:
hash
unsigned char

return_type: unsigned char


decompiled_code:
__pid_t __fastcall subprocess_exec(char *s)
{
size_t v1; // rax
__pid_t result; // eax
unsigned int v3; // eax
int v4; // ebp
char *v5; // r8
int *v6; // rax
char *v7; // rax
int *v8; // rbx
char *v9; // rax
char *argv[32]; // [rsp+8h] [rbp-1118h] BYREF
__int128 v11; // [rsp+108h] [rbp-1018h] BYREF
char v12[4080]; // [rsp+118h] [rbp-1008h] BYREF

memset(v12, 0, sizeof(v12));
v11 = 0LL;
memset(argv, 0, sizeof(argv));
v1 = strlen(s);
if ( v1 <= 0xFFE )
{
v3 = v1 + 1;
if ( v3 < 8 )
{
if ( (v3 & 4) != 0 )
{
LODWORD(v11) = *(_DWORD *)s;
*(_DWORD *)((char *)&v11 + v3 - 4) = *(_DWORD *)&s[v3 - 4];
}
else if ( v3 )
{
LOBYTE(v11) = *s;
if ( (v3 & 2) != 0 )
*(_WORD *)((char *)&v11 + v3 - 2) = *(_WORD *)&s[v3 - 2];
}
}
else
{
*(_QWORD *)((char *)&v11 + v3 - 8) = *(_QWORD *)&s[v3 - 8];
qmemcpy(&v11, s, 8LL * ((v3 - 1) >> 3));
}
v4 = 0;
v5 = (char *)&v11;
while ( 1 )
{
while ( 1 )
{
argv[v4] = v5;
string_split(v5, (__int64 (*)(void))&isspace);
if ( !strempty(argv[v4]) )
break;
argv[v4] = 0LL;
if ( !v5 )
goto LABEL_9;
}
if ( !v5 )
break;
if ( ++v4 == 31 )
{
logerr("subprocess_exec: Too many arguments: '%s'\n", s);
return -22;
}
}
LABEL_9:
if ( !argv[0] )
{
logerr("subprocess_exec: Too few arguments\n", 0.0);
return -22;
}
result = vfork();
if ( result < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
logerr("subprocess_exec: Failed to fork (%s)\n", v9);
result = -*v8;
}
else if ( !result )
{
execv(argv[0], argv);
v6 = _errno_location();
v7 = strerror(*v6);
logerr("subprocess_exec: Failed to exec '%s': %s\n", s, v7);
exit(0);
}
}
else
{
logerr("subprocess_exec: Command too long", 0.0);
result = -7;
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func4(char *s)
{
size_t v1; // rax
__pid_t result; // eax
unsigned int v3; // eax
int v4; // ebp
char *v5; // r8
int *v6; // rax
char *v7; // rax
int *v8; // rbx
char *v9; // rax
char *argv[32]; // [rsp+8h] [rbp-1118h] BYREF
__int128 v11; // [rsp+108h] [rbp-1018h] BYREF
char v12[4080]; // [rsp+118h] [rbp-1008h] BYREF

memset(v12, 0, sizeof(v12));
v11 = 0LL;
memset(argv, 0, sizeof(argv));
v1 = strlen(s);
if ( v1 <= 0xFFE )
{
v3 = v1 + 1;
if ( v3 < 8 )
{
if ( (v3 & 4) != 0 )
{
LODWORD(v11) = *(_DWORD *)s;
*(_DWORD *)((char *)&v11 + v3 - 4) = *(_DWORD *)&s[v3 - 4];
}
else if ( v3 )
{
LOBYTE(v11) = *s;
if ( (v3 & 2) != 0 )
*(_WORD *)((char *)&v11 + v3 - 2) = *(_WORD *)&s[v3 - 2];
}
}
else
{
*(_QWORD *)((char *)&v11 + v3 - 8) = *(_QWORD *)&s[v3 - 8];
qmemcpy(&v11, s, 8LL * ((v3 - 1) >> 3));
}
v4 = 0;
v5 = (char *)&v11;
while ( 1 )
{
while ( 1 )
{
argv[v4] = v5;
string_split(v5, (__int64 (*)(void))&isspace);
if ( !func0(argv[v4]) )
break;
argv[v4] = 0LL;
if ( !v5 )
goto LABEL_9;
}
if ( !v5 )
break;
if ( ++v4 == 31 )
{
logerr("subprocess_exec: Too many arguments: '%s'\n", s);
return -22;
}
}
LABEL_9:
if ( !argv[0] )
{
logerr("subprocess_exec: Too few arguments\n", 0.0);
return -22;
}
result = vfork();
if ( result < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
logerr("subprocess_exec: Failed to fork (%s)\n", v9);
result = -*v8;
}
else if ( !result )
{
execv(argv[0], argv);
v6 = _errno_location();
v7 = strerror(*v6);
logerr("subprocess_exec: Failed to exec '%s': %s\n", s, v7);
exit(0);
}
}
else
{
logerr("subprocess_exec: Command too long", 0.0);
result = -7;
}
return result;
}

original_code:
pid_t subprocess_exec(const char *_command)
{
 char command_buf[4096] = { };
 char *command;
 char *argv[32] = { };
 unsigned int i;
 long err = 0;
 pid_t pid;
 if (strlen(_command) >= sizeof(command_buf) - 1) {
  logerr("subprocess_exec: Command too long");
  err = -7;
  goto out;
 }
 strcpy(command_buf, _command);
 command = command_buf;
 for (i = 0; i < (sizeof(argv) / sizeof((argv)[0])) - 1; i++) {
  argv[i] = command;
  command = string_split(command, isspace);
  if (strempty(argv[i])) {
   argv[i] = ((void *)0);
   i--;
  }
  if (!command)
   break;
 }
 if (command) {
  logerr("subprocess_exec: Too many arguments: '%s'\n", _command);
  err = -22;
  goto out;
 }
 if (!argv[0]) {
  logerr("subprocess_exec: Too few arguments\n");
  err = -22;
  goto out;
 }
 pid = vfork();
 if (pid < 0) {
  logerr("subprocess_exec: Failed to fork (%s)\n", strerror((*__errno_location ())));
  err = -(*__errno_location ());
  goto out;
 }
 if (pid == 0) {
  execv(argv[0], argv);
  logerr("subprocess_exec: Failed to exec '%s': %s\n",
         _command, strerror((*__errno_location ())));
  exit(0);
  while (1);
 }
 err = pid;
out:
 return err;
}

canonical_original_code:
int subprocess_exec(char *_command)
{
 char command_buf[4096] = { };
 char *command;
 char *argv[32] = { };
 unsigned int i;
 long err = 0;
 int pid;
 if (strlen(_command) >= sizeof(command_buf) - 1) {
  logerr("subprocess_exec: Command too long");
  err = -7;
  goto out;
 }
 strcpy(command_buf, _command);
 command = command_buf;
 for (i = 0; i < (sizeof(argv) / sizeof((argv)[0])) - 1; i++) {
  argv[i] = command;
  command = string_split(command, isspace);
  if (strempty(argv[i])) {
   argv[i] = ((void *)0);
   i--;
  }
  if (!command)
   break;
 }
 if (command) {
  logerr("subprocess_exec: Too many arguments: '%s'\n", _command);
  err = -22;
  goto out;
 }
 if (!argv[0]) {
  logerr("subprocess_exec: Too few arguments\n");
  err = -22;
  goto out;
 }
 pid = vfork();
 if (pid < 0) {
  logerr("subprocess_exec: Failed to fork (%s)\n", strerror((*__errno_location ())));
  err = -(*__errno_location ());
  goto out;
 }
 if (pid == 0) {
  execv(argv[0], argv);
  logerr("subprocess_exec: Failed to exec '%s': %s\n",
         _command, strerror((*__errno_location ())));
  exit(0);
  while (1);
 }
 err = pid;
out:
 return err;
}

variable_types:
command
char *

variable_types:
argv
char *[32]

variable_types: err long

variable_types: pid int


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

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

original_code:
static int backlight_dummy_max_brightness(struct backlight *b)
{
 return 0;
}

variable_types: struct backlight { char *name; int (*min_brightness)(struct backlight *b); int (*max_brightness)(struct backlight *b); int (*brightness_step)(struct backlight *b); int (*current_brightness)(struct backlight *b); int (*set_brightness)(struct backlight *b, int value); int (*screen_lock)(struct backlight *b, int lock); int (*screen_is_locked)(struct backlight *b); void (*destroy)(struct backlight *b); int (*update)(struct backlight *b); unsigned int poll_interval; int autodim_enabled; int autodim_enabled_on_ac; int framebuffer_fd; int fb_blanked; struct sleeptimer { char *name; struct timespec { long tv_sec; long tv_nsec; } timeout; void (*callback)(struct sleeptimer *timer); unsigned long id; struct list_head { struct list_head *next; struct list_head *prev; } list; } timer; } *

user_defined_types: struct backlight { char *name; int (*min_brightness)(struct backlight *b); int (*max_brightness)(struct backlight *b); int (*brightness_step)(struct backlight *b); int (*current_brightness)(struct backlight *b); int (*set_brightness)(struct backlight *b, int value); int (*screen_lock)(struct backlight *b, int lock); int (*screen_is_locked)(struct backlight *b); void (*destroy)(struct backlight *b); int (*update)(struct backlight *b); unsigned int poll_interval; int autodim_enabled; int autodim_enabled_on_ac; int framebuffer_fd; int fb_blanked; struct sleeptimer timer; }

user_defined_types: struct sleeptimer { char *name; struct timespec timeout; void (*callback)(struct sleeptimer *timer); unsigned long id; struct list_head list; }


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

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

original_code:
static void backlight_dummy_destroy(struct backlight *b)
{
 struct backlight_dummy *bd = ({ __typeof__(((struct backlight_dummy *)0)->backlight) *__mptr = (b); (struct backlight_dummy *)((char *)__mptr - ((size_t)&((struct backlight_dummy *)0)->backlight)); });
 free(bd);
}

variable_types: struct backlight_dummy { struct backlight { char *name; int (*min_brightness)(struct backlight *b); int (*max_brightness)(struct backlight *b); int (*brightness_step)(struct backlight *b); int (*current_brightness)(struct backlight *b); int (*set_brightness)(struct backlight *b, int value); int (*screen_lock)(struct backlight *b, int lock); int (*screen_is_locked)(struct backlight *b); void (*destroy)(struct backlight *b); int (*update)(struct backlight *b); unsigned int poll_interval; int autodim_enabled; int autodim_enabled_on_ac; int framebuffer_fd; int fb_blanked; struct sleeptimer { char *name; struct timespec { long tv_sec; long tv_nsec; } timeout; void (*callback)(struct sleeptimer *timer); unsigned long id; struct list_head { struct list_head *next; struct list_head *prev; } list; } timer; } backlight; } *

user_defined_types: struct backlight_dummy { struct backlight backlight; }


decompiled_code:
_QWORD *backlight_dummy_probe()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = zalloc_constprop_0();
v1 = v0;
if ( v0 )
{
backlight_init(v0, "dummy");
v1[2] = backlight_dummy_max_brightness;
v1[8] = backlight_dummy_destroy;
}
return v1;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = func2();
v1 = v0;
if ( v0 )
{
backlight_init(v0, "dummy");
v1[2] = backlight_dummy_max_brightness;
v1[8] = backlight_dummy_destroy;
}
return v1;
}

original_code:
static struct backlight * backlight_dummy_probe(void)
{
 struct backlight_dummy *bd;
 bd = zalloc(sizeof(*bd));
 if (!bd)
  return ((void *)0);
 backlight_init(&bd->backlight, "dummy");
 bd->backlight.max_brightness = backlight_dummy_max_brightness;
 bd->backlight.destroy = backlight_dummy_destroy;
 return &bd->backlight;
}

canonical_original_code:
static struct backlight *backlight_dummy_probe()
{
 struct backlight_dummy *bd;
 bd = zalloc(sizeof(*bd));
 if (!bd)
  return ((void *)0);
 backlight_init(&bd->backlight, "dummy");
 bd->backlight.max_brightness = backlight_dummy_max_brightness;
 bd->backlight.destroy = backlight_dummy_destroy;
 return &bd->backlight;
}

return_type: struct backlight { char *name; int (*min_brightness)(struct backlight *b); int (*max_brightness)(struct backlight *b); int (*brightness_step)(struct backlight *b); int (*current_brightness)(struct backlight *b); int (*set_brightness)(struct backlight *b, int value); int (*screen_lock)(struct backlight *b, int lock); int (*screen_is_locked)(struct backlight *b); void (*destroy)(struct backlight *b); int (*update)(struct backlight *b); unsigned int poll_interval; int autodim_enabled; int autodim_enabled_on_ac; int framebuffer_fd; int fb_blanked; struct sleeptimer { char *name; struct timespec { long tv_sec; long tv_nsec; } timeout; void (*callback)(struct sleeptimer *timer); unsigned long id; struct list_head { struct list_head *next; struct list_head *prev; } list; } timer; } *


decompiled_code:
void __fastcall list_del(__int64 a1)
{
_QWORD *v1; // rax

_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
*v1 = 0LL;
v1[1] = 0LL;
}

original_code:
static inline void list_del(struct list_head *entry)
{
 __list_del(entry->prev, entry->next);
 entry->next = ((void *)0);
 entry->prev = ((void *)0);
}

variable_types: struct list_head { struct list_head *next; struct list_head *prev; } *


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

if ( a1 )
{
if ( *((int *)&cmdargs + 1) > 1 )
result = logdebug(
"Probing '%s' (%s @ %p)\n",
*(const char **)a1,
*(const char **)(a1 + 16),
*(const void **)(a1 + 8));
}
return result;
}

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

if ( a1 )
{
if ( *((int *)&cmdargs + 1) > 1 )
result = logdebug(
"Probing '%s' (%s @ %p)\n",
*(const char **)a1,
*(const char **)(a1 + 16),
*(const void **)(a1 + 8));
}
return result;
}

original_code:
void print_probe_message(const struct probe *probe)
{
 if (probe) {
  do { if ((cmdargs.loglevel >= LOGLEVEL_DEBUG)) _logdebug("Probing '%s' (%s @ %p)\n", probe->name, probe->func_name, probe->func); } while (0);
 }
}

canonical_original_code:
void print_probe_message(struct probe *probe)
{
 if (probe) {
  do { if ((cmdargs.loglevel >= LOGLEVEL_DEBUG)) _logdebug("Probing '%s' (%s @ %p)\n", probe->name, probe->func_name, probe->func); } while (0);
 }
}

variable_types: struct probe { char *name; void *(*func)(); char *func_name; int __end[]; } *


strempty

variable_types:
s
char *


decompiled_code:
__int64 __fastcall autodim_handle_state(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = *(unsigned int *)(a1 + 84);
if ( (unsigned int)result < *(_DWORD *)(a1 + 108) )
{
v2 = *(_QWORD *)(a1 + 96);
*(_DWORD *)(a1 + 84) = result + 1;
result = autodim_set_backlight(a1, *(_DWORD *)(v2 + 8LL * (unsigned int)result + 4));
}
return result;
}

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

result = *(unsigned int *)(a1 + 84);
if ( (unsigned int)result < *(_DWORD *)(a1 + 108) )
{
v2 = *(_QWORD *)(a1 + 96);
*(_DWORD *)(a1 + 84) = result + 1;
result = func1(a1, *(_DWORD *)(v2 + 8LL * (unsigned int)result + 4));
}
return result;
}

original_code:
static void autodim_handle_state(struct autodim *ad)
{
 struct autodim_step *step;
 if (ad->state < ad->nr_steps) {
  step = &ad->steps[ad->state];
  ad->state++;
  autodim_set_backlight(ad, step->percent);
 }
}

variable_types: struct autodim { struct backlight { char *name; int (*min_brightness)(struct backlight *b); int (*max_brightness)(struct backlight *b); int (*brightness_step)(struct backlight *b); int (*current_brightness)(struct backlight *b); int (*set_brightness)(struct backlight *b, int value); int (*screen_lock)(struct backlight *b, int lock); int (*screen_is_locked)(struct backlight *b); void (*destroy)(struct backlight *b); int (*update)(struct backlight *b); unsigned int poll_interval; int autodim_enabled; int autodim_enabled_on_ac; int framebuffer_fd; int fb_blanked; struct sleeptimer { char *name; struct timespec { long tv_sec; long tv_nsec; } timeout; void (*callback)(struct sleeptimer *timer); unsigned long id; struct list_head { struct list_head *next; struct list_head *prev; } list; } timer; } *bl; int *fds; unsigned int nr_fds; struct sleeptimer timer; int suspended; unsigned int state; unsigned int bl_percent; unsigned int max_percent; struct autodim_step { unsigned int second; unsigned int percent; } *steps; unsigned int nr_allocated_steps; unsigned int nr_steps; } *

user_defined_types: struct autodim { struct backlight *bl; int *fds; unsigned int nr_fds; struct sleeptimer timer; int suspended; unsigned int state; unsigned int bl_percent; unsigned int max_percent; struct autodim_step *steps; unsigned int nr_allocated_steps; unsigned int nr_steps; }


decompiled_code:
__int64 __fastcall autodim_force_realloc_steps(__int64 a1, unsigned int a2)
{
void *v2; // rax
__int64 result; // rax

v2 = realloc(*(void **)(a1 + 96), 8LL * a2);
if ( v2 )
{
*(_DWORD *)(a1 + 104) = a2;
*(_QWORD *)(a1 + 96) = v2;
result = 0LL;
}
else
{
logerr("Out of memory\n");
result = 4294967284LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
void *v2; // rax
__int64 result; // rax

v2 = realloc(*(void **)(a1 + 96), 8LL * a2);
if ( v2 )
{
*(_DWORD *)(a1 + 104) = a2;
*(_QWORD *)(a1 + 96) = v2;
result = 0LL;
}
else
{
logerr("Out of memory\n");
result = 4294967284LL;
}
return result;
}

original_code:
static int autodim_force_realloc_steps(struct autodim *ad, unsigned int newcount)
{
 void *buf;
 buf = realloc(ad->steps, newcount * sizeof(*ad->steps));
 if (!buf) {
  logerr("Out of memory\n");
  return -12;
 }
 ad->steps = buf;
 ad->nr_allocated_steps = newcount;
 return 0;
}

variable_types:
newcount
unsigned int

variable_types:
buf
void *

user_defined_types: struct autodim_step { unsigned int second; unsigned int percent; }

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

user_defined_types: struct list_head { struct list_head *next; struct list_head *prev; }


decompiled_code:
__int64 __fastcall autodim_realloc_steps(__int64 a1, unsigned int a2)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 104) < a2 )
result = autodim_force_realloc_steps(a1, a2);
else
result = 0LL;
return result;
}

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

if ( *(_DWORD *)(a1 + 104) < a2 )
result = func3(a1, a2);
else
result = 0LL;
return result;
}

original_code:
static int autodim_realloc_steps(struct autodim *ad, unsigned int newcount)
{
 if (newcount > ad->nr_allocated_steps)
  return autodim_force_realloc_steps(ad, newcount);
 return 0;
}


original_code:
static int autodim_optimize_steps(struct autodim *ad)
{
 struct autodim_step *cur, *next;
 unsigned int i;
 int err;
 for (i = 0; ad->nr_steps && i < ad->nr_steps - 1; i++) {
  cur = &ad->steps[i];
  next = &ad->steps[i + 1];
  if (cur->percent == next->percent ||
      cur->second >= next->second) {
   memmove(&ad->steps[i + 1], &ad->steps[i + 2],
    (ad->nr_steps - i - 2) * sizeof(*cur));
   ad->nr_steps--;
  }
 }
 err = autodim_force_realloc_steps(ad, ad->nr_steps);
 if (err)
  return err;
 return 0;
}

canonical_original_code:
static int autodim_optimize_steps(struct autodim *ad)
{
 struct autodim_step *cur; struct autodim_step *next;
 unsigned int i;
 int err;
 for (i = 0; ad->nr_steps && i < ad->nr_steps - 1; i++) {
  cur = &ad->steps[i];
  next = &ad->steps[i + 1];
  if (cur->percent == next->percent ||
      cur->second >= next->second) {
   memmove(&ad->steps[i + 1], &ad->steps[i + 2],
    (ad->nr_steps - i - 2) * sizeof(*cur));
   ad->nr_steps--;
  }
 }
 err = autodim_force_realloc_steps(ad, ad->nr_steps);
 if (err)
  return err;
 return 0;
}

variable_types: struct autodim_step { unsigned int second; unsigned int percent; } *

variable_types:
i
unsigned int

variable_types: err int


decompiled_code:
__int64 __fastcall autodim_dump_steps(__int64 a1, const char *a2)
{
unsigned int v2; // edx
unsigned int v3; // ebx
__int64 v4; // rax
const char *v5; // rcx

loginfo("Autodim steps (%s): ", a2);
v2 = *(_DWORD *)(a1 + 108);
if ( v2 )
{
v3 = 0;
do
{
v4 = v3++;
v5 = " ";
if ( v3 == v2 )
v5 = (const char *)&unk_CB2;
loginfo(
"%u/%u%s",
*(unsigned int *)(*(_QWORD *)(a1 + 96) + 8 * v4),
*(unsigned int *)(*(_QWORD *)(a1 + 96) + 8 * v4 + 4),
v5);
v2 = *(_DWORD *)(a1 + 108);
}
while ( v3 < v2 );
}
return loginfo("\n");
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
unsigned int v2; // edx
unsigned int v3; // ebx
__int64 v4; // rax
const char *v5; // rcx

loginfo("Autodim steps (%s): ", a2);
v2 = *(_DWORD *)(a1 + 108);
if ( v2 )
{
v3 = 0;
do
{
v4 = v3++;
v5 = " ";
if ( v3 == v2 )
v5 = (const char *)&unk_CB2;
loginfo(
"%u/%u%s",
*(unsigned int *)(*(_QWORD *)(a1 + 96) + 8 * v4),
*(unsigned int *)(*(_QWORD *)(a1 + 96) + 8 * v4 + 4),
v5);
v2 = *(_DWORD *)(a1 + 108);
}
while ( v3 < v2 );
}
return loginfo("\n");
}

original_code:
static void autodim_dump_steps(struct autodim *ad, const char *info)
{
 unsigned int i;
 loginfo("Autodim steps (%s): ", info);
 for (i = 0; i < ad->nr_steps; i++) {
  loginfo("%u/%u%s", ad->steps[i].second, ad->steps[i].percent,
   (i + 1 == ad->nr_steps) ? "" : " ");
 }
 loginfo("\n");
}

canonical_original_code:
static void autodim_dump_steps(struct autodim *ad, char *info)
{
 unsigned int i;
 loginfo("Autodim steps (%s): ", info);
 for (i = 0; i < ad->nr_steps; i++) {
  loginfo("%u/%u%s", ad->steps[i].second, ad->steps[i].percent,
   (i + 1 == ad->nr_steps) ? "" : " ");
 }
 loginfo("\n");
}

variable_types:
info
char *


decompiled_code:
__int64 __fastcall autodim_steps_get(__int64 a1, __int64 a2)
{
const char *v2; // rax
char *v3; // rax
unsigned int v4; // ebx
char *i; // rbp
int v6; // eax
__int64 v7; // rdx
char *v8; // rax
char *v9; // r15
bool v10; // cc
char *ptr; // [rsp+0h] [rbp-48h]
unsigned int v13; // [rsp+8h] [rbp-40h]

v2 = (const char *)config_get(a2, "BACKLIGHT", "autodim_steps", "15/75 25/50 50/25 75/10");
v3 = strdup(v2);
ptr = v3;
if ( !v3 )
return 4294967284LL;
v4 = 0;
for ( i = (char *)string_strip(v3); ; i = (char *)string_strip(v9) )
{
v8 = strchr(i, 32);
v9 = v8;
if ( v8 )
{
*v8 = 0;
v9 = v8 + 1;
}
if ( strempty(i) )
break;
v6 = autodim_realloc_steps(a1, v4 + 1);
if ( v6 )
goto LABEL_21;
v7 = *(_QWORD *)(a1 + 96) + 8LL * v4;
if ( sscanf(i, "%u/%u", v7, v7 + 4) != 2 )
{
logerr("Failed to parse autodim_steps config value\n");
v6 = -22;
goto LABEL_21;
}
if ( v4 && *(_DWORD *)(*(_QWORD *)(a1 + 96) + 8LL * (v4 - 1)) >= *(_DWORD *)(*(_QWORD *)(a1 + 96) + 8LL * v4) )
{
logerr("Error: autodim_steps, previous step idle-seconds value bigger than adjacent value\n");
v6 = -22;
goto LABEL_21;
}
if ( !v9 )
{
++v4;
break;
}
++v4;
}
v10 = *((_DWORD *)&cmdargs + 1) <= 1;
*(_DWORD *)(a1 + 108) = v4;
if ( !v10 )
autodim_dump_steps(a1, "parsed-config");
if ( (unsigned int)config_get_bool(a2, "BACKLIGHT", "autodim_smooth", 0LL) )
{
v6 = autodim_smoothen_steps(a1);
if ( v6 )
goto LABEL_21;
if ( *((int *)&cmdargs + 1) > 1 )
autodim_dump_steps(a1, "smoothened");
}
v6 = autodim_optimize_steps(a1);
if ( !v6 && *((int *)&cmdargs + 1) > 1 )
{
autodim_dump_steps(a1, "optimized");
v6 = 0;
}
LABEL_21:
v13 = v6;
free(ptr);
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
const char *v2; // rax
char *v3; // rax
unsigned int v4; // ebx
char *i; // rbp
int v6; // eax
__int64 v7; // rdx
char *v8; // rax
char *v9; // r15
bool v10; // cc
char *ptr; // [rsp+0h] [rbp-48h]
unsigned int v13; // [rsp+8h] [rbp-40h]

v2 = (const char *)config_get(a2, "BACKLIGHT", "autodim_steps", "15/75 25/50 50/25 75/10");
v3 = strdup(v2);
ptr = v3;
if ( !v3 )
return 4294967284LL;
v4 = 0;
for ( i = (char *)string_strip(v3); ; i = (char *)string_strip(v9) )
{
v8 = strchr(i, 32);
v9 = v8;
if ( v8 )
{
*v8 = 0;
v9 = v8 + 1;
}
if ( func0(i) )
break;
v6 = func4(a1, v4 + 1);
if ( v6 )
goto LABEL_21;
v7 = *(_QWORD *)(a1 + 96) + 8LL * v4;
if ( sscanf(i, "%u/%u", v7, v7 + 4) != 2 )
{
logerr("Failed to parse autodim_steps config value\n");
v6 = -22;
goto LABEL_21;
}
if ( v4 && *(_DWORD *)(*(_QWORD *)(a1 + 96) + 8LL * (v4 - 1)) >= *(_DWORD *)(*(_QWORD *)(a1 + 96) + 8LL * v4) )
{
logerr("Error: autodim_steps, previous step idle-seconds value bigger than adjacent value\n");
v6 = -22;
goto LABEL_21;
}
if ( !v9 )
{
++v4;
break;
}
++v4;
}
v10 = *((_DWORD *)&cmdargs + 1) <= 1;
*(_DWORD *)(a1 + 108) = v4;
if ( !v10 )
func7(a1, "parsed-config");
if ( (unsigned int)config_get_bool(a2, "BACKLIGHT", "autodim_smooth", 0LL) )
{
v6 = func5(a1);
if ( v6 )
goto LABEL_21;
if ( *((int *)&cmdargs + 1) > 1 )
func7(a1, "smoothened");
}
v6 = func6(a1);
if ( !v6 && *((int *)&cmdargs + 1) > 1 )
{
func7(a1, "optimized");
v6 = 0;
}
LABEL_21:
v13 = v6;
free(ptr);
return v13;
}

original_code:
static int autodim_steps_get(struct autodim *ad, struct config_file *config)
{
 char *string, *s, *next;
 unsigned int stepnr = 0;
 int ret = 0;
 string = strdup(config_get(config, "BACKLIGHT", "autodim_steps",
       "15/75 25/50 50/25 75/10"));
 if (!string)
  return -12;
 s = string_strip(string);
 while (1) {
  next = strchr(s, ' ');
  if (next) {
   next[0] = '\0';
   next++;
  }
  if (strempty(s))
   break;
  ret = autodim_realloc_steps(ad, stepnr + 1);
  if (ret)
   goto out;
  if (sscanf(s, "%u/%u", &ad->steps[stepnr].second,
      &ad->steps[stepnr].percent) != 2) {
   logerr("Failed to parse autodim_steps config value\n");
   ret = -22;
   goto out;
  }
  if (stepnr > 0) {
   if (ad->steps[stepnr - 1].second >= ad->steps[stepnr].second) {
    logerr("Error: autodim_steps, previous step idle-seconds "
           "value bigger than adjacent value\n");
    ret = -22;
    goto out;
   }
  }
  stepnr++;
  if (!next)
   break;
  s = string_strip(next);
 }
 ad->nr_steps = stepnr;
 if ((cmdargs.loglevel >= LOGLEVEL_DEBUG))
  autodim_dump_steps(ad, "parsed-config");
 if (config_get_bool(config, "BACKLIGHT", "autodim_smooth", 0)) {
  ret = autodim_smoothen_steps(ad);
  if (ret)
   goto out;
  if ((cmdargs.loglevel >= LOGLEVEL_DEBUG))
   autodim_dump_steps(ad, "smoothened");
 }
 ret = autodim_optimize_steps(ad);
 if (ret)
  goto out;
 if ((cmdargs.loglevel >= LOGLEVEL_DEBUG))
  autodim_dump_steps(ad, "optimized");
out:
 free(string);
 return ret;
}

canonical_original_code:
static int autodim_steps_get(struct autodim *ad, struct config_file *config)
{
 char *string; char *s; char *next;
 unsigned int stepnr = 0;
 int ret = 0;
 string = strdup(config_get(config, "BACKLIGHT", "autodim_steps",
       "15/75 25/50 50/25 75/10"));
 if (!string)
  return -12;
 s = string_strip(string);
 while (1) {
  next = strchr(s, ' ');
  if (next) {
   next[0] = '\0';
   next++;
  }
  if (strempty(s))
   break;
  ret = autodim_realloc_steps(ad, stepnr + 1);
  if (ret)
   goto out;
  if (sscanf(s, "%u/%u", &ad->steps[stepnr].second,
      &ad->steps[stepnr].percent) != 2) {
   logerr("Failed to parse autodim_steps config value\n");
   ret = -22;
   goto out;
  }
  if (stepnr > 0) {
   if (ad->steps[stepnr - 1].second >= ad->steps[stepnr].second) {
    logerr("Error: autodim_steps, previous step idle-seconds "
           "value bigger than adjacent value\n");
    ret = -22;
    goto out;
   }
  }
  stepnr++;
  if (!next)
   break;
  s = string_strip(next);
 }
 ad->nr_steps = stepnr;
 if ((cmdargs.loglevel >= LOGLEVEL_DEBUG))
  autodim_dump_steps(ad, "parsed-config");
 if (config_get_bool(config, "BACKLIGHT", "autodim_smooth", 0)) {
  ret = autodim_smoothen_steps(ad);
  if (ret)
   goto out;
  if ((cmdargs.loglevel >= LOGLEVEL_DEBUG))
   autodim_dump_steps(ad, "smoothened");
 }
 ret = autodim_optimize_steps(ad);
 if (ret)
  goto out;
 if ((cmdargs.loglevel >= LOGLEVEL_DEBUG))
  autodim_dump_steps(ad, "optimized");
out:
 free(string);
 return ret;
}

variable_types: struct config_file { struct config_section { struct config_file *file; char *name; struct config_item { struct config_section *section; char *name; char *value; struct config_item *next; } *item_hashtab[-1]; struct config_section *next; } *section_hashtab[-1]; } *

variable_types:
string
char *

variable_types:
next
char *

variable_types:
stepnr
unsigned int

variable_types: ret int


decompiled_code:
__int64 __fastcall autodim_timer_start(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // er12

result = *(unsigned int *)(a1 + 84);
if ( !(_DWORD)result )
{
v2 = **(_DWORD **)(a1 + 96);
if ( *((int *)&cmdargs + 1) <= 2 )
{
LABEL_3:
sleeptimer_set_timeout_relative(a1 + 24, 1000 * v2);
return sleeptimer_enqueue(a1 + 24);
}
LABEL_6:
logdebug("autodim: Next event in %u sec\n", v2);
goto LABEL_3;
}
if ( (unsigned int)result < *(_DWORD *)(a1 + 108) )
{
v2 = *(_DWORD *)(*(_QWORD *)(a1 + 96) + 8LL * (unsigned int)result)
- *(_DWORD *)(*(_QWORD *)(a1 + 96) + 8LL * (unsigned int)(result - 1));
if ( *((int *)&cmdargs + 1) <= 2 )
goto LABEL_3;
goto LABEL_6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // er12

result = *(unsigned int *)(a1 + 84);
if ( !(_DWORD)result )
{
v2 = **(_DWORD **)(a1 + 96);
if ( *((int *)&cmdargs + 1) <= 2 )
{
LABEL_3:
sleeptimer_set_timeout_relative(a1 + 24, 1000 * v2);
return sleeptimer_enqueue(a1 + 24);
}
LABEL_6:
logdebug("autodim: Next event in %u sec\n", v2);
goto LABEL_3;
}
if ( (unsigned int)result < *(_DWORD *)(a1 + 108) )
{
v2 = *(_DWORD *)(*(_QWORD *)(a1 + 96) + 8LL * (unsigned int)result)
- *(_DWORD *)(*(_QWORD *)(a1 + 96) + 8LL * (unsigned int)(result - 1));
if ( *((int *)&cmdargs + 1) <= 2 )
goto LABEL_3;
goto LABEL_6;
}
return result;
}

original_code:
static void autodim_timer_start(struct autodim *ad)
{
 unsigned int sec;
 if (ad->state == 0)
  sec = ad->steps[0].second;
 else if (ad->state < ad->nr_steps)
  sec = ad->steps[ad->state].second - ad->steps[ad->state - 1].second;
 else
  return;
 do { if ((cmdargs.loglevel >= LOGLEVEL_VERBOSE)) _logdebug("autodim: Next event in %u sec\n", sec); } while (0);
 sleeptimer_set_timeout_relative(&ad->timer, sec * 1000);
 sleeptimer_enqueue(&ad->timer);
}

variable_types:
sec
unsigned int


decompiled_code:
__int64 __fastcall autodim_timer_callback(__int64 a1)
{
__int64 v1; // rbp

v1 = a1 - 24;
if ( *((int *)&cmdargs + 1) > 2 )
logdebug("autodim: timer triggered\n");
autodim_handle_state(v1);
return autodim_timer_start(v1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rbp

v1 = a1 - 24;
if ( *((int *)&cmdargs + 1) > 2 )
logdebug("autodim: timer triggered\n");
func2(v1);
return func9(v1);
}

original_code:
static void autodim_timer_callback(struct sleeptimer *timer)
{
 struct autodim *ad = ({ __typeof__(((struct autodim *)0)->timer) *__mptr = (timer); (struct autodim *)((char *)__mptr - ((size_t)&((struct autodim *)0)->timer)); });
 do { if ((cmdargs.loglevel >= LOGLEVEL_VERBOSE)) _logdebug("autodim: timer triggered\n"); } while (0);
 autodim_handle_state(ad);
 autodim_timer_start(ad);
}

variable_types: struct sleeptimer { char *name; struct timespec { long tv_sec; long tv_nsec; } timeout; void (*callback)(struct sleeptimer *timer); unsigned long id; struct list_head { struct list_head *next; struct list_head *prev; } list; } *


decompiled_code:
__int64 __fastcall autodim_timer_stop(__int64 a1)
{
return sleeptimer_dequeue(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return sleeptimer_dequeue(a1 + 24);
}

original_code:
static void autodim_timer_stop(struct autodim *ad)
{
 sleeptimer_dequeue(&ad->timer);
}


decompiled_code:
// attributes: thunk
void *autodim_alloc()
{
return zalloc_constprop_0();
}

canonical_decompiled_code:
void *func13()
{
return func12();
}

original_code:
struct autodim * autodim_alloc(void)
{
 struct autodim *ad;
 ad = zalloc(sizeof(*ad));
 if (!ad)
  return ((void *)0);
 return ad;
}

canonical_original_code:
struct autodim *autodim_alloc()
{
 struct autodim *ad;
 ad = zalloc(sizeof(*ad));
 if (!ad)
  return ((void *)0);
 return ad;
}

return_type: struct autodim { struct backlight { char *name; int (*min_brightness)(struct backlight *b); int (*max_brightness)(struct backlight *b); int (*brightness_step)(struct backlight *b); int (*current_brightness)(struct backlight *b); int (*set_brightness)(struct backlight *b, int value); int (*screen_lock)(struct backlight *b, int lock); int (*screen_is_locked)(struct backlight *b); void (*destroy)(struct backlight *b); int (*update)(struct backlight *b); unsigned int poll_interval; int autodim_enabled; int autodim_enabled_on_ac; int framebuffer_fd; int fb_blanked; struct sleeptimer { char *name; struct timespec { long tv_sec; long tv_nsec; } timeout; void (*callback)(struct sleeptimer *timer); unsigned long id; struct list_head { struct list_head *next; struct list_head *prev; } list; } timer; } *bl; int *fds; unsigned int nr_fds; struct sleeptimer timer; int suspended; unsigned int state; unsigned int bl_percent; unsigned int max_percent; struct autodim_step { unsigned int second; unsigned int percent; } *steps; unsigned int nr_allocated_steps; unsigned int nr_steps; } *


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

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

original_code:
static void devicelock_dummy_destroy(struct devicelock *s)
{
 struct devicelock_dummy *ld = ({ __typeof__(((struct devicelock_dummy *)0)->devicelock) *__mptr = (s); (struct devicelock_dummy *)((char *)__mptr - ((size_t)&((struct devicelock_dummy *)0)->devicelock)); });
 free(ld);
}

variable_types: struct devicelock { char *name; void (*destroy)(struct devicelock *s); void (*event)(struct devicelock *s); } *

variable_types: struct devicelock_dummy { struct devicelock { char *name; void (*destroy)(struct devicelock *s); void (*event)(struct devicelock *s); } devicelock; } *

user_defined_types: struct devicelock_dummy { struct devicelock devicelock; }


decompiled_code:
_QWORD *devicelock_dummy_probe()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = zalloc_constprop_0();
v1 = v0;
if ( v0 )
{
devicelock_init(v0, "dummy");
v1[1] = devicelock_dummy_destroy;
}
return v1;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = func1();
v1 = v0;
if ( v0 )
{
devicelock_init(v0, "dummy");
v1[1] = devicelock_dummy_destroy;
}
return v1;
}

original_code:
static struct devicelock * devicelock_dummy_probe(void)
{
 struct devicelock_dummy *ld;
 ld = zalloc(sizeof(*ld));
 if (!ld)
  return ((void *)0);
 devicelock_init(&ld->devicelock, "dummy");
 ld->devicelock.destroy = devicelock_dummy_destroy;
 return &ld->devicelock;
}

canonical_original_code:
static struct devicelock *devicelock_dummy_probe()
{
 struct devicelock_dummy *ld;
 ld = zalloc(sizeof(*ld));
 if (!ld)
  return ((void *)0);
 devicelock_init(&ld->devicelock, "dummy");
 ld->devicelock.destroy = devicelock_dummy_destroy;
 return &ld->devicelock;
}


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
Display *v5; // rbx
int v6; // ebp
int v7; // ebp
unsigned int v8; // eax
int v9; // [rsp+Ch] [rbp-17Ch] BYREF
int v10; // [rsp+10h] [rbp-178h] BYREF
int v11; // [rsp+14h] [rbp-174h] BYREF
__pid_t v12; // [rsp+18h] [rbp-170h] BYREF
int v13[3]; // [rsp+1Ch] [rbp-16Ch] BYREF
int *v14; // [rsp+28h] [rbp-160h]
sigset_t set; // [rsp+30h] [rbp-158h] BYREF
XEvent v16; // [rsp+B0h] [rbp-D8h] BYREF

v13[0] = 0;
if ( argc == 4
&& (*(_QWORD *)&argc = argv[1], v3 = argv,
argv = (const char **)"%d",
sscanf(*(const char **)&argc, "%d", &v12) == 1)
&& (*(_QWORD *)&argc = v3[2], argv = (const char **)"%d", sscanf(*(const char **)&argc, "%d", &report_signal) == 1)
&& (*(_QWORD *)&argc = v3[3], argv = (const char **)"%u", sscanf(*(const char **)&argc, "%u", &grace_period_ms) == 1) )
{
report_pid = v12;
v5 = XOpenDisplay(0LL);
if ( v5 || (v5 = XOpenDisplay(":0")) != 0LL )
{
if ( XQueryExtension(v5, "XInputExtension", &v11, &v9, &v10) )
{
sigemptyset(&set);
v6 = sigprocmask(2, &set, 0LL);
v7 = install_sighandler_constprop_0(2) | v6;
if ( (unsigned int)install_sighandler_constprop_0(15) | v7 )
{
fwrite("pwrtray-xevrep: Failed to setup signal handlers\n", 1uLL, 0x30uLL, stderr);
}
else
{
LOWORD(v13[0]) |= 0x984Eu;
BYTE2(v13[0]) |= 1u;
v13[1] = 0;
v13[2] = 4;
v14 = v13;
v8 = XISelectEvents();
if ( !v8 )
{
puts("pwrtray-xevrep: Monitoring X11 input events...");
while ( 1 )
{
XNextEvent(v5, &v16);
if ( XGetEventData(v5, (XGenericEventCookie *)&v16) && v16.type == 35 && v16.xgeneric.extension == v11 )
report_event_constprop_0();
XFreeEventData(v5, (XGenericEventCookie *)&v16);
}
}
fprintf(stderr, "pwrtray-xevrep: Failed to set event mask (%d)\n", v8);
}
}
else
{
fwrite("pwrtray-xevrep: X Input extension not available.\n", 1uLL, 0x31uLL, stderr);
}
}
else
{
fwrite("pwrtray-xevrep: Failed to open DISPLAY\n", 1uLL, 0x27uLL, stderr);
}
}
else
{
usage(*(_QWORD *)&argc, argv, envp);
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
Display *v5; // rbx
int v6; // ebp
int v7; // ebp
unsigned int v8; // eax
int v9; // [rsp+Ch] [rbp-17Ch] BYREF
int v10; // [rsp+10h] [rbp-178h] BYREF
int v11; // [rsp+14h] [rbp-174h] BYREF
__pid_t v12; // [rsp+18h] [rbp-170h] BYREF
int v13[3]; // [rsp+1Ch] [rbp-16Ch] BYREF
int *v14; // [rsp+28h] [rbp-160h]
sigset_t set; // [rsp+30h] [rbp-158h] BYREF
XEvent v16; // [rsp+B0h] [rbp-D8h] BYREF

v13[0] = 0;
if ( argc == 4
&& (*(_QWORD *)&argc = argv[1], v3 = argv,
argv = (const char **)"%d",
sscanf(*(const char **)&argc, "%d", &v12) == 1)
&& (*(_QWORD *)&argc = v3[2], argv = (const char **)"%d", sscanf(*(const char **)&argc, "%d", &report_signal) == 1)
&& (*(_QWORD *)&argc = v3[3], argv = (const char **)"%u", sscanf(*(const char **)&argc, "%u", &grace_period_ms) == 1) )
{
report_pid = v12;
v5 = XOpenDisplay(0LL);
if ( v5 || (v5 = XOpenDisplay(":0")) != 0LL )
{
if ( XQueryExtension(v5, "XInputExtension", &v11, &v9, &v10) )
{
sigemptyset(&set);
v6 = sigprocmask(2, &set, 0LL);
v7 = func9(2) | v6;
if ( (unsigned int)func9(15) | v7 )
{
fwrite("pwrtray-xevrep: Failed to setup signal handlers\n", 1uLL, 0x30uLL, stderr);
}
else
{
LOWORD(v13[0]) |= 0x984Eu;
BYTE2(v13[0]) |= 1u;
v13[1] = 0;
v13[2] = 4;
v14 = v13;
v8 = XISelectEvents();
if ( !v8 )
{
puts("pwrtray-xevrep: Monitoring X11 input events...");
while ( 1 )
{
XNextEvent(v5, &v16);
if ( XGetEventData(v5, (XGenericEventCookie *)&v16) && v16.type == 35 && v16.xgeneric.extension == v11 )
func12();
XFreeEventData(v5, (XGenericEventCookie *)&v16);
}
}
fprintf(stderr, "pwrtray-xevrep: Failed to set event mask (%d)\n", v8);
}
}
else
{
fwrite("pwrtray-xevrep: X Input extension not available.\n", 1uLL, 0x31uLL, stderr);
}
}
else
{
fwrite("pwrtray-xevrep: Failed to open DISPLAY\n", 1uLL, 0x27uLL, stderr);
}
}
else
{
func7(*(_QWORD *)&argc, argv, envp);
}
return 1;
}

original_code:
int main(int argc, char **argv)
{
 Window window;
 int res;
 sigset_t sigset;
 display = XOpenDisplay(((void *)0));
 if (!display) {
  display = XOpenDisplay(":0");
  if (!display) {
   fprintf(stderr, "Failed to open DISPLAY\n");
   return 1;
  }
 }
 window = ((&((_XPrivDisplay)(display))->screens[(((_XPrivDisplay)(display))->default_screen)])->root);
 sigemptyset(&sigset);
 res = sigprocmask(2, &sigset, ((void *)0));
 res |= install_sighandler(2, signal_handler);
 res |= install_sighandler(15, signal_handler);
 if (res) {
  fprintf(stderr, "Failed to setup signal handlers\n");
  return 1;
 }
 res = XGrabPointer(display, window,
      0, 0, 1, 1,
      0L, 0L, 0L);
 if (res != 0) {
  fprintf(stderr, "Failed to grab pointer (res=%d)\n", res);
  return 1;
 }
 res = XGrabKeyboard(display, window,
       0, 1, 1,
       0L);
 if (res != 0) {
  fprintf(stderr, "Failed to grab keyboard (res=%d)\n", res);
  XUngrabPointer(display, 0L);
  return 1;
 }
 XFlush(display);
 printf("pwrtray-xlock: locked\n");
 while (1)
  sleep(0xFFFF);
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned long window;
 int res;
 struct __sigset_t sigset;
 display = XOpenDisplay(((void *)0));
 if (!display) {
  display = XOpenDisplay(":0");
  if (!display) {
   fprintf(stderr, "Failed to open DISPLAY\n");
   return 1;
  }
 }
 window = ((&((_XPrivDisplay)(display))->screens[(((_XPrivDisplay)(display))->default_screen)])->root);
 sigemptyset(&sigset);
 res = sigprocmask(2, &sigset, ((void *)0));
 res |= install_sighandler(2, signal_handler);
 res |= install_sighandler(15, signal_handler);
 if (res) {
  fprintf(stderr, "Failed to setup signal handlers\n");
  return 1;
 }
 res = XGrabPointer(display, window,
      0, 0, 1, 1,
      0L, 0L, 0L);
 if (res != 0) {
  fprintf(stderr, "Failed to grab pointer (res=%d)\n", res);
  return 1;
 }
 res = XGrabKeyboard(display, window,
       0, 1, 1,
       0L);
 if (res != 0) {
  fprintf(stderr, "Failed to grab keyboard (res=%d)\n", res);
  XUngrabPointer(display, 0L);
  return 1;
 }
 XFlush(display);
 printf("pwrtray-xlock: locked\n");
 while (1)
  sleep(0xFFFF);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
window
unsigned long

variable_types: res int

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


usage

decompiled_code:
int usage()
{
return puts("Usage: pwrtray-xevrep PID SIGNAL GRACEPERIOD");
}

canonical_decompiled_code:
int func7()
{
return puts("Usage: pwrtray-xevrep PID SIGNAL GRACEPERIOD");
}

original_code:
static void usage(void)
{
 printf("Usage: pwrtray-xevrep PID SIGNAL GRACEPERIOD\n");
}

canonical_original_code:
static void usage()
{
 printf("Usage: pwrtray-xevrep PID SIGNAL GRACEPERIOD\n");
}


decompiled_code:
_BOOL8 __fastcall timeval_after(_QWORD *a1, _QWORD *a2)
{
_BOOL8 result; // rax

result = 1LL;
if ( *a1 <= *a2 )
{
result = 0LL;
if ( *a1 == *a2 )
result = a1[1] > a2[1];
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_QWORD *a1, _QWORD *a2)
{
_BOOL8 result; // rax

result = 1LL;
if ( *a1 <= *a2 )
{
result = 0LL;
if ( *a1 == *a2 )
result = a1[1] > a2[1];
}
return result;
}

original_code:
int timeval_after(const struct timeval *a, const struct timeval *b)
{
 if (a->tv_sec > b->tv_sec)
  return 1;
 if ((a->tv_sec == b->tv_sec) && (a->tv_usec > b->tv_usec))
  return 1;
 return 0;
}

canonical_original_code:
int timeval_after(struct timeval *a, struct timeval *b)
{
 if (a->tv_sec > b->tv_sec)
  return 1;
 if ((a->tv_sec == b->tv_sec) && (a->tv_usec > b->tv_usec))
  return 1;
 return 0;
}

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

variable_types:
b
struct timeval *


decompiled_code:
__int64 __fastcall parse_commandline(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 2 )
{
v2 = getopt_long(argc, argv, "hBP:l:L:f", &long_options_0, longind);
if ( v2 == -1 )
return 0LL;
switch ( v2 )
{
case 'B':
cmdargs = 1;
continue;
case 'L':
*((_QWORD *)&cmdargs + 1) = optarg;
continue;
case 'P':
*((_QWORD *)&cmdargs + 2) = optarg;
continue;
case 'f':
*(&cmdargs + 6) = 1;
continue;
case 'h':
usage_constprop_0_isra_0(stdout, *argv);
result = 1LL;
break;
case 'l':
if ( sscanf(optarg, "%d", (unsigned int)((_DWORD)&cmdargs + 4)) == 1 )
continue;
fwrite("Failed to parse --loglevel argument.\n", 1uLL, 0x25uLL, stderr);
result = 0xFFFFFFFFLL;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 2 )
{
v2 = getopt_long(argc, argv, "hBP:l:L:f", &long_options_0, longind);
if ( v2 == -1 )
return 0LL;
switch ( v2 )
{
case 'B':
cmdargs = 1;
continue;
case 'L':
*((_QWORD *)&cmdargs + 1) = optarg;
continue;
case 'P':
*((_QWORD *)&cmdargs + 2) = optarg;
continue;
case 'f':
*(&cmdargs + 6) = 1;
continue;
case 'h':
func0(stdout, *argv);
result = 1LL;
break;
case 'l':
if ( sscanf(optarg, "%d", (unsigned int)((_DWORD)&cmdargs + 4)) == 1 )
continue;
fwrite("Failed to parse --loglevel argument.\n", 1uLL, 0x25uLL, stderr);
result = 0xFFFFFFFFLL;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
break;
}
return result;
}

original_code:
int parse_commandline(int argc, char **argv)
{
 static struct option long_options[] = {
  { "help", 0, 0, 'h' },
  { "background", 0, 0, 'B' },
  { "pidfile", 1, 0, 'P' },
  { "loglevel", 1, 0, 'l' },
  { "logfile", 1, 0, 'L' },
  { "force", 0, 0, 'f' },
 };
 int c, idx;
 while (1) {
  c = getopt_long(argc, argv, "hBP:l:L:f",
    long_options, &idx);
  if (c == -1)
   break;
  switch (c) {
  case 'h':
   usage(stdout, argc, argv);
   return 1;
  case 'B':
   cmdargs.background = 1;
   break;
  case 'P':
   cmdargs.pidfile = optarg;
   break;
  case 'l':
   if (sscanf(optarg, "%d", &cmdargs.loglevel) != 1) {
    fprintf(stderr, "Failed to parse --loglevel argument.\n");
    return -1;
   }
   break;
  case 'L':
   cmdargs.logfile = optarg;
   break;
  case 'f':
   cmdargs.force = 1;
   break;
  default:
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int parse_commandline(int argc, char **argv)
{
 static struct option long_options[] = {
  { "help", 0, 0, 'h' },
  { "background", 0, 0, 'B' },
  { "pidfile", 1, 0, 'P' },
  { "loglevel", 1, 0, 'l' },
  { "logfile", 1, 0, 'L' },
  { "force", 0, 0, 'f' },
 };
 int c; int idx;
 while (1) {
  c = getopt_long(argc, argv, "hBP:l:L:f",
    long_options, &idx);
  if (c == -1)
   break;
  switch (c) {
  case 'h':
   usage(stdout, argc, argv);
   return 1;
  case 'B':
   cmdargs.background = 1;
   break;
  case 'P':
   cmdargs.pidfile = optarg;
   break;
  case 'l':
   if (sscanf(optarg, "%d", &cmdargs.loglevel) != 1) {
    fprintf(stderr, "Failed to parse --loglevel argument.\n");
    return -1;
   }
   break;
  case 'L':
   cmdargs.logfile = optarg;
   break;
  case 'f':
   cmdargs.force = 1;
   break;
  default:
   return -1;
  }
 }
 return 0;
}

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

variable_types: c int

variable_types: idx int


decompiled_code:
_BOOL8 __fastcall list_empty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
static inline int list_empty(const struct list_head *head)
{
 return head->next == head;
}

canonical_original_code:
static inline int list_empty(struct list_head *head)
{
 return head->next == head;
}

variable_types: struct list_head { struct list_head *next; struct list_head *prev; } *


strempty

decompiled_code:
_BOOL8 __fastcall strempty(_BYTE *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1 )
result = *a1 == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_BYTE *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1 )
result = *a1 == 0;
return result;
}

original_code:
static inline int strempty(const char *s)
{
 return (s == ((void *)0)) || (s[0] == '\0');
}

variable_types:
s
char *


canonical_decompiled_code:
_BOOL8 __fastcall func0(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}


original_code:
int
pilot_connector_wait(struct pilot_connector *thiz)
{
 int ret = 0;
 int maxfd = 0;
 fd_set rfds;
 if (thiz->fd >= 0)
 {
  ((void) (((&rfds)->__fds_bits)[((thiz->fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((thiz->fd) % (8 * (int) sizeof (__fd_mask)))))));
  maxfd = thiz->fd + 1;
  do { thiz->prepare_wait.slots.it = thiz->prepare_wait.slots.next; while (thiz->prepare_wait.slots.it) { typeof(thiz->prepare_wait.slots) *slot_it = thiz->prepare_wait.slots.it; thiz->prepare_wait.slots.it = thiz->prepare_wait.slots.it->next; if (slot_it->action(slot_it->dest, thiz) < 0) break; } } while(0);
  if (thiz->distribut == 0)
  {
   ret = select(maxfd, &rfds, ((void *)0), ((void *)0), ((void *)0));
   if (ret > 0 && ((((&rfds)->__fds_bits)[((thiz->fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((thiz->fd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   {
    fprintf(stderr, "%s ""on %d""\n", __FUNCTION__,thiz->fd);
    thiz->distribut = 1;
   }
  }
  if (thiz->distribut) {
   do { thiz->dispatch_events.slots.it = thiz->dispatch_events.slots.next; while (thiz->dispatch_events.slots.it) { typeof(thiz->dispatch_events.slots) *slot_it = thiz->dispatch_events.slots.it; thiz->dispatch_events.slots.it = thiz->dispatch_events.slots.it->next; if (slot_it->action(slot_it->dest, thiz) < 0) break; } } while(0);
  }
  ret = thiz->distribut;
  thiz->distribut = 0;
 }
 else
  ret = -1;
 return ret;
}

canonical_original_code:
int pilot_connector_wait(struct pilot_connector *thiz)
{
 int ret = 0;
 int maxfd = 0;
 struct fd_set rfds;
 if (thiz->fd >= 0)
 {
  ((void) (((&rfds)->__fds_bits)[((thiz->fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((thiz->fd) % (8 * (int) sizeof (__fd_mask)))))));
  maxfd = thiz->fd + 1;
  do { thiz->prepare_wait.slots.it = thiz->prepare_wait.slots.next; while (thiz->prepare_wait.slots.it) { typeof(thiz->prepare_wait.slots) *slot_it = thiz->prepare_wait.slots.it; thiz->prepare_wait.slots.it = thiz->prepare_wait.slots.it->next; if (slot_it->action(slot_it->dest, thiz) < 0) break; } } while(0);
  if (thiz->distribut == 0)
  {
   ret = select(maxfd, &rfds, ((void *)0), ((void *)0), ((void *)0));
   if (ret > 0 && ((((&rfds)->__fds_bits)[((thiz->fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((thiz->fd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   {
    fprintf(stderr, "%s ""on %d""\n", __FUNCTION__,thiz->fd);
    thiz->distribut = 1;
   }
  }
  if (thiz->distribut) {
   do { thiz->dispatch_events.slots.it = thiz->dispatch_events.slots.next; while (thiz->dispatch_events.slots.it) { typeof(thiz->dispatch_events.slots) *slot_it = thiz->dispatch_events.slots.it; thiz->dispatch_events.slots.it = thiz->dispatch_events.slots.it->next; if (slot_it->action(slot_it->dest, thiz) < 0) break; } } while(0);
  }
  ret = thiz->distribut;
  thiz->distribut = 0;
 }
 else
  ret = -1;
 return ret;
}

variable_types: struct pilot_connector { struct pilot_application { struct _pilot_list_pilot_connector { struct pilot_connector *item; struct _pilot_list_pilot_connector *next; struct _pilot_list_pilot_connector *it; } connectors; struct _pilot_list_pilot_option { struct pilot_option { char *name; char *value; } *item; struct _pilot_list_pilot_option *next; struct _pilot_list_pilot_option *it; } options; struct fd_set { long __fds_bits[-1]; } rfds; int maxfd; int signal_pipe[2]; char running; char dispatch; } *application; int fd; char distribut; struct { struct pilot_connector_prepare_wait_slot { void *dest; struct pilot_connector_prepare_wait_slot *next; struct pilot_connector_prepare_wait_slot *it; int (*action)(void *, struct pilot_connector *); } slots; } prepare_wait; struct { struct pilot_connector_dispatch_events_slot { void *dest; struct pilot_connector_dispatch_events_slot *next; struct pilot_connector_dispatch_events_slot *it; int (*action)(void *, struct pilot_connector *); } slots; } dispatch_events; struct { struct pilot_connector_disconnect_slot { void *dest; struct pilot_connector_disconnect_slot *next; struct pilot_connector_disconnect_slot *it; int (*action)(void *, struct pilot_connector *); } slots; } disconnect; } *

variable_types: ret int

variable_types: maxfd int

variable_types:
rfds
struct fd_set { long __fds_bits[-1]; }

user_defined_types: struct pilot_connector { struct pilot_application *application; int fd; char distribut; struct { struct pilot_connector_prepare_wait_slot slots; } prepare_wait; struct { struct pilot_connector_dispatch_events_slot slots; } dispatch_events; struct { struct pilot_connector_disconnect_slot slots; } disconnect; }

user_defined_types: struct pilot_application { struct _pilot_list_pilot_connector connectors; struct _pilot_list_pilot_option options; struct fd_set rfds; int maxfd; int signal_pipe[2]; char running; char dispatch; }

user_defined_types: struct _pilot_list_pilot_option { struct pilot_option *item; struct _pilot_list_pilot_option *next; struct _pilot_list_pilot_option *it; }


decompiled_code:
void *__fastcall pilot_application_create(int a1, __int64 a2)
{
void *v2; // r12
__int64 *v3; // rbx

v2 = calloc(0xC0uLL, 1uLL);
if ( a1 > 1 )
{
v3 = (__int64 *)(a2 + 8);
do
{
if ( (unsigned int)pilot_application_storeopt((__int64)v2, *v3) )
break;
++v3;
}
while ( v3 != (__int64 *)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) );
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func5(int a1, __int64 a2)
{
void *v2; // r12
__int64 *v3; // rbx

v2 = calloc(0xC0uLL, 1uLL);
if ( a1 > 1 )
{
v3 = (__int64 *)(a2 + 8);
do
{
if ( (unsigned int)func2((__int64)v2, *v3) )
break;
++v3;
}
while ( v3 != (__int64 *)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) );
}
return v2;
}

original_code:
struct pilot_application *
pilot_application_create(int argc, const char **argv)
{
 struct pilot_application *application;
 application = malloc(sizeof(*application));
 memset(application, 0, sizeof(*application));
 int i;
 for (i = 1; i < argc; i++)
 {
  if (_pilot_application_storeopt(application, argv[i]))
   break;
 }
 return application;
}

canonical_original_code:
struct pilot_application *pilot_application_create(int argc, char **argv)
{
 struct pilot_application *application;
 application = malloc(sizeof(*application));
 memset(application, 0, sizeof(*application));
 int i;
 for (i = 1; i < argc; i++)
 {
  if (_pilot_application_storeopt(application, argv[i]))
   break;
 }
 return application;
}

variable_types: struct pilot_application { struct _pilot_list_pilot_connector { struct pilot_connector { struct pilot_application *application; int fd; char distribut; struct { struct pilot_connector_prepare_wait_slot { void *dest; struct pilot_connector_prepare_wait_slot *next; struct pilot_connector_prepare_wait_slot *it; int (*action)(void *, struct pilot_connector *); } slots; } prepare_wait; struct { struct pilot_connector_dispatch_events_slot { void *dest; struct pilot_connector_dispatch_events_slot *next; struct pilot_connector_dispatch_events_slot *it; int (*action)(void *, struct pilot_connector *); } slots; } dispatch_events; struct { struct pilot_connector_disconnect_slot { void *dest; struct pilot_connector_disconnect_slot *next; struct pilot_connector_disconnect_slot *it; int (*action)(void *, struct pilot_connector *); } slots; } disconnect; } *item; struct _pilot_list_pilot_connector *next; struct _pilot_list_pilot_connector *it; } connectors; struct _pilot_list_pilot_option { struct pilot_option { char *name; char *value; } *item; struct _pilot_list_pilot_option *next; struct _pilot_list_pilot_option *it; } options; struct fd_set { long __fds_bits[-1]; } rfds; int maxfd; int signal_pipe[2]; char running; char dispatch; } *

variable_types: i int

user_defined_types: struct _pilot_list_pilot_connector { struct pilot_connector *item; struct _pilot_list_pilot_connector *next; struct _pilot_list_pilot_connector *it; }


decompiled_code:
void __fastcall pilot_application_destroy(void *ptr)
{
_QWORD *v2; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
for ( *((_QWORD *)ptr + 2) = v2; v2; v2 = (_QWORD *)*((_QWORD *)ptr + 2) )
{
*((_QWORD *)ptr + 2) = v2[1];
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
_QWORD *v2; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
for ( *((_QWORD *)ptr + 2) = v2; v2; v2 = (_QWORD *)*((_QWORD *)ptr + 2) )
{
*((_QWORD *)ptr + 2) = v2[1];
free(v2);
}
free(ptr);
}

original_code:
void
pilot_application_destroy(struct pilot_application *application)
{
 do { application->connectors.it = application->connectors.next; while (application->connectors.it) { typeof (application->connectors) *tmp = application->connectors.it; application->connectors.it = application->connectors.it->next; free(tmp); } } while(0);
 free(application);
}

user_defined_types: struct pilot_option { char *name; char *value; }

user_defined_types: struct pilot_connector_prepare_wait_slot { void *dest; struct pilot_connector_prepare_wait_slot *next; struct pilot_connector_prepare_wait_slot *it; int (*action)(void *, struct pilot_connector *); }

user_defined_types: struct pilot_connector_dispatch_events_slot { void *dest; struct pilot_connector_dispatch_events_slot *next; struct pilot_connector_dispatch_events_slot *it; int (*action)(void *, struct pilot_connector *); }

user_defined_types: struct pilot_connector_disconnect_slot { void *dest; struct pilot_connector_disconnect_slot *next; struct pilot_connector_disconnect_slot *it; int (*action)(void *, struct pilot_connector *); }


decompiled_code:
__int64 __fastcall pilot_application_addconnector(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
char *v3; // rax

do
{
v2 = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
v3 = (char *)malloc(0x18uLL);
*(_QWORD *)(v2 + 8) = v3;
*(_QWORD *)v3 = a2;
*(_OWORD *)(v3 + 8) = 0LL;
return 0LL;
}

original_code:
int
pilot_application_addconnector(struct pilot_application *application,
      struct pilot_connector *connector)
{
 do { typeof (application->connectors) *it = &application->connectors; while (it->next) it = it->next; it->next = malloc(sizeof(typeof (application->connectors))); it = it->next; memset(it, 0, sizeof(typeof (application->connectors))); it->item = connector; } while(0);
 return 0;
}

variable_types:
connector
struct pilot_connector *


decompiled_code:
__int64 __fastcall pilot_application_removeconnector(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rbx

do
{
v2 = a1;
a1 = (_QWORD *)a1[1];
if ( !a1 )
return 0LL;
}
while ( *a1 != a2 );
v2[1] = a1[1];
free(a1);
v2[2] = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rbx

do
{
v2 = a1;
a1 = (_QWORD *)a1[1];
if ( !a1 )
return 0LL;
}
while ( *a1 != a2 );
v2[1] = a1[1];
free(a1);
v2[2] = 0LL;
return 0LL;
}

original_code:
int
pilot_application_removeconnector(struct pilot_application *application,
      struct pilot_connector *connector)
{
 do { typeof (application->connectors) *it = &application->connectors; while (it->next && it->next->item != connector) it = it->next; if (it->next) { it->it = it->next; it->next = it->next->next; free(it->it); it->it = ((void *)0); } } while(0);
 return 0;
}


decompiled_code:
void __fastcall pilot_connector_destroy(void *ptr)
{
_QWORD *v2; // rdi

v2 = *(_QWORD **)ptr;
if ( v2 )
pilot_application_removeconnector(v2, (__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
_QWORD *v2; // rdi

v2 = *(_QWORD **)ptr;
if ( v2 )
func8(v2, (__int64)ptr);
free(ptr);
}

original_code:
void
pilot_connector_destroy(struct pilot_connector *thiz)
{
 if (thiz->application != ((void *)0))
  pilot_application_removeconnector(thiz->application, thiz);
 free(thiz);
}


decompiled_code:
__int64 __fastcall pilot_application_dispatchevents(__int64 a1)
{
__int64 *v1; // rax
__int64 v3; // rdi

v1 = *(__int64 **)(a1 + 8);
for ( *(_QWORD *)(a1 + 16) = v1; v1; v1 = *(__int64 **)(a1 + 16) )
{
v3 = *v1;
*(_QWORD *)(a1 + 16) = v1[1];
if ( (int)pilot_application_dispatch_item_events_constprop_0(v3) < 0 )
break;
}
return 0LL;
}

original_code:
int
pilot_application_dispatchevents(struct pilot_application *application)
{
 do { application->connectors.it = application->connectors.next; while (application->connectors.it) { typeof (application->connectors) *it = application->connectors.it; application->connectors.it = application->connectors.it->next; if (_pilot_application_dispatch_item_events(application, it->item) < 0) break; } } while(0);
 return 0;
}


decompiled_code:
__int64 __fastcall pilot_application_check(__int64 a1)
{
__int64 *v1; // rax
__int64 v2; // rsi
bool v3; // r12
int v4; // er12
__int64 *v5; // rax
__int64 v6; // rsi
unsigned int v8; // eax

*(_DWORD *)(a1 + 176) = 0;
memset((void *)(a1 + 48), 0, 0x80uLL);
v1 = *(__int64 **)(a1 + 8);
for ( *(_QWORD *)(a1 + 16) = v1; v1; v1 = *(__int64 **)(a1 + 16) )
{
v2 = *v1;
*(_QWORD *)(a1 + 16) = v1[1];
if ( (int)pilot_application_fill_fdset(a1, v2) < 0 )
break;
}
if ( !*(_DWORD *)(a1 + 176) )
{
*(_BYTE *)(a1 + 188) &= 0xFEu;
return (unsigned int)-1;
}
v3 = (*(_BYTE *)(a1 + 188) & 2) != 0;
fprintf(stderr, "%s wait %d\n", "pilot_application_check", v3);
if ( v3 )
{
*(_BYTE *)(a1 + 188) &= 0xFDu;
v4 = 1;
fprintf(stderr, "%s continue %d\n", "pilot_application_check", 1LL);
goto LABEL_8;
}
v8 = select(*(_DWORD *)(a1 + 176), (fd_set *)(a1 + 48), 0LL, 0LL, 0LL);
*(_BYTE *)(a1 + 188) &= 0xFDu;
v4 = v8;
fprintf(stderr, "%s continue %d\n", "pilot_application_check", v8);
if ( v4 > 0 )
{
LABEL_8:
v5 = *(__int64 **)(a1 + 8);
for ( *(_QWORD *)(a1 + 16) = v5; v5; v5 = *(__int64 **)(a1 + 16) )
{
v6 = *v5;
*(_QWORD *)(a1 + 16) = v5[1];
if ( (int)pilot_application_check_fdset(a1, v6) < 0 )
break;
}
return (unsigned int)v4;
}
return (unsigned int)v4;
}

original_code:
int
pilot_application_check(struct pilot_application *application)
{
 int ret = 0;
 application->maxfd = 0;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&application->rfds)->__fds_bits)[0]) : "memory"); } while (0);
 do { application->connectors.it = application->connectors.next; while (application->connectors.it) { typeof (application->connectors) *it = application->connectors.it; application->connectors.it = application->connectors.it->next; if (_pilot_application_fill_fdset(application, it->item) < 0) break; } } while(0);
 if (application->maxfd == 0)
 {
  application->running = 0;
  return -1;
 }
 ret = (application->dispatch)?1:0;
 fprintf(stderr, "%s ""wait %d""\n", __FUNCTION__, ret);
 if (!ret)
  ret = select(application->maxfd, &application->rfds, ((void *)0), ((void *)0), ((void *)0));
 application->dispatch = 0;
 fprintf(stderr, "%s ""continue %d""\n", __FUNCTION__, ret);
 if (ret > 0)
  do { application->connectors.it = application->connectors.next; while (application->connectors.it) { typeof (application->connectors) *it = application->connectors.it; application->connectors.it = application->connectors.it->next; if (_pilot_application_check_fdset(application, it->item) < 0) break; } } while(0);
 return ret;
}

canonical_original_code:
int pilot_application_check(struct pilot_application *application)
{
 int ret = 0;
 application->maxfd = 0;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&application->rfds)->__fds_bits)[0]) : "memory"); } while (0);
 do { application->connectors.it = application->connectors.next; while (application->connectors.it) { typeof (application->connectors) *it = application->connectors.it; application->connectors.it = application->connectors.it->next; if (_pilot_application_fill_fdset(application, it->item) < 0) break; } } while(0);
 if (application->maxfd == 0)
 {
  application->running = 0;
  return -1;
 }
 ret = (application->dispatch)?1:0;
 fprintf(stderr, "%s ""wait %d""\n", __FUNCTION__, ret);
 if (!ret)
  ret = select(application->maxfd, &application->rfds, ((void *)0), ((void *)0), ((void *)0));
 application->dispatch = 0;
 fprintf(stderr, "%s ""continue %d""\n", __FUNCTION__, ret);
 if (ret > 0)
  do { application->connectors.it = application->connectors.next; while (application->connectors.it) { typeof (application->connectors) *it = application->connectors.it; application->connectors.it = application->connectors.it->next; if (_pilot_application_check_fdset(application, it->item) < 0) break; } } while(0);
 return ret;
}


decompiled_code:
__int64 __fastcall pilot_application_run(__int64 a1)
{
int v1; // er12

*(_BYTE *)(a1 + 188) |= 1u;
while ( 1 )
{
while ( 1 )
{
v1 = pilot_application_check(a1);
if ( v1 >= 0 )
v1 = pilot_application_dispatchevents(a1);
if ( v1 == -1 )
break;
if ( (*(_BYTE *)(a1 + 188) & 1) == 0 )
return (unsigned int)v1;
}
if ( *_errno_location() != 4 )
break;
if ( (*(_BYTE *)(a1 + 188) & 1) == 0 )
return 0;
}
return (unsigned int)v1;
}

original_code:
int
pilot_application_run(struct pilot_application *application)
{
 int ret = 0;
 application->running = 1;
 while (application->running && ret != -1) {
  ret = pilot_application_check(application);
  if (ret >=0)
   ret = pilot_application_dispatchevents(application);
  if (ret == -1 && (*__errno_location ()) == 4) {
   ret = 0;
  }
 }
 return ret;
}


decompiled_code:
__int64 __fastcall pilot_application_exit(__int64 a1, unsigned int a2)
{
*(_BYTE *)(a1 + 188) &= 0xFEu;
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2)
{
*(_BYTE *)(a1 + 188) &= 0xFEu;
return a2;
}

original_code:
int
pilot_application_exit(struct pilot_application *application, int ret)
{
 application->running = 0;
 return ret;
}


decompiled_code:
__int64 __fastcall pilot_application_getopt_string(__int64 a1, const char *a2)
{
__int64 *v2; // r14
int v3; // eax
__int64 v4; // rbx
size_t v5; // r13
__int64 *v6; // rax
__int64 result; // rax

v2 = *(__int64 **)(a1 + 32);
if ( v2 )
{
v3 = strlen(a2);
v4 = *v2;
*(_QWORD *)(a1 + 40) = v2;
if ( v4 )
{
v5 = v3;
while ( strncmp(a2, *(const char **)v4, v5) )
{
v6 = *(__int64 **)(*(_QWORD *)(a1 + 40) + 8LL);
if ( !v6 )
goto LABEL_8;
v4 = *v6;
*(_QWORD *)(a1 + 40) = v6;
if ( !v4 )
goto LABEL_7;
}
result = *(_QWORD *)(v4 + 8);
}
else
{
LABEL_7:
result = 0LL;
}
}
else
{
LABEL_8:
*(_QWORD *)(a1 + 40) = 0LL;
result = 0LL;
}
return result;
}

original_code:
const char *
pilot_application_getopt_string(struct pilot_application *application, char *name)
{
 struct pilot_option *option;
 const char *value = ((void *)0);
 int len = strlen(name);
 option = (application->options.next)?application->options.next->item:((void *)0); application->options.it = application->options.next;
 while (option && strncmp(name, option->name, len))
 {
  option = (application->options.it->next)?application->options.it->next->item:((void *)0);application->options.it = application->options.it->next;;
 }
 if (option)
  value = option->value;
 return value;
}

canonical_original_code:
char *pilot_application_getopt_string(struct pilot_application *application, char *name)
{
 struct pilot_option *option;
 char *value = ((void *)0);
 int len = strlen(name);
 option = (application->options.next)?application->options.next->item:((void *)0); application->options.it = application->options.next;
 while (option && strncmp(name, option->name, len))
 {
  option = (application->options.it->next)?application->options.it->next->item:((void *)0);application->options.it = application->options.it->next;;
 }
 if (option)
  value = option->value;
 return value;
}

variable_types:
name
char *

variable_types: struct pilot_option { char *name; char *value; } *

variable_types:
value
char *

variable_types: len int


decompiled_code:
int __fastcall pilot_application_getopt_int(__int64 a1, const char *a2)
{
const char ***v2; // r14
int v3; // eax
const char **v4; // rbx
size_t v5; // r13
const char ***v6; // rax
int result; // eax
const char *v8; // rdi

v2 = *(const char ****)(a1 + 32);
if ( v2 )
{
v3 = strlen(a2);
v4 = *v2;
*(_QWORD *)(a1 + 40) = v2;
if ( !v4 )
goto LABEL_7;
v5 = v3;
while ( strncmp(a2, *v4, v5) )
{
v6 = *(const char ****)(*(_QWORD *)(a1 + 40) + 8LL);
if ( !v6 )
goto LABEL_8;
v4 = *v6;
*(_QWORD *)(a1 + 40) = v6;
if ( !v4 )
goto LABEL_7;
}
v8 = v4[1];
if ( v8 )
result = atoi(v8);
else
LABEL_7:
result = 0;
}
else
{
LABEL_8:
*(_QWORD *)(a1 + 40) = 0LL;
result = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, const char *a2)
{
const char ***v2; // r14
int v3; // eax
const char **v4; // rbx
size_t v5; // r13
const char ***v6; // rax
int result; // eax
const char *v8; // rdi

v2 = *(const char ****)(a1 + 32);
if ( v2 )
{
v3 = strlen(a2);
v4 = *v2;
*(_QWORD *)(a1 + 40) = v2;
if ( !v4 )
goto LABEL_7;
v5 = v3;
while ( strncmp(a2, *v4, v5) )
{
v6 = *(const char ****)(*(_QWORD *)(a1 + 40) + 8LL);
if ( !v6 )
goto LABEL_8;
v4 = *v6;
*(_QWORD *)(a1 + 40) = v6;
if ( !v4 )
goto LABEL_7;
}
v8 = v4[1];
if ( v8 )
result = atoi(v8);
else
LABEL_7:
result = 0;
}
else
{
LABEL_8:
*(_QWORD *)(a1 + 40) = 0LL;
result = 0;
}
return result;
}

original_code:
int
pilot_application_getopt_int(struct pilot_application *application, char *name)
{
 struct pilot_option *option;
 int value = 0;
 int len = strlen(name);
 option = (application->options.next)?application->options.next->item:((void *)0); application->options.it = application->options.next;
 while (option && strncmp(name, option->name, len))
 {
  option = (application->options.it->next)?application->options.it->next->item:((void *)0);application->options.it = application->options.it->next;;
 }
 if (option && option->value)
  value = atoi(option->value);
 return value;
}

variable_types: value int


decompiled_code:
__int64 __fastcall set_cloexec_or_close(int fd)
{
unsigned int v1; // er12
int v2; // eax

v1 = fd;
if ( fd != -1 )
{
v2 = fcntl(fd, 1);
if ( v2 == -1 || fcntl(fd, 2, v2 | 1) == -1 )
{
v1 = -1;
close(fd);
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
unsigned int v1; // er12
int v2; // eax

v1 = fd;
if ( fd != -1 )
{
v2 = fcntl(fd, 1);
if ( v2 == -1 || fcntl(fd, 2, v2 | 1) == -1 )
{
v1 = -1;
close(fd);
}
}
return v1;
}

original_code:
static int
set_cloexec_or_close(int fd)
{
 long flags;
 if (fd == -1)
  return -1;
 flags = fcntl(fd, 1);
 if (flags == -1)
  goto err;
 if (fcntl(fd, 2, flags | 1) == -1)
  goto err;
 return fd;
err:
 close(fd);
 return -1;
}

variable_types: fd int

variable_types: flags long


decompiled_code:
__int64 __fastcall create_tmpfile_cloexec(char *name)
{
int v1; // eax
unsigned int v2; // er12

v1 = mkstemp(name);
v2 = v1;
if ( v1 >= 0 )
{
v2 = set_cloexec_or_close(v1);
unlink(name);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *name)
{
int v1; // eax
unsigned int v2; // er12

v1 = mkstemp(name);
v2 = v1;
if ( v1 >= 0 )
{
v2 = func0(v1);
unlink(name);
}
return v2;
}

original_code:
static int
create_tmpfile_cloexec(char *tmpname)
{
 int fd;
 fd = mkstemp(tmpname);
 if (fd >= 0) {
  fd = set_cloexec_or_close(fd);
  unlink(tmpname);
 }
 return fd;
}

variable_types:
tmpname
char *


decompiled_code:
__int64 __fastcall os_socketpair_cloexec(int domain, int type, int protocol, int fds[2])
{
int v6; // eax
unsigned int v7; // er12
int v9; // eax
int v10; // edi
int v11; // eax
int v12; // edi

v6 = socketpair(domain, type | 0x80000, protocol, fds);
if ( !v6 )
return 0LL;
v7 = v6;
if ( *_errno_location() != 22 )
return v7;
v7 = socketpair(domain, type, protocol, fds);
if ( (v7 & 0x80000000) != 0 )
return v7;
v9 = set_cloexec_or_close(*fds);
v10 = fds[1];
*fds = v9;
v11 = set_cloexec_or_close(v10);
v12 = *fds;
fds[1] = v11;
if ( v11 == -1 || v12 == -1 )
{
close(v12);
v7 = -1;
close(fds[1]);
return v7;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int domain, int type, int protocol, int fds[2])
{
int v6; // eax
unsigned int v7; // er12
int v9; // eax
int v10; // edi
int v11; // eax
int v12; // edi

v6 = socketpair(domain, type | 0x80000, protocol, fds);
if ( !v6 )
return 0LL;
v7 = v6;
if ( *_errno_location() != 22 )
return v7;
v7 = socketpair(domain, type, protocol, fds);
if ( (v7 & 0x80000000) != 0 )
return v7;
v9 = func0(*fds);
v10 = fds[1];
*fds = v9;
v11 = func0(v10);
v12 = *fds;
fds[1] = v11;
if ( v11 == -1 || v12 == -1 )
{
close(v12);
v7 = -1;
close(fds[1]);
return v7;
}
return 0LL;
}

original_code:
int
os_socketpair_cloexec(int domain, int type, int protocol, int *sv)
{
 int ret;
 ret = socketpair(domain, type | SOCK_CLOEXEC, protocol, sv);
 if (ret == 0 || (*__errno_location ()) != 22)
  return ret;
 ret = socketpair(domain, type, protocol, sv);
 if (ret < 0)
  return ret;
 sv[0] = set_cloexec_or_close(sv[0]);
 sv[1] = set_cloexec_or_close(sv[1]);
 if (sv[0] != -1 && sv[1] != -1)
  return 0;
 close(sv[0]);
 close(sv[1]);
 return -1;
}

variable_types: domain int

variable_types: type int

variable_types: protocol int

variable_types:
sv
int *


decompiled_code:
int os_epoll_create_cloexec()
{
int result; // eax
int v1; // eax

result = epoll_create1(0x80000);
if ( result < 0 )
{
if ( *_errno_location() == 22 )
{
v1 = epoll_create(1);
result = set_cloexec_or_close(v1);
}
else
{
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
int v1; // eax

result = epoll_create1(0x80000);
if ( result < 0 )
{
if ( *_errno_location() == 22 )
{
v1 = epoll_create(1);
result = func0(v1);
}
else
{
result = -1;
}
}
return result;
}

original_code:
int
os_epoll_create_cloexec(void)
{
 int fd;
 fd = epoll_create1(EPOLL_CLOEXEC);
 if (fd >= 0)
  return fd;
 if ((*__errno_location ()) != 22)
  return -1;
 fd = epoll_create(1);
 return set_cloexec_or_close(fd);
}

canonical_original_code:
int os_epoll_create_cloexec()
{
 int fd;
 fd = epoll_create1(EPOLL_CLOEXEC);
 if (fd >= 0)
  return fd;
 if ((*__errno_location ()) != 22)
  return -1;
 fd = epoll_create(1);
 return set_cloexec_or_close(fd);
}


decompiled_code:
__int64 __fastcall os_create_anonymous_file(__off_t length)
{
char *v1; // rax
char *v2; // r12
size_t v3; // rbx
char *v4; // rax
char *v5; // rbp
int v6; // er12

v1 = getenv("XDG_RUNTIME_DIR");
if ( !v1 )
{
v6 = -1;
*_errno_location() = 2;
return (unsigned int)v6;
}
v2 = v1;
v3 = strlen(v1);
v4 = (char *)malloc(v3 + 22);
v5 = v4;
if ( !v4 )
goto LABEL_7;
memcpy(v4, v2, v3 + 1);
strcpy(&v5[v3 + 16], "XXXXX");
*(__m128i *)&v5[v3] = _mm_load_si128((const __m128i *)&template_0);
v6 = create_tmpfile_cloexec(v5);
free(v5);
if ( v6 < 0 )
goto LABEL_7;
if ( ftruncate(v6, length) < 0 )
{
close(v6);
LABEL_7:
v6 = -1;
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__off_t length)
{
char *v1; // rax
char *v2; // r12
size_t v3; // rbx
char *v4; // rax
char *v5; // rbp
int v6; // er12

v1 = getenv("XDG_RUNTIME_DIR");
if ( !v1 )
{
v6 = -1;
*_errno_location() = 2;
return (unsigned int)v6;
}
v2 = v1;
v3 = strlen(v1);
v4 = (char *)malloc(v3 + 22);
v5 = v4;
if ( !v4 )
goto LABEL_7;
memcpy(v4, v2, v3 + 1);
strcpy(&v5[v3 + 16], "XXXXX");
*(__m128i *)&v5[v3] = _mm_load_si128((const __m128i *)&template_0);
v6 = func1(v5);
free(v5);
if ( v6 < 0 )
goto LABEL_7;
if ( ftruncate(v6, length) < 0 )
{
close(v6);
LABEL_7:
v6 = -1;
}
return (unsigned int)v6;
}

original_code:
int
os_create_anonymous_file(off_t size)
{
 static const char template[] = "/weston-shared-XXXXXX";
 const char *path;
 char *name;
 int fd;
 path = getenv("XDG_RUNTIME_DIR");
 if (!path) {
  (*__errno_location ()) = 2;
  return -1;
 }
 name = malloc(strlen(path) + sizeof(template));
 if (!name)
  return -1;
 strcpy(name, path);
 strcat(name, template);
 fd = create_tmpfile_cloexec(name);
 free(name);
 if (fd < 0)
  return -1;
 if (ftruncate(fd, size) < 0) {
  close(fd);
  return -1;
 }
 return fd;
}

canonical_original_code:
int os_create_anonymous_file(long size)
{
 static char template[] = "/weston-shared-XXXXXX";
 char *path;
 char *name;
 int fd;
 path = getenv("XDG_RUNTIME_DIR");
 if (!path) {
  (*__errno_location ()) = 2;
  return -1;
 }
 name = malloc(strlen(path) + sizeof(template));
 if (!name)
  return -1;
 strcpy(name, path);
 strcat(name, template);
 fd = create_tmpfile_cloexec(name);
 free(name);
 if (fd < 0)
  return -1;
 if (ftruncate(fd, size) < 0) {
  close(fd);
  return -1;
 }
 return fd;
}

variable_types: size long

variable_types:
template
char []

variable_types:
path
char *


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

result = pilot_widget_create(a1, *(_QWORD *)(a1 + 12), *(_QWORD *)(a1 + 20));
*(_QWORD *)(result + 48) = pilot_canvas_redraw;
*(_BYTE *)(result + 216) |= 1u;
*(_QWORD *)(result + 32) = pilot_canvas_destroy;
return result;
}

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

result = pilot_widget_create(a1, *(_QWORD *)(a1 + 12), *(_QWORD *)(a1 + 20));
*(_QWORD *)(result + 48) = pilot_canvas_redraw;
*(_BYTE *)(result + 216) |= 1u;
*(_QWORD *)(result + 32) = pilot_canvas_destroy;
return result;
}

original_code:
struct pilot_widget *
pilot_canvas_create(struct pilot_widget *parent)
{
 struct pilot_widget *thiz;
 int i;
 thiz = pilot_widget_create(parent, parent->drawingrect);
 thiz->action.redraw = _pilot_canvas_redraw;
 thiz->action.destroy = _pilot_canvas_destroy;
 thiz->focussable = 1;
 return thiz;
}

canonical_original_code:
struct pilot_widget *pilot_canvas_create(struct pilot_widget *parent)
{
 struct pilot_widget *thiz;
 int i;
 thiz = pilot_widget_create(parent, parent->drawingrect);
 thiz->action.redraw = _pilot_canvas_redraw;
 thiz->action.destroy = _pilot_canvas_destroy;
 thiz->focussable = 1;
 return thiz;
}

variable_types:
parent
struct pilot_widget *

variable_types: struct pilot_widget { struct pilot_widget *parent; enum pilot_widget_type_t { EWidgetWindow=0, EWidgetCommon=1 } type; struct pilot_rect { int x; int y; unsigned int w; unsigned int h; } drawingrect; struct { void (*destroy)(struct pilot_widget *thiz); int (*show)(struct pilot_widget *thiz); int (*redraw)(struct pilot_widget *thiz, struct pilot_blit { void *data; struct pilot_rect rect; enum pilot_pixel_format_t { PILOT_DISPLAY_ARGB8888=0, PILOT_DISPLAY_XRGB8888=1 } format; struct { void (*destroy)(struct pilot_blit *thiz); int (*fill)(struct pilot_blit *thiz, unsigned int color); int (*copy)(struct pilot_blit *thiz, struct pilot_blit *src); } action; } *blit); int (*resize)(struct pilot_widget *thiz, unsigned int width, unsigned int height); } action; struct _pilot_list_pilot_widget { struct pilot_widget *item; struct _pilot_list_pilot_widget *next; struct _pilot_list_pilot_widget *it; } childs; struct { struct pilot_widget_keyChanged_slot { void *dest; struct pilot_widget_keyChanged_slot *next; struct pilot_widget_keyChanged_slot *it; int (*action)(void *, unsigned int key, char state); } slots; } keyChanged; struct { struct pilot_widget_mouseMoved_slot { void *dest; struct pilot_widget_mouseMoved_slot *next; struct pilot_widget_mouseMoved_slot *it; int (*action)(void *, unsigned int key, char state); } slots; } mouseMoved; struct { struct pilot_widget_mousebuttonChanged_slot { void *dest; struct pilot_widget_mousebuttonChanged_slot *next; struct pilot_widget_mousebuttonChanged_slot *it; int (*action)(void *, unsigned int key, char state); } slots; } mousebuttonChanged; struct { struct pilot_widget_mousewheelMoved_slot { void *dest; struct pilot_widget_mousewheelMoved_slot *next; struct pilot_widget_mousewheelMoved_slot *it; int (*action)(void *, unsigned int key, char state); } slots; } mousewheelMoved; char focussable; char force_redraw; void *widget; } *

variable_types: i int

user_defined_types: struct pilot_widget { struct pilot_widget *parent; enum pilot_widget_type_t type; struct pilot_rect drawingrect; struct { void (*destroy)(struct pilot_widget *thiz); int (*show)(struct pilot_widget *thiz); int (*redraw)(struct pilot_widget *thiz, struct pilot_blit *blit); int (*resize)(struct pilot_widget *thiz, unsigned int width, unsigned int height); } action; struct _pilot_list_pilot_widget childs; struct { struct pilot_widget_keyChanged_slot slots; } keyChanged; struct { struct pilot_widget_mouseMoved_slot slots; } mouseMoved; struct { struct pilot_widget_mousebuttonChanged_slot slots; } mousebuttonChanged; struct { struct pilot_widget_mousewheelMoved_slot slots; } mousewheelMoved; char focussable; char force_redraw; void *widget; }

user_defined_types: struct pilot_blit { void *data; struct pilot_rect rect; enum pilot_pixel_format_t format; struct { void (*destroy)(struct pilot_blit *thiz); int (*fill)(struct pilot_blit *thiz, unsigned int color); int (*copy)(struct pilot_blit *thiz, struct pilot_blit *src); } action; }


decompiled_code:
__int64 __fastcall pilot_canvas_draw_data(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 224) + 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 224) + 8LL);
}

original_code:
void *
pilot_canvas_draw_data(struct pilot_widget *thiz)
{
 struct pilot_canvas_data *canvas = (struct pilot_canvas_data *)thiz->widget;
 return canvas->data;
}

canonical_original_code:
void *pilot_canvas_draw_data(struct pilot_widget *thiz)
{
 struct pilot_canvas_data *canvas = (struct pilot_canvas_data *)thiz->widget;
 return canvas->data;
}

variable_types: struct pilot_canvas_data { int (*handler)(void *draw_data, struct pilot_blit { void *data; struct pilot_rect { int x; int y; unsigned int w; unsigned int h; } rect; enum pilot_pixel_format_t { PILOT_DISPLAY_ARGB8888=0, PILOT_DISPLAY_XRGB8888=1 } format; struct { void (*destroy)(struct pilot_blit *thiz); int (*fill)(struct pilot_blit *thiz, unsigned int color); int (*copy)(struct pilot_blit *thiz, struct pilot_blit *src); } action; } *blit); void *data; } *

return_type: void *

user_defined_types: struct pilot_canvas_data { int (*handler)(void *draw_data, struct pilot_blit *blit); void *data; }

user_defined_types: enum pilot_widget_type_t { EWidgetWindow=0, EWidgetCommon=1 }

user_defined_types: struct _pilot_list_pilot_widget { struct pilot_widget *item; struct _pilot_list_pilot_widget *next; struct _pilot_list_pilot_widget *it; }

user_defined_types: struct pilot_widget_keyChanged_slot { void *dest; struct pilot_widget_keyChanged_slot *next; struct pilot_widget_keyChanged_slot *it; int (*action)(void *, unsigned int key, char state); }

user_defined_types: struct pilot_widget_mouseMoved_slot { void *dest; struct pilot_widget_mouseMoved_slot *next; struct pilot_widget_mouseMoved_slot *it; int (*action)(void *, unsigned int key, char state); }

user_defined_types: struct pilot_widget_mousebuttonChanged_slot { void *dest; struct pilot_widget_mousebuttonChanged_slot *next; struct pilot_widget_mousebuttonChanged_slot *it; int (*action)(void *, unsigned int key, char state); }

user_defined_types: struct pilot_widget_mousewheelMoved_slot { void *dest; struct pilot_widget_mousewheelMoved_slot *next; struct pilot_widget_mousewheelMoved_slot *it; int (*action)(void *, unsigned int key, char state); }


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

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

original_code:
void
pilot_canvas_data_destroy(struct pilot_canvas_data *thiz)
{
 free(thiz);
}

user_defined_types: struct pilot_rect { int x; int y; unsigned int w; unsigned int h; }

user_defined_types: enum pilot_pixel_format_t { PILOT_DISPLAY_ARGB8888=0, PILOT_DISPLAY_XRGB8888=1 }


decompiled_code:
__int64 __fastcall pilot_canvas_set_draw_handler(__int64 a1, __int64 a2, __int64 a3)
{
void *v5; // rdi

v5 = *(void **)(a1 + 224);
if ( v5 )
pilot_canvas_data_destroy(v5);
if ( !a2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 224) = pilot_canvas_data_create(a2, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
void *v5; // rdi

v5 = *(void **)(a1 + 224);
if ( v5 )
func3(v5);
if ( !a2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 224) = pilot_canvas_data_create(a2, a3);
return 0LL;
}

original_code:
int
pilot_canvas_set_draw_handler(struct pilot_widget *thiz, f_draw_handler handler, void *data)
{
 int ret = -1;
 if (thiz->widget)
 {
  pilot_canvas_data_destroy((struct pilot_canvas_data *)thiz->widget);
 }
 if (handler)
 {
  thiz->widget = (void*)pilot_canvas_data_create(handler,data);
  ret = 0;
 }
 return ret;
}

canonical_original_code:
int pilot_canvas_set_draw_handler(struct pilot_widget *thiz, int (*handler)(void *draw_data, struct pilot_blit *blit), void *data)
{
 int ret = -1;
 if (thiz->widget)
 {
  pilot_canvas_data_destroy((struct pilot_canvas_data *)thiz->widget);
 }
 if (handler)
 {
  thiz->widget = (void *)pilot_canvas_data_create(handler,data);
  ret = 0;
 }
 return ret;
}

variable_types: int (*)(void *draw_data, struct pilot_blit *blit)

variable_types:
data
void *

variable_types: ret int


mipow

repo: mchalek/euler

decompiled_code:
__int64 __fastcall mipow(int a1, int a2)
{
int v2; // ecx
__int64 result; // rax

if ( a2 <= 0 )
return 1LL;
v2 = 0;
LODWORD(result) = 1;
do
{
++v2;
result = (unsigned int)(a1 * (int)result % 250);
}
while ( a2 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
int v2; // ecx
__int64 result; // rax

if ( a2 <= 0 )
return 1LL;
v2 = 0;
LODWORD(result) = 1;
do
{
++v2;
result = (unsigned int)(a1 * (int)result % 250);
}
while ( a2 != v2 );
return result;
}

original_code:
int mipow(int a, int b)
{
    int ret = 1;
    int i;
    for(i = 0; i < b; i++) {
        ret *= a;
        ret %= 250;
    }
    return ret;
}

variable_types: a int

variable_types: b int


nn

decompiled_code:
__int64 __fastcall nn(int a1)
{
int v1; // esi
int v2; // edi
__int64 v3; // rcx
int v4; // eax

v1 = a1;
v2 = a1 % 250;
v3 = v2;
v4 = *((_DWORD *)&path_to_cycle + v2);
if ( v4 < v1 )
{
v2 = *((_DWORD *)&cycle_start + v2);
v1 = (v1 - v4 - 1) % *((_DWORD *)&cycle_len + v3) + 1;
}
return mipow(v2, v1);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
int v1; // esi
int v2; // edi
__int64 v3; // rcx
int v4; // eax

v1 = a1;
v2 = a1 % 250;
v3 = v2;
v4 = *((_DWORD *)&path_to_cycle + v2);
if ( v4 < v1 )
{
v2 = *((_DWORD *)&cycle_start + v2);
v1 = (v1 - v4 - 1) % *((_DWORD *)&cycle_len + v3) + 1;
}
return func8(v2, v1);
}

original_code:
int nn(int n)
{
    int base = n % 250;
    if(n <= path_to_cycle[base]) {
        return mipow(base, n);
    }
    int cycle_remainder = (n - path_to_cycle[base] - 1) % cycle_len[base];
    return mipow(cycle_start[base], 1 + cycle_remainder);
}

variable_types: n int

variable_types: base int


main

original_code:
int main()
{
    init();
    int i;
    long ways[250];
    memset(ways, 0, sizeof(ways));
    ways[0] = 1;
    ways[1] = 1;
    for(i = 2; i <= 250250; i++) {
        long prev[250];
        memcpy(prev, ways, sizeof(prev));
        int j;
        int item = nn(i);
        for(j = 0; j < 250; j++) {
            int k = (j + item) % 250;
            ways[k] += prev[j];
            ways[k] %= 10000000000000000l;
        }
    }
    printf("result: %ld\n", ways[0] - 1);
    return 0;
}

variable_types:
ways
long [250]

variable_types:
prev
long [250]

variable_types: j int

variable_types: item int

variable_types: k int


init

original_code:
void init()
{
    int i;
    cycle_len[0] = 1;
    path_to_cycle[0] = 0;
    cycle_start[0] = 0;
    cycle_len[1] = 1;
    path_to_cycle[1] = 0;
    cycle_start[1] = 1;
    _Bool hit[250];
    int logs[250];
    for(i = 2; i < 250; i++) {
        memset(hit, 0, sizeof(hit));
        memset(logs, 0, sizeof(logs));
        int j = i;
        int k = 1;
        do {
            logs[j] = k++;
            hit[j] = 1;
            j *= i;
            j %= 250;
        } while(!hit[j]);
        cycle_len[i] = k - logs[j];
        path_to_cycle[i] = logs[j] - 1;
        cycle_start[i] = j;
    }
}

variable_types:
hit
_Bool [250]

variable_types:
logs
int [250]