memoryToString

decompiled_code:
char *__fastcall memoryToString(__int64 a1)
{
char *v1; // r14
char *v2; // rbx
char *v3; // rax
char *v4; // r15
int v5; // er12
unsigned int v6; // ebp
unsigned __int16 v7; // ax

v1 = (char *)malloc(0xAuLL);
v2 = (char *)malloc(16 * *(_DWORD *)(a1 + 12));
v3 = (char *)malloc(0xAuLL);
if ( *(int *)(a1 + 8) > 0 )
{
v4 = v3;
v5 = 0;
v6 = 0;
do
{
v7 = getMemory((_QWORD *)a1, v6);
sprintf(v1, "0x%04X\n", v7);
sprintf(v4, "0x%04X: ", v6);
strcat(v2, v4);
strcat(v2, v1);
v6 = (unsigned __int16)++v5;
}
while ( (unsigned __int16)v5 < *(int *)(a1 + 8) );
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
char *v1; // r14
char *v2; // rbx
char *v3; // rax
char *v4; // r15
int v5; // er12
unsigned int v6; // ebp
unsigned __int16 v7; // ax

v1 = (char *)malloc(0xAuLL);
v2 = (char *)malloc(16 * *(_DWORD *)(a1 + 12));
v3 = (char *)malloc(0xAuLL);
if ( *(int *)(a1 + 8) > 0 )
{
v4 = v3;
v5 = 0;
v6 = 0;
do
{
v7 = func3((_QWORD *)a1, v6);
sprintf(v1, "0x%04X\n", v7);
sprintf(v4, "0x%04X: ", v6);
strcat(v2, v4);
strcat(v2, v1);
v6 = (unsigned __int16)++v5;
}
while ( (unsigned __int16)v5 < *(int *)(a1 + 8) );
}
return v2;
}

original_code:
char * memoryToString(MemoryPtr memory) {
 char * string = (char *) malloc(10);
 char * result = (char *) malloc(memory->capacity * 16);
 char * reg_string = (char *) malloc(10);
 Register i;
 for (i = 0; i < memory->size; i++) {
  Register reg = getMemory(memory, i);
  sprintf(string, "0x%04X\n", reg);
  sprintf(reg_string, "0x%04X: ", i);
  result = strcat(result, reg_string);
  result = strcat(result, string);
 }
 return result;
}

canonical_original_code:
char *memoryToString(struct Memory *memory) {
 char *string = (char *) malloc(10);
 char *result = (char *) malloc(memory->capacity * 16);
 char *reg_string = (char *) malloc(10);
 unsigned short i;
 for (i = 0; i < memory->size; i++) {
  unsigned short reg = getMemory(memory, i);
  sprintf(string, "0x%04X\n", reg);
  sprintf(reg_string, "0x%04X: ", i);
  result = strcat(result, reg_string);
  result = strcat(result, string);
 }
 return result;
}

variable_types:
string
char *

variable_types:
result
char *

variable_types:
i
unsigned short

variable_types:
reg
unsigned short

return_type: char *


ALUConstructor

repo: tuckerd/LC

variable_types: struct ALU { int mask_array[16]; unsigned short A; unsigned short flags; unsigned char c_out; } *


ALUSetOperands

original_code:
int ALUSetOperands(ALUPtr this, Register A, Register B) {
 this->A = A & 0x0000ffff;
 this->B = B & 0x0000ffff;
}

canonical_original_code:
int ALUSetOperands(struct ALU *this, unsigned short A, unsigned short B) {
 this->A = A & 0x0000ffff;
 this->B = B & 0x0000ffff;
}

variable_types:
A
unsigned short

variable_types:
B
unsigned short

return_type: int

user_defined_types: struct ALU { int mask_array[16]; unsigned short A; unsigned short flags; unsigned char c_out; }


ALUsetFlags

variable_types:
flags
unsigned short


rippleCarryAdderAdd

original_code:
int rippleCarryAdderAdd(ALUPtr this) {
 bit c_out;
 bit c_in = 0x0;
 bit a;
 bit b;
 bit r;
 Register R = 0x0000;
 int i;
 for (i = 0; i < 16; i++) {
  a = ((this->A & this->mask_array[i])?1:0);
  b = ((this->B & this->mask_array[i])?1:0);
  r = fullAdder(a, b, c_in, &c_out);
  c_in = c_out;
  R |= (r << i);
 }
 this->c_out = c_out;
 this->R = R;
 ALUsetFlags(this);
}

canonical_original_code:
int rippleCarryAdderAdd(struct ALU *this) {
 unsigned char c_out;
 unsigned char c_in = 0x0;
 unsigned char a;
 unsigned char b;
 unsigned char r;
 unsigned short R = 0x0000;
 int i;
 for (i = 0; i < 16; i++) {
  a = ((this->A & this->mask_array[i])?1:0);
  b = ((this->B & this->mask_array[i])?1:0);
  r = fullAdder(a, b, c_in, &c_out);
  c_in = c_out;
  R |= (r << i);
 }
 this->c_out = c_out;
 this->R = R;
 ALUsetFlags(this);
}

variable_types:
a
unsigned char

variable_types:
b
unsigned char

variable_types:
r
unsigned char

variable_types:
R
unsigned short

variable_types: i int


ALUNegation

original_code:
int ALUNegation(ALUPtr this) {
 ALUNot(this);
 Register b = this->B;
 this->c_out = 0;
 b += 0x01;
 this->B = b;
 this->R = b;
 ALUsetFlags(this);
 this->flags &= 0x0E00;
}

canonical_original_code:
int ALUNegation(struct ALU *this) {
 ALUNot(this);
 unsigned short b = this->B;
 this->c_out = 0;
 b += 0x01;
 this->B = b;
 this->R = b;
 ALUsetFlags(this);
 this->flags &= 0x0E00;
}

variable_types:
b
unsigned short


ALUSubtract

decompiled_code:
__int16 __fastcall ALUSubtract(__int64 a1)
{
ALUNegation(a1);
return rippleCarryAdderAdd(a1);
}

canonical_decompiled_code:
__int16 __fastcall func6(__int64 a1)
{
func5(a1);
return func3(a1);
}

original_code:
int ALUSubtract(ALUPtr this) {
 ALUNegation(this);
 return rippleCarryAdderAdd(this);
}

canonical_original_code:
int ALUSubtract(struct ALU *this) {
 ALUNegation(this);
 return rippleCarryAdderAdd(this);
}


ALUGetResult

decompiled_code:
__int64 __fastcall ALUGetResult(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 68);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 68);
}

original_code:
unsigned short ALUGetResult(ALUPtr this) {
 return this->R;
}

canonical_original_code:
unsigned short ALUGetResult(struct ALU *this) {
 return this->R;
}

return_type: unsigned short


ALUGetFlags

decompiled_code:
__int64 __fastcall ALUGetFlags(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 70);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 70);
}

original_code:
Register ALUGetFlags(ALUPtr this) {
 return this->flags;
}

canonical_original_code:
unsigned short ALUGetFlags(struct ALU *this) {
 return this->flags;
}


ControllerDestructor

decompiled_code:
void __fastcall ControllerDestructor(void *ptr)
{
free(*((void **)ptr + 1));
free(*(void **)ptr);
free(ptr);
}

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

original_code:
void ControllerDestructor(ControllerPtr this) {
 free(this->registers);
 free(this->alu);
 free(this);
}

canonical_original_code:
void ControllerDestructor(struct Controller *this) {
 free(this->registers);
 free(this->alu);
 free(this);
}

variable_types: struct Controller { struct ALU { int mask_array[16]; unsigned short A; unsigned short flags; unsigned char c_out; } *alu; struct Registers { unsigned short registers[8]; } *registers; struct Memory { unsigned short *memory; int size; int capacity; } *memory; unsigned short *PC; unsigned short codes; } *

return_type: void

user_defined_types: struct Controller { struct ALU *alu; struct Registers *registers; struct Memory *memory; unsigned short *PC; unsigned short codes; }


getRegisters

decompiled_code:
__int64 __fastcall getRegisters(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
RegistersPtr getRegisters(ControllerPtr controller) {
 return controller->registers;
}

canonical_original_code:
struct Registers *getRegisters(struct Controller *controller) {
 return controller->registers;
}

variable_types: struct Controller { struct ALU { int mask_array[16]; unsigned short A; unsigned short flags; unsigned char c_out; } *alu; struct Registers *registers; struct Memory { unsigned short *memory; int size; int capacity; } *memory; unsigned short *PC; unsigned short codes; } *

return_type: struct Registers { unsigned short registers[8]; } *


parseDest

decompiled_code:
__int64 __fastcall parseDest(__int16 a1)
{
return (a1 & 0xE00) >> 9;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1)
{
return (a1 & 0xE00) >> 9;
}

original_code:
int parseDest(Register ir) {
 int dest = ir & 0x0E00;
 dest = dest >> 9;
 return dest;
}

canonical_original_code:
int parseDest(unsigned short ir) {
 int dest = ir & 0x0E00;
 dest = dest >> 9;
 return dest;
}

variable_types:
ir
unsigned short

variable_types: dest int


decompiled_code:
__int64 __fastcall parseSrc1(__int16 a1)
{
return (a1 & 0x1C0) >> 6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1)
{
return (a1 & 0x1C0) >> 6;
}

original_code:
int parseSrc1(Register ir) {
 int src1 = ir & 0x01C0;
 src1 = src1 >> 6;
 return src1;
}

canonical_original_code:
int parseSrc1(unsigned short ir) {
 int src1 = ir & 0x01C0;
 src1 = src1 >> 6;
 return src1;
}


decompiled_code:
__int64 __fastcall parseSrc2(char a1)
{
return a1 & 3;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
return a1 & 3;
}

original_code:
int parseSrc2(Register ir) {
 int src2 = ir & 0x0003;
 return src2;
}

canonical_original_code:
int parseSrc2(unsigned short ir) {
 int src2 = ir & 0x0003;
 return src2;
}


parseImm

decompiled_code:
__int64 __fastcall parseImm(char a1)
{
return a1 & 0x1F;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
return a1 & 0x1F;
}

original_code:
Register parseImm(Register ir) {
 return ir & 0x001F;
}

canonical_original_code:
unsigned short parseImm(unsigned short ir) {
 return ir & 0x001F;
}


decompiled_code:
__int64 __fastcall sext6(unsigned int a1)
{
__int64 result; // rax

result = (unsigned __int8)a1 | 0xFFFFFFC0;
if ( (a1 & 0x20) == 0 )
result = a1;
return result;
}

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

result = (unsigned __int8)a1 | 0xFFFFFFC0;
if ( (a1 & 0x20) == 0 )
result = a1;
return result;
}

original_code:
Register sext6(Register offset) {
 if ((offset & 0x0020)?1:0 == 1) {
  offset |= 0xFFC0;
 }
 return offset;
}

canonical_original_code:
unsigned short sext6(unsigned short offset) {
 if ((offset & 0x0020)?1:0 == 1) {
  offset |= 0xFFC0;
 }
 return offset;
}

variable_types:
offset
unsigned short


strHelper

decompiled_code:
__int64 __fastcall strHelper(__int64 a1, __int16 a2)
{
__int64 v2; // r13
_WORD *v3; // r14
int v4; // ebp
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
v3 = (_WORD *)(v2 + 2LL * (int)parseDest(a2));
v4 = parseSrc1(a2);
result = (unsigned __int16)sext6(a2 & 0x3F) + *(unsigned __int16 *)(v2 + 2LL * v4);
*(_WORD *)(**(_QWORD **)(a1 + 16) + 2 * result) = *v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int16 a2)
{
__int64 v2; // r13
_WORD *v3; // r14
int v4; // ebp
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
v3 = (_WORD *)(v2 + 2LL * (int)func2(a2));
v4 = func3(a2);
result = (unsigned __int16)func8(a2 & 0x3F) + *(unsigned __int16 *)(v2 + 2LL * v4);
*(_WORD *)(**(_QWORD **)(a1 + 16) + 2 * result) = *v3;
return result;
}

original_code:
void strHelper(ControllerPtr controller, Register ir) {
 Register * registers = controller->registers->registers;
 Register * memory = controller->memory->memory;
 memory[registers[parseSrc1(ir)] + sext6(ir & 0x003F)] =
     registers[parseDest(ir)];
}

canonical_original_code:
void strHelper(struct Controller *controller, unsigned short ir) {
 unsigned short *registers = controller->registers->registers;
 unsigned short *memory = controller->memory->memory;
 memory[registers[parseSrc1(ir)] + sext6(ir & 0x003F)] =
     registers[parseDest(ir)];
}

variable_types:
registers
unsigned short *

variable_types:
memory
unsigned short *

user_defined_types: struct Registers { unsigned short registers[8]; }

user_defined_types: struct Memory { unsigned short *memory; int size; int capacity; }


decompiled_code:
__int64 __fastcall sext7(unsigned int a1)
{
__int64 result; // rax

result = (unsigned __int8)a1 | 0xFFFFFFC0;
if ( (a1 & 0x40) == 0 )
result = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
__int64 result; // rax

result = (unsigned __int8)a1 | 0xFFFFFFC0;
if ( (a1 & 0x40) == 0 )
result = a1;
return result;
}

original_code:
Register sext7(Register offset) {
 if ((offset & 0x0040)?1:0 == 1) {
  offset |= 0xFFC0;
 }
 return offset;
}

canonical_original_code:
unsigned short sext7(unsigned short offset) {
 if ((offset & 0x0040)?1:0 == 1) {
  offset |= 0xFFC0;
 }
 return offset;
}


