execute

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

m2ACD_systemInit();
LABEL_24:
while ( 1 )
{
result = m2C65();
if ( quit )
return result;
LDX_IMMED(58LL);
LDY_IMMED(44LL);
m1A26();
LDA_IMMED(0LL);
STA_ZEROP(139LL);
LDA_IMMED(100LL);
STA_ZEROP(140LL);
while ( 1 )
{
PollMessages();
LDX_IMMED(207LL);
LDY_IMMED(255LL);
LDA_IMMED(129LL);
osbyte();
CPY_IMMED(0LL);
if ( (r6502_ps & 2) == 0 )
{
LDA_IMMED(1LL);
goto LABEL_3;
}
LDX_IMMED(206LL);
LDY_IMMED(255LL);
LDA_IMMED(129LL);
osbyte();
CPY_IMMED(0LL);
if ( (r6502_ps & 2) == 0 )
{
LDA_IMMED(2LL);
goto LABEL_3;
}
LDX_IMMED(238LL);
LDY_IMMED(255LL);
LDA_IMMED(129LL);
osbyte();
CPY_IMMED(0LL);
if ( (r6502_ps & 2) == 0 )
{
LDA_IMMED(3LL);
goto LABEL_3;
}
LDX_IMMED(237LL);
LDY_IMMED(255LL);
LDA_IMMED(129LL);
osbyte();
CPY_IMMED(0LL);
if ( (r6502_ps & 2) == 0 )
break;
DEC_ZEROP(139LL);
if ( (r6502_ps & 2) != 0 )
{
delay(32LL);
DEC_ZEROP(140LL);
if ( (r6502_ps & 2) != 0 )
{
PLA();
PLA();
goto LABEL_24;
}
}
}
LDA_IMMED(4LL);
LABEL_3:
STA_ZEROP(94LL);
STA_ZEROP(95LL);
CLC();
ADC_IMMED(48LL);
oswrch();
LDA_IMMED(5LL);
m2C54();
m2BF6();
LABEL_18:
LDX_IMMED(168LL);
LDY_IMMED(42LL);
m1A26();
LDX_IMMED(191LL);
LDY_IMMED(42LL);
m1A26();
LDA_ZEROP(93LL);
CLC();
ADC_IMMED(49LL);
oswrch();
LDA_IMMED(20LL);
m2C54();
LABEL_19:
m2DC0();
m1B33();
m2E92();
while ( 1 )
{
m1A3B();
m1E63();
m3338();
m2374();
m2407();
m2F49();
m2728();
m1B10();
LDA_ZEROP(79LL);
if ( (r6502_ps & 2) == 0 )
break;
LDA_ZEROP(65LL);
CMP_IMMED(17LL);
if ( (r6502_ps & 1) == 0 )
break;
LDA_ZEROP(57LL);
if ( (r6502_ps & 2) != 0 )
{
LDA_ZEROP(61LL);
while ( (r6502_ps & 2) != 0 )
{
LDA_IMMED(1LL);
LDX_IMMED(6LL);
m1AB5();
m26DC();
m2F49();
LDA_ZEROP(60LL);
if ( (r6502_ps & 2) != 0 || (CMP_IMMED(5LL), (r6502_ps & 2) != 0) )
{
LDX_IMMED(176LL);
LDY_IMMED(12LL);
LDA_IMMED(7LL);
osword();
delay(50 * (unsigned int)memory[1627]);
PollMessages();
}
LDA_ZEROP(61LL);
}
INC_ZEROP(80LL);
m2E6B();
m2DFE();
m2E2D();
goto LABEL_19;
}
LDA_ZEROP(96LL);
if ( r6502_ps < 0 )
goto LABEL_24;
}
m2E6B();
LDX_IMMED(166LL);
LDY_IMMED(47LL);
m2F7C();
LDX_ZEROP(93LL);
DEC_ZEROX(32LL);
if ( (r6502_ps & 2) != 0 )
{
LDX_IMMED(138LL);
LDY_IMMED(42LL);
m1A26();
LDX_IMMED(191LL);
LDY_IMMED(42LL);
m1A26();
LDA_ZEROP(93LL);
CLC();
ADC_IMMED(49LL);
oswrch();
LDA_IMMED(10LL);
m2C54();
m28BE();
LDA_IMMED(5LL);
m2C54();
DEC_ZEROP(95LL);
if ( (r6502_ps & 2) != 0 )
continue;
}
do
{
do
{
LDX_ZEROP(93LL);
INX();
TXA();
AND_IMMED(3LL);
STA_ZEROP(93LL);
CMP_ZEROP(94LL);
}
while ( (r6502_ps & 1) != 0 );
TAX();
LDA_ZEROX(32LL);
}
while ( (r6502_ps & 2) != 0 );
m2E2D();
goto LABEL_18;
}
}

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

m2ACD_systemInit();
LABEL_24:
while ( 1 )
{
result = m2C65();
if ( quit )
return result;
LDX_IMMED(58LL);
LDY_IMMED(44LL);
m1A26();
LDA_IMMED(0LL);
STA_ZEROP(139LL);
LDA_IMMED(100LL);
STA_ZEROP(140LL);
while ( 1 )
{
PollMessages();
LDX_IMMED(207LL);
LDY_IMMED(255LL);
LDA_IMMED(129LL);
osbyte();
CPY_IMMED(0LL);
if ( (r6502_ps & 2) == 0 )
{
LDA_IMMED(1LL);
goto LABEL_3;
}
LDX_IMMED(206LL);
LDY_IMMED(255LL);
LDA_IMMED(129LL);
osbyte();
CPY_IMMED(0LL);
if ( (r6502_ps & 2) == 0 )
{
LDA_IMMED(2LL);
goto LABEL_3;
}
LDX_IMMED(238LL);
LDY_IMMED(255LL);
LDA_IMMED(129LL);
osbyte();
CPY_IMMED(0LL);
if ( (r6502_ps & 2) == 0 )
{
LDA_IMMED(3LL);
goto LABEL_3;
}
LDX_IMMED(237LL);
LDY_IMMED(255LL);
LDA_IMMED(129LL);
osbyte();
CPY_IMMED(0LL);
if ( (r6502_ps & 2) == 0 )
break;
DEC_ZEROP(139LL);
if ( (r6502_ps & 2) != 0 )
{
delay(32LL);
DEC_ZEROP(140LL);
if ( (r6502_ps & 2) != 0 )
{
PLA();
PLA();
goto LABEL_24;
}
}
}
LDA_IMMED(4LL);
LABEL_3:
STA_ZEROP(94LL);
STA_ZEROP(95LL);
CLC();
ADC_IMMED(48LL);
oswrch();
LDA_IMMED(5LL);
m2C54();
m2BF6();
LABEL_18:
LDX_IMMED(168LL);
LDY_IMMED(42LL);
m1A26();
LDX_IMMED(191LL);
LDY_IMMED(42LL);
m1A26();
LDA_ZEROP(93LL);
CLC();
ADC_IMMED(49LL);
oswrch();
LDA_IMMED(20LL);
m2C54();
LABEL_19:
m2DC0();
m1B33();
m2E92();
while ( 1 )
{
m1A3B();
m1E63();
m3338();
m2374();
m2407();
m2F49();
m2728();
m1B10();
LDA_ZEROP(79LL);
if ( (r6502_ps & 2) == 0 )
break;
LDA_ZEROP(65LL);
CMP_IMMED(17LL);
if ( (r6502_ps & 1) == 0 )
break;
LDA_ZEROP(57LL);
if ( (r6502_ps & 2) != 0 )
{
LDA_ZEROP(61LL);
while ( (r6502_ps & 2) != 0 )
{
LDA_IMMED(1LL);
LDX_IMMED(6LL);
m1AB5();
m26DC();
m2F49();
LDA_ZEROP(60LL);
if ( (r6502_ps & 2) != 0 || (CMP_IMMED(5LL), (r6502_ps & 2) != 0) )
{
LDX_IMMED(176LL);
LDY_IMMED(12LL);
LDA_IMMED(7LL);
osword();
delay(50 * (unsigned int)memory[1627]);
PollMessages();
}
LDA_ZEROP(61LL);
}
INC_ZEROP(80LL);
m2E6B();
m2DFE();
m2E2D();
goto LABEL_19;
}
LDA_ZEROP(96LL);
if ( r6502_ps < 0 )
goto LABEL_24;
}
m2E6B();
LDX_IMMED(166LL);
LDY_IMMED(47LL);
m2F7C();
LDX_ZEROP(93LL);
DEC_ZEROX(32LL);
if ( (r6502_ps & 2) != 0 )
{
LDX_IMMED(138LL);
LDY_IMMED(42LL);
m1A26();
LDX_IMMED(191LL);
LDY_IMMED(42LL);
m1A26();
LDA_ZEROP(93LL);
CLC();
ADC_IMMED(49LL);
oswrch();
LDA_IMMED(10LL);
m2C54();
m28BE();
LDA_IMMED(5LL);
m2C54();
DEC_ZEROP(95LL);
if ( (r6502_ps & 2) != 0 )
continue;
}
do
{
do
{
LDX_ZEROP(93LL);
INX();
TXA();
AND_IMMED(3LL);
STA_ZEROP(93LL);
CMP_ZEROP(94LL);
}
while ( (r6502_ps & 1) != 0 );
TAX();
LDA_ZEROX(32LL);
}
while ( (r6502_ps & 2) != 0 );
m2E2D();
goto LABEL_18;
}
}

original_code:
void execute(void)
{
 int duration;
  m2ACD_systemInit();
m29AE:
  m2C65();
  if (quit)
    return;
  _LDX_IMMED(0x3A);
  _LDY_IMMED(0x2C);
  m1A26();
  _LDA_IMMED(0x00);
  _STA_ZEROP(0x8B);
  _LDA_IMMED(0x64);
  _STA_ZEROP(0x8C);
m2B92:
  PollMessages();
  _LDX_IMMED(0xCF);
  _LDY_IMMED(0xFF);
  _LDA_IMMED(0x81);
  osbyte();
  _CPY_IMMED(0x00);
  if (r6502_ps & 0x02) goto m2BA4;
  _LDA_IMMED(0x01);
  goto m2BE7;
m2BA4:
  _LDX_IMMED(0xCE);
  _LDY_IMMED(0xFF);
  _LDA_IMMED(0x81);
  osbyte();
  _CPY_IMMED(0x00);
  if (r6502_ps & 0x02) goto m2BB6;
  _LDA_IMMED(0x02);
  goto m2BE7;
m2BB6:
  _LDX_IMMED(0xEE);
  _LDY_IMMED(0xFF);
  _LDA_IMMED(0x81);
  osbyte();
  _CPY_IMMED(0x00);
  if (r6502_ps & 0x02) goto m2BC8;
  _LDA_IMMED(0x03);
  goto m2BE7;
m2BC8:
  _LDX_IMMED(0xED);
  _LDY_IMMED(0xFF);
  _LDA_IMMED(0x81);
  osbyte();
  _CPY_IMMED(0x00);
  if (r6502_ps & 0x02) goto m2BDA;
  _LDA_IMMED(0x04);
  goto m2BE7;
m2BDA:
  _DEC_ZEROP(0x8B);
  if (!(r6502_ps & 0x02)) goto m2B92;
  delay(32);
  _DEC_ZEROP(0x8C);
  if (!(r6502_ps & 0x02)) goto m2B92;
  _PLA();
  _PLA();
  goto m29AE;
m2BE7:
  _STA_ZEROP(0x5E);
  _STA_ZEROP(0x5F);
  _CLC();
  _ADC_IMMED(0x30);
  oswrch();
  _LDA_IMMED(0x05);
  m2C54();
  m2BF6();
m29B4:
  _LDX_IMMED(0xA8);
  _LDY_IMMED(0x2A);
  m1A26();
  _LDX_IMMED(0xBF);
  _LDY_IMMED(0x2A);
  m1A26();
  _LDA_ZEROP(0x5D);
  _CLC();
  _ADC_IMMED(0x31);
  oswrch();
  _LDA_IMMED(0x14);
  m2C54();
m29CF:
  m2DC0();
  m1B33();
  m2E92();
m29D8:
  m1A3B();
  m1E63();
  m3338();
  m2374();
  m2407();
  m2F49();
  m2728();
  m1B10();
  _LDA_ZEROP(0x4F);
  if (!(r6502_ps & 0x02)) goto m2A39;
  _LDA_ZEROP(0x41);
  _CMP_IMMED(0x11);
  if (!(r6502_ps & 0x01)) goto m2A39;
  _LDA_ZEROP(0x39);
  if (r6502_ps & 0x02) goto m2A05;
  _LDA_ZEROP(0x60);
  if (r6502_ps & 0x80) goto m29AE;
  goto m29D8;
m2A05:
  _LDA_ZEROP(0x3D);
  if (!(r6502_ps & 0x02)) goto m2A2B;
m2A09:
  _LDA_IMMED(0x01);
  _LDX_IMMED(0x06);
  m1AB5();
  m26DC();
  m2F49();
  _LDA_ZEROP(0x3C);
  if (r6502_ps & 0x02) goto m2A1E;
  _CMP_IMMED(0x05);
  if (!(r6502_ps & 0x02)) goto m2A27;
m2A1E:
  _LDX_IMMED(0xB0);
  _LDY_IMMED(0x0C);
  _LDA_IMMED(0x07);
  osword();
  duration = ((memory[0x0CB7] << 8) | memory[0x0CB6]);
  delay((duration*1000)/20);
  PollMessages();
m2A27:
  _LDA_ZEROP(0x3D);
  if (r6502_ps & 0x02) goto m2A09;
m2A2B:
  _INC_ZEROP(0x50);
  m2E6B();
  m2DFE();
  m2E2D();
  goto m29CF;
m2A39:
  m2E6B();
  _LDX_IMMED(0xA6);
  _LDY_IMMED(0x2F);
  m2F7C();
  _LDX_ZEROP(0x5D);
  _DEC_ZEROX(0x20);
  if (!(r6502_ps & 0x02)) goto m2A70;
  _LDX_IMMED(0x8A);
  _LDY_IMMED(0x2A);
  m1A26();
  _LDX_IMMED(0xBF);
  _LDY_IMMED(0x2A);
  m1A26();
  _LDA_ZEROP(0x5D);
  _CLC();
  _ADC_IMMED(0x31);
  oswrch();
  _LDA_IMMED(0x0A);
  m2C54();
  m28BE();
  _LDA_IMMED(0x05);
  m2C54();
  _DEC_ZEROP(0x5F);
  if (r6502_ps & 0x02) goto m2A87;
m2A70:
  _LDX_ZEROP(0x5D);
  _INX();
  _TXA();
  _AND_IMMED(0x03);
  _STA_ZEROP(0x5D);
  _CMP_ZEROP(0x5E);
  if (r6502_ps & 0x01) goto m2A70;
  _TAX();
  _LDA_ZEROX(0x20);
  if (r6502_ps & 0x02) goto m2A70;
  m2E2D();
  goto m29B4;
m2A87:
  goto m29AE;
}

canonical_original_code:
void execute()
{
 int duration;
  m2ACD_systemInit();
m29AE:
  m2C65();
  if (quit)
    return;
  _LDX_IMMED(0x3A);
  _LDY_IMMED(0x2C);
  m1A26();
  _LDA_IMMED(0x00);
  _STA_ZEROP(0x8B);
  _LDA_IMMED(0x64);
  _STA_ZEROP(0x8C);
m2B92:
  PollMessages();
  _LDX_IMMED(0xCF);
  _LDY_IMMED(0xFF);
  _LDA_IMMED(0x81);
  osbyte();
  _CPY_IMMED(0x00);
  if (r6502_ps & 0x02) goto m2BA4;
  _LDA_IMMED(0x01);
  goto m2BE7;
m2BA4:
  _LDX_IMMED(0xCE);
  _LDY_IMMED(0xFF);
  _LDA_IMMED(0x81);
  osbyte();
  _CPY_IMMED(0x00);
  if (r6502_ps & 0x02) goto m2BB6;
  _LDA_IMMED(0x02);
  goto m2BE7;
m2BB6:
  _LDX_IMMED(0xEE);
  _LDY_IMMED(0xFF);
  _LDA_IMMED(0x81);
  osbyte();
  _CPY_IMMED(0x00);
  if (r6502_ps & 0x02) goto m2BC8;
  _LDA_IMMED(0x03);
  goto m2BE7;
m2BC8:
  _LDX_IMMED(0xED);
  _LDY_IMMED(0xFF);
  _LDA_IMMED(0x81);
  osbyte();
  _CPY_IMMED(0x00);
  if (r6502_ps & 0x02) goto m2BDA;
  _LDA_IMMED(0x04);
  goto m2BE7;
m2BDA:
  _DEC_ZEROP(0x8B);
  if (!(r6502_ps & 0x02)) goto m2B92;
  delay(32);
  _DEC_ZEROP(0x8C);
  if (!(r6502_ps & 0x02)) goto m2B92;
  _PLA();
  _PLA();
  goto m29AE;
m2BE7:
  _STA_ZEROP(0x5E);
  _STA_ZEROP(0x5F);
  _CLC();
  _ADC_IMMED(0x30);
  oswrch();
  _LDA_IMMED(0x05);
  m2C54();
  m2BF6();
m29B4:
  _LDX_IMMED(0xA8);
  _LDY_IMMED(0x2A);
  m1A26();
  _LDX_IMMED(0xBF);
  _LDY_IMMED(0x2A);
  m1A26();
  _LDA_ZEROP(0x5D);
  _CLC();
  _ADC_IMMED(0x31);
  oswrch();
  _LDA_IMMED(0x14);
  m2C54();
m29CF:
  m2DC0();
  m1B33();
  m2E92();
m29D8:
  m1A3B();
  m1E63();
  m3338();
  m2374();
  m2407();
  m2F49();
  m2728();
  m1B10();
  _LDA_ZEROP(0x4F);
  if (!(r6502_ps & 0x02)) goto m2A39;
  _LDA_ZEROP(0x41);
  _CMP_IMMED(0x11);
  if (!(r6502_ps & 0x01)) goto m2A39;
  _LDA_ZEROP(0x39);
  if (r6502_ps & 0x02) goto m2A05;
  _LDA_ZEROP(0x60);
  if (r6502_ps & 0x80) goto m29AE;
  goto m29D8;
m2A05:
  _LDA_ZEROP(0x3D);
  if (!(r6502_ps & 0x02)) goto m2A2B;
m2A09:
  _LDA_IMMED(0x01);
  _LDX_IMMED(0x06);
  m1AB5();
  m26DC();
  m2F49();
  _LDA_ZEROP(0x3C);
  if (r6502_ps & 0x02) goto m2A1E;
  _CMP_IMMED(0x05);
  if (!(r6502_ps & 0x02)) goto m2A27;
m2A1E:
  _LDX_IMMED(0xB0);
  _LDY_IMMED(0x0C);
  _LDA_IMMED(0x07);
  osword();
  duration = ((memory[0x0CB7] << 8) | memory[0x0CB6]);
  delay((duration*1000)/20);
  PollMessages();
m2A27:
  _LDA_ZEROP(0x3D);
  if (r6502_ps & 0x02) goto m2A09;
m2A2B:
  _INC_ZEROP(0x50);
  m2E6B();
  m2DFE();
  m2E2D();
  goto m29CF;
m2A39:
  m2E6B();
  _LDX_IMMED(0xA6);
  _LDY_IMMED(0x2F);
  m2F7C();
  _LDX_ZEROP(0x5D);
  _DEC_ZEROX(0x20);
  if (!(r6502_ps & 0x02)) goto m2A70;
  _LDX_IMMED(0x8A);
  _LDY_IMMED(0x2A);
  m1A26();
  _LDX_IMMED(0xBF);
  _LDY_IMMED(0x2A);
  m1A26();
  _LDA_ZEROP(0x5D);
  _CLC();
  _ADC_IMMED(0x31);
  oswrch();
  _LDA_IMMED(0x0A);
  m2C54();
  m28BE();
  _LDA_IMMED(0x05);
  m2C54();
  _DEC_ZEROP(0x5F);
  if (r6502_ps & 0x02) goto m2A87;
m2A70:
  _LDX_ZEROP(0x5D);
  _INX();
  _TXA();
  _AND_IMMED(0x03);
  _STA_ZEROP(0x5D);
  _CMP_ZEROP(0x5E);
  if (r6502_ps & 0x01) goto m2A70;
  _TAX();
  _LDA_ZEROX(0x20);
  if (r6502_ps & 0x02) goto m2A70;
  m2E2D();
  goto m29B4;
m2A87:
  goto m29AE;
}

variable_types: duration int


decompiled_code:
__int64 __fastcall read_byte(int a1)
{
int v1; // eax
__int64 result; // rax
int v3; // eax

printf("Reading byte from %d\n", (unsigned int)a1);
v1 = a1 & 0xF000;
if ( v1 == 40960 )
return read_memory_8(eram, a1 & 0x1FFF);
if ( (a1 & 0xF000u) > 0xA000 )
{
if ( v1 == 57344 )
return read_memory_8(wram, a1 & 0x1FFF);
if ( (a1 & 0xF000u) > 0xE000 )
{
if ( v1 != 61440 )
return 0LL;
v3 = a1 & 0xF00;
if ( v3 == 3584 )
{
LOBYTE(v3) = a1 <= 65183;
return (unsigned int)-v3;
}
if ( (a1 & 0xF00u) > 0xE00 )
{
if ( v3 != 3840 )
return 0LL;
result = 0LL;
if ( a1 > 65407 )
result = read_memory_8(zram, a1 & 0x7F);
return result;
}
if ( v3 != 1792 )
{
if ( (a1 & 0xF00u) <= 0x700 )
{
if ( v3 != 768 )
{
if ( (a1 & 0xF00u) <= 0x300 )
{
if ( v3 != 512 )
{
result = 0LL;
if ( (a1 & 0xE00) != 0 )
return result;
}
}
else if ( v3 != 1536 && (a1 & 0xE00) != 1024 )
{
return 0LL;
}
}
}
else if ( v3 != 2816 )
{
if ( (a1 & 0xF00u) <= 0xB00 )
{
if ( v3 != 2560 && (a1 & 0xE00) != 2048 )
return 0LL;
}
else if ( (a1 & 0xE00) != 3072 )
{
return 0LL;
}
}
}
return read_memory_8(wram, a1 & 0x1FFF);
}
if ( (a1 & 0xE000) == 49152 )
return read_memory_8(wram, a1 & 0x1FFF);
if ( v1 != 45056 )
return 0LL;
return read_memory_8(eram, a1 & 0x1FFF);
}
if ( v1 == 0x4000 )
return read_memory_8(rom, ROM_OFFS + (a1 & 0x3FFFu));
if ( (a1 & 0xF000u) <= 0x4000 )
{
if ( v1 != 4096 )
{
if ( (a1 & 0xF000u) <= 0x1000 )
{
if ( (a1 & 0xF000) != 0 )
return 0LL;
if ( !IN_BIOS )
{
puts("Reading from rom");
return read_memory_8(rom, (unsigned int)a1);
}
if ( a1 <= 255 )
return read_memory_8(bios, (unsigned int)a1);
if ( *(_WORD *)(state + 24LL) == 256 )
{
IN_BIOS = 0;
puts("Leaving BIOS.");
}
}
else if ( (a1 & 0xE000) != 0x2000 )
{
return 0LL;
}
}
return read_memory_8(rom, (unsigned int)a1);
}
if ( v1 == 0x8000 )
return read_memory_8(vram, a1 & 0x1FFF);
if ( (a1 & 0xF000u) <= 0x8000 )
{
if ( v1 != 24576 && (a1 & 0xD000) != 20480 )
return 0LL;
return read_memory_8(rom, ROM_OFFS + (a1 & 0x3FFFu));
}
if ( v1 == 36864 )
return read_memory_8(vram, a1 & 0x1FFF);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // eax
__int64 result; // rax
int v3; // eax

printf("Reading byte from %d\n", (unsigned int)a1);
v1 = a1 & 0xF000;
if ( v1 == 40960 )
return read_memory_8(eram, a1 & 0x1FFF);
if ( (a1 & 0xF000u) > 0xA000 )
{
if ( v1 == 57344 )
return read_memory_8(wram, a1 & 0x1FFF);
if ( (a1 & 0xF000u) > 0xE000 )
{
if ( v1 != 61440 )
return 0LL;
v3 = a1 & 0xF00;
if ( v3 == 3584 )
{
LOBYTE(v3) = a1 <= 65183;
return (unsigned int)-v3;
}
if ( (a1 & 0xF00u) > 0xE00 )
{
if ( v3 != 3840 )
return 0LL;
result = 0LL;
if ( a1 > 65407 )
result = read_memory_8(zram, a1 & 0x7F);
return result;
}
if ( v3 != 1792 )
{
if ( (a1 & 0xF00u) <= 0x700 )
{
if ( v3 != 768 )
{
if ( (a1 & 0xF00u) <= 0x300 )
{
if ( v3 != 512 )
{
result = 0LL;
if ( (a1 & 0xE00) != 0 )
return result;
}
}
else if ( v3 != 1536 && (a1 & 0xE00) != 1024 )
{
return 0LL;
}
}
}
else if ( v3 != 2816 )
{
if ( (a1 & 0xF00u) <= 0xB00 )
{
if ( v3 != 2560 && (a1 & 0xE00) != 2048 )
return 0LL;
}
else if ( (a1 & 0xE00) != 3072 )
{
return 0LL;
}
}
}
return read_memory_8(wram, a1 & 0x1FFF);
}
if ( (a1 & 0xE000) == 49152 )
return read_memory_8(wram, a1 & 0x1FFF);
if ( v1 != 45056 )
return 0LL;
return read_memory_8(eram, a1 & 0x1FFF);
}
if ( v1 == 0x4000 )
return read_memory_8(rom, ROM_OFFS + (a1 & 0x3FFFu));
if ( (a1 & 0xF000u) <= 0x4000 )
{
if ( v1 != 4096 )
{
if ( (a1 & 0xF000u) <= 0x1000 )
{
if ( (a1 & 0xF000) != 0 )
return 0LL;
if ( !IN_BIOS )
{
puts("Reading from rom");
return read_memory_8(rom, (unsigned int)a1);
}
if ( a1 <= 255 )
return read_memory_8(bios, (unsigned int)a1);
if ( *(_WORD *)(state + 24LL) == 256 )
{
IN_BIOS = 0;
puts("Leaving BIOS.");
}
}
else if ( (a1 & 0xE000) != 0x2000 )
{
return 0LL;
}
}
return read_memory_8(rom, (unsigned int)a1);
}
if ( v1 == 0x8000 )
return read_memory_8(vram, a1 & 0x1FFF);
if ( (a1 & 0xF000u) <= 0x8000 )
{
if ( v1 != 24576 && (a1 & 0xD000) != 20480 )
return 0LL;
return read_memory_8(rom, ROM_OFFS + (a1 & 0x3FFFu));
}
if ( v1 == 36864 )
return read_memory_8(vram, a1 & 0x1FFF);
return 0LL;
}

original_code:
uint8_t read_byte(int addr)
{
 printf("Reading byte from %d\n", addr);
 switch(addr & 0xF000)
 {
  case 0x0000:
   if (IN_BIOS) {
    if (addr < 0x0100)
     return read_memory_8(bios, addr);
    else if (state->Reg.pc == 0x0100) {
     IN_BIOS = 0;
     printf("Leaving BIOS.\n");
    }
   } else {
    printf("Reading from rom\n");
    return read_memory_8(rom, addr);
   }
  case 0x1000:
  case 0x2000:
  case 0x3000:
   return read_memory_8(rom, addr);
  case 0x4000:
  case 0x5000:
  case 0x6000:
  case 0x7000:
   return read_memory_8(rom, ROM_OFFS + (addr & 0x3FFF));
  case 0x8000:
  case 0x9000:
   return read_memory_8(vram, addr & 0x1FFF);
  case 0xA000:
  case 0xB000:
   return read_memory_8(eram, addr & 0x1FFF);
  case 0xC000:
  case 0xD000:
   return read_memory_8(wram, addr & 0x1FFF);
  case 0xE000:
   return read_memory_8(wram, addr & 0x1FFF);
  case 0xF000:
   switch(addr &0x0F00){
    case 0x000:
    case 0x100:
    case 0x200:
    case 0x300:
    case 0x400:
    case 0x500:
    case 0x600:
    case 0x700:
    case 0x800:
    case 0x900:
    case 0xA00:
    case 0xB00:
    case 0xC00:
    case 0xD00:
     return read_memory_8(wram, addr & 0x1FFF);
    case 0xE00:
     if (addr < 0xFEA0){
      return -1;
     } else {
      return 0;
     }
    case 0xF00:
     if (addr >= 0xFF80) {
      return read_memory_8(zram, addr & 0x7F);
     } else {
      return 0;
     }
   }
 }
 return 0;
}

canonical_original_code:
unsigned char read_byte(int addr)
{
 printf("Reading byte from %d\n", addr);
 switch(addr & 0xF000)
 {
  case 0x0000:
   if (IN_BIOS) {
    if (addr < 0x0100)
     return read_memory_8(bios, addr);
    else if (state->Reg.pc == 0x0100) {
     IN_BIOS = 0;
     printf("Leaving BIOS.\n");
    }
   } else {
    printf("Reading from rom\n");
    return read_memory_8(rom, addr);
   }
  case 0x1000:
  case 0x2000:
  case 0x3000:
   return read_memory_8(rom, addr);
  case 0x4000:
  case 0x5000:
  case 0x6000:
  case 0x7000:
   return read_memory_8(rom, ROM_OFFS + (addr & 0x3FFF));
  case 0x8000:
  case 0x9000:
   return read_memory_8(vram, addr & 0x1FFF);
  case 0xA000:
  case 0xB000:
   return read_memory_8(eram, addr & 0x1FFF);
  case 0xC000:
  case 0xD000:
   return read_memory_8(wram, addr & 0x1FFF);
  case 0xE000:
   return read_memory_8(wram, addr & 0x1FFF);
  case 0xF000:
   switch(addr &0x0F00){
    case 0x000:
    case 0x100:
    case 0x200:
    case 0x300:
    case 0x400:
    case 0x500:
    case 0x600:
    case 0x700:
    case 0x800:
    case 0x900:
    case 0xA00:
    case 0xB00:
    case 0xC00:
    case 0xD00:
     return read_memory_8(wram, addr & 0x1FFF);
    case 0xE00:
     if (addr < 0xFEA0){
      return -1;
     } else {
      return 0;
     }
    case 0xF00:
     if (addr >= 0xFF80) {
      return read_memory_8(zram, addr & 0x7F);
     } else {
      return 0;
     }
   }
 }
 return 0;
}

variable_types: addr int

return_type: unsigned char


decompiled_code:
__int64 __fastcall read_word(unsigned int a1)
{
unsigned __int8 v1; // bp

printf("Reading word from %d\n", a1);
v1 = read_byte(a1);
return v1 + ((unsigned int)read_byte(a1 + 1) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
unsigned __int8 v1; // bp

printf("Reading word from %d\n", a1);
v1 = func0(a1);
return v1 + ((unsigned int)func0(a1 + 1) << 8);
}

original_code:
uint16_t read_word(int addr)
{
 printf("Reading word from %d\n", addr);
 return read_byte(addr) + (read_byte(addr+1) << 8);
}

canonical_original_code:
unsigned short read_word(int addr)
{
 printf("Reading word from %d\n", addr);
 return read_byte(addr) + (read_byte(addr+1) << 8);
}

return_type: unsigned short


decompiled_code:
__int64 __fastcall write_byte(int a1, unsigned __int8 a2)
{
__int64 result; // rax
unsigned __int8 v3; // al

printf("Writing %u to addr %d\n", a2, (unsigned int)a1);
result = (unsigned __int16)a1 & 0xF000;
if ( (_DWORD)result == 28672 )
{
LABEL_18:
if ( CART_TYPE == 1 )
{
result = mbc;
*(_DWORD *)(mbc + 12LL) = a2 & 1;
}
return result;
}
if ( (a1 & 0xF000u) <= 0x7000 )
{
if ( (_DWORD)result == 12288 )
goto LABEL_22;
if ( (a1 & 0xF000u) > 0x3000 )
{
if ( (_DWORD)result != 20480 )
{
if ( (_DWORD)result == 24576 )
goto LABEL_18;
if ( (_DWORD)result != 0x4000 )
return result;
}
if ( CART_TYPE == 1 )
{
if ( *(_DWORD *)(mbc + 12LL) )
{
*(_DWORD *)(mbc + 4LL) = a2 & 3;
result = (unsigned int)(*(_DWORD *)(mbc + 4LL) << 13);
RAM_OFFS = *(_WORD *)(mbc + 4LL) << 13;
}
else
{
*mbc &= 0x1Fu;
*mbc |= (32 * a2) & 0x60;
result = (unsigned int)(*mbc << 14);
ROM_OFFS = *mbc << 14;
}
}
return result;
}
if ( (_DWORD)result != 4096 )
{
if ( (_DWORD)result == 0x2000 )
{
LABEL_22:
if ( CART_TYPE == 1 )
{
*mbc &= 0x60u;
v3 = 1;
if ( (a2 & 0x1F) != 0 )
v3 = a2 & 0x1F;
*mbc |= v3;
result = (unsigned int)(*mbc << 14);
ROM_OFFS = *mbc << 14;
}
return result;
}
if ( (a1 & 0xF000) != 0 )
return result;
}
if ( CART_TYPE == 1 )
{
result = mbc;
*(_DWORD *)(mbc + 8LL) = (a2 & 0xF) == 10;
}
return result;
}
if ( (_DWORD)result == 45056 )
return add_memory_eram(RAM_OFFS + (a1 & 0x1FFFu), a2);
if ( (a1 & 0xF000u) <= 0xB000 )
{
if ( (_DWORD)result != 36864 )
{
if ( (_DWORD)result == 40960 )
return add_memory_eram(RAM_OFFS + (a1 & 0x1FFFu), a2);
if ( (_DWORD)result != 0x8000 )
return result;
}
return add_memory_vram(a1 & 0x1FFF, a2);
}
if ( (_DWORD)result != 61440 )
{
if ( (_DWORD)result != 57344 )
{
result = (unsigned __int16)a1 & 0xE000;
if ( (_DWORD)result != 49152 )
return result;
}
add_memory_wram(a1 & 0x1FFF, a2);
}
result = a1 & 0xF00;
if ( (_DWORD)result == 3584 )
{
result = (unsigned __int8)a1;
if ( (unsigned __int8)a1 <= 0x9Fu )
return result;
}
else
{
if ( (a1 & 0xF00u) <= 0xE00 )
{
if ( (_DWORD)result != 1792 )
{
if ( (a1 & 0xF00u) <= 0x700 )
{
if ( (_DWORD)result != 768 )
{
if ( (a1 & 0xF00u) <= 0x300 )
{
if ( (_DWORD)result != 512 && (a1 & 0xE00) != 0 )
return result;
}
else if ( (_DWORD)result != 1536 )
{
result = a1 & 0xE00;
if ( (_DWORD)result != 1024 )
return result;
}
}
}
else if ( (_DWORD)result != 2816 )
{
if ( (a1 & 0xF00u) <= 0xB00 )
{
if ( (_DWORD)result != 2560 )
{
result = a1 & 0xE00;
if ( (_DWORD)result != 2048 )
return result;
}
}
else
{
result = a1 & 0xE00;
if ( (_DWORD)result != 3072 )
return result;
}
}
}
return add_memory_wram(a1 & 0x1FFF, a2);
}
if ( (_DWORD)result != 3840 )
return result;
}
if ( a1 > 65407 && a1 != 0xFFFF )
result = add_memory_zram(a1 & 0x7F, a2);
return result;
}

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

printf("Writing %u to addr %d\n", a2, (unsigned int)a1);
result = (unsigned __int16)a1 & 0xF000;
if ( (_DWORD)result == 28672 )
{
LABEL_18:
if ( CART_TYPE == 1 )
{
result = mbc;
*(_DWORD *)(mbc + 12LL) = a2 & 1;
}
return result;
}
if ( (a1 & 0xF000u) <= 0x7000 )
{
if ( (_DWORD)result == 12288 )
goto LABEL_22;
if ( (a1 & 0xF000u) > 0x3000 )
{
if ( (_DWORD)result != 20480 )
{
if ( (_DWORD)result == 24576 )
goto LABEL_18;
if ( (_DWORD)result != 0x4000 )
return result;
}
if ( CART_TYPE == 1 )
{
if ( *(_DWORD *)(mbc + 12LL) )
{
*(_DWORD *)(mbc + 4LL) = a2 & 3;
result = (unsigned int)(*(_DWORD *)(mbc + 4LL) << 13);
RAM_OFFS = *(_WORD *)(mbc + 4LL) << 13;
}
else
{
*mbc &= 0x1Fu;
*mbc |= (32 * a2) & 0x60;
result = (unsigned int)(*mbc << 14);
ROM_OFFS = *mbc << 14;
}
}
return result;
}
if ( (_DWORD)result != 4096 )
{
if ( (_DWORD)result == 0x2000 )
{
LABEL_22:
if ( CART_TYPE == 1 )
{
*mbc &= 0x60u;
v3 = 1;
if ( (a2 & 0x1F) != 0 )
v3 = a2 & 0x1F;
*mbc |= v3;
result = (unsigned int)(*mbc << 14);
ROM_OFFS = *mbc << 14;
}
return result;
}
if ( (a1 & 0xF000) != 0 )
return result;
}
if ( CART_TYPE == 1 )
{
result = mbc;
*(_DWORD *)(mbc + 8LL) = (a2 & 0xF) == 10;
}
return result;
}
if ( (_DWORD)result == 45056 )
return add_memory_eram(RAM_OFFS + (a1 & 0x1FFFu), a2);
if ( (a1 & 0xF000u) <= 0xB000 )
{
if ( (_DWORD)result != 36864 )
{
if ( (_DWORD)result == 40960 )
return add_memory_eram(RAM_OFFS + (a1 & 0x1FFFu), a2);
if ( (_DWORD)result != 0x8000 )
return result;
}
return add_memory_vram(a1 & 0x1FFF, a2);
}
if ( (_DWORD)result != 61440 )
{
if ( (_DWORD)result != 57344 )
{
result = (unsigned __int16)a1 & 0xE000;
if ( (_DWORD)result != 49152 )
return result;
}
add_memory_wram(a1 & 0x1FFF, a2);
}
result = a1 & 0xF00;
if ( (_DWORD)result == 3584 )
{
result = (unsigned __int8)a1;
if ( (unsigned __int8)a1 <= 0x9Fu )
return result;
}
else
{
if ( (a1 & 0xF00u) <= 0xE00 )
{
if ( (_DWORD)result != 1792 )
{
if ( (a1 & 0xF00u) <= 0x700 )
{
if ( (_DWORD)result != 768 )
{
if ( (a1 & 0xF00u) <= 0x300 )
{
if ( (_DWORD)result != 512 && (a1 & 0xE00) != 0 )
return result;
}
else if ( (_DWORD)result != 1536 )
{
result = a1 & 0xE00;
if ( (_DWORD)result != 1024 )
return result;
}
}
}
else if ( (_DWORD)result != 2816 )
{
if ( (a1 & 0xF00u) <= 0xB00 )
{
if ( (_DWORD)result != 2560 )
{
result = a1 & 0xE00;
if ( (_DWORD)result != 2048 )
return result;
}
}
else
{
result = a1 & 0xE00;
if ( (_DWORD)result != 3072 )
return result;
}
}
}
return add_memory_wram(a1 & 0x1FFF, a2);
}
if ( (_DWORD)result != 3840 )
return result;
}
if ( a1 > 65407 && a1 != 0xFFFF )
result = add_memory_zram(a1 & 0x7F, a2);
return result;
}

original_code:
void write_byte(int addr, uint8_t val)
{
 printf("Writing %u to addr %d\n", val, addr);
 switch(addr & 0xF000) {
  case 0x0000:
  case 0x1000:
   switch(CART_TYPE) {
    case 1:
     mbc->ramOn = ((val & 0xF) == 0xA) ? 1 : 0;
     break;
   }
   break;
  case 0x2000:
  case 0x3000:
   switch(CART_TYPE) {
    case 1:
     mbc->romBank &= 0x60;
     val &= 0x1F;
     if (!val)
      val = 1;
     mbc->romBank |= val;
     ROM_OFFS = mbc->romBank * 0x4000;
     break;
   }
   break;
  case 0x4000:
  case 0x5000:
   switch(CART_TYPE) {
    case 1:
     if (mbc->mode) {
      mbc->ramBank = val & 3;
      RAM_OFFS = mbc->ramBank * 0x2000;
     } else {
      mbc->romBank &= 0x1F;
      mbc->romBank |= ((val & 3) << 5);
      ROM_OFFS = mbc->romBank * 0x4000;
     }
   }
   break;
  case 0x6000:
  case 0x7000:
   switch(CART_TYPE) {
    case 1:
     mbc->mode = val & 1;
     break;
   }
   break;
  case 0x8000:
  case 0x9000:
   add_memory_vram(addr & 0x1FFF, val);
   break;
  case 0xA000:
  case 0xB000:
   add_memory_eram(RAM_OFFS + (addr &0x1FFF), val);
   break;
  case 0xC000:
  case 0xD000:
  case 0xE000:
   add_memory_wram(addr & 0x1FFF, val);
  case 0xF000:
   switch(addr & 0x0F00) {
    case 0x000:
    case 0x100:
    case 0x200:
    case 0x300:
    case 0x400:
    case 0x500:
    case 0x600:
    case 0x700:
    case 0x800:
    case 0x900:
    case 0xA00:
    case 0xB00:
    case 0xC00:
    case 0xD00:
     add_memory_wram(addr & 0x1FFF, val);
     break;
    case 0xE00:
     if ((addr & 0xFF) < 0xA0)
     break;
    case 0xF00:
     if (addr == 0xFFFF) {
     } else if (addr > 0xFF7F) {
      add_memory_zram(addr & 0x7F, val);
     } else {
      switch(addr & 0xF0) {
       case 0x00:
        switch(addr & 0xF) {
         case 0:
          break;
         case 4:
         case 5:
         case 6:
         case 7:
          break;
         case 15:
          break;
        }
       case 0x10:
       case 0x20:
       case 0x30:
        break;
       case 0x40:
       case 0x50:
       case 0x60:
       case 0x70:
        break;
      }
     }
     break;
   }
 }
}

canonical_original_code:
void write_byte(int addr, unsigned char val)
{
 printf("Writing %u to addr %d\n", val, addr);
 switch(addr & 0xF000) {
  case 0x0000:
  case 0x1000:
   switch(CART_TYPE) {
    case 1:
     mbc->ramOn = ((val & 0xF) == 0xA) ? 1 : 0;
     break;
   }
   break;
  case 0x2000:
  case 0x3000:
   switch(CART_TYPE) {
    case 1:
     mbc->romBank &= 0x60;
     val &= 0x1F;
     if (!val)
      val = 1;
     mbc->romBank |= val;
     ROM_OFFS = mbc->romBank * 0x4000;
     break;
   }
   break;
  case 0x4000:
  case 0x5000:
   switch(CART_TYPE) {
    case 1:
     if (mbc->mode) {
      mbc->ramBank = val & 3;
      RAM_OFFS = mbc->ramBank * 0x2000;
     } else {
      mbc->romBank &= 0x1F;
      mbc->romBank |= ((val & 3) << 5);
      ROM_OFFS = mbc->romBank * 0x4000;
     }
   }
   break;
  case 0x6000:
  case 0x7000:
   switch(CART_TYPE) {
    case 1:
     mbc->mode = val & 1;
     break;
   }
   break;
  case 0x8000:
  case 0x9000:
   add_memory_vram(addr & 0x1FFF, val);
   break;
  case 0xA000:
  case 0xB000:
   add_memory_eram(RAM_OFFS + (addr &0x1FFF), val);
   break;
  case 0xC000:
  case 0xD000:
  case 0xE000:
   add_memory_wram(addr & 0x1FFF, val);
  case 0xF000:
   switch(addr & 0x0F00) {
    case 0x000:
    case 0x100:
    case 0x200:
    case 0x300:
    case 0x400:
    case 0x500:
    case 0x600:
    case 0x700:
    case 0x800:
    case 0x900:
    case 0xA00:
    case 0xB00:
    case 0xC00:
    case 0xD00:
     add_memory_wram(addr & 0x1FFF, val);
     break;
    case 0xE00:
     if ((addr & 0xFF) < 0xA0)
     break;
    case 0xF00:
     if (addr == 0xFFFF) {
     } else if (addr > 0xFF7F) {
      add_memory_zram(addr & 0x7F, val);
     } else {
      switch(addr & 0xF0) {
       case 0x00:
        switch(addr & 0xF) {
         case 0:
          break;
         case 4:
         case 5:
         case 6:
         case 7:
          break;
         case 15:
          break;
        }
       case 0x10:
       case 0x20:
       case 0x30:
        break;
       case 0x40:
       case 0x50:
       case 0x60:
       case 0x70:
        break;
      }
     }
     break;
   }
 }
}

variable_types:
val
unsigned char

return_type: void


decompiled_code:
__int64 __fastcall write_word(unsigned int a1, __int16 a2)
{
printf("Writing word to %d\n", a1);
write_byte(a1, a2);
return write_byte(a1 + 1, HIBYTE(a2));
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int16 a2)
{
printf("Writing word to %d\n", a1);
func2(a1, a2);
return func2(a1 + 1, HIBYTE(a2));
}

original_code:
void write_word(int addr, uint16_t val)
{
 printf("Writing word to %d\n", addr);
 write_byte(addr, val & 255);
 write_byte(addr + 1, val >> 8);
}

canonical_original_code:
void write_word(int addr, unsigned short val)
{
 printf("Writing word to %d\n", addr);
 write_byte(addr, val & 255);
 write_byte(addr + 1, val >> 8);
}

variable_types:
val
unsigned short


decompiled_code:
__int64 __fastcall setup_boot(__int64 a1)
{
*(_BYTE *)(a1 + 16) = 1;
*(_BYTE *)(a1 + 23) = -80;
*(_BYTE *)(a1 + 19) = 0;
*(_BYTE *)(a1 + 20) = -40;
*(_BYTE *)(a1 + 21) = 1;
*(_BYTE *)(a1 + 22) = 77;
*(_WORD *)(a1 + 24) = 256;
*(_WORD *)(a1 + 26) = -2;
add_memory_wram(65285LL, 0LL);
add_memory_wram(65286LL, 0LL);
add_memory_wram(65287LL, 0LL);
add_memory_wram(65296LL, 128LL);
add_memory_wram(65297LL, 191LL);
add_memory_wram(65298LL, 243LL);
add_memory_wram(65300LL, 191LL);
add_memory_wram(65302LL, 63LL);
add_memory_wram(65303LL, 0LL);
add_memory_wram(65305LL, 191LL);
add_memory_wram(65306LL, 127LL);
add_memory_wram(65307LL, 255LL);
add_memory_wram(65308LL, 159LL);
add_memory_wram(65310LL, 191LL);
add_memory_wram(65312LL, 255LL);
add_memory_wram(65313LL, 0LL);
add_memory_wram(65314LL, 0LL);
add_memory_wram(65315LL, 191LL);
add_memory_wram(65316LL, 119LL);
add_memory_wram(65317LL, 243LL);
add_memory_wram(65318LL, 241LL);
add_memory_wram(65344LL, 145LL);
add_memory_wram(65346LL, 0LL);
add_memory_wram(65347LL, 0LL);
add_memory_wram(65349LL, 0LL);
add_memory_wram(65351LL, 252LL);
add_memory_wram(65352LL, 255LL);
add_memory_wram(65353LL, 255LL);
add_memory_wram(65354LL, 0LL);
add_memory_wram(65355LL, 0LL);
return add_memory_wram(0xFFFFLL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
*(_BYTE *)(a1 + 16) = 1;
*(_BYTE *)(a1 + 23) = -80;
*(_BYTE *)(a1 + 19) = 0;
*(_BYTE *)(a1 + 20) = -40;
*(_BYTE *)(a1 + 21) = 1;
*(_BYTE *)(a1 + 22) = 77;
*(_WORD *)(a1 + 24) = 256;
*(_WORD *)(a1 + 26) = -2;
add_memory_wram(65285LL, 0LL);
add_memory_wram(65286LL, 0LL);
add_memory_wram(65287LL, 0LL);
add_memory_wram(65296LL, 128LL);
add_memory_wram(65297LL, 191LL);
add_memory_wram(65298LL, 243LL);
add_memory_wram(65300LL, 191LL);
add_memory_wram(65302LL, 63LL);
add_memory_wram(65303LL, 0LL);
add_memory_wram(65305LL, 191LL);
add_memory_wram(65306LL, 127LL);
add_memory_wram(65307LL, 255LL);
add_memory_wram(65308LL, 159LL);
add_memory_wram(65310LL, 191LL);
add_memory_wram(65312LL, 255LL);
add_memory_wram(65313LL, 0LL);
add_memory_wram(65314LL, 0LL);
add_memory_wram(65315LL, 191LL);
add_memory_wram(65316LL, 119LL);
add_memory_wram(65317LL, 243LL);
add_memory_wram(65318LL, 241LL);
add_memory_wram(65344LL, 145LL);
add_memory_wram(65346LL, 0LL);
add_memory_wram(65347LL, 0LL);
add_memory_wram(65349LL, 0LL);
add_memory_wram(65351LL, 252LL);
add_memory_wram(65352LL, 255LL);
add_memory_wram(65353LL, 255LL);
add_memory_wram(65354LL, 0LL);
add_memory_wram(65355LL, 0LL);
return add_memory_wram(0xFFFFLL, 0LL);
}

original_code:
void setup_boot(z80_t* state)
{
 state->Reg.a = 1;
 state->Reg.f = 176;
 state->Reg.d = 0;
 state->Reg.e = 216;
 state->Reg.h = 1;
 state->Reg.l = 77;
 state->Reg.pc = 256;
 state->Reg.sp = 65534;
   add_memory_wram(0xFF05, 0x00);
   add_memory_wram(0xFF06, 0x00);
   add_memory_wram(0xFF07, 0x00);
   add_memory_wram(0xFF10, 0x80);
   add_memory_wram(0xFF11, 0xBF);
   add_memory_wram(0xFF12, 0xF3);
   add_memory_wram(0xFF14, 0xBF);
   add_memory_wram(0xFF16, 0x3F);
   add_memory_wram(0xFF17, 0x00);
   add_memory_wram(0xFF19, 0xBF);
   add_memory_wram(0xFF1A, 0x7F);
   add_memory_wram(0xFF1B, 0xFF);
   add_memory_wram(0xFF1C, 0x9F);
   add_memory_wram(0xFF1E, 0xBF);
   add_memory_wram(0xFF20, 0xFF);
   add_memory_wram(0xFF21, 0x00);
   add_memory_wram(0xFF22, 0x00);
   add_memory_wram(0xFF23, 0xBF);
   add_memory_wram(0xFF24, 0x77);
   add_memory_wram(0xFF25, 0xF3);
   add_memory_wram(0xFF26, 0xF1);
   add_memory_wram(0xFF40, 0x91);
   add_memory_wram(0xFF42, 0x00);
   add_memory_wram(0xFF43, 0x00);
   add_memory_wram(0xFF45, 0x00);
   add_memory_wram(0xFF47, 0xFC);
   add_memory_wram(0xFF48, 0xFF);
   add_memory_wram(0xFF49, 0xFF);
   add_memory_wram(0xFF4A, 0x00);
   add_memory_wram(0xFF4B, 0x00);
   add_memory_wram(0xFFFF, 0x00);
}

canonical_original_code:
void setup_boot(struct z80_t *state)
{
 state->Reg.a = 1;
 state->Reg.f = 176;
 state->Reg.d = 0;
 state->Reg.e = 216;
 state->Reg.h = 1;
 state->Reg.l = 77;
 state->Reg.pc = 256;
 state->Reg.sp = 65534;
   add_memory_wram(0xFF05, 0x00);
   add_memory_wram(0xFF06, 0x00);
   add_memory_wram(0xFF07, 0x00);
   add_memory_wram(0xFF10, 0x80);
   add_memory_wram(0xFF11, 0xBF);
   add_memory_wram(0xFF12, 0xF3);
   add_memory_wram(0xFF14, 0xBF);
   add_memory_wram(0xFF16, 0x3F);
   add_memory_wram(0xFF17, 0x00);
   add_memory_wram(0xFF19, 0xBF);
   add_memory_wram(0xFF1A, 0x7F);
   add_memory_wram(0xFF1B, 0xFF);
   add_memory_wram(0xFF1C, 0x9F);
   add_memory_wram(0xFF1E, 0xBF);
   add_memory_wram(0xFF20, 0xFF);
   add_memory_wram(0xFF21, 0x00);
   add_memory_wram(0xFF22, 0x00);
   add_memory_wram(0xFF23, 0xBF);
   add_memory_wram(0xFF24, 0x77);
   add_memory_wram(0xFF25, 0xF3);
   add_memory_wram(0xFF26, 0xF1);
   add_memory_wram(0xFF40, 0x91);
   add_memory_wram(0xFF42, 0x00);
   add_memory_wram(0xFF43, 0x00);
   add_memory_wram(0xFF45, 0x00);
   add_memory_wram(0xFF47, 0xFC);
   add_memory_wram(0xFF48, 0xFF);
   add_memory_wram(0xFF49, 0xFF);
   add_memory_wram(0xFF4A, 0x00);
   add_memory_wram(0xFF4B, 0x00);
   add_memory_wram(0xFFFF, 0x00);
}

variable_types: struct z80_t { int halt; int stop; struct Clock { int m; int t; } Clock; struct Reg { unsigned char a; unsigned short pc; int m; int ime; } Reg; struct Rsv { unsigned char a; } Rsv; } *

user_defined_types: struct z80_t { int halt; int stop; struct Clock Clock; struct Reg Reg; struct Rsv Rsv; }


step

decompiled_code:
__int64 step()
{
int v0; // edx
__int64 result; // rax

v0 = *(_DWORD *)(state + 32LL) + modeClock;
modeClock = v0;
result = (unsigned int)mode;
if ( mode == 2 )
{
if ( v0 > 79 )
{
modeClock = 0;
mode = 3;
}
}
else if ( mode > 2 )
{
if ( mode == 3 && v0 > 171 )
{
modeClock = 0;
mode = 0;
}
}
else if ( mode )
{
if ( mode == 1 && v0 > 455 )
{
modeClock = 0;
result = (unsigned int)(line + 1);
line = result;
if ( (int)result > 153 )
{
mode = 2;
line = 0;
}
}
}
else if ( v0 > 203 )
{
modeClock = 0;
result = (unsigned int)(++line != 143) + 1;
mode = (line != 143) + 1;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // edx
__int64 result; // rax

v0 = *(_DWORD *)(state + 32LL) + modeClock;
modeClock = v0;
result = (unsigned int)mode;
if ( mode == 2 )
{
if ( v0 > 79 )
{
modeClock = 0;
mode = 3;
}
}
else if ( mode > 2 )
{
if ( mode == 3 && v0 > 171 )
{
modeClock = 0;
mode = 0;
}
}
else if ( mode )
{
if ( mode == 1 && v0 > 455 )
{
modeClock = 0;
result = (unsigned int)(line + 1);
line = result;
if ( (int)result > 153 )
{
mode = 2;
line = 0;
}
}
}
else if ( v0 > 203 )
{
modeClock = 0;
result = (unsigned int)(++line != 143) + 1;
mode = (line != 143) + 1;
}
return result;
}

original_code:
void step()
{
 modeClock += state->Reg.t;
 switch(mode) {
  case 2:
   if (modeClock >= 80){
    modeClock = 0;
    mode = 3;
   }
   break;
  case 3:
   if (modeClock >= 172) {
    modeClock = 0;
    mode = 0;
   }
   break;
  case 0:
   if (modeClock >= 204) {
    modeClock = 0;
    line++;
    if (line == 143) {
     mode = 1;
    } else {
     mode = 2;
    }
   }
   break;
  case 1:
   if (modeClock >= 456) {
    modeClock = 0;
    line++;
    if (line > 153) {
     mode = 2;
     line = 0;
    }
   }
   break;
 }
}


repo: jamorton/kerneldb

decompiled_code:
void __noreturn exit_help()
{
puts("Usage: krcl [db_path] [command]\nCommands:\n bench - run the benchmark\n put [key] [val]\n get [key]");
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts("Usage: krcl [db_path] [command]\nCommands:\n bench - run the benchmark\n put [key] [val]\n get [key]");
exit(0);
}

original_code:
static void exit_help(void)
{
    printf(
        "Usage: krcl [db_path] [command]\n"
        "Commands:\n"
        "  bench - run the benchmark\n"
        "  put [key] [val]\n"
        "  get [key]\n"
    );
    exit(0);
}

canonical_original_code:
static void exit_help()
{
    printf(
        "Usage: krcl [db_path] [command]\n"
        "Commands:\n"
        "  bench - run the benchmark\n"
        "  put [key] [val]\n"
        "  get [key]\n"
    );
    exit(0);
}


repo: janmiderback/hooche

decompiled_code:
char *__fastcall str_tolower(char *s)
{
unsigned int v1; // ebp

v1 = 0;
if ( s )
{
while ( v1 < strlen(s) )
{
s[v1] = (*_ctype_tolower_loc())[s[v1]];
++v1;
}
}
return s;
}

canonical_decompiled_code:
char *__fastcall func0(char *s)
{
unsigned int v1; // ebp

v1 = 0;
if ( s )
{
while ( v1 < strlen(s) )
{
s[v1] = (*_ctype_tolower_loc())[s[v1]];
++v1;
}
}
return s;
}

original_code:
char* str_tolower(char* s)
{
    if (s != ((void *)0)) {
        unsigned int i;
        for (i = 0; i < strlen(s); ++i) s[i] = tolower(s[i]);
    }
    return s;
}

canonical_original_code:
char *str_tolower(char *s)
{
    if (s != ((void *)0)) {
        unsigned int i;
        for (i = 0; i < strlen(s); ++i) s[i] = tolower(s[i]);
    }
    return s;
}

variable_types:
s
char *

variable_types:
i
unsigned int

return_type: char *


decompiled_code:
__int64 __fastcall str_icmp(char *src, char *a2)
{
size_t v2; // rax
char *v3; // rbp
size_t v4; // rax
char *v5; // rbx
unsigned int v6; // er12

if ( !src )
_assert_fail("s1 != NULL", "src/util.c", 0x14u, "str_icmp");
if ( !a2 )
_assert_fail("s2 != NULL", "src/util.c", 0x15u, "str_icmp");
v2 = strlen(src);
v3 = (char *)malloc(v2 + 1);
v4 = strlen(a2);
v5 = (char *)malloc(v4 + 1);
strcpy(v3, src);
strcpy(v5, a2);
str_tolower(v3);
str_tolower(v5);
v6 = strcmp(v3, v5);
free(v3);
free(v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, char *a2)
{
size_t v2; // rax
char *v3; // rbp
size_t v4; // rax
char *v5; // rbx
unsigned int v6; // er12

if ( !src )
_assert_fail("s1 != NULL", "src/util.c", 0x14u, "str_icmp");
if ( !a2 )
_assert_fail("s2 != NULL", "src/util.c", 0x15u, "str_icmp");
v2 = strlen(src);
v3 = (char *)malloc(v2 + 1);
v4 = strlen(a2);
v5 = (char *)malloc(v4 + 1);
strcpy(v3, src);
strcpy(v5, a2);
func0(v3);
func0(v5);
v6 = strcmp(v3, v5);
free(v3);
free(v5);
return v6;
}

original_code:
int str_icmp(const char* s1, const char* s2)
{
    char* s1_cpy;
    char* s2_cpy;
    int retval;
    ((s1 != ((void *)0)) ? (void) (0) : __assert_fail ("s1 != NULL", "src/util.c", 20, __extension__ __PRETTY_FUNCTION__));
    ((s2 != ((void *)0)) ? (void) (0) : __assert_fail ("s2 != NULL", "src/util.c", 21, __extension__ __PRETTY_FUNCTION__));
    s1_cpy = malloc(strlen(s1) + 1);
    s2_cpy = malloc(strlen(s2) + 1);
    strcpy(s1_cpy, s1);
    strcpy(s2_cpy, s2);
    str_tolower(s1_cpy);
    str_tolower(s2_cpy);
    retval = strcmp(s1_cpy, s2_cpy);
    free(s1_cpy);
    free(s2_cpy);
    return retval;
}

canonical_original_code:
int str_icmp(char *s1, char *s2)
{
    char *s1_cpy;
    char *s2_cpy;
    int retval;
    ((s1 != ((void *)0)) ? (void) (0) : __assert_fail ("s1 != NULL", "src/util.c", 20, __extension__ __PRETTY_FUNCTION__));
    ((s2 != ((void *)0)) ? (void) (0) : __assert_fail ("s2 != NULL", "src/util.c", 21, __extension__ __PRETTY_FUNCTION__));
    s1_cpy = malloc(strlen(s1) + 1);
    s2_cpy = malloc(strlen(s2) + 1);
    strcpy(s1_cpy, s1);
    strcpy(s2_cpy, s2);
    str_tolower(s1_cpy);
    str_tolower(s2_cpy);
    retval = strcmp(s1_cpy, s2_cpy);
    free(s1_cpy);
    free(s2_cpy);
    return retval;
}

variable_types: retval int

return_type: int


main

canonical_name: main

repo: jannejango/c

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbp
int v4; // ebx
double v5; // xmm0_8
void *v6; // rax
double v7; // xmm0_8
__int64 v8; // rbp
int v9; // eax
void *ptr; // [rsp+0h] [rbp-8h]
__int64 vars0; // [rsp+8h] [rbp+0h] BYREF

v3 = &vars0;
v4 = 0;
while ( 1 )
{
v5 = pow(10.0, (double)v4);
v6 = malloc((int)v5);
*v3 = (__int64)v6;
if ( !v6 )
break;
v7 = pow(10.0, (double)v4);
printf("Allocate %d bytes.\n", (unsigned int)(int)v7);
++v4;
++v3;
if ( v4 == 100 )
goto LABEL_4;
}
puts("Error.");
if ( v4 <= 0 )
return 0;
LABEL_4:
v8 = 1LL;
do
{
free(*(&ptr + v8));
v9 = v8++;
}
while ( v9 <= 99 && v9 < v4 );
return 0;
}

original_code:
int
main()
{
  int *ptr[100];
  int i;
  for(i=0; i<100; i++){
    ptr[i] = malloc((int)pow(10.0, (double)i));
    if(ptr[i]==((void *)0)){
      printf("Error.\n");
      break;
    }else{
      printf("Allocate %d bytes.\n", (int)pow(10.0, (double)i));
    }
  }
  int j;
  for(j=0; j<100 && j<i; j++){
    free(ptr[j]);
  }
  return(0);
}

variable_types:
ptr
int *[100]

variable_types: i int

variable_types: j int


repo: jansegre/nanows

decompiled_code:
__int64 __fastcall serve_file(int out_fd, char *filename, int a3)
{
int v4; // ebp
size_t v6; // rax
ssize_t v7; // rax
off_t offset; // [rsp+8h] [rbp-E0h] BYREF
char s[32]; // [rsp+10h] [rbp-D8h] BYREF
struct stat v10; // [rsp+30h] [rbp-B8h] BYREF

stat(filename, &v10);
if ( (v10.st_mode & 0x4000) != 0 )
{
strcpy(&filename[strlen(filename)], "/index.html");
stat(filename, &v10);
}
if ( (v10.st_mode & 0x8000) == 0 )
{
write(out_fd, "HTTP/1.0 404 Not Found\r\n\r\n", 0x1AuLL);
puts("not found");
fwrite("ERROR ", 1uLL, 6uLL, stderr);
perror(filename);
return 0LL;
}
v4 = open(filename, 0, 256LL);
if ( v4 < 0 )
{
write(out_fd, "HTTP/1.0 403 Forbidden\r\n\r\n", 0x1AuLL);
puts("forbidden");
fwrite("ERROR ", 1uLL, 6uLL, stderr);
perror(filename);
return 0LL;
}
write(out_fd, "HTTP/1.0 200 OK\r\n", 0x11uLL);
write(out_fd, "Server: nanows-0.0.1\r\n", 0x16uLL);
sprintf(s, "Content-Length: %lli\r\n", v10.st_size);
if ( a3 )
{
v6 = strlen(s);
write(out_fd, s, v6);
write(out_fd, "\r\n", 2uLL);
offset = 0LL;
v7 = 0LL;
while ( 1 )
{
v7 = sendfile(out_fd, v4, &offset, v10.st_size - v7);
offset += v7;
if ( v7 < 0 )
break;
if ( v7 <= 0 )
goto LABEL_7;
}
if ( v4 <= 0 || close(v4) >= 0 )
{
perror("ERROR serving file");
return 1LL;
}
}
else
{
write(out_fd, "\r\n", 2uLL);
LABEL_7:
if ( close(v4) >= 0 )
{
puts("ok");
return 0LL;
}
}
perror("ERROR closing file");
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int out_fd, char *filename, int a3)
{
int v4; // ebp
size_t v6; // rax
ssize_t v7; // rax
off_t offset; // [rsp+8h] [rbp-E0h] BYREF
char s[32]; // [rsp+10h] [rbp-D8h] BYREF
struct stat v10; // [rsp+30h] [rbp-B8h] BYREF

func13(filename, &v10);
if ( (v10.st_mode & 0x4000) != 0 )
{
strcpy(&filename[strlen(filename)], "/index.html");
func13(filename, &v10);
}
if ( (v10.st_mode & 0x8000) == 0 )
{
write(out_fd, "HTTP/1.0 404 Not Found\r\n\r\n", 0x1AuLL);
puts("not found");
fwrite("ERROR ", 1uLL, 6uLL, stderr);
perror(filename);
return 0LL;
}
v4 = open(filename, 0, 256LL);
if ( v4 < 0 )
{
write(out_fd, "HTTP/1.0 403 Forbidden\r\n\r\n", 0x1AuLL);
puts("forbidden");
fwrite("ERROR ", 1uLL, 6uLL, stderr);
perror(filename);
return 0LL;
}
write(out_fd, "HTTP/1.0 200 OK\r\n", 0x11uLL);
write(out_fd, "Server: nanows-0.0.1\r\n", 0x16uLL);
sprintf(s, "Content-Length: %lli\r\n", v10.st_size);
if ( a3 )
{
v6 = strlen(s);
write(out_fd, s, v6);
write(out_fd, "\r\n", 2uLL);
offset = 0LL;
v7 = 0LL;
while ( 1 )
{
v7 = sendfile(out_fd, v4, &offset, v10.st_size - v7);
offset += v7;
if ( v7 < 0 )
break;
if ( v7 <= 0 )
goto LABEL_7;
}
if ( v4 <= 0 || close(v4) >= 0 )
{
perror("ERROR serving file");
return 1LL;
}
}
else
{
write(out_fd, "\r\n", 2uLL);
LABEL_7:
if ( close(v4) >= 0 )
{
puts("ok");
return 0LL;
}
}
perror("ERROR closing file");
return 2LL;
}

original_code:
int serve_file(int sockfd, char* filepath, int serve) {
  int fd;
  struct stat st;
  char contentlen[32];
  stat(filepath, &st);
  if (st.st_mode & 0040000) {
    char* path_append = filepath + strlen(filepath);
    sprintf(path_append, "/index.html");
    stat(filepath, &st);
  }
  if (!(st.st_mode & 0100000)) {
    write(sockfd, "HTTP/1.0 404 Not Found\r\n\r\n", 26);
    printf("not found\n");
    fprintf(stderr, "ERROR ");
    perror(filepath);
    return 0;
  }
  fd = open(filepath, 00, 0400);
  if (fd < 0) {
    write(sockfd, "HTTP/1.0 403 Forbidden\r\n\r\n", 26);
    printf("forbidden\n");
    fprintf(stderr, "ERROR ");
    perror(filepath);
    return 0;
  }
  write(sockfd, "HTTP/1.0 200 OK\r\n", 17);
  write(sockfd, "Server: nanows-0.0.1\r\n", 22);
  sprintf(contentlen, "Content-Length: %lli\r\n", (long long)st.st_size);
  if (serve)
    write(sockfd, contentlen, strlen(contentlen));
  write(sockfd, "\r\n", 2);
  if (serve) {
    off_t offset = 0;
    ssize_t n = 0;
    do {
      n = sendfile(sockfd, fd, &offset, st.st_size - n);
      offset += n;
      if (n < 0) goto error;
    } while (n > 0);
  }
  if (close(fd) < 0) goto error_close;
  printf("ok\n");
  return 0;
error:
  if (fd > 0) if (close(fd) < 0) goto error_close;
  perror("ERROR serving file");
  return 1;
error_close:
  perror("ERROR closing file");
  return 2;
}

canonical_original_code:
int serve_file(int sockfd, char *filepath, int serve) {
  int fd;
  struct stat st;
  char contentlen[32];
  stat(filepath, &st);
  if (st.st_mode & 0040000) {
    char *path_append = filepath + strlen(filepath);
    sprintf(path_append, "/index.html");
    stat(filepath, &st);
  }
  if (!(st.st_mode & 0100000)) {
    write(sockfd, "HTTP/1.0 404 Not Found\r\n\r\n", 26);
    printf("not found\n");
    fprintf(stderr, "ERROR ");
    perror(filepath);
    return 0;
  }
  fd = open(filepath, 00, 0400);
  if (fd < 0) {
    write(sockfd, "HTTP/1.0 403 Forbidden\r\n\r\n", 26);
    printf("forbidden\n");
    fprintf(stderr, "ERROR ");
    perror(filepath);
    return 0;
  }
  write(sockfd, "HTTP/1.0 200 OK\r\n", 17);
  write(sockfd, "Server: nanows-0.0.1\r\n", 22);
  sprintf(contentlen, "Content-Length: %lli\r\n", (long long)st.st_size);
  if (serve)
    write(sockfd, contentlen, strlen(contentlen));
  write(sockfd, "\r\n", 2);
  if (serve) {
    long offset = 0;
    long n = 0;
    do {
      n = sendfile(sockfd, fd, &offset, st.st_size - n);
      offset += n;
      if (n < 0) goto error;
    } while (n > 0);
  }
  if (close(fd) < 0) goto error_close;
  printf("ok\n");
  return 0;
error:
  if (fd > 0) if (close(fd) < 0) goto error_close;
  perror("ERROR serving file");
  return 1;
error_close:
  perror("ERROR closing file");
  return 2;
}

variable_types: sockfd int

variable_types:
filepath
char *

variable_types: serve int

variable_types: fd int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
contentlen
char [32]

variable_types: offset long

variable_types: n long

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall process_connection(int a1)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
v2 = v1;
if ( v1 < 0 || (v3 = process_request(v1)) != 0 )
{
close(v2);
perror("ERROR processing the connection");
v3 = 1;
}
else
{
close(v2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
v2 = v1;
if ( v1 < 0 || (v3 = process_request(v1)) != 0 )
{
close(v2);
perror("ERROR processing the connection");
v3 = 1;
}
else
{
close(v2);
}
return v3;
}

original_code:
int process_connection(int sockfd, const char* path) {
  int newsockfd;
  struct sockaddr cli_addr;
  socklen_t cli_addr_len;
  cli_addr_len = sizeof(cli_addr);
  newsockfd = accept(sockfd, &cli_addr, &cli_addr_len);
  if (newsockfd < 0) goto error;
  if (process_request(newsockfd, path) != 0) goto error;
  close(newsockfd);
  return 0;
error:
  close(newsockfd);
  perror("ERROR processing the connection");
  return 1;
}

canonical_original_code:
int process_connection(int sockfd, char *path) {
  int newsockfd;
  struct sockaddr cli_addr;
  unsigned int cli_addr_len;
  cli_addr_len = sizeof(cli_addr);
  newsockfd = accept(sockfd, &cli_addr, &cli_addr_len);
  if (newsockfd < 0) goto error;
  if (process_request(newsockfd, path) != 0) goto error;
  close(newsockfd);
  return 0;
error:
  close(newsockfd);
  perror("ERROR processing the connection");
  return 1;
}

variable_types:
path
char *

variable_types: newsockfd int

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


server

decompiled_code:
__int64 __fastcall server(unsigned int a1)
{
int v1; // eax
int v2; // ebx
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("ERROR opening socket");
}
else
{
v2 = v1;
optval = 1;
setsockopt(v1, 1, 2, &optval, 4u);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(a1);
if ( bind(v2, &addr, 0x10u) < 0 )
{
perror("ERROR on binding");
}
else
{
listen(v2, 1024);
printf("Listening on port %i.\n", a1);
while ( (int)process_connection(v2) >= 0 )
;
close(v2);
perror("ERROR unexpected error occurred");
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
int v1; // eax
int v2; // ebx
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("ERROR opening socket");
}
else
{
v2 = v1;
optval = 1;
setsockopt(v1, 1, 2, &optval, 4u);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func7(a1);
if ( bind(v2, &addr, 0x10u) < 0 )
{
perror("ERROR on binding");
}
else
{
listen(v2, 1024);
printf("Listening on port %i.\n", a1);
while ( (int)func9(v2) >= 0 )
;
close(v2);
perror("ERROR unexpected error occurred");
}
}
return 1LL;
}

original_code:
int server(const int port, const char* path) {
  int sockfd;
  struct sockaddr_in serv_addr;
  int optval;
  sockfd = socket(2, SOCK_STREAM, 0);
  if (sockfd < 0) {
    perror("ERROR opening socket");
    return 1;
  }
  optval = 1;
  setsockopt(sockfd, 1, 2, &optval, sizeof(optval));
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = 2;
  serv_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
  serv_addr.sin_port = htons(port);
  if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
    perror("ERROR on binding");
    return 1;
  }
  listen(sockfd, 1024);
  printf("Listening on port %i.\n", port);
  for (;;) {
    int n;
    n = process_connection(sockfd, path);
    if (n < 0) goto error;
  }
  close(sockfd);
  return 0;
error:
  close(sockfd);
  perror("ERROR unexpected error occurred");
  return 1;
}

canonical_original_code:
int server(int port, char *path) {
  int sockfd;
  struct sockaddr_in serv_addr;
  int optval;
  sockfd = socket(2, SOCK_STREAM, 0);
  if (sockfd < 0) {
    perror("ERROR opening socket");
    return 1;
  }
  optval = 1;
  setsockopt(sockfd, 1, 2, &optval, sizeof(optval));
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = 2;
  serv_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
  serv_addr.sin_port = htons(port);
  if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
    perror("ERROR on binding");
    return 1;
  }
  listen(sockfd, 1024);
  printf("Listening on port %i.\n", port);
  for (;;) {
    int n;
    n = process_connection(sockfd, path);
    if (n < 0) goto error;
  }
  close(sockfd);
  return 0;
error:
  close(sockfd);
  perror("ERROR unexpected error occurred");
  return 1;
}

variable_types: port int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: optval int

variable_types: n int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax

v3 = 5001;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "l:s:");
if ( v4 == -1 )
break;
if ( v4 == 108 )
{
v3 = atoi(optarg);
}
else if ( v4 != 115 )
{
fprintf(stderr, "Usage: %s [-l port] [-s path]\n", *argv);
return 1;
}
}
return server(v3);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax

v3 = 5001;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "l:s:");
if ( v4 == -1 )
break;
if ( v4 == 108 )
{
v3 = atoi(optarg);
}
else if ( v4 != 115 )
{
fprintf(stderr, "Usage: %s [-l port] [-s path]\n", *argv);
return 1;
}
}
return func10(v3);
}

original_code:
int main(int argc, char* argv[]) {
  int opt;
  int port = 5001;
  char *path = "./";
  while ((opt = getopt(argc, argv, "l:s:")) != -1) {
    switch (opt) {
      case 'l':
        port = atoi(optarg);
        break;
      case 's':
        path = optarg;
        break;
      default:
        fprintf(stderr, "Usage: %s [-l port] [-s path]\n", argv[0]);
        return 1;
    }
  }
  return server(port, path);
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int opt;
  int port = 5001;
  char *path = "./";
  while ((opt = getopt(argc, argv, "l:s:")) != -1) {
    switch (opt) {
      case 'l':
        port = atoi(optarg);
        break;
      case 's':
        path = optarg;
        break;
      default:
        fprintf(stderr, "Usage: %s [-l port] [-s path]\n", argv[0]);
        return 1;
    }
  }
  return server(port, path);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int


priceTrans

decompiled_code:
__m128i __fastcall priceTrans(char *s1)
{
__int64 v1; // rbx
unsigned int v2; // er12
__m128i v3; // xmm1

v1 = thead;
if ( thead )
{
v2 = LC0;
do
{
if ( !strcmp(s1, (const char *)(v1 + 4)) )
{
v3 = _mm_cvtsi32_si128(v2);
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 + *(float *)v1;
v2 = _mm_cvtsi128_si32(v3);
}
v1 = *(_QWORD *)(v1 + 88);
}
while ( v1 );
}
else
{
v2 = LC0;
}
return _mm_cvtsi32_si128(v2);
}

canonical_decompiled_code:
__m128i __fastcall func0(char *s1)
{
__int64 v1; // rbx
unsigned int v2; // er12
__m128i v3; // xmm1

v1 = thead;
if ( thead )
{
v2 = LC0;
do
{
if ( !strcmp(s1, (const char *)(v1 + 4)) )
{
v3 = _mm_cvtsi32_si128(v2);
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 + *(float *)v1;
v2 = _mm_cvtsi128_si32(v3);
}
v1 = *(_QWORD *)(v1 + 88);
}
while ( v1 );
}
else
{
v2 = LC0;
}
return _mm_cvtsi32_si128(v2);
}

original_code:
float priceTrans(char * trans)
{
 float price = 0;
 struct transaction *current = thead;
 while (current){
  if (!strcmp(trans, current->name))
   price += current->price;
  current=current->next;
 }
 return price;
}

canonical_original_code:
float priceTrans(char *trans)
{
 float price = 0;
 struct transaction *current = thead;
 while (current){
  if (!strcmp(trans, current->name))
   price += current->price;
  current=current->next;
 }
 return price;
}

variable_types:
trans
char *

variable_types: price float

variable_types: struct transaction { float price; char name[80]; struct transaction *next; int type; } *

return_type: float


repo: jappavoo/ClaraBell

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

v1 = listen(a1, 1024);
result = 1LL;
if ( v1 < 0 )
{
v3 = _errno_location();
fprintf(stderr, "Error: EventListen listen failed (%d)\n", (unsigned int)*v3);
result = 0xFFFFFFFFLL;
}
return result;
}

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

