decompiled_code:
__int64 __fastcall iC_Drive(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
sendSerial((unsigned int)iCreateCom, 137LL);
sendSerial((unsigned int)iCreateCom, a1);
sendSerial((unsigned int)iCreateCom, a2);
sendSerial((unsigned int)iCreateCom, a3);
return sendSerial((unsigned int)iCreateCom, a4);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
sendSerial((unsigned int)iCreateCom, 137LL);
sendSerial((unsigned int)iCreateCom, a1);
sendSerial((unsigned int)iCreateCom, a2);
sendSerial((unsigned int)iCreateCom, a3);
return sendSerial((unsigned int)iCreateCom, a4);
}

original_code:
void iC_Drive(unsigned char velocity_h, unsigned char velocity_l, unsigned char radius_h, unsigned char radius_l)
{
  sendSerial(iCreateCom,137);
  sendSerial(iCreateCom,velocity_h);
  sendSerial(iCreateCom,velocity_l);
  sendSerial(iCreateCom,radius_h);
  sendSerial(iCreateCom,radius_l);
}


repo: Elektordi/robotcite

decompiled_code:
__int64 __fastcall iC_DriveDirect(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
sendSerial((unsigned int)iCreateCom, 145LL);
sendSerial((unsigned int)iCreateCom, a1);
sendSerial((unsigned int)iCreateCom, a2);
sendSerial((unsigned int)iCreateCom, a3);
return sendSerial((unsigned int)iCreateCom, a4);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
sendSerial((unsigned int)iCreateCom, 145LL);
sendSerial((unsigned int)iCreateCom, a1);
sendSerial((unsigned int)iCreateCom, a2);
sendSerial((unsigned int)iCreateCom, a3);
return sendSerial((unsigned int)iCreateCom, a4);
}

original_code:
void iC_DriveDirect(unsigned char rVelocity_h, unsigned char rVelocity_l, unsigned char lVelocity_h, unsigned char lVelocity_l)
{
  sendSerial(iCreateCom,145);
  sendSerial(iCreateCom,rVelocity_h);
  sendSerial(iCreateCom,rVelocity_l);
  sendSerial(iCreateCom,lVelocity_h);
 sendSerial(iCreateCom,lVelocity_l);
}

return_type: void


