ngImageCreate

decompiled_code:
__int64 __fastcall ngImageCreate(__int64 a1, int a2)
{
__int64 v2; // r12
int v3; // ebp

v2 = gdImageCreateTrueColor();
gdImageColorAllocate();
gdImageFill();
gdImageColorTransparent();
if ( a2 - 27 >= 0 )
{
v3 = 0;
do
{
gdImageColorAllocateAlpha();
++v3;
gdImageLine();
}
while ( v3 != a2 - 26 );
}
gdImageColorAllocateAlpha();
gdImageRectangle();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
__int64 v2; // r12
int v3; // ebp

v2 = gdImageCreateTrueColor();
gdImageColorAllocate();
gdImageFill();
gdImageColorTransparent();
if ( a2 - 27 >= 0 )
{
v3 = 0;
do
{
gdImageColorAllocateAlpha();
++v3;
gdImageLine();
}
while ( v3 != a2 - 26 );
}
gdImageColorAllocateAlpha();
gdImageRectangle();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
return v2;
}

original_code:
gdImagePtr ngImageCreate(int x, int y)
{
    gdImagePtr img;
    int i;
    int color_bg, color_black;
    int graph_y;
    int gray_value, color_gradient;
    int border_left, border_right, border_top, border_bottom;
    int vertical_baseline, vertical_shift;
    int horizontal_baseline, horizontal_shift;
    border_left = 25;
    border_right = 5;
    border_top = 5;
    border_bottom = 20;
    img = gdImageCreateTrueColor(x, y);
    color_bg = gdImageColorAllocate(img, 255, 255, 255);
    gdImageFill(img, 0, 0, color_bg);
    gdImageColorTransparent(img, color_bg);
    graph_y = y - border_top - border_bottom - 2;
    for(i=0; i<=graph_y; i++) {
        gray_value = (int) 225 - (200 * ((double) i/graph_y));
        color_gradient = gdImageColorAllocateAlpha(img, gray_value, gray_value, gray_value, 0);
        gdImageLine(img, border_left+1, border_top + 1 + i, x - border_right - 1, border_top + 1 + i, color_gradient);
    }
    color_black = gdImageColorAllocateAlpha(img, 0, 0, 0, 0);
    gdImageRectangle(img, border_left, border_top, x-border_right, y-border_bottom, color_black);
    vertical_baseline = border_left - 5;
    horizontal_baseline = y-border_bottom + 9;
    vertical_shift = y - border_bottom;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 5;
    gdImageLine(img, vertical_baseline-3, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-3, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 10;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 15;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 20;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline-1, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-2, vertical_shift-1, vertical_baseline, vertical_shift-1, color_black);
    gdImageLine(img, vertical_baseline-3, vertical_shift-2, vertical_baseline-1, vertical_shift-2, color_black);
    gdImageLine(img, vertical_baseline-2, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-4, vertical_baseline-1, vertical_shift-4, color_black);
    vertical_shift = y - border_bottom - 24;
    gdImageLine(img, vertical_baseline-4, vertical_shift-2, vertical_baseline, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 28;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 33;
    gdImageLine(img, vertical_baseline-4, vertical_shift-1, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 37;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    horizontal_shift = border_left;
    gdImageLine(img, horizontal_shift+1, horizontal_baseline-4, horizontal_shift+1, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-4, color_black);
    horizontal_shift = border_left + 4;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    horizontal_shift = border_left + 6;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    gdImageLine(img, horizontal_shift+4, horizontal_baseline-4, horizontal_shift+4, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-3, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-3, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+3, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+3, horizontal_baseline-3, color_black);
    horizontal_shift = border_left + 12;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline, color_black);
    return img;
}

canonical_original_code:
struct gdImageStruct *ngImageCreate(int x, int y)
{
    struct gdImageStruct *img;
    int i;
    int color_bg; int color_black;
    int graph_y;
    int gray_value; int color_gradient;
    int border_left; int border_right; int border_top; int border_bottom;
    int vertical_baseline; int vertical_shift;
    int horizontal_baseline; int horizontal_shift;
    border_left = 25;
    border_right = 5;
    border_top = 5;
    border_bottom = 20;
    img = gdImageCreateTrueColor(x, y);
    color_bg = gdImageColorAllocate(img, 255, 255, 255);
    gdImageFill(img, 0, 0, color_bg);
    gdImageColorTransparent(img, color_bg);
    graph_y = y - border_top - border_bottom - 2;
    for(i=0; i<=graph_y; i++) {
        gray_value = (int) 225 - (200 * ((double) i/graph_y));
        color_gradient = gdImageColorAllocateAlpha(img, gray_value, gray_value, gray_value, 0);
        gdImageLine(img, border_left+1, border_top + 1 + i, x - border_right - 1, border_top + 1 + i, color_gradient);
    }
    color_black = gdImageColorAllocateAlpha(img, 0, 0, 0, 0);
    gdImageRectangle(img, border_left, border_top, x-border_right, y-border_bottom, color_black);
    vertical_baseline = border_left - 5;
    horizontal_baseline = y-border_bottom + 9;
    vertical_shift = y - border_bottom;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 5;
    gdImageLine(img, vertical_baseline-3, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-3, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 10;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 15;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 20;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline-1, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-2, vertical_shift-1, vertical_baseline, vertical_shift-1, color_black);
    gdImageLine(img, vertical_baseline-3, vertical_shift-2, vertical_baseline-1, vertical_shift-2, color_black);
    gdImageLine(img, vertical_baseline-2, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-4, vertical_baseline-1, vertical_shift-4, color_black);
    vertical_shift = y - border_bottom - 24;
    gdImageLine(img, vertical_baseline-4, vertical_shift-2, vertical_baseline, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 28;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 33;
    gdImageLine(img, vertical_baseline-4, vertical_shift-1, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 37;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    horizontal_shift = border_left;
    gdImageLine(img, horizontal_shift+1, horizontal_baseline-4, horizontal_shift+1, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-4, color_black);
    horizontal_shift = border_left + 4;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    horizontal_shift = border_left + 6;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    gdImageLine(img, horizontal_shift+4, horizontal_baseline-4, horizontal_shift+4, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-3, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-3, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+3, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+3, horizontal_baseline-3, color_black);
    horizontal_shift = border_left + 12;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline, color_black);
    return img;
}

variable_types: x int

variable_types: y int

variable_types: struct gdImageStruct { unsigned char **pixels; int sx; int sy; int colorsTotal; int red[256]; int green[256]; int blue[256]; int open[256]; int transparent; int *polyInts; int polyAllocated; struct gdImageStruct *brush; struct gdImageStruct *tile; int brushColorMap[256]; int tileColorMap[256]; int styleLength; int stylePos; int *style; int interlace; int thick; int alpha[256]; int trueColor; int **tpixels; int alphaBlendingFlag; int saveAlphaFlag; int AA; int AA_color; int AA_dont_blend; int cx1; int cy1; int cx2; int cy2; unsigned int res_x; unsigned int res_y; int paletteQuantizationMethod; int paletteQuantizationSpeed; int paletteQuantizationMinQuality; int paletteQuantizationMaxQuality; enum gdInterpolationMethod { GD_DEFAULT=0, GD_BELL=1, GD_BESSEL=2, GD_BILINEAR_FIXED=3, GD_BICUBIC=4, GD_BICUBIC_FIXED=5, GD_BLACKMAN=6, GD_BOX=7, GD_BSPLINE=8, GD_CATMULLROM=9, GD_GAUSSIAN=10, GD_GENERALIZED_CUBIC=11, GD_HERMITE=12, GD_HAMMING=13, GD_HANNING=14, GD_MITCHELL=15, GD_NEAREST_NEIGHBOUR=16, GD_POWER=17, GD_QUADRATIC=18, GD_SINC=19, GD_TRIANGLE=20, GD_WEIGHTED4=21, GD_LINEAR=22, GD_METHOD_COUNT=23 } interpolation_id; double (*interpolation)(double); } *

user_defined_types: struct gdImageStruct { unsigned char **pixels; int sx; int sy; int colorsTotal; int red[256]; int green[256]; int blue[256]; int open[256]; int transparent; int *polyInts; int polyAllocated; struct gdImageStruct *brush; struct gdImageStruct *tile; int brushColorMap[256]; int tileColorMap[256]; int styleLength; int stylePos; int *style; int interlace; int thick; int alpha[256]; int trueColor; int **tpixels; int alphaBlendingFlag; int saveAlphaFlag; int AA; int AA_color; int AA_dont_blend; int cx1; int cy1; int cx2; int cy2; unsigned int res_x; unsigned int res_y; int paletteQuantizationMethod; int paletteQuantizationSpeed; int paletteQuantizationMinQuality; int paletteQuantizationMaxQuality; enum gdInterpolationMethod interpolation_id; double (*interpolation)(double); }


uiUsage

repo: sardylan/smlgr

decompiled_code:
int uiUsage()
{
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
return fprintf(stderr, " %s [<option> <value> ...]\n", smlgr_program_name);
}

canonical_decompiled_code:
int func0()
{
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
return fprintf(stderr, " %s [<option> <value> ...]\n", smlgr_program_name);
}

original_code:
void uiUsage()
{
    fprintf(stderr, "Usage:\n");
    fprintf(stderr, "    %s [<option> <value> ...]\n", smlgr_program_name);
}

return_type: void


uiVersion

decompiled_code:
size_t uiVersion()
{
return fwrite("SolarMax Logger\n", 1uLL, 0x10uLL, stderr);
}

canonical_decompiled_code:
size_t func1()
{
return fwrite("SolarMax Logger\n", 1uLL, 0x10uLL, stderr);
}

original_code:
void uiVersion()
{
    fprintf(stderr, "SolarMax Logger\n");
}


uiHelp

decompiled_code:
size_t uiHelp()
{
fwrite("SolarMax S3000 DB Logger\n", 1uLL, 0x19uLL, stderr);
fputc(10, stderr);
uiUsage();
fputc(10, stderr);
fwrite("Options list with default values:\n", 1uLL, 0x22uLL, stderr);
fputc(10, stderr);
fwrite(" -c | --config Config file (overwrite all other options)\n", 1uLL, 0x47uLL, stderr);
fputc(10, stderr);
fwrite(" -h | --help This message\n", 1uLL, 0x2AuLL, stderr);
fwrite(" -V | --version Print Version and exit\n", 1uLL, 0x34uLL, stderr);
fputc(10, stderr);
fwrite(" -q | --quiet Disable output (debug level 0)\n", 1uLL, 0x3CuLL, stderr);
fwrite(" -v | --verbose Verbose output (debug level 4)\n", 1uLL, 0x3CuLL, stderr);
fprintf(stderr, " -d | --debug Debug level (%d)\n", 2LL);
fwrite(" 0 DISABLE (quiet)\n", 1uLL, 0x2FuLL, stderr);
fwrite(" 1 ERROR\n", 1uLL, 0x25uLL, stderr);
fwrite(" 2 WARNING\n", 1uLL, 0x27uLL, stderr);
fwrite(" 3 INFO\n", 1uLL, 0x24uLL, stderr);
fwrite(" 4 DEBUG (verbose)\n", 1uLL, 0x2FuLL, stderr);
fputc(10, stderr);
fprintf(stderr, " -a | --inv-addr Inverter IP Address (%s)\n", "172.16.83.2");
fprintf(stderr, " -p | --inv-port Inverter TCP Port (%d)\n", 12345LL);
fprintf(stderr, " -n | --inv-num Inverter number (%d)\n", 1LL);
fputc(10, stderr);
fprintf(stderr, " -k | --query Logger query (%s)\n", "UDC;IDC;UL1;IL1;PAC;PRL;TKK;TNF;KDY;KLD");
fprintf(stderr, " -i | --interval Logger interval in seconds (%d)\n", 10LL);
fputc(10, stderr);
fprintf(stderr, " -s | --mysql-addr MySQL Server IP Address (%s)\n", "127.0.0.1");
fprintf(stderr, " -t | --mysql-port MySQL Server TCP port (%d)\n", 3306LL);
fprintf(stderr, " -u | --mysql-user MySQL Server Username (%s)\n", "smlgr");
fprintf(stderr, " -w | --mysql-password MySQL Server Password (%s)\n", "smlgr");
fprintf(stderr, " -b | --mysql-database MySQL Server Database name (%s)\n", "smlgr");
fputc(10, stderr);
fprintf(stderr, " -l | --mysql-table Database table name (%s)\n", "invdata");
fputc(10, stderr);
return fwrite("All outputs are on Standard Error.\n", 1uLL, 0x23uLL, stderr);
}

canonical_decompiled_code:
size_t func2()
{
fwrite("SolarMax S3000 DB Logger\n", 1uLL, 0x19uLL, stderr);
fputc(10, stderr);
func0();
fputc(10, stderr);
fwrite("Options list with default values:\n", 1uLL, 0x22uLL, stderr);
fputc(10, stderr);
fwrite(" -c | --config Config file (overwrite all other options)\n", 1uLL, 0x47uLL, stderr);
fputc(10, stderr);
fwrite(" -h | --help This message\n", 1uLL, 0x2AuLL, stderr);
fwrite(" -V | --version Print Version and exit\n", 1uLL, 0x34uLL, stderr);
fputc(10, stderr);
fwrite(" -q | --quiet Disable output (debug level 0)\n", 1uLL, 0x3CuLL, stderr);
fwrite(" -v | --verbose Verbose output (debug level 4)\n", 1uLL, 0x3CuLL, stderr);
fprintf(stderr, " -d | --debug Debug level (%d)\n", 2LL);
fwrite(" 0 DISABLE (quiet)\n", 1uLL, 0x2FuLL, stderr);
fwrite(" 1 ERROR\n", 1uLL, 0x25uLL, stderr);
fwrite(" 2 WARNING\n", 1uLL, 0x27uLL, stderr);
fwrite(" 3 INFO\n", 1uLL, 0x24uLL, stderr);
fwrite(" 4 DEBUG (verbose)\n", 1uLL, 0x2FuLL, stderr);
fputc(10, stderr);
fprintf(stderr, " -a | --inv-addr Inverter IP Address (%s)\n", "172.16.83.2");
fprintf(stderr, " -p | --inv-port Inverter TCP Port (%d)\n", 12345LL);
fprintf(stderr, " -n | --inv-num Inverter number (%d)\n", 1LL);
fputc(10, stderr);
fprintf(stderr, " -k | --query Logger query (%s)\n", "UDC;IDC;UL1;IL1;PAC;PRL;TKK;TNF;KDY;KLD");
fprintf(stderr, " -i | --interval Logger interval in seconds (%d)\n", 10LL);
fputc(10, stderr);
fprintf(stderr, " -s | --mysql-addr MySQL Server IP Address (%s)\n", "127.0.0.1");
fprintf(stderr, " -t | --mysql-port MySQL Server TCP port (%d)\n", 3306LL);
fprintf(stderr, " -u | --mysql-user MySQL Server Username (%s)\n", "smlgr");
fprintf(stderr, " -w | --mysql-password MySQL Server Password (%s)\n", "smlgr");
fprintf(stderr, " -b | --mysql-database MySQL Server Database name (%s)\n", "smlgr");
fputc(10, stderr);
fprintf(stderr, " -l | --mysql-table Database table name (%s)\n", "invdata");
fputc(10, stderr);
return fwrite("All outputs are on Standard Error.\n", 1uLL, 0x23uLL, stderr);
}

original_code:
void uiHelp()
{
    fprintf(stderr, "SolarMax S3000 DB Logger\n");
    fprintf(stderr, "\n");
    uiUsage();
    fprintf(stderr, "\n");
    fprintf(stderr, "Options list with default values:\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "    -c | --config            Config file (overwrite all other options)\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "    -h | --help              This message\n");
    fprintf(stderr, "    -V | --version           Print Version and exit\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "    -q | --quiet             Disable output (debug level 0)\n");
    fprintf(stderr, "    -v | --verbose           Verbose output (debug level 4)\n");
    fprintf(stderr, "    -d | --debug             Debug level (%d)\n", 2);
    fprintf(stderr, "                             0 DISABLE (quiet)\n");
    fprintf(stderr, "                             1 ERROR\n");
    fprintf(stderr, "                             2 WARNING\n");
    fprintf(stderr, "                             3 INFO\n");
    fprintf(stderr, "                             4 DEBUG (verbose)\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "    -a | --inv-addr          Inverter IP Address (%s)\n", "172.16.83.2");
    fprintf(stderr, "    -p | --inv-port          Inverter TCP Port (%d)\n", 12345);
    fprintf(stderr, "    -n | --inv-num           Inverter number (%d)\n", 1);
    fprintf(stderr, "\n");
    fprintf(stderr, "    -k | --query             Logger query (%s)\n", "UDC;IDC;UL1;IL1;PAC;PRL;TKK;TNF;KDY;KLD");
    fprintf(stderr, "    -i | --interval          Logger interval in seconds (%d)\n", 10);
    fprintf(stderr, "\n");
    fprintf(stderr, "    -s | --mysql-addr        MySQL Server IP Address (%s)\n", "127.0.0.1");
    fprintf(stderr, "    -t | --mysql-port        MySQL Server TCP port (%d)\n", 3306);
    fprintf(stderr, "    -u | --mysql-user        MySQL Server Username (%s)\n", "smlgr");
    fprintf(stderr, "    -w | --mysql-password    MySQL Server Password (%s)\n", "smlgr");
    fprintf(stderr, "    -b | --mysql-database    MySQL Server Database name (%s)\n", "smlgr");
    fprintf(stderr, "\n");
    fprintf(stderr, "    -l | --mysql-table       Database table name (%s)\n", "invdata");
    fprintf(stderr, "\n");
    fprintf(stderr, "All outputs are on Standard Error.\n");
}


uiMessage

decompiled_code:
int uiMessage(int a1, const char *a2, ...)
{
int result; // eax
struct tm *v3; // rax
time_t timer; // [rsp+8h] [rbp-100h] BYREF
char s[24]; // [rsp+10h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+28h] [rbp-E0h] BYREF

result = conf;
if ( *conf >= a1 )
{
timer = time(0LL);
v3 = localtime(&timer);
strftime(s, 0x14uLL, "%Y-%m-%d %H:%M:%S", v3);
va_start(arg, a2);
switch ( a1 )
{
case 1:
fprintf(stderr, "%s [ERROR] ", s);
break;
case 2:
fprintf(stderr, "%s [WARN] ", s);
break;
case 3:
fprintf(stderr, "%s [INFO] ", s);
break;
case 4:
fprintf(stderr, "%s [DEBUG] ", s);
break;
}
vfprintf(stderr, a2, arg);
result = fputc(10, stderr);
}
return result;
}

canonical_decompiled_code:
int func3(int a1, const char *a2, ...)
{
int result; // eax
struct tm *v3; // rax
time_t timer; // [rsp+8h] [rbp-100h] BYREF
char s[24]; // [rsp+10h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+28h] [rbp-E0h] BYREF

result = conf;
if ( *conf >= a1 )
{
timer = time(0LL);
v3 = localtime(&timer);
strftime(s, 0x14uLL, "%Y-%m-%d %H:%M:%S", v3);
va_start(arg, a2);
switch ( a1 )
{
case 1:
fprintf(stderr, "%s [ERROR] ", s);
break;
case 2:
fprintf(stderr, "%s [WARN] ", s);
break;
case 3:
fprintf(stderr, "%s [INFO] ", s);
break;
case 4:
fprintf(stderr, "%s [DEBUG] ", s);
break;
}
vfprintf(stderr, a2, arg);
result = fputc(10, stderr);
}
return result;
}

original_code:
void uiMessage(int level, char *text, ...)
{
    va_list args;
    char datetime[20];
    time_t rawtime;
    struct tm *timeinfo;
    if(level <= conf->debug_level) {
        rawtime = time(((void *)0));
        timeinfo = localtime(&rawtime);
        strftime(datetime, 20, "%Y-%m-%d %H:%M:%S", timeinfo);
        __builtin_va_start(args,text);
        if(level == 1)
            fprintf(stderr, "%s [ERROR] ", datetime);
        if(level == 2)
            fprintf(stderr, "%s [WARN]  ", datetime);
        if(level == 3)
            fprintf(stderr, "%s [INFO]  ", datetime);
        if(level == 4)
            fprintf(stderr, "%s [DEBUG] ", datetime);
        vfprintf(stderr, text, args);
        fprintf(stderr, "\n");
        __builtin_va_end(args);
    }
}

canonical_original_code:
void uiMessage(int level, char *text, ...)
{
    __builtin_va_list args;
    char datetime[20];
    long rawtime;
    struct tm *timeinfo;
    if(level <= conf->debug_level) {
        rawtime = time(((void *)0));
        timeinfo = localtime(&rawtime);
        strftime(datetime, 20, "%Y-%m-%d %H:%M:%S", timeinfo);
        __builtin_va_start(args,text);
        if(level == 1)
            fprintf(stderr, "%s [ERROR] ", datetime);
        if(level == 2)
            fprintf(stderr, "%s [WARN]  ", datetime);
        if(level == 3)
            fprintf(stderr, "%s [INFO]  ", datetime);
        if(level == 4)
            fprintf(stderr, "%s [DEBUG] ", datetime);
        vfprintf(stderr, text, args);
        fprintf(stderr, "\n");
        __builtin_va_end(args);
    }
}

variable_types: level int

variable_types:
text
char *

variable_types:
datetime
char [20]

variable_types: rawtime long

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


uiError

decompiled_code:
int __fastcall uiError(const char *a1, unsigned int a2, const char *a3)
{
return uiMessage(1, "%s (%d): %s", a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func4(const char *a1, unsigned int a2, const char *a3)
{
return func3(1, "%s (%d): %s", a1, a2, a3);
}

original_code:
void uiError(char *text, int errnum, char *errtext)
{
    uiMessage(1, "%s (%d): %s", text, errnum, errtext);
}

variable_types: errnum int

variable_types:
errtext
char *


smlgr

decompiled_code:
void __noreturn smlgr()
{
__int64 v0; // r13
unsigned int v1; // eax
void *v2; // rbp
void *v3; // r12
_BYTE *v4; // r12

while ( 1 )
{
v2 = malloc(4uLL);
uiMessage(3LL, "Creating socket");
if ( (unsigned int)sckCreate(v2, *(_QWORD *)(conf + 8), *(unsigned int *)(conf + 16)) )
{
uiMessage(1LL, "Error creating socket.");
}
else
{
uiMessage(3LL, "Creating inverter query string");
v3 = (void *)strPrepare(*(_QWORD *)(conf + 24));
uiMessage(3LL, "Sending query");
sckSend(v2, v3);
free(v3);
uiMessage(3LL, "Receiving response");
v4 = (_BYTE *)sckRecv(v2);
if ( *v4 )
{
uiMessage(3LL, "Parsing data");
v0 = strParse(v4);
v1 = infosCounting(v0);
uiMessage(4LL, "%d elements on response", v1);
uiMessage(3LL, "Adding data to DB");
sqlSave(v0);
uiMessage(3LL, "Freeing memory");
infosFree(v0);
}
else
{
uiMessage(2LL, "Inverter doesn't answer");
}
free(v4);
uiMessage(3LL, "Destroying socket");
}
sckDestroy(v2);
free(v2);
uiMessage(3LL, "Sleeping");
sleep(*(_DWORD *)(conf + 32));
}
}

canonical_decompiled_code:
void __noreturn func0()
{
__int64 v0; // r13
unsigned int v1; // eax
void *v2; // rbp
void *v3; // r12
_BYTE *v4; // r12

while ( 1 )
{
v2 = malloc(4uLL);
uiMessage(3LL, "Creating socket");
if ( (unsigned int)sckCreate(v2, *(_QWORD *)(conf + 8), *(unsigned int *)(conf + 16)) )
{
uiMessage(1LL, "Error creating socket.");
}
else
{
uiMessage(3LL, "Creating inverter query string");
v3 = (void *)strPrepare(*(_QWORD *)(conf + 24));
uiMessage(3LL, "Sending query");
sckSend(v2, v3);
free(v3);
uiMessage(3LL, "Receiving response");
v4 = (_BYTE *)sckRecv(v2);
if ( *v4 )
{
uiMessage(3LL, "Parsing data");
v0 = strParse(v4);
v1 = infosCounting(v0);
uiMessage(4LL, "%d elements on response", v1);
uiMessage(3LL, "Adding data to DB");
sqlSave(v0);
uiMessage(3LL, "Freeing memory");
infosFree(v0);
}
else
{
uiMessage(2LL, "Inverter doesn't answer");
}
free(v4);
uiMessage(3LL, "Destroying socket");
}
sckDestroy(v2);
free(v2);
uiMessage(3LL, "Sleeping");
sleep(*(_DWORD *)(conf + 32));
}
}

original_code:
void smlgr()
{
    int *sock;
    int sock_ret;
    char *query;
    char *response;
    infos *data;
    while(1) {
        sock = (int *) malloc(sizeof(int));
        uiMessage(3, "Creating socket");
        sock_ret = sckCreate(sock, conf->inv_addr, conf->inv_port);
        if(sock_ret == 0) {
            uiMessage(3, "Creating inverter query string");
            query = strPrepare(conf->lgr_query);
            uiMessage(3, "Sending query");
            sckSend(sock, query);
            free(query);
            uiMessage(3, "Receiving response");
            response = sckRecv(sock);
            if(strlen(response) > 0) {
                uiMessage(3, "Parsing data");
                data = strParse(response);
                uiMessage(4, "%d elements on response", infosCounting(data));
                uiMessage(3, "Adding data to DB");
                sqlSave(data);
                uiMessage(3, "Freeing memory");
                infosFree(data);
            } else {
                uiMessage(2, "Inverter doesn't answer");
            }
            free(response);
            uiMessage(3, "Destroying socket");
        } else {
            uiMessage(1, "Error creating socket.");
        }
        sckDestroy(sock);
        free(sock);
        uiMessage(3, "Sleeping");
        sleep(conf->lgr_interval);
    }
    cfgFree();
}

canonical_original_code:
void smlgr()
{
    int *sock;
    int sock_ret;
    char *query;
    char *response;
    struct infos_s *data;
    while(1) {
        sock = (int *) malloc(sizeof(int));
        uiMessage(3, "Creating socket");
        sock_ret = sckCreate(sock, conf->inv_addr, conf->inv_port);
        if(sock_ret == 0) {
            uiMessage(3, "Creating inverter query string");
            query = strPrepare(conf->lgr_query);
            uiMessage(3, "Sending query");
            sckSend(sock, query);
            free(query);
            uiMessage(3, "Receiving response");
            response = sckRecv(sock);
            if(strlen(response) > 0) {
                uiMessage(3, "Parsing data");
                data = strParse(response);
                uiMessage(4, "%d elements on response", infosCounting(data));
                uiMessage(3, "Adding data to DB");
                sqlSave(data);
                uiMessage(3, "Freeing memory");
                infosFree(data);
            } else {
                uiMessage(2, "Inverter doesn't answer");
            }
            free(response);
            uiMessage(3, "Destroying socket");
        } else {
            uiMessage(1, "Error creating socket.");
        }
        sckDestroy(sock);
        free(sock);
        uiMessage(3, "Sleeping");
        sleep(conf->lgr_interval);
    }
    cfgFree();
}

variable_types:
sock
int *

variable_types:
query
char *

variable_types:
response
char *

variable_types: struct infos_s { char *param; char *value; struct infos_s *next; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
smlgr_program_name = (__int64)*argv;
cfgInit(argc, argv, envp);
if ( (unsigned int)cfgParse((unsigned int)argc, argv) )
{
cfgPrint();
smlgr();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
smlgr_program_name = (__int64)*argv;
cfgInit(argc, argv, envp);
if ( (unsigned int)cfgParse((unsigned int)argc, argv) )
{
cfgPrint();
func0();
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
    smlgr_program_name = argv[0];
    cfgInit();
    if(cfgParse(argc, argv)) {
        cfgPrint();
        smlgr();
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


sckCreate

decompiled_code:
__int64 __fastcall sckCreate(int *a1, const char *a2, unsigned int a3)
{
__int16 v3; // bx
int v4; // eax
unsigned int v5; // er12
void *v6; // rdx
int *v8; // rbx
char *v9; // rax
int *v10; // rbx
char *v11; // rax
int *v12; // rbx
char *v13; // rax
__m128i v14; // [rsp+0h] [rbp-48h] BYREF
__int64 optval[7]; // [rsp+10h] [rbp-38h] BYREF

v3 = a3;
uiMessage(4LL, "Creating socket %s:%d", a2, a3);
optval[0] = 3LL;
optval[1] = 0LL;
v4 = socket(2, 1, 0);
*a1 = v4;
v5 = v4;
if ( v4 == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
uiError("Error creating socket or setting timeout", (unsigned int)*v10, v11);
}
else
{
if ( setsockopt(v4, 1, 20, optval, 0x10u) == -1 && setsockopt(*a1, 1, 21, optval, 0x10u) == -1 )
v14 = _mm_load_si128((const __m128i *)&LC4);
v14.m128i_i16[0] = 2;
v14.m128i_i16[1] = _bswap_16(v3);
if ( inet_pton(2, a2, v6) <= 0 )
{
v5 = -1;
v8 = _errno_location();
v9 = strerror(*v8);
uiError("Error setting IP address", (unsigned int)*v8, v9);
}
else
{
v5 = connect(*a1, (const struct sockaddr *)&v14, 0x10u);
if ( v5 )
{
v5 = -1;
v12 = _errno_location();
v13 = strerror(*v12);
uiError("Error connecting socket", (unsigned int)*v12, v13);
}
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, const char *a2, unsigned int a3)
{
__int16 v3; // bx
int v4; // eax
unsigned int v5; // er12
void *v6; // rdx
int *v8; // rbx
char *v9; // rax
int *v10; // rbx
char *v11; // rax
int *v12; // rbx
char *v13; // rax
__m128i v14; // [rsp+0h] [rbp-48h] BYREF
__int64 optval[7]; // [rsp+10h] [rbp-38h] BYREF

v3 = a3;
uiMessage(4LL, "Creating socket %s:%d", a2, a3);
optval[0] = 3LL;
optval[1] = 0LL;
v4 = socket(2, 1, 0);
*a1 = v4;
v5 = v4;
if ( v4 == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
uiError("Error creating socket or setting timeout", (unsigned int)*v10, v11);
}
else
{
if ( setsockopt(v4, 1, 20, optval, 0x10u) == -1 && setsockopt(*a1, 1, 21, optval, 0x10u) == -1 )
v14 = _mm_load_si128((const __m128i *)&LC4);
v14.m128i_i16[0] = 2;
v14.m128i_i16[1] = func0(v3);
if ( inet_pton(2, a2, v6) <= 0 )
{
v5 = -1;
v8 = _errno_location();
v9 = strerror(*v8);
uiError("Error setting IP address", (unsigned int)*v8, v9);
}
else
{
v5 = connect(*a1, (const struct sockaddr *)&v14, 0x10u);
if ( v5 )
{
v5 = -1;
v12 = _errno_location();
v13 = strerror(*v12);
uiError("Error connecting socket", (unsigned int)*v12, v13);
}
}
}
return v5;
}

original_code:
int sckCreate(int *sock, char *addr, int port)
{
    int ret;
    struct sockaddr_in serv_addr;
    struct timeval timeout;
    ret = -1;
    uiMessage(4, "Creating socket %s:%d", addr, port);
    timeout.tv_sec = 3;
    timeout.tv_usec = 0;
    *sock = socket(2, SOCK_STREAM, 0);
    if(*sock != -1) {
        if(setsockopt(*sock, 1, 20, (char *) &timeout, sizeof(timeout)) == -1)
        if(setsockopt(*sock, 1, 21, (char *) &timeout, sizeof(timeout)) == -1)
        memset(&serv_addr, '0', sizeof(serv_addr));
        serv_addr.sin_family = 2;
        serv_addr.sin_port = htons(port);
        if(inet_pton(2, addr, &serv_addr.sin_addr) > 0)
            if(connect(*sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) == 0)
                ret = 0;
            else
                uiError("Error connecting socket", (*__errno_location ()), strerror((*__errno_location ())));
        else
            uiError("Error setting IP address", (*__errno_location ()), strerror((*__errno_location ())));
    } else
        uiError("Error creating socket or setting timeout", (*__errno_location ()), strerror((*__errno_location ())));
    return ret;
}

variable_types:
addr
char *

variable_types: port int

variable_types: ret int

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

variable_types: struct timeval { long tv_sec; long tv_usec; }

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

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


sckDestroy

decompiled_code:
int __fastcall sckDestroy(int *a1)
{
return close(*a1);
}

canonical_decompiled_code:
int __fastcall func2(int *a1)
{
return close(*a1);
}

original_code:
void sckDestroy(int *sock)
{
    close(*sock);
}


sckSend

decompiled_code:
ssize_t __fastcall sckSend(int *a1, const char *a2)
{
size_t v2; // rax

uiMessage(4LL, ">>> %s", a2);
v2 = strlen(a2);
return write(*a1, a2, v2);
}

canonical_decompiled_code:
ssize_t __fastcall func3(int *a1, const char *a2)
{
size_t v2; // rax

uiMessage(4LL, ">>> %s", a2);
v2 = strlen(a2);
return write(*a1, a2, v2);
}

original_code:
void sckSend(int *sock, char *buff)
{
    uiMessage(4, ">>> %s", buff);
    write(*sock, buff, strlen(buff));
}

variable_types:
buff
char *


decToHex

decompiled_code:
char *__fastcall decToHex(unsigned int a1, int a2)
{
char *v2; // rax
char *v3; // r12
char *v4; // rax
char *result; // rax
char s[48]; // [rsp+8h] [rbp-30h] BYREF

sprintf(s, "%%%dX", (unsigned int)a2);
v2 = (char *)calloc(a2 + 1, 1uLL);
v3 = v2;
if ( a2 <= 0 )
{
v2[a2] = 0;
sprintf(v2, s, a1);
result = v3;
}
else
{
memset(v2, 48, a2);
v3[a2] = 0;
sprintf(v3, s, a1);
v4 = v3;
do
{
if ( *v4 == 32 )
*v4 = 48;
++v4;
}
while ( &v3[a2] != v4 );
result = v3;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1, int a2)
{
char *v2; // rax
char *v3; // r12
char *v4; // rax
char *result; // rax
char s[48]; // [rsp+8h] [rbp-30h] BYREF

sprintf(s, "%%%dX", (unsigned int)a2);
v2 = (char *)calloc(a2 + 1, 1uLL);
v3 = v2;
if ( a2 <= 0 )
{
v2[a2] = 0;
sprintf(v2, s, a1);
result = v3;
}
else
{
memset(v2, 48, a2);
v3[a2] = 0;
sprintf(v3, s, a1);
v4 = v3;
do
{
if ( *v4 == 32 )
*v4 = 48;
++v4;
}
while ( &v3[a2] != v4 );
result = v3;
}
return result;
}

original_code:
char *decToHex(int input, int dim)
{
    char *ret;
    char pattern[8];
    int i;
    sprintf(pattern, "%%%dX", dim);
    ret = (char *) calloc(dim+1, sizeof(char));
    for(i=0; i<dim; i++)
        *(ret + i) = '0';
    *(ret + dim) = '\0';
    sprintf(ret, pattern, input);
    for(i=0; i<dim; i++)
        if(*(ret+i) == ' ')
            *(ret+i) = '0';
    return ret;
}

variable_types: input int

variable_types: dim int

variable_types:
ret
char *

variable_types:
pattern
char [8]

variable_types: i int

return_type: char *


decompiled_code:
char *__fastcall checksum16(const char *a1)
{
int v1; // ebp
size_t v2; // rax
const char *v3; // rcx
int v4; // eax

v1 = 0;
if ( a1 )
{
v2 = strlen(a1);
if ( v2 )
{
v3 = &a1[v2];
do
{
v4 = *a1++;
v1 = (v1 + v4) % 0x10000;
}
while ( v3 != a1 );
}
}
return decToHex(v1, 4);
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
int v1; // ebp
size_t v2; // rax
const char *v3; // rcx
int v4; // eax

v1 = 0;
if ( a1 )
{
v2 = strlen(a1);
if ( v2 )
{
v3 = &a1[v2];
do
{
v4 = *a1++;
v1 = (v1 + v4) % 0x10000;
}
while ( v3 != a1 );
}
}
return func0(v1, 4);
}

original_code:
char *checksum16(char *input)
{
    char *ret;
    int i;
    size_t ln;
    int sum;
    sum = 0;
    if(input != ((void *)0)) {
        ln = strlen(input);
        for(i=0; i<ln; i++) {
            sum += input[i];
            sum %= (int) pow(2, 16);
        }
    }
    ret = decToHex(sum, 4);
    return ret;
}

canonical_original_code:
char *checksum16(char *input)
{
    char *ret;
    int i;
    unsigned long ln;
    int sum;
    sum = 0;
    if(input != ((void *)0)) {
        ln = strlen(input);
        for(i=0; i<ln; i++) {
            sum += input[i];
            sum %= (int) pow(2, 16);
        }
    }
    ret = decToHex(sum, 4);
    return ret;
}

variable_types:
input
char *

variable_types:
ln
unsigned long

variable_types: sum int


strPrepare

decompiled_code:
char *__fastcall strPrepare(char *s)
{
size_t v1; // rax
int v2; // ebp
char *v3; // r12
char *v4; // r14
char *v5; // r13
char *v6; // rbp
char v8[1064]; // [rsp+0h] [rbp-428h] BYREF

if ( s && (uiMessage(4LL, "Query to prepare: %s", s), v1 = strlen(s), v2 = v1, v1 > 2) )
{
v3 = (char *)calloc(v1 + 20, 1uLL);
v4 = decToHex(*(_DWORD *)(conf + 20LL), 2);
v5 = decToHex(v2 + 19, 2);
sprintf(v8, "FB;%s;%s|64:%s|", v4, v5, s);
v6 = checksum16(v8);
sprintf(v3, "{%s%s}", v8, v6);
free(v4);
free(v5);
free(v6);
}
else
{
v3 = 0LL;
}
uiMessage(4LL, "Query prepared: %s", v3);
return v3;
}

canonical_decompiled_code:
char *__fastcall func2(char *s)
{
size_t v1; // rax
int v2; // ebp
char *v3; // r12
char *v4; // r14
char *v5; // r13
char *v6; // rbp
char v8[1064]; // [rsp+0h] [rbp-428h] BYREF

if ( s && (uiMessage(4LL, "Query to prepare: %s", s), v1 = strlen(s), v2 = v1, v1 > 2) )
{
v3 = (char *)calloc(v1 + 20, 1uLL);
v4 = func0(*(_DWORD *)(conf + 20LL), 2);
v5 = func0(v2 + 19, 2);
sprintf(v8, "FB;%s;%s|64:%s|", v4, v5, s);
v6 = func1(v8);
sprintf(v3, "{%s%s}", v8, v6);
free(v4);
free(v5);
free(v6);
}
else
{
v3 = 0LL;
}
uiMessage(4LL, "Query prepared: %s", v3);
return v3;
}

original_code:
char *strPrepare(char *query)
{
    char *ret;
    size_t ln;
    char *inv_id;
    char *len;
    char *checksum;
    char tmp[1024];
    ret = ((void *)0);
    if(query != ((void *)0)) {
        uiMessage(4, "Query to prepare: %s", query);
        ln = strlen(query);
        if(ln >= 3) {
            ret = (char *) calloc(13 + ln + 6 + 1, sizeof(char));
            inv_id = decToHex(conf->inv_num, 2);
            len = decToHex(13 + ln + 6, 2);
            sprintf(tmp, "FB;%s;%s|64:%s|", inv_id, len, query);
            checksum = checksum16(tmp);
            sprintf(ret, "{%s%s}", tmp, checksum);
            free(inv_id);
            free(len);
            free(checksum);
        }
    }
    uiMessage(4, "Query prepared: %s", ret);
    return ret;
}

canonical_original_code:
char *strPrepare(char *query)
{
    char *ret;
    unsigned long ln;
    char *inv_id;
    char *len;
    char *checksum;
    char tmp[1024];
    ret = ((void *)0);
    if(query != ((void *)0)) {
        uiMessage(4, "Query to prepare: %s", query);
        ln = strlen(query);
        if(ln >= 3) {
            ret = (char *) calloc(13 + ln + 6 + 1, sizeof(char));
            inv_id = decToHex(conf->inv_num, 2);
            len = decToHex(13 + ln + 6, 2);
            sprintf(tmp, "FB;%s;%s|64:%s|", inv_id, len, query);
            checksum = checksum16(tmp);
            sprintf(ret, "{%s%s}", tmp, checksum);
            free(inv_id);
            free(len);
            free(checksum);
        }
    }
    uiMessage(4, "Query prepared: %s", ret);
    return ret;
}

variable_types:
query
char *

variable_types:
len
char *

variable_types:
checksum
char *

variable_types:
tmp
char [1024]


infosPrint

decompiled_code:
int __fastcall infosPrint(__int64 a1)
{
__int64 v1; // rbx
const char *i; // rsi
int result; // eax

v1 = *(_QWORD *)(a1 + 16);
for ( i = *(const char **)v1; **(_BYTE **)v1; i = *(const char **)v1 )
{
result = printf("%s = %s\n", i, *(const char **)(v1 + 8));
v1 = *(_QWORD *)(v1 + 16);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
const char *i; // rsi
int result; // eax

v1 = *(_QWORD *)(a1 + 16);
for ( i = *(const char **)v1; **(_BYTE **)v1; i = *(const char **)v1 )
{
result = printf("%s = %s\n", i, *(const char **)(v1 + 8));
v1 = *(_QWORD *)(v1 + 16);
}
return result;
}

original_code:
void infosPrint(infos *input)
{
    input = input->next;
    while(strlen(input->param) > 0) {
        printf("%s = %s\n", input->param, input->value);
        input = input->next;
    }
}

canonical_original_code:
void infosPrint(struct infos_s *input)
{
    input = input->next;
    while(strlen(input->param) > 0) {
        printf("%s = %s\n", input->param, input->value);
        input = input->next;
    }
}

variable_types: struct infos_s { char *param; char *value; struct infos_s *next; } *


infosCounting

decompiled_code:
__int64 __fastcall infosCounting(__int64 a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *(_QWORD *)(a1 + 16);
for ( i = 0; **(_BYTE **)v1; ++i )
v1 = *(_QWORD *)(v1 + 16);
return i;
}

original_code:
int infosCounting(infos *input)
{
    int ret;
    input = input->next;
    ret = 0;
    while(strlen(input->param) > 0) {
        ret++;
        input = input->next;
    }
    return ret;
}

canonical_original_code:
int infosCounting(struct infos_s *input)
{
    int ret;
    input = input->next;
    ret = 0;
    while(strlen(input->param) > 0) {
        ret++;
        input = input->next;
    }
    return ret;
}

variable_types: ret int

user_defined_types: struct infos_s { char *param; char *value; struct infos_s *next; }


infosFree

decompiled_code:
void __fastcall infosFree(void *ptr)
{
void **v1; // rbp
void **v3; // rdi

v1 = (void **)*((_QWORD *)ptr + 2);
if ( ptr != v1 )
{
v1 = (void **)ptr;
do
{
free(*v1);
free(v1[1]);
v3 = v1;
v1 = (void **)v1[2];
free(v3);
}
while ( v1[2] != ptr );
}
free(*v1);
free(v1[1]);
free(v1);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void **v1; // rbp
void **v3; // rdi

v1 = (void **)*((_QWORD *)ptr + 2);
if ( ptr != v1 )
{
v1 = (void **)ptr;
do
{
free(*v1);
free(v1[1]);
v3 = v1;
v1 = (void **)v1[2];
free(v3);
}
while ( v1[2] != ptr );
}
free(*v1);
free(v1[1]);
free(v1);
}

original_code:
void infosFree(infos *input)
{
    infos *prev;
    infos *first;
    first = input;
    while(input->next != first) {
        free(input->param);
        free(input->value);
        prev = input;
        input = input->next;
        free(prev);
    }
    free(input->param);
    free(input->value);
    free(input);
}

canonical_original_code:
void infosFree(struct infos_s *input)
{
    struct infos_s *prev;
    struct infos_s *first;
    first = input;
    while(input->next != first) {
        free(input->param);
        free(input->value);
        prev = input;
        input = input->next;
        free(prev);
    }
    free(input->param);
    free(input->value);
    free(input);
}


cfgInit

original_code:
void cfgInit()
{
    int ln;
    conf = (cfg *) malloc(sizeof(cfg));
    conf->debug_level = 2;
    ln = strlen("172.16.83.2") + 1;
    conf->inv_addr = (char *) calloc(sizeof(char), ln);
    strcpy(conf->inv_addr, "172.16.83.2");
    conf->inv_port = 12345;
    conf->inv_num = 1;
    ln = strlen("UDC;IDC;UL1;IL1;PAC;PRL;TKK;TNF;KDY;KLD") + 1;
    conf->lgr_query = (char *) calloc(sizeof(char), ln);
    strcpy(conf->lgr_query, "UDC;IDC;UL1;IL1;PAC;PRL;TKK;TNF;KDY;KLD");
    conf->lgr_interval = 10;
    ln = strlen("127.0.0.1") + 1;
    conf->mysql_addr = (char *) calloc(sizeof(char), ln);
    strcpy(conf->mysql_addr, "127.0.0.1");
    conf->mysql_port = 3306;
    ln = strlen("smlgr") + 1;
    conf->mysql_user = (char *) calloc(sizeof(char), ln);
    strcpy(conf->mysql_user, "smlgr");
    ln = strlen("smlgr") + 1;
    conf->mysql_password = (char *) calloc(sizeof(char), ln);
    strcpy(conf->mysql_password, "smlgr");
    ln = strlen("smlgr") + 1;
    conf->mysql_database = (char *) calloc(sizeof(char), ln);
    strcpy(conf->mysql_database, "smlgr");
    ln = strlen("invdata") + 1;
    conf->mysql_table = (char *) calloc(sizeof(char), ln);
    strcpy(conf->mysql_table, "invdata");
}

canonical_original_code:
void cfgInit()
{
    int ln;
    conf = (struct cfg_s *) malloc(sizeof(cfg));
    conf->debug_level = 2;
    ln = strlen("172.16.83.2") + 1;
    conf->inv_addr = (char *) calloc(sizeof(char), ln);
    strcpy(conf->inv_addr, "172.16.83.2");
    conf->inv_port = 12345;
    conf->inv_num = 1;
    ln = strlen("UDC;IDC;UL1;IL1;PAC;PRL;TKK;TNF;KDY;KLD") + 1;
    conf->lgr_query = (char *) calloc(sizeof(char), ln);
    strcpy(conf->lgr_query, "UDC;IDC;UL1;IL1;PAC;PRL;TKK;TNF;KDY;KLD");
    conf->lgr_interval = 10;
    ln = strlen("127.0.0.1") + 1;
    conf->mysql_addr = (char *) calloc(sizeof(char), ln);
    strcpy(conf->mysql_addr, "127.0.0.1");
    conf->mysql_port = 3306;
    ln = strlen("smlgr") + 1;
    conf->mysql_user = (char *) calloc(sizeof(char), ln);
    strcpy(conf->mysql_user, "smlgr");
    ln = strlen("smlgr") + 1;
    conf->mysql_password = (char *) calloc(sizeof(char), ln);
    strcpy(conf->mysql_password, "smlgr");
    ln = strlen("smlgr") + 1;
    conf->mysql_database = (char *) calloc(sizeof(char), ln);
    strcpy(conf->mysql_database, "smlgr");
    ln = strlen("invdata") + 1;
    conf->mysql_table = (char *) calloc(sizeof(char), ln);
    strcpy(conf->mysql_table, "invdata");
}

variable_types: ln int

user_defined_types: struct cfg_s { int debug_level; char *inv_addr; int inv_port; int inv_num; char *lgr_query; int lgr_interval; char *mysql_addr; int mysql_port; char *mysql_user; char *mysql_password; char *mysql_database; char *mysql_table; }


cfgPrint

decompiled_code:
__int64 cfgPrint()
{
uiMessage(3LL, "debug_level = %d", *(unsigned int *)conf);
uiMessage(3LL, "inv_addr = %s", *((const char **)conf + 1));
uiMessage(3LL, "inv_port = %d", *((unsigned int *)conf + 4));
uiMessage(3LL, "inv_num = %d", *((unsigned int *)conf + 5));
uiMessage(3LL, "lgr_query = %s", *((const char **)conf + 3));
uiMessage(3LL, "lgr_interval = %d", *((unsigned int *)conf + 8));
uiMessage(3LL, "mysql_addr = %s", *((const char **)conf + 5));
uiMessage(3LL, "mysql_port = %d", *((unsigned int *)conf + 12));
uiMessage(3LL, "mysql_user = %s", *((const char **)conf + 7));
uiMessage(3LL, "mysql_password = %s", *((const char **)conf + 8));
uiMessage(3LL, "mysql_database = %s", *((const char **)conf + 9));
return uiMessage(3LL, "mysql_table = %s", *((const char **)conf + 10));
}

canonical_decompiled_code:
__int64 func1()
{
uiMessage(3LL, "debug_level = %d", *(unsigned int *)conf);
uiMessage(3LL, "inv_addr = %s", *((const char **)conf + 1));
uiMessage(3LL, "inv_port = %d", *((unsigned int *)conf + 4));
uiMessage(3LL, "inv_num = %d", *((unsigned int *)conf + 5));
uiMessage(3LL, "lgr_query = %s", *((const char **)conf + 3));
uiMessage(3LL, "lgr_interval = %d", *((unsigned int *)conf + 8));
uiMessage(3LL, "mysql_addr = %s", *((const char **)conf + 5));
uiMessage(3LL, "mysql_port = %d", *((unsigned int *)conf + 12));
uiMessage(3LL, "mysql_user = %s", *((const char **)conf + 7));
uiMessage(3LL, "mysql_password = %s", *((const char **)conf + 8));
uiMessage(3LL, "mysql_database = %s", *((const char **)conf + 9));
return uiMessage(3LL, "mysql_table = %s", *((const char **)conf + 10));
}

original_code:
void cfgPrint()
{
    uiMessage(3, "debug_level = %d", conf->debug_level);
    uiMessage(3, "inv_addr = %s", conf->inv_addr);
    uiMessage(3, "inv_port = %d", conf->inv_port);
    uiMessage(3, "inv_num = %d", conf->inv_num);
    uiMessage(3, "lgr_query = %s", conf->lgr_query);
    uiMessage(3, "lgr_interval = %d", conf->lgr_interval);
    uiMessage(3, "mysql_addr = %s", conf->mysql_addr);
    uiMessage(3, "mysql_port = %d", conf->mysql_port);
    uiMessage(3, "mysql_user = %s", conf->mysql_user);
    uiMessage(3, "mysql_password = %s", conf->mysql_password);
    uiMessage(3, "mysql_database = %s", conf->mysql_database);
    uiMessage(3, "mysql_table = %s", conf->mysql_table);
}


cfgFree

decompiled_code:
void cfgFree()
{
free(*((void **)conf + 1));
free(*((void **)conf + 3));
free(*((void **)conf + 5));
free(*((void **)conf + 7));
free(*((void **)conf + 8));
free(*((void **)conf + 9));
free(*((void **)conf + 10));
free(conf);
}

canonical_decompiled_code:
void func2()
{
free(*((void **)conf + 1));
free(*((void **)conf + 3));
free(*((void **)conf + 5));
free(*((void **)conf + 7));
free(*((void **)conf + 8));
free(*((void **)conf + 9));
free(*((void **)conf + 10));
free(conf);
}

original_code:
void cfgFree()
{
    free(conf->inv_addr);
    free(conf->lgr_query);
    free(conf->mysql_addr);
    free(conf->mysql_user);
    free(conf->mysql_password);
    free(conf->mysql_database);
    free(conf->mysql_table);
    free(conf);
}


cfgParse

decompiled_code:
__int64 __fastcall cfgParse(int argc, char **argv)
{
char *v2; // r13
int v4; // ebx
int v5; // eax
int v6; // eax
_QWORD *v7; // r14
void *v8; // rax
char *v9; // rsi
int v10; // eax
_QWORD *v11; // r14
void *v12; // rax
char *v13; // rsi
int v14; // eax
_QWORD *v15; // r14
void *v16; // rax
char *v17; // rsi
char *v18; // r14
size_t v19; // rbx
char *v20; // rax
size_t v21; // rdx
int v22; // eax
_QWORD *v23; // r14
void *v24; // rax
char *v25; // rsi
int v26; // eax
_QWORD *v27; // r14
void *v28; // rax
char *v29; // rsi
int v30; // eax
_QWORD *v31; // r14
void *v32; // rax
char *v33; // rsi
int v34; // eax
_QWORD *v35; // r14
void *v36; // rax
char *v37; // rsi
__int64 result; // rax
unsigned int v39; // [rsp+Ch] [rbp-3Ch]
int longind[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v4 = 0;
longind[0] = 0;
while ( 1 )
{
v5 = getopt_long(argc, argv, "c:hVqvd:a:p:n:k:i:s:t:u:w:b:l:", &long_options_0, longind);
if ( v5 == -1 )
break;
switch ( v5 )
{
case '?':
goto LABEL_36;
case 'c':
v18 = optarg;
v19 = strlen(optarg);
v20 = (char *)calloc(1uLL, (int)v19 + 1);
v21 = v19 + 1;
v4 = 1;
v2 = v20;
memcpy(v20, v18, v21);
break;
case 'h':
LABEL_36:
uiHelp();
result = 0LL;
goto LABEL_37;
case 'V':
uiVersion();
result = 0LL;
LABEL_37:
if ( v4 != 1 )
return result;
goto LABEL_40;
case 'q':
*(_DWORD *)conf = 0;
break;
case 'v':
*(_DWORD *)conf = 4;
break;
case 'd':
*(_DWORD *)conf = atoi(optarg);
break;
case 'a':
v6 = strlen(optarg);
v7 = conf;
v8 = realloc(*((void **)conf + 1), v6 + 1);
v9 = optarg;
v7[1] = v8;
strcpy(*((char **)conf + 1), v9);
break;
case 'p':
*((_DWORD *)conf + 4) = atoi(optarg);
break;
case 'n':
*((_DWORD *)conf + 5) = atoi(optarg);
break;
case 'k':
v10 = strlen(optarg);
v11 = conf;
v12 = realloc(*((void **)conf + 3), v10 + 1);
v13 = optarg;
v11[3] = v12;
strcpy(*((char **)conf + 3), v13);
break;
case 'i':
*((_DWORD *)conf + 8) = atoi(optarg);
break;
case 's':
v26 = strlen(optarg);
v27 = conf;
v28 = realloc(*((void **)conf + 5), v26 + 1);
v29 = optarg;
v27[5] = v28;
strcpy(*((char **)conf + 5), v29);
break;
case 't':
*((_DWORD *)conf + 12) = atoi(optarg);
break;
case 'u':
v34 = strlen(optarg);
v35 = conf;
v36 = realloc(*((void **)conf + 7), v34 + 1);
v37 = optarg;
v35[7] = v36;
strcpy(*((char **)conf + 7), v37);
break;
case 'w':
v30 = strlen(optarg);
v31 = conf;
v32 = realloc(*((void **)conf + 8), v30 + 1);
v33 = optarg;
v31[8] = v32;
strcpy(*((char **)conf + 8), v33);
break;
case 'b':
v22 = strlen(optarg);
v23 = conf;
v24 = realloc(*((void **)conf + 9), v22 + 1);
v25 = optarg;
v23[9] = v24;
strcpy(*((char **)conf + 9), v25);
break;
case 'l':
v14 = strlen(optarg);
v15 = conf;
v16 = realloc(*((void **)conf + 10), v14 + 1);
v17 = optarg;
v15[10] = v16;
strcpy(*((char **)conf + 10), v17);
break;
}
}
result = 1LL;
if ( v4 != 1 )
return result;
LABEL_40:
v39 = cfgFileParse(v2);
free(v2);
return v39;
}

canonical_decompiled_code:
__int64 __fastcall func4(int argc, char **argv)
{
char *v2; // r13
int v4; // ebx
int v5; // eax
int v6; // eax
_QWORD *v7; // r14
void *v8; // rax
char *v9; // rsi
int v10; // eax
_QWORD *v11; // r14
void *v12; // rax
char *v13; // rsi
int v14; // eax
_QWORD *v15; // r14
void *v16; // rax
char *v17; // rsi
char *v18; // r14
size_t v19; // rbx
char *v20; // rax
size_t v21; // rdx
int v22; // eax
_QWORD *v23; // r14
void *v24; // rax
char *v25; // rsi
int v26; // eax
_QWORD *v27; // r14
void *v28; // rax
char *v29; // rsi
int v30; // eax
_QWORD *v31; // r14
void *v32; // rax
char *v33; // rsi
int v34; // eax
_QWORD *v35; // r14
void *v36; // rax
char *v37; // rsi
__int64 result; // rax
unsigned int v39; // [rsp+Ch] [rbp-3Ch]
int longind[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v4 = 0;
longind[0] = 0;
while ( 1 )
{
v5 = getopt_long(argc, argv, "c:hVqvd:a:p:n:k:i:s:t:u:w:b:l:", &long_options_0, longind);
if ( v5 == -1 )
break;
switch ( v5 )
{
case '?':
goto LABEL_36;
case 'c':
v18 = optarg;
v19 = strlen(optarg);
v20 = (char *)calloc(1uLL, (int)v19 + 1);
v21 = v19 + 1;
v4 = 1;
v2 = v20;
memcpy(v20, v18, v21);
break;
case 'h':
LABEL_36:
uiHelp();
result = 0LL;
goto LABEL_37;
case 'V':
uiVersion();
result = 0LL;
LABEL_37:
if ( v4 != 1 )
return result;
goto LABEL_40;
case 'q':
*(_DWORD *)conf = 0;
break;
case 'v':
*(_DWORD *)conf = 4;
break;
case 'd':
*(_DWORD *)conf = atoi(optarg);
break;
case 'a':
v6 = strlen(optarg);
v7 = conf;
v8 = realloc(*((void **)conf + 1), v6 + 1);
v9 = optarg;
v7[1] = v8;
strcpy(*((char **)conf + 1), v9);
break;
case 'p':
*((_DWORD *)conf + 4) = atoi(optarg);
break;
case 'n':
*((_DWORD *)conf + 5) = atoi(optarg);
break;
case 'k':
v10 = strlen(optarg);
v11 = conf;
v12 = realloc(*((void **)conf + 3), v10 + 1);
v13 = optarg;
v11[3] = v12;
strcpy(*((char **)conf + 3), v13);
break;
case 'i':
*((_DWORD *)conf + 8) = atoi(optarg);
break;
case 's':
v26 = strlen(optarg);
v27 = conf;
v28 = realloc(*((void **)conf + 5), v26 + 1);
v29 = optarg;
v27[5] = v28;
strcpy(*((char **)conf + 5), v29);
break;
case 't':
*((_DWORD *)conf + 12) = atoi(optarg);
break;
case 'u':
v34 = strlen(optarg);
v35 = conf;
v36 = realloc(*((void **)conf + 7), v34 + 1);
v37 = optarg;
v35[7] = v36;
strcpy(*((char **)conf + 7), v37);
break;
case 'w':
v30 = strlen(optarg);
v31 = conf;
v32 = realloc(*((void **)conf + 8), v30 + 1);
v33 = optarg;
v31[8] = v32;
strcpy(*((char **)conf + 8), v33);
break;
case 'b':
v22 = strlen(optarg);
v23 = conf;
v24 = realloc(*((void **)conf + 9), v22 + 1);
v25 = optarg;
v23[9] = v24;
strcpy(*((char **)conf + 9), v25);
break;
case 'l':
v14 = strlen(optarg);
v15 = conf;
v16 = realloc(*((void **)conf + 10), v14 + 1);
v17 = optarg;
v15[10] = v16;
strcpy(*((char **)conf + 10), v17);
break;
}
}
result = 1LL;
if ( v4 != 1 )
return result;
LABEL_40:
v39 = func3(v2);
free(v2);
return v39;
}

original_code:
int cfgParse(int argc, char **argv)
{
    int ret = 0;
    int option_index = 0;
    int c;
    int ln;
    int conf_file = 0;
    char *config_file;
    static struct option long_options[] = {
        {"config", 1, 0, 'c'},
        {"help", 0, 0, 'h'},
        {"version", 0, 0, 'V'},
        {"quiet", 0, 0, 'q'},
        {"verbose", 0, 0, 'v'},
        {"debug", 1, 0, 'd'},
        {"inv-addr", 1, 0, 'a'},
        {"inv-port", 1, 0, 'p'},
        {"inv-num", 1, 0, 'n'},
        {"query", 1, 0, 'k'},
        {"interval", 1, 0, 'i'},
        {"mysql-addr", 1, 0, 's'},
        {"mysql-port", 1, 0, 't'},
        {"mysql-user", 1, 0, 'u'},
        {"mysql-password", 1, 0, 'w'},
        {"mysql-database", 1, 0, 'b'},
        {"mysql-table", 1, 0, 'l'},
        {0, 0, 0, 0}
    };
    while(1) {
        c = getopt_long(argc, argv, "c:hVqvd:a:p:n:k:i:s:t:u:w:b:l:", long_options, &option_index);
        if(c == -1) {
            ret = 1;
            break;
        }
        if(c == '?') {
            uiHelp();
            break;
        }
        if(c == 'c') {
            conf_file = 1;
            ln = strlen(optarg) + 1;
            config_file = (char *) calloc(sizeof(char), ln);
            strcpy(config_file, optarg);
        }
        if(c == 'h') {
            uiHelp();
            break;
        }
        if(c == 'V') {
            uiVersion();
            break;
        }
        if(c == 'q') {
            conf->debug_level = 0;
        }
        if(c == 'v') {
            conf->debug_level = 4;
        }
        if(c == 'd') {
            conf->debug_level = atoi(optarg);
        }
        if(c == 'a') {
            ln = strlen(optarg) + 1;
            conf->inv_addr = (char *) realloc((void *) conf->inv_addr, sizeof(char) * ln);
            strcpy(conf->inv_addr, optarg);
        }
        if(c == 'p') {
            conf->inv_port = atoi(optarg);
        }
        if(c == 'n') {
            conf->inv_num = atoi(optarg);
        }
        if(c == 'k') {
            ln = strlen(optarg) + 1;
            conf->lgr_query = (char *) realloc((void *) conf->lgr_query, sizeof(char) * ln);
            strcpy(conf->lgr_query, optarg);
        }
        if(c == 'i') {
            conf->lgr_interval = atoi(optarg);
        }
        if(c == 's') {
            ln = strlen(optarg) + 1;
            conf->mysql_addr = (char *) realloc((void *) conf->mysql_addr, sizeof(char) * ln);
            strcpy(conf->mysql_addr, optarg);
        }
        if(c == 't') {
            conf->mysql_port = atoi(optarg);
        }
        if(c == 'u') {
            ln = strlen(optarg) + 1;
            conf->mysql_user = (char *) realloc((void *) conf->mysql_user, sizeof(char) * ln);
            strcpy(conf->mysql_user, optarg);
        }
        if(c == 'w') {
            ln = strlen(optarg) + 1;
            conf->mysql_password = (char *) realloc((void *) conf->mysql_password, sizeof(char) * ln);
            strcpy(conf->mysql_password, optarg);
        }
        if(c == 'b') {
            ln = strlen(optarg) + 1;
            conf->mysql_database = (char *) realloc((void *) conf->mysql_database, sizeof(char) * ln);
            strcpy(conf->mysql_database, optarg);
        }
        if(c == 'l') {
            ln = strlen(optarg) + 1;
            conf->mysql_table = (char *) realloc((void *) conf->mysql_table, sizeof(char) * ln);
            strcpy(conf->mysql_table, optarg);
        }
    }
    if(conf_file == 1) {
        ret = cfgFileParse(config_file);
        free(config_file);
    }
    return ret;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


closeWave

repo: sarfata/learning-dsp

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

close(*(_DWORD *)ptr);
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
free(ptr);
}

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

close(*(_DWORD *)ptr);
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
free(ptr);
}

original_code:
void closeWave(t_wavef* wave)
{
  close(wave->fd);
  if (wave->header)
    free(wave->header);
  if (wave->audio)
    free(wave->audio);
  free(wave);
}

canonical_original_code:
void closeWave(struct t_wavef *wave)
{
  close(wave->fd);
  if (wave->header)
    free(wave->header);
  if (wave->audio)
    free(wave->audio);
  free(wave);
}

variable_types: struct t_wavef { int fd; struct t_wave_header { char chunkId[4]; unsigned int chunkSize; char chunkFormat[4]; unsigned int subChunk1Id; unsigned int formatSize; unsigned short audioFormat; unsigned short numChannels; unsigned int sampleRate; unsigned int byteRate; unsigned short blockAlign; unsigned short bitsPerSample; unsigned int subChunk2Id; unsigned int audioSize; } *header; unsigned char *audio; } *

user_defined_types: struct t_wavef { int fd; struct t_wave_header *header; unsigned char *audio; }


readHeader

decompiled_code:
__int64 __fastcall readHeader(__int64 a1)
{
void *v2; // rax
int v3; // edi
int v4; // eax

v2 = calloc(0x2CuLL, 1uLL);
v3 = *(_DWORD *)a1;
*(_QWORD *)(a1 + 8) = v2;
v4 = pread(v3, v2, 0x2CuLL, 0LL);
if ( v4 == 44 )
return 0LL;
fprintf(stderr, "Unable to read entire headers (%zi vs %zi)", v4, 0x2CuLL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
void *v2; // rax
int v3; // edi
int v4; // eax

v2 = calloc(0x2CuLL, 1uLL);
v3 = *(_DWORD *)a1;
*(_QWORD *)(a1 + 8) = v2;
v4 = pread(v3, v2, 0x2CuLL, 0LL);
if ( v4 == 44 )
return 0LL;
fprintf(stderr, "Unable to read entire headers (%zi vs %zi)", v4, 0x2CuLL);
return 0xFFFFFFFFLL;
}

original_code:
int readHeader(t_wavef* wave)
{
  ssize_t len;
  wave->header = malloc(sizeof(t_wave_header));
  memset(wave->header, 0, sizeof(t_wave_header));
  len = pread(wave->fd, wave->header, sizeof(t_wave_header), 0);
  if (len != sizeof(t_wave_header)) {
    fprintf (stderr, "Unable to read entire headers (%zi vs %zi)", len, sizeof(t_wave_header));
    return -1;
  }
  return 0;
}

canonical_original_code:
int readHeader(struct t_wavef *wave)
{
  long len;
  wave->header = malloc(sizeof(t_wave_header));
  memset(wave->header, 0, sizeof(t_wave_header));
  len = pread(wave->fd, wave->header, sizeof(t_wave_header), 0);
  if (len != sizeof(t_wave_header)) {
    fprintf (stderr, "Unable to read entire headers (%zi vs %zi)", len, sizeof(t_wave_header));
    return -1;
  }
  return 0;
}

variable_types: len long

user_defined_types: struct t_wave_header { char chunkId[4]; unsigned int chunkSize; char chunkFormat[4]; unsigned int subChunk1Id; unsigned int formatSize; unsigned short audioFormat; unsigned short numChannels; unsigned int sampleRate; unsigned int byteRate; unsigned short blockAlign; unsigned short bitsPerSample; unsigned int subChunk2Id; unsigned int audioSize; }


readAudio

decompiled_code:
__int64 __fastcall readAudio(__int64 a1)
{
size_t v2; // r12
void *v3; // rax
int v4; // edi
int v5; // eax

v2 = *(unsigned int *)(*(_QWORD *)(a1 + 8) + 40LL);
v3 = malloc(v2);
v4 = *(_DWORD *)a1;
*(_QWORD *)(a1 + 16) = v3;
v5 = pread(v4, v3, (unsigned int)v2, 44LL);
if ( *(_DWORD *)(*(_QWORD *)(a1 + 8) + 40LL) == (__int64)v5 )
return 0LL;
fprintf(stderr, "Unable to read complete audio data (%zi vs %zi)", v5, 4uLL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
size_t v2; // r12
void *v3; // rax
int v4; // edi
int v5; // eax

v2 = *(unsigned int *)(*(_QWORD *)(a1 + 8) + 40LL);
v3 = malloc(v2);
v4 = *(_DWORD *)a1;
*(_QWORD *)(a1 + 16) = v3;
v5 = pread(v4, v3, (unsigned int)v2, 44LL);
if ( *(_DWORD *)(*(_QWORD *)(a1 + 8) + 40LL) == (__int64)v5 )
return 0LL;
fprintf(stderr, "Unable to read complete audio data (%zi vs %zi)", v5, 4uLL);
return 0xFFFFFFFFLL;
}

original_code:
int readAudio(t_wavef* wave)
{
  ssize_t len;
  wave->audio = malloc(wave->header->audioSize);
  len = pread(wave->fd, wave->audio, wave->header->audioSize, sizeof(t_wave_header));
  if (len != wave->header->audioSize) {
    fprintf (stderr, "Unable to read complete audio data (%zi vs %zi)", len, sizeof(wave->header->audioSize));
    return -1;
  }
  return 0;
}

canonical_original_code:
int readAudio(struct t_wavef *wave)
{
  long len;
  wave->audio = malloc(wave->header->audioSize);
  len = pread(wave->fd, wave->audio, wave->header->audioSize, sizeof(t_wave_header));
  if (len != wave->header->audioSize) {
    fprintf (stderr, "Unable to read complete audio data (%zi vs %zi)", len, sizeof(wave->header->audioSize));
    return -1;
  }
  return 0;
}


waveSamples

decompiled_code:
__int64 __fastcall waveSamples(__int64 a1)
{
return *(_DWORD *)(a1 + 40) / (unsigned int)*(unsigned __int16 *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_DWORD *)(a1 + 40) / (unsigned int)*(unsigned __int16 *)(a1 + 32);
}

original_code:
uint32_t waveSamples(t_wave_header *header)
{
  return header->audioSize / header->blockAlign;
}

canonical_original_code:
unsigned int waveSamples(struct t_wave_header *header)
{
  return header->audioSize / header->blockAlign;
}

variable_types: struct t_wave_header { char chunkId[4]; unsigned int chunkSize; char chunkFormat[4]; unsigned int subChunk1Id; unsigned int formatSize; unsigned short audioFormat; unsigned short numChannels; unsigned int sampleRate; unsigned int byteRate; unsigned short blockAlign; unsigned short bitsPerSample; unsigned int subChunk2Id; unsigned int audioSize; } *

return_type: unsigned int


waveDuration

decompiled_code:
float __fastcall waveDuration(__int64 a1)
{
return (double)(int)waveSamples(a1) / (double)*(int *)(a1 + 24);
}

canonical_decompiled_code:
float __fastcall func5(__int64 a1)
{
return (double)(int)func4(a1) / (double)*(int *)(a1 + 24);
}

original_code:
float waveDuration(t_wave_header *header)
{
  return waveSamples(header) * 1.0 / header->sampleRate;
}

canonical_original_code:
float waveDuration(struct t_wave_header *header)
{
  return waveSamples(header) * 1.0 / header->sampleRate;
}

return_type: float


debugWaveHeader

decompiled_code:
int __fastcall debugWaveHeader(__int64 a1)
{
unsigned int v1; // eax
float v2; // xmm0_4

printf("ChunkId : %.4s\n", (const char *)a1);
printf("Format : %.4s\n\n", (const char *)(a1 + 8));
printf("Audio Format: %i\n", *(unsigned __int16 *)(a1 + 20));
printf("Num Channels: %i\n", *(unsigned __int16 *)(a1 + 22));
printf("Sample Rate: %i\n", *(unsigned int *)(a1 + 24));
printf("Byte Rate: %i\n", *(unsigned int *)(a1 + 28));
printf("Block Align: %i\n", *(unsigned __int16 *)(a1 + 32));
printf("BitsPerSample: %i\n\n", *(unsigned __int16 *)(a1 + 34));
printf("Data size: %i\n", *(unsigned int *)(a1 + 40));
v1 = waveSamples(a1);
printf("NumSamples: %i\n", v1);
v2 = waveDuration(a1);
return printf("File duration: %f\n", v2);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
unsigned int v1; // eax
float v2; // xmm0_4

printf("ChunkId : %.4s\n", (const char *)a1);
printf("Format : %.4s\n\n", (const char *)(a1 + 8));
printf("Audio Format: %i\n", *(unsigned __int16 *)(a1 + 20));
printf("Num Channels: %i\n", *(unsigned __int16 *)(a1 + 22));
printf("Sample Rate: %i\n", *(unsigned int *)(a1 + 24));
printf("Byte Rate: %i\n", *(unsigned int *)(a1 + 28));
printf("Block Align: %i\n", *(unsigned __int16 *)(a1 + 32));
printf("BitsPerSample: %i\n\n", *(unsigned __int16 *)(a1 + 34));
printf("Data size: %i\n", *(unsigned int *)(a1 + 40));
v1 = func4(a1);
printf("NumSamples: %i\n", v1);
v2 = func5(a1);
return printf("File duration: %f\n", v2);
}

original_code:
void debugWaveHeader(t_wave_header *header)
{
  printf("ChunkId   : %.4s\n", header->chunkId);
  printf("Format    : %.4s\n\n", header->chunkFormat);
  printf("Audio Format: %i\n", header->audioFormat);
  printf("Num Channels: %i\n", header->numChannels);
  printf("Sample Rate: %i\n", header->sampleRate);
  printf("Byte Rate: %i\n", header->byteRate);
  printf("Block Align: %i\n", header->blockAlign);
  printf("BitsPerSample: %i\n\n", header->bitsPerSample);
  printf("Data size: %i\n", header->audioSize);
  printf("NumSamples: %i\n", waveSamples(header));
  printf("File duration: %f\n", waveDuration(header));
}

canonical_original_code:
void debugWaveHeader(struct t_wave_header *header)
{
  printf("ChunkId   : %.4s\n", header->chunkId);
  printf("Format    : %.4s\n\n", header->chunkFormat);
  printf("Audio Format: %i\n", header->audioFormat);
  printf("Num Channels: %i\n", header->numChannels);
  printf("Sample Rate: %i\n", header->sampleRate);
  printf("Byte Rate: %i\n", header->byteRate);
  printf("Block Align: %i\n", header->blockAlign);
  printf("BitsPerSample: %i\n\n", header->bitsPerSample);
  printf("Data size: %i\n", header->audioSize);
  printf("NumSamples: %i\n", waveSamples(header));
  printf("File duration: %f\n", waveDuration(header));
}


dumpSamples

original_code:
void dumpSamples(t_wavef *wave, int count)
{
  int16_t *audio = (int16_t*)wave->audio;
  for (int i = 0; i < count && i < waveSamples(wave->header); i++) {
    printf("audio[%i]: %02X%02X %i\n", i, wave->audio[i*2], wave->audio[i*2+1], audio[i]);
  }
}

canonical_original_code:
void dumpSamples(struct t_wavef *wave, int count)
{
  short *audio = (int16_t*)wave->audio;
  for (int i = 0; i < count && i < waveSamples(wave->header); i++) {
    printf("audio[%i]: %02X%02X %i\n", i, wave->audio[i*2], wave->audio[i*2+1], audio[i]);
  }
}

variable_types: count int

variable_types:
audio
short *

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
__int64 v4; // rbp
__int64 v5; // r12

printf("%s: put some DSP classes to work\n", *argv);
if ( argc <= 2 )
{
fprintf(stderr, " Usage: %s <wave file> <samples to dft>\n", *argv);
fprintf(stderr, " Example: %s samples/sine-3200.wav 512\n", *argv);
exit(-1);
}
v3 = atoi(argv[2]);
v4 = openWave(argv[1]);
debugWaveHeader(*(_QWORD *)(v4 + 8));
v5 = performDft(*(_QWORD *)(v4 + 16), v3, 1LL);
printSpectrum(v5, *(unsigned int *)(*(_QWORD *)(v4 + 8) + 24LL));
freeSpectrum(v5);
closeWave(v4);
return 0;
}

original_code:
int main(int argc, char **argv) {
  t_wavef *wave;
  spectrum_t *mydft;
  int length;
  printf("%s: put some DSP classes to work\n", argv[0]);
  if (argc < 3) {
    fprintf(stderr, "  Usage: %s <wave file> <samples to dft>\n", argv[0]);
    fprintf(stderr, "  Example: %s samples/sine-3200.wav 512\n", argv[0]);
    exit(-1);
  }
  length = atoi(argv[2]);
  wave = openWave(argv[1]);
  debugWaveHeader(wave->header);
  mydft = performDft((int16_t*)wave->audio, length, 1);
  printSpectrum(mydft, wave->header->sampleRate);
  freeSpectrum(mydft);
  closeWave(wave);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  struct t_wavef *wave;
  struct spectrum_t *mydft;
  int length;
  printf("%s: put some DSP classes to work\n", argv[0]);
  if (argc < 3) {
    fprintf(stderr, "  Usage: %s <wave file> <samples to dft>\n", argv[0]);
    fprintf(stderr, "  Example: %s samples/sine-3200.wav 512\n", argv[0]);
    exit(-1);
  }
  length = atoi(argv[2]);
  wave = openWave(argv[1]);
  debugWaveHeader(wave->header);
  mydft = performDft((short *)wave->audio, length, 1);
  printSpectrum(mydft, wave->header->sampleRate);
  freeSpectrum(mydft);
  closeWave(wave);
  return 0;
}

variable_types: struct spectrum_t { unsigned int k; double *spectrum_r; double *spectrum_i; } *

variable_types: length int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_remove_spaces(argc, argv, envp);
test_stop_words();
test_remove_stop_words();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
func8();
func9();
return 0;
}

original_code:
int main(int argc, const char* argv[])
{
    test_remove_spaces();
    test_stop_words();
    test_remove_stop_words();
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    test_remove_spaces();
    test_stop_words();
    test_remove_stop_words();
    return 0;
}

variable_types:
argv
char *[]


original_code:
void test_remove_spaces()
{
    const char *cases[8][2] = {{" test  str  ", "test str"},
                         {"", ""},
                         {" ", ""},
                         {"  ", ""},
                         {" test ", "test"},
                         {"  test s  tring  s", "test s tring s"},
                         {"te st ", "te st"},
                         {"testvalue", "testvalue"}
                        };
    int i;
    for(i = 0; i < sizeof(cases) / (2 * sizeof(char *)); i++)
    {
        char buf[256];
        strcpy(buf, cases[i][0]);
        remove_spaces_impl(buf);
        ((void) sizeof ((strcmp(buf, cases[i][1]) == 0) ? 1 : 0), __extension__ ({ if (strcmp(buf, cases[i][1]) == 0) ; else __assert_fail ("strcmp(buf, cases[i][1]) == 0", "test.c", 25, __extension__ __PRETTY_FUNCTION__); }));
    }
    remove_spaces_impl(0);
}

canonical_original_code:
void test_remove_spaces()
{
    char *cases[8][2] = {{" test  str  ", "test str"},
                         {"", ""},
                         {" ", ""},
                         {"  ", ""},
                         {" test ", "test"},
                         {"  test s  tring  s", "test s tring s"},
                         {"te st ", "te st"},
                         {"testvalue", "testvalue"}
                        };
    int i;
    for(i = 0; i < sizeof(cases) / (2 * sizeof(char *)); i++)
    {
        char buf[256];
        strcpy(buf, cases[i][0]);
        remove_spaces_impl(buf);
        ((void) sizeof ((strcmp(buf, cases[i][1]) == 0) ? 1 : 0), __extension__ ({ if (strcmp(buf, cases[i][1]) == 0) ; else __assert_fail ("strcmp(buf, cases[i][1]) == 0", "test.c", 25, __extension__ __PRETTY_FUNCTION__); }));
    }
    remove_spaces_impl(0);
}

variable_types:
cases
char *[8][2]

variable_types:
buf
char [256]


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

if ( (unsigned int)is_stop_word("non_stop") )
__assert_fail("is_stop_word(\"non_stop\") == 0", "test.c", 0x21u, "test_stop_words");
if ( (unsigned int)is_stop_word("the der") )
__assert_fail("is_stop_word(\"the der\") == 0", "test.c", 0x22u, "test_stop_words");
if ( (unsigned int)is_stop_word("the") != 1 )
__assert_fail("is_stop_word(\"the\") == 1", "test.c", 0x23u, "test_stop_words");
if ( (unsigned int)is_stop_word("der") != 1 )
__assert_fail("is_stop_word(\"der\") == 1", "test.c", 0x24u, "test_stop_words");
if ( (unsigned int)is_stop_word(&unk_402101) != 1 )
__assert_fail(aIsStopWord, "test.c", 0x25u, "test_stop_words");
result = is_stop_word("");
if ( (_DWORD)result != 1 )
__assert_fail("is_stop_word(\"\") == 1", "test.c", 0x26u, "test_stop_words");
return result;
}

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

if ( (unsigned int)func13("non_stop") )
__assert_fail("is_stop_word(\"non_stop\") == 0", "test.c", 0x21u, "test_stop_words");
if ( (unsigned int)func13("the der") )
__assert_fail("is_stop_word(\"the der\") == 0", "test.c", 0x22u, "test_stop_words");
if ( (unsigned int)func13("the") != 1 )
__assert_fail("is_stop_word(\"the\") == 1", "test.c", 0x23u, "test_stop_words");
if ( (unsigned int)func13("der") != 1 )
__assert_fail("is_stop_word(\"der\") == 1", "test.c", 0x24u, "test_stop_words");
if ( (unsigned int)func13(&unk_402101) != 1 )
__assert_fail(aIsStopWord, "test.c", 0x25u, "test_stop_words");
result = func13("");
if ( (_DWORD)result != 1 )
__assert_fail("is_stop_word(\"\") == 1", "test.c", 0x26u, "test_stop_words");
return result;
}

original_code:
void test_stop_words()
{
    ((void) sizeof ((is_stop_word("non_stop") == 0) ? 1 : 0), __extension__ ({ if (is_stop_word("non_stop") == 0) ; else __assert_fail ("is_stop_word(\"non_stop\") == 0", "test.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((is_stop_word("the der") == 0) ? 1 : 0), __extension__ ({ if (is_stop_word("the der") == 0) ; else __assert_fail ("is_stop_word(\"the der\") == 0", "test.c", 34, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((is_stop_word("the") == 1) ? 1 : 0), __extension__ ({ if (is_stop_word("the") == 1) ; else __assert_fail ("is_stop_word(\"the\") == 1", "test.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((is_stop_word("der") == 1) ? 1 : 0), __extension__ ({ if (is_stop_word("der") == 1) ; else __assert_fail ("is_stop_word(\"der\") == 1", "test.c", 36, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((is_stop_word("на") == 1) ? 1 : 0), __extension__ ({ if (is_stop_word("на") == 1) ; else __assert_fail ("is_stop_word(\"на\") == 1", "test.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((is_stop_word("") == 1) ? 1 : 0), __extension__ ({ if (is_stop_word("") == 1) ; else __assert_fail ("is_stop_word(\"\") == 1", "test.c", 38, __extension__ __PRETTY_FUNCTION__); }));
}


original_code:
void test_remove_stop_words()
{
    const char *cases[9][2] = {{"test", "test"},
                               {"the test", "test"},
                               {"two tests", "two tests"},
                               {"test of the tests hoho", "test tests hoho"},
                               {"", ""},
                               {"the of", ""},
                               {"  ", ""},
                               {" word  ", "word"},
                               {" the word ", "word"}
                        };
    int i;
    for(i = 0; i < sizeof(cases) / (2 * sizeof(char *)); i++)
    {
        char buf[256];
        strcpy(buf, cases[i][0]);
        remove_stop_words_impl(buf);
        ((void) sizeof ((strcmp(buf, cases[i][1]) == 0) ? 1 : 0), __extension__ ({ if (strcmp(buf, cases[i][1]) == 0) ; else __assert_fail ("strcmp(buf, cases[i][1]) == 0", "test.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    }
    remove_stop_words_impl(0);
}

canonical_original_code:
void test_remove_stop_words()
{
    char *cases[9][2] = {{"test", "test"},
                               {"the test", "test"},
                               {"two tests", "two tests"},
                               {"test of the tests hoho", "test tests hoho"},
                               {"", ""},
                               {"the of", ""},
                               {"  ", ""},
                               {" word  ", "word"},
                               {" the word ", "word"}
                        };
    int i;
    for(i = 0; i < sizeof(cases) / (2 * sizeof(char *)); i++)
    {
        char buf[256];
        strcpy(buf, cases[i][0]);
        remove_stop_words_impl(buf);
        ((void) sizeof ((strcmp(buf, cases[i][1]) == 0) ? 1 : 0), __extension__ ({ if (strcmp(buf, cases[i][1]) == 0) ; else __assert_fail ("strcmp(buf, cases[i][1]) == 0", "test.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    }
    remove_stop_words_impl(0);
}

variable_types:
cases
char *[9][2]


decompiled_code:
void __fastcall remove_stop_words_impl(void *s)
{
char *v1; // rbx
size_t v2; // rax
char *v3; // rbp
int v4; // er14
int v5; // eax
char *v6; // rdi
char delim[2]; // [rsp+0h] [rbp-32h] BYREF
char *stringp[6]; // [rsp+2h] [rbp-30h] BYREF

if ( s )
{
v1 = (char *)s;
if ( *(_BYTE *)s )
{
strcpy(delim, " ");
stringp[0] = strdup((const char *)s);
v2 = strlen((const char *)s);
memset(s, 32, v2);
v3 = strsep(stringp, delim);
if ( v3 )
{
v4 = 0;
do
{
if ( !(unsigned int)is_stop_word(v3) )
{
v5 = strlen(v3);
v6 = &v1[-(v4 == 0) + 1];
v1 = &v6[v5];
v4 = 1;
memcpy(v6, v3, v5);
}
v3 = strsep(stringp, delim);
}
while ( v3 );
}
*v1 = 0;
free(stringp[0]);
}
}
}

canonical_decompiled_code:
void __fastcall func11(void *s)
{
char *v1; // rbx
size_t v2; // rax
char *v3; // rbp
int v4; // er14
int v5; // eax
char *v6; // rdi
char delim[2]; // [rsp+0h] [rbp-32h] BYREF
char *stringp[6]; // [rsp+2h] [rbp-30h] BYREF

if ( s )
{
v1 = (char *)s;
if ( *(_BYTE *)s )
{
strcpy(delim, " ");
stringp[0] = strdup((const char *)s);
v2 = strlen((const char *)s);
memset(s, 32, v2);
v3 = strsep(stringp, delim);
if ( v3 )
{
v4 = 0;
do
{
if ( !(unsigned int)func13(v3) )
{
v5 = strlen(v3);
v6 = &v1[-(v4 == 0) + 1];
v1 = &v6[v5];
v4 = 1;
memcpy(v6, v3, v5);
}
v3 = strsep(stringp, delim);
}
while ( v3 );
}
*v1 = 0;
free(stringp[0]);
}
}
}

original_code:
void remove_stop_words_impl(char *str)
{
    if(str && *str)
    {
        const char delimiters[] = " ";
        char *token = ((void *)0);
        char *cp = strdup(str);
        memset(str, ' ', strlen(str));
        int first = 0;
        token = strsep(&cp, delimiters);
        while(token)
        {
            if(!is_stop_word(token))
            {
                if(first != 0)
                    *++str;
                else
                    first = 1;
                int len = strlen(token);
                memcpy(str, token, len);
                str += len;
            }
            token = strsep(&cp, delimiters);
        }
        *str = 0;
        free((void *)cp);
    }
}

canonical_original_code:
void remove_stop_words_impl(char *str)
{
    if(str && *str)
    {
        char delimiters[] = " ";
        char *token = ((void *)0);
        char *cp = strdup(str);
        memset(str, ' ', strlen(str));
        int first = 0;
        token = strsep(&cp, delimiters);
        while(token)
        {
            if(!is_stop_word(token))
            {
                if(first != 0)
                    *++str;
                else
                    first = 1;
                int len = strlen(token);
                memcpy(str, token, len);
                str += len;
            }
            token = strsep(&cp, delimiters);
        }
        *str = 0;
        free((void *)cp);
    }
}

variable_types:
str
char *

variable_types:
delimiters
char []

variable_types:
token
char *

variable_types:
cp
char *

variable_types: first int

variable_types: len int