decompiled_code:
__int16 __fastcall sext9(__int16 a1)
{
__int16 result; // ax

result = a1 | 0xFE00;
if ( (a1 & 0x100) == 0 )
result = a1;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func12(__int16 a1)
{
__int16 result; // ax

result = a1 | 0xFE00;
if ( (a1 & 0x100) == 0 )
result = a1;
return result;
}

original_code:
Register sext9(Register offset) {
 if ((offset & 0x0100)?1:0 == 1) {
  offset |= 0xFE00;
 }
 return offset;
}

canonical_original_code:
unsigned short sext9(unsigned short offset) {
 if ((offset & 0x0100)?1:0 == 1) {
  offset |= 0xFE00;
 }
 return offset;
}


stHelper

decompiled_code:
__int64 __fastcall stHelper(__int64 a1, __int16 a2)
{
_WORD *v2; // r12
__int64 result; // rax

v2 = (_WORD *)(*(_QWORD *)(a1 + 8) + 2LL * (int)parseDest(a2));
result = (unsigned __int16)sext9(a2 & 0x1FF) + **(unsigned __int16 **)(a1 + 24);
*(_WORD *)(**(_QWORD **)(a1 + 16) + 2 * result) = *v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int16 a2)
{
_WORD *v2; // r12
__int64 result; // rax

v2 = (_WORD *)(*(_QWORD *)(a1 + 8) + 2LL * (int)func2(a2));
result = (unsigned __int16)func12(a2 & 0x1FF) + **(unsigned __int16 **)(a1 + 24);
*(_WORD *)(**(_QWORD **)(a1 + 16) + 2 * result) = *v2;
return result;
}

original_code:
void stHelper(ControllerPtr controller, Register ir) {
 Register * registers = controller->registers->registers;
 Register * memory = controller->memory->memory;
 memory[*(controller->PC) + sext9(ir & 0x01FF)] =
       registers[parseDest(ir)];
}

canonical_original_code:
void stHelper(struct Controller *controller, unsigned short ir) {
 unsigned short *registers = controller->registers->registers;
 unsigned short *memory = controller->memory->memory;
 memory[*(controller->PC) + sext9(ir & 0x01FF)] =
       registers[parseDest(ir)];
}


stiHelper

decompiled_code:
__int64 __fastcall stiHelper(__int64 a1, __int16 a2)
{
__int64 v2; // rbp
_WORD *v3; // r13
__int64 result; // rax

v2 = **(_QWORD **)(a1 + 16);
v3 = (_WORD *)(*(_QWORD *)(a1 + 8) + 2LL * (int)parseDest(a2));
result = *(unsigned __int16 *)(v2 + 2LL * ((unsigned __int16)sext9(a2 & 0x1FF) + **(unsigned __int16 **)(a1 + 24)));
*(_WORD *)(v2 + 2 * result) = *v3;
return result;
}

original_code:
void stiHelper(ControllerPtr controller, Register ir) {
 Register * registers = controller->registers->registers;
 Register * memory = controller->memory->memory;
 memory[memory[*(controller->PC) + sext9(ir & 0x01FF)]] =
     registers[parseDest(ir)];
}

canonical_original_code:
void stiHelper(struct Controller *controller, unsigned short ir) {
 unsigned short *registers = controller->registers->registers;
 unsigned short *memory = controller->memory->memory;
 memory[memory[*(controller->PC) + sext9(ir & 0x01FF)]] =
     registers[parseDest(ir)];
}


decompiled_code:
__int16 __fastcall sext11(__int16 a1)
{
__int16 result; // ax

result = a1 | 0xF800;
if ( (a1 & 0x400) == 0 )
result = a1;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func15(__int16 a1)
{
__int16 result; // ax

result = a1 | 0xF800;
if ( (a1 & 0x400) == 0 )
result = a1;
return result;
}

original_code:
Register sext11(Register offset) {
 if ((offset & 0x0400)?1:0 == 1) {
  offset |= 0xF800;
 }
 return offset;
}

canonical_original_code:
unsigned short sext11(unsigned short offset) {
 if ((offset & 0x0400)?1:0 == 1) {
  offset |= 0xF800;
 }
 return offset;
}


parseOpcode

decompiled_code:
__int16 __fastcall parseOpcode(__int16 a1)
{
return a1 & 0xF000;
}

canonical_decompiled_code:
__int16 __fastcall func16(__int16 a1)
{
return a1 & 0xF000;
}

original_code:
Register parseOpcode(Register ir) {
 return ir & 0xF000;
}

canonical_original_code:
unsigned short parseOpcode(unsigned short ir) {
 return ir & 0xF000;
}


setCC

decompiled_code:
void __fastcall setCC(__int64 a1, __int16 a2)
{
*(_WORD *)(a1 + 32) = a2;
}

original_code:
void setCC(ControllerPtr controller, Register codes) {
 controller->codes = codes;
}

canonical_original_code:
void setCC(struct Controller *controller, unsigned short codes) {
 controller->codes = codes;
}

variable_types:
codes
unsigned short


addHelper

decompiled_code:
void __fastcall addHelper(_QWORD *a1, __int16 a2)
{
int v2; // er12
int v3; // er13
__int64 v4; // r14
unsigned __int16 v5; // ax
__int16 v6; // ax
int v7; // eax

v2 = parseDest(a2);
v3 = parseSrc1(a2);
v4 = a1[1];
if ( (a2 & 0x20) != 0 )
{
v5 = parseImm(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), v5);
}
else
{
v7 = parseSrc2(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), *(unsigned __int16 *)(v4 + 2LL * v7));
}
rippleCarryAdderAdd(*a1);
*(_WORD *)(v4 + 2LL * v2) = ALUGetResult(*a1);
v6 = ALUGetFlags(*a1);
setCC((__int64)a1, v6);
}

canonical_decompiled_code:
void __fastcall func18(_QWORD *a1, __int16 a2)
{
int v2; // er12
int v3; // er13
__int64 v4; // r14
unsigned __int16 v5; // ax
__int16 v6; // ax
int v7; // eax

v2 = func2(a2);
v3 = func3(a2);
v4 = a1[1];
if ( (a2 & 0x20) != 0 )
{
v5 = func7(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), v5);
}
else
{
v7 = func6(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), *(unsigned __int16 *)(v4 + 2LL * v7));
}
rippleCarryAdderAdd(*a1);
*(_WORD *)(v4 + 2LL * v2) = ALUGetResult(*a1);
v6 = ALUGetFlags(*a1);
func17((__int64)a1, v6);
}

original_code:
void addHelper(ControllerPtr controller, Register ir) {
 int dest = parseDest(ir);
 int src1 = parseSrc1(ir);
 Register * registers = controller->registers->registers;
 if ((ir & 0x0020)?1:0 == 1) {
  int imm = parseImm(ir);
  ALUSetOperands(controller->alu, registers[src1], imm);
 } else {
  int src2 = parseSrc2(ir);
  ALUSetOperands(controller->alu, registers[src1], registers[src2]);
 }
 rippleCarryAdderAdd(controller->alu);
 registers[dest] = ALUGetResult(controller->alu);
 setCC(controller, ALUGetFlags(controller->alu));
}

canonical_original_code:
void addHelper(struct Controller *controller, unsigned short ir) {
 int dest = parseDest(ir);
 int src1 = parseSrc1(ir);
 unsigned short *registers = controller->registers->registers;
 if ((ir & 0x0020)?1:0 == 1) {
  int imm = parseImm(ir);
  ALUSetOperands(controller->alu, registers[src1], imm);
 } else {
  int src2 = parseSrc2(ir);
  ALUSetOperands(controller->alu, registers[src1], registers[src2]);
 }
 rippleCarryAdderAdd(controller->alu);
 registers[dest] = ALUGetResult(controller->alu);
 setCC(controller, ALUGetFlags(controller->alu));
}

variable_types: imm int


andHelper

decompiled_code:
void __fastcall andHelper(_QWORD *a1, __int16 a2)
{
int v2; // er12
int v3; // er13
__int64 v4; // r14
unsigned __int16 v5; // ax
__int16 v6; // ax
int v7; // eax

v2 = parseDest(a2);
v3 = parseSrc1(a2);
v4 = a1[1];
if ( (a2 & 0x20) != 0 )
{
v5 = parseImm(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), v5);
}
else
{
v7 = parseSrc2(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), *(unsigned __int16 *)(v4 + 2LL * v7));
}
ALUAnd(*a1);
*(_WORD *)(v4 + 2LL * v2) = ALUGetResult(*a1);
v6 = ALUGetFlags(*a1);
setCC((__int64)a1, v6);
}

canonical_decompiled_code:
void __fastcall func19(_QWORD *a1, __int16 a2)
{
int v2; // er12
int v3; // er13
__int64 v4; // r14
unsigned __int16 v5; // ax
__int16 v6; // ax
int v7; // eax

v2 = func2(a2);
v3 = func3(a2);
v4 = a1[1];
if ( (a2 & 0x20) != 0 )
{
v5 = func7(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), v5);
}
else
{
v7 = func6(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), *(unsigned __int16 *)(v4 + 2LL * v7));
}
ALUAnd(*a1);
*(_WORD *)(v4 + 2LL * v2) = ALUGetResult(*a1);
v6 = ALUGetFlags(*a1);
func17((__int64)a1, v6);
}

original_code:
void andHelper(ControllerPtr controller, Register ir) {
 int dest = parseDest(ir);
 int src1 = parseSrc1(ir);
 Register * registers = controller->registers->registers;
 if ((ir & 0x0020)?1:0 == 1) {
  Register imm = parseImm(ir);
  ALUSetOperands(controller->alu, registers[src1], imm);
 } else {
  int src2 = parseSrc2(ir);
  ALUSetOperands(controller->alu, registers[src1], registers[src2]);
 }
 ALUAnd(controller->alu);
 registers[dest] = ALUGetResult(controller->alu);
 setCC(controller, ALUGetFlags(controller->alu));
}

canonical_original_code:
void andHelper(struct Controller *controller, unsigned short ir) {
 int dest = parseDest(ir);
 int src1 = parseSrc1(ir);
 unsigned short *registers = controller->registers->registers;
 if ((ir & 0x0020)?1:0 == 1) {
  unsigned short imm = parseImm(ir);
  ALUSetOperands(controller->alu, registers[src1], imm);
 } else {
  int src2 = parseSrc2(ir);
  ALUSetOperands(controller->alu, registers[src1], registers[src2]);
 }
 ALUAnd(controller->alu);
 registers[dest] = ALUGetResult(controller->alu);
 setCC(controller, ALUGetFlags(controller->alu));
}

variable_types:
imm
unsigned short


notHelper

decompiled_code:
void __fastcall notHelper(_QWORD *a1, __int16 a2)
{
int v2; // eax
__int64 v3; // rbp
__int64 v4; // r13
_WORD *v5; // r12
__int16 v6; // ax

v2 = parseSrc1(a2);
v3 = *a1;
v4 = a1[1];
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v2), *(unsigned __int16 *)(v4 + 2LL * v2));
ALUNot(v3);
v5 = (_WORD *)(v4 + 2LL * (int)parseDest(a2));
*v5 = ALUGetResult(v3);
v6 = ALUGetFlags(v3);
setCC((__int64)a1, v6);
}

canonical_decompiled_code:
void __fastcall func20(_QWORD *a1, __int16 a2)
{
int v2; // eax
__int64 v3; // rbp
__int64 v4; // r13
_WORD *v5; // r12
__int16 v6; // ax

v2 = func3(a2);
v3 = *a1;
v4 = a1[1];
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v2), *(unsigned __int16 *)(v4 + 2LL * v2));
ALUNot(v3);
v5 = (_WORD *)(v4 + 2LL * (int)func2(a2));
*v5 = ALUGetResult(v3);
v6 = ALUGetFlags(v3);
func17((__int64)a1, v6);
}

original_code:
void notHelper(ControllerPtr controller, Register ir) {
 int src = parseSrc1(ir);
 ALUPtr alu = controller->alu;
 Register * registers = controller->registers->registers;
 ALUSetOperands(alu, registers[src], registers[src]);
 ALUNot(alu);
 registers[parseDest(ir)] = ALUGetResult(alu);
 setCC(controller, ALUGetFlags(alu));
}

canonical_original_code:
void notHelper(struct Controller *controller, unsigned short ir) {
 int src = parseSrc1(ir);
 struct ALU *alu = controller->alu;
 unsigned short *registers = controller->registers->registers;
 ALUSetOperands(alu, registers[src], registers[src]);
 ALUNot(alu);
 registers[parseDest(ir)] = ALUGetResult(alu);
 setCC(controller, ALUGetFlags(alu));
}

variable_types: src int

variable_types: struct ALU { int mask_array[16]; unsigned short A; unsigned short flags; unsigned char c_out; } *


subHelper

decompiled_code:
void __fastcall subHelper(_QWORD *a1, __int16 a2)
{
int v2; // er12
int v3; // er13
__int64 v4; // r14
unsigned __int16 v5; // ax
__int16 v6; // ax
int v7; // eax

v2 = parseDest(a2);
v3 = parseSrc1(a2);
v4 = a1[1];
if ( (a2 & 0x20) != 0 )
{
v5 = parseImm(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), v5);
}
else
{
v7 = parseSrc2(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), *(unsigned __int16 *)(v4 + 2LL * v7));
}
ALUSubtract(*a1);
*(_WORD *)(v4 + 2LL * v2) = ALUGetResult(*a1);
v6 = ALUGetFlags(*a1);
setCC((__int64)a1, v6);
}

canonical_decompiled_code:
void __fastcall func21(_QWORD *a1, __int16 a2)
{
int v2; // er12
int v3; // er13
__int64 v4; // r14
unsigned __int16 v5; // ax
__int16 v6; // ax
int v7; // eax

v2 = func2(a2);
v3 = func3(a2);
v4 = a1[1];
if ( (a2 & 0x20) != 0 )
{
v5 = func7(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), v5);
}
else
{
v7 = func6(a2);
ALUSetOperands(*a1, *(unsigned __int16 *)(v4 + 2LL * v3), *(unsigned __int16 *)(v4 + 2LL * v7));
}
ALUSubtract(*a1);
*(_WORD *)(v4 + 2LL * v2) = ALUGetResult(*a1);
v6 = ALUGetFlags(*a1);
func17((__int64)a1, v6);
}

original_code:
void subHelper(ControllerPtr controller, Register ir) {
 int dest = parseDest(ir);
 int src1 = parseSrc1(ir);
 Register * registers = controller->registers->registers;
 if ((ir & 0x0020)?1:0 == 1) {
  int imm = parseImm(ir);
  ALUSetOperands(controller->alu, registers[src1], imm);
 } else {
  int src2 = parseSrc2(ir);
  ALUSetOperands(controller->alu, registers[src1], registers[src2]);
 }
 ALUSubtract(controller->alu);
 registers[dest] = ALUGetResult(controller->alu);
 setCC(controller, ALUGetFlags(controller->alu));
}

