setAllCredits

decompiled_code:
void __fastcall setAllCredits(unsigned int a1)
{
__int64 v1; // rbx
unsigned int v2; // eax
unsigned int v3; // ebp

if ( nEntFiles > 0 )
{
v1 = 0LL;
do
{
v3 = v1;
if ( !quiet )
printf("Setting %d credits to %s\n", a1, *(const char **)(entFileNames + 8 * v1));
++v1;
v2 = max(0LL, a1);
writeCredits(v3, v2);
}
while ( nEntFiles > (int)v1 );
}
}

canonical_decompiled_code:
void __fastcall func3(unsigned int a1)
{
__int64 v1; // rbx
unsigned int v2; // eax
unsigned int v3; // ebp

if ( nEntFiles > 0 )
{
v1 = 0LL;
do
{
v3 = v1;
if ( !quiet )
printf("Setting %d credits to %s\n", a1, *(const char **)(entFileNames + 8 * v1));
++v1;
v2 = max(0LL, a1);
writeCredits(v3, v2);
}
while ( nEntFiles > (int)v1 );
}
}

original_code:
void setAllCredits(int credits) {
  for(int i=0;i<nEntFiles;i++) {
    if(!quiet) printf("Setting %d credits to %s\n",credits,entFileNames[i]);
    writeCredits(i,max(0,credits));
  }
}

canonical_original_code:
void setAllCredits(int credits) {
  for(int i = 0;i<nEntFiles;i++) {
    if(!quiet) printf("Setting %d credits to %s\n",credits,entFileNames[i]);
    writeCredits(i,max(0,credits));
  }
}


addAllCredits

repo: mbrx/axe

decompiled_code:
void __fastcall addAllCredits(unsigned int a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
int v4; // eax
unsigned int v5; // eax
unsigned int v6; // er12

if ( nEntFiles > 0 )
{
v2 = 0LL;
do
{
v6 = v2;
if ( !quiet )
printf("Adding %d credits to %s\n", a1, *(const char **)(entFileNames + 8 * v2));
v3 = (unsigned int)v2++;
v4 = readCredits(v3);
v5 = max(0LL, v4 + a1);
writeCredits(v6, v5);
}
while ( nEntFiles > (int)v2 );
}
}

canonical_decompiled_code:
void __fastcall func4(unsigned int a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
int v4; // eax
unsigned int v5; // eax
unsigned int v6; // er12

if ( nEntFiles > 0 )
{
v2 = 0LL;
do
{
v6 = v2;
if ( !quiet )
printf("Adding %d credits to %s\n", a1, *(const char **)(entFileNames + 8 * v2));
v3 = (unsigned int)v2++;
v4 = readCredits(v3);
v5 = max(0LL, v4 + a1);
writeCredits(v6, v5);
}
while ( nEntFiles > (int)v2 );
}
}

original_code:
void addAllCredits(int credits) {
  for(int i=0;i<nEntFiles;i++) {
    if(!quiet) printf("Adding %d credits to %s\n",credits,entFileNames[i]);
    writeCredits(i,max(0,readCredits(i)+credits));
  }
}

canonical_original_code:
void addAllCredits(int credits) {
  for(int i = 0;i<nEntFiles;i++) {
    if(!quiet) printf("Adding %d credits to %s\n",credits,entFileNames[i]);
    writeCredits(i,max(0,readCredits(i)+credits));
  }
}

variable_types: credits int

variable_types: i int

return_type: void


multAllCredits

decompiled_code:
void __fastcall multAllCredits(float a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
int v3; // eax
unsigned int v4; // eax
unsigned int v5; // ebp

if ( nEntFiles > 0 )
{
v1 = 0LL;
do
{
v5 = v1;
if ( !quiet )
printf("Multiplying credits of %s by %.3f\n", *(const char **)(entFileNames + 8 * v1), a1);
v2 = (unsigned int)v1++;
v3 = readCredits(v2);
v4 = max(0LL, (unsigned int)(int)(float)((float)v3 * a1));
writeCredits(v5, v4);
}
while ( nEntFiles > (int)v1 );
}
}

canonical_decompiled_code:
void __fastcall func5(float a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
int v3; // eax
unsigned int v4; // eax
unsigned int v5; // ebp

if ( nEntFiles > 0 )
{
v1 = 0LL;
do
{
v5 = v1;
if ( !quiet )
printf("Multiplying credits of %s by %.3f\n", *(const char **)(entFileNames + 8 * v1), a1);
v2 = (unsigned int)v1++;
v3 = readCredits(v2);
v4 = max(0LL, (unsigned int)(int)(float)((float)v3 * a1));
writeCredits(v5, v4);
}
while ( nEntFiles > (int)v1 );
}
}

original_code:
void multAllCredits(float factor) {
  for(int i=0;i<nEntFiles;i++) {
    if(!quiet) printf("Multiplying credits of %s by %.3f\n",entFileNames[i],factor);
    writeCredits(i,max(0,(int)(readCredits(i)*factor)));
  }
}

canonical_original_code:
void multAllCredits(float factor) {
  for(int i = 0;i<nEntFiles;i++) {
    if(!quiet) printf("Multiplying credits of %s by %.3f\n",entFileNames[i],factor);
    writeCredits(i,max(0,(int)(readCredits(i)*factor)));
  }
}

variable_types: factor float


printAllBlock

