decompiled_code:
__int64 __fastcall read_register(unsigned __int8 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
char v5[28]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = a1;
if ( (unsigned int)i2c_writeb(a1, v5, 0LL) )
result = 0xFFFFFFFFLL;
else
result = i2c_read(a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
char v5[28]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = a1;
if ( (unsigned int)i2c_writeb(a1, v5, 0LL) )
result = 0xFFFFFFFFLL;
else
result = i2c_read(a2, a3);
return result;
}

original_code:
int read_register(uint8_t reg, uint8_t *data, int len){
  if(i2c_writeb(reg, &reg, 0))
    return -1;
  return i2c_read(data, len);
}

canonical_original_code:
int read_register(unsigned char reg, unsigned char *data, int len){
  if(i2c_writeb(reg, &reg, 0))
    return -1;
  return i2c_read(data, len);
}

variable_types:
reg
unsigned char

variable_types:
data
unsigned char *

variable_types: len int


repo: anre/lielas

decompiled_code:
__int64 __fastcall rtc4162_get(__int64 a1)
{
__int64 result; // rax
char v2; // [rsp+0h] [rbp-28h] BYREF
unsigned __int8 v3; // [rsp+1h] [rbp-27h]
unsigned __int8 v4; // [rsp+2h] [rbp-26h]
unsigned __int8 v5; // [rsp+3h] [rbp-25h]
unsigned __int8 v6; // [rsp+5h] [rbp-23h]
unsigned __int8 v7; // [rsp+6h] [rbp-22h]
unsigned __int8 v8; // [rsp+7h] [rbp-21h]

v2 = 0;
if ( oscfailed )
{
lielas_log("rtc error: failed to read date/time, oscfailed flag is set", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
result = read_register(0, (__int64)&v2, 8u);
if ( (_DWORD)result )
{
lielas_log("rtc error: failed to read date/time", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)a1 = (v3 & 0xF) + 10 * ((v3 >> 4) & 7);
*(_DWORD *)(a1 + 4) = (v4 & 0xF) + 10 * ((v4 >> 4) & 7);
*(_DWORD *)(a1 + 8) = (v5 & 0xF) + 10 * ((v5 >> 4) & 3);
*(_DWORD *)(a1 + 12) = (v6 & 0xF) + 10 * ((v6 >> 4) & 3);
*(_DWORD *)(a1 + 16) = (v7 & 0xF) + 10 * ((v7 >> 4) & 1);
*(_QWORD *)(a1 + 20) = (v8 & 0xF) + 10 * (unsigned int)(v8 >> 4) + 100;
*(_DWORD *)(a1 + 28) = 0;
*(_DWORD *)(a1 + 32) = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
char v2; // [rsp+0h] [rbp-28h] BYREF
unsigned __int8 v3; // [rsp+1h] [rbp-27h]
unsigned __int8 v4; // [rsp+2h] [rbp-26h]
unsigned __int8 v5; // [rsp+3h] [rbp-25h]
unsigned __int8 v6; // [rsp+5h] [rbp-23h]
unsigned __int8 v7; // [rsp+6h] [rbp-22h]
unsigned __int8 v8; // [rsp+7h] [rbp-21h]

v2 = 0;
if ( oscfailed )
{
lielas_log("rtc error: failed to read date/time, oscfailed flag is set", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
result = func0(0, (__int64)&v2, 8u);
if ( (_DWORD)result )
{
lielas_log("rtc error: failed to read date/time", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)a1 = (v3 & 0xF) + 10 * ((v3 >> 4) & 7);
*(_DWORD *)(a1 + 4) = (v4 & 0xF) + 10 * ((v4 >> 4) & 7);
*(_DWORD *)(a1 + 8) = (v5 & 0xF) + 10 * ((v5 >> 4) & 3);
*(_DWORD *)(a1 + 12) = (v6 & 0xF) + 10 * ((v6 >> 4) & 3);
*(_DWORD *)(a1 + 16) = (v7 & 0xF) + 10 * ((v7 >> 4) & 1);
*(_QWORD *)(a1 + 20) = (v8 & 0xF) + 10 * (unsigned int)(v8 >> 4) + 100;
*(_DWORD *)(a1 + 28) = 0;
*(_DWORD *)(a1 + 32) = 0;
}
}
return result;
}

canonical_original_code:
int rtc4162_get(struct tm *dt){
  unsigned char buf[20];
  buf[0] = 0;
  if(oscfailed){
    lielas_log((unsigned char *)"rtc error: failed to read date/time, oscfailed flag is set", 0);
    return -1;
  }
  if(read_register(0x00, buf, 8)){
    lielas_log((unsigned char *)"rtc error: failed to read date/time", 0);
    return -1;
  }
  dt->tm_sec = ((((buf[1] & 0x7F)>>4) & 0x0F)*10 + ((buf[1] & 0x7F) & 0x0F));
  dt->tm_min = ((((buf[2] & 0x7F)>>4) & 0x0F)*10 + ((buf[2] & 0x7F) & 0x0F));
  dt->tm_hour= ((((buf[3] & 0x3F)>>4) & 0x0F)*10 + ((buf[3] & 0x3F) & 0x0F));
  dt->tm_mday= ((((buf[5] & 0x3F)>>4) & 0x0F)*10 + ((buf[5] & 0x3F) & 0x0F));
  dt->tm_mon = ((((buf[6] & 0x1F)>>4) & 0x0F)*10 + ((buf[6] & 0x1F) & 0x0F));
  dt->tm_year= ((((buf[7] & 0xFF)>>4) & 0x0F)*10 + ((buf[7] & 0xFF) & 0x0F)) + 100;
  dt->tm_wday = 0;
  dt->tm_yday = 0;
  dt->tm_isdst = 0;
  return 0;
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
buf
unsigned char [20]

return_type: int


decompiled_code:
__int64 __fastcall write_register(unsigned __int8 a1, __int64 a2, __int64 a3)
{
if ( (int)a3 <= 16 )
return i2c_writeb(a1, a2, a3);
lielas_log("rtc write_register error: len to big", 1LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, __int64 a2, __int64 a3)
{
if ( (int)a3 <= 16 )
return i2c_writeb(a1, a2, a3);
lielas_log("rtc write_register error: len to big", 1LL);
return 0xFFFFFFFFLL;
}

original_code:
int write_register(uint8_t reg, uint8_t *data, int len){
  if(len > 16){
    lielas_log((uint8_t *)"rtc write_register error: len to big", 1);
    return -1;
  }
  return i2c_writeb(reg, data, len);
}

canonical_original_code:
int write_register(unsigned char reg, unsigned char *data, int len){
  if(len > 16){
    lielas_log((unsigned char *)"rtc write_register error: len to big", 1);
    return -1;
  }
  return i2c_writeb(reg, data, len);
}


decompiled_code:
__int64 rtc4162_init()
{
__int64 result; // rax
unsigned __int8 v1; // bp
char v2[25]; // [rsp+Fh] [rbp-19h] BYREF

i2c_init(104LL, 1LL);
if ( (unsigned __int8)read_register(0xFu, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_FLAGS", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
oscfailed = 0;
result = 0LL;
if ( (v2[0] & 4) != 0 )
{
oscfailed = 1;
lielas_log("rtc: oscillator failure or initial startup", 1LL);
v2[0] |= 0x80u;
v1 = write_register(1u, (__int64)v2, 1LL);
v2[0] &= 0x7Fu;
if ( (unsigned __int8)write_register(1u, (__int64)v2, 1LL) | v1 )
{
lielas_log("rtc error: failed to reset oscillator", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
sleep(5u);
if ( (unsigned __int8)read_register(4u, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_DAYOW", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
v2[0] &= 0xFu;
if ( (unsigned __int8)write_register(4u, (__int64)v2, 1LL) )
{
lielas_log("rtc error: failed to write REG_DAYOW", 0LL);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned __int8)read_register(0xAu, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_MONTH_ALARM", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
v2[0] &= 0xBFu;
if ( (unsigned __int8)write_register(0xAu, (__int64)v2, 1LL) )
{
lielas_log("rtc error: failed to write REG_MONTH_ALARM", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
unsigned __int8 v1; // bp
char v2[25]; // [rsp+Fh] [rbp-19h] BYREF

i2c_init(104LL, 1LL);
if ( (unsigned __int8)func0(0xFu, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_FLAGS", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
oscfailed = 0;
result = 0LL;
if ( (v2[0] & 4) != 0 )
{
oscfailed = 1;
lielas_log("rtc: oscillator failure or initial startup", 1LL);
v2[0] |= 0x80u;
v1 = func2(1u, (__int64)v2, 1LL);
v2[0] &= 0x7Fu;
if ( (unsigned __int8)func2(1u, (__int64)v2, 1LL) | v1 )
{
lielas_log("rtc error: failed to reset oscillator", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
sleep(5u);
if ( (unsigned __int8)func0(4u, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_DAYOW", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
v2[0] &= 0xFu;
if ( (unsigned __int8)func2(4u, (__int64)v2, 1LL) )
{
lielas_log("rtc error: failed to write REG_DAYOW", 0LL);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned __int8)func0(0xAu, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_MONTH_ALARM", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
v2[0] &= 0xBFu;
if ( (unsigned __int8)func2(0xAu, (__int64)v2, 1LL) )
{
lielas_log("rtc error: failed to write REG_MONTH_ALARM", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
}
}
}
}
return result;
}

original_code:
int rtc4162_init(){
  uint8_t byte;
  uint8_t status;
  i2c_init(0x68, 1);
  status = read_register(0x0F, &byte, 1);
  if(status){
    lielas_log((uint8_t *)"rtc error: failed to read REG_FLAGS", 0);
    return -1;
  }
  oscfailed = 0;
  if(byte & (1<<(2))){
    oscfailed = 1;
    lielas_log((uint8_t *)"rtc: oscillator failure or initial startup", 1);
    byte |= (1<<(7));
    status |= write_register(0x01, &byte, 1);
  byte &= ~(1<<(7));
  status |= write_register(0x01, &byte, 1);
    if(status){
      lielas_log((uint8_t *)"rtc error: failed to reset oscillator", 0);
      return -1;
    }
    sleep(5);
  status = read_register(0x04, &byte, 1);
    if(status){
      lielas_log((uint8_t *)"rtc error: failed to read REG_DAYOW", 0);
      return -1;
    }
  byte &= 0x0F;
  status = write_register(0x04, &byte, 1);
    if(status){
      lielas_log((uint8_t *)"rtc error: failed to write REG_DAYOW", 0);
      return -1;
    }
  status = read_register(0x0A, &byte, 1);
    if(status){
      lielas_log((uint8_t *)"rtc error: failed to read REG_MONTH_ALARM", 0);
      return -1;
    }
  byte &= ~(1<<(6));
  status = write_register(0x0A, &byte, 1);
    if(status){
      lielas_log((uint8_t *)"rtc error: failed to write REG_MONTH_ALARM", 0);
      return -1;
    }
  }
  return 0;
}

canonical_original_code:
int rtc4162_init(){
  unsigned char byte;
  unsigned char status;
  i2c_init(0x68, 1);
  status = read_register(0x0F, &byte, 1);
  if(status){
    lielas_log((unsigned char *)"rtc error: failed to read REG_FLAGS", 0);
    return -1;
  }
  oscfailed = 0;
  if(byte & (1<<(2))){
    oscfailed = 1;
    lielas_log((unsigned char *)"rtc: oscillator failure or initial startup", 1);
    byte |= (1<<(7));
    status |= write_register(0x01, &byte, 1);
  byte &= ~(1<<(7));
  status |= write_register(0x01, &byte, 1);
    if(status){
      lielas_log((unsigned char *)"rtc error: failed to reset oscillator", 0);
      return -1;
    }
    sleep(5);
  status = read_register(0x04, &byte, 1);
    if(status){
      lielas_log((unsigned char *)"rtc error: failed to read REG_DAYOW", 0);
      return -1;
    }
  byte &= 0x0F;
  status = write_register(0x04, &byte, 1);
    if(status){
      lielas_log((unsigned char *)"rtc error: failed to write REG_DAYOW", 0);
      return -1;
    }
  status = read_register(0x0A, &byte, 1);
    if(status){
      lielas_log((unsigned char *)"rtc error: failed to read REG_MONTH_ALARM", 0);
      return -1;
    }
  byte &= ~(1<<(6));
  status = write_register(0x0A, &byte, 1);
    if(status){
      lielas_log((unsigned char *)"rtc error: failed to write REG_MONTH_ALARM", 0);
      return -1;
    }
  }
  return 0;
}

variable_types:
byte
unsigned char

variable_types:
status
unsigned char


canonical_original_code:
int rtc4162_set(struct tm *dt){
  unsigned char buf[10] = {0};
  buf[1] = (buf[1] & ~0x7F) | ((((((dt->tm_sec)/10)<<4) & 0xF0) + (dt->tm_sec)%10) & 0x7F);
 buf[2] = (buf[2] & ~0x7F) | ((((((dt->tm_min)/10)<<4) & 0xF0) + (dt->tm_min)%10) & 0x7F);
 buf[3] = (buf[3] & ~0x3F) | ((((((dt->tm_hour)/10)<<4) & 0xF0) + (dt->tm_hour)%10) & 0x3F);
 buf[5] = (buf[5] & ~0x3F) | ((((((dt->tm_mday)/10)<<4) & 0xF0) + (dt->tm_mday)%10) & 0x3F);
 buf[6] = (buf[6] & ~0x1F) | ((((((dt->tm_mon)/10)<<4) & 0xF0) + (dt->tm_mon)%10) & 0x1F);
 buf[7] = (buf[7] & ~0xFF) | (((((((unsigned char)(dt->tm_year - 100))/10)<<4) & 0xF0) + ((unsigned char)(dt->tm_year - 100))%10) & 0xFF);
  if(write_register(0x00, buf, 8)){
    lielas_log((unsigned char *)"rtc error: failed to set date/time", 0);
    return -1;
  }
  if(oscfailed){
    buf[0] = 0;
    if(read_register(0x0F, buf, 1)){
      lielas_log((unsigned char *)"rtc error: failed to read REG_FLAGS", 0);
      return -1;
    }
    buf[0] &= ~(1<<(2));
    if(write_register(0x0F, buf, 1)){
      lielas_log((unsigned char *)"rtc error: failed to write REG_FLAGS", 0);
      return -1;
    }
  }
  return 0;
}

variable_types:
buf
unsigned char [10]

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


parseAttribute

decompiled_code:
__int64 __fastcall parseAttribute(__int64 a1, const char *a2, char *a3, int a4, __int64 a5)
{
__int64 v5; // rbx
__int64 v6; // r15
__int64 result; // rax
size_t v11; // rax
int v12; // edx
int v13; // esi
int v14; // edx
char v15[5064]; // [rsp+0h] [rbp-13C8h] BYREF

v5 = 16LL * a4;
v6 = a5 + v5;
result = 0LL;
if ( *(_DWORD *)(a5 + v5) == 3 )
{
v11 = strlen(a2);
v12 = strncmp((const char *)(a1 + *(int *)(v6 + 4)), a2, v11);
result = 0LL;
if ( !v12 )
{
v13 = *(_DWORD *)(a5 + v5 + 20);
v14 = *(_DWORD *)(a5 + v5 + 24) - v13;
if ( v14 > 255 )
{
snprintf(v15, 0x1388uLL, "attribute %s too big", a2);
lielas_log(v15, 1LL);
result = 0xFFFFFFFFLL;
}
else
{
strncpy(a3, (const char *)(a1 + v13), v14);
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, char *a3, int a4, __int64 a5)
{
__int64 v5; // rbx
__int64 v6; // r15
__int64 result; // rax
size_t v11; // rax
int v12; // edx
int v13; // esi
int v14; // edx
char v15[5064]; // [rsp+0h] [rbp-13C8h] BYREF

v5 = 16LL * a4;
v6 = a5 + v5;
result = 0LL;
if ( *(_DWORD *)(a5 + v5) == 3 )
{
v11 = strlen(a2);
v12 = strncmp((const char *)(a1 + *(int *)(v6 + 4)), a2, v11);
result = 0LL;
if ( !v12 )
{
v13 = *(_DWORD *)(a5 + v5 + 20);
v14 = *(_DWORD *)(a5 + v5 + 24) - v13;
if ( v14 > 255 )
{
snprintf(v15, 0x1388uLL, "attribute %s too big", a2);
lielas_log(v15, 1LL);
result = 0xFFFFFFFFLL;
}
else
{
strncpy(a3, (const char *)(a1 + v13), v14);
result = 1LL;
}
}
}
return result;
}

original_code:
int parseAttribute(char *file, char *attr, char *val, int nt, jsmntok_t *tok){
  int attrLen;
  char log[5000];
  if( tok[nt].type == JSMN_STRING){
    if(!strncmp(&file[tok[nt].start], attr, strlen(attr))){
      nt += 1;
      attrLen = tok[nt].end - tok[nt].start;
      if(attrLen < 256){
        strncpy(val, &file[tok[nt].start], attrLen);
        printSetting(attr, val);
        return 1;
      }else{
        snprintf(log, 5000, "attribute %s too big", attr);
        lielas_log((unsigned char*)log, 1);
        return -1;
      }
    }
  }
  return 0;
}

canonical_original_code:
int parseAttribute(char *file, char *attr, char *val, int nt, struct jsmntok_t *tok){
  int attrLen;
  char log[5000];
  if( tok[nt].type == JSMN_STRING){
    if(!strncmp(&file[tok[nt].start], attr, strlen(attr))){
      nt += 1;
      attrLen = tok[nt].end - tok[nt].start;
      if(attrLen < 256){
        strncpy(val, &file[tok[nt].start], attrLen);
        printSetting(attr, val);
        return 1;
      }else{
        snprintf(log, 5000, "attribute %s too big", attr);
        lielas_log((unsigned char *)log, 1);
        return -1;
      }
    }
  }
  return 0;
}

variable_types:
file
char *

variable_types:
attr
char *

variable_types:
val
char *

variable_types: nt int

variable_types: struct jsmntok_t { enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 } type; int start; int end; int size; } *

variable_types: attrLen int

variable_types:
log
char [5000]

user_defined_types: struct jsmntok_t { enum jsmntype_t type; int start; int end; int size; }


decompiled_code:
char *set_getSqlUser()
{
return sqlUser;
}

canonical_decompiled_code:
char *func2()
{
return sqlUser;
}

original_code:
const char *set_getSqlUser(){
 return sqlUser;
}

return_type: char *


decompiled_code:
char *set_getSqlPass()
{
return sqlPass;
}

canonical_decompiled_code:
char *func3()
{
return sqlPass;
}

original_code:
const char *set_getSqlPass(){
 return sqlPass;
}


decompiled_code:
char *set_getSqlDb()
{
return sqlDb;
}

canonical_decompiled_code:
char *func4()
{
return sqlDb;
}

original_code:
const char *set_getSqlDb(){
 return sqlDb;
}

canonical_original_code:
char *set_getSqlDb(){
 return sqlDb;
}


decompiled_code:
char *set_getSqlHost()
{
return sqlHost;
}

canonical_decompiled_code:
char *func5()
{
return sqlHost;
}

original_code:
const char *set_getSqlHost(){
 return sqlHost;
}


decompiled_code:
char *set_getSqlPort()
{
return sqlPort;
}

canonical_decompiled_code:
char *func6()
{
return sqlPort;
}

original_code:
const char *set_getSqlPort(){
 return sqlPort;
}


decompiled_code:
char *set_getCoapAddr()
{
return coapAddr;
}

canonical_decompiled_code:
char *func7()
{
return coapAddr;
}

original_code:
const char *set_getCoapAddr(){
 return coapAddr;
}


decompiled_code:
char *set_getCoapPort()
{
return coapPort;
}

canonical_decompiled_code:
char *func8()
{
return coapPort;
}

original_code:
const char *set_getCoapPort(){
 return coapPort;
}


decompiled_code:
char *set_getGatewaynodeAddr()
{
return gatewaynodeAddr;
}

canonical_decompiled_code:
char *func9()
{
return gatewaynodeAddr;
}

original_code:
const char *set_getGatewaynodeAddr(){
 return gatewaynodeAddr;
}


decompiled_code:
char *set_getGatewaynodePort()
{
return gatewaynodePort;
}

canonical_decompiled_code:
char *func10()
{
return gatewaynodePort;
}

original_code:
const char *set_getGatewaynodePort(){
 return gatewaynodePort;
}


decompiled_code:
__int64 set_getStdRegModePanid()
{
return (unsigned int)regmodePanid;
}

canonical_decompiled_code:
__int64 func11()
{
return (unsigned int)regmodePanid;
}

original_code:
int set_getStdRegModePanid(){
  return regmodePanid;
}


decompiled_code:
__int64 set_getStdNormalModePanid()
{
return (unsigned int)normalmodePanid;
}

canonical_decompiled_code:
__int64 func12()
{
return (unsigned int)normalmodePanid;
}

original_code:
int set_getStdNormalModePanid(){
  return normalmodePanid;
}


decompiled_code:
__int64 set_getRegModeLen()
{
return (unsigned int)regmodeLen;
}

canonical_decompiled_code:
__int64 func13()
{
return (unsigned int)regmodeLen;
}

original_code:
int set_getRegModeLen(){
  return regmodeLen;
}


decompiled_code:
__int64 set_getMaxRegModeLen()
{
return (unsigned int)regmodeMaxLen;
}

canonical_decompiled_code:
__int64 func14()
{
return (unsigned int)regmodeMaxLen;
}

original_code:
int set_getMaxRegModeLen(){
  return regmodeMaxLen;
}


printSetting

decompiled_code:
void printSetting()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

original_code:
void printSetting(char *s, char *v){
}

canonical_original_code:
void printSetting(char *s, char *v){
}

variable_types:
s
char *

variable_types:
v
char *

return_type: void


SQLclose

decompiled_code:
void SQLclose(void)
{
if ( con )
{
if ( !(unsigned int)PQstatus() )
PQfinish(con);
}
}

canonical_decompiled_code:
void func0(void)
{
if ( con )
{
if ( !(unsigned int)PQstatus() )
PQfinish(con);
}
}

original_code:
void SQLclose(){
   if(con != ((void *)0) && PQstatus(con) == CONNECTION_OK){
     PQfinish(con);
   }
}


SQLconnect

decompiled_code:
__int64 __fastcall SQLconnect(__int64 a1, __int64 a2)
{
const char *v2; // rbx
size_t v3; // rax
const char *v4; // rbx
size_t v5; // rax
const char *v6; // rbx
size_t v7; // rax
const char *v8; // rbx
size_t v9; // rax
const char *v10; // rbx
size_t v11; // rax
char dest[8]; // [rsp+0h] [rbp-208h] BYREF
__int64 v14; // [rsp+8h] [rbp-200h]
char v15[480]; // [rsp+10h] [rbp-1F8h] BYREF
int v16[6]; // [rsp+1F0h] [rbp-18h] BYREF

*(_WORD *)&dest[6] = 0;
v14 = 0LL;
memset(v15, 0, sizeof(v15));
v16[0] = 0;
strcpy(dest, "user=");
v2 = (const char *)set_getSqlUser(v16, a2);
v3 = strlen(dest);
strcpy(&dest[v3], v2);
strcat(dest, " password=");
v4 = (const char *)set_getSqlPass();
v5 = strlen(dest);
strcpy(&dest[v5], v4);
strcat(dest, " dbname=");
v6 = (const char *)set_getSqlDb();
v7 = strlen(dest);
strcpy(&dest[v7], v6);
strcat(dest, " host=");
v8 = (const char *)set_getSqlHost();
v9 = strlen(dest);
strcpy(&dest[v9], v8);
strcat(dest, " port=");
v10 = (const char *)set_getSqlPort();
v11 = strlen(dest);
strcpy(&dest[v11], v10);
con = PQconnectdb(dest);
if ( (unsigned int)PQstatus(con) )
{
lielas_log("Couldn't connect do database using:", 0LL);
lielas_log(dest, 0LL);
exit(1);
}
atexit(SQLclose);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
const char *v2; // rbx
size_t v3; // rax
const char *v4; // rbx
size_t v5; // rax
const char *v6; // rbx
size_t v7; // rax
const char *v8; // rbx
size_t v9; // rax
const char *v10; // rbx
size_t v11; // rax
char dest[8]; // [rsp+0h] [rbp-208h] BYREF
__int64 v14; // [rsp+8h] [rbp-200h]
char v15[480]; // [rsp+10h] [rbp-1F8h] BYREF
int v16[6]; // [rsp+1F0h] [rbp-18h] BYREF

*(_WORD *)&dest[6] = 0;
v14 = 0LL;
memset(v15, 0, sizeof(v15));
v16[0] = 0;
strcpy(dest, "user=");
v2 = (const char *)set_getSqlUser(v16, a2);
v3 = strlen(dest);
strcpy(&dest[v3], v2);
strcat(dest, " password=");
v4 = (const char *)set_getSqlPass();
v5 = strlen(dest);
strcpy(&dest[v5], v4);
strcat(dest, " dbname=");
v6 = (const char *)set_getSqlDb();
v7 = strlen(dest);
strcpy(&dest[v7], v6);
strcat(dest, " host=");
v8 = (const char *)set_getSqlHost();
v9 = strlen(dest);
strcpy(&dest[v9], v8);
strcat(dest, " port=");
v10 = (const char *)set_getSqlPort();
v11 = strlen(dest);
strcpy(&dest[v11], v10);
con = PQconnectdb(dest);
if ( (unsigned int)PQstatus(con) )
{
lielas_log("Couldn't connect do database using:", 0LL);
lielas_log(dest, 0LL);
exit(1);
}
atexit(SQLclose);
return 0LL;
}

original_code:
int SQLconnect(){
 char conSt[500] = { 0 };
 strcpy(conSt, "user=");
 strcpy(&conSt[strlen(conSt)], set_getSqlUser());
 strcpy(&conSt[strlen(conSt)], " password=");
 strcpy(&conSt[strlen(conSt)], set_getSqlPass());
 strcpy(&conSt[strlen(conSt)], " dbname=");
 strcpy(&conSt[strlen(conSt)], set_getSqlDb());
 strcpy(&conSt[strlen(conSt)], " host=");
 strcpy(&conSt[strlen(conSt)], set_getSqlHost());
 strcpy(&conSt[strlen(conSt)], " port=");
 strcpy(&conSt[strlen(conSt)], set_getSqlPort());
 con = PQconnectdb(conSt);
  if(PQstatus(con) != CONNECTION_OK){
  lielas_log((unsigned char*)"Couldn't connect do database using:", 0);
  lielas_log((unsigned char*)conSt, 0);
     exit(1);
  }
 atexit(SQLclose);
 return 0;
}

canonical_original_code:
int SQLconnect(){
 char conSt[500] = { 0 };
 strcpy(conSt, "user=");
 strcpy(&conSt[strlen(conSt)], set_getSqlUser());
 strcpy(&conSt[strlen(conSt)], " password=");
 strcpy(&conSt[strlen(conSt)], set_getSqlPass());
 strcpy(&conSt[strlen(conSt)], " dbname=");
 strcpy(&conSt[strlen(conSt)], set_getSqlDb());
 strcpy(&conSt[strlen(conSt)], " host=");
 strcpy(&conSt[strlen(conSt)], set_getSqlHost());
 strcpy(&conSt[strlen(conSt)], " port=");
 strcpy(&conSt[strlen(conSt)], set_getSqlPort());
 con = PQconnectdb(conSt);
  if(PQstatus(con) != CONNECTION_OK){
  lielas_log((unsigned char *)"Couldn't connect do database using:", 0);
  lielas_log((unsigned char *)conSt, 0);
     exit(1);
  }
 atexit(SQLclose);
 return 0;
}

variable_types:
conSt
char [500]


InitDeviceEvents

decompiled_code:
void InitDeviceEvents()
{
eventlist = 0LL;
}

canonical_decompiled_code:
void func0()
{
eventlist = 0LL;
}

original_code:
void InitDeviceEvents(){
 eventlist = ((void *)0);
}


LremoveEvent

original_code:
void LremoveEvent(Levent* event){
 event->lastDeviceEvent->nextDeviceEvent = event->nextDeviceEvent;
 event->nextDeviceEvent->lastDeviceEvent = event->lastDeviceEvent;
 free(event);
}

canonical_original_code:
void LremoveEvent(struct deviceevent_struct *event){
 event->lastDeviceEvent->nextDeviceEvent = event->nextDeviceEvent;
 event->nextDeviceEvent->lastDeviceEvent = event->lastDeviceEvent;
 free(event);
}

variable_types: struct deviceevent_struct { struct Ldevice_struct { unsigned int id; int registered; char address[50]; char mac[50]; char mint[50]; char pint[50]; char aint[50]; char name[64]; char sw_ver[64]; char supply[64]; int moduls; struct Lmodul_struct { unsigned int id; char address[50]; int channels; char mint[50]; char pint[50]; char aint[50]; struct Lchannel_struct { unsigned int id; char address[50]; char type[50]; char sensor[50]; char unit[50]; char class[50]; double exponent; } *channel[20]; } *modul[20]; struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } lastProcessed; int hasLogger; int event; struct lwp_wkc_struct { struct lwp_resource_struct { char name[100]; int attributes; struct lwp_attr_struct { char name[100]; } attr[10]; } info; struct lwp_resource_struct device; struct lwp_resource_struct modul; struct lwp_resource_struct network; struct lwp_resource_struct database; struct lwp_resource_struct logger; struct lwp_resource_struct channel[20]; int channels; } wkc; } *d; int type; struct deviceevent_struct *nextDeviceEvent; struct deviceevent_struct *lastDeviceEvent; } *

user_defined_types: struct deviceevent_struct { struct Ldevice_struct *d; int type; struct deviceevent_struct *nextDeviceEvent; struct deviceevent_struct *lastDeviceEvent; }

user_defined_types: struct Ldevice_struct { unsigned int id; int registered; char address[50]; char mac[50]; char mint[50]; char pint[50]; char aint[50]; char name[64]; char sw_ver[64]; char supply[64]; int moduls; struct Lmodul_struct *modul[20]; struct tm lastProcessed; int hasLogger; int event; struct lwp_wkc_struct wkc; }

user_defined_types: struct lwp_wkc_struct { struct lwp_resource_struct info; struct lwp_resource_struct device; struct lwp_resource_struct modul; struct lwp_resource_struct network; struct lwp_resource_struct database; struct lwp_resource_struct logger; struct lwp_resource_struct channel[20]; int channels; }

user_defined_types: struct lwp_resource_struct { char name[100]; int attributes; struct lwp_attr_struct attr[10]; }

user_defined_types: struct Lmodul_struct { unsigned int id; char address[50]; int channels; char mint[50]; char pint[50]; char aint[50]; struct Lchannel_struct *channel[20]; }


decompiled_code:
__int64 lielas_createTables()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
int v6; // ebx
int v7; // ebx
int v8; // ebx

v0 = -(int)lielas_createLbusTbl();
v1 = v0 - lielas_createUsersTbl();
v2 = v1 - lielas_createDeviceGroupsTbl();
v3 = v2 - lielas_createUserGroupsTbl();
v4 = v3 - lielas_createDevicesTbl();
v5 = v4 - lielas_createModulsTbl();
v6 = v5 - lielas_createChannelsTbl();
v7 = v6 - lielas_createDataTbl();
v8 = v7 - lielas_createSettingsTbl();
return v8 - (unsigned int)lielas_createEventsTbl();
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
int v6; // ebx
int v7; // ebx
int v8; // ebx

v0 = -(int)func1();
v1 = v0 - func2();
v2 = v1 - func3();
v3 = v2 - func4();
v4 = v3 - func5();
v5 = v4 - func6();
v6 = v5 - func7();
v7 = v6 - func8();
v8 = v7 - func9();
return v8 - (unsigned int)func10();
}

original_code:
int lielas_createTables(){
  int error = 0;
  error -= lielas_createLbusTbl();
  error -= lielas_createUsersTbl();
  error -= lielas_createDeviceGroupsTbl();
  error -= lielas_createUserGroupsTbl();
  error -= lielas_createDevicesTbl();
  error -= lielas_createModulsTbl();
  error -= lielas_createChannelsTbl();
  error -= lielas_createDataTbl();
  error -= lielas_createSettingsTbl();
  error -= lielas_createEventsTbl();
  return error;
}

variable_types: error int


decompiled_code:
__int64 __fastcall set_cloexec_or_close(int fd)
{
unsigned int v1; // ebx
int v2; // eax

v1 = fd;
if ( fd != -1 )
{
v2 = fcntl(fd, 1);
if ( v2 == -1 || fcntl(fd, 2, v2 | 1) == -1 )
{
close(fd);
v1 = -1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
unsigned int v1; // ebx
int v2; // eax

v1 = fd;
if ( fd != -1 )
{
v2 = fcntl(fd, 1);
if ( v2 == -1 || fcntl(fd, 2, v2 | 1) == -1 )
{
close(fd);
v1 = -1;
}
}
return v1;
}

original_code:
static int
set_cloexec_or_close(int fd)
{
 long flags;
 if (fd == -1)
  return -1;
 flags = fcntl(fd, 1);
 if (flags == -1)
  goto err;
 if (fcntl(fd, 2, flags | 1) == -1)
  goto err;
 return fd;
err:
 close(fd);
 return -1;
}

variable_types: fd int

variable_types: flags long


decompiled_code:
__int64 __fastcall create_tmpfile_cloexec(char *name)
{
int v1; // eax
unsigned int v2; // ebx

v1 = mkstemp(name);
v2 = v1;
if ( v1 >= 0 )
{
v2 = set_cloexec_or_close(v1);
unlink(name);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *name)
{
int v1; // eax
unsigned int v2; // ebx

v1 = mkstemp(name);
v2 = v1;
if ( v1 >= 0 )
{
v2 = func0(v1);
unlink(name);
}
return v2;
}

original_code:
static int
create_tmpfile_cloexec(char *tmpname)
{
 int fd;
 fd = mkstemp(tmpname);
 if (fd >= 0) {
  fd = set_cloexec_or_close(fd);
  unlink(tmpname);
 }
 return fd;
}

variable_types:
tmpname
char *


decompiled_code:
__int64 __fastcall os_socketpair_cloexec(int domain, int type, int protocol, int fds[2])
{
int v6; // ebx
int v8; // eax
int v9; // edi

v6 = socketpair(domain, type | 0x80000, protocol, fds);
if ( v6 )
{
if ( *_errno_location() == 22 )
{
v6 = socketpair(domain, type, protocol, fds);
if ( v6 >= 0 )
{
*fds = set_cloexec_or_close(*fds);
v8 = set_cloexec_or_close(fds[1]);
fds[1] = v8;
v9 = *fds;
if ( v8 == -1 || v9 == -1 )
{
close(v9);
close(fds[1]);
v6 = -1;
}
else
{
v6 = 0;
}
}
}
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(int domain, int type, int protocol, int fds[2])
{
int v6; // ebx
int v8; // eax
int v9; // edi

v6 = socketpair(domain, type | 0x80000, protocol, fds);
if ( v6 )
{
if ( *_errno_location() == 22 )
{
v6 = socketpair(domain, type, protocol, fds);
if ( v6 >= 0 )
{
*fds = func0(*fds);
v8 = func0(fds[1]);
fds[1] = v8;
v9 = *fds;
if ( v8 == -1 || v9 == -1 )
{
close(v9);
close(fds[1]);
v6 = -1;
}
else
{
v6 = 0;
}
}
}
}
return (unsigned int)v6;
}

original_code:
int
os_socketpair_cloexec(int domain, int type, int protocol, int *sv)
{
 int ret;
 ret = socketpair(domain, type | SOCK_CLOEXEC, protocol, sv);
 if (ret == 0 || (*__errno_location ()) != 22)
  return ret;
 ret = socketpair(domain, type, protocol, sv);
 if (ret < 0)
  return ret;
 sv[0] = set_cloexec_or_close(sv[0]);
 sv[1] = set_cloexec_or_close(sv[1]);
 if (sv[0] != -1 && sv[1] != -1)
  return 0;
 close(sv[0]);
 close(sv[1]);
 return -1;
}

variable_types: domain int

variable_types: type int

variable_types: protocol int

variable_types:
sv
int *

variable_types: ret int


decompiled_code:
int os_epoll_create_cloexec()
{
int result; // eax
int v1; // eax

result = epoll_create1(0x80000);
if ( result < 0 )
{
if ( *_errno_location() == 22 )
{
v1 = epoll_create(1);
result = set_cloexec_or_close(v1);
}
else
{
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
int v1; // eax

result = epoll_create1(0x80000);
if ( result < 0 )
{
if ( *_errno_location() == 22 )
{
v1 = epoll_create(1);
result = func0(v1);
}
else
{
result = -1;
}
}
return result;
}

original_code:
int
os_epoll_create_cloexec(void)
{
 int fd;
 fd = epoll_create1(EPOLL_CLOEXEC);
 if (fd >= 0)
  return fd;
 if ((*__errno_location ()) != 22)
  return -1;
 fd = epoll_create(1);
 return set_cloexec_or_close(fd);
}

canonical_original_code:
int os_epoll_create_cloexec()
{
 int fd;
 fd = epoll_create1(EPOLL_CLOEXEC);
 if (fd >= 0)
  return fd;
 if ((*__errno_location ()) != 22)
  return -1;
 fd = epoll_create(1);
 return set_cloexec_or_close(fd);
}


decompiled_code:
__int64 __fastcall os_create_anonymous_file(__off_t length)
{
char *v1; // rax
const char *v2; // rbp
size_t v3; // rax
char *v4; // rax
char *v5; // rbx
size_t v6; // rax
int v7; // ebp

v1 = getenv("XDG_RUNTIME_DIR");
if ( v1 )
{
v2 = v1;
v3 = strlen(v1);
v4 = (char *)malloc(v3 + 22);
v5 = v4;
if ( v4 )
{
strcpy(v4, v2);
v6 = strlen(v5);
*(__m128i *)&v5[v6] = _mm_load_si128((const __m128i *)&template_0);
strcpy(&v5[v6 + 16], "XXXXX");
v7 = create_tmpfile_cloexec(v5);
free(v5);
if ( v7 < 0 )
{
v7 = -1;
}
else if ( ftruncate(v7, length) < 0 )
{
close(v7);
v7 = -1;
}
}
else
{
v7 = -1;
}
}
else
{
*_errno_location() = 2;
v7 = -1;
}
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(__off_t length)
{
char *v1; // rax
const char *v2; // rbp
size_t v3; // rax
char *v4; // rax
char *v5; // rbx
size_t v6; // rax
int v7; // ebp

v1 = getenv("XDG_RUNTIME_DIR");
if ( v1 )
{
v2 = v1;
v3 = strlen(v1);
v4 = (char *)malloc(v3 + 22);
v5 = v4;
if ( v4 )
{
strcpy(v4, v2);
v6 = strlen(v5);
*(__m128i *)&v5[v6] = _mm_load_si128((const __m128i *)&template_0);
strcpy(&v5[v6 + 16], "XXXXX");
v7 = func1(v5);
free(v5);
if ( v7 < 0 )
{
v7 = -1;
}
else if ( ftruncate(v7, length) < 0 )
{
close(v7);
v7 = -1;
}
}
else
{
v7 = -1;
}
}
else
{
*_errno_location() = 2;
v7 = -1;
}
return (unsigned int)v7;
}

original_code:
int
os_create_anonymous_file(off_t size)
{
 static const char template[] = "/weston-shared-XXXXXX";
 const char *path;
 char *name;
 int fd;
 path = getenv("XDG_RUNTIME_DIR");
 if (!path) {
  (*__errno_location ()) = 2;
  return -1;
 }
 name = malloc(strlen(path) + sizeof(template));
 if (!name)
  return -1;
 strcpy(name, path);
 strcat(name, template);
 fd = create_tmpfile_cloexec(name);
 free(name);
 if (fd < 0)
  return -1;
 if (ftruncate(fd, size) < 0) {
  close(fd);
  return -1;
 }
 return fd;
}

canonical_original_code:
int os_create_anonymous_file(long size)
{
 static char template[] = "/weston-shared-XXXXXX";
 char *path;
 char *name;
 int fd;
 path = getenv("XDG_RUNTIME_DIR");
 if (!path) {
  (*__errno_location ()) = 2;
  return -1;
 }
 name = malloc(strlen(path) + sizeof(template));
 if (!name)
  return -1;
 strcpy(name, path);
 strcat(name, template);
 fd = create_tmpfile_cloexec(name);
 free(name);
 if (fd < 0)
  return -1;
 if (ftruncate(fd, size) < 0) {
  close(fd);
  return -1;
 }
 return fd;
}

variable_types: size long

variable_types:
template
char []

variable_types:
path
char *

variable_types:
name
char *


child

repo: antonblanchard/will-it-scale

decompiled_code:
void __fastcall __noreturn child(int *a1)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

while ( 1 )
{
while ( (unsigned int)read(*a1, buf, 1uLL) != 1 )
{
if ( *_errno_location() != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x1Cu, "child");
}
while ( (unsigned int)write(a1[3], buf, 1uLL) != 1 )
{
if ( *_errno_location() != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x21u, "child");
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int *a1)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

while ( 1 )
{
while ( (unsigned int)read(*a1, buf, 1uLL) != 1 )
{
if ( *_errno_location() != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x1Cu, "child");
}
while ( (unsigned int)write(a1[3], buf, 1uLL) != 1 )
{
if ( *_errno_location() != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x21u, "child");
}
}
}

original_code:
static void *child(void *arg)
{
 struct args *a = arg;
 char c;
 int ret;
 while (1) {
  do {
   ret = read(a->fd1[0], &c, 1);
  } while (ret != 1 && (*__errno_location ()) == 4);
  ((void) sizeof ((ret == 1) ? 1 : 0), __extension__ ({ if (ret == 1) ; else __assert_fail ("ret == 1", "tests/context_switch1.c", 28, __extension__ __PRETTY_FUNCTION__); }));
  do {
   ret = write(a->fd2[1], &c, 1);
  } while (ret != 1 && (*__errno_location ()) == 4);
  ((void) sizeof ((ret == 1) ? 1 : 0), __extension__ ({ if (ret == 1) ; else __assert_fail ("ret == 1", "tests/context_switch1.c", 33, __extension__ __PRETTY_FUNCTION__); }));
 }
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct args { int fd1[2]; int fd2[2]; } *

variable_types: c char

return_type: void *


testcase

decompiled_code:
void __fastcall __noreturn testcase(_QWORD *a1)
{
int *v1; // rbx
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = (int *)malloc(0x10uLL);
if ( pipe(v1) )
_assert_fail("pipe(a->fd1) == 0", "tests/context_switch1.c", 0x2Du, "testcase");
if ( pipe(v1 + 2) )
_assert_fail("pipe(a->fd2) == 0", "tests/context_switch1.c", 0x2Eu, "testcase");
new_task(child, v1);
while ( 1 )
{
while ( (unsigned int)write(v1[1], buf, 1uLL) != 1 )
{
if ( *_errno_location() != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x36u, "testcase");
}
while ( (unsigned int)read(v1[2], buf, 1uLL) != 1 )
{
if ( *_errno_location() != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x3Bu, "testcase");
}
*a1 += 2LL;
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(_QWORD *a1)
{
int *v1; // rbx
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = (int *)malloc(0x10uLL);
if ( pipe(v1) )
_assert_fail("pipe(a->fd1) == 0", "tests/context_switch1.c", 0x2Du, "testcase");
if ( pipe(v1 + 2) )
_assert_fail("pipe(a->fd2) == 0", "tests/context_switch1.c", 0x2Eu, "testcase");
new_task(child, v1);
while ( 1 )
{
while ( (unsigned int)write(v1[1], buf, 1uLL) != 1 )
{
if ( *_errno_location() != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x36u, "testcase");
}
while ( (unsigned int)read(v1[2], buf, 1uLL) != 1 )
{
if ( *_errno_location() != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x3Bu, "testcase");
}
*a1 += 2LL;
}
}

original_code:
void testcase(unsigned long long *iterations, unsigned long nr)
{
 struct args *a;
 char c;
 int ret;
 a = malloc(sizeof(struct args));
 ((void) sizeof ((pipe(a->fd1) == 0) ? 1 : 0), __extension__ ({ if (pipe(a->fd1) == 0) ; else __assert_fail ("pipe(a->fd1) == 0", "tests/context_switch1.c", 45, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((pipe(a->fd2) == 0) ? 1 : 0), __extension__ ({ if (pipe(a->fd2) == 0) ; else __assert_fail ("pipe(a->fd2) == 0", "tests/context_switch1.c", 46, __extension__ __PRETTY_FUNCTION__); }));
 new_task(child, a);
 while (1) {
  do {
   ret = write(a->fd1[1], &c, 1);
  } while (ret != 1 && (*__errno_location ()) == 4);
  ((void) sizeof ((ret == 1) ? 1 : 0), __extension__ ({ if (ret == 1) ; else __assert_fail ("ret == 1", "tests/context_switch1.c", 54, __extension__ __PRETTY_FUNCTION__); }));
  do {
   ret = read(a->fd2[0], &c, 1);
  } while (ret != 1 && (*__errno_location ()) == 4);
  ((void) sizeof ((ret == 1) ? 1 : 0), __extension__ ({ if (ret == 1) ; else __assert_fail ("ret == 1", "tests/context_switch1.c", 59, __extension__ __PRETTY_FUNCTION__); }));
  (*iterations) += 2;
 }
 free(a);
}

variable_types:
iterations
unsigned long long *

variable_types:
nr
unsigned long


handler

decompiled_code:
void handler()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void handler(int junk)
{
}

canonical_original_code:
void handler(int junk)
{
}

variable_types: junk int


testcase

decompiled_code:
void __fastcall __noreturn testcase(_QWORD *a1)
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_handler = (__sighandler_t)handler;
sigaction(10, &v1, 0LL);
while ( 1 )
{
raise(10);
++*a1;
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(_QWORD *a1)
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_handler = (__sighandler_t)handler;
sigaction(10, &v1, 0LL);
while ( 1 )
{
raise(10);
++*a1;
}
}

original_code:
void testcase(unsigned long long *iterations, unsigned long nr)
{
 struct sigaction act;
 memset(&act, 0, sizeof(act));
 act.__sigaction_handler.sa_handler = handler;
 sigaction(10, &act, ((void *)0));
 while (1) {
  raise(10);
  (*iterations)++;
 }
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


repo: antoniofabio/idmclib

original_code:
static int check_points(double *a, double *b, int dim, double eps) {
 int i;
 double dst = 0.0;
 for(i=0; i<dim; i++)
  dst += (a[i] - b[i])*(a[i] - b[i]);
 return ( dst < eps );
}

variable_types:
a
double *

variable_types:
b
double *

variable_types: dim int

variable_types: eps double

variable_types: i int

variable_types: dst double


decompiled_code:
void __fastcall idmc_attractor_point_free(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void idmc_attractor_point_free(idmc_attractor_point* p) {
 idmc_attractor_point *n;
 while(p) {
  n = p->next;
  free(p->x);
  free(p);
  p = n;
 }
}

canonical_original_code:
void idmc_attractor_point_free(struct attractor_pt *p) {
 struct attractor_pt *n;
 while(p) {
  n = p->next;
  free(p->x);
  free(p);
  p = n;
 }
}

variable_types: struct attractor_pt { double *x; struct attractor_pt *next; } *


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

result = a2;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

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

result = a2;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

original_code:
idmc_attractor_point* idmc_attractor_point_add(idmc_attractor_point* last,
 idmc_attractor_point* p) {
 last->next = p;
 return p;
}

canonical_original_code:
struct attractor_pt *idmc_attractor_point_add(struct attractor_pt *last, struct attractor_pt *p) {
 last->next = p;
 return p;
}

variable_types:
last
struct attractor_pt *

variable_types:
p
struct attractor_pt *

return_type: struct attractor_pt { double *x; struct attractor_pt *next; } *


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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
idmc_attractor_point* idmc_attractor_point_last(idmc_attractor_point* head) {
 while(head->next)
  head = head->next;
 return head;
}

canonical_original_code:
struct attractor_pt *idmc_attractor_point_last(struct attractor_pt *head) {
 while(head->next)
  head = head->next;
 return head;
}

variable_types:
head
struct attractor_pt *

user_defined_types: struct attractor_pt { double *x; struct attractor_pt *next; }


decompiled_code:
void __fastcall idmc_attractor_free(void *ptr)
{
idmc_attractor_point_free(*(void **)ptr);
free(ptr);
}

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

original_code:
void idmc_attractor_free(idmc_attractor* p) {
 idmc_attractor_point_free(p->hd);
 free(p);
}

canonical_original_code:
void idmc_attractor_free(struct attr_lst *p) {
 idmc_attractor_point_free(p->hd);
 free(p);
}

variable_types: struct attr_lst { struct attractor_pt { double *x; struct attractor_pt *next; } *hd; int dim; struct attr_lst *next; struct attr_lst *previous; } *

user_defined_types: struct attr_lst { struct attractor_pt *hd; int dim; struct attr_lst *next; struct attr_lst *previous; }


decompiled_code:
__int64 __fastcall idmc_attractor_length(__int64 *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

original_code:
int idmc_attractor_length(idmc_attractor* p) {
 int i=0;
 idmc_attractor_point* hd = p->hd;
 while(hd) {
  i++;
  hd = hd->next;
 }
 return i;
}

canonical_original_code:
int idmc_attractor_length(struct attr_lst *p) {
 int i = 0;
 struct attractor_pt *hd = p->hd;
 while(hd) {
  i++;
  hd = hd->next;
 }
 return i;
}


decompiled_code:
_BOOL8 __fastcall idmc_attractor_check_point(__int64 a1, __int64 a2, double a3)
{
__int64 *v3; // rbx
int v4; // er13
_BOOL8 result; // rax

v3 = *(__int64 **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
v4 = *(_DWORD *)(a1 + 8);
while ( 1 )
{
result = check_points(*v3, a2, v4, a3);
if ( result )
break;
v3 = (__int64 *)v3[1];
if ( !v3 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, __int64 a2, double a3)
{
__int64 *v3; // rbx
int v4; // er13
_BOOL8 result; // rax

v3 = *(__int64 **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
v4 = *(_DWORD *)(a1 + 8);
while ( 1 )
{
result = func0(*v3, a2, v4, a3);
if ( result )
break;
v3 = (__int64 *)v3[1];
if ( !v3 )
return result;
}
return 1LL;
}

original_code:
int idmc_attractor_check_point(idmc_attractor* p, double* x, double eps) {
 idmc_attractor_point *ap = p->hd;
 while(ap) {
  if(check_points(ap->x, x, p->dim, eps))
   return 1;
  ap = ap->next;
 }
 return 0;
}

canonical_original_code:
int idmc_attractor_check_point(struct attr_lst *p, double *x, double eps) {
 struct attractor_pt *ap = p->hd;
 while(ap) {
  if(check_points(ap->x, x, p->dim, eps))
   return 1;
  ap = ap->next;
 }
 return 0;
}

variable_types:
x
double *


decompiled_code:
__int64 __fastcall idmc_attractor_list_free(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rdi
__int64 result; // rax

for ( i = a1; i; result = idmc_attractor_free(v2) )
{
v2 = i;
i = *(_QWORD *)(i + 16);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rdi
__int64 result; // rax

for ( i = a1; i; result = idmc_attractor_free(v2) )
{
v2 = i;
i = *(_QWORD *)(i + 16);
}
return result;
}

original_code:
void idmc_attractor_list_free(idmc_attractor* head) {
 idmc_attractor *n;
 while(head) {
  n = head->next;
  idmc_attractor_free(head);
  head = n;
 }
}

canonical_original_code:
void idmc_attractor_list_free(struct attr_lst *head) {
 struct attr_lst *n;
 while(head) {
  n = head->next;
  idmc_attractor_free(head);
  head = n;
 }
}


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

result = a2;
*(_QWORD *)(a2 + 24) = a1;
*(_QWORD *)(a1 + 16) = a2;
return result;
}

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

result = a2;
*(_QWORD *)(a2 + 24) = a1;
*(_QWORD *)(a1 + 16) = a2;
return result;
}

original_code:
idmc_attractor* idmc_attractor_list_add(idmc_attractor* last, idmc_attractor* i) {
 i->previous = last;
 last->next = i;
 return i;
}

canonical_original_code:
struct attr_lst *idmc_attractor_list_add(struct attr_lst *last, struct attr_lst *i) {
 i->previous = last;
 last->next = i;
 return i;
}

variable_types:
last
struct attr_lst *

variable_types:
i
struct attr_lst *

return_type: struct attr_lst { struct attractor_pt { double *x; struct attractor_pt *next; } *hd; int dim; struct attr_lst *next; struct attr_lst *previous; } *


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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

original_code:
int idmc_attractor_list_length(idmc_attractor* head) {
 int i=0;
 while(head) {
  i++;
  head = head->next;
 }
 return i;
}

canonical_original_code:
int idmc_attractor_list_length(struct attr_lst *head) {
 int i = 0;
 while(head) {
  i++;
  head = head->next;
 }
 return i;
}


decompiled_code:
__int64 __fastcall idmc_attractor_list_get(__int64 a1, int a2)
{
int i; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
a1 = *(_QWORD *)(a1 + 16);
}
return a1;
}

original_code:
idmc_attractor* idmc_attractor_list_get(idmc_attractor* head, int id) {
 int i;
 idmc_attractor* ans = head;
 for(i=0; i<id; i++)
  ans = ans->next;
 return ans;
}

canonical_original_code:
struct attr_lst *idmc_attractor_list_get(struct attr_lst *head, int id) {
 int i;
 struct attr_lst *ans = head;
 for(i=0; i<id; i++)
  ans = ans->next;
 return ans;
}

variable_types:
head
struct attr_lst *

variable_types: id int


decompiled_code:
__int64 __fastcall idmc_attractor_list_check_point(__int64 a1, __int64 a2, double a3)
{
__int64 v3; // rbp
int v4; // eax
unsigned int v5; // er15
unsigned int v6; // ebx
int v8; // er12
__int64 v9; // rax

v3 = a1;
srand(0);
v4 = idmc_attractor_list_length(a1);
v5 = v4;
if ( v4 > 99 )
{
v8 = 100;
while ( 1 )
{
v6 = v5 * (int)((double)rand() * 4.656612873077393e-10);
v9 = idmc_attractor_list_get(a1, v6);
if ( (unsigned int)idmc_attractor_check_point(v9, a2, a3) )
break;
if ( !--v8 )
return v5;
}
}
else if ( a1 )
{
v6 = 0;
while ( !(unsigned int)idmc_attractor_check_point(v3, a2, a3) )
{
v3 = *(_QWORD *)(v3 + 16);
++v6;
if ( !v3 )
return v5;
}
}
else
{
v6 = v4;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, double a3)
{
__int64 v3; // rbp
int v4; // eax
unsigned int v5; // er15
unsigned int v6; // ebx
int v8; // er12
__int64 v9; // rax

v3 = a1;
srand(0);
v4 = func2(a1);
v5 = v4;
if ( v4 > 99 )
{
v8 = 100;
while ( 1 )
{
v6 = v5 * (int)((double)rand() * 4.656612873077393e-10);
v9 = func3(a1, v6);
if ( (unsigned int)idmc_attractor_check_point(v9, a2, a3) )
break;
if ( !--v8 )
return v5;
}
}
else if ( a1 )
{
v6 = 0;
while ( !(unsigned int)idmc_attractor_check_point(v3, a2, a3) )
{
v3 = *(_QWORD *)(v3 + 16);
++v6;
if ( !v3 )
return v5;
}
}
else
{
v6 = v4;
}
return v6;
}

original_code:
int idmc_attractor_list_check_point(idmc_attractor* head, double* x, double eps) {
 int i;
 srand(0);
 int N = idmc_attractor_list_length(head);
 if(N < 100) {
  int i=0;
  while(head) {
   if( idmc_attractor_check_point(head, x, eps) )
    return i;
   head = head->next;
   i++;
  }
  } else {
  for(int j = 100; j; j--) {
   i = (int) ( (double)rand() / ((double)(2147483647)+(double)(1)) ) * N;
   if( idmc_attractor_check_point( idmc_attractor_list_get(head, i), x, eps ) ) {
    return i;
   }
  }
 }
 return N;
}

canonical_original_code:
int idmc_attractor_list_check_point(struct attr_lst *head, double *x, double eps) {
 int i;
 srand(0);
 int N = idmc_attractor_list_length(head);
 if(N < 100) {
  int i = 0;
  while(head) {
   if( idmc_attractor_check_point(head, x, eps) )
    return i;
   head = head->next;
   i++;
  }
  } else {
  for(int j = 100; j; j--) {
   i = (int) ( (double)rand() / ((double)(2147483647)+(double)(1)) ) * N;
   if( idmc_attractor_check_point( idmc_attractor_list_get(head, i), x, eps ) ) {
    return i;
   }
  }
 }
 return N;
}

variable_types: N int

variable_types: j int


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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

original_code:
idmc_attractor* idmc_attractor_list_last(idmc_attractor* head) {
 while(head->next)
  head = head->next;
 return head;
}

canonical_original_code:
struct attr_lst *idmc_attractor_list_last(struct attr_lst *head) {
 while(head->next)
  head = head->next;
 return head;
}


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

result = idmc_attractor_list_last(a1);
*(_QWORD *)(result + 16) = a2;
*(_QWORD *)(a2 + 24) = result;
return result;
}

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

result = func5(a1);
*(_QWORD *)(result + 16) = a2;
*(_QWORD *)(a2 + 24) = result;
return result;
}

original_code:
void idmc_attractor_list_append(idmc_attractor* head, idmc_attractor* i) {
 idmc_attractor* last = idmc_attractor_list_last(head);
 last->next = i;
 i->previous = last;
}

canonical_original_code:
void idmc_attractor_list_append(struct attr_lst *head, struct attr_lst *i) {
 struct attr_lst *last = idmc_attractor_list_last(head);
 last->next = i;
 i->previous = last;
}


original_code:
void idmc_attractor_list_drop(idmc_attractor* p) {
 if(p->previous)
  (p->previous)->next = p->next;
 if(p->next)
  (p->next)->previous = p->previous;
 idmc_attractor_free(p);
}

canonical_original_code:
void idmc_attractor_list_drop(struct attr_lst *p) {
 if(p->previous)
  (p->previous)->next = p->next;
 if(p->next)
  (p->next)->previous = p->previous;
 idmc_attractor_free(p);
}


decompiled_code:
__int64 __fastcall idmc_attractor_list_merge(__int64 a1, int a2, int a3)
{
int v3; // ebp
int v4; // eax
_QWORD *v5; // r12
_QWORD *v6; // rbp
__int64 v7; // r12

v3 = a3;
if ( a2 > a3 )
{
v4 = a2;
a2 = a3;
v3 = v4;
}
v5 = (_QWORD *)idmc_attractor_list_get(a1, a2);
v6 = (_QWORD *)idmc_attractor_list_get(a1, v3);
v7 = idmc_attractor_point_last(*v5);
*(_QWORD *)(v7 + 8) = idmc_attractor_point_clone(*v6, *(unsigned int *)(a1 + 8));
return idmc_attractor_list_drop((__int64)v6);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3)
{
int v3; // ebp
int v4; // eax
_QWORD *v5; // r12
_QWORD *v6; // rbp
__int64 v7; // r12

v3 = a3;
if ( a2 > a3 )
{
v4 = a2;
a2 = a3;
v3 = v4;
}
v5 = (_QWORD *)func3(a1, a2);
v6 = (_QWORD *)func3(a1, v3);
v7 = idmc_attractor_point_last(*v5);
*(_QWORD *)(v7 + 8) = idmc_attractor_point_clone(*v6, *(unsigned int *)(a1 + 8));
return func7((__int64)v6);
}

original_code:
void idmc_attractor_list_merge(idmc_attractor* head, int a, int b) {
 int tmp;
 if(a>b) {
  tmp=a;
  a=b;
  b=tmp;
 }
 idmc_attractor* a1 = idmc_attractor_list_get(head, a);
 idmc_attractor* a2 = idmc_attractor_list_get(head, b);
 idmc_attractor_point* tail1 = idmc_attractor_point_last( a1->hd );
 idmc_attractor_point* head2 = a2->hd;
 tail1->next = idmc_attractor_point_clone(head2, head->dim);
 idmc_attractor_list_drop(a2);
}

canonical_original_code:
void idmc_attractor_list_merge(struct attr_lst *head, int a, int b) {
 int tmp;
 if(a>b) {
  tmp=a;
  a=b;
  b=tmp;
 }
 struct attr_lst *a1 = idmc_attractor_list_get(head, a);
 struct attr_lst *a2 = idmc_attractor_list_get(head, b);
 struct attractor_pt *tail1 = idmc_attractor_point_last( a1->hd );
 struct attractor_pt *head2 = a2->hd;
 tail1->next = idmc_attractor_point_clone(head2, head->dim);
 idmc_attractor_list_drop(a2);
}

variable_types: a int

variable_types: b int

variable_types: tmp int


decompiled_code:
void __fastcall idmc_raster_free(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void idmc_raster_free(idmc_raster* p)
{
 if(p->data!=((void *)0))
  free(p->data);
 free(p);
}

canonical_original_code:
void idmc_raster_free(struct idmc_raster *p)
{
 if(p->data!=((void *)0))
  free(p->data);
 free(p);
}

variable_types: struct idmc_raster { void *g_data; int *data; double xmin; double xrange; double xeps; int xres; double ymin; double yrange; double yeps; int yres; } *


decompiled_code:
__int64 __fastcall idmc_raster_alloc(int a1, int a2, double **a3, double a4, double a5, double a6, double a7)
{
double *v8; // rax
double *v9; // rbx
void *v10; // rax
__int64 result; // rax

v8 = (double *)malloc(0x50uLL);
if ( !v8 )
return 1LL;
v9 = v8;
v10 = malloc(4LL * a2 * a1);
*((_QWORD *)v9 + 1) = v10;
if ( v10 )
{
v9[2] = a4;
v9[3] = a5 - a4;
v9[4] = (a5 - a4) / (double)a1;
*((_DWORD *)v9 + 10) = a1;
v9[6] = a6;
v9[7] = a7 - a6;
v9[8] = (a7 - a6) / (double)a2;
*((_DWORD *)v9 + 18) = a2;
*a3 = v9;
result = 0LL;
}
else
{
idmc_raster_free(v9);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, double **a3, double a4, double a5, double a6, double a7)
{
double *v8; // rax
double *v9; // rbx
void *v10; // rax
__int64 result; // rax

v8 = (double *)malloc(0x50uLL);
if ( !v8 )
return 1LL;
v9 = v8;
v10 = malloc(4LL * a2 * a1);
*((_QWORD *)v9 + 1) = v10;
if ( v10 )
{
v9[2] = a4;
v9[3] = a5 - a4;
v9[4] = (a5 - a4) / (double)a1;
*((_DWORD *)v9 + 10) = a1;
v9[6] = a6;
v9[7] = a7 - a6;
v9[8] = (a7 - a6) / (double)a2;
*((_DWORD *)v9 + 18) = a2;
*a3 = v9;
result = 0LL;
}
else
{
func0(v9);
result = 1LL;
}
return result;
}

original_code:
int idmc_raster_alloc(double xmin, double xmax, int xres,
 double ymin, double ymax, int yres,
 idmc_raster** out_raster)
{
 idmc_raster *ans = (idmc_raster*) malloc( sizeof(idmc_raster) );
 if(ans==((void *)0))
  return 1;
 ans->data = (int*) malloc(xres * yres * sizeof(int));
 if(ans->data==((void *)0)) {
  idmc_raster_free(ans);
  return 1;
 }
 ans->xmin = xmin;
 ans->xrange = xmax - xmin;
 ans->xeps = ans->xrange / (double) xres;
 ans->xres = xres;
 ans->ymin = ymin;
 ans->yrange = ymax - ymin;
 ans->yeps = ans->yrange / (double) yres;
 ans->yres = yres;
 *out_raster = ans;
 return 0;
}

canonical_original_code:
int idmc_raster_alloc(double xmin, double xmax, int xres, double ymin, double ymax, int yres, struct idmc_raster **out_raster)
{
 struct idmc_raster *ans = (idmc_raster*) malloc( sizeof(idmc_raster) );
 if(ans==((void *)0))
  return 1;
 ans->data = (int *) malloc(xres * yres * sizeof(int));
 if(ans->data==((void *)0)) {
  idmc_raster_free(ans);
  return 1;
 }
 ans->xmin = xmin;
 ans->xrange = xmax - xmin;
 ans->xeps = ans->xrange / (double) xres;
 ans->xres = xres;
 ans->ymin = ymin;
 ans->yrange = ymax - ymin;
 ans->yeps = ans->yrange / (double) yres;
 ans->yres = yres;
 *out_raster = ans;
 return 0;
}

variable_types: xmin double

variable_types: xmax double

variable_types: xres int

variable_types: ymin double

variable_types: ymax double

variable_types: yres int

variable_types: struct idmc_raster { void *g_data; int *data; double xmin; double xrange; double xeps; int xres; double ymin; double yrange; double yeps; int yres; } **


decompiled_code:
__int64 __fastcall idmc_raster_setxy(__int64 a1, int a2, double a3, double a4)
{
__int64 result; // rax

result = (int)((a3 - *(double *)(a1 + 16)) / *(double *)(a1 + 32))
+ *(_DWORD *)(a1 + 40) * (*(_DWORD *)(a1 + 72) + ~(int)((a4 - *(double *)(a1 + 48)) / *(double *)(a1 + 64)));
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4 * result) = a2;
return result;
}

original_code:
void idmc_raster_setxy(idmc_raster* p, double x, double y, int value)
{
 p->data[ ( ((p)->yres - ((int)( ((y) - (p)->ymin)/(p)->yeps )) - 1) * ((p)->xres) + ((int)( ((x) - (p)->xmin)/(p)->xeps )) ) ] = value;
}

canonical_original_code:
void idmc_raster_setxy(struct idmc_raster *p, double x, double y, int value)
{
 p->data[ ( ((p)->yres - ((int)( ((y) - (p)->ymin)/(p)->yeps )) - 1) * ((p)->xres) + ((int)( ((x) - (p)->xmin)/(p)->xeps )) ) ] = value;
}

variable_types: x double

variable_types: y double

variable_types: value int

user_defined_types: struct idmc_raster { void *g_data; int *data; double xmin; double xrange; double xeps; int xres; double ymin; double yrange; double yeps; int yres; }


original_code:
int idmc_raster_getxy(idmc_raster* p, double x, double y)
{
 return p->data[ ( ((p)->yres - ((int)( ((y) - (p)->ymin)/(p)->yeps )) - 1) * ((p)->xres) + ((int)( ((x) - (p)->xmin)/(p)->xeps )) ) ];
}

canonical_original_code:
int idmc_raster_getxy(struct idmc_raster *p, double x, double y)
{
 return p->data[ ( ((p)->yres - ((int)( ((y) - (p)->ymin)/(p)->yeps )) - 1) * ((p)->xres) + ((int)( ((x) - (p)->xmin)/(p)->xeps )) ) ];
}


decompiled_code:
__int64 __fastcall idmc_raster_setXY(__int64 a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(result + 4LL * (a2 + *(_DWORD *)(a1 + 40) * (*(_DWORD *)(a1 + 72) + ~a3))) = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(result + 4LL * (a2 + *(_DWORD *)(a1 + 40) * (*(_DWORD *)(a1 + 72) + ~a3))) = a4;
return result;
}

original_code:
void idmc_raster_setXY(idmc_raster* p, int x, int y, int value)
{
 p->data[ ( ((p)->yres - (y) - 1) * ((p)->xres) + (x) ) ] = value;
}

canonical_original_code:
void idmc_raster_setXY(struct idmc_raster *p, int x, int y, int value)
{
 p->data[ ( ((p)->yres - (y) - 1) * ((p)->xres) + (x) ) ] = value;
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall idmc_raster_getXY(__int64 a1, int a2, int a3)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * (a2 + *(_DWORD *)(a1 + 40) * (*(_DWORD *)(a1 + 72) + ~a3)));
}

original_code:
int idmc_raster_getXY(idmc_raster* p, int x, int y)
{
 return p->data[ ( ((p)->yres - (y) - 1) * ((p)->xres) + (x) ) ];
}

canonical_original_code:
int idmc_raster_getXY(struct idmc_raster *p, int x, int y)
{
 return p->data[ ( ((p)->yres - (y) - 1) * ((p)->xres) + (x) ) ];
}


decompiled_code:
void *__fastcall idmc_raster_set(__int64 a1, int a2)
{
return memset(*(void **)(a1 + 8), a2, 4LL * *(_DWORD *)(a1 + 72) * *(_DWORD *)(a1 + 40));
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, int a2)
{
return memset(*(void **)(a1 + 8), a2, 4LL * *(_DWORD *)(a1 + 72) * *(_DWORD *)(a1 + 40));
}

original_code:
void idmc_raster_set(idmc_raster* p, int value)
{
 memset(p->data, value, (p->xres * p->yres) * sizeof(int));
}

canonical_original_code:
void idmc_raster_set(struct idmc_raster *p, int value)
{
 memset(p->data, value, (p->xres * p->yres) * sizeof(int));
}


decompiled_code:
_BOOL8 __fastcall idmc_raster_isXYInsideBounds(__int64 a1, int a2, int a3)
{
_BOOL8 result; // rax

if ( a2 < 0 || a3 < 0 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 40) > a2 )
result = *(_DWORD *)(a1 + 72) > a3;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, int a2, int a3)
{
_BOOL8 result; // rax

if ( a2 < 0 || a3 < 0 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 40) > a2 )
result = *(_DWORD *)(a1 + 72) > a3;
return result;
}

original_code:
int idmc_raster_isXYInsideBounds(idmc_raster *p, int x, int y)
{
 return (x>=0 && y>=0 && x<(p->xres) && y<(p->yres));
}

canonical_original_code:
int idmc_raster_isXYInsideBounds(struct idmc_raster *p, int x, int y)
{
 return (x>=0 && y>=0 && x<(p->xres) && y<(p->yres));
}


decompiled_code:
_BOOL8 __fastcall idmc_raster_isxyInsideBounds(double *a1, double a2, double a3)
{
return idmc_raster_isXYInsideBounds((__int64)a1, (int)((a2 - a1[2]) / a1[4]), (int)((a3 - a1[6]) / a1[8]));
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(double *a1, double a2, double a3)
{
return func7((__int64)a1, (int)((a2 - a1[2]) / a1[4]), (int)((a3 - a1[6]) / a1[8]));
}

original_code:
int idmc_raster_isxyInsideBounds(idmc_raster *p, double x, double y)
{
 return idmc_raster_isXYInsideBounds( p, (int)( ((x) - (p)->xmin)/(p)->xeps ), (int)( ((y) - (p)->ymin)/(p)->yeps ) );
}

canonical_original_code:
int idmc_raster_isxyInsideBounds(struct idmc_raster *p, double x, double y)
{
 return idmc_raster_isXYInsideBounds( p, (int)( ((x) - (p)->xmin)/(p)->xeps ), (int)( ((y) - (p)->ymin)/(p)->yeps ) );
}


decompiled_code:
int __fastcall vector_out(__int64 *a1, double a2)
{
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rax

v2 = *a1;
putchar(40);
if ( (int)v2 > 0 )
{
v3 = (unsigned int)(v2 - 1);
v4 = 0LL;
do
{
gsl_vector_get(a1, v4);
printf("%.5e ", a2);
v5 = v4++;
}
while ( v5 != v3 );
}
return puts(")");
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, double a2)
{
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rax

v2 = *a1;
putchar(40);
if ( (int)v2 > 0 )
{
v3 = (unsigned int)(v2 - 1);
v4 = 0LL;
do
{
gsl_vector_get(a1, v4);
printf("%.5e ", a2);
v5 = v4++;
}
while ( v5 != v3 );
}
return puts(")");
}

original_code:
void vector_out(gsl_vector* v){
 int i;
 int d=(*v).size;
 printf("(");
 for (i=0;i<d;i++){
  printf("%.5e ",gsl_vector_get(v,i));
 }
 printf(")\n");
}

canonical_original_code:
void vector_out(struct gsl_vector *v){
 int i;
 int d = (*v).size;
 printf("(");
 for (i=0;i<d;i++){
  printf("%.5e ",gsl_vector_get(v,i));
 }
 printf(")\n");
}

variable_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: i int

variable_types: d int

user_defined_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; }


decompiled_code:
__int64 __fastcall matrix_out(__int64 *a1, double a2)
{
__int64 result; // rax
int v3; // er14
__int64 v4; // r15
__int64 i; // rbp
__int64 v6; // rbx
__int64 v7; // rax
int v8; // [rsp+Ch] [rbp-3Ch]

putchar(91);
result = *a1;
v8 = *a1;
if ( v8 > 0 )
{
v3 = a1[1];
v4 = (unsigned int)(result - 1);
for ( i = 0LL; ; ++i )
{
v6 = 0LL;
if ( v3 > 0 )
{
do
{
gsl_matrix_get(a1, i, v6);
printf("%.5e ", a2);
v7 = v6++;
}
while ( v3 - 1 != v7 );
}
if ( v8 - 1 <= (int)i )
puts("]");
else
putchar(10);
result = i + 1;
if ( i == v4 )
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, double a2)
{
__int64 result; // rax
int v3; // er14
__int64 v4; // r15
__int64 i; // rbp
__int64 v6; // rbx
__int64 v7; // rax
int v8; // [rsp+Ch] [rbp-3Ch]

putchar(91);
result = *a1;
v8 = *a1;
if ( v8 > 0 )
{
v3 = a1[1];
v4 = (unsigned int)(result - 1);
for ( i = 0LL; ; ++i )
{
v6 = 0LL;
if ( v3 > 0 )
{
do
{
gsl_matrix_get(a1, i, v6);
printf("%.5e ", a2);
v7 = v6++;
}
while ( v3 - 1 != v7 );
}
if ( v8 - 1 <= (int)i )
puts("]");
else
putchar(10);
result = i + 1;
if ( i == v4 )
break;
}
}
return result;
}

original_code:
void matrix_out(gsl_matrix* m){
 printf("[");
 int i,j;
 int d1=(*m).size1;
 int d2=(*m).size2;
 for (i=0;i<d1;i++){
  for (j=0;j<d2;j++){
   printf("%.5e ",gsl_matrix_get(m,i,j));
  }
  if (i<d1-1)
   printf("\n");
  else
   printf("]\n");
 }
}

canonical_original_code:
void matrix_out(struct gsl_matrix *m){
 printf("[");
 int i; int j;
 int d1 = (*m).size1;
 int d2 = (*m).size2;
 for (i=0;i<d1;i++){
  for (j=0;j<d2;j++){
   printf("%.5e ",gsl_matrix_get(m,i,j));
  }
  if (i<d1-1)
   printf("\n");
  else
   printf("]\n");
 }
}

variable_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: j int

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }


decompiled_code:
int __fastcall vector_arr_out(__int64 a1, int a2)
{
double v2; // xmm0_8
__int64 v4[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = gsl_vector_view_array(v4, a1, a2);
return vector_out(v4, v2);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2)
{
double v2; // xmm0_8
__int64 v4[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = gsl_vector_view_array(v4, a1, a2);
return func0(v4, v2);
}

original_code:
void vector_arr_out(double* v,int n){
 gsl_vector_view vv=gsl_vector_view_array(v,n);
 vector_out(&vv.vector);
}

canonical_original_code:
void vector_arr_out(double *v, int n){
 struct _gsl_vector_view vv = gsl_vector_view_array(v,n);
 vector_out(&vv.vector);
}

variable_types:
v
double *

variable_types: n int

variable_types: struct _gsl_vector_view { struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } vector; }

user_defined_types: struct _gsl_vector_view { struct gsl_vector vector; }


decompiled_code:
__int64 __fastcall matrix_arr_out(__int64 a1, int a2, int a3)
{
double v3; // xmm0_8
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

v3 = gsl_matrix_view_array(v5, a1, a2, a3);
return matrix_out(v5, v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
double v3; // xmm0_8
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

v3 = gsl_matrix_view_array(v5, a1, a2, a3);
return func1(v5, v3);
}

original_code:
void matrix_arr_out(double* v,int m,int n){
 gsl_matrix_view mv=gsl_matrix_view_array(v,m,n);
 matrix_out(&mv.matrix);
}

canonical_original_code:
void matrix_arr_out(double *v, int m, int n){
 struct _gsl_matrix_view mv = gsl_matrix_view_array(v,m,n);
 matrix_out(&mv.matrix);
}

variable_types: m int

variable_types: struct _gsl_matrix_view { struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } matrix; }

user_defined_types: struct _gsl_matrix_view { struct gsl_matrix matrix; }


decompiled_code:
__int64 __fastcall clone_matrix(_QWORD *a1)
{
__int64 v1; // rbp

v1 = gsl_matrix_alloc(*a1, a1[1]);
gsl_matrix_memcpy(v1, a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
__int64 v1; // rbp

v1 = gsl_matrix_alloc(*a1, a1[1]);
gsl_matrix_memcpy(v1, a1);
return v1;
}

original_code:
gsl_matrix* clone_matrix(gsl_matrix* m){
 gsl_matrix* m1=gsl_matrix_alloc((*m).size1,(*m).size2);
 gsl_matrix_memcpy(m1,m);
 return m1;
}

canonical_original_code:
struct gsl_matrix *clone_matrix(struct gsl_matrix *m){
 struct gsl_matrix *m1 = gsl_matrix_alloc((*m).size1,(*m).size2);
 gsl_matrix_memcpy(m1,m);
 return m1;
}

variable_types:
m
struct gsl_matrix *

return_type: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *


decompiled_code:
void *__fastcall clone_array(void *src, int a2)
{
void *v2; // rax

v2 = malloc(8 * a2);
return memcpy(v2, src, 8 * a2);
}

canonical_decompiled_code:
void *__fastcall func5(void *src, int a2)
{
void *v2; // rax

v2 = malloc(8 * a2);
return memcpy(v2, src, 8 * a2);
}

original_code:
double* clone_array(double* a, int d){
 int dd=d*sizeof(double);
 double* b=(double*) malloc(dd);
 memcpy(b,a,dd);
 return b;
}

canonical_original_code:
double *clone_array(double *a, int d){
 int dd = d*sizeof(double);
 double *b = (double*) malloc(dd);
 memcpy(b,a,dd);
 return b;
}

variable_types:
a
double *

variable_types: dd int

variable_types:
b
double *

return_type: double *


mvproduct

decompiled_code:
__int64 __fastcall mvproduct(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
__int64 v7; // rbp
_BYTE v9[48]; // [rsp+0h] [rbp-B8h] BYREF
char v10[48]; // [rsp+30h] [rbp-88h] BYREF
char v11[88]; // [rsp+60h] [rbp-58h] BYREF

v7 = a5;
gsl_vector_view_array(v11, a2, a5);
gsl_matrix_view_array(v10, a1, a4, v7);
gsl_vector_view_array(v9, a3, a4);
return gsl_blas_dgemv(111LL, v10, v11, v9, 1.0, 0.0);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
__int64 v7; // rbp
_BYTE v9[48]; // [rsp+0h] [rbp-B8h] BYREF
char v10[48]; // [rsp+30h] [rbp-88h] BYREF
char v11[88]; // [rsp+60h] [rbp-58h] BYREF

v7 = a5;
gsl_vector_view_array(v11, a2, a5);
gsl_matrix_view_array(v10, a1, a4, v7);
gsl_vector_view_array(v9, a3, a4);
return gsl_blas_dgemv(111LL, v10, v11, v9, 1.0, 0.0);
}

original_code:
inline void mvproduct(double* a, double* b, double* result,int m,int n){
 gsl_vector_view vv=gsl_vector_view_array(b,n);
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 gsl_vector_view rv=gsl_vector_view_array(result,m);
 gsl_blas_dgemv(CblasNoTrans,1.0,&(av.matrix),&(vv.vector),0.0,&(rv.vector));
}

canonical_original_code:
inline void mvproduct(double *a, double *b, double *result, int m, int n){
 struct _gsl_vector_view vv = gsl_vector_view_array(b,n);
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 struct _gsl_vector_view rv = gsl_vector_view_array(result,m);
 gsl_blas_dgemv(CblasNoTrans,1.0,&(av.matrix),&(vv.vector),0.0,&(rv.vector));
}

variable_types:
result
double *

user_defined_types: struct gsl_block_struct { unsigned long size; double *data; }


sum

decompiled_code:
__int64 __fastcall sum(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
double v4; // xmm0_8
_BYTE v6[48]; // [rsp+0h] [rbp-78h] BYREF
char v7[72]; // [rsp+30h] [rbp-48h] BYREF

v3 = a3;
gsl_vector_view_array(v7, a1, a3);
v4 = gsl_vector_view_array(v6, a2, v3);
return gsl_vector_add(v7, v6, v4);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
double v4; // xmm0_8
_BYTE v6[48]; // [rsp+0h] [rbp-78h] BYREF
char v7[72]; // [rsp+30h] [rbp-48h] BYREF

v3 = a3;
gsl_vector_view_array(v7, a1, a3);
v4 = gsl_vector_view_array(v6, a2, v3);
return gsl_vector_add(v7, v6, v4);
}

original_code:
inline void sum(double* a, double* b, int d){
 gsl_vector_view av=gsl_vector_view_array(a,d);
 gsl_vector_view bv=gsl_vector_view_array(b,d);
 gsl_vector_add(&av.vector,&bv.vector);
}

canonical_original_code:
inline void sum(double *a, double *b, int d){
 struct _gsl_vector_view av = gsl_vector_view_array(a,d);
 struct _gsl_vector_view bv = gsl_vector_view_array(b,d);
 gsl_vector_add(&av.vector,&bv.vector);
}


mmproduct

decompiled_code:
__int64 __fastcall mmproduct(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v8; // rbp
__int64 v9; // r12
_BYTE v11[48]; // [rsp+0h] [rbp-B8h] BYREF
char v12[48]; // [rsp+30h] [rbp-88h] BYREF
char v13[88]; // [rsp+60h] [rbp-58h] BYREF

v8 = a6;
v9 = a5;
gsl_matrix_view_array(v13, a2, a5, a6);
gsl_matrix_view_array(v12, a1, a4, v9);
gsl_matrix_view_array(v11, a3, a4, v8);
return gsl_blas_dgemm(111LL, 111LL, v12, v13, v11, 1.0, 0.0);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v8; // rbp
__int64 v9; // r12
_BYTE v11[48]; // [rsp+0h] [rbp-B8h] BYREF
char v12[48]; // [rsp+30h] [rbp-88h] BYREF
char v13[88]; // [rsp+60h] [rbp-58h] BYREF

v8 = a6;
v9 = a5;
gsl_matrix_view_array(v13, a2, a5, a6);
gsl_matrix_view_array(v12, a1, a4, v9);
gsl_matrix_view_array(v11, a3, a4, v8);
return gsl_blas_dgemm(111LL, 111LL, v12, v13, v11, 1.0, 0.0);
}

original_code:
inline void mmproduct(const double* a, const double* b, double* result,int m,int n,int p){
 gsl_matrix_view bv=gsl_matrix_view_array((double*) b,n,p);
 gsl_matrix_view av=gsl_matrix_view_array((double*) a,m,n);
 gsl_matrix_view rv=gsl_matrix_view_array(result,m,p);
 gsl_blas_dgemm(CblasNoTrans,CblasNoTrans,1.0,&(av.matrix),&(bv.matrix),0.0,&(rv.matrix));
}

canonical_original_code:
inline void mmproduct(double *a, double *b, double *result, int m, int n, int p){
 struct _gsl_matrix_view bv = gsl_matrix_view_array((double*) b,n,p);
 struct _gsl_matrix_view av = gsl_matrix_view_array((double*) a,m,n);
 struct _gsl_matrix_view rv = gsl_matrix_view_array(result,m,p);
 gsl_blas_dgemm(CblasNoTrans,CblasNoTrans,1.0,&(av.matrix),&(bv.matrix),0.0,&(rv.matrix));
}

variable_types: p int


mcproduct

decompiled_code:
__int64 __fastcall mcproduct(__int64 a1, int a2, int a3, double a4)
{
_BYTE v6[56]; // [rsp+0h] [rbp-38h] BYREF

gsl_matrix_view_array(v6, a1, a2, a3);
return gsl_matrix_scale(v6, a4);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3, double a4)
{
_BYTE v6[56]; // [rsp+0h] [rbp-38h] BYREF

gsl_matrix_view_array(v6, a1, a2, a3);
return gsl_matrix_scale(v6, a4);
}

original_code:
inline void mcproduct(double* a,double c,int m,int n){
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 gsl_matrix_scale(&av.matrix,c);
}

canonical_original_code:
inline void mcproduct(double *a, double c, int m, int n){
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 gsl_matrix_scale(&av.matrix,c);
}

variable_types: c double


vcproduct

decompiled_code:
__int64 __fastcall vcproduct(__int64 a1, int a2, double a3)
{
_BYTE v5[56]; // [rsp+0h] [rbp-38h] BYREF

gsl_vector_view_array(v5, a1, a2);
return gsl_vector_scale(v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, double a3)
{
_BYTE v5[56]; // [rsp+0h] [rbp-38h] BYREF

gsl_vector_view_array(v5, a1, a2);
return gsl_vector_scale(v5, a3);
}

original_code:
inline void vcproduct(double* v, double c,int n){
 gsl_vector_view vv=gsl_vector_view_array(v,n);
 gsl_vector_scale(&vv.vector,c);
}

canonical_original_code:
inline void vcproduct(double *v, double c, int n){
 struct _gsl_vector_view vv = gsl_vector_view_array(v,n);
 gsl_vector_scale(&vv.vector,c);
}


transpose

decompiled_code:
__int64 __fastcall transpose(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 v4; // rbx
__int64 v5; // rbp
double v6; // xmm0_8
_BYTE v8[48]; // [rsp+0h] [rbp-78h] BYREF
char v9[72]; // [rsp+30h] [rbp-48h] BYREF

v4 = a4;
v5 = a3;
gsl_matrix_view_array(v9, a1, a3, a4);
v6 = gsl_matrix_view_array(v8, a2, v4, v5);
return gsl_matrix_transpose_memcpy(v8, v9, v6);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 v4; // rbx
__int64 v5; // rbp
double v6; // xmm0_8
_BYTE v8[48]; // [rsp+0h] [rbp-78h] BYREF
char v9[72]; // [rsp+30h] [rbp-48h] BYREF

v4 = a4;
v5 = a3;
gsl_matrix_view_array(v9, a1, a3, a4);
v6 = gsl_matrix_view_array(v8, a2, v4, v5);
return gsl_matrix_transpose_memcpy(v8, v9, v6);
}

original_code:
inline void transpose(const double* a, double* b, int m,int n){
 gsl_matrix_view av=gsl_matrix_view_array((double*) a,m,n);
 gsl_matrix_view bv=gsl_matrix_view_array(b,n,m);
 gsl_matrix_transpose_memcpy(&bv.matrix,&av.matrix);
}

canonical_original_code:
inline void transpose(double *a, double *b, int m, int n){
 struct _gsl_matrix_view av = gsl_matrix_view_array((double*) a,m,n);
 struct _gsl_matrix_view bv = gsl_matrix_view_array(b,n,m);
 gsl_matrix_transpose_memcpy(&bv.matrix,&av.matrix);
}


asym

decompiled_code:
__int64 __fastcall asym(__int64 a1, int a2)
{
double v2; // xmm0_8
__int64 i; // rbx
_BYTE v5[48]; // [rsp+0h] [rbp-D8h] BYREF
char v6[48]; // [rsp+30h] [rbp-A8h] BYREF
char v7[48]; // [rsp+60h] [rbp-78h] BYREF
char v8[72]; // [rsp+90h] [rbp-48h] BYREF

v2 = gsl_matrix_view_array(v8, a1, a2, a2);
if ( a2 > 1 )
{
for ( i = 1LL; i != a2; ++i )
{
gsl_matrix_superdiagonal(v5, v8, i, v2);
gsl_matrix_subdiagonal(v6, v8, i);
gsl_vector_memcpy(v5, v6);
v2 = *(double *)&LC5;
gsl_vector_scale(v5, -1.0);
}
}
gsl_matrix_superdiagonal(v7, v8, 0LL, v2);
return gsl_vector_set_zero(v7);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
double v2; // xmm0_8
__int64 i; // rbx
_BYTE v5[48]; // [rsp+0h] [rbp-D8h] BYREF
char v6[48]; // [rsp+30h] [rbp-A8h] BYREF
char v7[48]; // [rsp+60h] [rbp-78h] BYREF
char v8[72]; // [rsp+90h] [rbp-48h] BYREF

v2 = gsl_matrix_view_array(v8, a1, a2, a2);
if ( a2 > 1 )
{
for ( i = 1LL; i != a2; ++i )
{
gsl_matrix_superdiagonal(v5, v8, i, v2);
gsl_matrix_subdiagonal(v6, v8, i);
gsl_vector_memcpy(v5, v6);
v2 = *(double *)&LC5;
gsl_vector_scale(v5, -1.0);
}
}
gsl_matrix_superdiagonal(v7, v8, 0LL, v2);
return gsl_vector_set_zero(v7);
}

original_code:
inline void asym(double* a,int n){
 int i;
 gsl_matrix_view av=gsl_matrix_view_array(a,n,n);
 for (i=1;i<n;i++){
  gsl_vector_view vsup=gsl_matrix_superdiagonal(&av.matrix,i);
  gsl_vector_view vsub=gsl_matrix_subdiagonal(&av.matrix,i);
  gsl_vector_memcpy(&vsup.vector,&vsub.vector);
  gsl_vector_scale(&vsup.vector,-1);
 }
 gsl_vector_view vsup=gsl_matrix_superdiagonal(&av.matrix,0);
 gsl_vector_set_zero(&vsup.vector);
}

canonical_original_code:
inline void asym(double *a, int n){
 int i;
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,n,n);
 for (i=1;i<n;i++){
  struct _gsl_vector_view vsup = gsl_matrix_superdiagonal(&av.matrix,i);
  struct _gsl_vector_view vsub = gsl_matrix_subdiagonal(&av.matrix,i);
  gsl_vector_memcpy(&vsup.vector,&vsub.vector);
  gsl_vector_scale(&vsup.vector,-1);
 }
 struct _gsl_vector_view vsup = gsl_matrix_superdiagonal(&av.matrix,0);
 gsl_vector_set_zero(&vsup.vector);
}


decompiled_code:
__int64 __fastcall qr_coded(__int64 a1, __int64 a2, int a3, int a4)
{
int v6; // edx
double v7; // xmm0_8
_BYTE v9[48]; // [rsp+0h] [rbp-78h] BYREF
char v10[72]; // [rsp+30h] [rbp-48h] BYREF

gsl_matrix_view_array(v10, a1, a3, a4);
v6 = a3;
if ( a4 <= a3 )
v6 = a4;
v7 = gsl_vector_view_array(v9, a2, v6);
return gsl_linalg_QR_decomp(v10, v9, v7);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, int a3, int a4)
{
int v6; // edx
double v7; // xmm0_8
_BYTE v9[48]; // [rsp+0h] [rbp-78h] BYREF
char v10[72]; // [rsp+30h] [rbp-48h] BYREF

gsl_matrix_view_array(v10, a1, a3, a4);
v6 = a3;
if ( a4 <= a3 )
v6 = a4;
v7 = gsl_vector_view_array(v9, a2, v6);
return gsl_linalg_QR_decomp(v10, v9, v7);
}

original_code:
inline void qr_coded(double* a, double* tau, int m,int n){
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 int d;
 if (m<n) d=m; else d=n;
 gsl_vector_view tv=gsl_vector_view_array(tau,d);
 gsl_linalg_QR_decomp(&av.matrix,&tv.vector);
}

canonical_original_code:
inline void qr_coded(double *a, double *tau, int m, int n){
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 int d;
 if (m<n) d=m; else d=n;
 struct _gsl_vector_view tv = gsl_vector_view_array(tau,d);
 gsl_linalg_QR_decomp(&av.matrix,&tv.vector);
}

variable_types:
tau
double *


decompiled_code:
__int64 __fastcall qr_decomp(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5, int a6)
{
__int64 v9; // r12
int v10; // edx
double v11; // xmm0_8
char v13[48]; // [rsp+10h] [rbp-F8h] BYREF
char v14[48]; // [rsp+40h] [rbp-C8h] BYREF
char v15[48]; // [rsp+70h] [rbp-98h] BYREF
char v16[104]; // [rsp+A0h] [rbp-68h] BYREF

v9 = a5;
gsl_matrix_view_array(v16, a3, a5, a5);
gsl_matrix_view_array(v15, a4, v9, a6);
gsl_matrix_view_array(v14, a1, v9, a6);
v10 = a6;
if ( a5 <= a6 )
v10 = a5;
v11 = gsl_vector_view_array(v13, a2, v10);
return gsl_linalg_QR_unpack(v14, v13, v16, v15, v11);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5, int a6)
{
__int64 v9; // r12
int v10; // edx
double v11; // xmm0_8
char v13[48]; // [rsp+10h] [rbp-F8h] BYREF
char v14[48]; // [rsp+40h] [rbp-C8h] BYREF
char v15[48]; // [rsp+70h] [rbp-98h] BYREF
char v16[104]; // [rsp+A0h] [rbp-68h] BYREF

v9 = a5;
gsl_matrix_view_array(v16, a3, a5, a5);
gsl_matrix_view_array(v15, a4, v9, a6);
gsl_matrix_view_array(v14, a1, v9, a6);
v10 = a6;
if ( a5 <= a6 )
v10 = a5;
v11 = gsl_vector_view_array(v13, a2, v10);
return gsl_linalg_QR_unpack(v14, v13, v16, v15, v11);
}

original_code:
inline void qr_decomp(double* a, double* tau, double* q, double* r,int m,int n){
 gsl_matrix_view qv=gsl_matrix_view_array(q,m,m);
 gsl_matrix_view rv=gsl_matrix_view_array(r,m,n);
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 int d;
 if (m<n) d=m; else d=n;
 gsl_vector_view tv=gsl_vector_view_array(tau,d);
 gsl_linalg_QR_unpack(&av.matrix,&tv.vector,&qv.matrix,&rv.matrix);
}

canonical_original_code:
inline void qr_decomp(double *a, double *tau, double *q, double *r, int m, int n){
 struct _gsl_matrix_view qv = gsl_matrix_view_array(q,m,m);
 struct _gsl_matrix_view rv = gsl_matrix_view_array(r,m,n);
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 int d;
 if (m<n) d=m; else d=n;
 struct _gsl_vector_view tv = gsl_vector_view_array(tau,d);
 gsl_linalg_QR_unpack(&av.matrix,&tv.vector,&qv.matrix,&rv.matrix);
}

variable_types:
q
double *

variable_types:
r
double *


decompiled_code:
void __fastcall qr_qmproduct(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v10; // r15
int v11; // edx
double v12; // xmm0_8
__int64 v13; // rbx
_BYTE v14[48]; // [rsp+0h] [rbp-F8h] BYREF
char v15[48]; // [rsp+30h] [rbp-C8h] BYREF
char v16[48]; // [rsp+60h] [rbp-98h] BYREF
char v17[104]; // [rsp+90h] [rbp-68h] BYREF

v10 = a4;
gsl_matrix_view_array(v17, a1, a4, a5);
gsl_matrix_view_array(v16, a3, v10, a6);
v11 = a4;
if ( a5 <= a4 )
v11 = a5;
v12 = gsl_vector_view_array(v15, a2, v11);
if ( a6 > 0 )
{
v13 = 0LL;
do
{
gsl_matrix_column(v14, v16, v13, v12);
gsl_linalg_QR_Qvec(v17, v15, v14);
++v13;
}
while ( v13 != a6 );
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v10; // r15
int v11; // edx
double v12; // xmm0_8
__int64 v13; // rbx
_BYTE v14[48]; // [rsp+0h] [rbp-F8h] BYREF
char v15[48]; // [rsp+30h] [rbp-C8h] BYREF
char v16[48]; // [rsp+60h] [rbp-98h] BYREF
char v17[104]; // [rsp+90h] [rbp-68h] BYREF

v10 = a4;
gsl_matrix_view_array(v17, a1, a4, a5);
gsl_matrix_view_array(v16, a3, v10, a6);
v11 = a4;
if ( a5 <= a4 )
v11 = a5;
v12 = gsl_vector_view_array(v15, a2, v11);
if ( a6 > 0 )
{
v13 = 0LL;
do
{
gsl_matrix_column(v14, v16, v13, v12);
gsl_linalg_QR_Qvec(v17, v15, v14);
++v13;
}
while ( v13 != a6 );
}
}

original_code:
inline void qr_qmproduct(double* a, double* tau,
double* s, int m,int n,int p){
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 gsl_matrix_view sv=gsl_matrix_view_array(s,m,p);
 int d;
 if (m<n) d=m; else d=n;
 gsl_vector_view tv=gsl_vector_view_array(tau,d);
 int i;
 for (i=0;i<p;i++){
  gsl_vector_view scv=gsl_matrix_column(&sv.matrix,i);
  gsl_linalg_QR_Qvec(&av.matrix,&tv.vector,&scv.vector);
 }
}

canonical_original_code:
inline void qr_qmproduct(double *a, double *tau, double *s, int m, int n, int p){
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 struct _gsl_matrix_view sv = gsl_matrix_view_array(s,m,p);
 int d;
 if (m<n) d=m; else d=n;
 struct _gsl_vector_view tv = gsl_vector_view_array(tau,d);
 int i;
 for (i=0;i<p;i++){
  struct _gsl_vector_view scv = gsl_matrix_column(&sv.matrix,i);
  gsl_linalg_QR_Qvec(&av.matrix,&tv.vector,&scv.vector);
 }
}

variable_types:
s
double *

variable_types: d int

variable_types: i int


decompiled_code:
void __fastcall qr_qtmproduct(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v10; // r15
int v11; // edx
double v12; // xmm0_8
__int64 v13; // rbx
_BYTE v14[48]; // [rsp+0h] [rbp-F8h] BYREF
char v15[48]; // [rsp+30h] [rbp-C8h] BYREF
char v16[48]; // [rsp+60h] [rbp-98h] BYREF
char v17[104]; // [rsp+90h] [rbp-68h] BYREF

v10 = a4;
gsl_matrix_view_array(v17, a1, a4, a5);
gsl_matrix_view_array(v16, a3, v10, a6);
v11 = a4;
if ( a5 <= a4 )
v11 = a5;
v12 = gsl_vector_view_array(v15, a2, v11);
if ( a6 > 0 )
{
v13 = 0LL;
do
{
gsl_matrix_column(v14, v16, v13, v12);
gsl_linalg_QR_QTvec(v17, v15, v14);
++v13;
}
while ( v13 != a6 );
}
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v10; // r15
int v11; // edx
double v12; // xmm0_8
__int64 v13; // rbx
_BYTE v14[48]; // [rsp+0h] [rbp-F8h] BYREF
char v15[48]; // [rsp+30h] [rbp-C8h] BYREF
char v16[48]; // [rsp+60h] [rbp-98h] BYREF
char v17[104]; // [rsp+90h] [rbp-68h] BYREF

v10 = a4;
gsl_matrix_view_array(v17, a1, a4, a5);
gsl_matrix_view_array(v16, a3, v10, a6);
v11 = a4;
if ( a5 <= a4 )
v11 = a5;
v12 = gsl_vector_view_array(v15, a2, v11);
if ( a6 > 0 )
{
v13 = 0LL;
do
{
gsl_matrix_column(v14, v16, v13, v12);
gsl_linalg_QR_QTvec(v17, v15, v14);
++v13;
}
while ( v13 != a6 );
}
}

original_code:
inline void qr_qtmproduct(double* a, double* tau,
double* s, int m,int n,int p){
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 gsl_matrix_view sv=gsl_matrix_view_array(s,m,p);
 int d;
 if (m<n) d=m; else d=n;
 gsl_vector_view tv=gsl_vector_view_array(tau,d);
 int i;
 for (i=0;i<p;i++){
  gsl_vector_view scv=gsl_matrix_column(&sv.matrix,i);
  gsl_linalg_QR_QTvec(&av.matrix,&tv.vector,&scv.vector);
 }
}

canonical_original_code:
inline void qr_qtmproduct(double *a, double *tau, double *s, int m, int n, int p){
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 struct _gsl_matrix_view sv = gsl_matrix_view_array(s,m,p);
 int d;
 if (m<n) d=m; else d=n;
 struct _gsl_vector_view tv = gsl_vector_view_array(tau,d);
 int i;
 for (i=0;i<p;i++){
  struct _gsl_vector_view scv = gsl_matrix_column(&sv.matrix,i);
  gsl_linalg_QR_QTvec(&av.matrix,&tv.vector,&scv.vector);
 }
}

variable_types: n int


decompiled_code:
__int64 __fastcall idmc_cycles_eigval(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // r13
__int64 result; // rax
__int64 v6; // r14
__int64 i; // rbx
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // [rsp+8h] [rbp-F0h]
__m128i v13; // [rsp+10h] [rbp-E8h] BYREF
__m128i v14; // [rsp+20h] [rbp-D8h] BYREF
__m128i v15; // [rsp+30h] [rbp-C8h] BYREF
char v16[48]; // [rsp+40h] [rbp-B8h] BYREF
char v17[48]; // [rsp+70h] [rbp-88h] BYREF
__int128 v18[5]; // [rsp+A0h] [rbp-58h] BYREF

v4 = gsl_vector_complex_alloc(a2);
result = 1LL;
if ( v4 )
{
gsl_matrix_view_array(&v13, a1, a2, a2);
v18[0] = (__int128)_mm_loadu_si128(&v13);
v18[1] = (__int128)_mm_loadu_si128(&v14);
v18[2] = (__int128)_mm_loadu_si128(&v15);
v6 = gsl_eigen_nonsymm_alloc(a2);
result = 1LL;
if ( v6 )
{
gsl_eigen_nonsymm_params(0LL, 1LL, v6);
gsl_eigen_nonsymm(v18, v4, v6);
gsl_vector_complex_real(v17, v4);
gsl_vector_complex_imag(v16, v4);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; *(double *)(a3 + 8 * i++) = v11 )
{
v8 = gsl_vector_get(v17, i);
v12 = v8 * v8;
v9 = gsl_vector_get(v16, i);
v10 = v9 * v9 + v12;
if ( v10 < 0.0 )
v11 = sqrt(v10);
else
v11 = sqrt(v10);
}
}
gsl_eigen_nonsymm_free(v6);
gsl_vector_complex_free(v4);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // r13
__int64 result; // rax
__int64 v6; // r14
__int64 i; // rbx
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // [rsp+8h] [rbp-F0h]
__m128i v13; // [rsp+10h] [rbp-E8h] BYREF
__m128i v14; // [rsp+20h] [rbp-D8h] BYREF
__m128i v15; // [rsp+30h] [rbp-C8h] BYREF
char v16[48]; // [rsp+40h] [rbp-B8h] BYREF
char v17[48]; // [rsp+70h] [rbp-88h] BYREF
__int128 v18[5]; // [rsp+A0h] [rbp-58h] BYREF

v4 = gsl_vector_complex_alloc(a2);
result = 1LL;
if ( v4 )
{
gsl_matrix_view_array(&v13, a1, a2, a2);
v18[0] = (__int128)_mm_loadu_si128(&v13);
v18[1] = (__int128)_mm_loadu_si128(&v14);
v18[2] = (__int128)_mm_loadu_si128(&v15);
v6 = gsl_eigen_nonsymm_alloc(a2);
result = 1LL;
if ( v6 )
{
gsl_eigen_nonsymm_params(0LL, 1LL, v6);
gsl_eigen_nonsymm(v18, v4, v6);
gsl_vector_complex_real(v17, v4);
gsl_vector_complex_imag(v16, v4);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; *(double *)(a3 + 8 * i++) = v11 )
{
v8 = gsl_vector_get(v17, i);
v12 = v8 * v8;
v9 = gsl_vector_get(v16, i);
v10 = v9 * v9 + v12;
if ( v10 < 0.0 )
v11 = sqrt(v10);
else
v11 = sqrt(v10);
}
}
gsl_eigen_nonsymm_free(v6);
gsl_vector_complex_free(v4);
result = 0LL;
}
}
return result;
}

original_code:
int idmc_cycles_eigval(double *mat, int dim, double *ans) {
  gsl_eigen_nonsymm_workspace *ws;
  gsl_matrix_view A;
  gsl_vector_complex *eval;
  int res;
  eval = gsl_vector_complex_alloc(dim);
  if(eval==((void *)0))
    return 1;
  A = gsl_matrix_view_array(mat, dim, dim);
  ws = gsl_eigen_nonsymm_alloc(dim);
  if(ws==((void *)0))
    return 1;
  gsl_eigen_nonsymm_params( 0, 1, ws);
  res = gsl_eigen_nonsymm (&A.matrix, eval, ws);
  gsl_vector_view vr = gsl_vector_complex_real (eval);
  gsl_vector_view vi = gsl_vector_complex_imag (eval);
  for(int i=0; i<dim; i++)
    ans[i] = sqrt( pow(gsl_vector_get(&vr.vector, i),2) + pow(gsl_vector_get(&vi.vector, i),2) );
  gsl_eigen_nonsymm_free(ws);
  gsl_vector_complex_free(eval);
  return 0;
}

canonical_original_code:
int idmc_cycles_eigval(double *mat, int dim, double *ans) {
  struct gsl_eigen_nonsymm_workspace *ws;
  struct _gsl_matrix_view A;
  struct gsl_vector_complex *eval;
  int res;
  eval = gsl_vector_complex_alloc(dim);
  if(eval==((void *)0))
    return 1;
  A = gsl_matrix_view_array(mat, dim, dim);
  ws = gsl_eigen_nonsymm_alloc(dim);
  if(ws==((void *)0))
    return 1;
  gsl_eigen_nonsymm_params( 0, 1, ws);
  res = gsl_eigen_nonsymm (&A.matrix, eval, ws);
  struct _gsl_vector_view vr = gsl_vector_complex_real (eval);
  struct _gsl_vector_view vi = gsl_vector_complex_imag (eval);
  for(int i = 0; i<dim; i++)
    ans[i] = sqrt( pow(gsl_vector_get(&vr.vector, i),2) + pow(gsl_vector_get(&vi.vector, i),2) );
  gsl_eigen_nonsymm_free(ws);
  gsl_vector_complex_free(eval);
  return 0;
}

variable_types:
mat
double *

variable_types: dim int

variable_types:
ans
double *

variable_types: struct gsl_eigen_nonsymm_workspace { unsigned long size; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *diag; struct gsl_vector *tau; struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *Z; int do_balance; unsigned long n_evals; struct gsl_eigen_francis_workspace { unsigned long size; unsigned long max_iterations; unsigned long n_iter; unsigned long n_evals; int compute_t; struct gsl_matrix *H; struct gsl_matrix *Z; } *francis_workspace_p; } *

variable_types: struct gsl_vector_complex { unsigned long size; unsigned long stride; double *data; struct gsl_block_complex_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: res int

variable_types: struct _gsl_vector_view { struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } vector; }

user_defined_types: struct gsl_eigen_nonsymm_workspace { unsigned long size; struct gsl_vector *diag; struct gsl_vector *tau; struct gsl_matrix *Z; int do_balance; unsigned long n_evals; struct gsl_eigen_francis_workspace *francis_workspace_p; }

user_defined_types: struct gsl_vector_complex { unsigned long size; unsigned long stride; double *data; struct gsl_block_complex_struct *block; int owner; }


repo: antonis-m/Parallel-Processing-Systems

decompiled_code:
int __fastcall do_error(int a1, const char *a2, void *a3)
{
size_t v4; // rax
int v5; // edi
char *v7; // rbx
size_t v8; // rax
char s[2]; // [rsp+0h] [rbp-1018h] BYREF

s[0] = 0;
if ( program_name )
snprintf(s, 0x1000uLL, "%s: ", (const char *)program_name);
v4 = strlen(s);
vsnprintf(&s[v4], 0x1000uLL, a2, a3);
if ( a1 )
{
v5 = *_errno_location();
if ( v5 )
{
v7 = strerror(v5);
v8 = strlen(s);
snprintf(&s[v8], 0x1000uLL, ": %s", v7);
}
}
*(_WORD *)&s[strlen(s)] = 10;
fflush(stdout);
fputs(s, stderr);
return fflush(0LL);
}

canonical_decompiled_code:
int __fastcall func0(int a1, const char *a2, void *a3)
{
size_t v4; // rax
int v5; // edi
char *v7; // rbx
size_t v8; // rax
char s[2]; // [rsp+0h] [rbp-1018h] BYREF

s[0] = 0;
if ( program_name )
snprintf(s, 0x1000uLL, "%s: ", (const char *)program_name);
v4 = strlen(s);
vsnprintf(&s[v4], 0x1000uLL, a2, a3);
if ( a1 )
{
v5 = *_errno_location();
if ( v5 )
{
v7 = strerror(v5);
v8 = strlen(s);
snprintf(&s[v8], 0x1000uLL, ": %s", v7);
}
}
*(_WORD *)&s[strlen(s)] = 10;
fflush(stdout);
fputs(s, stderr);
return fflush(0LL);
}

original_code:
static void
do_error(int use_errno, const char *fmt, va_list arg)
{
    char errmsg[4096];
    *errmsg = '\0';
    if (program_name)
        snprintf(errmsg, 4096, "%s: ", program_name);
    vsnprintf(errmsg + strlen(errmsg), 4096, fmt, arg);
    if (use_errno && (*__errno_location ()))
        snprintf(errmsg + strlen(errmsg), 4096,
                 ": %s", strerror((*__errno_location ())));
    strncat(errmsg, "\n", 4096);
    fflush(stdout);
    fputs(errmsg, stderr);
    fflush(((void *)0));
    return;
}

canonical_original_code:
static void do_error(int use_errno, char *fmt, __builtin_va_list arg)
{
    char errmsg[4096];
    *errmsg = '\0';
    if (program_name)
        snprintf(errmsg, 4096, "%s: ", program_name);
    vsnprintf(errmsg + strlen(errmsg), 4096, fmt, arg);
    if (use_errno && (*__errno_location ()))
        snprintf(errmsg + strlen(errmsg), 4096,
                 ": %s", strerror((*__errno_location ())));
    strncat(errmsg, "\n", 4096);
    fflush(stdout);
    fputs(errmsg, stderr);
    fflush(((void *)0));
    return;
}

variable_types:
fmt
char *

variable_types:
errmsg
char [4096]


warning

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

va_start(va, a2);
return do_error(a1, a2, va);
}

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

va_start(va, a2);
return func0(a1, a2, va);
}

original_code:
void
warning(int use_errno, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    return;
}

canonical_original_code:
void warning(int use_errno, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    return;
}


error

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

va_start(va, a2);
do_error(a1, a2, va);
exit(1);
}

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

va_start(va, a2);
func0(a1, a2, va);
exit(1);
}

original_code:
void
error(int use_errno, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    exit(1);
}

canonical_original_code:
void error(int use_errno, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    exit(1);
}


decompiled_code:
void __fastcall set_program_name(const char *a1)
{
if ( !program_name )
{
program_name = (__int64)strdup(a1);
if ( !program_name )
error(1, "strdup failed");
}
}

canonical_decompiled_code:
void __fastcall func3(const char *a1)
{
if ( !program_name )
{
program_name = (__int64)strdup(a1);
if ( !program_name )
func2(1, "strdup failed");
}
}

original_code:
void
set_program_name(char *path)
{
    if (!program_name)
        program_name = strdup(path);
    if (!program_name)
        error(1, "strdup failed");
}

variable_types:
path
char *