v1 = listen(a1, 1024);
result = 1LL;
if ( v1 < 0 )
{
v3 = _errno_location();
fprintf(stderr, "Error: EventListen listen failed (%d)\n", (unsigned int)*v3);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
extern int
net_listen(FDType fd)
{
  if (listen(fd, 1024) < 0) {
    fprintf(stderr, "Error: EventListen listen failed (%d)\n", (*__errno_location ()));
    return -1;
  }
  return 1;
}

canonical_original_code:
extern int net_listen(int fd)
{
  if (listen(fd, 1024) < 0) {
    fprintf(stderr, "Error: EventListen listen failed (%d)\n", (*__errno_location ()));
    return -1;
  }
  return 1;
}

variable_types: fd int


decompiled_code:
int __fastcall net_accept(int a1)
{
return accept(a1, 0LL, 0LL);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
return accept(a1, 0LL, 0LL);
}

original_code:
extern FDType
net_accept(FDType fd)
{
  FDType nfd;
  nfd=accept(fd, ((void *)0), ((void *)0));
  return nfd;
}

canonical_original_code:
extern int net_accept(int fd)
{
  int nfd;
  nfd=accept(fd, ((void *)0), ((void *)0));
  return nfd;
}

variable_types: nfd int


decompiled_code:
__int64 __fastcall net_setup_listen_socket(int *a1, _DWORD *a2)
{
int v2; // eax
int v3; // ebx
int *v5; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
int *v9; // rax
int v10; // [rsp+4h] [rbp-34h] BYREF
socklen_t len; // [rsp+8h] [rbp-30h] BYREF
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
len = 16;
v10 = 1;
v2 = socket(2, 1, 6);
if ( v2 < 0 )
{
v5 = _errno_location();
fprintf(stderr, "Error: server socket create failed (%d)\n", (unsigned int)*v5);
exit(1);
}
v3 = v2;
if ( setsockopt(v2, 1, 2, &optval, 4u) )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "setsockopt(SO_REUSEADDR): %s\n", v7);
exit(1);
}
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
if ( *a2 )
*(_WORD *)addr.sa_data = _bswap_16(*a2);
if ( bind(v3, &addr, len) < 0 )
{
v8 = _errno_location();
fprintf(stderr, "Error: server bind failed (%d)\n", (unsigned int)*v8);
close(v3);
exit(1);
}
if ( ioctl(v3, 0x5421uLL, &v10) < 0 )
{
perror("ioctl() failed");
close(v3);
exit(-1);
}
if ( !*a2 )
{
if ( getsockname(v3, &addr, &len) < 0 )
{
v9 = _errno_location();
fprintf(stderr, "Error server getsocketname failed (%d)\n", (unsigned int)*v9);
close(v3);
exit(1);
}
*a2 = (unsigned __int16)_bswap_16(*(__int16 *)addr.sa_data);
}
*a1 = v3;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, _DWORD *a2)
{
int v2; // eax
int v3; // ebx
int *v5; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
int *v9; // rax
int v10; // [rsp+4h] [rbp-34h] BYREF
socklen_t len; // [rsp+8h] [rbp-30h] BYREF
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
len = 16;
v10 = 1;
v2 = socket(2, 1, 6);
if ( v2 < 0 )
{
v5 = _errno_location();
fprintf(stderr, "Error: server socket create failed (%d)\n", (unsigned int)*v5);
exit(1);
}
v3 = v2;
if ( setsockopt(v2, 1, 2, &optval, 4u) )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "setsockopt(SO_REUSEADDR): %s\n", v7);
exit(1);
}
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func0(0);
if ( *a2 )
*(_WORD *)addr.sa_data = func1(*a2);
if ( bind(v3, &addr, len) < 0 )
{
v8 = _errno_location();
fprintf(stderr, "Error: server bind failed (%d)\n", (unsigned int)*v8);
close(v3);
exit(1);
}
if ( ioctl(v3, 0x5421uLL, &v10) < 0 )
{
perror("ioctl() failed");
close(v3);
exit(-1);
}
if ( !*a2 )
{
if ( getsockname(v3, &addr, &len) < 0 )
{
v9 = _errno_location();
fprintf(stderr, "Error server getsocketname failed (%d)\n", (unsigned int)*v9);
close(v3);
exit(1);
}
*a2 = (unsigned __int16)func1(*(__int16 *)addr.sa_data);
}
*a1 = v3;
return 1LL;
}

original_code:
extern int
net_setup_listen_socket(FDType *fd, PortType *port)
{
    struct sockaddr_in name;
    int one = 1;
    FDType fd_listen;
    socklen_t addrLen = sizeof(struct sockaddr);
    int rc;
    int on=1;
    fd_listen = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (fd_listen < 0) {
        fprintf(stderr, "Error: server socket create failed (%d)\n", (*__errno_location ()));
        exit(1);
    }
    rc = setsockopt(fd_listen, 1, 2, &one, sizeof(one));
    if (rc != 0) {
        fprintf(stderr, "setsockopt(SO_REUSEADDR): %s\n", strerror((*__errno_location ())));
        exit(1);
    }
    bzero(&name, sizeof(name));
    name.sin_family = 2;
    name.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    if (*port) name.sin_port = htons(*port);
    else name.sin_port = 0;
    rc = bind(fd_listen, (struct sockaddr *)&name, addrLen);
    if (rc < 0) {
        fprintf(stderr, "Error: server bind failed (%d)\n", (*__errno_location ()));
        close (fd_listen);
        exit(1);
    }
   rc = ioctl(fd_listen, 0x5421, (char *)&on);
   if (rc < 0)
   {
      perror("ioctl() failed");
      close(fd_listen);
      exit(-1);
   }
    if (*port == 0) {
        rc = getsockname(fd_listen, (struct sockaddr *)&name, &addrLen);
        if (rc < 0) {
            fprintf(stderr, "Error server getsocketname failed (%d)\n", (*__errno_location ()));
            close(fd_listen);
            exit(1);
        }
        *port = ntohs(name.sin_port);
    }
    *fd = fd_listen;
    return 1;
}

canonical_original_code:
extern int net_setup_listen_socket(int *fd, int *port)
{
    struct sockaddr_in name;
    int one = 1;
    int fd_listen;
    unsigned int addrLen = sizeof(struct sockaddr);
    int rc;
    int on = 1;
    fd_listen = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (fd_listen < 0) {
        fprintf(stderr, "Error: server socket create failed (%d)\n", (*__errno_location ()));
        exit(1);
    }
    rc = setsockopt(fd_listen, 1, 2, &one, sizeof(one));
    if (rc != 0) {
        fprintf(stderr, "setsockopt(SO_REUSEADDR): %s\n", strerror((*__errno_location ())));
        exit(1);
    }
    bzero(&name, sizeof(name));
    name.sin_family = 2;
    name.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    if (*port) name.sin_port = htons(*port);
    else name.sin_port = 0;
    rc = bind(fd_listen, (struct sockaddr *)&name, addrLen);
    if (rc < 0) {
        fprintf(stderr, "Error: server bind failed (%d)\n", (*__errno_location ()));
        close (fd_listen);
        exit(1);
    }
   rc = ioctl(fd_listen, 0x5421, (char *)&on);
   if (rc < 0)
   {
      perror("ioctl() failed");
      close(fd_listen);
      exit(-1);
   }
    if (*port == 0) {
        rc = getsockname(fd_listen, (struct sockaddr *)&name, &addrLen);
        if (rc < 0) {
            fprintf(stderr, "Error server getsocketname failed (%d)\n", (*__errno_location ()));
            close(fd_listen);
            exit(1);
        }
        *port = ntohs(name.sin_port);
    }
    *fd = fd_listen;
    return 1;
}

variable_types:
fd
int *

variable_types:
port
int *

variable_types: one int

variable_types:
addrLen
unsigned int

variable_types: rc int

variable_types: on int


decompiled_code:
__int64 __fastcall net_setup_connection(int *a1, const char *a2, unsigned int a3)
{
struct hostent *v4; // rax
int v5; // ebx
int v6; // edx
__int64 result; // rax
struct sockaddr v8; // [rsp+0h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v4 = gethostbyname(a2);
if ( v4 )
{
v8.sa_family = v4->h_addrtype;
memcpy(&v8.sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)v8.sa_data = _bswap_16(a3);
v5 = socket(2, 1, 0);
*a1 = v5;
if ( v5 < 0 )
{
fwrite("unable to create socket", 1uLL, 0x17uLL, stderr);
perror("oops ");
result = 0xFFFFFFFFLL;
}
else
{
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = _bswap_32(0);
*(_WORD *)addr.sa_data = _bswap_16(0);
if ( bind(v5, &addr, 0x10u) < 0 )
{
fprintf(stderr, "cannot bind port TCP %u\n", a3);
perror("oops ");
result = 0xFFFFFFFFLL;
}
else
{
v6 = connect(*a1, &v8, 0x10u);
result = 1LL;
if ( v6 < 0 )
{
perror("cannot connect ");
result = 0xFFFFFFFFLL;
}
}
}
}
else
{
fprintf(stderr, "unknown host '%s'\n", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, const char *a2, unsigned int a3)
{
struct hostent *v4; // rax
int v5; // ebx
int v6; // edx
__int64 result; // rax
struct sockaddr v8; // [rsp+0h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v4 = gethostbyname(a2);
if ( v4 )
{
v8.sa_family = v4->h_addrtype;
memcpy(&v8.sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)v8.sa_data = func1(a3);
v5 = socket(2, 1, 0);
*a1 = v5;
if ( v5 < 0 )
{
fwrite("unable to create socket", 1uLL, 0x17uLL, stderr);
perror("oops ");
result = 0xFFFFFFFFLL;
}
else
{
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = func0(0);
*(_WORD *)addr.sa_data = func1(0);
if ( bind(v5, &addr, 0x10u) < 0 )
{
fprintf(stderr, "cannot bind port TCP %u\n", a3);
perror("oops ");
result = 0xFFFFFFFFLL;
}
else
{
v6 = connect(*a1, &v8, 0x10u);
result = 1LL;
if ( v6 < 0 )
{
perror("cannot connect ");
result = 0xFFFFFFFFLL;
}
}
}
}
else
{
fprintf(stderr, "unknown host '%s'\n", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
extern int
net_setup_connection(FDType *fd, char *host, PortType port)
{
    int rc;
    struct sockaddr_in localAddr, servAddr;
    struct hostent *h;
    h = gethostbyname(host);
    if (h == ((void *)0)) {
        fprintf(stderr, "unknown host '%s'\n", host);
        return -1;
    }
    servAddr.sin_family = h->h_addrtype;
    memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
    servAddr.sin_port = htons(port);
    *fd = socket(2, SOCK_STREAM, 0);
    if (*fd<0) {
        fprintf(stderr, "unable to create socket");
        perror("oops ");
        return -1;
    }
    localAddr.sin_family = 2;
    localAddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    localAddr.sin_port = htons(0);
    rc = bind(*fd, (struct sockaddr *)&localAddr, sizeof(localAddr));
    if (rc<0) {
        fprintf(stderr, "cannot bind port TCP %u\n", port);
        perror("oops ");
        return -1;
    }
    rc = connect(*fd, (struct sockaddr *) &servAddr, sizeof(servAddr));
    if (rc<0) {
        perror("cannot connect ");
        return -1;
    }
    return 1;
}

canonical_original_code:
extern int net_setup_connection(int *fd, char *host, int port)
{
    int rc;
    struct sockaddr_in localAddr; struct sockaddr_in servAddr;
    struct hostent *h;
    h = gethostbyname(host);
    if (h == ((void *)0)) {
        fprintf(stderr, "unknown host '%s'\n", host);
        return -1;
    }
    servAddr.sin_family = h->h_addrtype;
    memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
    servAddr.sin_port = htons(port);
    *fd = socket(2, SOCK_STREAM, 0);
    if (*fd<0) {
        fprintf(stderr, "unable to create socket");
        perror("oops ");
        return -1;
    }
    localAddr.sin_family = 2;
    localAddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    localAddr.sin_port = htons(0);
    rc = bind(*fd, (struct sockaddr *)&localAddr, sizeof(localAddr));
    if (rc<0) {
        fprintf(stderr, "cannot bind port TCP %u\n", port);
        perror("oops ");
        return -1;
    }
    rc = connect(*fd, (struct sockaddr *) &servAddr, sizeof(servAddr));
    if (rc<0) {
        perror("cannot connect ");
        return -1;
    }
    return 1;
}

variable_types:
host
char *

variable_types: port int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


decompiled_code:
size_t __fastcall net_writen(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax
int v7; // eax
int *v8; // rax

v3 = n;
if ( n )
{
v5 = n;
do
{
v6 = send(fd, buf, v5, 0x4000);
if ( v6 <= 0 )
{
if ( v6 >= 0 || (v7 = *_errno_location(), v7 != 4) && v7 != 11 )
{
v8 = _errno_location();
fprintf(stderr, "net_writen %d: ", (unsigned int)*v8);
perror("write");
return -1LL;
}
v6 = 0LL;
}
buf = (char *)buf + v6;
v5 -= v6;
}
while ( v5 );
}
return v3;
}

canonical_decompiled_code:
size_t __fastcall func6(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax
int v7; // eax
int *v8; // rax

v3 = n;
if ( n )
{
v5 = n;
do
{
v6 = send(fd, buf, v5, 0x4000);
if ( v6 <= 0 )
{
if ( v6 >= 0 || (v7 = *_errno_location(), v7 != 4) && v7 != 11 )
{
v8 = _errno_location();
fprintf(stderr, "net_writen %d: ", (unsigned int)*v8);
perror("write");
return -1LL;
}
v6 = 0LL;
}
buf = (char *)buf + v6;
v5 -= v6;
}
while ( v5 );
}
return v3;
}

original_code:
extern ssize_t
net_writen(FDType fd, const void *vptr, size_t n)
{
  size_t nleft;
  ssize_t nwritten;
  const char *ptr;
  ptr = vptr;
  nleft = n;
  while (nleft > 0) {
    if ( (nwritten = send(fd, ptr, nleft, MSG_NOSIGNAL)) <= 0) {
      if (nwritten < 0 && ((*__errno_location ()) == 4 || (*__errno_location ())==11 || (*__errno_location ())==11))
 nwritten = 0;
      else {
        fprintf(stderr, "net_writen %d: ", (*__errno_location ()));
 perror("write");
 return(-1);
      }
    }
    nleft -= nwritten;
    ptr += nwritten;
  }
  return(n);
}

canonical_original_code:
extern long net_writen(int fd, void *vptr, unsigned long n)
{
  unsigned long nleft;
  long nwritten;
  char *ptr;
  ptr = vptr;
  nleft = n;
  while (nleft > 0) {
    if ( (nwritten = send(fd, ptr, nleft, MSG_NOSIGNAL)) <= 0) {
      if (nwritten < 0 && ((*__errno_location ()) == 4 || (*__errno_location ())==11 || (*__errno_location ())==11))
 nwritten = 0;
      else {
        fprintf(stderr, "net_writen %d: ", (*__errno_location ()));
 perror("write");
 return(-1);
      }
    }
    nleft -= nwritten;
    ptr += nwritten;
  }
  return(n);
}

variable_types:
vptr
void *

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nwritten long

variable_types:
ptr
char *

return_type: long


decompiled_code:
size_t __fastcall net_readn(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
__int64 v6; // rdx
ssize_t v7; // rax

v3 = n;
if ( n )
{
v5 = n;
while ( 1 )
{
v7 = recv(fd, buf, v5, 0x4000);
if ( v7 < 0 )
{
v6 = (unsigned int)*_errno_location();
if ( (_DWORD)v6 != 4 && (_DWORD)v6 != 11 )
{
fprintf(stderr, "net_nread: %d", v6);
perror("read");
return -1LL;
}
v7 = 0LL;
}
else if ( !v7 )
{
return v3 - v5;
}
buf = (char *)buf + v7;
v5 -= v7;
if ( !v5 )
return v3 - v5;
}
}
v5 = 0LL;
return v3 - v5;
}

canonical_decompiled_code:
size_t __fastcall func7(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
__int64 v6; // rdx
ssize_t v7; // rax

v3 = n;
if ( n )
{
v5 = n;
while ( 1 )
{
v7 = recv(fd, buf, v5, 0x4000);
if ( v7 < 0 )
{
v6 = (unsigned int)*_errno_location();
if ( (_DWORD)v6 != 4 && (_DWORD)v6 != 11 )
{
fprintf(stderr, "net_nread: %d", v6);
perror("read");
return -1LL;
}
v7 = 0LL;
}
else if ( !v7 )
{
return v3 - v5;
}
buf = (char *)buf + v7;
v5 -= v7;
if ( !v5 )
return v3 - v5;
}
}
v5 = 0LL;
return v3 - v5;
}

original_code:
extern ssize_t
net_readn(FDType fd, void *vptr, size_t n)
{
  size_t nleft;
  ssize_t nread;
  char *ptr;
  ptr = vptr;
  nleft = n;
  while (nleft > 0) {
    if ( (nread = recv(fd, ptr, nleft, MSG_NOSIGNAL)) < 0) {
      if ((*__errno_location ()) == 4 || (*__errno_location ())==11 || (*__errno_location ())==11 )
 nread = 0;
      else {
 fprintf(stderr, "net_nread: %d", (*__errno_location ()));
 perror("read");
 return(-1);
      }
    } else if (nread == 0)
      break;
    nleft -= nread;
    ptr += nread;
  }
  return(n - nleft);
}

canonical_original_code:
extern long net_readn(int fd, void *vptr, unsigned long n)
{
  unsigned long nleft;
  long nread;
  char *ptr;
  ptr = vptr;
  nleft = n;
  while (nleft > 0) {
    if ( (nread = recv(fd, ptr, nleft, MSG_NOSIGNAL)) < 0) {
      if ((*__errno_location ()) == 4 || (*__errno_location ())==11 || (*__errno_location ())==11 )
 nread = 0;
      else {
 fprintf(stderr, "net_nread: %d", (*__errno_location ()));
 perror("read");
 return(-1);
      }
    } else if (nread == 0)
      break;
    nleft -= nread;
    ptr += nread;
  }
  return(n - nleft);
}

variable_types: fd int

variable_types: nread long


usage

decompiled_code:
int usage()
{
return puts(
"Usage: arduino-serial -p <serialport> [OPTIONS]\n"
"\n"
"Options:\n"
" -h, --help Print this help message\n"
" -p, --port=serialport Serial port Arduino is on\n"
" -b, --baud=baudrate Baudrate (bps) of Arduino\n"
" -s, --send=data Send data to Arduino\n"
" -r, --receive Receive data from Arduino & print it out\n"
" -n --num=num Send a number as a single byte\n"
" -d --delay=millis Delay for specified milliseconds\n"
"\n"
"Note: Order is important. Set '-b' before doing '-p'. \n"
" Used to make series of actions: '-d 2000 -s hello -d 100 -r' \n"
" means 'wait 2secs, send 'hello', wait 100msec, get reply'\n");
}

canonical_decompiled_code:
int func0()
{
return puts(
"Usage: arduino-serial -p <serialport> [OPTIONS]\n"
"\n"
"Options:\n"
" -h, --help Print this help message\n"
" -p, --port=serialport Serial port Arduino is on\n"
" -b, --baud=baudrate Baudrate (bps) of Arduino\n"
" -s, --send=data Send data to Arduino\n"
" -r, --receive Receive data from Arduino & print it out\n"
" -n --num=num Send a number as a single byte\n"
" -d --delay=millis Delay for specified milliseconds\n"
"\n"
"Note: Order is important. Set '-b' before doing '-p'. \n"
" Used to make series of actions: '-d 2000 -s hello -d 100 -r' \n"
" means 'wait 2secs, send 'hello', wait 100msec, get reply'\n");
}

original_code:
void usage(void) {
    printf("Usage: arduino-serial -p <serialport> [OPTIONS]\n"
    "\n"
    "Options:\n"
    "  -h, --help                   Print this help message\n"
    "  -p, --port=serialport        Serial port Arduino is on\n"
    "  -b, --baud=baudrate          Baudrate (bps) of Arduino\n"
    "  -s, --send=data              Send data to Arduino\n"
    "  -r, --receive                Receive data from Arduino & print it out\n"
    "  -n  --num=num                Send a number as a single byte\n"
    "  -d  --delay=millis           Delay for specified milliseconds\n"
    "\n"
    "Note: Order is important. Set '-b' before doing '-p'. \n"
    "      Used to make series of actions:  '-d 2000 -s hello -d 100 -r' \n"
    "      means 'wait 2secs, send 'hello', wait 100msec, get reply'\n"
    "\n");
}

canonical_original_code:
void usage() {
    printf("Usage: arduino-serial -p <serialport> [OPTIONS]\n"
    "\n"
    "Options:\n"
    "  -h, --help                   Print this help message\n"
    "  -p, --port=serialport        Serial port Arduino is on\n"
    "  -b, --baud=baudrate          Baudrate (bps) of Arduino\n"
    "  -s, --send=data              Send data to Arduino\n"
    "  -r, --receive                Receive data from Arduino & print it out\n"
    "  -n  --num=num                Send a number as a single byte\n"
    "  -d  --delay=millis           Delay for specified milliseconds\n"
    "\n"
    "Note: Order is important. Set '-b' before doing '-p'. \n"
    "      Used to make series of actions:  '-d 2000 -s hello -d 100 -r' \n"
    "      means 'wait 2secs, send 'hello', wait 100msec, get reply'\n"
    "\n");
}


decompiled_code:
__int64 __fastcall serialport_writebyte(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (unsigned int)-((unsigned int)write(a1, buf, 1uLL) != 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (unsigned int)-((unsigned int)write(a1, buf, 1uLL) != 1);
}

original_code:
int serialport_writebyte( int fd, uint8_t b)
{
    int n = write(fd,&b,1);
    if( n!=1)
        return -1;
    return 0;
}

canonical_original_code:
int serialport_writebyte(int fd, unsigned char b)
{
    int n = write(fd,&b,1);
    if( n!=1)
        return -1;
    return 0;
}

variable_types:
b
unsigned char

variable_types: n int


decompiled_code:
__int64 __fastcall serialport_write(int fd, char *s)
{
int v2; // ebx

v2 = strlen(s);
return (unsigned int)-(v2 != (unsigned int)write(fd, s, v2));
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, char *s)
{
int v2; // ebx

v2 = strlen(s);
return (unsigned int)-(v2 != (unsigned int)write(fd, s, v2));
}

original_code:
int serialport_write(int fd, const char* str)
{
    int len = strlen(str);
    int n = write(fd, str, len);
    if( n!=len )
        return -1;
    return 0;
}

canonical_original_code:
int serialport_write(int fd, char *str)
{
    int len = strlen(str);
    int n = write(fd, str, len);
    if( n!=len )
        return -1;
    return 0;
}

variable_types:
str
char *

variable_types: len int


decompiled_code:
ssize_t __fastcall serialport_write_loop(int fd)
{
ssize_t result; // rax
int v2; // ebx
int v3; // eax
_BYTE v4[104]; // [rsp+0h] [rbp-68h] BYREF

while ( 1 )
{
result = read(0, v4, 0x50uLL);
v2 = result;
if ( (int)result <= 0 )
break;
do
{
v3 = write(fd, v4, v2);
if ( v3 <= 0 )
usleep(0x2710u);
else
v2 -= v3;
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(int fd)
{
ssize_t result; // rax
int v2; // ebx
int v3; // eax
_BYTE v4[104]; // [rsp+0h] [rbp-68h] BYREF

while ( 1 )
{
result = read(0, v4, 0x50uLL);
v2 = result;
if ( (int)result <= 0 )
break;
do
{
v3 = write(fd, v4, v2);
if ( v3 <= 0 )
usleep(0x2710u);
else
v2 -= v3;
}
while ( v2 );
}
return result;
}

original_code:
void serialport_write_loop(int fd)
{
  char buf[80];
  int n,m;
  while ((n=read(0, buf, 80))>0) {
    while (n) {
      m=write(fd,buf,n);
      if (m<=0) {
 usleep(10 * 1000);
        continue;
      }
      n-=m;
    }
  }
}

canonical_original_code:
void serialport_write_loop(int fd)
{
  char buf[80];
  int n; int m;
  while ((n=read(0, buf, 80))>0) {
    while (n) {
      m=write(fd,buf,n);
      if (m<=0) {
 usleep(10 * 1000);
        continue;
      }
      n-=m;
    }
  }
}

variable_types:
buf
char [80]

variable_types: m int


decompiled_code:
ssize_t __fastcall serialport_read_loop(int fd)
{
ssize_t result; // rax
_BYTE v2[88]; // [rsp+0h] [rbp-58h] BYREF

while ( 1 )
{
result = read(fd, v2, 0x50uLL);
if ( (_DWORD)result == -1 )
break;
if ( (_DWORD)result )
write(1, v2, (int)result);
else
usleep(0x2710u);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func4(int fd)
{
ssize_t result; // rax
_BYTE v2[88]; // [rsp+0h] [rbp-58h] BYREF

while ( 1 )
{
result = read(fd, v2, 0x50uLL);
if ( (_DWORD)result == -1 )
break;
if ( (_DWORD)result )
write(1, v2, (int)result);
else
usleep(0x2710u);
}
return result;
}

original_code:
void serialport_read_loop(int fd)
{
  char b[80];
  int i=0;
  while (1) {
    int n = read(fd, b, 80);
    if( n==-1) return;
    if( n==0 ) {
      usleep( 10 * 1000 );
      continue;
    }
    write(1, b, n);
  }
}

canonical_original_code:
void serialport_read_loop(int fd)
{
  char b[80];
  int i = 0;
  while (1) {
    int n = read(fd, b, 80);
    if( n==-1) return;
    if( n==0 ) {
      usleep( 10 * 1000 );
      continue;
    }
    write(1, b, n);
  }
}

variable_types:
b
char [80]

variable_types: i int


decompiled_code:
__int64 __fastcall serialport_read_until(int fd, __int64 a2, char a3)
{
int v4; // ebx
unsigned int v5; // eax
unsigned int v6; // edx
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

v4 = 0;
while ( 1 )
{
v5 = read(fd, buf, 1uLL);
v6 = v5;
if ( v5 == -1 )
break;
if ( v5 )
*(_BYTE *)(a2 + v4++) = buf[0];
else
usleep(0x2710u);
if ( buf[0] == a3 )
{
*(_BYTE *)(a2 + v4) = 0;
return 0;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, __int64 a2, char a3)
{
int v4; // ebx
unsigned int v5; // eax
unsigned int v6; // edx
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

v4 = 0;
while ( 1 )
{
v5 = read(fd, buf, 1uLL);
v6 = v5;
if ( v5 == -1 )
break;
if ( v5 )
*(_BYTE *)(a2 + v4++) = buf[0];
else
usleep(0x2710u);
if ( buf[0] == a3 )
{
*(_BYTE *)(a2 + v4) = 0;
return 0;
}
}
return v6;
}

original_code:
int serialport_read_until(int fd, char* buf, char until)
{
    char b[1];
    int i=0;
    do {
        int n = read(fd, b, 1);
        if( n==-1) return -1;
        if( n==0 ) {
            usleep( 10 * 1000 );
            continue;
        }
        buf[i] = b[0]; i++;
    } while( b[0] != until );
    buf[i] = 0;
    return 0;
}

canonical_original_code:
int serialport_read_until(int fd, char *buf, char until)
{
    char b[1];
    int i = 0;
    do {
        int n = read(fd, b, 1);
        if( n==-1) return -1;
        if( n==0 ) {
            usleep( 10 * 1000 );
            continue;
        }
        buf[i] = b[0]; i++;
    } while( b[0] != until );
    buf[i] = 0;
    return 0;
}

variable_types:
buf
char *

variable_types: until char

variable_types:
b
char [1]


decompiled_code:
__int64 __fastcall serialport_init(const char *a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
speed_t v4; // ebp
struct termios v6; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 2306);
v3 = v2;
if ( v2 == -1 )
{
perror("init_serialport: Unable to open port ");
return v3;
}
if ( tcgetattr(v2, &v6) < 0 )
{
perror("init_serialport: Couldn't get term attributes");
return (unsigned int)-1;
}
if ( a2 == 38400 )
{
v4 = 15;
}
else if ( a2 > 38400 )
{
v4 = 4097;
if ( a2 != 57600 )
{
if ( a2 != 115200 )
{
LABEL_8:
v4 = a2;
goto LABEL_14;
}
v4 = 4098;
}
}
else
{
v4 = 13;
if ( a2 != 9600 )
{
v4 = 14;
if ( a2 != 19200 )
{
v4 = 12;
if ( a2 != 4800 )
goto LABEL_8;
}
}
}
LABEL_14:
cfsetispeed(&v6, v4);
cfsetospeed(&v6, v4);
*(_QWORD *)&v6.c_cflag = __PAIR64__(v6.c_lflag, v6.c_cflag & 0x7FFFFE8F | 0x8B0) & 0xFFFFFFE4FFFFFFFFLL;
v6.c_iflag &= 0xFFFFE3FF;
v6.c_oflag &= 0xFFFFFFFE;
v6.c_cc[6] = 0;
v6.c_cc[5] = 20;
if ( tcsetattr(v3, 0, &v6) < 0 )
{
perror("init_serialport: Couldn't set term attributes");
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
speed_t v4; // ebp
struct termios v6; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 2306);
v3 = v2;
if ( v2 == -1 )
{
perror("init_serialport: Unable to open port ");
return v3;
}
if ( tcgetattr(v2, &v6) < 0 )
{
perror("init_serialport: Couldn't get term attributes");
return (unsigned int)-1;
}
if ( a2 == 38400 )
{
v4 = 15;
}
else if ( a2 > 38400 )
{
v4 = 4097;
if ( a2 != 57600 )
{
if ( a2 != 115200 )
{
LABEL_8:
v4 = a2;
goto LABEL_14;
}
v4 = 4098;
}
}
else
{
v4 = 13;
if ( a2 != 9600 )
{
v4 = 14;
if ( a2 != 19200 )
{
v4 = 12;
if ( a2 != 4800 )
goto LABEL_8;
}
}
}
LABEL_14:
cfsetispeed(&v6, v4);
cfsetospeed(&v6, v4);
*(_QWORD *)&v6.c_cflag = __PAIR64__(v6.c_lflag, v6.c_cflag & 0x7FFFFE8F | 0x8B0) & 0xFFFFFFE4FFFFFFFFLL;
v6.c_iflag &= 0xFFFFE3FF;
v6.c_oflag &= 0xFFFFFFFE;
v6.c_cc[6] = 0;
v6.c_cc[5] = 20;
if ( tcsetattr(v3, 0, &v6) < 0 )
{
perror("init_serialport: Couldn't set term attributes");
v3 = -1;
}
return v3;
}

original_code:
int serialport_init(const char* serialport, int baud)
{
    struct termios toptions;
    int fd;
    fd = open(serialport, 02 | 0400 | 04000);
    if (fd == -1) {
        perror("init_serialport: Unable to open port ");
        return -1;
    }
    if (tcgetattr(fd, &toptions) < 0) {
        perror("init_serialport: Couldn't get term attributes");
        return -1;
    }
    speed_t brate = baud;
    switch(baud) {
    case 4800: brate=0000014; break;
    case 9600: brate=0000015; break;
    case 19200: brate=0000016; break;
    case 38400: brate=0000017; break;
    case 57600: brate=0010001; break;
    case 115200: brate=0010002; break;
    }
    cfsetispeed(&toptions, brate);
    cfsetospeed(&toptions, brate);
    toptions.c_cflag &= ~0000400;
    toptions.c_cflag &= ~0000100;
    toptions.c_cflag &= ~0000060;
    toptions.c_cflag |= 0000060;
    toptions.c_cflag &= ~020000000000;
    toptions.c_cflag |= 0000200 | 0004000;
    toptions.c_iflag &= ~(0002000 | 0010000 | 0004000);
    toptions.c_lflag &= ~(0000002 | 0000010 | 0000020 | 0000001);
    toptions.c_oflag &= ~0000001;
    toptions.c_cc[6] = 0;
    toptions.c_cc[5] = 20;
    if( tcsetattr(fd, 0, &toptions) < 0) {
        perror("init_serialport: Couldn't set term attributes");
        return -1;
    }
    return fd;
}

canonical_original_code:
int serialport_init(char *serialport, int baud)
{
    struct termios toptions;
    int fd;
    fd = open(serialport, 02 | 0400 | 04000);
    if (fd == -1) {
        perror("init_serialport: Unable to open port ");
        return -1;
    }
    if (tcgetattr(fd, &toptions) < 0) {
        perror("init_serialport: Couldn't get term attributes");
        return -1;
    }
    unsigned int brate = baud;
    switch(baud) {
    case 4800: brate=0000014; break;
    case 9600: brate=0000015; break;
    case 19200: brate=0000016; break;
    case 38400: brate=0000017; break;
    case 57600: brate=0010001; break;
    case 115200: brate=0010002; break;
    }
    cfsetispeed(&toptions, brate);
    cfsetospeed(&toptions, brate);
    toptions.c_cflag &= ~0000400;
    toptions.c_cflag &= ~0000100;
    toptions.c_cflag &= ~0000060;
    toptions.c_cflag |= 0000060;
    toptions.c_cflag &= ~020000000000;
    toptions.c_cflag |= 0000200 | 0004000;
    toptions.c_iflag &= ~(0002000 | 0010000 | 0004000);
    toptions.c_lflag &= ~(0000002 | 0000010 | 0000020 | 0000001);
    toptions.c_oflag &= ~0000001;
    toptions.c_cc[6] = 0;
    toptions.c_cc[5] = 20;
    if( tcsetattr(fd, 0, &toptions) < 0) {
        perror("init_serialport: Couldn't set term attributes");
        return -1;
    }
    return fd;
}

variable_types:
serialport
char *

variable_types: baud int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types:
brate
unsigned int


original_code:
qboolean zbc_ZbotCheck(int client, usercmd_t *ucmd) {
    int tog0, tog1;
    tog0 = proxyinfo[client].zbc_tog;
    proxyinfo[client].zbc_tog ^= 1;
    tog1 = proxyinfo[client].zbc_tog;
    if (ucmd->angles[0] == proxyinfo[client].zbc_angles[tog1][0] &&
            ucmd->angles[1] == proxyinfo[client].zbc_angles[tog1][1] &&
            ucmd->angles[0] != proxyinfo[client].zbc_angles[tog0][0] &&
            ucmd->angles[1] != proxyinfo[client].zbc_angles[tog0][1] &&
            abs(ucmd->angles[0] - proxyinfo[client].zbc_angles[tog0][0]) +
            abs(ucmd->angles[1] - proxyinfo[client].zbc_angles[tog0][1]) >= zbc_jittermove) {
        if (ltime <= proxyinfo[client].zbc_jitter_last + 0.1) {
            if (!proxyinfo[client].zbc_jitter)
                proxyinfo[client].zbc_jitter_time = ltime;
            if (proxyinfo[client].zbc_jitter++ >= zbc_jittermax)
                return qtrue;
        }
        proxyinfo[client].zbc_jitter_last = ltime;
    }
    proxyinfo[client].zbc_angles[tog1][0] = ucmd->angles[0];
    proxyinfo[client].zbc_angles[tog1][1] = ucmd->angles[1];
    if (ltime > (proxyinfo[client].zbc_jitter_time + zbc_jittertime))
        proxyinfo[client].zbc_jitter = 0;
    return qfalse;
}

canonical_original_code:
enum qboolean zbc_ZbotCheck(int client, struct usercmd_s *ucmd) {
    int tog0; int tog1;
    tog0 = proxyinfo[client].zbc_tog;
    proxyinfo[client].zbc_tog ^= 1;
    tog1 = proxyinfo[client].zbc_tog;
    if (ucmd->angles[0] == proxyinfo[client].zbc_angles[tog1][0] &&
            ucmd->angles[1] == proxyinfo[client].zbc_angles[tog1][1] &&
            ucmd->angles[0] != proxyinfo[client].zbc_angles[tog0][0] &&
            ucmd->angles[1] != proxyinfo[client].zbc_angles[tog0][1] &&
            abs(ucmd->angles[0] - proxyinfo[client].zbc_angles[tog0][0]) +
            abs(ucmd->angles[1] - proxyinfo[client].zbc_angles[tog0][1]) >= zbc_jittermove) {
        if (ltime <= proxyinfo[client].zbc_jitter_last + 0.1) {
            if (!proxyinfo[client].zbc_jitter)
                proxyinfo[client].zbc_jitter_time = ltime;
            if (proxyinfo[client].zbc_jitter++ >= zbc_jittermax)
                return qtrue;
        }
        proxyinfo[client].zbc_jitter_last = ltime;
    }
    proxyinfo[client].zbc_angles[tog1][0] = ucmd->angles[0];
    proxyinfo[client].zbc_angles[tog1][1] = ucmd->angles[1];
    if (ltime > (proxyinfo[client].zbc_jitter_time + zbc_jittertime))
        proxyinfo[client].zbc_jitter = 0;
    return qfalse;
}

variable_types: client int

variable_types: struct usercmd_s { unsigned char msec; unsigned char buttons; short angles[3]; short forwardmove; unsigned char impulse; unsigned char lightlevel; } *

return_type: enum qboolean { qfalse=0, qtrue=1 }


decompiled_code:
char *__fastcall q2a_inet_ntop4(unsigned __int8 *a1, char *a2, unsigned int a3)
{
unsigned __int64 v4; // rdx
char *result; // rax
char v6[40]; // [rsp+0h] [rbp-28h] BYREF

v4 = sprintf(v6, "%u.%u.%u.%u", *a1, a1[1], a1[2], a1[3]);
result = 0LL;
if ( v4 < a3 )
result = strcpy(a2, v6);
return result;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int8 *a1, char *a2, unsigned int a3)
{
unsigned __int64 v4; // rdx
char *result; // rax
char v6[40]; // [rsp+0h] [rbp-28h] BYREF

v4 = sprintf(v6, "%u.%u.%u.%u", *a1, a1[1], a1[2], a1[3]);
result = 0LL;
if ( v4 < a3 )
result = strcpy(a2, v6);
return result;
}

original_code:
static const char *q2a_inet_ntop4 (const u_char *src, char *dst, socklen_t size)
{
        static const char fmt[] = "%u.%u.%u.%u";
        char tmp[sizeof "255.255.255.255"];
        if (((size_t)sprintf (tmp, fmt, src[0], src[1], src[2], src[3])) >= size) {
                return (((void *)0));
        }
        return strcpy(dst, tmp);
}

canonical_original_code:
static char *q2a_inet_ntop4(unsigned char *src, char *dst, unsigned int size)
{
        static char fmt[] = "%u.%u.%u.%u";
        char tmp[-1];
        if (((unsigned long)sprintf (tmp, fmt, src[0], src[1], src[2], src[3])) >= size) {
                return (((void *)0));
        }
        return strcpy(dst, tmp);
}

variable_types:
src
unsigned char *

variable_types:
dst
char *

variable_types:
size
unsigned int

variable_types:
fmt
char []

variable_types:
tmp
char [-1]


original_code:
static const char *q2a_inet_ntop6 (const u_char *src, char *dst, socklen_t size)
{
        char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
        struct { int base, len; } best, cur;
        u_int words[16 / 2];
        int i;
        memset(words, '\0', sizeof words);
        for (i = 0; i < 16; i += 2)
                words[i / 2] = (src[i] << 8) | src[i + 1];
        best.base = -1;
        cur.base = -1;
        best.len = 0;
        cur.len = 0;
        for (i = 0; i < (16 / 2); i++) {
                if (words[i] == 0) {
                        if (cur.base == -1)
                                cur.base = i, cur.len = 1;
                        else
                                cur.len++;
                } else {
                        if (cur.base != -1) {
                                if (best.base == -1 || cur.len > best.len)
                                        best = cur;
                                cur.base = -1;
                        }
                }
        }
        if (cur.base != -1) {
                if (best.base == -1 || cur.len > best.len)
                        best = cur;
        }
        if (best.base != -1 && best.len < 2)
                best.base = -1;
        tp = tmp;
        for (i = 0; i < (16 / 2); i++) {
                if (best.base != -1 && i >= best.base &&
                    i < (best.base + best.len)) {
                        if (i == best.base)
                                *tp++ = ':';
                        continue;
                }
                if (i != 0)
                        *tp++ = ':';
                if (i == 6 && best.base == 0 &&
                    (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
                        if (!q2a_inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
                                return (((void *)0));
                        tp += strlen(tp);
                        break;
                }
                tp += ((size_t)sprintf (tp, "%x", words[i]));
        }
        if (best.base != -1 && (best.base + best.len) ==
            (16 / 2))
                *tp++ = ':';
        *tp++ = '\0';
        if ((socklen_t)(tp - tmp) > size) {
                return (((void *)0));
        }
        return strcpy(dst, tmp);
}

canonical_original_code:
static char *q2a_inet_ntop6(unsigned char *src, char *dst, unsigned int size)
{
        char tmp[-1]; char *tp;
        struct { int base; } best; struct { int base; } cur;
        unsigned int words[-1];
        int i;
        memset(words, '\0', sizeof words);
        for (i = 0; i < 16; i += 2)
                words[i / 2] = (src[i] << 8) | src[i + 1];
        best.base = -1;
        cur.base = -1;
        best.len = 0;
        cur.len = 0;
        for (i = 0; i < (16 / 2); i++) {
                if (words[i] == 0) {
                        if (cur.base == -1)
                                cur.base = i, cur.len = 1;
                        else
                                cur.len++;
                } else {
                        if (cur.base != -1) {
                                if (best.base == -1 || cur.len > best.len)
                                        best = cur;
                                cur.base = -1;
                        }
                }
        }
        if (cur.base != -1) {
                if (best.base == -1 || cur.len > best.len)
                        best = cur;
        }
        if (best.base != -1 && best.len < 2)
                best.base = -1;
        tp = tmp;
        for (i = 0; i < (16 / 2); i++) {
                if (best.base != -1 && i >= best.base &&
                    i < (best.base + best.len)) {
                        if (i == best.base)
                                *tp++ = ':';
                        continue;
                }
                if (i != 0)
                        *tp++ = ':';
                if (i == 6 && best.base == 0 &&
                    (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
                        if (!q2a_inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
                                return (((void *)0));
                        tp += strlen(tp);
                        break;
                }
                tp += ((unsigned long)sprintf (tp, "%x", words[i]));
        }
        if (best.base != -1 && (best.base + best.len) ==
            (16 / 2))
                *tp++ = ':';
        *tp++ = '\0';
        if ((socklen_t)(tp - tmp) > size) {
                return (((void *)0));
        }
        return strcpy(dst, tmp);
}

variable_types:
tp
char *

variable_types:
best
struct { int base; }

variable_types:
cur
struct { int base; }

variable_types:
words
unsigned int [-1]


decompiled_code:
char *__fastcall inet_ntop(int a1, unsigned __int8 *a2, char *a3, unsigned int a4)
{
if ( a1 == 2 )
return q2a_inet_ntop4(a2, a3, a4);
if ( a1 == 10 )
return q2a_inet_ntop6((__int64)a2, a3, a4);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func2(int a1, unsigned __int8 *a2, char *a3, unsigned int a4)
{
if ( a1 == 2 )
return func0(a2, a3, a4);
if ( a1 == 10 )
return func1((__int64)a2, a3, a4);
return 0LL;
}

original_code:
const char *inet_ntop (int af, const void *src, char *dst, socklen_t size)
{
        switch (af) {
        case 2:
                return (q2a_inet_ntop4(src, dst, size));
        case 10:
                return (q2a_inet_ntop6(src, dst, size));
        default:
                return (((void *)0));
        }
}

canonical_original_code:
char *inet_ntop(int af, void *src, char *dst, unsigned int size)
{
        switch (af) {
        case 2:
                return (q2a_inet_ntop4(src, dst, size));
        case 10:
                return (q2a_inet_ntop6(src, dst, size));
        default:
                return (((void *)0));
        }
}

variable_types: af int

variable_types:
src
void *


freeDisableLists

decompiled_code:
__int64 freeDisableLists()
{
__int64 result; // rax
regex_t *v1; // rdi

while ( 1 )
{
result = (unsigned int)maxdisable_cmds[0];
if ( !maxdisable_cmds[0] )
break;
--maxdisable_cmds[0];
gi[34](*((const char **)&disablecmds + 3 * (int)result - 3));
v1 = (regex_t *)*((_QWORD *)&disablecmds + 3 * maxdisable_cmds[0] + 2);
if ( v1 )
{
regfree(v1);
gi[34](*((const char **)&disablecmds + 3 * maxdisable_cmds[0] + 2));
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
regex_t *v1; // rdi

while ( 1 )
{
result = (unsigned int)maxdisable_cmds[0];
if ( !maxdisable_cmds[0] )
break;
--maxdisable_cmds[0];
gi[34](*((const char **)&disablecmds + 3 * (int)result - 3));
v1 = (regex_t *)*((_QWORD *)&disablecmds + 3 * maxdisable_cmds[0] + 2);
if ( v1 )
{
regfree(v1);
gi[34](*((const char **)&disablecmds + 3 * maxdisable_cmds[0] + 2));
}
}
return result;
}

original_code:
void freeDisableLists(void) {
    while (maxdisable_cmds) {
        maxdisable_cmds--;
        gi.TagFree(disablecmds[maxdisable_cmds].disablecmd);
        if (disablecmds[maxdisable_cmds].r) {
            regfree(disablecmds[maxdisable_cmds].r);
            gi.TagFree(disablecmds[maxdisable_cmds].r);
        }
    }
}

canonical_original_code:
void freeDisableLists() {
    while (maxdisable_cmds) {
        maxdisable_cmds--;
        gi.TagFree(disablecmds[maxdisable_cmds].disablecmd);
        if (disablecmds[maxdisable_cmds].r) {
            regfree(disablecmds[maxdisable_cmds].r);
            gi.TagFree(disablecmds[maxdisable_cmds].r);
        }
    }
}