xstrdup

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

result = strdup(a1);
if ( !result )
{
fwrite("Out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
return result;
}

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

result = strdup(a1);
if ( !result )
{
fwrite("Out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
return result;
}

original_code:
char * xstrdup(const char *str)
{
 char *c;
 c = strdup(str);
 if (!c) {
  fprintf(stderr, "Out of memory\n");
  exit(1);
 }
 return c;
}

canonical_original_code:
char *xstrdup(char *str)
{
 char *c;
 c = strdup(str);
 if (!c) {
  fprintf(stderr, "Out of memory\n");
  exit(1);
 }
 return c;
}

variable_types:
str
char *

variable_types:
c
char *

return_type: char *


decompiled_code:
__int64 __fastcall cpu_to_be16(__int16 a1)
{
unsigned __int16 v2; // [rsp+0h] [rbp-2h]

LOBYTE(v2) = HIBYTE(a1);
HIBYTE(v2) = a1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1)
{
unsigned __int16 v2; // [rsp+0h] [rbp-2h]

LOBYTE(v2) = HIBYTE(a1);
HIBYTE(v2) = a1;
return v2;
}

original_code:
be16_t cpu_to_be16(uint16_t x)
{
 be16_t ret;
 uint8_t *tmp = (uint8_t *)(&ret);
 tmp[0] = (x & 0xFF00) >> 8;
 tmp[1] = (x & 0x00FF);
 return ret;
}

canonical_original_code:
unsigned short cpu_to_be16(unsigned short x)
{
 unsigned short ret;
 unsigned char *tmp = (uint8_t *)(&ret);
 tmp[0] = (x & 0xFF00) >> 8;
 tmp[1] = (x & 0x00FF);
 return ret;
}

variable_types:
x
unsigned short

variable_types:
ret
unsigned short

variable_types:
tmp
unsigned char *

return_type: unsigned short


decompiled_code:
__int64 __fastcall cpu_to_be32(int a1)
{
unsigned int v2; // [rsp+0h] [rbp-4h]

LOBYTE(v2) = HIBYTE(a1);
BYTE1(v2) = BYTE2(a1);
BYTE2(v2) = BYTE1(a1);
HIBYTE(v2) = a1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int v2; // [rsp+0h] [rbp-4h]

LOBYTE(v2) = HIBYTE(a1);
BYTE1(v2) = BYTE2(a1);
BYTE2(v2) = BYTE1(a1);
HIBYTE(v2) = a1;
return v2;
}

canonical_original_code:
unsigned int cpu_to_be32(unsigned int x)
{
 unsigned int ret;
 unsigned char *tmp = (uint8_t *)(&ret);
 tmp[0] = (x & 0xFF000000) >> 24;
 tmp[1] = (x & 0x00FF0000) >> 16;
 tmp[2] = (x & 0x0000FF00) >> 8;
 tmp[3] = (x & 0x000000FF);
 return ret;
}

variable_types:
x
unsigned int

variable_types:
ret
unsigned int

return_type: unsigned int


prinfo

decompiled_code:
int prinfo(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = cmdargs[4];
if ( result )
{
va_start(arg, format);
result = vfprintf(stdout, format, arg);
}
return result;
}

canonical_decompiled_code:
int func0(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = cmdargs[4];
if ( result )
{
va_start(arg, format);
result = vfprintf(stdout, format, arg);
}
return result;
}

original_code:
int prinfo(const char *fmt, ...)
{
 int ret;
 va_list va;
 if (!cmdargs.verbose)
  return 0;
 __builtin_va_start(va,fmt);
 ret = vfprintf(stdout, fmt, va);
 __builtin_va_end(va);
 return ret;
}

canonical_original_code:
int prinfo(char *fmt, ...)
{
 int ret;
 __builtin_va_list va;
 if (!cmdargs.verbose)
  return 0;
 __builtin_va_start(va,fmt);
 ret = vfprintf(stdout, fmt, va);
 __builtin_va_end(va);
 return ret;
}

variable_types:
fmt
char *

variable_types: ret int

return_type: int


prerror

decompiled_code:
int prerror(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

original_code:
int prerror(const char *fmt, ...)
{
 int ret;
 va_list va;
 __builtin_va_start(va,fmt);
 ret = vfprintf(stderr, fmt, va);
 __builtin_va_end(va);
 return ret;
}

canonical_original_code:
int prerror(char *fmt, ...)
{
 int ret;
 __builtin_va_list va;
 __builtin_va_start(va,fmt);
 ret = vfprintf(stderr, fmt, va);
 __builtin_va_end(va);
 return ret;
}


oom

decompiled_code:
void __noreturn oom()
{
prerror("ERROR: Out of memory!\n"
"Virtual memory exhausted. Please close some applications, add more RAM or SWAP space.\n");
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
func1("ERROR: Out of memory!\n"
"Virtual memory exhausted. Please close some applications, add more RAM or SWAP space.\n");
exit(1);
}

original_code:
static void oom(void)
{
 prerror("ERROR: Out of memory!\n"
  "Virtual memory exhausted. "
  "Please close some applications, "
  "add more RAM or SWAP space.\n");
 exit(1);
}

canonical_original_code:
static void oom()
{
 prerror("ERROR: Out of memory!\n"
  "Virtual memory exhausted. "
  "Please close some applications, "
  "add more RAM or SWAP space.\n");
 exit(1);
}

return_type: void


prdata

decompiled_code:
int prdata(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stdout, format, arg);
}

canonical_decompiled_code:
int func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stdout, format, arg);
}

original_code:
int prdata(const char *fmt, ...)
{
 int ret;
 va_list va;
 __builtin_va_start(va,fmt);
 ret = vfprintf(stdout, fmt, va);
 __builtin_va_end(va);
 return ret;
}

canonical_original_code:
int prdata(char *fmt, ...)
{
 int ret;
 __builtin_va_list va;
 __builtin_va_start(va,fmt);
 ret = vfprintf(stdout, fmt, va);
 __builtin_va_end(va);
 return ret;
}