canonical_original_code:
void subHelper(struct Controller *controller, unsigned short ir) {
 int dest = parseDest(ir);
 int src1 = parseSrc1(ir);
 unsigned short *registers = controller->registers->registers;
 if ((ir & 0x0020)?1:0 == 1) {
  int imm = parseImm(ir);
  ALUSetOperands(controller->alu, registers[src1], imm);
 } else {
  int src2 = parseSrc2(ir);
  ALUSetOperands(controller->alu, registers[src1], registers[src2]);
 }
 ALUSubtract(controller->alu);
 registers[dest] = ALUGetResult(controller->alu);
 setCC(controller, ALUGetFlags(controller->alu));
}


checkCC

original_code:
void checkCC(ControllerPtr controller, Register value) {
 Register codes = 0x0000;
 if (((value & 0x0000ffff)?1:0) == 0) {
  codes |= 0x0400;
 } else if (((value& 0x00008000)?1:0) == 1) {
  codes |= 0x0800;
 } else {
  codes |= 0x0200;
 }
 setCC(controller, codes);
}

canonical_original_code:
void checkCC(struct Controller *controller, unsigned short value) {
 unsigned short codes = 0x0000;
 if (((value & 0x0000ffff)?1:0) == 0) {
  codes |= 0x0400;
 } else if (((value& 0x00008000)?1:0) == 1) {
  codes |= 0x0800;
 } else {
  codes |= 0x0200;
 }
 setCC(controller, codes);
}

variable_types:
value
unsigned short


ldHelper

decompiled_code:
__int64 __fastcall ldHelper(__int64 a1, __int16 a2)
{
__int64 v2; // rbp
unsigned __int16 v3; // r13
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
v3 = *(_WORD *)(**(_QWORD **)(a1 + 16) + 2LL
* ((unsigned __int16)sext9(a2 & 0x1FF) + **(unsigned __int16 **)(a1 + 24)));
checkCC(a1, v3);
result = (int)parseDest(a2);
*(_WORD *)(v2 + 2LL * (int)result) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, __int16 a2)
{
__int64 v2; // rbp
unsigned __int16 v3; // r13
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
v3 = *(_WORD *)(**(_QWORD **)(a1 + 16) + 2LL
* ((unsigned __int16)func12(a2 & 0x1FF) + **(unsigned __int16 **)(a1 + 24)));
func22(a1, v3);
result = (int)func2(a2);
*(_WORD *)(v2 + 2LL * (int)result) = v3;
return result;
}

original_code:
void ldHelper(ControllerPtr controller, Register ir) {
 Register * registers = controller->registers->registers;
 Register * memory = controller->memory->memory;
 Register value = memory[*(controller->PC) + sext9(ir & 0x01FF)];
 checkCC(controller, value);
 int destination = parseDest(ir);
 registers[destination] = value;
}

canonical_original_code:
void ldHelper(struct Controller *controller, unsigned short ir) {
 unsigned short *registers = controller->registers->registers;
 unsigned short *memory = controller->memory->memory;
 unsigned short value = memory[*(controller->PC) + sext9(ir & 0x01FF)];
 checkCC(controller, value);
 int destination = parseDest(ir);
 registers[destination] = value;
}

variable_types: destination int


ldiHelper

decompiled_code:
__int64 __fastcall ldiHelper(__int64 a1, __int16 a2)
{
__int64 v2; // r12
__int64 v3; // r13
__int64 result; // rax

v2 = **(_QWORD **)(a1 + 16);
v3 = *(_QWORD *)(a1 + 8);
LOWORD(v2) = *(_WORD *)(v2
+ 2LL
* *(unsigned __int16 *)(v2
+ 2LL * ((unsigned __int16)sext9(a2) + **(unsigned __int16 **)(a1 + 24))));
checkCC(a1, v2);
result = (int)parseDest(a2);
*(_WORD *)(v3 + 2LL * (int)result) = v2;
return result;
}

original_code:
void ldiHelper(ControllerPtr controller, Register ir) {
 Register * memory = controller->memory->memory;
 Register * registers = controller->registers->registers;
 Register value = memory[memory[*(controller->PC) + sext9(ir)]];
 checkCC(controller, value);
 registers[parseDest(ir)] = value;
}

canonical_original_code:
void ldiHelper(struct Controller *controller, unsigned short ir) {
 unsigned short *memory = controller->memory->memory;
 unsigned short *registers = controller->registers->registers;
 unsigned short value = memory[memory[*(controller->PC) + sext9(ir)]];
 checkCC(controller, value);
 registers[parseDest(ir)] = value;
}


ldrHelper

decompiled_code:
__int64 __fastcall ldrHelper(__int64 a1, __int16 a2)
{
__int64 v2; // r12
int v3; // er14
unsigned __int16 v4; // bx
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
v3 = parseSrc1(a2);
v4 = *(_WORD *)(**(_QWORD **)(a1 + 16)
+ 2LL * ((unsigned __int16)sext6(a2 & 0x3F) + *(unsigned __int16 *)(v2 + 2LL * v3)));
checkCC(a1, v4);
result = (int)parseDest(a2);
*(_WORD *)(v2 + 2LL * (int)result) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1, __int16 a2)
{
__int64 v2; // r12
int v3; // er14
unsigned __int16 v4; // bx
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
v3 = func3(a2);
v4 = *(_WORD *)(**(_QWORD **)(a1 + 16)
+ 2LL * ((unsigned __int16)func8(a2 & 0x3F) + *(unsigned __int16 *)(v2 + 2LL * v3)));
func22(a1, v4);
result = (int)func2(a2);
*(_WORD *)(v2 + 2LL * (int)result) = v4;
return result;
}

original_code:
void ldrHelper(ControllerPtr controller, Register ir) {
 Register * registers = controller->registers->registers;
 Register * memory = controller->memory->memory;
 Register value = memory[registers[parseSrc1(ir)] + sext6(ir & 0x003F)];
 checkCC(controller, value);
 registers[parseDest(ir)] = value;
}

canonical_original_code:
void ldrHelper(struct Controller *controller, unsigned short ir) {
 unsigned short *registers = controller->registers->registers;
 unsigned short *memory = controller->memory->memory;
 unsigned short value = memory[registers[parseSrc1(ir)] + sext6(ir & 0x003F)];
 checkCC(controller, value);
 registers[parseDest(ir)] = value;
}


leaHelper

decompiled_code:
__int64 __fastcall leaHelper(__int64 a1, __int16 a2)
{
__int64 v2; // r13
unsigned __int16 v3; // r12
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
v3 = **(_WORD **)(a1 + 24) + sext9(a2 & 0x1FF);
checkCC(a1, v3);
result = (int)parseDest(a2);
*(_WORD *)(v2 + 2LL * (int)result) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1, __int16 a2)
{
__int64 v2; // r13
unsigned __int16 v3; // r12
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
v3 = **(_WORD **)(a1 + 24) + func12(a2 & 0x1FF);
func22(a1, v3);
result = (int)func2(a2);
*(_WORD *)(v2 + 2LL * (int)result) = v3;
return result;
}

original_code:
void leaHelper(ControllerPtr controller, Register ir) {
 Register * registers = controller->registers->registers;
 Register value = *(controller->PC) + sext9(ir & 0x01FF);
 checkCC(controller, value);
 registers[parseDest(ir)] = value;
}

canonical_original_code:
void leaHelper(struct Controller *controller, unsigned short ir) {
 unsigned short *registers = controller->registers->registers;
 unsigned short value = *(controller->PC) + sext9(ir & 0x01FF);
 checkCC(controller, value);
 registers[parseDest(ir)] = value;
}


execute

decompiled_code:
void __fastcall execute(_QWORD *a1, __int16 a2)
{
__int16 v2; // ax

v2 = parseOpcode(a2);
if ( v2 == 28672 )
{
strHelper((__int64)a1, a2);
}
else if ( (unsigned __int16)v2 > 0x7000u )
{
if ( v2 == -16384 )
{
jmpHelper((__int64)a1, a2);
}
else if ( (unsigned __int16)v2 <= 0xC000u )
{
switch ( v2 )
{
case -24576:
ldiHelper((__int64)a1, a2);
break;
case -20480:
stiHelper((__int64)a1, a2);
break;
case -28672:
notHelper(a1, a2);
break;
}
}
else if ( v2 == -12288 )
{
subHelper(a1, a2);
}
else if ( v2 == -8192 )
{
leaHelper((__int64)a1, a2);
}
}
else if ( v2 == 12288 )
{
stHelper((__int64)a1, a2);
}
else if ( (unsigned __int16)v2 <= 0x3000u )
{
switch ( v2 )
{
case 0x1000:
addHelper(a1, a2);
break;
case 0x2000:
ldHelper((__int64)a1, a2);
break;
case 0:
brHelper((__int64)a1, a2);
break;
}
}
else
{
switch ( v2 )
{
case 20480:
andHelper(a1, a2);
break;
case 24576:
ldrHelper((__int64)a1, a2);
break;
case 16384:
jsrHelper((__int64)a1, a2);
break;
}
}
}

original_code:
void execute(ControllerPtr controller, Register ir) {
 Register opcode = parseOpcode(ir);
 switch (opcode) {
  case 0x1000:
   addHelper(controller, ir);
   break;
  case 0x5000:
   andHelper(controller, ir);
   break;
  case 0x0000:
   brHelper(controller, ir);
   break;
  case 0xC000:
   jmpHelper(controller, ir);
   break;
  case 0x4000:
   jsrHelper(controller, ir);
   break;
  case 0x2000:
   ldHelper(controller, ir);
   break;
  case 0xA000:
   ldiHelper(controller, ir);
   break;
  case 0x6000:
   ldrHelper(controller, ir);
   break;
  case 0xE000:
   leaHelper(controller, ir);
   break;
  case 0x9000:
   notHelper(controller, ir);
   break;
  case 0x3000:
   stHelper(controller, ir);
   break;
  case 0xB000:
   stiHelper(controller, ir);
   break;
  case 0x7000:
   strHelper(controller, ir);
   break;
  case 0xD000:
   subHelper(controller, ir);
   break;
  default:
   break;
 }
}

canonical_original_code:
void execute(struct Controller *controller, unsigned short ir) {
 unsigned short opcode = parseOpcode(ir);
 switch (opcode) {
  case 0x1000:
   addHelper(controller, ir);
   break;
  case 0x5000:
   andHelper(controller, ir);
   break;
  case 0x0000:
   brHelper(controller, ir);
   break;
  case 0xC000:
   jmpHelper(controller, ir);
   break;
  case 0x4000:
   jsrHelper(controller, ir);
   break;
  case 0x2000:
   ldHelper(controller, ir);
   break;
  case 0xA000:
   ldiHelper(controller, ir);
   break;
  case 0x6000:
   ldrHelper(controller, ir);
   break;
  case 0xE000:
   leaHelper(controller, ir);
   break;
  case 0x9000:
   notHelper(controller, ir);
   break;
  case 0x3000:
   stHelper(controller, ir);
   break;
  case 0xB000:
   stiHelper(controller, ir);
   break;
  case 0x7000:
   strHelper(controller, ir);
   break;
  case 0xD000:
   subHelper(controller, ir);
   break;
  default:
   break;
 }
}

variable_types:
opcode
unsigned short


getCC

decompiled_code:
__int64 __fastcall getCC(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func28(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 32);
}

original_code:
Register getCC(ControllerPtr controller) {
 return controller->codes;
}

canonical_original_code:
unsigned short getCC(struct Controller *controller) {
 return controller->codes;
}


debugerConstructor

decompiled_code:
_DWORD *debugerConstructor()
{
_DWORD *result; // rax

result = malloc(0x3E8uLL);
*result = 0;
result[1] = 0;
result[2] = 0;
result[3] = 0;
result[4] = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = malloc(0x3E8uLL);
*result = 0;
result[1] = 0;
result[2] = 0;
result[3] = 0;
result[4] = 0;
return result;
}

original_code:
debugerPTR debugerConstructor(){
 debugerPTR debuger = (debugerPTR) malloc(1000);
 debuger->user_wants_to_continue = 0;
 debuger->want_step = 0;
 debuger->command = 0;
 debuger->halt_index = 0;
 debuger->break_index = 0;
 return debuger;
}

canonical_original_code:
struct debuger *debugerConstructor(){
 struct debuger *debuger = (debugerPTR) malloc(1000);
 debuger->user_wants_to_continue = 0;
 debuger->want_step = 0;
 debuger->command = 0;
 debuger->halt_index = 0;
 debuger->break_index = 0;
 return debuger;
}

variable_types: struct debuger { int user_wants_to_continue; int want_step; int command; int halt_index; int break_index; } *


buildIntFromHexString

decompiled_code:
__int64 __fastcall buildIntFromHexString(_BYTE *a1)
{
char v1; // dl
__int64 result; // rax
unsigned __int8 *v3; // rcx
unsigned __int8 *v4; // rdi
int v5; // esi
unsigned int v6; // eax
char v7; // dl

v1 = *a1;
LOBYTE(result) = *a1 - 48;
if ( (char)*a1 > 57 )
{
LOBYTE(result) = v1 - 55;
if ( v1 >= 71 )
LOBYTE(result) = v1 - 87;
}
LOWORD(result) = (char)result;
v3 = a1 + 1;
v4 = a1 + 4;
do
{
v5 = 16 * (unsigned __int16)result;
v6 = *v3;
v7 = v6 - 48;
if ( (char)v6 > 57 )
{
v7 = v6 - 55;
if ( (char)v6 >= 71 )
v7 = v6 - 87;
}
LOWORD(v6) = v7;
result = v5 | v6;
++v3;
}
while ( v3 != v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
char v1; // dl
__int64 result; // rax
unsigned __int8 *v3; // rcx
unsigned __int8 *v4; // rdi
int v5; // esi
unsigned int v6; // eax
char v7; // dl

v1 = *a1;
LOBYTE(result) = *a1 - 48;
if ( (char)*a1 > 57 )
{
LOBYTE(result) = v1 - 55;
if ( v1 >= 71 )
LOBYTE(result) = v1 - 87;
}
LOWORD(result) = (char)result;
v3 = a1 + 1;
v4 = a1 + 4;
do
{
v5 = 16 * (unsigned __int16)result;
v6 = *v3;
v7 = v6 - 48;
if ( (char)v6 > 57 )
{
v7 = v6 - 55;
if ( (char)v6 >= 71 )
v7 = v6 - 87;
}
LOWORD(v6) = v7;
result = v5 | v6;
++v3;
}
while ( v3 != v4 );
return result;
}

original_code:
Register buildIntFromHexString(char * s_num) {
 int length = 4;
 Register result = 0x0;
 char digit = s_num[0];
 if (digit < 58) {
  digit = digit - 48;
 } else if (digit < 71) {
  digit = digit - 55;
 } else {
  digit = digit - 87;
 }
 result = result | digit;
 int i;
 for (i = 1; i < length; i++) {
  result = result << length;
  digit = s_num[i];
  if (digit < 58) {
   digit = digit - 48;
  } else if (digit < 71) {
   digit = digit - 55;
  } else {
   digit = digit - 87;
  }
  result = result | digit;
 }
 return (result);
}

canonical_original_code:
unsigned short buildIntFromHexString(char *s_num) {
 int length = 4;
 unsigned short result = 0x0;
 char digit = s_num[0];
 if (digit < 58) {
  digit = digit - 48;
 } else if (digit < 71) {
  digit = digit - 55;
 } else {
  digit = digit - 87;
 }
 result = result | digit;
 int i;
 for (i = 1; i < length; i++) {
  result = result << length;
  digit = s_num[i];
  if (digit < 58) {
   digit = digit - 48;
  } else if (digit < 71) {
   digit = digit - 55;
  } else {
   digit = digit - 87;
  }
  result = result | digit;
 }
 return (result);
}

variable_types: length int

variable_types:
result
unsigned short

variable_types: digit char

variable_types: i int


getUserContinue

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

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

original_code:
int getUserContinue(debugerPTR this) {
 return (this->user_wants_to_continue);
}

canonical_original_code:
int getUserContinue(struct debuger *this) {
 return (this->user_wants_to_continue);
}

user_defined_types: struct debuger { int user_wants_to_continue; int want_step; int command; int halt_index; int break_index; }


nextStep

decompiled_code:
int __fastcall nextStep(__int64 a1, __int64 a2)
{
int result; // eax

result = *(_DWORD *)(a1 + 12) + 1;
if ( *(unsigned __int16 *)(a2 + 20) == result )
{
*(_DWORD *)(a1 + 4) = 0;
}
else
{
result = step((const char *)a2, (const char *)a2);
*(_DWORD *)(a1 + 4) = 1;
}
return result;
}

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

result = *(_DWORD *)(a1 + 12) + 1;
if ( *(unsigned __int16 *)(a2 + 20) == result )
{
*(_DWORD *)(a1 + 4) = 0;
}
else
{
result = step((const char *)a2, (const char *)a2);
*(_DWORD *)(a1 + 4) = 1;
}
return result;
}

original_code:
void nextStep(debugerPTR this, CPUPtr cpu) {
 if (cpu->PC != this->halt_index + 1) {
  step(cpu);
  this->want_step = 1;
 }
 else {
  this->want_step = 0;
 }
}

canonical_original_code:
void nextStep(struct debuger *this, struct CPU *cpu) {
 if (cpu->PC != this->halt_index + 1) {
  step(cpu);
  this->want_step = 1;
 }
 else {
  this->want_step = 0;
 }
}

variable_types: struct CPU { struct Controller { struct ALU { int mask_array[16]; unsigned short A; unsigned short flags; unsigned char c_out; } *alu; struct Registers { unsigned short registers[8]; } *registers; struct Memory { unsigned short *memory; int size; int capacity; } *memory; unsigned short *PC; unsigned short codes; } *controller; struct Memory *memory; unsigned short MAR; unsigned short MDR; unsigned short PC; } *

user_defined_types: struct CPU { struct Controller *controller; struct Memory *memory; unsigned short MAR; unsigned short MDR; unsigned short PC; }


setHaltIndex

decompiled_code:
void __fastcall setHaltIndex(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 12) = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 12) = a2;
}

original_code:
void setHaltIndex(debugerPTR this, int n) {
 this->halt_index = n;
}

canonical_original_code:
void setHaltIndex(struct debuger *this, int n) {
 this->halt_index = n;
}

variable_types: n int


selectLoadProgram

decompiled_code:
int __fastcall selectLoadProgram(__int64 a1, __int64 a2)
{
__int64 v2; // r12
const char *v3; // rbx
int result; // eax
const char *v5; // rbx

*(_DWORD *)(a1 + 4) = 0;
destroyCPU(a2);
v2 = CPUConstructor();
puts("Please select a program to load:");
puts(
"1) Add From Memory\n"
"2) Add Overflow From Memory\n"
"3) Subtract From Memory\n"
"4) Not From Memory\n"
"5) Enter your own program name.hex");
v3 = (const char *)malloc(0x65uLL);
gets(v3);
switch ( atoi(v3) )
{
case 1:
result = loadFile(a1, "addfrommemory.hex", v2);
break;
case 2:
result = loadFile(a1, "addoverflowfrommem.hex", v2);
break;
case 3:
result = loadFile(a1, "subfrommemory.hex", v2);
break;
case 4:
result = loadFile(a1, "notfrommemory.hex", v2);
break;
case 5:
printf("Type in the name.hex of the program to load: ");
v5 = (const char *)malloc(0x65uLL);
gets(v5);
result = loadFile(a1, v5, v2);
break;
default:
result = printf("Please enter a number 1-5.");
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2)
{
__int64 v2; // r12
const char *v3; // rbx
int result; // eax
const char *v5; // rbx

*(_DWORD *)(a1 + 4) = 0;
destroyCPU(a2);
v2 = CPUConstructor();
puts("Please select a program to load:");
puts(
"1) Add From Memory\n"
"2) Add Overflow From Memory\n"
"3) Subtract From Memory\n"
"4) Not From Memory\n"
"5) Enter your own program name.hex");
v3 = (const char *)malloc(0x65uLL);
gets(v3);
switch ( atoi(v3) )
{
case 1:
result = func5(a1, "addfrommemory.hex", v2);
break;
case 2:
result = func5(a1, "addoverflowfrommem.hex", v2);
break;
case 3:
result = func5(a1, "subfrommemory.hex", v2);
break;
case 4:
result = func5(a1, "notfrommemory.hex", v2);
break;
case 5:
printf("Type in the name.hex of the program to load: ");
v5 = (const char *)malloc(0x65uLL);
gets(v5);
result = func5(a1, v5, v2);
break;
default:
result = printf("Please enter a number 1-5.");
break;
}
return result;
}

original_code:
void selectLoadProgram(debugerPTR this, CPUPtr cputhis) {
        this->want_step = 0;
 destroyCPU(cputhis);
 CPUPtr cpu = CPUConstructor();
 int command = 0;
 printf("Please select a program to load:\n");
 printf("1) Add From Memory\n2) Add Overflow From Memory\n3) Subtract From Memory\n4) Not From Memory\n5) Enter your own program name.hex\n");
 char * input = (char *) malloc(101);
 gets(input);
 command = atoi(input);
 switch (command) {
 case 1:
  loadFile(this, "addfrommemory.hex" , cpu);
  break;
 case 2:
  loadFile(this, "addoverflowfrommem.hex" , cpu);
  break;
 case 3:
  loadFile(this, "subfrommemory.hex" , cpu);
  break;
 case 4:
  loadFile(this, "notfrommemory.hex" , cpu);
  break;
 case 5:
  printf("Type in the name.hex of the program to load: ");
  char * name = (char *) malloc(101);
  gets(name);
  loadFile(this, name , cpu);
  break;
 default:
  printf("Please enter a number 1-5.");
  break;
 }
}

canonical_original_code:
void selectLoadProgram(struct debuger *this, struct CPU *cputhis) {
        this->want_step = 0;
 destroyCPU(cputhis);
 struct CPU *cpu = CPUConstructor();
 int command = 0;
 printf("Please select a program to load:\n");
 printf("1) Add From Memory\n2) Add Overflow From Memory\n3) Subtract From Memory\n4) Not From Memory\n5) Enter your own program name.hex\n");
 char *input = (char *) malloc(101);
 gets(input);
 command = atoi(input);
 switch (command) {
 case 1:
  loadFile(this, "addfrommemory.hex" , cpu);
  break;
 case 2:
  loadFile(this, "addoverflowfrommem.hex" , cpu);
  break;
 case 3:
  loadFile(this, "subfrommemory.hex" , cpu);
  break;
 case 4:
  loadFile(this, "notfrommemory.hex" , cpu);
  break;
 case 5:
  printf("Type in the name.hex of the program to load: ");
  char *name = (char *) malloc(101);
  gets(name);
  loadFile(this, name , cpu);
  break;
 default:
  printf("Please enter a number 1-5.");
  break;
 }
}

variable_types: command int

variable_types:
input
char *

variable_types:
name
char *


showFlags

decompiled_code:
int __fastcall showFlags(__int64 a1)
{
char v1; // r14
int v2; // er13
unsigned __int16 v3; // bp
__int16 v4; // bx
__int16 v5; // ax

v1 = ((__int64 (*)(void))getFlagsFromCPU)();
v2 = getFlagsFromCPU(a1);
v3 = getFlagsFromCPU(a1);
v4 = getFlagsFromCPU(a1);
v5 = getFlagsFromCPU(a1);
return printf(
"Flags: N = %d, Z = %d, P = %d, C = %d, O = %d\n",
(v5 & 0x800) != 0,
(v4 & 0x400) != 0,
(v3 >> 9) & 1,
BYTE1(v2) & 1,
(v1 & 0x80) != 0);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
char v1; // r14
int v2; // er13
unsigned __int16 v3; // bp
__int16 v4; // bx
__int16 v5; // ax

v1 = ((__int64 (*)(void))getFlagsFromCPU)();
v2 = getFlagsFromCPU(a1);
v3 = getFlagsFromCPU(a1);
v4 = getFlagsFromCPU(a1);
v5 = getFlagsFromCPU(a1);
return printf(
"Flags: N = %d, Z = %d, P = %d, C = %d, O = %d\n",
(v5 & 0x800) != 0,
(v4 & 0x400) != 0,
(v3 >> 9) & 1,
BYTE1(v2) & 1,
(v1 & 0x80) != 0);
}

original_code:
void showFlags(CPUPtr cpu){
 printf("Flags:  N = %d, Z = %d, P = %d, C = %d, O = %d\n", ((getFlagsFromCPU(cpu) & 0x0800)?1:0), ((getFlagsFromCPU(cpu) & 0x0400)?1:0), ((getFlagsFromCPU(cpu) & 0x0200)?1:0), ((getFlagsFromCPU(cpu) & 0x0100)?1:0), ((getFlagsFromCPU(cpu) & 0x0080)?1:0));
}

canonical_original_code:
void showFlags(struct CPU *cpu){
 printf("Flags:  N = %d, Z = %d, P = %d, C = %d, O = %d\n", ((getFlagsFromCPU(cpu) & 0x0800)?1:0), ((getFlagsFromCPU(cpu) & 0x0400)?1:0), ((getFlagsFromCPU(cpu) & 0x0200)?1:0), ((getFlagsFromCPU(cpu) & 0x0100)?1:0), ((getFlagsFromCPU(cpu) & 0x0080)?1:0));
}


display

decompiled_code:
int __fastcall display(_QWORD *a1)
{
const char *v1; // rax
const char *v2; // rax
unsigned __int16 v3; // ax
unsigned __int16 v4; // ax
unsigned __int16 v5; // ax

puts("\nMemory:");
v1 = (const char *)memoryToString(a1[1]);
printf("%s\n\n", v1);
puts("Registers:");
v2 = (const char *)registersToString(*(_QWORD *)(*a1 + 8LL));
printf("%s\n\n", v2);
v3 = getMAR(a1);
printf("MAR: %04X\n", v3);
v4 = getMDR(a1);
printf("IR/MDR: %04X\n", v4);
v5 = getPC(a1);
printf("PC: %04x\n", v5);
return showFlags((__int64)a1);
}

canonical_decompiled_code:
int __fastcall func9(_QWORD *a1)
{
const char *v1; // rax
const char *v2; // rax
unsigned __int16 v3; // ax
unsigned __int16 v4; // ax
unsigned __int16 v5; // ax

puts("\nMemory:");
v1 = (const char *)memoryToString(a1[1]);
printf("%s\n\n", v1);
puts("Registers:");
v2 = (const char *)registersToString(*(_QWORD *)(*a1 + 8LL));
printf("%s\n\n", v2);
v3 = getMAR(a1);
printf("MAR: %04X\n", v3);
v4 = getMDR(a1);
printf("IR/MDR: %04X\n", v4);
v5 = getPC(a1);
printf("PC: %04x\n", v5);
return func8((__int64)a1);
}

original_code:
void display(CPUPtr cpu) {
 printf("\nMemory:\n");
 printf("%s\n\n", memoryToString(cpu->memory));
 printf("Registers:\n");
 printf("%s\n\n", registersToString(cpu->controller->registers));
 printf("MAR:       %04X\n", getMAR(cpu));
 printf("IR/MDR:    %04X\n", getMDR(cpu));
 printf("PC:        %04x\n" , getPC(cpu));
        showFlags(cpu);
}

canonical_original_code:
void display(struct CPU *cpu) {
 printf("\nMemory:\n");
 printf("%s\n\n", memoryToString(cpu->memory));
 printf("Registers:\n");
 printf("%s\n\n", registersToString(cpu->controller->registers));
 printf("MAR:       %04X\n", getMAR(cpu));
 printf("IR/MDR:    %04X\n", getMDR(cpu));
 printf("PC:        %04x\n" , getPC(cpu));
        showFlags(cpu);
}


showMenu

decompiled_code:
int __fastcall showMenu(_DWORD *a1, __int64 a2)
{
__int64 v2; // r15
const char *v3; // rbp
const char *v4; // r13
char *v5; // rax
char *v6; // r14
int v7; // eax
int v8; // ebx
int i; // ebp
unsigned int v10; // er12
__int64 v11; // rbp
unsigned int v12; // ebx
signed int j; // ebp
unsigned __int16 v14; // ax

v2 = *(_QWORD *)(a2 + 8);
puts(
"\n"
"Select numerical option:\n"
" 1) Load\n"
" 2) Run\n"
" 3) Step\n"
" 4) Set & Run Breakpoint\n"
" 5) Clear Mem\n"
" 6) Modify a Register\n"
" 7) Show Memory\n"
" 8) Display LC+\n"
" 9) Exit");
v3 = (const char *)malloc(3uLL);
gets(v3);
LODWORD(v3) = atoi(v3);
v4 = (const char *)malloc(5uLL);
v5 = (char *)malloc(5uLL);
v6 = v5;
switch ( (int)v3 )
{
case 1:
LODWORD(v5) = selectLoadProgram((__int64)a1, a2);
break;
case 2:
a1[1] = 0;
for ( LODWORD(v5) = a1[3] + 1; *(unsigned __int16 *)(a2 + 20) != (_DWORD)v5; LODWORD(v5) = a1[3] + 1 )
step((const char *)a2, (const char *)a2);
break;
case 3:
a1[1] = 1;
break;
case 4:
printf("Please enter the breakpoint:");
gets(v6);
v7 = atoi(v6);
a1[4] = v7;
a1[1] = 0;
while ( *(unsigned __int16 *)(a2 + 20) != a1[4] )
step((const char *)a2, (const char *)a2);
LODWORD(v5) = printf("Reached breakpoint.");
break;
case 5:
a1[1] = 0;
puts("Select start of memory you would like to clear.");
gets(v4);
v8 = atoi(v4);
puts("Select end of memory you would like to clear.");
gets(v4);
LODWORD(v5) = atoi(v4);
for ( i = (int)v5; i >= v8; ++v8 )
LODWORD(v5) = setMemory(v2, 0LL, (unsigned int)v8);
break;
case 6:
puts("Please select the register you would like to modify: 1, 2, 3, 4, 5, 6, 7");
gets(v4);
v10 = atoi(v4);
puts("Please enter the 0x0000 value for the register: ");
gets(v6);
v11 = (unsigned __int16)buildIntFromHexString(v6);
printf("%x", v11);
LODWORD(v5) = setRegister(*(_QWORD *)(*(_QWORD *)a2 + 8LL), (unsigned int)v11, v10);
break;
case 7:
a1[1] = 0;
puts("Select start of memory to show");
gets(v4);
v12 = atoi(v4);
puts("Select end of memory to show.");
gets(v4);
LODWORD(v5) = atoi(v4);
for ( j = (int)v5; j >= (int)v12; ++v12 )
{
v14 = getMemory(v2, v12);
LODWORD(v5) = printf("%04x : %04x \n", v12, v14);
}
break;
case 8:
a1[1] = 0;
LODWORD(v5) = display((_QWORD *)a2);
break;
case 9:
LODWORD(v5) = puts("Exiting Program.");
a1[1] = 0;
*a1 = 0;
break;
default:
LODWORD(v5) = puts("Please enter a numerical option 1-5");
break;
}
return (int)v5;
}

canonical_decompiled_code:
int __fastcall func10(_DWORD *a1, __int64 a2)
{
__int64 v2; // r15
const char *v3; // rbp
const char *v4; // r13
char *v5; // rax
char *v6; // r14
int v7; // eax
int v8; // ebx
int i; // ebp
unsigned int v10; // er12
__int64 v11; // rbp
unsigned int v12; // ebx
signed int j; // ebp
unsigned __int16 v14; // ax

v2 = *(_QWORD *)(a2 + 8);
puts(
"\n"
"Select numerical option:\n"
" 1) Load\n"
" 2) Run\n"
" 3) Step\n"
" 4) Set & Run Breakpoint\n"
" 5) Clear Mem\n"
" 6) Modify a Register\n"
" 7) Show Memory\n"
" 8) Display LC+\n"
" 9) Exit");
v3 = (const char *)malloc(3uLL);
gets(v3);
LODWORD(v3) = atoi(v3);
v4 = (const char *)malloc(5uLL);
v5 = (char *)malloc(5uLL);
v6 = v5;
switch ( (int)v3 )
{
case 1:
LODWORD(v5) = func7((__int64)a1, a2);
break;
case 2:
a1[1] = 0;
for ( LODWORD(v5) = a1[3] + 1; *(unsigned __int16 *)(a2 + 20) != (_DWORD)v5; LODWORD(v5) = a1[3] + 1 )
step((const char *)a2, (const char *)a2);
break;
case 3:
a1[1] = 1;
break;
case 4:
printf("Please enter the breakpoint:");
gets(v6);
v7 = atoi(v6);
a1[4] = v7;
a1[1] = 0;
while ( *(unsigned __int16 *)(a2 + 20) != a1[4] )
step((const char *)a2, (const char *)a2);
LODWORD(v5) = printf("Reached breakpoint.");
break;
case 5:
a1[1] = 0;
puts("Select start of memory you would like to clear.");
gets(v4);
v8 = atoi(v4);
puts("Select end of memory you would like to clear.");
gets(v4);
LODWORD(v5) = atoi(v4);
for ( i = (int)v5; i >= v8; ++v8 )
LODWORD(v5) = setMemory(v2, 0LL, (unsigned int)v8);
break;
case 6:
puts("Please select the register you would like to modify: 1, 2, 3, 4, 5, 6, 7");
gets(v4);
v10 = atoi(v4);
puts("Please enter the 0x0000 value for the register: ");
gets(v6);
v11 = (unsigned __int16)func2(v6);
printf("%x", v11);
LODWORD(v5) = setRegister(*(_QWORD *)(*(_QWORD *)a2 + 8LL), (unsigned int)v11, v10);
break;
case 7:
a1[1] = 0;
puts("Select start of memory to show");
gets(v4);
v12 = atoi(v4);
puts("Select end of memory to show.");
gets(v4);
LODWORD(v5) = atoi(v4);
for ( j = (int)v5; j >= (int)v12; ++v12 )
{
v14 = getMemory(v2, v12);
LODWORD(v5) = printf("%04x : %04x \n", v12, v14);
}
break;
case 8:
a1[1] = 0;
LODWORD(v5) = func9((_QWORD *)a2);
break;
case 9:
LODWORD(v5) = puts("Exiting Program.");
a1[1] = 0;
*a1 = 0;
break;
default:
LODWORD(v5) = puts("Please enter a numerical option 1-5");
break;
}
return (int)v5;
}

original_code:
void showMenu(debugerPTR this, CPUPtr cpu) {
 int command = 0;
 MemoryPtr mem = cpu->memory;
 printf("\nSelect numerical option:\n 1) Load\n 2) Run\n 3) Step\n 4) Set & Run Breakpoint\n 5) Clear Mem\n 6) Modify a Register\n 7) Show Memory\n 8) Display LC+\n 9) Exit\n");
 char * input = (char *) malloc(3);
 gets(input);
 command = atoi(input);
 int end;
 int start;
 int i;
 unsigned int regval;
 char * num = (char *) malloc(5);
 char * in = (char *) malloc(5);
 switch(command) {
 case 1:
  selectLoadProgram(this, cpu);
  break;
 case 2:
  this->want_step = 0;
  while (cpu->PC != this->halt_index + 1) {
  step(cpu);
  }
  break;
 case 3:
  this->want_step = 1;
  break;
 case 4:
  printf("Please enter the breakpoint:");
  gets(in);
  this->break_index = atoi(in);
  this->want_step = 0;
  while (cpu->PC != this->break_index) {
  step(cpu);
  }
  printf("Reached breakpoint.");
  break;
 case 5:
  this->want_step = 0;
  printf("Select start of memory you would like to clear.\n");
  gets(num);
  start = atoi(num);
  printf("Select end of memory you would like to clear.\n");
  gets(num);
  end = atoi(num);
  while (start <= end) {
   setMemory(mem, 0, start);
   start ++;
  }
  break;
 case 6:
         printf("Please select the register you would like to modify: 1, 2, 3, 4, 5, 6, 7\n");
         gets(num);
         i = atoi(num);
         printf("Please enter the 0x0000 value for the register: \n");
  gets(in);
  regval = buildIntFromHexString(in);
  printf("%x", regval);
         setRegister(cpu->controller->registers, regval, i);
         break;
 case 7:
  this->want_step = 0;
  printf("Select start of memory to show\n");
  gets(num);
  start = atoi(num);
  printf("Select end of memory to show.\n");
  gets(num);
  end = atoi(num);
  while (start <= end) {
   printf("%04x : %04x \n", start, getMemory(mem, start));
   start ++;
  }
  break;
 case 8:
  this->want_step = 0;
  display(cpu);
  break;
 case 9:
  printf("Exiting Program.\n");
  this->want_step = 0;
  this->user_wants_to_continue = 0;
  break;
 default:
  printf("Please enter a numerical option 1-5\n");
  break;
 }
}

canonical_original_code:
void showMenu(struct debuger *this, struct CPU *cpu) {
 int command = 0;
 struct Memory *mem = cpu->memory;
 printf("\nSelect numerical option:\n 1) Load\n 2) Run\n 3) Step\n 4) Set & Run Breakpoint\n 5) Clear Mem\n 6) Modify a Register\n 7) Show Memory\n 8) Display LC+\n 9) Exit\n");
 char *input = (char *) malloc(3);
 gets(input);
 command = atoi(input);
 int end;
 int start;
 int i;
 unsigned int regval;
 char *num = (char *) malloc(5);
 char *in = (char *) malloc(5);
 switch(command) {
 case 1:
  selectLoadProgram(this, cpu);
  break;
 case 2:
  this->want_step = 0;
  while (cpu->PC != this->halt_index + 1) {
  step(cpu);
  }
  break;
 case 3:
  this->want_step = 1;
  break;
 case 4:
  printf("Please enter the breakpoint:");
  gets(in);
  this->break_index = atoi(in);
  this->want_step = 0;
  while (cpu->PC != this->break_index) {
  step(cpu);
  }
  printf("Reached breakpoint.");
  break;
 case 5:
  this->want_step = 0;
  printf("Select start of memory you would like to clear.\n");
  gets(num);
  start = atoi(num);
  printf("Select end of memory you would like to clear.\n");
  gets(num);
  end = atoi(num);
  while (start <= end) {
   setMemory(mem, 0, start);
   start ++;
  }
  break;
 case 6:
         printf("Please select the register you would like to modify: 1, 2, 3, 4, 5, 6, 7\n");
         gets(num);
         i = atoi(num);
         printf("Please enter the 0x0000 value for the register: \n");
  gets(in);
  regval = buildIntFromHexString(in);
  printf("%x", regval);
         setRegister(cpu->controller->registers, regval, i);
         break;
 case 7:
  this->want_step = 0;
  printf("Select start of memory to show\n");
  gets(num);
  start = atoi(num);
  printf("Select end of memory to show.\n");
  gets(num);
  end = atoi(num);
  while (start <= end) {
   printf("%04x : %04x \n", start, getMemory(mem, start));
   start ++;
  }
  break;
 case 8:
  this->want_step = 0;
  display(cpu);
  break;
 case 9:
  printf("Exiting Program.\n");
  this->want_step = 0;
  this->user_wants_to_continue = 0;
  break;
 default:
  printf("Please enter a numerical option 1-5\n");
  break;
 }
}

variable_types: struct Memory { unsigned short *memory; int size; int capacity; } *

variable_types: end int

variable_types: start int

variable_types:
regval
unsigned int

variable_types:
num
char *

variable_types:
in
char *


debug

decompiled_code:
int __fastcall debug(_DWORD *a1, __int64 a2)
{
int result; // eax

getMemoryPtr(a2);
*a1 = 1;
do
{
showMenu(a1, a2);
if ( a1[1] == 1 )
nextStep((__int64)a1, a2);
display((_QWORD *)a2);
result = a1[3] + 1;
if ( *(unsigned __int16 *)(a2 + 20) != result )
continue;
if ( !*a1 )
break;
result = printf("The program has finished.");
}
while ( *a1 );
return result;
}

canonical_decompiled_code:
int __fastcall func11(_DWORD *a1, __int64 a2)
{
int result; // eax

getMemoryPtr(a2);
*a1 = 1;
do
{
func10(a1, a2);
if ( a1[1] == 1 )
func4((__int64)a1, a2);
func9((_QWORD *)a2);
result = a1[3] + 1;
if ( *(unsigned __int16 *)(a2 + 20) != result )
continue;
if ( !*a1 )
break;
result = printf("The program has finished.");
}
while ( *a1 );
return result;
}

original_code:
void debug(debugerPTR this, CPUPtr cpu) {
 MemoryPtr mem = getMemoryPtr(cpu);
 this->user_wants_to_continue = 1;
 while(this->user_wants_to_continue) {
  showMenu(this, cpu);
  if(this->want_step == 1) {
   nextStep(this, cpu);
  }
  display(cpu);
  if (cpu->PC == this->halt_index + 1 && this->user_wants_to_continue) {
   printf("The program has finished.");
  }
 }
}

canonical_original_code:
void debug(struct debuger *this, struct CPU *cpu) {
 struct Memory *mem = getMemoryPtr(cpu);
 this->user_wants_to_continue = 1;
 while(this->user_wants_to_continue) {
  showMenu(this, cpu);
  if(this->want_step == 1) {
   nextStep(this, cpu);
  }
  display(cpu);
  if (cpu->PC == this->halt_index + 1 && this->user_wants_to_continue) {
   printf("The program has finished.");
  }
 }
}


RegistersConstructor

decompiled_code:
_WORD *RegistersConstructor()
{
_WORD *result; // rax

result = malloc(0x10uLL);
*result = 0;
result[1] = 0;
result[2] = 0;
result[3] = 0;
result[4] = 0;
result[5] = 0;
result[6] = 0;
result[7] = 0;
return result;
}

canonical_decompiled_code:
_WORD *func0()
{
_WORD *result; // rax

result = malloc(0x10uLL);
*result = 0;
result[1] = 0;
result[2] = 0;
result[3] = 0;
result[4] = 0;
result[5] = 0;
result[6] = 0;
result[7] = 0;
return result;
}

original_code:
RegistersPtr RegistersConstructor(void) {
 RegistersPtr registers = (RegistersPtr) malloc(sizeof(Registers));
 int i;
 for (i = 0; i < 8; i++) {
  registers->registers[i] = 0x0000;
 }
 return registers;
}

canonical_original_code:
struct Registers *RegistersConstructor() {
 struct Registers *registers = (RegistersPtr) malloc(sizeof(Registers));
 int i;
 for (i = 0; i < 8; i++) {
  registers->registers[i] = 0x0000;
 }
 return registers;
}

variable_types: struct Registers { unsigned short registers[8]; } *


setRegister

decompiled_code:
void __fastcall setRegister(__int64 a1, __int16 a2, int a3)
{
*(_WORD *)(a1 + 2LL * a3) = a2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int16 a2, int a3)
{
*(_WORD *)(a1 + 2LL * a3) = a2;
}

original_code:
void setRegister(RegistersPtr registers, Register value, int index) {
 registers->registers[index] = value;
}

canonical_original_code:
void setRegister(struct Registers *registers, unsigned short value, int index) {
 registers->registers[index] = value;
}

variable_types:
value
unsigned short

variable_types: index int


getRegister

decompiled_code:
__int64 __fastcall getRegister(__int64 a1, int a2)
{
return *(unsigned __int16 *)(a1 + 2LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
return *(unsigned __int16 *)(a1 + 2LL * a2);
}

original_code:
Register getRegister(RegistersPtr registers, int index) {
 return registers->registers[index];
}

canonical_original_code:
unsigned short getRegister(struct Registers *registers, int index) {
 return registers->registers[index];
}


registersToString

decompiled_code:
char *__fastcall registersToString(__int64 a1)
{
char *v1; // r13
char *v2; // rbp
char *v3; // r12
__int64 i; // rbx
char *result; // rax

v1 = (char *)malloc(9uLL);
v2 = (char *)malloc(0xC8uLL);
v3 = (char *)malloc(9uLL);
for ( i = 0LL; i != 8; ++i )
{
sprintf(v1, "0x%04X\n", *(unsigned __int16 *)(a1 + 2 * i));
sprintf(v3, "R%d: ", (unsigned int)i);
strcat(v2, v3);
result = strcat(v2, v1);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1)
{
char *v1; // r13
char *v2; // rbp
char *v3; // r12
__int64 i; // rbx
char *result; // rax

v1 = (char *)malloc(9uLL);
v2 = (char *)malloc(0xC8uLL);
v3 = (char *)malloc(9uLL);
for ( i = 0LL; i != 8; ++i )
{
sprintf(v1, "0x%04X\n", *(unsigned __int16 *)(a1 + 2 * i));
sprintf(v3, "R%d: ", (unsigned int)i);
strcat(v2, v3);
result = strcat(v2, v1);
}
return result;
}

original_code:
char * registersToString(RegistersPtr registers) {
 char * string = (char *) malloc(9);
 char * result = (char *) malloc(200);
 char * reg_string = (char *) malloc(9);
 Register * regs = registers->registers;
 int i;
 for (i = 0; i < 8; i++) {
  sprintf(string, "0x%04X\n", regs[i]);
  sprintf(reg_string, "R%d: ", i);
  result = strcat(result, reg_string);
  result = strcat(result, string);
 }
 return result;
}

canonical_original_code:
char *registersToString(struct Registers *registers) {
 char *string = (char *) malloc(9);
 char *result = (char *) malloc(200);
 char *reg_string = (char *) malloc(9);
 unsigned short *regs = registers->registers;
 int i;
 for (i = 0; i < 8; i++) {
  sprintf(string, "0x%04X\n", regs[i]);
  sprintf(reg_string, "R%d: ", i);
  result = strcat(result, reg_string);
  result = strcat(result, string);
 }
 return result;
}

variable_types:
string
char *

variable_types:
result
char *

variable_types:
regs
unsigned short *


fullAdder

decompiled_code:
__int64 __fastcall fullAdder(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, _BYTE *a4)
{
unsigned int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // er13
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // er14
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax
unsigned int v19; // er12
unsigned int v20; // eax
unsigned int v21; // ebx
unsigned int v22; // eax
unsigned __int8 v24; // [rsp+0h] [rbp-48h]
unsigned __int8 v25; // [rsp+4h] [rbp-44h]
unsigned __int8 v26; // [rsp+8h] [rbp-40h]
unsigned int v27; // [rsp+Ch] [rbp-3Ch]

v5 = a3;
v6 = and(a1, a2);
v24 = and(v6, v5);
v7 = not(v5);
v8 = and(a1, a2);
v25 = and(v8, v7);
v9 = not(a2);
v10 = and(a1, v9);
LOBYTE(v7) = and(v10, v5);
v11 = not(v5);
v12 = not(a2);
v13 = and(a1, v12);
v26 = and(v13, v11);
v14 = not(a1);
v15 = and(v14, a2);
LOBYTE(v11) = and(v15, v5);
v27 = not(v5);
v16 = not(a1);
v17 = and(v16, a2);
LOBYTE(v27) = and(v17, v27);
v18 = nor(a1, a2);
LOBYTE(v5) = and(v18, v5);
v19 = or((unsigned __int8)v7, (unsigned __int8)v11);
v20 = or(v24, v25);
*a4 = or(v20, v19);
v21 = or((unsigned __int8)v27, (unsigned __int8)v5);
v22 = or(v24, v26);
return or(v22, v21);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, _BYTE *a4)
{
unsigned int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // er13
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // er14
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax
unsigned int v19; // er12
unsigned int v20; // eax
unsigned int v21; // ebx
unsigned int v22; // eax
unsigned __int8 v24; // [rsp+0h] [rbp-48h]
unsigned __int8 v25; // [rsp+4h] [rbp-44h]
unsigned __int8 v26; // [rsp+8h] [rbp-40h]
unsigned int v27; // [rsp+Ch] [rbp-3Ch]

v5 = a3;
v6 = and(a1, a2);
v24 = and(v6, v5);
v7 = not(v5);
v8 = and(a1, a2);
v25 = and(v8, v7);
v9 = not(a2);
v10 = and(a1, v9);
LOBYTE(v7) = and(v10, v5);
v11 = not(v5);
v12 = not(a2);
v13 = and(a1, v12);
v26 = and(v13, v11);
v14 = not(a1);
v15 = and(v14, a2);
LOBYTE(v11) = and(v15, v5);
v27 = not(v5);
v16 = not(a1);
v17 = and(v16, a2);
LOBYTE(v27) = and(v17, v27);
v18 = nor(a1, a2);
LOBYTE(v5) = and(v18, v5);
v19 = or((unsigned __int8)v7, (unsigned __int8)v11);
v20 = or(v24, v25);
*a4 = or(v20, v19);
v21 = or((unsigned __int8)v27, (unsigned __int8)v5);
v22 = or(v24, v26);
return or(v22, v21);
}

original_code:
bit fullAdder(bit a, bit b, bit c_in, bit * c_out) {
 bit gate_1 = and(and(a, b), c_in);
 bit gate_2 = and(and(a, b), not(c_in));
 bit gate_3 = and(and(a, not(b)), c_in);
 bit gate_4 = and(and(a, not(b)), not(c_in));
 bit gate_5 = and(and(not(a), b), c_in);
 bit gate_6 = and(and(not(a), b), not(c_in));
 bit gate_7 = and(nor(a, b), c_in);
 *c_out = or(or(gate_1, gate_2), or(gate_3, gate_5));
 bit result = or(or(gate_1, gate_4), or(gate_6, gate_7));
 return result;
}

canonical_original_code:
unsigned char fullAdder(unsigned char a, unsigned char b, unsigned char c_in, unsigned char *c_out) {
 unsigned char gate_1 = and(and(a, b), c_in);
 unsigned char gate_2 = and(and(a, b), not(c_in));
 unsigned char gate_3 = and(and(a, not(b)), c_in);
 unsigned char gate_4 = and(and(a, not(b)), not(c_in));
 unsigned char gate_5 = and(and(not(a), b), c_in);
 unsigned char gate_6 = and(and(not(a), b), not(c_in));
 unsigned char gate_7 = and(nor(a, b), c_in);
 *c_out = or(or(gate_1, gate_2), or(gate_3, gate_5));
 unsigned char result = or(or(gate_1, gate_4), or(gate_6, gate_7));
 return result;
}

variable_types:
a
unsigned char

variable_types:
b
unsigned char

variable_types:
result
unsigned char

return_type: unsigned char


repo: tudordavid/libslock

decompiled_code:
__int64 __fastcall get_cluster(int a1)
{
return (unsigned int)(a1 / 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)(a1 / 8);
}

original_code:
static inline int get_cluster(int thread_id) {
        return thread_id/8;
    }


decompiled_code:
__int64 __fastcall swap_pointer(volatile __int64 *a1, __int64 a2)
{
return _InterlockedExchange64(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(volatile __int64 *a1, __int64 a2)
{
return _InterlockedExchange64(a1, a2);
}

original_code:
static inline void* swap_pointer(volatile void* ptr, void *x) {
    __asm__ __volatile__("xchgq %0,%1"
            :"=r" ((unsigned long long) x)
            :"m" (*(volatile long long *)ptr), "0" ((unsigned long long) x)
            :"memory");
    return x;
}

canonical_original_code:
static inline void *swap_pointer(void *ptr, void *x) {
    __asm__ __volatile__("xchgq %0,%1"
            :"=r" ((unsigned long long) x)
            :"m" (*(long long *)ptr), "0" ((unsigned long long) x)
            :"memory");
    return x;
}

variable_types:
ptr
void *

variable_types:
x
void *

return_type: void *


decompiled_code:
int __fastcall set_cpu(int a1)
{
cpu_set_t *v1; // rsi
unsigned int v2; // eax
pthread_t v3; // rax
int result; // eax
cpu_set_t v5; // [rsp+0h] [rbp-88h] BYREF

v1 = &v5;
memset(&v5, 0, sizeof(v5));
if ( (unsigned __int64)a1 <= 0x3FF )
{
v1 = (cpu_set_t *)(1LL << a1);
v5.__bits[(unsigned __int64)a1 >> 6] |= 1LL << a1;
}
v2 = get_cluster(a1);
numa_set_preferred(v2, v1);
v3 = pthread_self();
result = pthread_setaffinity_np(v3, 0x80uLL, &v5);
if ( result )
result = fwrite("Error setting thread affinity\n", 1uLL, 0x1EuLL, stderr);
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
cpu_set_t *v1; // rsi
unsigned int v2; // eax
pthread_t v3; // rax
int result; // eax
cpu_set_t v5; // [rsp+0h] [rbp-88h] BYREF

v1 = &v5;
memset(&v5, 0, sizeof(v5));
if ( (unsigned __int64)a1 <= 0x3FF )
{
v1 = (cpu_set_t *)(1LL << a1);
v5.__bits[(unsigned __int64)a1 >> 6] |= 1LL << a1;
}
v2 = func0(a1);
numa_set_preferred(v2, v1);
v3 = pthread_self();
result = pthread_setaffinity_np(v3, 0x80uLL, &v5);
if ( result )
result = fwrite("Error setting thread affinity\n", 1uLL, 0x1EuLL, stderr);
return result;
}

original_code:
static inline void set_cpu(int cpu) {
        cpu_set_t mask;
        do __builtin_memset (&mask, '\0', sizeof (cpu_set_t)); while (0);
        (__extension__ ({ size_t __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
        numa_set_preferred(get_cluster(cpu));
        pthread_t thread = pthread_self();
        if (pthread_setaffinity_np(thread, sizeof(cpu_set_t), &mask) != 0) {
            fprintf(stderr, "Error setting thread affinity\n");
        }
    }

canonical_original_code:
static inline void set_cpu(int cpu) {
        struct cpu_set_t mask;
        do __builtin_memset (&mask, '\0', sizeof (cpu_set_t)); while (0);
        (__extension__ ({ unsigned long __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
        numa_set_preferred(get_cluster(cpu));
        unsigned long thread = pthread_self();
        if (pthread_setaffinity_np(thread, sizeof(cpu_set_t), &mask) != 0) {
            fprintf(stderr, "Error setting thread affinity\n");
        }
    }

variable_types: cpu int

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }

variable_types:
thread
unsigned long


decompiled_code:
_BOOL8 __fastcall mcs_trylock(volatile signed __int64 *a1, signed __int64 a2)
{
*(_QWORD *)(a2 + 8) = 0LL;
return _InterlockedCompareExchange64(a1, a2, 0LL) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(volatile signed __int64 *a1, signed __int64 a2)
{
*(_QWORD *)(a2 + 8) = 0LL;
return _InterlockedCompareExchange64(a1, a2, 0LL) != 0;
}

original_code:
int mcs_trylock(mcs_lock *L, mcs_qnode_ptr I) {
    I->next=((void *)0);
    if (__sync_val_compare_and_swap(L,((void *)0),I)==((void *)0)) return 0;
    return 1;
}

canonical_original_code:
int mcs_trylock(struct mcs_qnode **L, struct mcs_qnode *I) {
    I->next=((void *)0);
    if (__sync_val_compare_and_swap(L,((void *)0),I)==((void *)0)) return 0;
    return 1;
}

variable_types: struct mcs_qnode { unsigned char waiting; struct mcs_qnode *next; unsigned char padding[-1]; } **

variable_types:
I
struct mcs_qnode *


decompiled_code:
__int64 __fastcall mcs_acquire(volatile __int64 *a1, unsigned __int8 *a2)
{
__int64 result; // rax

*((_QWORD *)a2 + 1) = 0LL;
result = swap_pointer(a1, (__int64)a2);
if ( result )
{
*a2 = 1;
_mm_mfence();
*(_QWORD *)(result + 8) = a2;
for ( result = *a2; (_BYTE)result; result = *a2 )
_mm_pause();
}
return result;
}

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

*((_QWORD *)a2 + 1) = 0LL;
result = func1(a1, (__int64)a2);
if ( result )
{
*a2 = 1;
_mm_mfence();
*(_QWORD *)(result + 8) = a2;
for ( result = *a2; (_BYTE)result; result = *a2 )
_mm_pause();
}
return result;
}

original_code:
void mcs_acquire(mcs_lock *L, mcs_qnode_ptr I)
{
    I->next = ((void *)0);
    mcs_qnode_ptr pred = (mcs_qnode*) swap_pointer((volatile void*) L,(void*) I);
    if (pred == ((void *)0))
        return;
    I->waiting = 1;
    __sync_synchronize();
    pred->next = I;
    while (I->waiting != 0)
    {
        _mm_pause();
    }
}

canonical_original_code:
void mcs_acquire(struct mcs_qnode **L, struct mcs_qnode *I)
{
    I->next = ((void *)0);
    struct mcs_qnode *pred = (mcs_qnode*) swap_pointer((volatile void*) L,(void*) I);
    if (pred == ((void *)0))
        return;
    I->waiting = 1;
    __sync_synchronize();
    pred->next = I;
    while (I->waiting != 0)
    {
        _mm_pause();
    }
}

variable_types: struct mcs_qnode { unsigned char waiting; struct mcs_qnode *next; unsigned char padding[-1]; } *


decompiled_code:
_BOOL8 __fastcall is_free_mcs(_QWORD *a1)
{
return *a1 == 0LL;
}

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

original_code:
int is_free_mcs(mcs_lock *L ){
    if ((*L) == ((void *)0)) return 1;
    return 0;
}

canonical_original_code:
int is_free_mcs(struct mcs_qnode **L){
    if ((*L) == ((void *)0)) return 1;
    return 0;
}

user_defined_types: struct mcs_qnode { unsigned char waiting; struct mcs_qnode *next; unsigned char padding[-1]; }


decompiled_code:
void __fastcall end_mcs_array_local(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

original_code:
void end_mcs_array_local(mcs_qnode** the_qnodes, uint32_t size) {
    uint32_t i;
    for (i = 0; i < size; i++) {
        free(the_qnodes[i]);
    }
    free(the_qnodes);
}

canonical_original_code:
void end_mcs_array_local(struct mcs_qnode **the_qnodes, unsigned int size) {
    unsigned int i;
    for (i = 0; i < size; i++) {
        free(the_qnodes[i]);
    }
    free(the_qnodes);
}

variable_types:
size
unsigned int

variable_types:
i
unsigned int


decompiled_code:
void __fastcall end_mcs_array_global(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
{
free(*v2);
v2 += 8;
}
while ( v2 != (void **)((char *)ptr + 64 * (unsigned __int64)(unsigned int)(a2 - 1) + 64) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
{
free(*v2);
v2 += 8;
}
while ( v2 != (void **)((char *)ptr + 64 * (unsigned __int64)(unsigned int)(a2 - 1) + 64) );
}
free(ptr);
}

original_code:
void end_mcs_array_global(mcs_global_params* the_locks, uint32_t size) {
    uint32_t i;
    for (i = 0; i < size; i++) {
        free(the_locks[i].the_lock);
    }
    free(the_locks);
}

canonical_original_code:
void end_mcs_array_global(struct mcs_global_params *the_locks, unsigned int size) {
    unsigned int i;
    for (i = 0; i < size; i++) {
        free(the_locks[i].the_lock);
    }
    free(the_locks);
}

variable_types: struct mcs_global_params { struct mcs_qnode { unsigned char waiting; struct mcs_qnode *next; unsigned char padding[-1]; } **the_lock; unsigned char padding[-1]; } *

user_defined_types: struct mcs_global_params { struct mcs_qnode **the_lock; unsigned char padding[-1]; }


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

v1 = malloc(8uLL);
*a1 = v1;
*v1 = 0LL;
_mm_mfence();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
_QWORD *v1; // rax

v1 = malloc(8uLL);
*a1 = v1;
*v1 = 0LL;
_mm_mfence();
return 0LL;
}

original_code:
int init_mcs_global(mcs_global_params* the_lock) {
    the_lock->the_lock=(mcs_lock*)malloc(sizeof(mcs_lock));
    *(the_lock->the_lock)=0;
    __sync_synchronize();
    return 0;
}

canonical_original_code:
int init_mcs_global(struct mcs_global_params *the_lock) {
    the_lock->the_lock=(struct mcs_qnode **)malloc(sizeof(mcs_lock));
    *(the_lock->the_lock)=0;
    __sync_synchronize();
    return 0;
}


decompiled_code:
__int64 __fastcall init_mcs_local(int a1, void **a2)
{
set_cpu(a1);
*a2 = malloc(0x40uLL);
_mm_mfence();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, void **a2)
{
func2(a1);
*a2 = malloc(0x40uLL);
_mm_mfence();
return 0LL;
}

original_code:
int init_mcs_local(uint32_t thread_num, mcs_qnode** the_qnode) {
    set_cpu(thread_num);
    (*the_qnode)=(mcs_qnode*)malloc(sizeof(mcs_qnode));
    __sync_synchronize();
    return 0;
}

canonical_original_code:
int init_mcs_local(unsigned int thread_num, struct mcs_qnode **the_qnode) {
    set_cpu(thread_num);
    (*the_qnode)=(struct mcs_qnode *)malloc(sizeof(mcs_qnode));
    __sync_synchronize();
    return 0;
}


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

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

original_code:
void end_mcs_local(mcs_qnode* the_qnodes) {
    free(the_qnodes);
}

canonical_original_code:
void end_mcs_local(struct mcs_qnode *the_qnodes) {
    free(the_qnodes);
}


decompiled_code:
void __fastcall end_mcs_global(int a1, int a2, int a3, int a4, int a5, int a6, void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(int a1, int a2, int a3, int a4, int a5, int a6, void *ptr)
{
free(ptr);
}

original_code:
void end_mcs_global(mcs_global_params the_locks) {
    free(the_locks.the_lock);
}

canonical_original_code:
void end_mcs_global(struct mcs_global_params the_locks) {
    free(the_locks.the_lock);
}

variable_types: struct mcs_global_params { struct mcs_qnode { unsigned char waiting; struct mcs_qnode *next; unsigned char padding[-1]; } **the_lock; unsigned char padding[-1]; }


canonical_original_code:
static inline int get_cluster(int thread_id) {
        return thread_id/8;
    }


canonical_decompiled_code:
int __fastcall func1(int a1)
{
cpu_set_t *v1; // rsi
unsigned int v2; // eax
pthread_t v3; // rax
int result; // eax
cpu_set_t v5; // [rsp+0h] [rbp-88h] BYREF

v1 = &v5;
memset(&v5, 0, sizeof(v5));
if ( (unsigned __int64)a1 <= 0x3FF )
{
v1 = (cpu_set_t *)(1LL << a1);
v5.__bits[(unsigned __int64)a1 >> 6] |= 1LL << a1;
}
v2 = func0(a1);
numa_set_preferred(v2, v1);
v3 = pthread_self();
result = pthread_setaffinity_np(v3, 0x80uLL, &v5);
if ( result )
result = fwrite("Error setting thread affinity\n", 1uLL, 0x1EuLL, stderr);
return result;
}

user_defined_types: struct cpu_set_t { unsigned long __bits[-1]; }


decompiled_code:
_BOOL8 __fastcall is_free_alock(_DWORD *a1)
{
return LOWORD(a1[16 * (unsigned __int64)(unsigned int)(*a1 % a1[1]) + 2]) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_DWORD *a1)
{
return LOWORD(a1[16 * (unsigned __int64)(unsigned int)(*a1 % a1[1]) + 2]) == 1;
}

original_code:
int is_free_alock(lock_shared_t* the_lock) {
    if ((the_lock->flags[(the_lock->tail) % the_lock->size].flag) == (uint32_t)1) return 1;
    return 0;
}

canonical_original_code:
int is_free_alock(struct lock_shared *the_lock) {
    if ((the_lock->flags[(the_lock->tail) % the_lock->size].flag) == (unsigned int)1) return 1;
    return 0;
}

variable_types: struct lock_shared { unsigned int tail; unsigned int size; struct flag_line { unsigned short flag; unsigned char padding[-1]; } flags[80]; } *

user_defined_types: struct lock_shared { unsigned int tail; unsigned int size; struct flag_line flags[80]; }


decompiled_code:
__int64 __fastcall alock_trylock(__int64 a1)
{
unsigned __int32 *v1; // rcx
unsigned __int32 v2; // esi
__int64 result; // rax

v1 = *(unsigned __int32 **)(a1 + 8);
v2 = *v1;
result = 1LL;
if ( LOWORD(v1[16 * (unsigned __int64)(*v1 % v1[1]) + 2]) == 1 )
{
result = 1LL;
if ( _InterlockedCompareExchange((volatile signed __int32 *)v1, v2 + 1, v2) == v2 )
{
*(_DWORD *)a1 = v2 % v1[1];
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned __int32 *v1; // rcx
unsigned __int32 v2; // esi
__int64 result; // rax

v1 = *(unsigned __int32 **)(a1 + 8);
v2 = *v1;
result = 1LL;
if ( LOWORD(v1[16 * (unsigned __int64)(*v1 % v1[1]) + 2]) == 1 )
{
result = 1LL;
if ( _InterlockedCompareExchange((volatile signed __int32 *)v1, v2 + 1, v2) == v2 )
{
*(_DWORD *)a1 = v2 % v1[1];
result = 0LL;
}
}
return result;
}

original_code:
int alock_trylock(array_lock_t* local_lock) {
    lock_shared_t *lock = local_lock->shared_data;
    uint32_t tail = lock->tail;
    if (lock->flags[tail % lock->size].flag==1) {
        if (__sync_val_compare_and_swap(&(lock->tail),tail,tail+1)==tail) {
            local_lock->my_index = tail % lock->size;
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int alock_trylock(struct lock *local_lock) {
    struct lock_shared *lock = local_lock->shared_data;
    unsigned int tail = lock->tail;
    if (lock->flags[tail % lock->size].flag==1) {
        if (__sync_val_compare_and_swap(&(lock->tail),tail,tail+1)==tail) {
            local_lock->my_index = tail % lock->size;
            return 0;
        }
    }
    return 1;
}

variable_types: struct lock { unsigned int my_index; struct lock_shared { unsigned int tail; unsigned int size; struct flag_line { unsigned short flag; unsigned char padding[-1]; } flags[80]; } *shared_data; } *

variable_types:
tail
unsigned int

user_defined_types: struct lock { unsigned int my_index; struct lock_shared *shared_data; }


decompiled_code:
__int64 __fastcall alock_lock(__int64 a1)
{
__int64 v1; // rcx
unsigned int v2; // edx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = (unsigned int)_InterlockedExchangeAdd((volatile signed __int32 *)v1, 1u) % *(_DWORD *)(v1 + 4);
*(_DWORD *)a1 = v2;
result = v1 + ((unsigned __int64)v2 << 6);
while ( !*(_WORD *)(result + 8) )
_mm_pause();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rcx
unsigned int v2; // edx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = (unsigned int)_InterlockedExchangeAdd((volatile signed __int32 *)v1, 1u) % *(_DWORD *)(v1 + 4);
*(_DWORD *)a1 = v2;
result = v1 + ((unsigned __int64)v2 << 6);
while ( !*(_WORD *)(result + 8) )
_mm_pause();
return result;
}

original_code:
void alock_lock(array_lock_t* local_lock)
{
    lock_shared_t *lock = local_lock->shared_data;
    uint32_t slot = __sync_fetch_and_add(&(lock->tail),1) % lock->size;
    local_lock->my_index = slot;
    volatile uint16_t* flag = &lock->flags[slot].flag;
    while (*flag == 0)
    {
        _mm_pause();
    }
}

canonical_original_code:
void alock_lock(struct lock *local_lock)
{
    struct lock_shared *lock = local_lock->shared_data;
    unsigned int slot = __sync_fetch_and_add(&(lock->tail),1) % lock->size;
    local_lock->my_index = slot;
    unsigned short *flag = &lock->flags[slot].flag;
    while (*flag == 0)
    {
        _mm_pause();
    }
}

variable_types:
slot
unsigned int

variable_types:
flag
unsigned short *

user_defined_types: struct flag_line { unsigned short flag; unsigned char padding[-1]; }


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

*(_QWORD *)(a2 + 5120) = 0LL;
result = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 5128) >> 3));
*(_DWORD *)(a2 + 4) = a1;
*(_WORD *)(a2 + 8) = 1;
*(_DWORD *)a2 = 0;
_mm_mfence();
return result;
}

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

*(_QWORD *)(a2 + 5120) = 0LL;
result = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 5128) >> 3));
*(_DWORD *)(a2 + 4) = a1;
*(_WORD *)(a2 + 8) = 1;
*(_DWORD *)a2 = 0;
_mm_mfence();
return result;
}

original_code:
int init_alock_global(uint32_t num_processes, lock_shared_t* the_lock) {
    bzero((void*)the_lock,sizeof(lock_shared_t));
    the_lock->size = num_processes;
    the_lock->flags[0].flag=1;
    the_lock->tail=0;
    __sync_synchronize();
    return 0;
}

canonical_original_code:
int init_alock_global(unsigned int num_processes, struct lock_shared *the_lock) {
    bzero((void *)the_lock,sizeof(lock_shared_t));
    the_lock->size = num_processes;
    the_lock->flags[0].flag=1;
    the_lock->tail=0;
    __sync_synchronize();
    return 0;
}


decompiled_code:
__int64 __fastcall init_alock_local(int a1, __int64 a2, __int64 a3)
{
set_cpu(a1);
*(_DWORD *)a3 = 0;
*(_QWORD *)(a3 + 8) = a2;
_mm_mfence();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, __int64 a2, __int64 a3)
{
func1(a1);
*(_DWORD *)a3 = 0;
*(_QWORD *)(a3 + 8) = a2;
_mm_mfence();
return 0LL;
}

original_code:
int init_alock_local(uint32_t thread_num, lock_shared_t* the_lock, array_lock_t* local_lock) {
    set_cpu(thread_num);
    local_lock->my_index=0;
    local_lock->shared_data = the_lock;
    __sync_synchronize();
    return 0;
}

canonical_original_code:
int init_alock_local(unsigned int thread_num, struct lock_shared *the_lock, struct lock *local_lock) {
    set_cpu(thread_num);
    local_lock->my_index=0;
    local_lock->shared_data = the_lock;
    __sync_synchronize();
    return 0;
}

variable_types: struct lock { unsigned int my_index; struct lock_shared *shared_data; } *


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

original_code:
void end_alock_array_local(array_lock_t* local_locks, uint32_t size) {
    free(local_locks);
}

canonical_original_code:
void end_alock_array_local(struct lock *local_locks, unsigned int size) {
    free(local_locks);
}


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

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

original_code:
void end_alock_array_global(lock_shared_t* the_locks, uint32_t size) {
    free(the_locks);
}

canonical_original_code:
void end_alock_array_global(struct lock_shared *the_locks, unsigned int size) {
    free(the_locks);
}


decompiled_code:
void end_alock_local()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void end_alock_local(array_lock_t local_lock) {
}

canonical_original_code:
void end_alock_local(struct lock local_lock) {
}

variable_types: struct lock { unsigned int my_index; struct lock_shared { unsigned int tail; unsigned int size; struct flag_line { unsigned short flag; unsigned char padding[-1]; } flags[80]; } *shared_data; }


decompiled_code:
void end_alock_global()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code:
void end_alock_global(lock_shared_t the_lock) {
}

canonical_original_code:
void end_alock_global(struct lock_shared the_lock) {
}

variable_types: struct lock_shared { unsigned int tail; unsigned int size; struct flag_line { unsigned short flag; unsigned char padding[-1]; } flags[80]; }


decompiled_code:
void __fastcall nop_rep(int a1)
{
int i; // eax

if ( a1 )
{
for ( i = 0; i != a1; ++i )
;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
int i; // eax

if ( a1 )
{
for ( i = 0; i != a1; ++i )
;
}
}

original_code:
static inline void
        nop_rep(uint32_t num_reps)
        {
            uint32_t i;
            for (i = 0; i < num_reps; i++)
            {
                asm volatile ("NOP");
            }
        }

canonical_original_code:
static inline void nop_rep(unsigned int num_reps)
        {
            unsigned int i;
            for (i = 0; i < num_reps; i++)
            {
                asm volatile ("NOP");
            }
        }


getticks

decompiled_code:
unsigned __int64 getticks()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func2()
{
return __rdtsc();
}

original_code:
static inline ticks getticks(void)
    {
        unsigned hi, lo;
        __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
        return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
    }

canonical_original_code:
static inline unsigned long getticks()
    {
        unsigned int hi; unsigned int lo;
        __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
        return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
    }

variable_types:
hi
unsigned int

variable_types:
lo
unsigned int

return_type: unsigned long


decompiled_code:
int __fastcall set_cpu(int a1)
{
cpu_set_t *v1; // rsi
unsigned int v2; // eax
pthread_t v3; // rax
int result; // eax
cpu_set_t v5; // [rsp+0h] [rbp-88h] BYREF

v1 = &v5;
memset(&v5, 0, sizeof(v5));
if ( (unsigned __int64)a1 <= 0x3FF )
{
v1 = (cpu_set_t *)(1LL << a1);
v5.__bits[(unsigned __int64)a1 >> 6] |= 1LL << a1;
}
v2 = get_cluster(a1);
numa_set_preferred(v2, v1);
v3 = pthread_self();
result = pthread_setaffinity_np(v3, 0x80uLL, &v5);
if ( result )
result = fwrite("Error setting thread affinity\n", 1uLL, 0x1EuLL, stderr);
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
cpu_set_t *v1; // rsi
unsigned int v2; // eax
pthread_t v3; // rax
int result; // eax
cpu_set_t v5; // [rsp+0h] [rbp-88h] BYREF

v1 = &v5;
memset(&v5, 0, sizeof(v5));
if ( (unsigned __int64)a1 <= 0x3FF )
{
v1 = (cpu_set_t *)(1LL << a1);
v5.__bits[(unsigned __int64)a1 >> 6] |= 1LL << a1;
}
v2 = func0(a1);
numa_set_preferred(v2, v1);
v3 = pthread_self();
result = pthread_setaffinity_np(v3, 0x80uLL, &v5);
if ( result )
result = fwrite("Error setting thread affinity\n", 1uLL, 0x1EuLL, stderr);
return result;
}

original_code:
static inline void set_cpu(int cpu) {
        cpu_set_t mask;
        do __builtin_memset (&mask, '\0', sizeof (cpu_set_t)); while (0);
        (__extension__ ({ size_t __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
        numa_set_preferred(get_cluster(cpu));
        pthread_t thread = pthread_self();
        if (pthread_setaffinity_np(thread, sizeof(cpu_set_t), &mask) != 0) {
            fprintf(stderr, "Error setting thread affinity\n");
        }
    }

canonical_original_code:
static inline void set_cpu(int cpu) {
        struct cpu_set_t mask;
        do __builtin_memset (&mask, '\0', sizeof (cpu_set_t)); while (0);
        (__extension__ ({ unsigned long __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
        numa_set_preferred(get_cluster(cpu));
        unsigned long thread = pthread_self();
        if (pthread_setaffinity_np(thread, sizeof(cpu_set_t), &mask) != 0) {
            fprintf(stderr, "Error setting thread affinity\n");
        }
    }

variable_types: cpu int

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }

variable_types:
thread
unsigned long


decompiled_code:
unsigned __int64 __fastcall wait_cycles(unsigned __int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rdx
unsigned __int64 v3; // rbx

if ( a1 > 0xFF )
{
v3 = a1 + getticks() - 130;
do
result = getticks();
while ( result < v3 );
}
else
{
result = 0xAAAAAAAAAAAAAAABLL * a1;
v2 = a1 / 6;
if ( a1 > 5 )
{
do
{
_mm_pause();
--v2;
}
while ( v2 );
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(unsigned __int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rdx
unsigned __int64 v3; // rbx

if ( a1 > 0xFF )
{
v3 = a1 + func2() - 130;
do
result = func2();
while ( result < v3 );
}
else
{
result = 0xAAAAAAAAAAAAAAABLL * a1;
v2 = a1 / 6;
if ( a1 > 5 )
{
do
{
_mm_pause();
--v2;
}
while ( v2 );
}
}
return result;
}

original_code:
static inline void
wait_cycles(uint64_t cycles)
{
    if (cycles < 256)
    {
        cycles /= 6;
        while (cycles--)
        {
            _mm_pause();
        }
    }
    else
    {
        ticks _start_ticks = getticks();
        ticks _end_ticks = _start_ticks + cycles - 130;
        while (getticks() < _end_ticks);
    }
}

canonical_original_code:
static inline void wait_cycles(unsigned long cycles)
{
    if (cycles < 256)
    {
        cycles /= 6;
        while (cycles--)
        {
            _mm_pause();
        }
    }
    else
    {
        unsigned long _start_ticks = getticks();
        unsigned long _end_ticks = _start_ticks + cycles - 130;
        while (getticks() < _end_ticks);
    }
}

variable_types:
cycles
unsigned long


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

for ( result = *(unsigned int *)(a1 + 4); (_DWORD)result != a2; result = *(unsigned int *)(a1 + 4) )
{
v3 = sub_abs(*(_DWORD *)(a1 + 4), a2);
if ( v3 > 1 )
nop_rep(v3 << 9);
else
_mm_pause();
}
return result;
}

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

for ( result = *(unsigned int *)(a1 + 4); (_DWORD)result != a2; result = *(unsigned int *)(a1 + 4) )
{
v3 = func3(*(_DWORD *)(a1 + 4), a2);
if ( v3 > 1 )
func1(v3 << 9);
else
_mm_pause();
}
return result;
}

original_code:
static inline void
htlock_wait_ticket(htlock_local_t* lock, const uint32_t ticket)
{
    while (lock->cur != ticket)
    {
        uint32_t distance = sub_abs(lock->cur, ticket);
        if (distance > 1)
        {
            nop_rep(distance * 512);
        }
        else
        {
            _mm_pause();
        }
    }
}

canonical_original_code:
static inline void htlock_wait_ticket(struct htlock_local *lock, unsigned int ticket)
{
    while (lock->cur != ticket)
    {
        unsigned int distance = sub_abs(lock->cur, ticket);
        if (distance > 1)
        {
            nop_rep(distance * 512);
        }
        else
        {
            _mm_pause();
        }
    }
}

variable_types: struct htlock_local { int nxt; int cur; unsigned char padding[-1]; } *

variable_types:
ticket
unsigned int

variable_types:
distance
unsigned int


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

for ( result = *(unsigned int *)(a1 + 4); (_DWORD)result != a2; result = *(unsigned int *)(a1 + 4) )
{
v3 = sub_abs(*(_DWORD *)(a1 + 4), a2);
if ( v3 > 1 )
wait_cycles(v3 << 8);
else
_mm_pause();
}
return result;
}

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

for ( result = *(unsigned int *)(a1 + 4); (_DWORD)result != a2; result = *(unsigned int *)(a1 + 4) )
{
v3 = func3(*(_DWORD *)(a1 + 4), a2);
if ( v3 > 1 )
func5(v3 << 8);
else
_mm_pause();
}
return result;
}

original_code:
static inline void
htlock_wait_global(htlock_local_t* lock, const uint32_t ticket)
{
    while (lock->cur != ticket)
    {
        uint32_t distance = sub_abs(lock->cur, ticket);
        if (distance > 1)
        {
            wait_cycles(distance * 256);
        }
        else
        {
            _mm_pause();
        }
    }
}

canonical_original_code:
static inline void htlock_wait_global(struct htlock_local *lock, unsigned int ticket)
{
    while (lock->cur != ticket)
    {
        unsigned int distance = sub_abs(lock->cur, ticket);
        if (distance > 1)
        {
            wait_cycles(distance * 256);
        }
        else
        {
            _mm_pause();
        }
    }
}

user_defined_types: struct htlock_local { int nxt; int cur; unsigned char padding[-1]; }


decompiled_code:
__int64 __fastcall create_htlock(_QWORD *a1)
{
_DWORD *v1; // rbx
_DWORD *v2; // rax

if ( !a1 )
_assert_fail("htl != NULL", "src/htlock.c", 0x31u, "create_htlock");
v1 = memalign(0x40uLL, 0x40uLL);
*a1 = v1;
if ( !v1 )
_assert_fail("htl->global != NULL", "src/htlock.c", 0x38u, "create_htlock");
v2 = malloc(0x40uLL);
a1[1] = v2;
v2[1] = 128;
*v2 = 0;
v1[1] = 0;
*v1 = 0;
_mm_mfence();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
_DWORD *v1; // rbx
_DWORD *v2; // rax

if ( !a1 )
_assert_fail("htl != NULL", "src/htlock.c", 0x31u, "create_htlock");
v1 = memalign(0x40uLL, 0x40uLL);
*a1 = v1;
if ( !v1 )
_assert_fail("htl->global != NULL", "src/htlock.c", 0x38u, "create_htlock");
v2 = malloc(0x40uLL);
a1[1] = v2;
v2[1] = 128;
*v2 = 0;
v1[1] = 0;
*v1 = 0;
_mm_mfence();
return 0LL;
}

original_code:
int create_htlock(htlock_t* htl)
{
    ((void) sizeof ((htl != ((void *)0)) ? 1 : 0), __extension__ ({ if (htl != ((void *)0)) ; else __assert_fail ("htl != NULL", "src/htlock.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    htl->global = memalign(64, sizeof(htlock_global_t));
    if (htl == ((void *)0))
    {
        fprintf(stderr,"Error @ memalign : create htlock\n");
     }
    ((void) sizeof ((htl->global != ((void *)0)) ? 1 : 0), __extension__ ({ if (htl->global != ((void *)0)) ; else __assert_fail ("htl->global != NULL", "src/htlock.c", 56, __extension__ __PRETTY_FUNCTION__); }));
    uint32_t s;
    for (s = 0; s < 1; s++)
    {
        htl->local[s] = (htlock_local_t*) malloc(sizeof(htlock_local_t));
        htl->local[s]->cur = 128;
        htl->local[s]->nxt = 0;
        ((void) sizeof ((htl->local != ((void *)0)) ? 1 : 0), __extension__ ({ if (htl->local != ((void *)0)) ; else __assert_fail ("htl->local != NULL", "src/htlock.c", 69, __extension__ __PRETTY_FUNCTION__); }));
    }
    htl->global->cur = 0;
    htl->global->nxt = 0;
    __sync_synchronize();
    return 0;
}

canonical_original_code:
int create_htlock(struct htlock *htl)
{
    ((void) sizeof ((htl != ((void *)0)) ? 1 : 0), __extension__ ({ if (htl != ((void *)0)) ; else __assert_fail ("htl != NULL", "src/htlock.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    htl->global = memalign(64, sizeof(htlock_global_t));
    if (htl == ((void *)0))
    {
        fprintf(stderr,"Error @ memalign : create htlock\n");
     }
    ((void) sizeof ((htl->global != ((void *)0)) ? 1 : 0), __extension__ ({ if (htl->global != ((void *)0)) ; else __assert_fail ("htl->global != NULL", "src/htlock.c", 56, __extension__ __PRETTY_FUNCTION__); }));
    unsigned int s;
    for (s = 0; s < 1; s++)
    {
        htl->local[s] = (struct htlock_local *) malloc(sizeof(htlock_local_t));
        htl->local[s]->cur = 128;
        htl->local[s]->nxt = 0;
        ((void) sizeof ((htl->local != ((void *)0)) ? 1 : 0), __extension__ ({ if (htl->local != ((void *)0)) ; else __assert_fail ("htl->local != NULL", "src/htlock.c", 69, __extension__ __PRETTY_FUNCTION__); }));
    }
    htl->global->cur = 0;
    htl->global->nxt = 0;
    __sync_synchronize();
    return 0;
}

variable_types: struct htlock { struct htlock_global { unsigned int nxt; unsigned int cur; unsigned char padding[-1]; } *global; struct htlock_local { int nxt; int cur; unsigned char padding[-1]; } *local[1]; } *

variable_types:
s
unsigned int

user_defined_types: struct htlock { struct htlock_global *global; struct htlock_local *local[1]; }


decompiled_code:
__int64 __fastcall init_thread_htlocks(unsigned int a1)
{
__int64 result; // rax

set_cpu(a1);
__writefsdword((unsigned int)&htlock_id_mine, a1);
result = get_cluster(a1);
__writefsdword((unsigned int)&htlock_node_mine, result);
_mm_mfence();
return result;
}

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

func4(a1);
__writefsdword((unsigned int)&htlock_id_mine, a1);
result = func0(a1);
__writefsdword((unsigned int)&htlock_node_mine, result);
_mm_mfence();
return result;
}

original_code:
void
init_thread_htlocks(uint32_t phys_core)
{
    set_cpu(phys_core);
    htlock_id_mine = phys_core;
    htlock_node_mine = get_cluster(phys_core);
    __sync_synchronize();
}

canonical_original_code:
void init_thread_htlocks(unsigned int phys_core)
{
    set_cpu(phys_core);
    htlock_id_mine = phys_core;
    htlock_node_mine = get_cluster(phys_core);
    __sync_synchronize();
}