decompiled_code:
int __fastcall printAllBlock(unsigned int a1)
{
int result; // eax
unsigned int v2; // er12
unsigned int v3; // ebp
unsigned int v4; // eax

result = nEntFiles;
if ( nEntFiles > 0 )
{
v2 = -1;
v3 = 0;
printf("%s : ", (const char *)*entFileNames);
while ( 1 )
{
v4 = findBlockIndex(0LL, a1, v2);
v2 = v4;
if ( v4 == -1 )
break;
v3 += getValueAsInt(0LL, v4);
}
result = printf("%d\n", v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1)
{
int result; // eax
unsigned int v2; // er12
unsigned int v3; // ebp
unsigned int v4; // eax

result = nEntFiles;
if ( nEntFiles > 0 )
{
v2 = -1;
v3 = 0;
printf("%s : ", (const char *)*entFileNames);
while ( 1 )
{
v4 = findBlockIndex(0LL, a1, v2);
v2 = v4;
if ( v4 == -1 )
break;
v3 += getValueAsInt(0LL, v4);
}
result = printf("%d\n", v3);
}
return result;
}

original_code:
void printAllBlock(int block) {
  for(int i=0;i<nEntFiles;i++) {
    printf("%s : ",entFileNames[i]);
    int prevIndex=-1;
    for(int total=0;;) {
      int index=findBlockIndex(i,block, prevIndex);
      if(index == -1) {
 printf("%d\n",total);
 return;
      }
      prevIndex=index;
      total += getValueAsInt(i,index);
    }
  }
}

canonical_original_code:
void printAllBlock(int block) {
  for(int i = 0;i<nEntFiles;i++) {
    printf("%s : ",entFileNames[i]);
    int prevIndex = -1;
    for(int total = 0;;) {
      int index = findBlockIndex(i,block, prevIndex);
      if(index == -1) {
 printf("%d\n",total);
 return;
      }
      prevIndex=index;
      total += getValueAsInt(i,index);
    }
  }
}

variable_types: block int

variable_types: prevIndex int

variable_types: total int

variable_types: index int


setBlockAmount

decompiled_code:
__int64 __fastcall setBlockAmount(unsigned int a1, __int64 a2, int a3)
{
if ( !a3 )
{
puts("Sorry, we cannot delete items yet - for now it will just have to be a zero entry item");
a2 = (unsigned int)a2;
}
return findBlockIndex(a1, a2, 0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, __int64 a2, int a3)
{
if ( !a3 )
{
puts("Sorry, we cannot delete items yet - for now it will just have to be a zero entry item");
a2 = (unsigned int)a2;
}
return findBlockIndex(a1, a2, 0xFFFFFFFFLL);
}

original_code:
void setBlockAmount(int entId, int block, int amount) {
  if(amount == 0) {
    printf("Sorry, we cannot delete items yet - for now it will just have to be a zero entry item\n");
  }
  int index=findBlockIndex(entId,block,-1);
}

canonical_original_code:
void setBlockAmount(int entId, int block, int amount) {
  if(amount == 0) {
    printf("Sorry, we cannot delete items yet - for now it will just have to be a zero entry item\n");
  }
  int index = findBlockIndex(entId,block,-1);
}

variable_types: entId int

variable_types: amount int


getBlockAmount

decompiled_code:
__int64 __fastcall getBlockAmount(unsigned int a1, unsigned int a2)
{
unsigned int i; // er12
unsigned int v3; // eax

for ( i = 0; ; i += getValueAsInt(a1, v3) )
{
v3 = findBlockIndex(a1, a2, 0xFFFFFFFFLL);
if ( v3 == -1 )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2)
{
unsigned int i; // er12
unsigned int v3; // eax

for ( i = 0; ; i += getValueAsInt(a1, v3) )
{
v3 = findBlockIndex(a1, a2, 0xFFFFFFFFLL);
if ( v3 == -1 )
break;
}
return i;
}

original_code:
int getBlockAmount(int entId, int block) {
  int total=0;
  int prev=-1;
  for(;;) {
    int index=findBlockIndex(entId,block,prev);
    if(index == -1) return total;
    total += getValueAsInt(entId,index);
  }
  return 0;
}

canonical_original_code:
int getBlockAmount(int entId, int block) {
  int total = 0;
  int prev = -1;
  for(;;) {
    int index = findBlockIndex(entId,block,prev);
    if(index == -1) return total;
    total += getValueAsInt(entId,index);
  }
  return 0;
}

variable_types: prev int

return_type: int


setAllBlock

decompiled_code:
int __fastcall setAllBlock(unsigned int a1, unsigned int a2)
{
int result; // eax
__int64 v4; // rbp
unsigned int v5; // eax
unsigned int v6; // er12
unsigned int v7; // er15
unsigned int v8; // eax
__int64 v9; // rsi

result = printf("SetAllBlock %d %d\n", a1, a2);
if ( nEntFiles > 0 )
{
v4 = 0LL;
do
{
while ( 1 )
{
v6 = v4;
printf("Setting block %d in %s\n", a1, *(const char **)(entFileNames + 8 * v4));
v7 = findBlockIndex((unsigned int)v4, a1, 0xFFFFFFFFLL);
if ( v7 == -1 )
break;
v8 = max(0LL, a2);
setValueAsInt((unsigned int)v4, v7, v8);
while ( 1 )
{
result = findBlockIndex((unsigned int)v4, a1, v7);
if ( result == -1 )
break;
v9 = v7;
v7 = result;
setValueAsInt((unsigned int)v4, v9, 0LL);
}
if ( nEntFiles <= (int)++v4 )
return result;
}
if ( !quiet )
printf("Block %d not previously existing in %s\n", a1, *(const char **)(entFileNames + 8 * v4));
++v4;
v5 = max(0LL, a2);
result = createNewBlockEntry(v6, a1, v5);
}
while ( nEntFiles > (int)v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1, unsigned int a2)
{
int result; // eax
__int64 v4; // rbp
unsigned int v5; // eax
unsigned int v6; // er12
unsigned int v7; // er15
unsigned int v8; // eax
__int64 v9; // rsi

result = printf("SetAllBlock %d %d\n", a1, a2);
if ( nEntFiles > 0 )
{
v4 = 0LL;
do
{
while ( 1 )
{
v6 = v4;
printf("Setting block %d in %s\n", a1, *(const char **)(entFileNames + 8 * v4));
v7 = findBlockIndex((unsigned int)v4, a1, 0xFFFFFFFFLL);
if ( v7 == -1 )
break;
v8 = max(0LL, a2);
setValueAsInt((unsigned int)v4, v7, v8);
while ( 1 )
{
result = findBlockIndex((unsigned int)v4, a1, v7);
if ( result == -1 )
break;
v9 = v7;
v7 = result;
setValueAsInt((unsigned int)v4, v9, 0LL);
}
if ( nEntFiles <= (int)++v4 )
return result;
}
if ( !quiet )
printf("Block %d not previously existing in %s\n", a1, *(const char **)(entFileNames + 8 * v4));
++v4;
v5 = max(0LL, a2);
result = createNewBlockEntry(v6, a1, v5);
}
while ( nEntFiles > (int)v4 );
}
return result;
}

original_code:
void setAllBlock(int block, int amount) {
  printf("SetAllBlock %d %d\n",block,amount);
  for(int i=0;i<nEntFiles;i++) {
    printf("Setting block %d in %s\n",block,entFileNames[i]);
    int first=findBlockIndex(i,block,-1);
    if(first != -1) {
      setValueAsInt(i,first,max(0,amount));
      while(1) {
 int next=findBlockIndex(i,block,first);
 if(next == -1) break;
 setValueAsInt(i,first,0);
 first=next;
      }
    }
    else {
      if(!quiet) printf("Block %d not previously existing in %s\n",block,entFileNames[i]);
      createNewBlockEntry(i, block, max(0,amount));
    }
  }
}

canonical_original_code:
void setAllBlock(int block, int amount) {
  printf("SetAllBlock %d %d\n",block,amount);
  for(int i = 0;i<nEntFiles;i++) {
    printf("Setting block %d in %s\n",block,entFileNames[i]);
    int first = findBlockIndex(i,block,-1);
    if(first != -1) {
      setValueAsInt(i,first,max(0,amount));
      while(1) {
 int next = findBlockIndex(i,block,first);
 if(next == -1) break;
 setValueAsInt(i,first,0);
 first=next;
      }
    }
    else {
      if(!quiet) printf("Block %d not previously existing in %s\n",block,entFileNames[i]);
      createNewBlockEntry(i, block, max(0,amount));
    }
  }
}

variable_types: first int

variable_types: next int


addAllBlock

decompiled_code:
int __fastcall addAllBlock(unsigned int a1, unsigned int a2)
{
int result; // eax
__int64 v4; // rbx
int v5; // eax
unsigned int v6; // eax
__int64 v7; // rdi
unsigned int v8; // er13
unsigned int v9; // eax
unsigned int v10; // ebp
unsigned int v11; // eax

result = printf("AddAllBlock %d %d\n", a1, a2);
if ( nEntFiles > 0 )
{
v4 = 0LL;
do
{
while ( 1 )
{
v8 = v4;
v9 = findBlockIndex((unsigned int)v4, a1, 0xFFFFFFFFLL);
v10 = v9;
if ( v9 == -1 )
break;
v5 = getValueAsInt((unsigned int)v4, v9);
v6 = max(0LL, v5 + a2);
v7 = (unsigned int)v4++;
result = setValueAsInt(v7, v10, v6);
if ( nEntFiles <= (int)v4 )
return result;
}
if ( !quiet )
printf("Block %d not previously existing in %s\n", a1, *(const char **)(entFileNames + 8 * v4));
++v4;
v11 = max(0LL, a2);
result = createNewBlockEntry(v8, a1, v11);
}
while ( nEntFiles > (int)v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, unsigned int a2)
{
int result; // eax
__int64 v4; // rbx
int v5; // eax
unsigned int v6; // eax
__int64 v7; // rdi
unsigned int v8; // er13
unsigned int v9; // eax
unsigned int v10; // ebp
unsigned int v11; // eax

result = printf("AddAllBlock %d %d\n", a1, a2);
if ( nEntFiles > 0 )
{
v4 = 0LL;
do
{
while ( 1 )
{
v8 = v4;
v9 = findBlockIndex((unsigned int)v4, a1, 0xFFFFFFFFLL);
v10 = v9;
if ( v9 == -1 )
break;
v5 = getValueAsInt((unsigned int)v4, v9);
v6 = max(0LL, v5 + a2);
v7 = (unsigned int)v4++;
result = setValueAsInt(v7, v10, v6);
if ( nEntFiles <= (int)v4 )
return result;
}
if ( !quiet )
printf("Block %d not previously existing in %s\n", a1, *(const char **)(entFileNames + 8 * v4));
++v4;
v11 = max(0LL, a2);
result = createNewBlockEntry(v8, a1, v11);
}
while ( nEntFiles > (int)v4 );
}
return result;
}

original_code:
void addAllBlock(int block, int amount) {
  printf("AddAllBlock %d %d\n",block,amount);
  for(int i=0;i<nEntFiles;i++) {
    int index=findBlockIndex(i,block,-1);
    if(index != -1) setValueAsInt(i,index,max(0,getValueAsInt(i,index)+amount));
    else {
      if(!quiet) printf("Block %d not previously existing in %s\n",block,entFileNames[i]);
      createNewBlockEntry(i, block, max(0,amount));
    }
  }
}

canonical_original_code:
void addAllBlock(int block, int amount) {
  printf("AddAllBlock %d %d\n",block,amount);
  for(int i = 0;i<nEntFiles;i++) {
    int index = findBlockIndex(i,block,-1);
    if(index != -1) setValueAsInt(i,index,max(0,getValueAsInt(i,index)+amount));
    else {
      if(!quiet) printf("Block %d not previously existing in %s\n",block,entFileNames[i]);
      createNewBlockEntry(i, block, max(0,amount));
    }
  }
}


multAllBlock

decompiled_code:
__int64 __fastcall multAllBlock(unsigned int a1, float a2)
{
__int64 result; // rax
__int64 v3; // rbx
unsigned int v4; // ebp
int v5; // eax
unsigned int v6; // eax

printf("MultAllBlock %d %f\n", a1, a2);
result = nEntFiles;
if ( nEntFiles > 0 )
{
v3 = 0LL;
do
{
printf("Multiplying block %d in %s\n", a1, *(const char **)(entFileNames + 8 * v3));
result = findBlockIndex((unsigned int)v3, a1, 0xFFFFFFFFLL);
v4 = result;
if ( (_DWORD)result != -1 )
{
v5 = getValueAsInt((unsigned int)v3, (unsigned int)result);
v6 = max(0LL, (unsigned int)(int)(float)((float)v5 * a2));
result = setValueAsInt((unsigned int)v3, v4, v6);
}
++v3;
}
while ( nEntFiles > (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, float a2)
{
__int64 result; // rax
__int64 v3; // rbx
unsigned int v4; // ebp
int v5; // eax
unsigned int v6; // eax

printf("MultAllBlock %d %f\n", a1, a2);
result = nEntFiles;
if ( nEntFiles > 0 )
{
v3 = 0LL;
do
{
printf("Multiplying block %d in %s\n", a1, *(const char **)(entFileNames + 8 * v3));
result = findBlockIndex((unsigned int)v3, a1, 0xFFFFFFFFLL);
v4 = result;
if ( (_DWORD)result != -1 )
{
v5 = getValueAsInt((unsigned int)v3, (unsigned int)result);
v6 = max(0LL, (unsigned int)(int)(float)((float)v5 * a2));
result = setValueAsInt((unsigned int)v3, v4, v6);
}
++v3;
}
while ( nEntFiles > (int)v3 );
}
return result;
}

original_code:
void multAllBlock(int block, float factor) {
  printf("MultAllBlock %d %f\n",block,factor);
  for(int i=0;i<nEntFiles;i++) {
    printf("Multiplying block %d in %s\n",block,entFileNames[i]);
    int index=findBlockIndex(i,block,-1);
    if(index != -1) setValueAsInt(i,index,max(0,getValueAsInt(i,index)*factor));
    else {
    }
  }
}

canonical_original_code:
void multAllBlock(int block, float factor) {
  printf("MultAllBlock %d %f\n",block,factor);
  for(int i = 0;i<nEntFiles;i++) {
    printf("Multiplying block %d in %s\n",block,entFileNames[i]);
    int index = findBlockIndex(i,block,-1);
    if(index != -1) setValueAsInt(i,index,max(0,getValueAsInt(i,index)*factor));
    else {
    }
  }
}


printFrom

decompiled_code:
__int64 __fastcall printFrom(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
char *v3; // [rsp+0h] [rbp-186C0h] BYREF
char v4[100024]; // [rsp+8h] [rbp-186B8h] BYREF

result = nEntFiles;
if ( nEntFiles > 0 )
{
v2 = 0LL;
do
{
puts(*(const char **)(entFileNames + 8 * v2));
result = readTag((unsigned int)v2, a1, v4, 100000LL);
if ( (int)result > 0 )
{
v3 = v4;
result = printStruct(&v3);
}
++v2;
}
while ( nEntFiles > (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
char *v3; // [rsp+0h] [rbp-186C0h] BYREF
char v4[100024]; // [rsp+8h] [rbp-186B8h] BYREF

result = nEntFiles;
if ( nEntFiles > 0 )
{
v2 = 0LL;
do
{
puts(*(const char **)(entFileNames + 8 * v2));
result = readTag((unsigned int)v2, a1, v4, 100000LL);
if ( (int)result > 0 )
{
v3 = v4;
result = printStruct(&v3);
}
++v2;
}
while ( nEntFiles > (int)v2 );
}
return result;
}

original_code:
void printFrom(char *tag) {
  uint8_t buf[100000];
  for(int i=0;i<nEntFiles;i++) {
    printf("%s\n",entFileNames[i]);
    int len=readTag(i,tag,buf,sizeof(buf));
    if(len>0) {
      uint8_t *pnt=buf;
      printStruct(&pnt);
    }
  }
}

canonical_original_code:
void printFrom(char *tag) {
  unsigned char buf[100000];
  for(int i = 0;i<nEntFiles;i++) {
    printf("%s\n",entFileNames[i]);
    int len = readTag(i,tag,buf,sizeof(buf));
    if(len>0) {
      unsigned char *pnt = buf;
      printStruct(&pnt);
    }
  }
}

variable_types:
tag
char *

variable_types:
buf
unsigned char [100000]

variable_types: len int

variable_types:
pnt
unsigned char *


min

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

original_code: int min(int a,int b) { return a<b?a:b;}

canonical_original_code: int min(int a, int b) { return a<b?a:b;}

variable_types: a int

variable_types: b int


max

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

original_code: int max(int a,int b) { return a>b?a:b;}

canonical_original_code: int max(int a, int b) { return a>b?a:b;}


decompiled_code:
__int16 __fastcall bufToUInt16(_WORD *a1)
{
return __ROL2__(*a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func3(_WORD *a1)
{
return __ROL2__(*a1, 8);
}

original_code:
uint16_t bufToUInt16(uint8_t *buf) {
  return (buf[0]<<8) | (buf[1]<<0);
}

canonical_original_code:
unsigned short bufToUInt16(unsigned char *buf) {
  return (buf[0]<<8) | (buf[1]<<0);
}

variable_types:
buf
unsigned char *

return_type: unsigned short


decompiled_code:
__int64 __fastcall bufToUInt32(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

canonical_original_code:
unsigned int bufToUInt32(unsigned char *buf) {
  return (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | (buf[3]<<0);
}

return_type: unsigned int


decompiled_code:
unsigned __int64 __fastcall bufToUInt64(unsigned __int64 *a1)
{
return _byteswap_uint64(*a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(unsigned __int64 *a1)
{
return _byteswap_uint64(*a1);
}

canonical_original_code:
unsigned long bufToUInt64(unsigned char *buf) {
  return (((unsigned long)buf[0])<<56) | (((unsigned long)buf[1])<<48) | (((unsigned long)buf[2])<<40) | (((unsigned long)buf[3])<<32) | (((unsigned long)buf[4])<<24) | (((unsigned long)buf[5])<<16) | (((unsigned long)buf[6])<<8) | (((unsigned long)buf[7])<<0);
}

return_type: unsigned long


decompiled_code:
__int16 __fastcall bufToInt16(_WORD *a1)
{
return __ROL2__(*a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func6(_WORD *a1)
{
return __ROL2__(*a1, 8);
}

original_code:
int16_t bufToInt16(uint8_t *buf) {
  return (buf[0]<<8) | (buf[1]<<0);
}

canonical_original_code:
short bufToInt16(unsigned char *buf) {
  return (buf[0]<<8) | (buf[1]<<0);
}

return_type: short


decompiled_code:
__int64 __fastcall bufToInt32(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}


decompiled_code:
unsigned __int64 __fastcall bufToInt64(unsigned __int64 *a1)
{
return _byteswap_uint64(*a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(unsigned __int64 *a1)
{
return _byteswap_uint64(*a1);
}

return_type: long


bufToFloat

decompiled_code:
float __fastcall bufToFloat(__int64 a1)
{
return *(float *)a1;
}

canonical_decompiled_code:
float __fastcall func9(__int64 a1)
{
return *(float *)a1;
}

original_code:
float bufToFloat(uint8_t *buf) {
  return *((float*) buf);
}

canonical_original_code:
float bufToFloat(unsigned char *buf) {
  return *((float *) buf);
}

return_type: float


hexDump

original_code:
void hexDump(void *data,int datalen) {
  int i, row, nRows=datalen/16;
  for(row=0;row<nRows||(row==nRows && datalen%16 != 0);row++) {
    for(i=0;i<16 && (row < nRows || i < (datalen%16));i++) {
      printf("%02x",((unsigned char*)data)[i+row*16]);
      if(i % 4 == 3) printf(" ");
    }
    for(;i<16;i++) {
      printf("  ");
      if(i % 4 == 3) printf(" ");
    }
    printf("    ");
    for(i=0;i<16 && (row < nRows || i < (datalen%16));i++) {
      unsigned char c = ((unsigned char*)data)[i+row*16];
      if(isprint(c))
 printf("%c",((unsigned char*)data)[i+row*16]);
      else
 printf("@");
      if(i % 4 == 3) printf(" ");
    }
    printf("\n");
  }
}

canonical_original_code:
void hexDump(void *data, int datalen) {
  int i; int row; int nRows = datalen/16;
  for(row=0;row<nRows||(row==nRows && datalen%16 != 0);row++) {
    for(i=0;i<16 && (row < nRows || i < (datalen%16));i++) {
      printf("%02x",((unsigned char *)data)[i+row*16]);
      if(i % 4 == 3) printf(" ");
    }
    for(;i<16;i++) {
      printf("  ");
      if(i % 4 == 3) printf(" ");
    }
    printf("    ");
    for(i=0;i<16 && (row < nRows || i < (datalen%16));i++) {
      unsigned char c = ((unsigned char*)data)[i+row*16];
      if(isprint(c))
 printf("%c",((unsigned char *)data)[i+row*16]);
      else
 printf("@");
      if(i % 4 == 3) printf(" ");
    }
    printf("\n");
  }
}

variable_types:
data
void *

variable_types: datalen int

variable_types: i int

variable_types: row int

variable_types: nRows int

variable_types:
c
unsigned char


min

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}


max

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}


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

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

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

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

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


original_code:
static void assemble_write_mmio(struct ivals_context *ctx,
    unsigned int offset,
    unsigned int size,
    unsigned int value)
{
 struct initval *iv;
 iv = xmalloc(sizeof(struct initval));
 iv->offset = offset;
 iv->size = size;
 iv->value = value;
 do { (&iv->list)->next = (&iv->list); (&iv->list)->prev = (&iv->list); } while (0);
 list_add_tail(&iv->list, &ctx->ivals);
 ctx->ivals_count++;
}

variable_types: struct ivals_context { struct initvals_sect { char *name; struct list_head { struct list_head *next; } ops; struct list_head list; } *sect; struct list_head ivals; unsigned int ivals_count; } *

variable_types:
offset
unsigned int

variable_types:
size
unsigned int

variable_types:
value
unsigned int

variable_types: struct initval { unsigned int offset; unsigned int size; unsigned int value; struct list_head { struct list_head *next; } list; } *

user_defined_types: struct initval { unsigned int offset; unsigned int size; unsigned int value; struct list_head list; }

user_defined_types: struct ivals_context { struct initvals_sect *sect; struct list_head ivals; unsigned int ivals_count; }

user_defined_types: struct initvals_sect { char *name; struct list_head ops; struct list_head list; }


decompiled_code:
void __fastcall assemble_write_phy(__int64 a1, int a2, int a3)
{
assemble_write_mmio(a1, 1020, 2, a2);
assemble_write_mmio(a1, 1022, 2, a3);
}

original_code:
static void assemble_write_phy(struct ivals_context *ctx,
          unsigned int offset,
          unsigned int value)
{
 assemble_write_mmio(ctx, 0x3FC, 2, offset);
 assemble_write_mmio(ctx, 0x3FE, 2, value);
}

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
void __fastcall assemble_write_radio(__int64 a1, int a2, int a3)
{
assemble_write_mmio(a1, 1014, 2, a2);
assemble_write_mmio(a1, 1018, 2, a3);
}

original_code:
static void assemble_write_radio(struct ivals_context *ctx,
     unsigned int offset,
     unsigned int value)
{
 assemble_write_mmio(ctx, 0x3F6, 2, offset);
 assemble_write_mmio(ctx, 0x3FA, 2, value);
}


decompiled_code:
void __fastcall shm_control_word(__int64 a1, int a2, unsigned __int16 a3)
{
assemble_write_mmio(a1, 352, 4, (a2 << 16) | a3);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2, unsigned __int16 a3)
{
func3(a1, 352, 4, (a2 << 16) | a3);
}

original_code:
static void shm_control_word(struct ivals_context *ctx,
        unsigned int routing,
        unsigned int offset)
{
 unsigned int control;
 control = (routing & 0xFFFF);
 control <<= 16;
 control |= (offset & 0xFFFF);
 assemble_write_mmio(ctx, 0x160, 4, control);
}

variable_types:
routing
unsigned int

variable_types:
control
unsigned int


decompiled_code:
void __fastcall shm_write16(__int64 a1, char a2, unsigned int a3, int a4)
{
char v5; // al

if ( a2 == 1 && (v5 = a3, a3 >>= 2, (v5 & 3) != 0) )
{
shm_control_word(a1, a2, a3);
assemble_write_mmio(a1, 358, 2, a4);
}
else
{
shm_control_word(a1, a2, a3);
assemble_write_mmio(a1, 356, 2, a4);
}
}

original_code:
static void shm_write16(struct ivals_context *ctx,
   unsigned int routing,
   unsigned int offset,
   unsigned int value)
{
 if ((routing & 0xFF) == 0x01) {
  if (offset & 0x0003) {
   shm_control_word(ctx, routing, offset >> 2);
   assemble_write_mmio(ctx, 0x166, 2,
         value);
   return;
  }
  offset >>= 2;
 }
 shm_control_word(ctx, routing, offset);
 assemble_write_mmio(ctx, 0x164, 2, value);
}


decompiled_code:
void __fastcall shm_write32(__int64 a1, char a2, unsigned int a3, unsigned int a4)
{
unsigned int v5; // er12
int v6; // ecx
int v7; // edx

LOWORD(v5) = a3;
if ( a2 == 1 && (v5 = a3 >> 2, (a3 & 3) != 0) )
{
shm_control_word(a1, a2, v5);
assemble_write_mmio(a1, 358, 2, HIWORD(a4));
shm_control_word(a1, a2, v5 + 1);
v6 = (unsigned __int16)a4;
v7 = 2;
}
else
{
shm_control_word(a1, a2, v5);
v6 = a4;
v7 = 4;
}
assemble_write_mmio(a1, 356, v7, v6);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, char a2, unsigned int a3, unsigned int a4)
{
unsigned int v5; // er12
int v6; // ecx
int v7; // edx

LOWORD(v5) = a3;
if ( a2 == 1 && (v5 = a3 >> 2, (a3 & 3) != 0) )
{
func6(a1, a2, v5);
func3(a1, 358, 2, HIWORD(a4));
func6(a1, a2, v5 + 1);
v6 = (unsigned __int16)a4;
v7 = 2;
}
else
{
func6(a1, a2, v5);
v6 = a4;
v7 = 4;
}
func3(a1, 356, v7, v6);
}

original_code:
static void shm_write32(struct ivals_context *ctx,
   unsigned int routing,
   unsigned int offset,
   unsigned int value)
{
 if ((routing & 0xFF) == 0x01) {
  if (offset & 0x0003) {
   shm_control_word(ctx, routing, offset >> 2);
   assemble_write_mmio(ctx, 0x166, 2,
         (value >> 16) & 0xFFFF);
   shm_control_word(ctx, routing, (offset >> 2) + 1);
   assemble_write_mmio(ctx, 0x164, 2,
         (value & 0xFFFF));
   return;
  }
  offset >>= 2;
 }
 shm_control_word(ctx, routing, offset);
 assemble_write_mmio(ctx, 0x164, 4, value);
}


decompiled_code:
void __fastcall assemble_write_tram(__int64 a1, int a2, int a3)
{
assemble_write_mmio(a1, 304, 4, a2);
assemble_write_mmio(a1, 308, 4, a3);
}

original_code:
static void assemble_write_tram(struct ivals_context *ctx,
    unsigned int offset,
    unsigned int value)
{
 assemble_write_mmio(ctx, 0x130, 4, offset);
 assemble_write_mmio(ctx, 0x134, 4, value);
}


decompiled_code:
void __fastcall assemble_write_shm(__int64 a1, char a2, unsigned int a3, unsigned int a4, int a5)
{
if ( a5 == 2 )
{
shm_write16(a1, a2, a3, a4);
}
else
{
if ( a5 != 4 )
{
fwrite("Internal assembler BUG. SHMwrite invalid size\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
shm_write32(a1, a2, a3, a4);
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, char a2, unsigned int a3, unsigned int a4, int a5)
{
if ( a5 == 2 )
{
func7(a1, a2, a3, a4);
}
else
{
if ( a5 != 4 )
{
fwrite("Internal assembler BUG. SHMwrite invalid size\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
func8(a1, a2, a3, a4);
}
}

original_code:
static void assemble_write_shm(struct ivals_context *ctx,
          unsigned int routing,
          unsigned int offset,
          unsigned int value,
          unsigned int size)
{
 switch (routing & 0xFF) {
 case 0: case 1: case 2: case 3: case 4:
  break;
 default:
  break;
 }
 switch (size) {
 case 2:
  shm_write16(ctx, routing, offset, value);
  break;
 case 4:
  shm_write32(ctx, routing, offset, value);
  break;
 default:
  fprintf(stderr, "Internal assembler BUG. SHMwrite invalid size\n");
  exit(1);
 }
}


decompiled_code:
__int64 __fastcall initval_to_raw(const char ***a1, __int64 a2, unsigned int *a3)
{
unsigned int v4; // eax
__int64 result; // rax

*(_DWORD *)a2 = 0;
*(_WORD *)(a2 + 4) = 0;
if ( (*a3 & 0xFFFF8000) != 0 )
{
fwrite("InitVals ERROR", 1uLL, 0xEuLL, stderr);
fprintf(stderr, " (Section \"%s\")", **a1);
fprintf(stderr, ":\n Initval offset 0x%04X too big. Offset must be <= 0x%04X\n", *a3, 0x7FFFLL);
exit(1);
}
*(_WORD *)a2 = ((__int64 (*)(void))cpu_to_be16)();
v4 = a3[1];
if ( v4 == 2 )
{
*(_WORD *)(a2 + 2) = cpu_to_be16(*((unsigned __int16 *)a3 + 4));
result = 4LL;
}
else
{
if ( v4 != 4 )
{
fwrite("InitVals ERROR", 1uLL, 0xEuLL, stderr);
fprintf(stderr, " (Section \"%s\")", **a1);
fwrite(":\n Internal error. initval_to_raw invalid size.\n", 1uLL, 0x31uLL, stderr);
exit(1);
}
*(_DWORD *)(a2 + 2) = cpu_to_be32(a3[2]);
*(_WORD *)a2 |= cpu_to_be16(0x8000LL);
result = 6LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char ***a1, __int64 a2, unsigned int *a3)
{
unsigned int v4; // eax
__int64 result; // rax

*(_DWORD *)a2 = 0;
*(_WORD *)(a2 + 4) = 0;
if ( (*a3 & 0xFFFF8000) != 0 )
{
fwrite("InitVals ERROR", 1uLL, 0xEuLL, stderr);
fprintf(stderr, " (Section \"%s\")", **a1);
fprintf(stderr, ":\n Initval offset 0x%04X too big. Offset must be <= 0x%04X\n", *a3, 0x7FFFLL);
exit(1);
}
*(_WORD *)a2 = ((__int64 (*)(void))cpu_to_be16)();
v4 = a3[1];
if ( v4 == 2 )
{
*(_WORD *)(a2 + 2) = cpu_to_be16(*((unsigned __int16 *)a3 + 4));
result = 4LL;
}
else
{
if ( v4 != 4 )
{
fwrite("InitVals ERROR", 1uLL, 0xEuLL, stderr);
fprintf(stderr, " (Section \"%s\")", **a1);
fwrite(":\n Internal error. initval_to_raw invalid size.\n", 1uLL, 0x31uLL, stderr);
exit(1);
}
*(_DWORD *)(a2 + 2) = cpu_to_be32(a3[2]);
*(_WORD *)a2 |= cpu_to_be16(0x8000LL);
result = 6LL;
}
return result;
}

original_code:
static unsigned int initval_to_raw(struct ivals_context *ctx,
       struct initval_raw *raw,
       const struct initval *iv)
{
 unsigned int size;
 memset(raw, 0, sizeof(*raw));
 if (iv->offset & ~0x7FFF) {
  do { do { fprintf(stderr, "InitVals " "ERROR"); fprintf(stderr, " (Section \"%s\")", ctx->sect->name); fprintf(stderr, ":\n  " "Initval offset 0x%04X too big. " "Offset must be <= 0x%04X" "\n" , iv->offset, 0x7FFF); } while (0); exit(1); } while (0);
 }
 raw->offset_size = cpu_to_be16(iv->offset);
 switch (iv->size) {
 case 2:
  raw->data.d16 = cpu_to_be16(iv->value);
  size = sizeof(be16_t) + sizeof(be16_t);
  break;
 case 4:
  raw->data.d32 = cpu_to_be32(iv->value);
  raw->offset_size |= cpu_to_be16(0x8000);
  size = sizeof(be16_t) + sizeof(be32_t);
  break;
 default:
  do { do { fprintf(stderr, "InitVals " "ERROR"); fprintf(stderr, " (Section \"%s\")", ctx->sect->name); fprintf(stderr, ":\n  " "Internal error. initval_to_raw invalid size." "\n"); } while (0); exit(1); } while (0);
  break;
 }
 return size;
}

canonical_original_code:
static unsigned int initval_to_raw(struct ivals_context *ctx, struct initval_raw *raw, struct initval *iv)
{
 unsigned int size;
 memset(raw, 0, sizeof(*raw));
 if (iv->offset & ~0x7FFF) {
  do { do { fprintf(stderr, "InitVals " "ERROR"); fprintf(stderr, " (Section \"%s\")", ctx->sect->name); fprintf(stderr, ":\n  " "Initval offset 0x%04X too big. " "Offset must be <= 0x%04X" "\n" , iv->offset, 0x7FFF); } while (0); exit(1); } while (0);
 }
 raw->offset_size = cpu_to_be16(iv->offset);
 switch (iv->size) {
 case 2:
  raw->data.d16 = cpu_to_be16(iv->value);
  size = sizeof(be16_t) + sizeof(be16_t);
  break;
 case 4:
  raw->data.d32 = cpu_to_be32(iv->value);
  raw->offset_size |= cpu_to_be16(0x8000);
  size = sizeof(be16_t) + sizeof(be32_t);
  break;
 default:
  do { do { fprintf(stderr, "InitVals " "ERROR"); fprintf(stderr, " (Section \"%s\")", ctx->sect->name); fprintf(stderr, ":\n  " "Internal error. initval_to_raw invalid size." "\n"); } while (0); exit(1); } while (0);
  break;
 }
 return size;
}

variable_types: struct initval_raw { unsigned short offset_size; union { unsigned short d16; unsigned int d32; } data; } *

variable_types: struct initval { unsigned int offset; unsigned int size; unsigned int value; struct list_head list; } *


dump

decompiled_code:
int __fastcall dump(__int64 a1, __int64 a2, const char *a3)
{
__int64 v3; // rbx
__int64 v4; // rcx
__int64 v5; // rdx
__int64 v6; // rdx

v3 = 0LL;
fprintf(stderr, "Data dump (%s, %zd bytes):", a3, a2);
if ( a2 )
{
do
{
while ( 1 )
{
v6 = *(unsigned __int8 *)(a1 + v3);
if ( (v3 & 7) != 0 )
break;
v4 = (unsigned __int8)v6;
v5 = v3++;
fprintf(stderr, "\n0x%08zx: 0x%02x, ", v5, v4);
if ( a2 == v3 )
return fputc(10, stderr);
}
++v3;
fprintf(stderr, "0x%02x, ", v6);
}
while ( a2 != v3 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, const char *a3)
{
__int64 v3; // rbx
__int64 v4; // rcx
__int64 v5; // rdx
__int64 v6; // rdx

v3 = 0LL;
fprintf(stderr, "Data dump (%s, %zd bytes):", a3, a2);
if ( a2 )
{
do
{
while ( 1 )
{
v6 = *(unsigned __int8 *)(a1 + v3);
if ( (v3 & 7) != 0 )
break;
v4 = (unsigned __int8)v6;
v5 = v3++;
fprintf(stderr, "\n0x%08zx: 0x%02x, ", v5, v4);
if ( a2 == v3 )
return fputc(10, stderr);
}
++v3;
fprintf(stderr, "0x%02x, ", v6);
}
while ( a2 != v3 );
}
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:
size
unsigned long

variable_types:
description
char *

variable_types:
i
unsigned long

variable_types: c char


xmalloc

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

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

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

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

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:
p
void *

return_type: void *


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:
__int16 __fastcall cpu_to_be16(__int16 a1)
{
return __ROL2__(a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func3(__int16 a1)
{
return __ROL2__(a1, 8);
}

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 *


decompiled_code:
__int64 __fastcall cpu_to_be32(unsigned int a1)
{
return _byteswap_ulong(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return _byteswap_ulong(a1);
}

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


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


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


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:
ret
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()
{
__int64 result; // rax

if ( *outfile_name != 45 || (result = (unsigned __int8)outfile_name[1], outfile_name[1]) )
{
outfile = fopen(outfile_name, "w+");
if ( outfile )
{
result = 0LL;
}
else
{
fprintf(stderr, "Could not open OUTPUT_FILE %s\n", outfile_name);
result = 0xFFFFFFFFLL;
}
}
else
{
outfile = stdout;
}
return result;
}

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

if ( *outfile_name != 45 || (result = (unsigned __int8)outfile_name[1], outfile_name[1]) )
{
outfile = fopen(outfile_name, "w+");
if ( outfile )
{
result = 0LL;
}
else
{
fprintf(stderr, "Could not open OUTPUT_FILE %s\n", outfile_name);
result = 0xFFFFFFFFLL;
}
}
else
{
outfile = stdout;
}
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:
int close_output_file()
{
int result; // eax

result = (int)outfile_name;
if ( *outfile_name != 45 || outfile_name[1] )
result = fclose(outfile);
return result;
}

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

result = (int)outfile_name;
if ( *outfile_name != 45 || outfile_name[1] )
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

variable_types:
data
char *

variable_types:
size
unsigned long

variable_types:
description
char *

variable_types:
i
unsigned long

variable_types: c char


xmalloc

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:
// attributes: thunk
void battery_dummy_destroy(void *ptr)
{
free(ptr);
}

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

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

v0 = zalloc_constprop_0();
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; // r12

v0 = func2();
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:
// attributes: thunk
__int64 default_current_brightness()
{
return default_min_brightness();
}

canonical_decompiled_code:
__int64 func4()
{
return func1();
}

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:
// attributes: thunk
__int64 default_screen_lock()
{
return default_set_brightness();
}

canonical_decompiled_code:
__int64 func6()
{
return func5();
}

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

variable_types: lock int


decompiled_code:
// attributes: thunk
__int64 default_screen_is_locked()
{
return default_min_brightness();
}

canonical_decompiled_code:
__int64 func7()
{
return func1();
}

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; // er12
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; // er12
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; // rbp
int v3; // eax
int v4; // er12
bool v5; // cc
int *v6; // rax
char *v7; // 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 )
{
v6 = _errno_location();
v7 = strerror(*v6);
LODWORD(v1) = logerr("Failed to open framebuffer dev %s: %s\n", v2, v7);
}
else
{
LODWORD(v1) = do_framebuffer_blank(v3, 0);
if ( (_DWORD)v1 )
{
LODWORD(v1) = close(v4);
}
else
{
v5 = cmdargs[1] <= 1;
*(_DWORD *)(a1 + 96) = 0;
*(_DWORD *)(a1 + 92) = v4;
if ( !v5 )
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; // rbp
int v3; // eax
int v4; // er12
bool v5; // cc
int *v6; // rax
char *v7; // 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 )
{
v6 = _errno_location();
v7 = strerror(*v6);
LODWORD(v1) = logerr("Failed to open framebuffer dev %s: %s\n", v2, v7);
}
else
{
LODWORD(v1) = func8(v3, 0);
if ( (_DWORD)v1 )
{
LODWORD(v1) = close(v4);
}
else
{
v5 = cmdargs[1] <= 1;
*(_DWORD *)(a1 + 96) = 0;
*(_DWORD *)(a1 + 92) = v4;
if ( !v5 )
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 func11(__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:
void __fastcall update_screen_blanking(__int64 a1)
{
int v1; // ebx

v1 = (*(__int64 (**)(void))(a1 + 32))();
if ( (*(unsigned int (__fastcall **)(__int64))(a1 + 56))(a1) )
{
block_x11_input((unsigned int)((_DWORD)&backend + 32));
goto LABEL_3;
}
if ( !v1 )
{
LABEL_3:
framebuffer_blank_isra_0(a1, 1);
return;
}
framebuffer_blank_isra_0(a1, 0);
unblock_x11_input((unsigned int)((_DWORD)&backend + 32));
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1)
{
int v1; // ebx

v1 = (*(__int64 (**)(void))(a1 + 32))();
if ( (*(unsigned int (__fastcall **)(__int64))(a1 + 56))(a1) )
{
block_x11_input((unsigned int)((_DWORD)&backend + 32));
goto LABEL_3;
}
if ( !v1 )
{
LABEL_3:
func15(a1, 1);
return;
}
func15(a1, 0);
unblock_x11_input((unsigned int)((_DWORD)&backend + 32));
}

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

v0 = (__int64 (**)(void))&_start_probe_backlight;
if ( &_start_probe_backlight < (_UNKNOWN *)&_stop_probe_backlight )
{
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_7;
}
fbblank_init(v1);
backlight_start((__int64)v2);
if ( (int)cmdargs[1] > 1 )
{
logdebug("Initialized backlight driver \"%s\"\n", *v2);
return v2;
}
}
else
{
LABEL_7:
v2 = 0LL;
logerr("Failed to find any backlight controls.\n");
}
return v2;
}

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

v0 = (__int64 (**)(void))&_start_probe_backlight;
if ( &_start_probe_backlight < (_UNKNOWN *)&_stop_probe_backlight )
{
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_7;
}
func9(v1);
func12((__int64)v2);
if ( (int)cmdargs[1] > 1 )
{
logdebug("Initialized backlight driver \"%s\"\n", *v2);
return v2;
}
}
else
{
LABEL_7:
v2 = 0LL;
logerr("Failed to find any backlight controls.\n");
}
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; // er12

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

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; // er12
__int128 v3; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+10h] [rbp-18h]

v3 = 0LL;
v4 = 0LL;
LOWORD(v3) = _bswap_16_constprop_0(a1, &v3);
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; // er12
__int128 v3; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+10h] [rbp-18h]

v3 = 0LL;
v4 = 0LL;
LOWORD(v3) = func14(a1, &v3);
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; // er12

v2 = backlight_set_percentage_no_notify(a1, a2);
if ( v2 )
return v2;
backlight_notify_state_change(a1);
update_screen_blanking(a1);
return 0LL;
}

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

v2 = func0(a1, a2);
if ( v2 )
return v2;
func24(a1);
func16(a1);
return 0LL;
}

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; // ebx
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; // ebx
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:
// attributes: thunk
__int64 default_min_level()
{
return default_on_ac();
}

canonical_decompiled_code:
__int64 func5()
{
return func2();
}

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:
// attributes: thunk
__int64 default_charge_level()
{
return default_on_ac();
}

canonical_decompiled_code:
__int64 func7()
{
return func2();
}

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:
// attributes: thunk
__int64 default_current_mA()
{
return default_capacity_mAh();
}

canonical_decompiled_code:
__int64 func9()
{
return func8();
}

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


decompiled_code:
// attributes: thunk
__int64 default_temperature_K()
{
return default_capacity_mAh();
}

canonical_decompiled_code:
__int64 func10()
{
return func8();
}

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


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

result = *(unsigned int *)(a1 + 96);
if ( (_DWORD)result )
{
(*(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

result = *(unsigned int *)(a1 + 96);
if ( (_DWORD)result )
{
(*(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; // r12

v0 = (__int64 (**)(void))&_start_probe_battery;
if ( &_start_probe_battery < (_UNKNOWN *)&_stop_probe_battery )
{
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_7;
}
battery_start(v1);
if ( *((int *)&cmdargs + 1) > 1 )
{
logdebug("Initialized battery driver \"%s\"\n", *v2);
return v2;
}
}
else
{
LABEL_7:
v2 = 0LL;
logerr("Failed to find a battery\n");
}
return v2;
}

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

v0 = (__int64 (**)(void))&_start_probe_battery;
if ( &_start_probe_battery < (_UNKNOWN *)&_stop_probe_battery )
{
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_7;
}
func11(v1);
if ( *((int *)&cmdargs + 1) > 1 )
{
logdebug("Initialized battery driver \"%s\"\n", *v2);
return v2;
}
}
else
{
LABEL_7:
v2 = 0LL;
logerr("Failed to find a battery\n");
}
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 a3)
{
__int64 v4; // rdi
unsigned int v5; // er12
__int128 v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8; // [rsp+10h] [rbp-18h]

v7 = 0LL;
v8 = 0LL;
LOWORD(v7) = _bswap_16_constprop_0(a1, a2, a3);
battery_emergency_check(a1);
v4 = backend[6];
if ( v4 )
autodim_handle_battery_event(v4);
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 a3)
{
__int64 v4; // rdi
unsigned int v5; // er12
__int128 v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8; // [rsp+10h] [rbp-18h]

v7 = 0LL;
v8 = 0LL;
LOWORD(v7) = func15(a1, a2, a3);
func14(a1);
v4 = backend[6];
if ( v4 )
autodim_handle_battery_event(v4);
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 || *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 || *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; // r12
char *v3; // rbp
_QWORD *v4; // rbx
void *v5; // rdi

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

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

if ( ptr )
{
v2 = (char *)ptr + 272;
v3 = (char *)ptr + 16;
do
{
v4 = *(_QWORD **)v3;
if ( *(_QWORD *)v3 )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[3];
func2(v5);
}
while ( v4 );
}
v3 += 8;
}
while ( v3 != v2 );
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; // r13
__int64 result; // rax
__int64 v3; // r12
const char *v4; // rcx
__int64 j; // rbp
__int64 v6; // r14
const char *v7; // rcx

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 i; // r13
__int64 result; // rax
__int64 v3; // r12
const char *v4; // rcx
__int64 j; // rbp
__int64 v6; // r14
const char *v7; // rcx

if ( *((int *)&cmdargs + 1) > 2 )
logdebug("Parsed config file:\n");
for ( i = 0LL; i != 32; ++i )
{
result = a1;
v3 = *(_QWORD *)(a1 + 8 * i);
if ( v3 )
{
if ( *((int *)&cmdargs + 1) > 2 )
{
v4 = (const char *)&unk_76C;
LABEL_7:
result = logdebug("\t[%02X] Section '%s'%s\n", (unsigned int)i, *(const char **)(v3 + 8), v4);
}
while ( 1 )
{
for ( j = 0LL; j != 32; ++j )
{
v6 = *(_QWORD *)(v3 + 8 * j + 16);
if ( v6 )
{
result = *((unsigned int *)&cmdargs + 1);
if ( (int)result <= 2 )
goto LABEL_14;
v7 = (const char *)&unk_76C;
LABEL_13:
logdebug("\t\t[%02X] Item '%s'%s\n", (unsigned int)j, *(const char **)(v6 + 8), v7);
result = *((unsigned int *)&cmdargs + 1);
LABEL_14:
while ( 1 )
{
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
break;
v7 = "\t\t<== ### COLLISION ###";
if ( (int)result > 2 )
goto LABEL_13;
}
}
}
v3 = *(_QWORD *)(v3 + 272);
if ( !v3 )
break;
v4 = "\t\t<== ### COLLISION ###";
if ( *((int *)&cmdargs + 1) > 2 )
goto LABEL_7;
}
}
}
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 v7; // rbx

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

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

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

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