decompiled_code:
void __fastcall __noreturn internal_error(const char *a1)
{
prerror("Internal programming error: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1)
{
func1("Internal programming error: %s\n", a1);
exit(1);
}

original_code:
void internal_error(const char *message)
{
 prerror("Internal programming error: %s\n", message);
 exit(1);
}

canonical_original_code:
void internal_error(char *message)
{
 prerror("Internal programming error: %s\n", message);
 exit(1);
}

variable_types:
message
char *


malloce

decompiled_code:
void *__fastcall malloce(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
oom();
return result;
}

canonical_decompiled_code:
void *__fastcall func5(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
func2();
return result;
}

original_code:
void * malloce(size_t size)
{
 void *ret;
 ret = malloc(size);
 if (!ret)
  oom();
 return ret;
}

canonical_original_code:
void *malloce(unsigned long size)
{
 void *ret;
 ret = malloc(size);
 if (!ret)
  oom();
 return ret;
}

variable_types:
size
unsigned long

variable_types:
ret
void *

return_type: void *


realloce

decompiled_code:
void *__fastcall realloce(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
oom();
return result;
}

canonical_decompiled_code:
void *__fastcall func6(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
func2();
return result;
}

original_code:
void * realloce(void *ptr, size_t newsize)
{
 void *ret;
 ret = realloc(ptr, newsize);
 if (!ret)
  oom();
 return ret;
}

canonical_original_code:
void *realloce(void *ptr, unsigned long newsize)
{
 void *ret;
 ret = realloc(ptr, newsize);
 if (!ret)
  oom();
 return ret;
}

variable_types:
ptr
void *

variable_types:
newsize
unsigned long


decompiled_code:
__int64 __fastcall crc8(char a1, char a2)
{
return (unsigned __int8)t_0[(unsigned __int8)(a1 ^ a2)];
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, char a2)
{
return (unsigned __int8)t_0[(unsigned __int8)(a1 ^ a2)];
}

variable_types:
crc
unsigned char

variable_types:
data
unsigned char

variable_types:
t
unsigned char []

return_type: unsigned char


decompiled_code:
__int64 open_output_file()
{
bool v0; // zf
__int64 result; // rax

v0 = strcmp(outfile_name, "-") == 0;
result = !v0;
if ( v0 )
{
outfile = stdout;
}
else
{
outfile = fopen(outfile_name, "w+");
if ( outfile )
{
result = 0LL;
}
else
{
fprintf(stderr, "Could not open OUTPUT_FILE %s\n", outfile_name);
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

v0 = strcmp(outfile_name, "-") == 0;
result = !v0;
if ( v0 )
{
outfile = stdout;
}
else
{
outfile = fopen(outfile_name, "w+");
if ( outfile )
{
result = 0LL;
}
else
{
fprintf(stderr, "Could not open OUTPUT_FILE %s\n", outfile_name);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int open_output_file(void)
{
 if (strcmp(outfile_name, "-") == 0) {
  outfile = stdout;
 } else {
  outfile = fopen(outfile_name, "w+");
  if (!outfile) {
   fprintf(stderr, "Could not open OUTPUT_FILE %s\n",
    outfile_name);
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int open_output_file()
{
 if (strcmp(outfile_name, "-") == 0) {
  outfile = stdout;
 } else {
  outfile = fopen(outfile_name, "w+");
  if (!outfile) {
   fprintf(stderr, "Could not open OUTPUT_FILE %s\n",
    outfile_name);
   return -1;
  }
 }
 return 0;
}


decompiled_code:
char close_output_file()
{
bool v0; // zf
char result; // al

v0 = strcmp(outfile_name, "-") == 0;
result = !v0;
if ( !v0 )
result = fclose(outfile);
return result;
}

canonical_decompiled_code:
char func7()
{
bool v0; // zf
char result; // al

v0 = strcmp(outfile_name, "-") == 0;
result = !v0;
if ( !v0 )
result = fclose(outfile);
return result;
}

original_code:
void close_output_file(void)
{
 if (strcmp(outfile_name, "-") != 0)
  fclose(outfile);
}

canonical_original_code:
void close_output_file()
{
 if (strcmp(outfile_name, "-") != 0)
  fclose(outfile);
}


original_code:
void MD5Update(struct MD5Context *ctx, unsigned char *buf, unsigned len)
{
    uint32_t t;
    t = ctx->bits[0];
    if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
 ctx->bits[1]++;
    ctx->bits[1] += len >> 29;
    t = (t >> 3) & 0x3f;
    if (t) {
 unsigned char *p = &ctx->u.in[t];
 t = 64 - t;
 if (len < t) {
     memcpy(p, buf, len);
     return;
 }
 memcpy(p, buf, t);
 byteReverse(ctx->u.in, 16);
 MD5Transform(ctx->buf, ctx->u.in_u32);
 buf += t;
 len -= t;
    }
    while (len >= 64) {
 memcpy(ctx->u.in, buf, 64);
 byteReverse(ctx->u.in, 16);
 MD5Transform(ctx->buf, ctx->u.in_u32);
 buf += 64;
 len -= 64;
    }
    memcpy(ctx->u.in, buf, len);
}

canonical_original_code:
void MD5Update(struct MD5Context *ctx, unsigned char *buf, unsigned int len)
{
    unsigned int t;
    t = ctx->bits[0];
    if ((ctx->bits[0] = t + ((unsigned int) len << 3)) < t)
 ctx->bits[1]++;
    ctx->bits[1] += len >> 29;
    t = (t >> 3) & 0x3f;
    if (t) {
 unsigned char *p = &ctx->u.in[t];
 t = 64 - t;
 if (len < t) {
     memcpy(p, buf, len);
     return;
 }
 memcpy(p, buf, t);
 byteReverse(ctx->u.in, 16);
 MD5Transform(ctx->buf, ctx->u.in_u32);
 buf += t;
 len -= t;
    }
    while (len >= 64) {
 memcpy(ctx->u.in, buf, 64);
 byteReverse(ctx->u.in, 16);
 MD5Transform(ctx->buf, ctx->u.in_u32);
 buf += 64;
 len -= 64;
    }
    memcpy(ctx->u.in, buf, len);
}

variable_types: struct MD5Context { unsigned int buf[4]; unsigned int bits[2]; union _u { unsigned char in[64]; unsigned int in_u32[16]; } u; } *

variable_types:
buf
unsigned char *

variable_types:
len
unsigned int

variable_types:
t
unsigned int

variable_types:
p
unsigned char *

user_defined_types: struct MD5Context { unsigned int buf[4]; unsigned int bits[2]; union _u u; }


original_code:
void MD5Final(unsigned char *digest, struct MD5Context *ctx)
{
    unsigned count;
    unsigned char *p;
    count = (ctx->bits[0] >> 3) & 0x3F;
    p = &ctx->u.in[count];
    *p++ = 0x80;
    count = 64 - 1 - count;
    if (count < 8) {
 memset(p, 0, count);
 byteReverse(ctx->u.in, 16);
 MD5Transform(ctx->buf, ctx->u.in_u32);
 memset(ctx->u.in, 0, 56);
    } else {
 memset(p, 0, count - 8);
    }
    byteReverse(ctx->u.in, 14);
    ctx->u.in_u32[14] = ctx->bits[0];
    ctx->u.in_u32[15] = ctx->bits[1];
    MD5Transform(ctx->buf, ctx->u.in_u32);
    byteReverse((unsigned char *) ctx->buf, 4);
    memcpy(digest, ctx->buf, 16);
    memset(ctx, 0, sizeof(*ctx));
}

canonical_original_code:
void MD5Final(unsigned char *digest, struct MD5Context *ctx)
{
    unsigned int count;
    unsigned char *p;
    count = (ctx->bits[0] >> 3) & 0x3F;
    p = &ctx->u.in[count];
    *p++ = 0x80;
    count = 64 - 1 - count;
    if (count < 8) {
 memset(p, 0, count);
 byteReverse(ctx->u.in, 16);
 MD5Transform(ctx->buf, ctx->u.in_u32);
 memset(ctx->u.in, 0, 56);
    } else {
 memset(p, 0, count - 8);
    }
    byteReverse(ctx->u.in, 14);
    ctx->u.in_u32[14] = ctx->bits[0];
    ctx->u.in_u32[15] = ctx->bits[1];
    MD5Transform(ctx->buf, ctx->u.in_u32);
    byteReverse((unsigned char *) ctx->buf, 4);
    memcpy(digest, ctx->buf, 16);
    memset(ctx, 0, sizeof(*ctx));
}

variable_types:
digest
unsigned char *

variable_types:
count
unsigned int

user_defined_types: union _u { unsigned char in[64]; unsigned int in_u32[16]; }


dump

decompiled_code:
int __fastcall dump(__int64 a1, __int64 a2, const char *a3)
{
__int64 i; // rbx
unsigned __int8 v4; // dl

fprintf(stderr, "Data dump (%s, %zd bytes):", a3, a2);
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v4 = *(_BYTE *)(a1 + i);
if ( (i & 7) != 0 )
fprintf(stderr, "0x%02x, ", v4);
else
fprintf(stderr, "\n0x%08zx: 0x%02x, ", i, v4);
}
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, const char *a3)
{
__int64 i; // rbx
unsigned __int8 v4; // dl

fprintf(stderr, "Data dump (%s, %zd bytes):", a3, a2);
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v4 = *(_BYTE *)(a1 + i);
if ( (i & 7) != 0 )
fprintf(stderr, "0x%02x, ", v4);
else
fprintf(stderr, "\n0x%08zx: 0x%02x, ", i, v4);
}
}
return fputc(10, stderr);
}

original_code:
void dump(const char *data,
   size_t size,
   const char *description)
{
 size_t i;
 char c;
 fprintf(stderr, "Data dump (%s, %zd bytes):",
         description, size);
 for (i = 0; i < size; i++) {
  c = data[i];
  if (i % 8 == 0) {
   fprintf(stderr, "\n0x%08zx:  0x%02x, ",
    i, c & 0xff);
  } else
   fprintf(stderr, "0x%02x, ", c & 0xff);
 }
 fprintf(stderr, "\n");
}

canonical_original_code:
void dump(char *data, unsigned long size, char *description)
{
 unsigned long i;
 char c;
 fprintf(stderr, "Data dump (%s, %zd bytes):",
         description, size);
 for (i = 0; i < size; i++) {
  c = data[i];
  if (i % 8 == 0) {
   fprintf(stderr, "\n0x%08zx:  0x%02x, ",
    i, c & 0xff);
  } else
   fprintf(stderr, "0x%02x, ", c & 0xff);
 }
 fprintf(stderr, "\n");
}

variable_types:
data
char *

variable_types:
description
char *

variable_types:
i
unsigned long

variable_types: c char


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t n)
{
void *v1; // rax

v1 = malloc(n);
if ( !v1 )
{
fwrite("Out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
return memset(v1, 0, n);
}

canonical_decompiled_code:
void *__fastcall func1(size_t n)
{
void *v1; // rax

v1 = malloc(n);
if ( !v1 )
{
fwrite("Out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
return memset(v1, 0, n);
}

original_code:
void * xmalloc(size_t size)
{
 void *p;
 p = malloc(size);
 if (!p) {
  fprintf(stderr, "Out of memory\n");
  exit(1);
 }
 memset(p, 0, size);
 return p;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
 void *p;
 p = malloc(size);
 if (!p) {
  fprintf(stderr, "Out of memory\n");
  exit(1);
 }
 memset(p, 0, size);
 return p;
}

variable_types:
size
unsigned long

variable_types:
p
void *


xstrdup

variable_types:
str
char *

variable_types:
c
char *


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
fwrite("Out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
fwrite("Out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
return result;
}

original_code:
void * xrealloc(void *in, size_t size)
{
 void *out;
 out = realloc(in, size);
 if (!out) {
  fprintf(stderr, "Out of memory\n");
  exit(1);
 }
 return out;
}

canonical_original_code:
void *xrealloc(void *in, unsigned long size)
{
 void *out;
 out = realloc(in, size);
 if (!out) {
  fprintf(stderr, "Out of memory\n");
  exit(1);
 }
 return out;
}

variable_types:
in
void *

variable_types:
out
void *


repo: mbuesch/pwrtray

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

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

original_code:
static int battery_dummy_max_level(struct battery *b)
{
 return 0;
}

variable_types: struct battery { char *name; int (*on_ac)(struct battery *b); int (*charger_enable)(struct battery *b, int enable); int (*charging)(struct battery *b); int (*min_level)(struct battery *b); int (*max_level)(struct battery *b); int (*charge_level)(struct battery *b); int (*capacity_mAh)(struct battery *b); int (*current_mA)(struct battery *b); int (*temperature_K)(struct battery *b); void (*destroy)(struct battery *b); int (*update)(struct battery *b); unsigned int poll_interval; 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; int emergency_handled; } *

user_defined_types: struct battery { char *name; int (*on_ac)(struct battery *b); int (*charger_enable)(struct battery *b, int enable); int (*charging)(struct battery *b); int (*min_level)(struct battery *b); int (*max_level)(struct battery *b); int (*charge_level)(struct battery *b); int (*capacity_mAh)(struct battery *b); int (*current_mA)(struct battery *b); int (*temperature_K)(struct battery *b); void (*destroy)(struct battery *b); int (*update)(struct battery *b); unsigned int poll_interval; struct sleeptimer timer; int emergency_handled; }

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


decompiled_code:
void __fastcall battery_dummy_destroy(void *a1)
{
free(a1);
}

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

original_code:
static void battery_dummy_destroy(struct battery *b)
{
 struct battery_dummy *bd = ({ __typeof__(((struct battery_dummy *)0)->battery) *__mptr = (b); (struct battery_dummy *)((char *)__mptr - ((size_t)&((struct battery_dummy *)0)->battery)); });
 free(bd);
}

variable_types: struct battery_dummy { struct battery { char *name; int (*on_ac)(struct battery *b); int (*charger_enable)(struct battery *b, int enable); int (*charging)(struct battery *b); int (*min_level)(struct battery *b); int (*max_level)(struct battery *b); int (*charge_level)(struct battery *b); int (*capacity_mAh)(struct battery *b); int (*current_mA)(struct battery *b); int (*temperature_K)(struct battery *b); void (*destroy)(struct battery *b); int (*update)(struct battery *b); unsigned int poll_interval; 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; int emergency_handled; } battery; } *

user_defined_types: struct battery_dummy { struct battery battery; }


decompiled_code:
_QWORD *battery_dummy_probe()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx

v0 = zalloc(0xA8uLL);
v1 = v0;
if ( v0 )
{
battery_init(v0, "dummy");
v1[10] = battery_dummy_destroy;
v1[5] = battery_dummy_max_level;
}
return v1;
}

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

v0 = func2(0xA8uLL);
v1 = v0;
if ( v0 )
{
battery_init(v0, "dummy");
v1[10] = battery_dummy_destroy;
v1[5] = battery_dummy_max_level;
}
return v1;
}

original_code:
static struct battery * battery_dummy_probe(void)
{
 struct battery_dummy *bd;
 bd = zalloc(sizeof(*bd));
 if (!bd)
  return ((void *)0);
 battery_init(&bd->battery, "dummy");
 bd->battery.destroy = battery_dummy_destroy;
 bd->battery.max_level = battery_dummy_max_level;
 return &bd->battery;
}

canonical_original_code:
static struct battery *battery_dummy_probe()
{
 struct battery_dummy *bd;
 bd = zalloc(sizeof(*bd));
 if (!bd)
  return ((void *)0);
 battery_init(&bd->battery, "dummy");
 bd->battery.destroy = battery_dummy_destroy;
 bd->battery.max_level = battery_dummy_max_level;
 return &bd->battery;
}

return_type: struct battery { char *name; int (*on_ac)(struct battery *b); int (*charger_enable)(struct battery *b, int enable); int (*charging)(struct battery *b); int (*min_level)(struct battery *b); int (*max_level)(struct battery *b); int (*charge_level)(struct battery *b); int (*capacity_mAh)(struct battery *b); int (*current_mA)(struct battery *b); int (*temperature_K)(struct battery *b); void (*destroy)(struct battery *b); int (*update)(struct battery *b); unsigned int poll_interval; 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; int emergency_handled; } *


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

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

original_code:
static int default_min_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; }


decompiled_code:
__int64 default_max_brightness()
{
return 100LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 100LL;
}

original_code:
static int default_max_brightness(struct backlight *b)
{
 return 100;
}

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 default_brightness_step()
{
return 1LL;
}

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

original_code:
static int default_brightness_step(struct backlight *b)
{
 return 1;
}


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

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

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


decompiled_code:
__int64 default_set_brightness()
{
return 4294967201LL;
}

original_code:
static int default_set_brightness(struct backlight *b, int value)
{
 return -95;
}

variable_types: value int


decompiled_code:
__int64 default_screen_lock()
{
return 4294967201LL;
}

original_code:
static int default_screen_lock(struct backlight *b, int lock)
{
 return -95;
}

variable_types: lock int


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

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

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


decompiled_code:
__int64 __fastcall do_framebuffer_blank(int a1, int a2)
{
unsigned int v3; // ebx
const char *v4; // rsi

if ( ioctl(a1, 0x4611uLL, 4LL * (a2 != 0)) )
return (unsigned int)-19;
v3 = 0;
if ( *((int *)&cmdargs + 1) > 1 )
{
v4 = "blanked";
if ( !a2 )
v4 = "unblanked";
logdebug("Framebuffer %s\n", v4);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
unsigned int v3; // ebx
const char *v4; // rsi

if ( ioctl(a1, 0x4611uLL, 4LL * (a2 != 0)) )
return (unsigned int)-19;
v3 = 0;
if ( *((int *)&cmdargs + 1) > 1 )
{
v4 = "blanked";
if ( !a2 )
v4 = "unblanked";
logdebug("Framebuffer %s\n", v4);
}
return v3;
}

original_code:
static int do_framebuffer_blank(int fd, int blank)
{
 int ret;
 unsigned long arg;
 arg = blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK;
 ret = ioctl(fd, 0x4611, arg);
 if (ret)
  return -19;
 do { if ((cmdargs.loglevel >= LOGLEVEL_DEBUG)) _logdebug("Framebuffer %s\n", blank ? "blanked" : "unblanked"); } while (0);
 return 0;
}

variable_types: fd int

variable_types: blank int

variable_types: ret int

variable_types:
arg
unsigned long


decompiled_code:
int __fastcall fbblank_init(__int64 a1)
{
const char *v1; // rax
const char *v2; // rbx
int v3; // eax
int v4; // er12
int *v5; // rax
char *v6; // rax

*(_DWORD *)(a1 + 92) = -1;
v1 = (const char *)config_get(backend, "SCREEN", "fbdev", 0LL);
if ( v1 )
{
v2 = v1;
v3 = open(v1, 2);
v4 = v3;
if ( v3 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
LODWORD(v1) = logerr("Failed to open framebuffer dev %s: %s\n", v2, v6);
}
else
{
LODWORD(v1) = do_framebuffer_blank(v3, 0);
if ( (_DWORD)v1 )
{
LODWORD(v1) = close(v4);
}
else
{
*(_DWORD *)(a1 + 96) = 0;
*(_DWORD *)(a1 + 92) = v4;
if ( *((int *)&cmdargs + 1) > 1 )
LODWORD(v1) = logdebug("Opened %s for fb blanking\n", v2);
}
}
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
const char *v1; // rax
const char *v2; // rbx
int v3; // eax
int v4; // er12
int *v5; // rax
char *v6; // rax

*(_DWORD *)(a1 + 92) = -1;
v1 = (const char *)config_get(backend, "SCREEN", "fbdev", 0LL);
if ( v1 )
{
v2 = v1;
v3 = open(v1, 2);
v4 = v3;
if ( v3 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
LODWORD(v1) = logerr("Failed to open framebuffer dev %s: %s\n", v2, v6);
}
else
{
LODWORD(v1) = func8(v3, 0);
if ( (_DWORD)v1 )
{
LODWORD(v1) = close(v4);
}
else
{
*(_DWORD *)(a1 + 96) = 0;
*(_DWORD *)(a1 + 92) = v4;
if ( *((int *)&cmdargs + 1) > 1 )
LODWORD(v1) = logdebug("Opened %s for fb blanking\n", v2);
}
}
}
return (int)v1;
}

original_code:
static void fbblank_init(struct backlight *b)
{
 const char *fbdev;
 int err, fd;
 b->framebuffer_fd = -1;
 fbdev = config_get(backend.config, "SCREEN", "fbdev", ((void *)0));
 if (!fbdev)
  return;
 fd = open(fbdev, 02);
 if (fd < 0) {
  logerr("Failed to open framebuffer dev %s: %s\n",
         fbdev, strerror((*__errno_location ())));
  return;
 }
 err = do_framebuffer_blank(fd, 0);
 if (err) {
  close(fd);
  return;
 }
 b->fb_blanked = 0;
 b->framebuffer_fd = fd;
 do { if ((cmdargs.loglevel >= LOGLEVEL_DEBUG)) _logdebug("Opened %s for fb blanking\n", fbdev); } while (0);
}

canonical_original_code:
static void fbblank_init(struct backlight *b)
{
 char *fbdev;
 int err; int fd;
 b->framebuffer_fd = -1;
 fbdev = config_get(backend.config, "SCREEN", "fbdev", ((void *)0));
 if (!fbdev)
  return;
 fd = open(fbdev, 02);
 if (fd < 0) {
  logerr("Failed to open framebuffer dev %s: %s\n",
         fbdev, strerror((*__errno_location ())));
  return;
 }
 err = do_framebuffer_blank(fd, 0);
 if (err) {
  close(fd);
  return;
 }
 b->fb_blanked = 0;
 b->framebuffer_fd = fd;
 do { if ((cmdargs.loglevel >= LOGLEVEL_DEBUG)) _logdebug("Opened %s for fb blanking\n", fbdev); } while (0);
}

variable_types:
fbdev
char *

variable_types: err int


decompiled_code:
int __fastcall fbblank_exit(__int64 a1)
{
int v2; // edi
int result; // eax

v2 = *(_DWORD *)(a1 + 92);
if ( v2 >= 0 )
{
do_framebuffer_blank(v2, 0);
result = close(*(_DWORD *)(a1 + 92));
*(_DWORD *)(a1 + 92) = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
int v2; // edi
int result; // eax

v2 = *(_DWORD *)(a1 + 92);
if ( v2 >= 0 )
{
func8(v2, 0);
result = close(*(_DWORD *)(a1 + 92));
*(_DWORD *)(a1 + 92) = -1;
}
return result;
}

original_code:
static void fbblank_exit(struct backlight *b)
{
 if (b->framebuffer_fd >= 0) {
  do_framebuffer_blank(b->framebuffer_fd, 0);
  close(b->framebuffer_fd);
  b->framebuffer_fd = -1;
 }
}


decompiled_code:
__int64 __fastcall backlight_poll_callback(__int64 a1)
{
(*(void (__fastcall **)(__int64))(a1 - 32))(a1 - 104);
sleeptimer_set_timeout_relative(a1, *(unsigned int *)(a1 - 24));
return sleeptimer_enqueue(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
(*(void (__fastcall **)(__int64))(a1 - 32))(a1 - 104);
sleeptimer_set_timeout_relative(a1, *(unsigned int *)(a1 - 24));
return sleeptimer_enqueue(a1);
}

original_code:
static void backlight_poll_callback(struct sleeptimer *timer)
{
 struct backlight *b = ({ __typeof__(((struct backlight *)0)->timer) *__mptr = (timer); (struct backlight *)((char *)__mptr - ((size_t)&((struct backlight *)0)->timer)); });
 b->update(b);
 sleeptimer_set_timeout_relative(&b->timer, b->poll_interval);
 sleeptimer_enqueue(&b->timer);
}

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 update_screen_blanking(__int64 a1)
{
int v1; // ebp
int v2; // eax
__int64 result; // rax

v1 = (*(__int64 (**)(void))(a1 + 32))();
v2 = (*(__int64 (__fastcall **)(__int64))(a1 + 56))(a1);
if ( !v2 && v1 )
{
framebuffer_blank(a1, 0);
result = unblock_x11_input((unsigned int)((_DWORD)&backend + 32));
}
else
{
if ( v2 )
block_x11_input((unsigned int)((_DWORD)&backend + 32));
result = framebuffer_blank(a1, 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
int v1; // ebp
int v2; // eax
__int64 result; // rax

v1 = (*(__int64 (**)(void))(a1 + 32))();
v2 = (*(__int64 (__fastcall **)(__int64))(a1 + 56))(a1);
if ( !v2 && v1 )
{
func11(a1, 0);
result = unblock_x11_input((unsigned int)((_DWORD)&backend + 32));
}
else
{
if ( v2 )
block_x11_input((unsigned int)((_DWORD)&backend + 32));
result = func11(a1, 1);
}
return result;
}

original_code:
static void update_screen_blanking(struct backlight *b)
{
 int brightness = b->current_brightness(b);
 int screen_locked = b->screen_is_locked(b);
 if (screen_locked || brightness == 0) {
  if (screen_locked)
   block_x11_input(&backend.x11lock);
  framebuffer_blank(b, 1);
 } else {
  framebuffer_blank(b, 0);
  unblock_x11_input(&backend.x11lock);
 }
}

variable_types: brightness int


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

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

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

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

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

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

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

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:
__int64 __fastcall backlight_set_brightness(__int64 a1)
{
unsigned int v1; // ebp

v1 = (*(__int64 (**)(void))(a1 + 40))();
if ( !v1 )
update_screen_blanking(a1);
return v1;
}

original_code:
int backlight_set_brightness(struct backlight *b, int value)
{
 int err;
 err = b->set_brightness(b, value);
 if (err)
  return err;
 update_screen_blanking(b);
 return 0;
}


decompiled_code:
__int64 __fastcall backlight_screen_lock(__int64 a1)
{
unsigned int v1; // ebp

v1 = (*(__int64 (**)(void))(a1 + 48))();
if ( !v1 )
update_screen_blanking(a1);
return v1;
}

original_code:
int backlight_screen_lock(struct backlight *b, int lock)
{
 int err;
 err = b->screen_lock(b, lock);
 if (err)
  return err;
 update_screen_blanking(b);
 return 0;
}


original_code:
int backlight_fill_pt_message_stat(struct backlight *b, struct pt_message *msg)
{
 int min_brightness, max_brightness, cur_brightness, brightness_step;
 int autodim_enabled, autodim_ac;
 min_brightness = b->min_brightness(b);
 max_brightness = b->max_brightness(b);
 cur_brightness = b->current_brightness(b);
 brightness_step = b->brightness_step(b);
 autodim_enabled = b->autodim_enabled;
 autodim_ac = b->autodim_enabled_on_ac;
 if (autodim_enabled) {
  cur_brightness = backlight_get_percentage(b);
  if (cur_brightness < 0)
   cur_brightness = 100;
  min_brightness = 0;
  max_brightness = 100;
  brightness_step = 1;
 }
 msg->bl_stat.min_brightness = htonl(min_brightness);
 msg->bl_stat.max_brightness = htonl(max_brightness);
 msg->bl_stat.brightness_step = htonl(brightness_step);
 msg->bl_stat.brightness = htonl(cur_brightness);
 msg->bl_stat.flags = autodim_enabled ? htonl((1 << 0)) : 0;
 msg->bl_stat.flags |= autodim_ac ? htonl((1 << 1)) : 0;
 return 0;
}

canonical_original_code:
int backlight_fill_pt_message_stat(struct backlight *b, struct pt_message *msg)
{
 int min_brightness; int max_brightness; int cur_brightness; int brightness_step;
 int autodim_enabled; int autodim_ac;
 min_brightness = b->min_brightness(b);
 max_brightness = b->max_brightness(b);
 cur_brightness = b->current_brightness(b);
 brightness_step = b->brightness_step(b);
 autodim_enabled = b->autodim_enabled;
 autodim_ac = b->autodim_enabled_on_ac;
 if (autodim_enabled) {
  cur_brightness = backlight_get_percentage(b);
  if (cur_brightness < 0)
   cur_brightness = 100;
  min_brightness = 0;
  max_brightness = 100;
  brightness_step = 1;
 }
 msg->bl_stat.min_brightness = htonl(min_brightness);
 msg->bl_stat.max_brightness = htonl(max_brightness);
 msg->bl_stat.brightness_step = htonl(brightness_step);
 msg->bl_stat.brightness = htonl(cur_brightness);
 msg->bl_stat.flags = autodim_enabled ? htonl((1 << 0)) : 0;
 msg->bl_stat.flags |= autodim_ac ? htonl((1 << 1)) : 0;
 return 0;
}

variable_types: struct pt_message { unsigned short id; unsigned short flags; union { struct { unsigned int flags; int min_brightness; int max_brightness; int brightness_step; int brightness; } bl_stat; struct { int brightness; } bl_set; struct { unsigned int flags; int max_percent; } bl_autodim; struct { unsigned int flags; int min_level; int max_level; int level; } bat_stat; struct { int code; } error; }; } *


decompiled_code:
__int64 __fastcall backlight_notify_state_change(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v3[1] = 0LL;
v3[2] = 0LL;
v3[0] = (unsigned __int16)_bswap_16(3841);
v1 = backlight_fill_pt_message_stat(a1, v3);
if ( !v1 )
notify_clients(v3, 2LL);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v3[1] = 0LL;
v3[2] = 0LL;
v3[0] = (unsigned __int16)func15(3841);
v1 = func23(a1, v3);
if ( !v1 )
notify_clients(v3, 2LL);
return v1;
}

original_code:
int backlight_notify_state_change(struct backlight *b)
{
 struct pt_message msg = {
  .id = htons(PTNOTI_BL_CHANGED),
 };
 int err;
 err = backlight_fill_pt_message_stat(b, &msg);
 if (err)
  return err;
 notify_clients(&msg, (1 << 1));
 return 0;
}

variable_types: struct pt_message { unsigned short id; unsigned short flags; union { struct { unsigned int flags; int min_brightness; int max_brightness; int brightness_step; int brightness; } bl_stat; struct { int brightness; } bl_set; struct { unsigned int flags; int max_percent; } bl_autodim; struct { unsigned int flags; int min_level; int max_level; int level; } bat_stat; struct { int code; } error; }; }


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

v2 = backlight_set_percentage_no_notify(a1, a2);
if ( !v2 )
{
backlight_notify_state_change(a1);
update_screen_blanking(a1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebx

v2 = func0(a1, a2);
if ( !v2 )
{
func24(a1);
func16(a1);
}
return v2;
}

original_code:
int backlight_set_percentage(struct backlight *b, unsigned int percent)
{
 int err;
 err = backlight_set_percentage_no_notify(b, percent);
 if (!err) {
  backlight_notify_state_change(b);
  update_screen_blanking(b);
 }
 return err;
}

variable_types:
percent
unsigned int


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 *


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

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

original_code:
static int default_on_ac(struct battery *b)
{
 return 0;
}

variable_types: struct battery { char *name; int (*on_ac)(struct battery *b); int (*charger_enable)(struct battery *b, int enable); int (*charging)(struct battery *b); int (*min_level)(struct battery *b); int (*max_level)(struct battery *b); int (*charge_level)(struct battery *b); int (*capacity_mAh)(struct battery *b); int (*current_mA)(struct battery *b); int (*temperature_K)(struct battery *b); void (*destroy)(struct battery *b); int (*update)(struct battery *b); unsigned int poll_interval; 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; int emergency_handled; } *


decompiled_code:
__int64 default_charger_enable()
{
return 4294967277LL;
}

original_code:
static int default_charger_enable(struct battery *b, int enable)
{
 return -19;
}

variable_types: enable int


decompiled_code:
__int64 __fastcall default_charging(__int64 a1)
{
int v1; // ebp
int v2; // eax
__int64 result; // rax

v1 = (*(__int64 (**)(void))(a1 + 8))();
v2 = battery_get_charge_percent(a1);
if ( v1 < 0 || v2 < 0 )
result = 0xFFFFFFFFLL;
else
result = (v1 != 0) & (unsigned __int8)(v2 <= 94);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // ebp
int v2; // eax
__int64 result; // rax

v1 = (*(__int64 (**)(void))(a1 + 8))();
v2 = func1(a1);
if ( v1 < 0 || v2 < 0 )
result = 0xFFFFFFFFLL;
else
result = (v1 != 0) & (unsigned __int8)(v2 <= 94);
return result;
}

original_code:
static int default_charging(struct battery *b)
{
 int on_ac = b->on_ac(b);
 int percent;
 percent = battery_get_charge_percent(b);
 if (on_ac < 0 || percent < 0)
  return -1;
 return on_ac && percent < 95;
}

variable_types: percent int


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

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

original_code:
static int default_min_level(struct battery *b)
{
 return 0;
}


decompiled_code:
__int64 default_max_level()
{
return 100LL;
}

canonical_decompiled_code:
__int64 func6()
{
return 100LL;
}

original_code:
static int default_max_level(struct battery *b)
{
 return 100;
}


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

original_code:
static int default_charge_level(struct battery *b)
{
 return 0;
}


decompiled_code:
__int64 default_capacity_mAh()
{
return 4294967277LL;
}

original_code:
static int default_capacity_mAh(struct battery *b)
{
 return -19;
}


decompiled_code:
__int64 default_current_mA()
{
return 4294967277LL;
}

original_code:
static int default_current_mA(struct battery *b)
{
 return -19;
}


decompiled_code:
__int64 default_temperature_K()
{
return 4294967277LL;
}

original_code:
static int default_temperature_K(struct battery *b)
{
 return -19;
}


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

if ( *(_DWORD *)(a1 + 96) )
{
(*(void (**)(void))(a1 + 88))();
sleeptimer_init(a1 + 104, "battery", battery_poll_callback);
sleeptimer_set_timeout_relative(a1 + 104, *(unsigned int *)(a1 + 96));
result = sleeptimer_enqueue(a1 + 104);
}
return result;
}

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

if ( *(_DWORD *)(a1 + 96) )
{
(*(void (**)(void))(a1 + 88))();
sleeptimer_init(a1 + 104, "battery", battery_poll_callback);
sleeptimer_set_timeout_relative(a1 + 104, *(unsigned int *)(a1 + 96));
result = sleeptimer_enqueue(a1 + 104);
}
return result;
}

original_code:
static void battery_start(struct battery *b)
{
 if (b->poll_interval) {
  b->update(b);
  sleeptimer_init(&b->timer, "battery", battery_poll_callback);
  sleeptimer_set_timeout_relative(&b->timer, b->poll_interval);
  sleeptimer_enqueue(&b->timer);
 }
}


decompiled_code:
__int64 __fastcall battery_poll_callback(__int64 a1)
{
(*(void (__fastcall **)(__int64))(a1 - 16))(a1 - 104);
sleeptimer_set_timeout_relative(a1, *(unsigned int *)(a1 - 8));
return sleeptimer_enqueue(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
(*(void (__fastcall **)(__int64))(a1 - 16))(a1 - 104);
sleeptimer_set_timeout_relative(a1, *(unsigned int *)(a1 - 8));
return sleeptimer_enqueue(a1);
}

original_code:
static void battery_poll_callback(struct sleeptimer *timer)
{
 struct battery *b = ({ __typeof__(((struct battery *)0)->timer) *__mptr = (timer); (struct battery *)((char *)__mptr - ((size_t)&((struct battery *)0)->timer)); });
 b->update(b);
 sleeptimer_set_timeout_relative(&b->timer, b->poll_interval);
 sleeptimer_enqueue(&b->timer);
}


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

v0 = (__int64 (**)(void))&_start_probe_battery;
if ( &_start_probe_battery >= (_UNKNOWN *)&_stop_probe_battery )
{
LABEL_4:
logerr("Failed to find a battery\n");
v2 = 0LL;
}
else
{
while ( 1 )
{
print_probe_message(v0);
v1 = v0[1]();
v2 = (const char **)v1;
if ( v1 )
break;
v0 += 4;
if ( v0 >= &_stop_probe_battery )
goto LABEL_4;
}
battery_start(v1);
if ( *((int *)&cmdargs + 1) > 1 )
logdebug("Initialized battery driver \"%s\"\n", *v2);
}
return v2;
}

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

v0 = (__int64 (**)(void))&_start_probe_battery;
if ( &_start_probe_battery >= (_UNKNOWN *)&_stop_probe_battery )
{
LABEL_4:
logerr("Failed to find a battery\n");
v2 = 0LL;
}
else
{
while ( 1 )
{
print_probe_message(v0);
v1 = v0[1]();
v2 = (const char **)v1;
if ( v1 )
break;
v0 += 4;
if ( v0 >= &_stop_probe_battery )
goto LABEL_4;
}
func11(v1);
if ( *((int *)&cmdargs + 1) > 1 )
logdebug("Initialized battery driver \"%s\"\n", *v2);
}
return v2;
}

original_code:
struct battery * battery_probe(void)
{
 struct battery *b;
 const struct probe *probe;
 for (probe = &__start_probe_battery; probe < &__stop_probe_battery && ({ print_probe_message(probe); 1; }); probe++) {
  b = probe->func();
  if (b) {
   battery_start(b);
   do { if ((cmdargs.loglevel >= LOGLEVEL_DEBUG)) _logdebug("Initialized battery driver \"%s\"\n", b->name); } while (0);
   return b;
  }
 }
 logerr("Failed to find a battery\n");
 return ((void *)0);
}

canonical_original_code:
struct battery *battery_probe()
{
 struct battery *b;
 struct probe *probe;
 for (probe = &__start_probe_battery; probe < &__stop_probe_battery && ({ print_probe_message(probe); 1; }); probe++) {
  b = probe->func();
  if (b) {
   battery_start(b);
   do { if ((cmdargs.loglevel >= LOGLEVEL_DEBUG)) _logdebug("Initialized battery driver \"%s\"\n", b->name); } while (0);
   return b;
  }
 }
 logerr("Failed to find a battery\n");
 return ((void *)0);
}

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


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

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

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

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

original_code:
void battery_destroy(struct battery *b)
{
 if (b)
  b->destroy(b);
}


original_code:
int battery_fill_pt_message_stat(struct battery *b, struct pt_message *msg)
{
 int on_ac = b->on_ac(b);
 int charging = b->charging(b);
 msg->bat_stat.flags = 0;
 if (on_ac > 0)
  msg->bat_stat.flags |= htonl((1 << 0));
 else if (on_ac < 0)
  msg->bat_stat.flags |= htonl((1 << 1));
 if (charging > 0)
  msg->bat_stat.flags |= htonl((1 << 2));
 else if (charging < 0)
  msg->bat_stat.flags |= htonl((1 << 3));
 msg->bat_stat.min_level = htonl(b->min_level(b));
 msg->bat_stat.max_level = htonl(b->max_level(b));
 msg->bat_stat.level = htonl(b->charge_level(b));
 return 0;
}

variable_types: charging int

user_defined_types: struct pt_message { unsigned short id; unsigned short flags; union { struct { unsigned int flags; int min_brightness; int max_brightness; int brightness_step; int brightness; } bl_stat; struct { int brightness; } bl_set; struct { unsigned int flags; int max_percent; } bl_autodim; struct { unsigned int flags; int min_level; int max_level; int level; } bat_stat; struct { int code; } error; }; }


decompiled_code:
__int64 __fastcall battery_notify_state_change(__int64 a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v4; // rdi
unsigned int v5; // ebx
__int64 v7[5]; // [rsp+0h] [rbp-28h] BYREF

v7[1] = 0LL;
v7[2] = 0LL;
v7[0] = (unsigned __int16)_bswap_16(3842);
battery_emergency_check(a1);
v4 = backend[6];
if ( v4 )
autodim_handle_battery_event(v4, a2, v3);
v5 = battery_fill_pt_message_stat(a1, v7);
if ( !v5 )
notify_clients(v7, 2LL);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v4; // rdi
unsigned int v5; // ebx
__int64 v7[5]; // [rsp+0h] [rbp-28h] BYREF

v7[1] = 0LL;
v7[2] = 0LL;
v7[0] = (unsigned __int16)func14(3842);
func15(a1);
v4 = backend[6];
if ( v4 )
autodim_handle_battery_event(v4, a2, v3);
v5 = func19(a1, v7);
if ( !v5 )
notify_clients(v7, 2LL);
return v5;
}

original_code:
int battery_notify_state_change(struct battery *b)
{
 struct pt_message msg = {
  .id = htons(PTNOTI_BAT_CHANGED),
 };
 int err;
 battery_emergency_check(b);
 if (backend.autodim)
  autodim_handle_battery_event(backend.autodim);
 err = battery_fill_pt_message_stat(b, &msg);
 if (err)
  return err;
 notify_clients(&msg, (1 << 1));
 return 0;
}


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

if ( log_fd )
result = fclose(log_fd);
log_fd = 0LL;
return result;
}

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

if ( log_fd )
result = fclose(log_fd);
log_fd = 0LL;
return result;
}

original_code:
void log_exit(void)
{
 if (log_fd)
  fclose(log_fd);
 log_fd = ((void *)0);
}

canonical_original_code:
void log_exit()
{
 if (log_fd)
  fclose(log_fd);
 log_fd = ((void *)0);
}


loginfo

decompiled_code:
void loginfo(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( *((int *)&cmdargs + 1) > 0 )
{
va_start(va, a1);
write_log(stdout, 30, a1, va);
}
}

canonical_decompiled_code:
void func2(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( *((int *)&cmdargs + 1) > 0 )
{
va_start(va, a1);
func0(stdout, 30, a1, va);
}
}

original_code:
void loginfo(const char *fmt, ...)
{
 va_list args;
 if ((cmdargs.loglevel >= LOGLEVEL_INFO)) {
  __builtin_va_start(args,fmt);
  write_log(stdout, (((3<<3)) | (6)), fmt, args);
  __builtin_va_end(args);
 }
}

canonical_original_code:
void loginfo(char *fmt, ...)
{
 __builtin_va_list args;
 if ((cmdargs.loglevel >= LOGLEVEL_INFO)) {
  __builtin_va_start(args,fmt);
  write_log(stdout, (((3<<3)) | (6)), fmt, args);
  __builtin_va_end(args);
 }
}

variable_types:
fmt
char *


logerr

decompiled_code:
void logerr(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( *((int *)&cmdargs + 1) >= 0 )
{
va_start(va, a1);
write_log(stderr, 27, a1, va);
}
}

canonical_decompiled_code:
void func3(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( *((int *)&cmdargs + 1) >= 0 )
{
va_start(va, a1);
func0(stderr, 27, a1, va);
}
}

original_code:
void logerr(const char *fmt, ...)
{
 va_list args;
 if ((cmdargs.loglevel >= LOGLEVEL_ERROR)) {
  __builtin_va_start(args,fmt);
  write_log(stderr, (((3<<3)) | (3)), fmt, args);
  __builtin_va_end(args);
 }
}

canonical_original_code:
void logerr(char *fmt, ...)
{
 __builtin_va_list args;
 if ((cmdargs.loglevel >= LOGLEVEL_ERROR)) {
  __builtin_va_start(args,fmt);
  write_log(stderr, (((3<<3)) | (3)), fmt, args);
  __builtin_va_end(args);
 }
}


decompiled_code:
void log_initialize()
{
const char *v0; // rdi

v0 = (const char *)*((_QWORD *)&cmdargs + 1);
if ( v0 )
{
log_fd = fopen(v0, "w+");
if ( !log_fd )
logerr("Failed to open logfile: %s\n", *((const char **)&cmdargs + 1));
}
}

canonical_decompiled_code:
void func4()
{
const char *v0; // rdi

v0 = (const char *)*((_QWORD *)&cmdargs + 1);
if ( v0 )
{
log_fd = fopen(v0, "w+");
if ( !log_fd )
func3("Failed to open logfile: %s\n", *((const char **)&cmdargs + 1));
}
}

original_code:
void log_initialize(void)
{
 if (cmdargs.logfile) {
  log_fd = fopen(cmdargs.logfile, "w+");
  if (!log_fd)
   logerr("Failed to open logfile: %s\n", cmdargs.logfile);
 }
}

canonical_original_code:
void log_initialize()
{
 if (cmdargs.logfile) {
  log_fd = fopen(cmdargs.logfile, "w+");
  if (!log_fd)
   logerr("Failed to open logfile: %s\n", cmdargs.logfile);
 }
}


decompiled_code:
__int64 conf_hash()
{
return tiny_hash() & 0x1F;
}

canonical_decompiled_code:
__int64 func0()
{
return tiny_hash() & 0x1F;
}

original_code:
static inline uint_fast8_t conf_hash(const char *str)
{
 return tiny_hash(str) & ((1 << 5) - 1);
}

canonical_original_code:
static inline unsigned char conf_hash(char *str)
{
 return tiny_hash(str) & ((1 << 5) - 1);
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall string_to_int(const char *a1, _DWORD *a2)
{
int v2; // eax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = strtol(a1, &endptr, 0);
if ( endptr == a1 )
return 4294967274LL;
if ( *endptr )
return 4294967274LL;
*a2 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, _DWORD *a2)
{
int v2; // eax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = strtol(a1, &endptr, 0);
if ( endptr == a1 )
return 4294967274LL;
if ( *endptr )
return 4294967274LL;
*a2 = v2;
return 0LL;
}

original_code:
static int string_to_int(const char *string, int *i)
{
 char *tailptr;
 long retval;
 retval = strtol(string, &tailptr, 0);
 if (tailptr == string || tailptr[0] != '\0')
  return -22;
 *i = retval;
 return 0;
}

canonical_original_code:
static int string_to_int(char *string, int *i)
{
 char *tailptr;
 long retval;
 retval = strtol(string, &tailptr, 0);
 if (tailptr == string || tailptr[0] != '\0')
  return -22;
 *i = retval;
 return 0;
}

variable_types:
string
char *

variable_types:
i
int *

variable_types:
tailptr
char *

variable_types: retval long


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

if ( ptr )
{
v2 = (char *)ptr + 16;
v3 = (char *)ptr + 272;
do
{
v4 = *(_QWORD **)v2;
if ( *(_QWORD *)v2 )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[3];
free_item(v5);
}
while ( v4 );
}
v2 += 8;
}
while ( v2 != v3 );
free(*((void **)ptr + 1));
free(ptr);
}
}

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

if ( ptr )
{
v2 = (char *)ptr + 16;
v3 = (char *)ptr + 272;
do
{
v4 = *(_QWORD **)v2;
if ( *(_QWORD *)v2 )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[3];
func2(v5);
}
while ( v4 );
}
v2 += 8;
}
while ( v2 != v3 );
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
static void free_section(struct config_section *s)
{
 unsigned int i;
 struct config_item *it, *next;
 if (s) {
  for (i = 0; i < (1 << 5); i++) {
   for (it = s->item_hashtab[i]; it; it = next) {
    next = it->next;
    free_item(it);
   }
  }
  free(s->name);
  free(s);
 }
}

canonical_original_code:
static void free_section(struct config_section *s)
{
 unsigned int i;
 struct config_item *it; struct config_item *next;
 if (s) {
  for (i = 0; i < (1 << 5); i++) {
   for (it = s->item_hashtab[i]; it; it = next) {
    next = it->next;
    free_item(it);
   }
  }
  free(s->name);
  free(s);
 }
}

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

variable_types:
i
unsigned int

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

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


zalloc

decompiled_code:
void *__fastcall zalloc(size_t size)
{
return calloc(1uLL, size);
}

canonical_decompiled_code:
void *__fastcall func4(size_t size)
{
return calloc(1uLL, size);
}

original_code:
static inline void * zalloc(size_t size)
{
 return calloc(1, size);
}

canonical_original_code:
static inline void *zalloc(unsigned long size)
{
 return calloc(1, size);
}

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall dump_config_tree(__int64 a1)
{
__int64 i; // r15
__int64 v2; // rbx
int v3; // eax
const char *v4; // rcx
__int64 j; // r12
__int64 v6; // r13
__int64 result; // rax
const char *v8; // rcx

if ( *((int *)&cmdargs + 1) > 2 )
logdebug("Parsed config file:\n");
for ( i = 0LL; i != 32; ++i )
{
result = a1;
v6 = *(_QWORD *)(a1 + 8 * i);
if ( v6 )
{
LODWORD(result) = 0;
do
{
if ( *((int *)&cmdargs + 1) > 2 )
{
v8 = "\t\t<== ### COLLISION ###";
if ( !(_DWORD)result )
v8 = (const char *)&unk_711;
logdebug("\t[%02X] Section '%s'%s\n", (unsigned int)i, *(const char **)(v6 + 8), v8);
}
for ( j = 0LL; j != 32; ++j )
{
v2 = *(_QWORD *)(v6 + 8 * j + 16);
if ( v2 )
{
v3 = 0;
do
{
if ( *((int *)&cmdargs + 1) > 2 )
{
v4 = "\t\t<== ### COLLISION ###";
if ( !v3 )
v4 = (const char *)&unk_711;
logdebug("\t\t[%02X] Item '%s'%s\n", (unsigned int)j, *(const char **)(v2 + 8), v4);
}
v2 = *(_QWORD *)(v2 + 24);
v3 = 1;
}
while ( v2 );
}
}
v6 = *(_QWORD *)(v6 + 272);
result = 1LL;
}
while ( v6 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 i; // r15
__int64 v2; // rbx
int v3; // eax
const char *v4; // rcx
__int64 j; // r12
__int64 v6; // r13
__int64 result; // rax
const char *v8; // rcx

if ( *((int *)&cmdargs + 1) > 2 )
logdebug("Parsed config file:\n");
for ( i = 0LL; i != 32; ++i )
{
result = a1;
v6 = *(_QWORD *)(a1 + 8 * i);
if ( v6 )
{
LODWORD(result) = 0;
do
{
if ( *((int *)&cmdargs + 1) > 2 )
{
v8 = "\t\t<== ### COLLISION ###";
if ( !(_DWORD)result )
v8 = (const char *)&unk_711;
logdebug("\t[%02X] Section '%s'%s\n", (unsigned int)i, *(const char **)(v6 + 8), v8);
}
for ( j = 0LL; j != 32; ++j )
{
v2 = *(_QWORD *)(v6 + 8 * j + 16);
if ( v2 )
{
v3 = 0;
do
{
if ( *((int *)&cmdargs + 1) > 2 )
{
v4 = "\t\t<== ### COLLISION ###";
if ( !v3 )
v4 = (const char *)&unk_711;
logdebug("\t\t[%02X] Item '%s'%s\n", (unsigned int)j, *(const char **)(v2 + 8), v4);
}
v2 = *(_QWORD *)(v2 + 24);
v3 = 1;
}
while ( v2 );
}
}
v6 = *(_QWORD *)(v6 + 272);
result = 1LL;
}
while ( v6 );
}
}
return result;
}

original_code:
static void dump_config_tree(struct config_file *f)
{
 struct config_section *s;
 struct config_item *i;
 unsigned int j, k;
 int sect_coll, item_coll;
 const char *collstr = "\t\t<== ### COLLISION ###";
 do { if ((cmdargs.loglevel >= LOGLEVEL_VERBOSE)) _logdebug("Parsed config file:\n"); } while (0);
 for (j = 0; j < (1 << 5); j++) {
  sect_coll = 0;
  for (s = f->section_hashtab[j]; s; s = s->next) {
   do { if ((cmdargs.loglevel >= LOGLEVEL_VERBOSE)) _logdebug("\t[%02X] Section '%s'%s\n", j & 0xFF, s->name, sect_coll ? collstr : ""); } while (0);
   for (k = 0; k < (1 << 5); k++) {
    item_coll = 0;
    for (i = s->item_hashtab[k]; i; i = i->next) {
     do { if ((cmdargs.loglevel >= LOGLEVEL_VERBOSE)) _logdebug("\t\t[%02X] Item '%s'%s\n", k & 0xFF, i->name, item_coll ? collstr : ""); } while (0);
     item_coll = 1;
    }
   }
   sect_coll = 1;
  }
 }
}

canonical_original_code:
static void dump_config_tree(struct config_file *f)
{
 struct config_section *s;
 struct config_item *i;
 unsigned int j; unsigned int k;
 int sect_coll; int item_coll;
 char *collstr = "\t\t<== ### COLLISION ###";
 do { if ((cmdargs.loglevel >= LOGLEVEL_VERBOSE)) _logdebug("Parsed config file:\n"); } while (0);
 for (j = 0; j < (1 << 5); j++) {
  sect_coll = 0;
  for (s = f->section_hashtab[j]; s; s = s->next) {
   do { if ((cmdargs.loglevel >= LOGLEVEL_VERBOSE)) _logdebug("\t[%02X] Section '%s'%s\n", j & 0xFF, s->name, sect_coll ? collstr : ""); } while (0);
   for (k = 0; k < (1 << 5); k++) {
    item_coll = 0;
    for (i = s->item_hashtab[k]; i; i = i->next) {
     do { if ((cmdargs.loglevel >= LOGLEVEL_VERBOSE)) _logdebug("\t\t[%02X] Item '%s'%s\n", k & 0xFF, i->name, item_coll ? collstr : ""); } while (0);
     item_coll = 1;
    }
   }
   sect_coll = 1;
  }
 }
}

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:
j
unsigned int

variable_types:
k
unsigned int

variable_types:
collstr
char *

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


decompiled_code:
__int64 __fastcall config_get(__int64 a1, const char *a2, const char *a3, __int64 a4)
{
__int64 v6; // rbx
__int64 v8; // rbx

if ( a3 != 0LL && a2 != 0LL )
{
if ( a1 )
{
v6 = *(_QWORD *)(a1 + 8LL * (unsigned __int8)conf_hash(a2));
if ( v6 )
{
while ( strcmp(*(const char **)(v6 + 8), a2) )
{
v6 = *(_QWORD *)(v6 + 272);
if ( !v6 )
return a4;
}
v8 = *(_QWORD *)(v6 + 8LL * (unsigned __int8)conf_hash(a3) + 16);
if ( v8 )
{
while ( strcmp(*(const char **)(v8 + 8), a3) )
{
v8 = *(_QWORD *)(v8 + 24);
if ( !v8 )
return a4;
}
a4 = *(_QWORD *)(v8 + 16);
}
}
}
}
return a4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, const char *a3, __int64 a4)
{
__int64 v6; // rbx
__int64 v8; // rbx

if ( a3 != 0LL && a2 != 0LL )
{
if ( a1 )
{
v6 = *(_QWORD *)(a1 + 8LL * (unsigned __int8)func0(a2));
if ( v6 )
{
while ( strcmp(*(const char **)(v6 + 8), a2) )
{
v6 = *(_QWORD *)(v6 + 272);
if ( !v6 )
return a4;
}
v8 = *(_QWORD *)(v6 + 8LL * (unsigned __int8)func0(a3) + 16);
if ( v8 )
{
while ( strcmp(*(const char **)(v8 + 8), a3) )
{
v8 = *(_QWORD *)(v8 + 24);
if ( !v8 )
return a4;
}
a4 = *(_QWORD *)(v8 + 16);
}
}
}
}
return a4;
}

original_code:
const char * config_get(struct config_file *f,
   const char *section,
   const char *item,
   const char *_default)
{
 struct config_section *s;
 struct config_item *i;
 if (!f || !section || !item)
  return _default;
 s = ({ typeof(*(f->section_hashtab[0])) *_e; for (_e = f->section_hashtab[conf_hash(section)]; _e && strcmp(_e->name, (section)) != 0; _e = _e->next); _e; });
 if (s) {
  i = ({ typeof(*(s->item_hashtab[0])) *_e; for (_e = s->item_hashtab[conf_hash(item)]; _e && strcmp(_e->name, (item)) != 0; _e = _e->next); _e; });
  if (i)
   return i->value;
 }
 return _default;
}

canonical_original_code:
char *config_get(struct config_file *f, char *section, char *item, char *_default)
{
 struct config_section *s;
 struct config_item *i;
 if (!f || !section || !item)
  return _default;
 s = ({ typeof(*(f->section_hashtab[0])) *_e; for (_e = f->section_hashtab[conf_hash(section)]; _e && strcmp(_e->name, (section)) != 0; _e = _e->next); _e; });
 if (s) {
  i = ({ typeof(*(s->item_hashtab[0])) *_e; for (_e = s->item_hashtab[conf_hash(item)]; _e && strcmp(_e->name, (item)) != 0; _e = _e->next); _e; });
  if (i)
   return i->value;
 }
 return _default;
}

variable_types:
section
char *

variable_types:
item
char *

user_defined_types: struct config_item { struct config_section *section; char *name; char *value; struct config_item *next; }


decompiled_code:
__int64 __fastcall config_get_int(__int64 a1, const char *a2, const char *a3, unsigned int a4)
{
const char *v5; // 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) )
a4 = v7[0];
return a4;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2, const char *a3, unsigned int a4)
{
const char *v5; // 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) )
a4 = v7[0];
return a4;
}

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


decompiled_code:
int __fastcall config_get_bool(__int64 a1, const char *a2, const char *a3, int a4)
{
const char *v5; // rbx
int result; // eax
int v7; // edx
int v8; // edx
int v9; // edx
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

canonical_decompiled_code:
int __fastcall func8(__int64 a1, const char *a2, const char *a3, int a4)
{
const char *v5; // rbx
int result; // eax
int v7; // edx
int v8; // edx
int v9; // edx
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

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


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

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

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

if ( ptr )
{
v1 = ptr;
v2 = (char *)ptr;
v3 = (char *)ptr + 256;
do
{
v4 = *(_QWORD **)v2;
if ( *(_QWORD *)v2 )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[34];
func3(v5);
}
while ( v4 );
}
v2 += 8;
}
while ( v2 != v3 );
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);
 }
}


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; // rbp

v0 = (__int64 (**)(void))&_start_probe_devicelock;
if ( &_start_probe_devicelock >= (_UNKNOWN *)&_stop_probe_devicelock )
{
LABEL_4:
logerr("Failed to find any devicelock controls.\n");
v2 = 0LL;
}
else
{
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_4;
}
if ( *((int *)&cmdargs + 1) > 1 )
logdebug("Initialized devicelock driver \"%s\"\n", *v1);
}
return v2;
}

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

v0 = (__int64 (**)(void))&_start_probe_devicelock;
if ( &_start_probe_devicelock >= (_UNKNOWN *)&_stop_probe_devicelock )
{
LABEL_4:
logerr("Failed to find any devicelock controls.\n");
v2 = 0LL;
}
else
{
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_4;
}
if ( *((int *)&cmdargs + 1) > 1 )
logdebug("Initialized devicelock driver \"%s\"\n", *v1);
}
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');
}

variable_types:
s
char *


msleep

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

v6.tv_sec = 0LL;
if ( a1 > 0x3E7 )
{
v1 = 1LL;
do
{
v2 = v1;
a1 -= 1000;
++v1;
}
while ( a1 > 0x3E7 );
v6.tv_sec = v2;
}
v6.tv_nsec = 1000000LL * a1;
while ( 1 )
{
result = nanosleep(&v6, &v6);
if ( !result )
break;
v4 = *_errno_location();
if ( v4 != 4 )
{
v5 = strerror(v4);
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 result; // eax
int v4; // edi
char *v5; // rax
struct timespec v6; // [rsp+0h] [rbp-18h] BYREF

v6.tv_sec = 0LL;
if ( a1 > 0x3E7 )
{
v1 = 1LL;
do
{
v2 = v1;
a1 -= 1000;
++v1;
}
while ( a1 > 0x3E7 );
v6.tv_sec = v2;
}
v6.tv_nsec = 1000000LL * a1;
while ( 1 )
{
result = nanosleep(&v6, &v6);
if ( !result )
break;
v4 = *_errno_location();
if ( v4 != 4 )
{
v5 = strerror(v4);
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)
{
char *v1; // rbx
char v2; // bp
const unsigned __int16 *v3; // rax
size_t v4; // rbp
const unsigned __int16 **v5; // rcx

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

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

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

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


decompiled_code:
__int64 __fastcall tiny_hash(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rcx
int v2; // eax
unsigned int v3; // edx

v1 = a1 + 1;
v2 = *a1;
if ( !(_BYTE)v2 )
return 21;
v3 = 21;
do
{
v3 += v2 + 8 * v3;
v2 = *v1++;
}
while ( (_BYTE)v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rcx
int v2; // eax
unsigned int v3; // edx

v1 = a1 + 1;
v2 = *a1;
if ( !(_BYTE)v2 )
return 21;
v3 = 21;
do
{
v3 += v2 + 8 * v3;
v2 = *v1++;
}
while ( (_BYTE)v2 );
return v3;
}

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


decompiled_code:
__int64 __fastcall subprocess_exec(char *s)
{
__int64 result; // rax
int v2; // ebp
char *v3; // rbx
int *v4; // rbx
char *v5; // rax
int *v6; // rax
char *v7; // rax
char *path[32]; // [rsp+10h] [rbp-1118h] BYREF
char dest[8]; // [rsp+110h] [rbp-1018h] BYREF
__int64 v10; // [rsp+118h] [rbp-1010h]
char v11[4080]; // [rsp+120h] [rbp-1008h] BYREF

*(_QWORD *)dest = 0LL;
v10 = 0LL;
memset(v11, 0, sizeof(v11));
memset(path, 0, sizeof(path));
if ( strlen(s) <= 0xFFE )
{
strcpy(dest, s);
v2 = 0;
v3 = dest;
while ( 1 )
{
path[v2] = v3;
v3 = string_split(v3, (unsigned int (__fastcall *)(_QWORD))&isspace);
if ( strempty(path[v2]) )
path[v2--] = 0LL;
if ( !v3 )
break;
if ( (unsigned int)++v2 > 0x1E )
{
logerr("subprocess_exec: Too many arguments: '%s'\n", s);
return -22LL;
}
}
if ( path[0] )
{
LODWORD(result) = vfork();
if ( (int)result < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logerr("subprocess_exec: Failed to fork (%s)\n", v5);
result = -*v4;
}
else
{
result = (int)result;
if ( !(_DWORD)result )
{
execv(path[0], path);
v6 = _errno_location();
v7 = strerror(*v6);
logerr("subprocess_exec: Failed to exec '%s': %s\n", s, v7);
exit(0);
}
}
}
else
{
logerr("subprocess_exec: Too few arguments\n");
result = -22LL;
}
}
else
{
logerr("subprocess_exec: Command too long");
result = -7LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s)
{
__int64 result; // rax
int v2; // ebp
char *v3; // rbx
int *v4; // rbx
char *v5; // rax
int *v6; // rax
char *v7; // rax
char *path[32]; // [rsp+10h] [rbp-1118h] BYREF
char dest[8]; // [rsp+110h] [rbp-1018h] BYREF
__int64 v10; // [rsp+118h] [rbp-1010h]
char v11[4080]; // [rsp+120h] [rbp-1008h] BYREF

*(_QWORD *)dest = 0LL;
v10 = 0LL;
memset(v11, 0, sizeof(v11));
memset(path, 0, sizeof(path));
if ( strlen(s) <= 0xFFE )
{
strcpy(dest, s);
v2 = 0;
v3 = dest;
while ( 1 )
{
path[v2] = v3;
v3 = string_split(v3, (unsigned int (__fastcall *)(_QWORD))&isspace);
if ( func0(path[v2]) )
path[v2--] = 0LL;
if ( !v3 )
break;
if ( (unsigned int)++v2 > 0x1E )
{
logerr("subprocess_exec: Too many arguments: '%s'\n", s);
return -22LL;
}
}
if ( path[0] )
{
LODWORD(result) = vfork();
if ( (int)result < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logerr("subprocess_exec: Failed to fork (%s)\n", v5);
result = -*v4;
}
else
{
result = (int)result;
if ( !(_DWORD)result )
{
execv(path[0], path);
v6 = _errno_location();
v7 = strerror(*v6);
logerr("subprocess_exec: Failed to exec '%s': %s\n", s, v7);
exit(0);
}
}
}
else
{
logerr("subprocess_exec: Too few arguments\n");
result = -22LL;
}
}
else
{
logerr("subprocess_exec: Command too long");
result = -7LL;
}
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:
i
unsigned int

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


decompiled_code:
void __fastcall backlight_dummy_destroy(void *a1)
{
free(a1);
}

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

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; // rbx

v0 = zalloc(0xA0uLL);
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; // rbx

v0 = func2(0xA0uLL);
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;
}


decompiled_code:
void __fastcall list_del(__int64 a1)
{
_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 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

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

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 func3(__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 = func2(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 )
{
*(_QWORD *)(a1 + 96) = v2;
*(_DWORD *)(a1 + 104) = a2;
result = 0LL;
}
else
{
logerr("Out of memory\n");
result = 4294967284LL;
}
return result;
}

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

v2 = realloc(*(void **)(a1 + 96), 8LL * a2);
if ( v2 )
{
*(_QWORD *)(a1 + 96) = v2;
*(_DWORD *)(a1 + 104) = a2;
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; }


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

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

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

result = 0LL;
if ( *(_DWORD *)(a1 + 104) < a2 )
result = func4(a1, a2);
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;
}


decompiled_code:
__int64 __fastcall autodim_optimize_steps(__int64 a1)
{
unsigned int v2; // esi
unsigned int v3; // eax
__int64 v5; // rcx
_DWORD *v6; // rdx
unsigned int v7; // ebp
_DWORD *v8; // rdi

v2 = *(_DWORD *)(a1 + 108);
v3 = 0;
if ( v2 )
{
while ( v2 - 1 > v3 )
{
v5 = *(_QWORD *)(a1 + 96);
v6 = (_DWORD *)(v5 + 8LL * v3);
v7 = v3 + 1;
v8 = (_DWORD *)(v5 + 8LL * (v3 + 1));
if ( v6[1] == v8[1] || *v6 >= *v8 )
{
memmove(v8, (const void *)(v5 + 8LL * (v3 + 2)), 8LL * (v2 - 2 - v3));
--*(_DWORD *)(a1 + 108);
}
v2 = *(_DWORD *)(a1 + 108);
if ( !v2 )
break;
v3 = v7;
}
}
return autodim_force_realloc_steps(a1, v2);
}

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: err int


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

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

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

loginfo("Autodim steps (%s): ", a2);
v2 = *(_DWORD *)(a1 + 108);
if ( v2 )
{
v3 = 0;
do
{
v4 = v3++;
v5 = " ";
if ( v3 == v2 )
v5 = (const char *)&unk_B92;
v6 = (unsigned int *)(*(_QWORD *)(a1 + 96) + 8LL * v4);
loginfo("%u/%u%s", *v6, v6[1], 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 *