decompiled_code:
__int64 __fastcall iC_LEDs(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3)
{
sendSerial((unsigned int)iCreateCom, 139LL);
sendSerial((unsigned int)iCreateCom, a1);
sendSerial((unsigned int)iCreateCom, a2);
return sendSerial((unsigned int)iCreateCom, a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3)
{
sendSerial((unsigned int)iCreateCom, 139LL);
sendSerial((unsigned int)iCreateCom, a1);
sendSerial((unsigned int)iCreateCom, a2);
return sendSerial((unsigned int)iCreateCom, a3);
}

original_code:
void iC_LEDs(unsigned char LEDBits, unsigned char powerCol, unsigned char powerInt)
{
  sendSerial(iCreateCom,139);
  sendSerial(iCreateCom,LEDBits);
  sendSerial(iCreateCom,powerCol);
  sendSerial(iCreateCom,powerInt);
}

variable_types:
LEDBits
unsigned char

variable_types:
powerCol
unsigned char

variable_types:
powerInt
unsigned char


decompiled_code:
__int64 __fastcall iC_PWMLowSide(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3)
{
sendSerial((unsigned int)iCreateCom, 144LL);
sendSerial((unsigned int)iCreateCom, a1);
sendSerial((unsigned int)iCreateCom, a2);
return sendSerial((unsigned int)iCreateCom, a3);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3)
{
sendSerial((unsigned int)iCreateCom, 144LL);
sendSerial((unsigned int)iCreateCom, a1);
sendSerial((unsigned int)iCreateCom, a2);
return sendSerial((unsigned int)iCreateCom, a3);
}

original_code:
void iC_PWMLowSide(unsigned char LSD2Duty, unsigned char LSD1Duty, unsigned char LSD0Duty)
{
  sendSerial(iCreateCom,144);
  sendSerial(iCreateCom,LSD2Duty);
  sendSerial(iCreateCom,LSD1Duty);
  sendSerial(iCreateCom,LSD0Duty);
}


decompiled_code:
__int64 __fastcall iC_LowSideDrivers(unsigned __int8 a1)
{
sendSerial((unsigned int)iCreateCom, 138LL);
return sendSerial((unsigned int)iCreateCom, a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int8 a1)
{
sendSerial((unsigned int)iCreateCom, 138LL);
return sendSerial((unsigned int)iCreateCom, a1);
}

original_code:
void iC_LowSideDrivers(unsigned char driverBits)
{
  sendSerial(iCreateCom,138);
  sendSerial(iCreateCom,driverBits);
}

variable_types:
driverBits
unsigned char


decompiled_code:
__int64 __fastcall iC_SendIR(unsigned __int8 a1)
{
sendSerial((unsigned int)iCreateCom, 151LL);
return sendSerial((unsigned int)iCreateCom, a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 a1)
{
sendSerial((unsigned int)iCreateCom, 151LL);
return sendSerial((unsigned int)iCreateCom, a1);
}

original_code:
void iC_SendIR(unsigned char byteValue)
{
  sendSerial(iCreateCom,151);
  sendSerial(iCreateCom,byteValue);
}

variable_types:
byteValue
unsigned char


decompiled_code:
__int64 __fastcall iC_Sensor(unsigned __int8 a1)
{
sendSerial((unsigned int)iCreateCom, 142LL);
return sendSerial((unsigned int)iCreateCom, a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int8 a1)
{
sendSerial((unsigned int)iCreateCom, 142LL);
return sendSerial((unsigned int)iCreateCom, a1);
}

original_code:
void iC_Sensor(unsigned char sensorId)
{
  sendSerial(iCreateCom,142);
  sendSerial(iCreateCom,sensorId);
}

variable_types:
sensorId
unsigned char


decompiled_code:
__int64 iC_getBumpsAndWDrops()
{
iC_Sensor(7u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func15()
{
func14(7u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getBumpsAndWDrops()
{
  iC_Sensor(7);
  return receiveSerial(iCreateCom);
}

return_type: unsigned char


decompiled_code:
__int64 iC_getWall()
{
iC_Sensor(8u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func16()
{
func14(8u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getWall()
{
  iC_Sensor(8);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getCliffL()
{
iC_Sensor(9u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func17()
{
func14(9u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getCliffL()
{
  iC_Sensor(9);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getCliffFL()
{
iC_Sensor(0xAu);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func18()
{
func14(0xAu);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getCliffFL()
{
  iC_Sensor(10);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getCliffFR()
{
iC_Sensor(0xBu);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func19()
{
func14(0xBu);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getCliffFR()
{
  iC_Sensor(11);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getCliffR()
{
iC_Sensor(0xCu);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func20()
{
func14(0xCu);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getCliffR()
{
  iC_Sensor(12);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getVirtualWall()
{
iC_Sensor(0xDu);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func21()
{
func14(0xDu);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getVirtualWall()
{
  iC_Sensor(13);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getOvercurrents()
{
iC_Sensor(0xEu);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func22()
{
func14(0xEu);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getOvercurrents()
{
  iC_Sensor(14);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getButtons()
{
iC_Sensor(0x12u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func24()
{
func14(0x12u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getButtons()
{
  iC_Sensor(18);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getDistance()
{
int v0; // ebx

iC_Sensor(0x13u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

canonical_decompiled_code:
__int64 func25()
{
int v0; // ebx

func14(0x13u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

original_code:
signed short iC_getDistance()
{
  iC_Sensor(19);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom) - 0x7FFF;
}

return_type: short


decompiled_code:
__int64 iC_getAngle()
{
int v0; // ebx

iC_Sensor(0x14u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

canonical_decompiled_code:
__int64 func26()
{
int v0; // ebx

func14(0x14u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

original_code:
signed short iC_getAngle()
{
  iC_Sensor(20);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom) - 0x7FFF;
}


decompiled_code:
__int64 iC_getVoltage()
{
int v0; // ebx

iC_Sensor(0x16u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func28()
{
int v0; // ebx

func14(0x16u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned short iC_getVoltage()
{
  iC_Sensor(22);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom);
}

return_type: unsigned short


decompiled_code:
__int64 iC_getCurrent()
{
int v0; // ebx

iC_Sensor(0x17u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

canonical_decompiled_code:
__int64 func29()
{
int v0; // ebx

func14(0x17u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

original_code:
signed short iC_getCurrent()
{
  iC_Sensor(23);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom) - 0x7FFF;
}


decompiled_code:
__int64 iC_getBattTemp()
{
iC_Sensor(0x18u);
return (unsigned int)receiveSerial((unsigned int)iCreateCom) - 127;
}

canonical_decompiled_code:
__int64 func30()
{
func14(0x18u);
return (unsigned int)receiveSerial((unsigned int)iCreateCom) - 127;
}

original_code:
signed char iC_getBattTemp()
{
  iC_Sensor(24);
  return receiveSerial(iCreateCom) - 0x7F;
}

return_type: char


decompiled_code:
__int64 iC_getBattCap()
{
int v0; // ebx

iC_Sensor(0x1Au);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func32()
{
int v0; // ebx

func14(0x1Au);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned short iC_getBattCap()
{
  iC_Sensor(26);
 return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getCliffLSig()
{
int v0; // ebx

iC_Sensor(0x1Cu);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func34()
{
int v0; // ebx

func14(0x1Cu);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned short iC_getCliffLSig()
{
  iC_Sensor(28);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getCliffFLSig()
{
int v0; // ebx

iC_Sensor(0x1Du);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func35()
{
int v0; // ebx

func14(0x1Du);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned short iC_getCliffFLSig()
{
  iC_Sensor(29);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getCliffFRSig()
{
int v0; // ebx

iC_Sensor(0x1Eu);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func36()
{
int v0; // ebx

func14(0x1Eu);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned short iC_getCliffFRSig()
{
  iC_Sensor(30);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getCliffRSig()
{
int v0; // ebx

iC_Sensor(0x1Fu);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func37()
{
int v0; // ebx

func14(0x1Fu);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned short iC_getCliffRSig()
{
  iC_Sensor(31);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getDigitalIn()
{
iC_Sensor(0x20u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func38()
{
func14(0x20u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getDigitalIn()
{
  iC_Sensor(32);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getAnalogIn()
{
int v0; // ebx

iC_Sensor(0x21u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func39()
{
int v0; // ebx

func14(0x21u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned short iC_getAnalogIn()
{
  iC_Sensor(33);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getChargeSrcAvailable()
{
iC_Sensor(0x22u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func40()
{
func14(0x22u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getChargeSrcAvailable()
{
  iC_Sensor(34);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getOIMode()
{
iC_Sensor(0x23u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func41()
{
func14(0x23u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getOIMode()
{
  iC_Sensor(35);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getSongNumber()
{
iC_Sensor(0x24u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func42()
{
func14(0x24u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getSongNumber()
{
  iC_Sensor(36);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getSongPlaying()
{
iC_Sensor(0x25u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func43()
{
func14(0x25u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getSongPlaying()
{
  iC_Sensor(37);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getNStreamPackets()
{
iC_Sensor(0x26u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func44()
{
func14(0x26u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getNStreamPackets()
{
  iC_Sensor(38);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getVelocity()
{
int v0; // ebx

iC_Sensor(0x27u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

canonical_decompiled_code:
__int64 func45()
{
int v0; // ebx

func14(0x27u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

original_code:
signed short iC_getVelocity()
{
  iC_Sensor(39);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom) - 0x7FFF;
}


decompiled_code:
__int64 iC_getRadius()
{
int v0; // ebx

iC_Sensor(0x28u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

canonical_decompiled_code:
__int64 func46()
{
int v0; // ebx

func14(0x28u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

original_code:
signed short iC_getRadius()
{
  iC_Sensor(40);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom) - 0x7FFF;
}


decompiled_code:
__int64 iC_getRVelocity()
{
int v0; // ebx

iC_Sensor(0x29u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

canonical_decompiled_code:
__int64 func47()
{
int v0; // ebx

func14(0x29u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

original_code:
signed short iC_getRVelocity()
{
  iC_Sensor(41);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom) - 0x7FFF;
}


decompiled_code:
__int64 iC_getLVelocity()
{
int v0; // ebx

iC_Sensor(0x2Au);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

canonical_decompiled_code:
__int64 func48()
{
int v0; // ebx

func14(0x2Au);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom) - 0x7FFF;
}

original_code:
signed short iC_getLVelocity()
{
  iC_Sensor(42);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom) - 0x7FFF;
}


decompiled_code:
__int64 iC_Full()
{
return sendSerial((unsigned int)iCreateCom, 132LL);
}

canonical_decompiled_code:
__int64 func5()
{
return sendSerial((unsigned int)iCreateCom, 132LL);
}

original_code:
void iC_Full(void)
{
  sendSerial(iCreateCom,132);
}

canonical_original_code:
void iC_Full()
{
  sendSerial(iCreateCom,132);
}


decompiled_code:
__int64 __fastcall iC_Demo(unsigned __int8 a1)
{
sendSerial((unsigned int)iCreateCom, 136LL);
return sendSerial((unsigned int)iCreateCom, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1)
{
sendSerial((unsigned int)iCreateCom, 136LL);
return sendSerial((unsigned int)iCreateCom, a1);
}

original_code:
void iC_Demo(unsigned char demoID)
{
  sendSerial(iCreateCom,136);
  sendSerial(iCreateCom,demoID);
}

variable_types:
demoID
unsigned char


decompiled_code:
__int64 __fastcall iC_DigitalOut(unsigned __int8 a1)
{
sendSerial((unsigned int)iCreateCom, 147LL);
return sendSerial((unsigned int)iCreateCom, a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 a1)
{
sendSerial((unsigned int)iCreateCom, 147LL);
return sendSerial((unsigned int)iCreateCom, a1);
}

original_code:
void iC_DigitalOut(unsigned char outBits)
{
  sendSerial(iCreateCom,147);
  sendSerial(iCreateCom,outBits);
}

variable_types:
outBits
unsigned char


decompiled_code:
__int64 iC_getIRByte()
{
iC_Sensor(0x11u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func23()
{
func14(0x11u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getIRByte()
{
  iC_Sensor(17);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getChargeState()
{
iC_Sensor(0x15u);
return receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func27()
{
func14(0x15u);
return receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned char iC_getChargeState()
{
  iC_Sensor(21);
  return receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getBattCharge()
{
int v0; // ebx

iC_Sensor(0x19u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func31()
{
int v0; // ebx

func14(0x19u);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned short iC_getBattCharge()
{
  iC_Sensor(25);
 return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom);
}


decompiled_code:
__int64 iC_getWallSig()
{
int v0; // ebx

iC_Sensor(0x1Bu);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

canonical_decompiled_code:
__int64 func33()
{
int v0; // ebx

func14(0x1Bu);
v0 = receiveSerial((unsigned int)iCreateCom);
return (v0 << 8) + (unsigned int)(unsigned __int8)receiveSerial((unsigned int)iCreateCom);
}

original_code:
unsigned short iC_getWallSig()
{
  iC_Sensor(27);
  return (receiveSerial(iCreateCom)<<8) + receiveSerial(iCreateCom);
}


original_code:
void init_erc_shared()
{
 ERC->alive = 0;
 strcpy(ERC->status,"");
 ERC->id_status = -1;
 ERC->Battery = 0;
 ERC->ManualControl = 0;
 ERC->vl = 0;
 ERC->vr = 0;
 ERC->plante_a_portee = -1;
 int i;
 for(i=0;i<5;i++)
 {
  ERC->level_w[i]=100;
  ERC->level_p[i]=100;
  ERC->level_n[i]=100;
  ERC->level_k[i]=100;
 }
}

variable_types: i int


decompiled_code:
void *shm_master()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 950);
if ( v0 < 0 )
{
puts("Shared memory create failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

canonical_decompiled_code:
void *func2()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 950);
if ( v0 < 0 )
{
puts("Shared memory create failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

original_code:
void shm_master()
{
 int mem_ID;
 void* ptr_mem_partagee;
 if ((mem_ID = shmget(shm_key, sizeof(ERC), 0666 | 01000)) < 0)
 {
  printf("Shared memory create failed!\n");
  abort();
 }
 if ((ptr_mem_partagee = shmat(mem_ID, ((void *)0), 0)) == (void*) -1)
 {
  printf("Shared memory attach failed!\n");
  abort();
 }
 ERC = ptr_mem_partagee;
}

canonical_original_code:
void shm_master()
{
 int mem_ID;
 void *ptr_mem_partagee;
 if ((mem_ID = shmget(shm_key, sizeof(ERC), 0666 | 01000)) < 0)
 {
  printf("Shared memory create failed!\n");
  abort();
 }
 if ((ptr_mem_partagee = shmat(mem_ID, ((void *)0), 0)) == (void *) -1)
 {
  printf("Shared memory attach failed!\n");
  abort();
 }
 ERC = ptr_mem_partagee;
}


decompiled_code:
void *shm_slave()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 438);
if ( v0 < 0 )
{
puts("Shared memory get failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

canonical_decompiled_code:
void *func3()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 438);
if ( v0 < 0 )
{
puts("Shared memory get failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

original_code:
void shm_slave()
{
 int mem_ID;
 void* ptr_mem_partagee;
 if ((mem_ID = shmget(shm_key, sizeof(ERC), 0666)) < 0)
 {
  printf("Shared memory get failed!\n");
  abort();
 }
 if ((ptr_mem_partagee = shmat(mem_ID, ((void *)0), 0)) == (void*) -1)
 {
  printf("Shared memory attach failed!\n");
  abort();
 }
 ERC = ptr_mem_partagee;
}

canonical_original_code:
void shm_slave()
{
 int mem_ID;
 void *ptr_mem_partagee;
 if ((mem_ID = shmget(shm_key, sizeof(ERC), 0666)) < 0)
 {
  printf("Shared memory get failed!\n");
  abort();
 }
 if ((ptr_mem_partagee = shmat(mem_ID, ((void *)0), 0)) == (void *) -1)
 {
  printf("Shared memory attach failed!\n");
  abort();
 }
 ERC = ptr_mem_partagee;
}


decompiled_code:
int shm_leave()
{
return shmdt(ERC);
}

canonical_decompiled_code:
int func4()
{
return shmdt(ERC);
}

original_code:
void shm_leave()
{
 shmdt(ERC);
}

canonical_original_code:
void shm_leave()
{
 shmdt(ERC);
}


decompiled_code:
void *__fastcall set_status(char a1, const char *a2)
{
void *result; // rax

strcpy(robot_status, a2);
result = ERC;
*((_BYTE *)ERC + 129) = a1;
return result;
}

canonical_decompiled_code:
void *__fastcall func7(char a1, const char *a2)
{
void *result; // rax

strcpy(robot_status, a2);
result = ERC;
*((_BYTE *)ERC + 129) = a1;
return result;
}

original_code:
void set_status(int id, const char* status)
{
 strcpy(robot_status,status);
 ERC->id_status = id;
}

canonical_original_code:
void set_status(int id, char *status)
{
 strcpy(robot_status,status);
 ERC->id_status = id;
}

variable_types: id int

variable_types:
status
char *


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

set_status(3, "Backwarding");
if ( ++backstep > 9 )
result = drive_direct(-100 * lastrot, 100 * lastrot);
else
result = drive_direct(0xFFFFFF9C, 0xFFFFFF9C);
if ( backstep > 20 )
{
result = drive_direct(0, 0);
backstep = 0;
state = (__int64)state_search;
}
return result;
}

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

func7(3, "Backwarding");
if ( ++backstep > 9 )
result = func8(-100 * lastrot, 100 * lastrot);
else
result = func8(0xFFFFFF9C, 0xFFFFFF9C);
if ( backstep > 20 )
{
result = func8(0, 0);
backstep = 0;
state = (__int64)state_search;
}
return result;
}

original_code:
void state_back()
{
 set_status(3,"Backwarding");
 backstep++;
 if(backstep<10)
 {
  drive_direct(-100,-100);
 }
 else
 {
  drive_direct(-100*lastrot,100*lastrot);
 }
 if(backstep>20)
 {
  drive_direct(0,0);
  backstep=0;
  state = state_search;
 }
}


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

set_status(7, "Disengaging");
if ( ++undock_step > 19 )
result = drive_direct(0x64u, 0xFFFFFF9C);
else
result = drive_direct(0xFFFFFF9C, 0xFFFFFF9C);
if ( undock_step > 30 )
{
result = drive_direct(0, 0);
undock_step = 0;
state = (__int64)state_search;
}
return result;
}

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

func7(7, "Disengaging");
if ( ++undock_step > 19 )
result = func8(0x64u, 0xFFFFFF9C);
else
result = func8(0xFFFFFF9C, 0xFFFFFF9C);
if ( undock_step > 30 )
{
result = func8(0, 0);
undock_step = 0;
state = (__int64)state_search;
}
return result;
}

original_code:
void state_undock()
{
 set_status(7,"Disengaging");
 undock_step++;
 if(undock_step<20)
 {
  drive_direct(-100,-100);
 }
 else
 {
  drive_direct(100,-100);
 }
 if(undock_step>30)
 {
  drive_direct(0,0);
  undock_step=0;
  state = state_search;
 }
}


decompiled_code:
__int16 state_search()
{
__int16 result; // ax

set_status(1, "Searching flowers");
result = search_around();
if ( !(_BYTE)result )
{
if ( (__int16)iC_getBattCharge() < low_charge )
state = (__int64)state_search_base;
result = (unsigned __int8)iC_getIRByte();
if ( base_is_flower && result != 255 )
{
state = (__int64)state_docking;
flower = 0;
*((_BYTE *)ERC + 178) = 0;
}
if ( result <= 239 )
{
state = (__int64)state_docking;
result >>= 4;
flower = result;
*((_BYTE *)ERC + 178) = result;
}
}
return result;
}

canonical_decompiled_code:
__int16 func16()
{
__int16 result; // ax

func7(1, "Searching flowers");
result = func14();
if ( !(_BYTE)result )
{
if ( (__int16)func11() < low_charge )
state = (__int64)state_search_base;
result = (unsigned __int8)func15();
if ( base_is_flower && result != 255 )
{
state = (__int64)state_docking;
flower = 0;
*((_BYTE *)ERC + 178) = 0;
}
if ( result <= 239 )
{
state = (__int64)state_docking;
result >>= 4;
flower = result;
*((_BYTE *)ERC + 178) = result;
}
}
return result;
}

original_code:
void state_search()
{
 set_status(1,"Searching flowers");
 if(search_around()) return;
 if(iC_getBattCharge()<low_charge)
 {
  state = state_search_base;
 }
 short ir = iC_getIRByte();
 if(base_is_flower && ir != 255)
 {
  state = state_docking;
  ERC->plante_a_portee = flower = 0;
 }
 if(ir<240)
 {
  state = state_docking;
  ERC->plante_a_portee = flower = ir>>4;
 }
}

variable_types: ir short


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

set_status(2, "Searching base");
result = search_around();
if ( !(_BYTE)result )
{
result = iC_getIRByte();
if ( (_BYTE)result == 0xFE )
{
drive_direct(0, 0);
result = iC_Demo(1);
state = state_demo_dock;
}
}
return result;
}

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

func7(2, "Searching base");
result = func14();
if ( !(_BYTE)result )
{
result = func15();
if ( (_BYTE)result == 0xFE )
{
func8(0, 0);
result = func20(1);
state = state_demo_dock;
}
}
return result;
}

original_code:
void state_search_base()
{
 set_status(2,"Searching base");
 if(search_around()) return;
 if(iC_getIRByte()==254)
 {
  drive_direct(0,0);
  iC_Demo(1);
  state = state_demo_dock;
 }
}


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

set_status(4, "Docking on base");
if ( (char)iC_getChargeState() > 0 )
state = state_charge;
result = iC_getIRByte();
if ( (_BYTE)result == 0xFF || (unsigned __int8)result < 0xF1u || (unsigned __int8)result == 242 )
++demo_dock_timeout;
if ( demo_dock_timeout > 30 )
{
iC_Demo(-1);
usleep(0x7A120u);
result = iC_Full();
state = (__int64 (*)(void))state_search_base;
demo_dock_timeout = 0;
}
return result;
}

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

func7(4, "Docking on base");
if ( (char)func18() > 0 )
state = state_charge;
result = func15();
if ( (_BYTE)result == 0xFF || (unsigned __int8)result < 0xF1u || (unsigned __int8)result == 242 )
++demo_dock_timeout;
if ( demo_dock_timeout > 30 )
{
func20(-1);
usleep(0x7A120u);
result = func19();
state = (__int64 (*)(void))state_search_base;
demo_dock_timeout = 0;
}
return result;
}

original_code:
void state_demo_dock()
{
 set_status(4,"Docking on base");
 if(iC_getChargeState()>0)
 {
  state = state_charge;
 }
 int ir = iC_getIRByte();
 if(ir<240 || ir==255 || ir==242 || ir==240)
  demo_dock_timeout++;
 if(demo_dock_timeout>30)
 {
  iC_Demo(-1);
  usleep(500000);
  iC_Full();
  state = state_search_base;
  demo_dock_timeout = 0;
 }
}

variable_types: ir int


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

set_status(5, "Charging battery");
result = (__int16)iC_getBattCharge();
if ( (__int16)result > high_charge )
{
iC_Demo(-1);
usleep(0x7A120u);
result = iC_Full();
state = (__int64 (*)(void))state_undock;
}
return result;
}

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

func7(5, "Charging battery");
result = (__int16)func11();
if ( (__int16)result > high_charge )
{
func20(-1);
usleep(0x7A120u);
result = func19();
state = (__int64 (*)(void))state_undock;
}
return result;
}

original_code:
void state_charge()
{
 set_status(5,"Charging battery");
 if(iC_getBattCharge()>high_charge)
 {
  iC_Demo(-1);
  usleep(500000);
  iC_Full();
  state = state_undock;
 }
}


decompiled_code:
int state_action()
{
int result; // eax
int v1; // edx

result = (unsigned __int8)action_state;
if ( action_state == 4 )
{
result = (int)ERC;
++*((_WORD *)ERC + flower + 79);
v1 = action_lenght;
if ( action_lenght > 0 )
goto LABEL_23;
action_state = 5;
LABEL_16:
set_status(14, "[flower] Distributing K.");
action_lenght = 100 - *((__int16 *)ERC + flower + 84);
return iC_DigitalOut(action_state);
}
if ( action_state > 4 )
{
if ( action_state == 5 )
{
result = (int)ERC;
++*((_WORD *)ERC + flower + 84);
v1 = action_lenght;
if ( action_lenght > 0 )
goto LABEL_23;
}
else
{
v1 = action_lenght;
if ( action_lenght > 0 )
goto LABEL_23;
}
LABEL_10:
flower = -1;
*((_BYTE *)ERC + 178) = -1;
action_state = 0;
state = (__int64 (*)(void))state_undock;
return iC_DigitalOut(action_state);
}
if ( action_state == 2 )
{
result = (int)ERC;
++*((_WORD *)ERC + flower + 69);
v1 = action_lenght;
if ( action_lenght > 0 )
goto LABEL_23;
action_state = 3;
LABEL_13:
set_status(12, "[flower] Distributing P.");
action_lenght = 100 - *((__int16 *)ERC + flower + 74);
return iC_DigitalOut(action_state);
}
if ( action_state == 3 )
{
result = (int)ERC;
++*((_WORD *)ERC + flower + 74);
v1 = action_lenght;
if ( action_lenght <= 0 )
{
action_state = 4;
LABEL_7:
set_status(13, "[flower] Distributing N.");
action_lenght = 100 - *((__int16 *)ERC + flower + 79);
return iC_DigitalOut(action_state);
}
}
else
{
v1 = action_lenght;
if ( action_lenght <= 0 )
{
++action_state;
switch ( (char)result )
{
case 0:
set_status(10, "[flower] Scanning");
action_lenght = 50;
break;
case 1:
set_status(11, "[flower] Watering");
action_lenght = 100 - *((__int16 *)ERC + flower + 69);
break;
case 2:
goto LABEL_13;
case 3:
goto LABEL_7;
case 4:
goto LABEL_16;
default:
goto LABEL_10;
}
return iC_DigitalOut(action_state);
}
}
LABEL_23:
action_lenght = v1 - 1;
return result;
}

canonical_decompiled_code:
int func25()
{
int result; // eax
int v1; // edx

result = (unsigned __int8)action_state;
if ( action_state == 4 )
{
result = (int)ERC;
++*((_WORD *)ERC + flower + 79);
v1 = action_lenght;
if ( action_lenght > 0 )
goto LABEL_23;
action_state = 5;
LABEL_16:
func7(14, "[flower] Distributing K.");
action_lenght = 100 - *((__int16 *)ERC + flower + 84);
return func24(action_state);
}
if ( action_state > 4 )
{
if ( action_state == 5 )
{
result = (int)ERC;
++*((_WORD *)ERC + flower + 84);
v1 = action_lenght;
if ( action_lenght > 0 )
goto LABEL_23;
}
else
{
v1 = action_lenght;
if ( action_lenght > 0 )
goto LABEL_23;
}
LABEL_10:
flower = -1;
*((_BYTE *)ERC + 178) = -1;
action_state = 0;
state = (__int64 (*)(void))state_undock;
return func24(action_state);
}
if ( action_state == 2 )
{
result = (int)ERC;
++*((_WORD *)ERC + flower + 69);
v1 = action_lenght;
if ( action_lenght > 0 )
goto LABEL_23;
action_state = 3;
LABEL_13:
func7(12, "[flower] Distributing P.");
action_lenght = 100 - *((__int16 *)ERC + flower + 74);
return func24(action_state);
}
if ( action_state == 3 )
{
result = (int)ERC;
++*((_WORD *)ERC + flower + 74);
v1 = action_lenght;
if ( action_lenght <= 0 )
{
action_state = 4;
LABEL_7:
func7(13, "[flower] Distributing N.");
action_lenght = 100 - *((__int16 *)ERC + flower + 79);
return func24(action_state);
}
}
else
{
v1 = action_lenght;
if ( action_lenght <= 0 )
{
++action_state;
switch ( (char)result )
{
case 0:
func7(10, "[flower] Scanning");
action_lenght = 50;
break;
case 1:
func7(11, "[flower] Watering");
action_lenght = 100 - *((__int16 *)ERC + flower + 69);
break;
case 2:
goto LABEL_13;
case 3:
goto LABEL_7;
case 4:
goto LABEL_16;
default:
goto LABEL_10;
}
return func24(action_state);
}
}
LABEL_23:
action_lenght = v1 - 1;
return result;
}

original_code:
void state_action()
{
 switch(action_state)
 {
  case 2:
   ERC->level_w[flower]++;
   break;
  case 3:
   ERC->level_p[flower]++;
   break;
  case 4:
   ERC->level_n[flower]++;
   break;
  case 5:
   ERC->level_k[flower]++;
   break;
 }
 if(action_lenght<=0)
 {
  action_state++;
  switch(action_state)
  {
   case 1:
    set_status(10,"[flower] Scanning");
    action_lenght = 50;
    break;
   case 2:
    set_status(11,"[flower] Watering");
    action_lenght = 100 - ERC->level_w[flower];
    break;
   case 3:
    set_status(12,"[flower] Distributing P.");
    action_lenght = 100 - ERC->level_p[flower];
    break;
   case 4:
    set_status(13,"[flower] Distributing N.");
    action_lenght = 100 - ERC->level_n[flower];
    break;
   case 5:
    set_status(14,"[flower] Distributing K.");
    action_lenght = 100 - ERC->level_k[flower];
    break;
   default:
    ERC->plante_a_portee = flower = -1;
    action_state = 0;
    state = state_undock;
  }
  iC_DigitalOut(action_state);
 }
 else
  action_lenght--;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebp
int result; // eax
__int64 v6; // r14
const char *v7; // rbx
char v8; // si
WINDOW *v9; // rbx
unsigned int v10; // eax
char *v11; // rsi
int v12; // ebx
_WORD *v13; // rbx

if ( argc <= 1 )
{
LABEL_20:
v9 = initscr();
cbreak();
noecho();
nodelay(v9, 1);
scrollok(v9, 1);
idlok(v9, 1);
printw("Simulating connection...\n");
iC_Full();
signal(2, (__sighandler_t)quit);
signal(15, (__sighandler_t)quit);
signal(3, (__sighandler_t)quit);
shm_master();
init_erc_shared();
v10 = time(0LL);
srand(v10);
v11 = (char *)(unsigned int)(__int16)iC_getBattCharge();
printw("Connected... (Battery=%d)\n", v11);
state = (__int64 (*)(void))state_search;
*(_BYTE *)ERC = 1;
help();
while ( loop )
{
wrefresh(stdscr);
usleep(0x186A0u);
if ( wgetch(stdscr) != -1 )
printw("Touche %d inconnue !\n", v11);
v12 = sub_delay;
if ( !sub_delay )
{
sub_delay = 50;
do
{
if ( flower != v12 )
{
if ( *((__int16 *)ERC + v12 + 69) > 5 )
*((_WORD *)ERC + v12 + 69) -= rand() % 6;
else
*((_WORD *)ERC + v12 + 69) = 0;
if ( *((__int16 *)ERC + v12 + 74) > 2 )
*((_WORD *)ERC + v12 + 74) -= rand() % 3;
else
*((_WORD *)ERC + v12 + 74) = 0;
if ( *((__int16 *)ERC + v12 + 79) > 2 )
*((_WORD *)ERC + v12 + 79) -= rand() % 3;
else
*((_WORD *)ERC + v12 + 79) = 0;
if ( *((__int16 *)ERC + v12 + 84) > 2 )
*((_WORD *)ERC + v12 + 84) -= rand() % 3;
else
*((_WORD *)ERC + v12 + 84) = 0;
}
++v12;
}
while ( v12 != 5 );
}
--sub_delay;
v11 = robot_status;
if ( strcmp(robot_laststatus, robot_status) )
{
printw("New status: %s (was: %s)\n", robot_status, robot_laststatus);
strcpy(robot_laststatus, robot_status);
v11 = robot_status;
strcpy((char *)ERC + 1, robot_status);
}
v13 = ERC;
v13[65] = iC_getBattCharge();
if ( *((_BYTE *)v13 + 132) )
{
set_status(0, "Manual control");
v11 = (char *)(unsigned int)*((__int16 *)ERC + 68);
drive_direct(*((__int16 *)ERC + 67), (unsigned int)v11);
}
else
{
state();
}
}
*(_BYTE *)ERC = 0;
printw("Terminated...\n");
shm_leave();
endwin();
result = 0;
}
else
{
v4 = 1;
while ( 2 )
{
v6 = v4;
v7 = argv[v6];
if ( *v7 == 45 && strlen(argv[v4]) == 2 )
{
v8 = v7[1];
switch ( v8 )
{
case 'V':
case 'h':
return usage(*argv);
case 'b':
base_is_flower = 1;
printw("Homebase will now be seen as a flower...\n");
++v4;
goto LABEL_8;
case 'c':
if ( v4 + 1 < argc )
high_charge = atoi(argv[v6 + 1]);
v4 += 2;
goto LABEL_8;
case 'k':
if ( v4 + 1 < argc )
shm_key = atoi(argv[v6 + 1]);
v4 += 2;
goto LABEL_8;
case 'l':
if ( v4 + 1 < argc )
low_charge = atoi(argv[v6 + 1]);
v4 += 2;
LABEL_8:
if ( v4 < argc )
continue;
goto LABEL_20;
default:
return printw("Unknow argument -%c\nRun %s -h for help...\n", (unsigned int)v8, *argv);
}
}
break;
}
result = printw("Bad argument: %s\nRun %s -h for help...\n", v7, *argv);
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebp
int result; // eax
__int64 v6; // r14
const char *v7; // rbx
char v8; // si
WINDOW *v9; // rbx
unsigned int v10; // eax
char *v11; // rsi
int v12; // ebx
_WORD *v13; // rbx

if ( argc <= 1 )
{
LABEL_20:
v9 = initscr();
cbreak();
noecho();
nodelay(v9, 1);
scrollok(v9, 1);
idlok(v9, 1);
printw("Simulating connection...\n");
func19();
signal(2, (__sighandler_t)quit);
signal(15, (__sighandler_t)quit);
signal(3, (__sighandler_t)quit);
func2();
func1();
v10 = time(0LL);
srand(v10);
v11 = (char *)(unsigned int)(__int16)func11();
printw("Connected... (Battery=%d)\n", v11);
state = (__int64 (*)(void))state_search;
*(_BYTE *)ERC = 1;
func5();
while ( loop )
{
wrefresh(stdscr);
usleep(0x186A0u);
if ( wgetch(stdscr) != -1 )
printw("Touche %d inconnue !\n", v11);
v12 = sub_delay;
if ( !sub_delay )
{
sub_delay = 50;
do
{
if ( flower != v12 )
{
if ( *((__int16 *)ERC + v12 + 69) > 5 )
*((_WORD *)ERC + v12 + 69) -= rand() % 6;
else
*((_WORD *)ERC + v12 + 69) = 0;
if ( *((__int16 *)ERC + v12 + 74) > 2 )
*((_WORD *)ERC + v12 + 74) -= rand() % 3;
else
*((_WORD *)ERC + v12 + 74) = 0;
if ( *((__int16 *)ERC + v12 + 79) > 2 )
*((_WORD *)ERC + v12 + 79) -= rand() % 3;
else
*((_WORD *)ERC + v12 + 79) = 0;
if ( *((__int16 *)ERC + v12 + 84) > 2 )
*((_WORD *)ERC + v12 + 84) -= rand() % 3;
else
*((_WORD *)ERC + v12 + 84) = 0;
}
++v12;
}
while ( v12 != 5 );
}
--sub_delay;
v11 = robot_status;
if ( strcmp(robot_laststatus, robot_status) )
{
printw("New status: %s (was: %s)\n", robot_status, robot_laststatus);
strcpy(robot_laststatus, robot_status);
v11 = robot_status;
strcpy((char *)ERC + 1, robot_status);
}
v13 = ERC;
v13[65] = func11();
if ( *((_BYTE *)v13 + 132) )
{
func7(0, "Manual control");
v11 = (char *)(unsigned int)*((__int16 *)ERC + 68);
func8(*((__int16 *)ERC + 67), (unsigned int)v11);
}
else
{
state();
}
}
*(_BYTE *)ERC = 0;
printw("Terminated...\n");
func4();
endwin();
result = 0;
}
else
{
v4 = 1;
while ( 2 )
{
v6 = v4;
v7 = argv[v6];
if ( *v7 == 45 && strlen(argv[v4]) == 2 )
{
v8 = v7[1];
switch ( v8 )
{
case 'V':
case 'h':
return func6(*argv);
case 'b':
base_is_flower = 1;
printw("Homebase will now be seen as a flower...\n");
++v4;
goto LABEL_8;
case 'c':
if ( v4 + 1 < argc )
high_charge = atoi(argv[v6 + 1]);
v4 += 2;
goto LABEL_8;
case 'k':
if ( v4 + 1 < argc )
shm_key = atoi(argv[v6 + 1]);
v4 += 2;
goto LABEL_8;
case 'l':
if ( v4 + 1 < argc )
low_charge = atoi(argv[v6 + 1]);
v4 += 2;
LABEL_8:
if ( v4 < argc )
continue;
goto LABEL_20;
default:
return printw("Unknow argument -%c\nRun %s -h for help...\n", (unsigned int)v8, *argv);
}
}
break;
}
result = printw("Bad argument: %s\nRun %s -h for help...\n", v7, *argv);
}
return result;
}

original_code:
int main( int argc, char* args[] )
{
 char* serialport = "/dev/ttyUSB0";
 if(argc>1)
 {
  int arg=1;
  while(arg<argc)
  {
   if(args[arg][0]!='-' || strlen(args[arg])!=2)
   {
    printf("Bad argument: %s\nRun %s -h for help...\n",args[arg],args[0]);
    return;
   }
   switch(args[arg][1])
   {
    case 'h':
    case 'V':
     usage(args[0]);
     return;
    case 's':
     if(arg+1<argc)
      serialport = args[arg+1];
     arg+=2;
     break;
    case 'l':
     if(arg+1<argc)
      low_charge = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'c':
     if(arg+1<argc)
      high_charge = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'k':
     if(arg+1<argc)
      shm_key = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'b':
     base_is_flower = 1;
     printf("Homebase will now be seen as a flower...\n");
     arg++;
     break;
    default:
     printf("Unknow argument -%c\nRun %s -h for help...\n",args[arg][1],args[0]);
     return;
   }
  }
 }
 printf("Connecting to %s...\n",serialport);
 initICreateCom(serialport);
 iC_Start();
 iC_Full();
 signal(2,quit);
  signal(15,quit);
  signal(3,quit);
  shm_master();
  init_erc_shared();
  srand ( time(((void *)0)) );
 printf("Connected... (Battery=%d)\n",iC_getBattCharge());
 state = state_search;
 ERC->alive=1;
 while(loop)
 {
  usleep(100000);
  if(!sub_delay)
  {
   sub_delay = 50;
   int flwid;
   for(flwid=0;flwid<5;flwid++)
   {
    if(flwid==flower) continue;
    if(ERC->level_w[flwid]<6)
     ERC->level_w[flwid]=0;
    else
     ERC->level_w[flwid]-= rand()%6;
    if(ERC->level_p[flwid]<3)
     ERC->level_p[flwid]=0;
    else
     ERC->level_p[flwid]-= rand()%3;
    if(ERC->level_n[flwid]<3)
     ERC->level_n[flwid]=0;
    else
     ERC->level_n[flwid]-= rand()%3;
    if(ERC->level_k[flwid]<3)
     ERC->level_k[flwid]=0;
    else
     ERC->level_k[flwid]-= rand()%3;
   }
  }
  sub_delay--;
  if(strcmp(robot_laststatus,robot_status)!=0)
  {
   printf("New status: %s (was: %s)\n",robot_status,robot_laststatus);
   strcpy(robot_laststatus,robot_status);
   strcpy(ERC->status,robot_status);
  }
  ERC->Battery = iC_getBattCharge();
  if(ERC->ManualControl)
  {
   set_status(0,"Manual control");
   drive_direct(ERC->vl, ERC->vr);
  }
  else
   (*state)();
 }
 ERC->alive=0;
 iC_DriveDirect(0,0,0,0);
 closeICreateCom();
 printf("Terminated...\n");
 shm_leave();
}

canonical_original_code:
int main(int argc, char *args[])
{
 char *serialport = "/dev/ttyUSB0";
 if(argc>1)
 {
  int arg = 1;
  while(arg<argc)
  {
   if(args[arg][0]!='-' || strlen(args[arg])!=2)
   {
    printf("Bad argument: %s\nRun %s -h for help...\n",args[arg],args[0]);
    return;
   }
   switch(args[arg][1])
   {
    case 'h':
    case 'V':
     usage(args[0]);
     return;
    case 's':
     if(arg+1<argc)
      serialport = args[arg+1];
     arg+=2;
     break;
    case 'l':
     if(arg+1<argc)
      low_charge = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'c':
     if(arg+1<argc)
      high_charge = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'k':
     if(arg+1<argc)
      shm_key = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'b':
     base_is_flower = 1;
     printf("Homebase will now be seen as a flower...\n");
     arg++;
     break;
    default:
     printf("Unknow argument -%c\nRun %s -h for help...\n",args[arg][1],args[0]);
     return;
   }
  }
 }
 printf("Connecting to %s...\n",serialport);
 initICreateCom(serialport);
 iC_Start();
 iC_Full();
 signal(2,quit);
  signal(15,quit);
  signal(3,quit);
  shm_master();
  init_erc_shared();
  srand ( time(((void *)0)) );
 printf("Connected... (Battery=%d)\n",iC_getBattCharge());
 state = state_search;
 ERC->alive=1;
 while(loop)
 {
  usleep(100000);
  if(!sub_delay)
  {
   sub_delay = 50;
   int flwid;
   for(flwid=0;flwid<5;flwid++)
   {
    if(flwid==flower) continue;
    if(ERC->level_w[flwid]<6)
     ERC->level_w[flwid]=0;
    else
     ERC->level_w[flwid]-= rand()%6;
    if(ERC->level_p[flwid]<3)
     ERC->level_p[flwid]=0;
    else
     ERC->level_p[flwid]-= rand()%3;
    if(ERC->level_n[flwid]<3)
     ERC->level_n[flwid]=0;
    else
     ERC->level_n[flwid]-= rand()%3;
    if(ERC->level_k[flwid]<3)
     ERC->level_k[flwid]=0;
    else
     ERC->level_k[flwid]-= rand()%3;
   }
  }
  sub_delay--;
  if(strcmp(robot_laststatus,robot_status)!=0)
  {
   printf("New status: %s (was: %s)\n",robot_status,robot_laststatus);
   strcpy(robot_laststatus,robot_status);
   strcpy(ERC->status,robot_status);
  }
  ERC->Battery = iC_getBattCharge();
  if(ERC->ManualControl)
  {
   set_status(0,"Manual control");
   drive_direct(ERC->vl, ERC->vr);
  }
  else
   (*state)();
 }
 ERC->alive=0;
 iC_DriveDirect(0,0,0,0);
 closeICreateCom();
 printf("Terminated...\n");
 shm_leave();
}

variable_types: argc int

variable_types:
args
char *[]

variable_types:
serialport
char *

variable_types: arg int

variable_types: flwid int

return_type: int


closeSerial

decompiled_code:
int __fastcall closeSerial(int a1)
{
int result; // eax

result = close(a1);
if ( result < 0 )
result = puts("close failed... ignored!");
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int result; // eax

result = close(a1);
if ( result < 0 )
result = puts("close failed... ignored!");
return result;
}

original_code:
void closeSerial(int fd)
{
 if(close(fd)<0)
  printf("close failed... ignored!\n");
}

variable_types: fd int


sendSerial

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

buf[0] = a2;
write(a1, buf, 1uLL);
return usleep(0x2710u);
}

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

buf[0] = a2;
write(a1, buf, 1uLL);
return usleep(0x2710u);
}

original_code:
int sendSerial(int fd, unsigned char data)
{
  write(fd,&data,1);
 usleep(10000);
}

variable_types:
data
unsigned char


receiveSerial

decompiled_code:
__int64 __fastcall receiveSerial(int fd)
{
clock_t v1; // rbp
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = clock() + 1000000;
while ( !read(fd, buf, 1uLL) )
{
usleep(1u);
if ( clock() > v1 )
{
puts("receive timed out!");
abort();
}
}
return (unsigned __int8)buf[0];
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd)
{
clock_t v1; // rbp
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = clock() + 1000000;
while ( !read(fd, buf, 1uLL) )
{
usleep(1u);
if ( clock() > v1 )
{
puts("receive timed out!");
abort();
}
}
return (unsigned __int8)buf[0];
}

original_code:
unsigned char receiveSerial(int fd)
{
 clock_t timeout;
 timeout = clock()+((__clock_t) 1000000);
  unsigned char data;
  while(!read(fd,&data,1))
  {
   usleep(1);
   if(clock() > timeout)
  {
   printf("receive timed out!\n");
   abort();
  }
  }
  return data;
}

canonical_original_code:
unsigned char receiveSerial(int fd)
{
 long timeout;
 timeout = clock()+((long) 1000000);
  unsigned char data;
  while(!read(fd,&data,1))
  {
   usleep(1);
   if(clock() > timeout)
  {
   printf("receive timed out!\n");
   abort();
  }
  }
  return data;
}

variable_types: timeout long


flushRecieveBuffer

decompiled_code:
ssize_t __fastcall flushRecieveBuffer(int fd)
{
ssize_t result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

do
result = read(fd, buf, 1uLL);
while ( result > 0 );
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(int fd)
{
ssize_t result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

do
result = read(fd, buf, 1uLL);
while ( result > 0 );
return result;
}

original_code:
void flushRecieveBuffer(int fd)
{
 unsigned char data;
 while(read(fd,&data,1)>0);
}


selectBaud

original_code:
long selectBaud(long baudrate)
{
  long BAUD;
  switch (baudrate)
  {
      case 230400:
        BAUD = 0010003;
        break;
      case 115200:
        BAUD = 0010002;
        break;
      case 57600:
        BAUD = 0010001;
        break;
      case 38400:
        BAUD = 0000017;
        break;
      case 19200:
        BAUD = 0000016;
        break;
      case 9600:
      default :
        BAUD = 0000015;
        break;
      case 4800:
        BAUD = 0000014;
        break;
      case 2400:
        BAUD = 0000013;
        break;
      case 1800:
        BAUD = 0000012;
        break;
      case 1200:
        BAUD = 0000011;
        break;
      case 600:
        BAUD = 0000010;
        break;
      case 300:
        BAUD = 0000007;
        break;
      case 200:
        BAUD = 0000006;
        break;
      case 150:
        BAUD = 0000005;
        break;
      case 134:
        BAUD = 0000004;
        break;
      case 110:
        BAUD = 0000003;
        break;
      case 75:
        BAUD = 0000002;
        break;
      case 50:
        BAUD = 0000001;
        break;
      case 0:
        BAUD = 0000000;
        break;
  }
  return BAUD;
}

variable_types: baudrate long

variable_types: BAUD long

return_type: long


selectNDataBits

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

result = 16LL;
if ( a1 != 6 )
{
result = 32LL;
if ( a1 != 7 )
{
result = 48LL;
if ( a1 == 5 )
result = 0LL;
}
}
return result;
}

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

result = 16LL;
if ( a1 != 6 )
{
result = 32LL;
if ( a1 != 7 )
{
result = 48LL;
if ( a1 == 5 )
result = 0LL;
}
}
return result;
}

original_code:
long selectNDataBits(int nData)
{
  long DATABITS;
  switch (nData)
  {
      case 8:
      default:
        DATABITS = 0000060;
        break;
      case 7:
        DATABITS = 0000040;
        break;
      case 6:
        DATABITS = 0000020;
        break;
      case 5:
        DATABITS = 0000000;
        break;
  }
  return DATABITS;
}

variable_types: nData int

variable_types: DATABITS long


selectNStopBits

decompiled_code:
unsigned __int64 __fastcall selectNStopBits(int a1)
{
return (unsigned __int64)(a1 == 2) << 6;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(int a1)
{
return (unsigned __int64)(a1 == 2) << 6;
}

original_code:
long selectNStopBits(int nStop)
{
  long STOPBITS;
  switch (nStop)
  {
      case 1:
      default:
        STOPBITS = 0;
        break;
      case 2:
        STOPBITS = 0000100;
        break;
  }
  return STOPBITS;
}

variable_types: nStop int

variable_types: STOPBITS long


selectParity

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

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

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

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

original_code:
ParityState selectParity(int parity)
{
  ParityState par;
  switch (parity)
  {
      case 0:
      default:
        par.PARITY_ON = 0;
        par.PARITY_ODD = 0;
        break;
      case 1:
        par.PARITY_ON = 0000400;
        par.PARITY_ODD = 0001000;
        break;
      case 2:
        par.PARITY_ON = 0000400;
        par.PARITY_ODD = 0;
        break;
  }
  return par;
}

canonical_original_code:
struct ParityState selectParity(int parity)
{
  struct ParityState par;
  switch (parity)
  {
      case 0:
      default:
        par.PARITY_ON = 0;
        par.PARITY_ODD = 0;
        break;
      case 1:
        par.PARITY_ON = 0000400;
        par.PARITY_ODD = 0001000;
        break;
      case 2:
        par.PARITY_ON = 0000400;
        par.PARITY_ODD = 0;
        break;
  }
  return par;
}

variable_types: parity int

variable_types: struct ParityState { long PARITY_ON; long PARITY_ODD; }


initSerial

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

v2 = open(a1, 2306);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
fcntl(v2, 4, 0LL);
tcgetattr(v3, &v6);
v4 = selectBaud(a2);
v6.c_cflag = v6.c_cflag & 0x7FFFEEC0 | 0x8F0;
cfsetospeed(&v6, v4);
cfsetispeed(&v6, v4);
v6.c_iflag |= 5u;
v6.c_lflag = 0;
v6.c_oflag = 0;
v6.c_cc[6] = 0;
v6.c_cc[5] = 0;
if ( tcsetattr(v3, 0, &v6) < 0 )
{
puts("tcsetattr failed");
v3 = -1;
}
return v3;
}

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

v2 = open(a1, 2306);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
fcntl(v2, 4, 0LL);
tcgetattr(v3, &v6);
v4 = func4(a2);
v6.c_cflag = v6.c_cflag & 0x7FFFEEC0 | 0x8F0;
cfsetospeed(&v6, v4);
cfsetispeed(&v6, v4);
v6.c_iflag |= 5u;
v6.c_lflag = 0;
v6.c_oflag = 0;
v6.c_cc[6] = 0;
v6.c_cc[5] = 0;
if ( tcsetattr(v3, 0, &v6) < 0 )
{
puts("tcsetattr failed");
v3 = -1;
}
return v3;
}

original_code:
int initSerial(char* device, long baudrate, int nData, int nStop, int parity)
{
  struct termios new_attributes;
  int tty_fd= open(device,02 | 0400 | 04000);
  if (tty_fd<0) {
    return -1;
  } else {
    fcntl(tty_fd, 4, 0);
    tcgetattr(tty_fd,&new_attributes);
    long BAUD = selectBaud(baudrate);
    long DATABITS = selectNDataBits(nData);
    long STOPBITS = selectNStopBits(nStop);
    ParityState par = selectParity(parity);
    new_attributes.c_cflag &= ~(0000400| 0010017 |0000060 | 020000000000);
    new_attributes.c_cflag |= (0000060 | 0000100 | 0000200 | 0004000);
   cfsetospeed(&new_attributes, BAUD);
    cfsetispeed(&new_attributes, BAUD);
    new_attributes.c_iflag |= 0000004;
    new_attributes.c_iflag |= 0000001;
    new_attributes.c_lflag = 0;
    new_attributes.c_oflag = 0;
    new_attributes.c_cc[6]=0;
    new_attributes.c_cc[5]=0;
    if(tcsetattr(tty_fd, 0, &new_attributes)<0)
    {
     printf("tcsetattr failed\n");
   return -1;
  }
    return tty_fd;
  }
}

canonical_original_code:
int initSerial(char *device, long baudrate, int nData, int nStop, int parity)
{
  struct termios new_attributes;
  int tty_fd = open(device,02 | 0400 | 04000);
  if (tty_fd<0) {
    return -1;
  } else {
    fcntl(tty_fd, 4, 0);
    tcgetattr(tty_fd,&new_attributes);
    long BAUD = selectBaud(baudrate);
    long DATABITS = selectNDataBits(nData);
    long STOPBITS = selectNStopBits(nStop);
    struct ParityState par = selectParity(parity);
    new_attributes.c_cflag &= ~(0000400| 0010017 |0000060 | 020000000000);
    new_attributes.c_cflag |= (0000060 | 0000100 | 0000200 | 0004000);
   cfsetospeed(&new_attributes, BAUD);
    cfsetispeed(&new_attributes, BAUD);
    new_attributes.c_iflag |= 0000004;
    new_attributes.c_iflag |= 0000001;
    new_attributes.c_lflag = 0;
    new_attributes.c_oflag = 0;
    new_attributes.c_cc[6]=0;
    new_attributes.c_cc[5]=0;
    if(tcsetattr(tty_fd, 0, &new_attributes)<0)
    {
     printf("tcsetattr failed\n");
   return -1;
  }
    return tty_fd;
  }
}

variable_types:
device
char *

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

user_defined_types: struct ParityState { long PARITY_ON; long PARITY_ODD; }


original_code:
void init_erc_shared()
{
 ERC->alive = 0;
 strcpy(ERC->status,"");
 ERC->id_status = -1;
 ERC->Battery = 0;
 ERC->ManualControl = 0;
 ERC->vl = 0;
 ERC->vr = 0;
 ERC->plante_a_portee = -1;
 int i;
 for(i=0;i<5;i++)
 {
  ERC->level_w[i]=100;
  ERC->level_p[i]=100;
  ERC->level_n[i]=100;
  ERC->level_k[i]=100;
 }
}

variable_types: i int


decompiled_code:
void *shm_master()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 950);
if ( v0 < 0 )
{
puts("Shared memory create failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

canonical_decompiled_code:
void *func10()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 950);
if ( v0 < 0 )
{
puts("Shared memory create failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

original_code:
void shm_master()
{
 int mem_ID;
 void* ptr_mem_partagee;
 if ((mem_ID = shmget(shm_key, sizeof(ERC), 0666 | 01000)) < 0)
 {
  printf("Shared memory create failed!\n");
  abort();
 }
 if ((ptr_mem_partagee = shmat(mem_ID, ((void *)0), 0)) == (void*) -1)
 {
  printf("Shared memory attach failed!\n");
  abort();
 }
 ERC = ptr_mem_partagee;
}


decompiled_code:
void *shm_slave()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 438);
if ( v0 < 0 )
{
puts("Shared memory get failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

canonical_decompiled_code:
void *func11()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 438);
if ( v0 < 0 )
{
puts("Shared memory get failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

original_code:
void shm_slave()
{
 int mem_ID;
 void* ptr_mem_partagee;
 if ((mem_ID = shmget(shm_key, sizeof(ERC), 0666)) < 0)
 {
  printf("Shared memory get failed!\n");
  abort();
 }
 if ((ptr_mem_partagee = shmat(mem_ID, ((void *)0), 0)) == (void*) -1)
 {
  printf("Shared memory attach failed!\n");
  abort();
 }
 ERC = ptr_mem_partagee;
}


decompiled_code:
int shm_leave()
{
return shmdt(ERC);
}

canonical_decompiled_code:
int func12()
{
return shmdt(ERC);
}

original_code:
void shm_leave()
{
 shmdt(ERC);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
const char *v4; // rbx
char v5; // si
int result; // eax

gtk_init();
if ( argc <= 1 )
{
LABEL_14:
signal(2, (__sighandler_t)quit);
signal(15, (__sighandler_t)quit);
signal(3, (__sighandler_t)quit);
shm_slave();
MainWindow = gtk_window_new();
g_type_check_instance_cast();
g_signal_connect_data();
gtk_window_get_type();
g_type_check_instance_cast();
gtk_window_set_title();
g_type_check_instance_cast();
gtk_window_resize();
g_type_check_instance_cast();
gtk_window_set_position();
Label1 = gtk_label_new();
gtk_label_get_type();
g_type_check_instance_cast();
gtk_label_set_use_markup();
g_type_check_instance_cast();
gtk_label_set_justify();
gtk_container_get_type();
g_type_check_instance_cast();
gtk_container_add();
g_timeout_add();
gtk_widget_show_all();
gtk_main();
gtk_exit();
shm_leave();
result = 0;
}
else
{
v3 = 1LL;
while ( 1 )
{
v4 = argv[v3];
if ( *v4 != 45 || strlen(argv[v3]) != 2 )
return printf("Bad argument: %s\nRun %s -h for help...\n", v4, *argv);
v5 = v4[1];
if ( v5 == 104 )
break;
if ( v5 != 107 )
{
if ( v5 != 86 )
return printf("Unknow argument -%c\nRun %s -h for help...\n", (unsigned int)v5, *argv);
break;
}
if ( argc > (int)v3 + 1 )
shm_key = atoi(argv[v3 + 1]);
v3 += 2LL;
if ( argc <= (int)v3 )
goto LABEL_14;
}
result = usage(*argv);
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
const char *v4; // rbx
char v5; // si
int result; // eax

gtk_init();
if ( argc <= 1 )
{
LABEL_14:
signal(2, (__sighandler_t)quit);
signal(15, (__sighandler_t)quit);
signal(3, (__sighandler_t)quit);
func11();
MainWindow = gtk_window_new();
g_type_check_instance_cast();
g_signal_connect_data();
gtk_window_get_type();
g_type_check_instance_cast();
gtk_window_set_title();
g_type_check_instance_cast();
gtk_window_resize();
g_type_check_instance_cast();
gtk_window_set_position();
Label1 = gtk_label_new();
gtk_label_get_type();
g_type_check_instance_cast();
gtk_label_set_use_markup();
g_type_check_instance_cast();
gtk_label_set_justify();
gtk_container_get_type();
g_type_check_instance_cast();
gtk_container_add();
g_timeout_add();
gtk_widget_show_all();
gtk_main();
gtk_exit();
func12();
result = 0;
}
else
{
v3 = 1LL;
while ( 1 )
{
v4 = argv[v3];
if ( *v4 != 45 || strlen(argv[v3]) != 2 )
return printf("Bad argument: %s\nRun %s -h for help...\n", v4, *argv);
v5 = v4[1];
if ( v5 == 104 )
break;
if ( v5 != 107 )
{
if ( v5 != 86 )
return printf("Unknow argument -%c\nRun %s -h for help...\n", (unsigned int)v5, *argv);
break;
}
if ( argc > (int)v3 + 1 )
shm_key = atoi(argv[v3 + 1]);
v3 += 2LL;
if ( argc <= (int)v3 )
goto LABEL_14;
}
result = func13(*argv);
}
return result;
}

variable_types: argc int

variable_types:
args
char *[]

variable_types:
serialport
char *


die

repo: ElessarWebb/turing

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
int v2; // edi
char *v3; // r8

if ( a1 )
{
v2 = *_errno_location();
v3 = "None";
if ( v2 )
v3 = strerror(v2);
fprintf(stderr, "[ERROR] ( %s:%d: errno: %s ) Error: %s.\n\n", "errors.c", 9LL, v3, a1);
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
int v2; // edi
char *v3; // r8

if ( a1 )
{
v2 = *_errno_location();
v3 = "None";
if ( v2 )
v3 = strerror(v2);
fprintf(stderr, "[ERROR] ( %s:%d: errno: %s ) Error: %s.\n\n", "errors.c", 9LL, v3, a1);
}
exit(1);
}

original_code:
void die( char *message )
{
 if( message )
 {
  fprintf( stderr, "[ERROR] ( %s:%d: errno: %s ) " "Error: %s.\n" "\n", "errors.c", 9, ( (*__errno_location ()) == 0 ? "None" : strerror( (*__errno_location ()) ) ), message );
 }
 exit(1);
}

canonical_original_code:
void die(char *message)
{
 if( message )
 {
  fprintf( stderr, "[ERROR] ( %s:%d: errno: %s ) " "Error: %s.\n" "\n", "errors.c", 9, ( (*__errno_location ()) == 0 ? "None" : strerror( (*__errno_location ()) ) ), message );
 }
 exit(1);
}

variable_types:
message
char *


repo: EmielM/zmqcat

decompiled_code:
void __fastcall zmqcat_recv(__int64 a1, int a2, int a3)
{
int *v4; // rbx
const char *v5; // rax
int *v6; // rbx
const char *v7; // rax
FILE *v8; // r13
const void *v9; // rax
__int64 v10; // rax
size_t v11; // rbx

if ( a2 != 8 && a2 != 1 )
{
if ( (int)zmq_msg_init() >= 0 )
{
if ( (int)zmq_msg_recv() < 0 )
{
v6 = __errno_location();
v7 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v6, v7);
}
else
{
zmq_getsockopt();
v10 = zmq_msg_size();
v11 = v10;
if ( a3 )
fprintf(stderr, "receiving %ld bytes\n", v10);
v8 = _bss_start;
v9 = (const void *)zmq_msg_data();
fwrite(v9, 1uLL, v11, v8);
}
}
else
{
v4 = __errno_location();
v5 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v4, v5);
}
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2, int a3)
{
int *v4; // rbx
const char *v5; // rax
int *v6; // rbx
const char *v7; // rax
FILE *v8; // r13
const void *v9; // rax
__int64 v10; // rax
size_t v11; // rbx

if ( a2 != 8 && a2 != 1 )
{
if ( (int)zmq_msg_init() >= 0 )
{
if ( (int)zmq_msg_recv() < 0 )
{
v6 = __errno_location();
v7 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v6, v7);
}
else
{
zmq_getsockopt();
v10 = zmq_msg_size();
v11 = v10;
if ( a3 )
fprintf(stderr, "receiving %ld bytes\n", v10);
v8 = _bss_start;
v9 = (const void *)zmq_msg_data();
fwrite(v9, 1uLL, v11, v8);
}
}
else
{
v4 = __errno_location();
v5 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v4, v5);
}
}
}

original_code:
void zmqcat_recv(void* socket, int type, int verbose) {
 if (type == 8 || type == 1)
  return;
 int ok;
 int64_t rcvmore = 0;
 size_t rcvmore_size = sizeof(rcvmore);
 zmq_msg_t msg;
 ok = zmq_msg_init(&msg);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return;
 }
 do {
  ok = zmq_msg_recv(&msg, socket, 0);
  if (ok < 0) {
   fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
   return;
  }
  zmq_getsockopt(socket, 13, &rcvmore, &rcvmore_size);
  size_t size = zmq_msg_size(&msg);
  if (verbose)
   fprintf(stderr, "receiving %ld bytes\n", size);
  fwrite(zmq_msg_data(&msg), 1, size, stdout);
 } while (rcvmore);
}

canonical_original_code:
void zmqcat_recv(void *socket, int type, int verbose) {
 if (type == 8 || type == 1)
  return;
 int ok;
 long rcvmore = 0;
 unsigned long rcvmore_size = sizeof(rcvmore);
 struct zmq_msg_t msg;
 ok = zmq_msg_init(&msg);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return;
 }
 do {
  ok = zmq_msg_recv(&msg, socket, 0);
  if (ok < 0) {
   fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
   return;
  }
  zmq_getsockopt(socket, 13, &rcvmore, &rcvmore_size);
  unsigned long size = zmq_msg_size(&msg);
  if (verbose)
   fprintf(stderr, "receiving %ld bytes\n", size);
  fwrite(zmq_msg_data(&msg), 1, size, stdout);
 } while (rcvmore);
}

variable_types:
socket
void *

variable_types: type int

variable_types: verbose int

variable_types: ok int

variable_types: rcvmore long

variable_types: struct zmq_msg_t { unsigned char _[64]; }

variable_types:
size
unsigned long


decompiled_code:
void __fastcall zmqcat_send(__int64 a1, int a2, int a3)
{
__int64 v3; // r13
char *i; // rbx
char *v5; // rax
size_t v6; // rax
char *v7; // rbx
unsigned __int64 v8; // r14
char *v9; // r12
size_t v10; // rbp
void *v11; // rbx
void *v12; // rdi
int *v13; // rbx
const char *v14; // rax
char ptr[8192]; // [rsp+50h] [rbp-2048h] BYREF
void *v17; // [rsp+2050h] [rbp-48h]

if ( a2 != 7 && a2 != 2 )
{
v17 = 0LL;
v3 = 0LL;
for ( i = ptr; ; i = v5 )
{
v6 = fread(i, 1uLL, 0x2000uLL, stdin);
v3 += v6;
if ( v6 != 0x2000 )
break;
v5 = (char *)malloc(0x2008uLL);
*((_QWORD *)v5 + 1024) = 0LL;
*((_QWORD *)i + 1024) = v5;
}
if ( (int)zmq_msg_init_size() < 0 )
goto LABEL_14;
v7 = (char *)zmq_msg_data();
v8 = (unsigned __int64)&v7[v3];
v9 = ptr;
do
{
v10 = v8 - (_QWORD)v7;
if ( v8 > (unsigned __int64)(v7 + 0x2000) )
v10 = 0x2000LL;
memcpy(v7, v9, v10);
v9 = (char *)*((_QWORD *)v9 + 1024);
v7 += v10;
}
while ( v9 );
if ( a3 )
fprintf(stderr, "sending %ld bytes\n", v3);
if ( (int)zmq_msg_send() < 0 )
{
LABEL_14:
v13 = __errno_location();
v14 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v13, v14);
}
v11 = v17;
while ( v11 )
{
v12 = v11;
v11 = (void *)*((_QWORD *)v11 + 1024);
free(v12);
}
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2, int a3)
{
__int64 v3; // r13
char *i; // rbx
char *v5; // rax
size_t v6; // rax
char *v7; // rbx
unsigned __int64 v8; // r14
char *v9; // r12
size_t v10; // rbp
void *v11; // rbx
void *v12; // rdi
int *v13; // rbx
const char *v14; // rax
char ptr[8192]; // [rsp+50h] [rbp-2048h] BYREF
void *v17; // [rsp+2050h] [rbp-48h]

if ( a2 != 7 && a2 != 2 )
{
v17 = 0LL;
v3 = 0LL;
for ( i = ptr; ; i = v5 )
{
v6 = fread(i, 1uLL, 0x2000uLL, stdin);
v3 += v6;
if ( v6 != 0x2000 )
break;
v5 = (char *)malloc(0x2008uLL);
*((_QWORD *)v5 + 1024) = 0LL;
*((_QWORD *)i + 1024) = v5;
}
if ( (int)zmq_msg_init_size() < 0 )
goto LABEL_14;
v7 = (char *)zmq_msg_data();
v8 = (unsigned __int64)&v7[v3];
v9 = ptr;
do
{
v10 = v8 - (_QWORD)v7;
if ( v8 > (unsigned __int64)(v7 + 0x2000) )
v10 = 0x2000LL;
memcpy(v7, v9, v10);
v9 = (char *)*((_QWORD *)v9 + 1024);
v7 += v10;
}
while ( v9 );
if ( a3 )
fprintf(stderr, "sending %ld bytes\n", v3);
if ( (int)zmq_msg_send() < 0 )
{
LABEL_14:
v13 = __errno_location();
v14 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v13, v14);
}
v11 = v17;
while ( v11 )
{
v12 = v11;
v11 = (void *)*((_QWORD *)v11 + 1024);
free(v12);
}
}
}

original_code:
void zmqcat_send(void* socket, int type, int verbose) {
 char *sbuf, *tbuf;
 if (type == 7 || type == 2)
  return;
 char stack_buffer[8192 + sizeof(char *)];
 *(char **)(stack_buffer+8192) = ((void *)0);
 char* buffer = stack_buffer;
 size_t total = 0;
 while (1) {
  size_t read = fread(buffer, 1, 8192, stdin);
  total += read;
  if (read != 8192)
   break;
  char *new_buffer = malloc(8192 + sizeof(char *));
  *((char **)&new_buffer[8192]) = ((void *)0);
  *((char **)&buffer[8192]) = new_buffer;
  buffer = new_buffer;
 }
 int ok;
 zmq_msg_t msg;
 ok = zmq_msg_init_size(&msg, total);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  goto dealloc;
 }
 char *msg_at = (char *)zmq_msg_data(&msg);
 char *msg_end = msg_at + total;
 buffer = stack_buffer;
 while (buffer != ((void *)0)) {
  size_t chunk_size = 8192;
  if (msg_at + chunk_size >= msg_end)
   chunk_size = msg_end - msg_at;
  memcpy(msg_at, buffer, chunk_size);
  buffer = *(char **)&buffer[8192];
  msg_at += chunk_size;
 }
 if (verbose)
  fprintf(stderr, "sending %ld bytes\n", total);
 ok = zmq_msg_send(&msg, socket, 0);
 if (ok < 0)
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
dealloc:
 sbuf = *(char **)&stack_buffer[8192];
 while (sbuf) {
  tbuf = sbuf;
  sbuf = *(char **)&sbuf[8192];
  free(tbuf);
 }
}

canonical_original_code:
void zmqcat_send(void *socket, int type, int verbose) {
 char *sbuf; char *tbuf;
 if (type == 7 || type == 2)
  return;
 char stack_buffer[-1];
 *(char **)(stack_buffer+8192) = ((void *)0);
 char *buffer = stack_buffer;
 unsigned long total = 0;
 while (1) {
  unsigned long read = fread(buffer, 1, 8192, stdin);
  total += read;
  if (read != 8192)
   break;
  char *new_buffer = malloc(8192 + sizeof(char *));
  *((char **)&new_buffer[8192]) = ((void *)0);
  *((char **)&buffer[8192]) = new_buffer;
  buffer = new_buffer;
 }
 int ok;
 struct zmq_msg_t msg;
 ok = zmq_msg_init_size(&msg, total);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  goto dealloc;
 }
 char *msg_at = (char *)zmq_msg_data(&msg);
 char *msg_end = msg_at + total;
 buffer = stack_buffer;
 while (buffer != ((void *)0)) {
  unsigned long chunk_size = 8192;
  if (msg_at + chunk_size >= msg_end)
   chunk_size = msg_end - msg_at;
  memcpy(msg_at, buffer, chunk_size);
  buffer = *(char **)&buffer[8192];
  msg_at += chunk_size;
 }
 if (verbose)
  fprintf(stderr, "sending %ld bytes\n", total);
 ok = zmq_msg_send(&msg, socket, 0);
 if (ok < 0)
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
dealloc:
 sbuf = *(char **)&stack_buffer[8192];
 while (sbuf) {
  tbuf = sbuf;
  sbuf = *(char **)&sbuf[8192];
  free(tbuf);
 }
}

variable_types:
sbuf
char *

variable_types:
tbuf
char *

variable_types:
buffer
char *

variable_types:
total
unsigned long

variable_types:
read
unsigned long

user_defined_types: struct zmq_msg_t { unsigned char _[64]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
const char *v4; // r14
const char *v5; // r12
bool v6; // zf
int v7; // eax
char v8; // al
__int64 v9; // rbx
signed int v10; // eax
const char *v11; // rdx
int v12; // edx
int result; // eax
int *v14; // rbx
const char *v15; // rax
int v16; // [rsp+8h] [rbp-40h]
int v17; // [rsp+Ch] [rbp-3Ch]

v3 = 0;
v17 = 0;
v4 = 0LL;
v16 = 8;
while ( 1 )
{
v8 = getopt(argc, (char *const *)argv, "t:e:bv");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 't':
v5 = optarg;
if ( !strcasecmp(optarg, "pull") )
{
v16 = 7;
}
else if ( !strcasecmp(v5, "req") )
{
v16 = 3;
}
else if ( !strcasecmp(v5, "rep") )
{
v16 = 4;
}
else if ( !strcasecmp(v5, "pub") )
{
v16 = 1;
}
else
{
v6 = strcasecmp(v5, "sub") == 0;
v7 = v16;
if ( v6 )
v7 = 1;
v16 = v7;
}
break;
case 'e':
v4 = optarg;
break;
case 'b':
v17 = 1;
break;
case 'v':
v3 = 1;
break;
}
}
if ( v4 )
{
if ( !zmq_init() )
goto LABEL_42;
v9 = zmq_socket();
if ( !v9 )
goto LABEL_42;
v10 = v17 ? (unsigned int)zmq_bind() : (unsigned int)zmq_connect();
if ( v10 < 0 )
goto LABEL_42;
if ( v3 )
{
v11 = "bound";
if ( !v17 )
v11 = "connecting";
fprintf(stderr, "%s to %s\n", v11, v4);
}
if ( v16 == 4 )
{
zmqcat_recv(v9, 4, v3);
zmqcat_send(v9, 4, v3);
}
else
{
zmqcat_send(v9, v16, v3);
zmqcat_recv(v9, v16, v3);
}
if ( (int)zmq_close() < 0 || (v12 = zmq_term(), result = 0, v12 < 0) )
{
LABEL_42:
v14 = __errno_location();
v15 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v14, v15);
result = 1;
}
}
else
{
fprintf(stderr, "usage: %s [-t type] -e endpoint [-b] [-v]\n", *argv);
fwrite(" -t : PUSH | PULL | REQ | REP | PUB | SUB\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -e : endpoint, e.g. \"tcp://127.0.0.1:5000\"\n", 1uLL, 0x2DuLL, stderr);
fwrite(" -b : bind instead of connect\n", 1uLL, 0x1FuLL, stderr);
fwrite(" -v : verbose output to stderr\n", 1uLL, 0x20uLL, stderr);
result = 254;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
const char *v4; // r14
const char *v5; // r12
bool v6; // zf
int v7; // eax
char v8; // al
__int64 v9; // rbx
signed int v10; // eax
const char *v11; // rdx
int v12; // edx
int result; // eax
int *v14; // rbx
const char *v15; // rax
int v16; // [rsp+8h] [rbp-40h]
int v17; // [rsp+Ch] [rbp-3Ch]

v3 = 0;
v17 = 0;
v4 = 0LL;
v16 = 8;
while ( 1 )
{
v8 = getopt(argc, (char *const *)argv, "t:e:bv");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 't':
v5 = optarg;
if ( !strcasecmp(optarg, "pull") )
{
v16 = 7;
}
else if ( !strcasecmp(v5, "req") )
{
v16 = 3;
}
else if ( !strcasecmp(v5, "rep") )
{
v16 = 4;
}
else if ( !strcasecmp(v5, "pub") )
{
v16 = 1;
}
else
{
v6 = strcasecmp(v5, "sub") == 0;
v7 = v16;
if ( v6 )
v7 = 1;
v16 = v7;
}
break;
case 'e':
v4 = optarg;
break;
case 'b':
v17 = 1;
break;
case 'v':
v3 = 1;
break;
}
}
if ( v4 )
{
if ( !zmq_init() )
goto LABEL_42;
v9 = zmq_socket();
if ( !v9 )
goto LABEL_42;
v10 = v17 ? (unsigned int)zmq_bind() : (unsigned int)zmq_connect();
if ( v10 < 0 )
goto LABEL_42;
if ( v3 )
{
v11 = "bound";
if ( !v17 )
v11 = "connecting";
fprintf(stderr, "%s to %s\n", v11, v4);
}
if ( v16 == 4 )
{
func7(v9, 4, v3);
func8(v9, 4, v3);
}
else
{
func8(v9, v16, v3);
func7(v9, v16, v3);
}
if ( (int)zmq_close() < 0 || (v12 = zmq_term(), result = 0, v12 < 0) )
{
LABEL_42:
v14 = __errno_location();
v15 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v14, v15);
result = 1;
}
}
else
{
fprintf(stderr, "usage: %s [-t type] -e endpoint [-b] [-v]\n", *argv);
fwrite(" -t : PUSH | PULL | REQ | REP | PUB | SUB\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -e : endpoint, e.g. \"tcp://127.0.0.1:5000\"\n", 1uLL, 0x2DuLL, stderr);
fwrite(" -b : bind instead of connect\n", 1uLL, 0x1FuLL, stderr);
fwrite(" -v : verbose output to stderr\n", 1uLL, 0x20uLL, stderr);
result = 254;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
 int type = 8;
 char *endpoint = ((void *)0);
 int bind = 0;
 int verbose = 0;
 char c;
 while ((c = getopt(argc, argv, "t:e:bv")) != -1) {
  if (c == 't') {
   if (!strcasecmp(optarg, "pull"))
    type = 7;
   else if (!strcasecmp(optarg, "req"))
    type = 3;
   else if (!strcasecmp(optarg, "rep"))
    type = 4;
   else if (!strcasecmp(optarg, "pub"))
    type = 1;
   else if (!strcasecmp(optarg, "sub"))
    type = 1;
  }
  else if (c == 'e') {
   endpoint = optarg;
  }
  else if (c == 'b') {
   bind = 1;
  }
  else if (c == 'v') {
   verbose = 1;
  }
 }
 if (!endpoint) {
  fprintf(stderr, "usage: %s [-t type] -e endpoint [-b] [-v]\n", argv[0]);
  fprintf(stderr, "  -t : PUSH | PULL | REQ | REP | PUB | SUB\n");
  fprintf(stderr, "  -e : endpoint, e.g. \"tcp://127.0.0.1:5000\"\n");
  fprintf(stderr, "  -b : bind instead of connect\n");
  fprintf(stderr, "  -v : verbose output to stderr\n");
  return 254;
 }
 void *ctx = zmq_init(1);
 if (ctx == ((void *)0)) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return 1;
 }
 void *socket = zmq_socket(ctx, type);
 if (socket == ((void *)0)) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return 1;
 }
 int ok;
 if (bind)
  ok = zmq_bind(socket, endpoint);
 else
  ok = zmq_connect(socket, endpoint);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return 1;
 }
 if (verbose)
  fprintf(stderr, "%s to %s\n", (bind ? "bound" : "connecting"), endpoint);
 if (type == 4) {
  zmqcat_recv(socket, type, verbose);
  zmqcat_send(socket, type, verbose);
 }
 else {
  zmqcat_send(socket, type, verbose);
  zmqcat_recv(socket, type, verbose);
 }
 ok = zmq_close(socket);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return 1;
 }
 ok = zmq_term(ctx);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return 1;
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types:
endpoint
char *

variable_types: bind int

variable_types: c char

variable_types:
ctx
void *


repo: EmptyStackExn/ipgp-dtft

decompiled_code:
__int64 __fastcall init_array_window(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 result; // rax
__int64 v5; // rsi
__int64 v6; // rdx

result = a2;
if ( a3 > 0 )
{
v5 = (unsigned int)a3;
v6 = result + 4LL * a4 * a3;
for ( result = 0LL; result != v5; ++result )
*(_DWORD *)(a1 + 4 * result) = *(_DWORD *)(v6 + 4 * result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 result; // rax
__int64 v5; // rsi
__int64 v6; // rdx

result = a2;
if ( a3 > 0 )
{
v5 = (unsigned int)a3;
v6 = result + 4LL * a4 * a3;
for ( result = 0LL; result != v5; ++result )
*(_DWORD *)(a1 + 4 * result) = *(_DWORD *)(v6 + 4 * result);
}
return result;
}

original_code:
void init_array_window (float window[], float signal[], int samp_window_length, int index){
  int n;
  for (n = 0 ; n < samp_window_length ; n++)
    window [n] = signal [index * samp_window_length + n];
  return;
}

canonical_original_code:
void init_array_window(float window[], float signal[], int samp_window_length, int index){
  int n;
  for (n = 0 ; n < samp_window_length ; n++)
    window [n] = signal [index * samp_window_length + n];
  return;
}

variable_types:
window
float []

variable_types:
signal
float []

variable_types: index int

variable_types: n int


decompiled_code:
__int64 __fastcall int_of_string(__int64 a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1, &unk_1360, v2);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1, &unk_1360, v2);
return v2[0];
}

original_code:
int int_of_string (char *s){
  int n[1];
  sscanf (s, "%d", n);
  return n[0];
}

canonical_original_code:
int int_of_string(char *s){
  int n[1];
  sscanf (s, "%d", n);
  return n[0];
}

variable_types:
s
char *

variable_types:
n
int [1]


decompiled_code:
__int64 __fastcall is_number(char a1)
{
return (a1 == 45) | (unsigned __int8)((unsigned __int8)(a1 - 48) <= 9u);
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
return (a1 == 45) | (unsigned __int8)((unsigned __int8)(a1 - 48) <= 9u);
}


decompiled_code:
size_t __fastcall format_string_field_selection_as_lvm(char *s, int a2)
{
int i; // ebp
size_t result; // rax

*s = 0;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
strcat(s, "%*f\t");
}
result = strlen(s);
strcpy(&s[result], "%f");
return result;
}

canonical_decompiled_code:
size_t __fastcall func5(char *s, int a2)
{
int i; // ebp
size_t result; // rax

*s = 0;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
strcat(s, "%*f\t");
}
result = strlen(s);
strcpy(&s[result], "%f");
return result;
}

original_code:
void format_string_field_selection_as_lvm (char *s, int n){
  int i;
  strcpy (s, "");
  for (i = 0 ; i < n ; i++)
    strcat (s, "%*f\t");
  strcat (s, "%f");
}

canonical_original_code:
void format_string_field_selection_as_lvm(char *s, int n){
  int i;
  strcpy (s, "");
  for (i = 0 ; i < n ; i++)
    strcat (s, "%*f\t");
  strcat (s, "%f");
}

variable_types: i int


decompiled_code:
int __fastcall print_float_array(int a1, float *a2)
{
float *v3; // rbx

if ( a1 > 6 )
return printf("{ %f, %f, ..., %f }", *a2, a2[1], a2[a1 - 1]);
printf("{ ");
if ( a1 > 0 )
{
v3 = a2;
do
printf("%f ; ", *v3++);
while ( v3 != &a2[a1 - 1 + 1] );
}
return printf(" }");
}

original_code:
void print_float_array (int length, float t[]){
  if (length < 7){
    int i;
    printf("{ ");
    for (i = 0 ; i < length ; i++)
      printf ("%f ; ", t[i]);
    printf(" }");
    return;
  }
  else{
    printf("{ %f, %f, ..., %f }", t[0], t[1], t[length - 1]);
  }
}

canonical_original_code:
void print_float_array(int length, float t[]){
  if (length < 7){
    int i;
    printf("{ ");
    for (i = 0 ; i < length ; i++)
      printf ("%f ; ", t[i]);
    printf(" }");
    return;
  }
  else{
    printf("{ %f, %f, ..., %f }", t[0], t[1], t[length - 1]);
  }
}

variable_types: length int

variable_types:
t
float []


decompiled_code:
void __fastcall frequency_components_array_init(__int64 a1, float a2, float a3, float a4)
{
int v4; // edx
float v5; // xmm1_4
__int64 i; // rax

v4 = (int)(float)(a3 / a4);
if ( v4 > 0 )
{
v5 = a2 - (float)(a3 * 0.5);
for ( i = 0LL; i != v4; ++i )
*(float *)(a1 + 4 * i) = (float)((float)(int)i * a4) + v5;
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, float a2, float a3, float a4)
{
int v4; // edx
float v5; // xmm1_4
__int64 i; // rax

v4 = (int)(float)(a3 / a4);
if ( v4 > 0 )
{
v5 = a2 - (float)(a3 * 0.5);
for ( i = 0LL; i != v4; ++i )
*(float *)(a1 + 4 * i) = (float)((float)(int)i * a4) + v5;
}
}

original_code:
void frequency_components_array_init (float central_frequency, float span, float bandwidth_res, float frequency_components[]){
  int number_frequency_components = (int) (span / bandwidth_res);
  int i;
  for (i = 0 ; i < number_frequency_components ; i++){
    frequency_components[i] = (central_frequency - (span / 2)) + i * bandwidth_res;
  }
}

canonical_original_code:
void frequency_components_array_init(float central_frequency, float span, float bandwidth_res, float frequency_components[]){
  int number_frequency_components = (int) (span / bandwidth_res);
  int i;
  for (i = 0 ; i < number_frequency_components ; i++){
    frequency_components[i] = (central_frequency - (span / 2)) + i * bandwidth_res;
  }
}

variable_types: span float


replace

decompiled_code:
char *__fastcall replace(char *src, char *s, const char *a3)
{
char *v4; // rbx
char *result; // rax
size_t v6; // rax

v4 = strstr(src, s);
result = src;
if ( v4 )
{
strncpy(buffer_0, src, v4 - src);
buffer_0[v4 - src] = 0;
v6 = strlen(s);
sprintf(&buffer_0[v4 - src], "%s%s", a3, &v4[v6]);
result = buffer_0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(char *src, char *s, const char *a3)
{
char *v4; // rbx
char *result; // rax
size_t v6; // rax

v4 = strstr(src, s);
result = src;
if ( v4 )
{
strncpy(buffer_0, src, v4 - src);
buffer_0[v4 - src] = 0;
v6 = strlen(s);
sprintf(&buffer_0[v4 - src], "%s%s", a3, &v4[v6]);
result = buffer_0;
}
return result;
}

original_code:
char* replace(char *st, char *orig, char *repl) {
  static char buffer[4096];
  char *ch;
  if (!(ch = strstr(st, orig)))
   return st;
  strncpy(buffer, st, ch-st);
  buffer[ch-st] = 0;
  sprintf(buffer+(ch-st), "%s%s", repl, ch+strlen(orig));
  return buffer;
}

canonical_original_code:
char *replace(char *st, char *orig, char *repl) {
  static char buffer[4096];
  char *ch;
  if (!(ch = strstr(st, orig)))
   return st;
  strncpy(buffer, st, ch-st);
  buffer[ch-st] = 0;
  sprintf(buffer+(ch-st), "%s%s", repl, ch+strlen(orig));
  return buffer;
}

variable_types:
st
char *

variable_types:
orig
char *

variable_types:
repl
char *

variable_types:
buffer
char [4096]

variable_types:
ch
char *

return_type: char *


decompiled_code:
char *__fastcall string2float(char *a1)
{
return replace(a1, ",", ".");
}

canonical_decompiled_code:
char *__fastcall func9(char *a1)
{
return func8(a1, ",", ".");
}

original_code:
char* string2float(char* buf){
  return replace(buf,",",".");
}

canonical_original_code:
char *string2float(char *buf){
  return replace(buf,",",".");
}

variable_types:
buf
char *


decompiled_code:
void __noreturn print_usage()
{
puts(
"usage: slimebattery <option> [...]\n"
" --help\t\t\tprint this help message\n"
" --change-icon\t\t\tchange tray icon theme (chane if you miss default icon)\n"
" --verbose\t\t\ttray icon's tooltip will display extra info\n"
" --colors\t\t\t(only in text-mode) change text color (green when it's full, red when it's low)\n"
" --text-mode <font size>\tshow battery status in plain text mode\n"
" --interval <time>\t\tcheck battery status at every specified seconds");
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
puts(
"usage: slimebattery <option> [...]\n"
" --help\t\t\tprint this help message\n"
" --change-icon\t\t\tchange tray icon theme (chane if you miss default icon)\n"
" --verbose\t\t\ttray icon's tooltip will display extra info\n"
" --colors\t\t\t(only in text-mode) change text color (green when it's full, red when it's low)\n"
" --text-mode <font size>\tshow battery status in plain text mode\n"
" --interval <time>\t\tcheck battery status at every specified seconds");
exit(0);
}

original_code:
static void print_usage(void)
{
    printf("usage: slimebattery <option> [...]\n"
           "  --help\t\t\tprint this help message\n"
           "  --change-icon\t\t\tchange tray icon theme (chane if you miss default icon)\n"
           "  --verbose\t\t\ttray icon's tooltip will display extra info\n"
           "  --colors\t\t\t(only in text-mode) change text color (green when it's full, red when it's low)\n"
           "  --text-mode <font size>\tshow battery status in plain text mode\n"
           "  --interval <time>\t\tcheck battery status at every specified seconds\n");
    exit(0);
}

canonical_original_code:
static void print_usage()
{
    printf("usage: slimebattery <option> [...]\n"
           "  --help\t\t\tprint this help message\n"
           "  --change-icon\t\t\tchange tray icon theme (chane if you miss default icon)\n"
           "  --verbose\t\t\ttray icon's tooltip will display extra info\n"
           "  --colors\t\t\t(only in text-mode) change text color (green when it's full, red when it's low)\n"
           "  --text-mode <font size>\tshow battery status in plain text mode\n"
           "  --interval <time>\t\tcheck battery status at every specified seconds\n");
    exit(0);
}


indexof

decompiled_code:
__int64 __fastcall indexof(const char *a1, char a2)
{
char *v2; // rax
__int64 result; // rax

v2 = strchr(a1, a2);
if ( v2 )
result = (unsigned int)((_DWORD)v2 - (_DWORD)a1);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, char a2)
{
char *v2; // rax
__int64 result; // rax

v2 = strchr(a1, a2);
if ( v2 )
result = (unsigned int)((_DWORD)v2 - (_DWORD)a1);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static gint indexof(gchar * string, gchar c)
{
    gchar * p = strchr(string, c);
    return p ? strchr(string, c) - string : -1;
}

canonical_original_code:
static int indexof(char *string, char c)
{
    char *p = strchr(string, c);
    return p ? strchr(string, c) - string : -1;
}

variable_types:
string
char *

variable_types: c char

variable_types:
p
char *


repo: Ensembl/WiggleTools

original_code:
static char hashlist_increment(HashList* hl, int key) {
 int i;
 for (i = 0; i < hl->count; i++)
  if (hl->list[i].key == key) {
   hl->list[i].value++;
   return 1;
  }
 hl->list[hl->count].key = key;
 hl->list[hl->count].value = 1;
 hl->count++;
 return 0;
}

canonical_original_code:
static char hashlist_increment(struct hashlist_st *hl, int key) {
 int i;
 for (i = 0; i < hl->count; i++)
  if (hl->list[i].key == key) {
   hl->list[i].value++;
   return 1;
  }
 hl->list[hl->count].key = key;
 hl->list[hl->count].value = 1;
 hl->count++;
 return 0;
}

variable_types: struct hashlist_st { unsigned long size; unsigned long count; struct hashel_st { int key; int value; } *list; } *

variable_types: key int

user_defined_types: struct hashlist_st { unsigned long size; unsigned long count; struct hashel_st *list; }


original_code:
static int hashlist_remove(HashList * hl, int key) {
 int i;
 int value = 0;
 char found = 0;
 for (i = 0; i < hl->count; i++) {
  if (hl->list[i].key == key) {
   value = hl->list[i].value;
   found = 1;
  }
  if (found && i < hl->count - 1) {
   hl->list[i].key = hl->list[i+1].key;
   hl->list[i].value = hl->list[i+1].value;
  }
 }
 if (found)
  hl->count--;
 return value;
}

canonical_original_code:
static int hashlist_remove(struct hashlist_st *hl, int key) {
 int i;
 int value = 0;
 char found = 0;
 for (i = 0; i < hl->count; i++) {
  if (hl->list[i].key == key) {
   value = hl->list[i].value;
   found = 1;
  }
  if (found && i < hl->count - 1) {
   hl->list[i].key = hl->list[i+1].key;
   hl->list[i].value = hl->list[i+1].value;
  }
 }
 if (found)
  hl->count--;
 return value;
}

variable_types: value int

variable_types: found char

user_defined_types: struct hashel_st { int key; int value; }


decompiled_code:
_QWORD *hash_construct()
{
_QWORD *v0; // rbp
__int64 i; // rbx

v0 = calloc(8uLL, 1uLL);
*v0 = calloc(0x18uLL, 0x400uLL);
for ( i = 0LL; i != 24576; i += 24LL )
hashlist_init((_QWORD *)(*v0 + i));
return v0;
}

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *v0; // rbp
__int64 i; // rbx

v0 = calloc(8uLL, 1uLL);
*v0 = calloc(0x18uLL, 0x400uLL);
for ( i = 0LL; i != 24576; i += 24LL )
func2((_QWORD *)(*v0 + i));
return v0;
}

original_code:
Hash *hash_construct() {
 Hash * res = (Hash *) calloc(sizeof(Hash), 1);
 res->lists = calloc(sizeof(HashList), BUCKET_COUNT);
 int i;
 for (i =0; i < BUCKET_COUNT; i++)
  hashlist_init(res->lists + i);
 return res;
}

canonical_original_code:
struct hash_st *hash_construct() {
 struct hash_st *res = (Hash *) calloc(sizeof(Hash), 1);
 res->lists = calloc(sizeof(HashList), BUCKET_COUNT);
 int i;
 for (i =0; i < BUCKET_COUNT; i++)
  hashlist_init(res->lists + i);
 return res;
}

variable_types: struct hash_st { struct hashlist_st { unsigned long size; unsigned long count; struct hashel_st { int key; int value; } *list; } *lists; } *

variable_types: i int

user_defined_types: struct hash_st { struct hashlist_st *lists; }


decompiled_code:
void __fastcall hash_destroy(void *ptr)
{
__int64 i; // rbx

for ( i = 0LL; i != 24576; i += 24LL )
hashlist_destroy(*(_QWORD *)ptr + i);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
__int64 i; // rbx

for ( i = 0LL; i != 24576; i += 24LL )
func3(*(_QWORD *)ptr + i);
free(*(void **)ptr);
free(ptr);
}

original_code:
void hash_destroy(Hash * hash) {
 int i;
 for (i =0; i < BUCKET_COUNT; i++)
  hashlist_destroy(hash->lists + i);
 free(hash->lists);
 free(hash);
}

canonical_original_code:
void hash_destroy(struct hash_st *hash) {
 int i;
 for (i =0; i < BUCKET_COUNT; i++)
  hashlist_destroy(hash->lists + i);
 free(hash->lists);
 free(hash);
}


decompiled_code:
__int64 __fastcall hash_increment(_QWORD *a1, int a2)
{
return hashlist_increment(*a1 + 24LL * (a2 & 0x3FF), a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, int a2)
{
return func0(*a1 + 24LL * (a2 & 0x3FF), a2);
}

original_code:
char hash_increment(Hash * hash, int key) {
 return hashlist_increment(hash->lists + (key % BUCKET_COUNT), key);
}

canonical_original_code:
char hash_increment(struct hash_st *hash, int key) {
 return hashlist_increment(hash->lists + (key % BUCKET_COUNT), key);
}


decompiled_code:
__int64 __fastcall hash_remove(_QWORD *a1, int a2)
{
return hashlist_remove(*a1 + 24LL * (a2 & 0x3FF), a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2)
{
return func1(*a1 + 24LL * (a2 & 0x3FF), a2);
}

original_code:
int hash_remove(Hash * hash, int key) {
 return hashlist_remove(hash->lists + (key % BUCKET_COUNT), key);
}

canonical_original_code:
int hash_remove(struct hash_st *hash, int key) {
 return hashlist_remove(hash->lists + (key % BUCKET_COUNT), key);
}


createBlockData

decompiled_code:
_QWORD *createBlockData()
{
_QWORD *v0; // rbx

v0 = calloc(1uLL, 0x30uLL);
*v0 = calloc(0x2710uLL, 8uLL);
v0[1] = calloc(0x2710uLL, 4uLL);
v0[2] = calloc(0x2710uLL, 4uLL);
v0[3] = calloc(0x2710uLL, 8uLL);
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rbx

v0 = calloc(1uLL, 0x30uLL);
*v0 = calloc(0x2710uLL, 8uLL);
v0[1] = calloc(0x2710uLL, 4uLL);
v0[2] = calloc(0x2710uLL, 4uLL);
v0[3] = calloc(0x2710uLL, 8uLL);
return v0;
}

original_code:
static BlockData * createBlockData() {
 BlockData * new = (BlockData * ) calloc(1, sizeof(BlockData));
 new->chrom = (char **) calloc(BLOCK_SIZE, sizeof(char*));
 new->start = (int *) calloc(BLOCK_SIZE, sizeof(int));
 new->finish = (int *) calloc(BLOCK_SIZE, sizeof(int));
 new->value = (double *) calloc(BLOCK_SIZE, sizeof(double));
 return new;
}

canonical_original_code:
static struct blockData_st *createBlockData() {
 struct blockData_st *new = (BlockData * ) calloc(1, sizeof(BlockData));
 new->chrom = (char **) calloc(BLOCK_SIZE, sizeof(char *));
 new->start = (int *) calloc(BLOCK_SIZE, sizeof(int));
 new->finish = (int *) calloc(BLOCK_SIZE, sizeof(int));
 new->value = (double *) calloc(BLOCK_SIZE, sizeof(double));
 return new;
}

variable_types: struct blockData_st { char **chrom; int *start; int *finish; double *value; int count; struct blockData_st *next; } *


declareNewBlock

decompiled_code:
__int64 __fastcall declareNewBlock(__int64 a1)
{
pthread_mutex_t *v1; // rbp
int v2; // eax
__int64 result; // rax

v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
if ( *(int *)(a1 + 112) > 3 )
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v1);
v2 = *(_DWORD *)(a1 + 112);
if ( v2 < 0 )
{
pthread_mutex_unlock(v1);
result = 1LL;
}
else
{
*(_DWORD *)(a1 + 112) = v2 + 1;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock(v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
pthread_mutex_t *v1; // rbp
int v2; // eax
__int64 result; // rax

v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
if ( *(int *)(a1 + 112) > 3 )
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v1);
v2 = *(_DWORD *)(a1 + 112);
if ( v2 < 0 )
{
pthread_mutex_unlock(v1);
result = 1LL;
}
else
{
*(_DWORD *)(a1 + 112) = v2 + 1;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock(v1);
result = 0LL;
}
return result;
}

original_code:
static char declareNewBlock(BufferedReaderData * data) {
 pthread_mutex_lock(&data->count_mutex);
 if (data->blockCount > MAX_HEAD_START) {
  pthread_cond_wait(&data->count_cond, &data->count_mutex);
 }
 if (data->blockCount < 0) {
  pthread_mutex_unlock(&data->count_mutex);
  return 1;
 }
 data->blockCount++;
 pthread_cond_signal(&data->count_cond);
 pthread_mutex_unlock(&data->count_mutex);
 return 0;
}

canonical_original_code:
static char declareNewBlock(struct bufferedReaderData_st *data) {
 pthread_mutex_lock(&data->count_mutex);
 if (data->blockCount > MAX_HEAD_START) {
  pthread_cond_wait(&data->count_cond, &data->count_mutex);
 }
 if (data->blockCount < 0) {
  pthread_mutex_unlock(&data->count_mutex);
  return 1;
 }
 data->blockCount++;
 pthread_cond_signal(&data->count_cond);
 pthread_mutex_unlock(&data->count_mutex);
 return 0;
}

variable_types: struct bufferedReaderData_st { unsigned long downloaderThreadID; struct blockData_st { char **chrom; int *start; int *finish; double *value; int count; struct blockData_st *next; } *blockData; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } count_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } count_cond; int blockCount; int readIndex; void *readerData; char killed; } *

user_defined_types: struct bufferedReaderData_st { unsigned long downloaderThreadID; struct blockData_st *blockData; union pthread_mutex_t count_mutex; union pthread_cond_t count_cond; int blockCount; int readIndex; void *readerData; char killed; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }