decompiled_code:
size_t print_usage()
{
return fwrite(
"Summary:\n"
" Extract subgrids of data from a GridFloat file. GridFloat\n"
" is a simple format commonly used by the USGS for packaging\n"
" elevation data. A header file with geolocation metadata is\n"
" required for making queries based on latitude/longitude.\n"
"\n"
"Usage:\n"
" gridfloat [options] FLOATFILE HEADERFILE\n"
" gridfloat [options] FLOAT_HEADER_PREFIX\n"
"\n"
" where, for the first case, FLOATFILE should have\n"
" extension .flt and HEADERFILE .hdr. If both HEADERFILE\n"
" and FLOATFILE have the same filename prefix, then you\n"
" can use the second case.\n"
"\n"
"Options:\n"
" -h: Print this help message.\n"
" -i: Print helpful info derived from GridFloat header file.\n"
" -R: Resolution of extraction. If a single integer is\n"
" supplied, then the resolution is the same in both\n"
" directions. Otherwise, the format is (by example):\n"
" '-R 128x256' where the first number is the resolution\n"
" in the x-direction (along lines of latitude).\n"
" -l: Left bound for extraction.\n"
" -r: Right bound for extraction.\n"
" -b: Bottom bound for extraction.\n"
" -t: Top bound for extraction.\n"
" -B: Specify extraction bounds using a comma-separated\n"
" list of the form LEFT,RIGHT,BOTTOM,TOP. E.g.\n"
" '-B -123.112,-123.110,42.100,42.101'.\n"
" -n: Longitude midpoint of extraction. Must use with '-s'\n"
" option. Example: '-n 42'.\n"
" -w: Latitude midpoint of extraction. Must use with '-s'\n"
" option. Example: '-w 123' (notice there is no minus\n"
" sign here).\n"
" -p: Lat/Lng midpoint of extraction. Must use with '-s'\n"
" option. Example: '-p -123,42'.\n"
" -s: Size of box (in degrees) around midpoint. Used with '-p'\n"
" and '-n','-w' options. Examples: '-s 1.0x1.0' or just '-s 1'.\n"
" If a rectangular size is requested, the first number refers\n"
" to the width of the box (along x; i.e. along lines of\n"
" latitude).\n"
" -T: Transpose and invert along y before printing the array\n"
" (so that a[i, j] gives longitude increasing with i and\n"
" latitude increasing with j).\n"
" -o: Output subgrid data to a file. Detects output format based\n"
" on file extension. Supported: (.png, .stl). For a .png\n"
" extension, see \"PNG output options\" below. Otherwise,\n"
" gridfloat will assume you want to save another GridFloat\n"
" file. In this case, it will write the appropriate data\n"
" and header files, appending .flt and .hdr, respectively,\n"
" to the argument of -o.\n"
"\n"
"PNG output options:\n"
" When png output is specified, gridfloat automatically renders\n"
" a shaded relief map. The following options determine which\n"
" slopes are sunny.\n"
"\n"
" -A: Azimuthal angle (in degrees) of view toward sun (for\n"
" relief shading). 0 means sun is East, 90 North, etc.\n"
" Default: 45 (NE).\n"
" -P: Polar angle (in degrees) of view toward sun (for\n"
" relief shading). 0 means sun is on horizon, 90 when\n"
" directly overhead. Default: 30.\n"
"\n"
"Examples:\n"
" All of the following are equivalent and simply print data\n"
" to stdout.\n"
"\n"
" gridfloat -l -123 -r -122 -b 42 -t 43 file.{hdr,flt}\n"
" gridfloat -B -123,-122,42,43 file.{hdr,flt}\n"
" gridfloat -p -122.5,42.5 -s 1 file.{hdr,flt}\n"
" gridfloat -w 122.5 -n 42.5 -s 1x1 file.{hdr,flt}\n"
"\n",
1uLL,
0xC45uLL,
stdout);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite(
"Summary:\n"
" Extract subgrids of data from a GridFloat file. GridFloat\n"
" is a simple format commonly used by the USGS for packaging\n"
" elevation data. A header file with geolocation metadata is\n"
" required for making queries based on latitude/longitude.\n"
"\n"
"Usage:\n"
" gridfloat [options] FLOATFILE HEADERFILE\n"
" gridfloat [options] FLOAT_HEADER_PREFIX\n"
"\n"
" where, for the first case, FLOATFILE should have\n"
" extension .flt and HEADERFILE .hdr. If both HEADERFILE\n"
" and FLOATFILE have the same filename prefix, then you\n"
" can use the second case.\n"
"\n"
"Options:\n"
" -h: Print this help message.\n"
" -i: Print helpful info derived from GridFloat header file.\n"
" -R: Resolution of extraction. If a single integer is\n"
" supplied, then the resolution is the same in both\n"
" directions. Otherwise, the format is (by example):\n"
" '-R 128x256' where the first number is the resolution\n"
" in the x-direction (along lines of latitude).\n"
" -l: Left bound for extraction.\n"
" -r: Right bound for extraction.\n"
" -b: Bottom bound for extraction.\n"
" -t: Top bound for extraction.\n"
" -B: Specify extraction bounds using a comma-separated\n"
" list of the form LEFT,RIGHT,BOTTOM,TOP. E.g.\n"
" '-B -123.112,-123.110,42.100,42.101'.\n"
" -n: Longitude midpoint of extraction. Must use with '-s'\n"
" option. Example: '-n 42'.\n"
" -w: Latitude midpoint of extraction. Must use with '-s'\n"
" option. Example: '-w 123' (notice there is no minus\n"
" sign here).\n"
" -p: Lat/Lng midpoint of extraction. Must use with '-s'\n"
" option. Example: '-p -123,42'.\n"
" -s: Size of box (in degrees) around midpoint. Used with '-p'\n"
" and '-n','-w' options. Examples: '-s 1.0x1.0' or just '-s 1'.\n"
" If a rectangular size is requested, the first number refers\n"
" to the width of the box (along x; i.e. along lines of\n"
" latitude).\n"
" -T: Transpose and invert along y before printing the array\n"
" (so that a[i, j] gives longitude increasing with i and\n"
" latitude increasing with j).\n"
" -o: Output subgrid data to a file. Detects output format based\n"
" on file extension. Supported: (.png, .stl). For a .png\n"
" extension, see \"PNG output options\" below. Otherwise,\n"
" gridfloat will assume you want to save another GridFloat\n"
" file. In this case, it will write the appropriate data\n"
" and header files, appending .flt and .hdr, respectively,\n"
" to the argument of -o.\n"
"\n"
"PNG output options:\n"
" When png output is specified, gridfloat automatically renders\n"
" a shaded relief map. The following options determine which\n"
" slopes are sunny.\n"
"\n"
" -A: Azimuthal angle (in degrees) of view toward sun (for\n"
" relief shading). 0 means sun is East, 90 North, etc.\n"
" Default: 45 (NE).\n"
" -P: Polar angle (in degrees) of view toward sun (for\n"
" relief shading). 0 means sun is on horizon, 90 when\n"
" directly overhead. Default: 30.\n"
"\n"
"Examples:\n"
" All of the following are equivalent and simply print data\n"
" to stdout.\n"
"\n"
" gridfloat -l -123 -r -122 -b 42 -t 43 file.{hdr,flt}\n"
" gridfloat -B -123,-122,42,43 file.{hdr,flt}\n"
" gridfloat -p -122.5,42.5 -s 1 file.{hdr,flt}\n"
" gridfloat -w 122.5 -n 42.5 -s 1x1 file.{hdr,flt}\n"
"\n",
1uLL,
0xC45uLL,
stdout);
}

original_code:
void print_usage(void) {
    fprintf(stdout,
        "Summary:\n"
        "  Extract subgrids of data from a GridFloat file. GridFloat\n"
        "  is a simple format commonly used by the USGS for packaging\n"
        "  elevation data. A header file with geolocation metadata is\n"
        "  required for making queries based on latitude/longitude.\n"
        "\n"
        "Usage:\n"
        "  gridfloat [options] FLOATFILE HEADERFILE\n"
        "  gridfloat [options] FLOAT_HEADER_PREFIX\n"
        "\n"
        "  where, for the first case, FLOATFILE should have\n"
        "  extension .flt and HEADERFILE .hdr. If both HEADERFILE\n"
        "  and FLOATFILE have the same filename prefix, then you\n"
        "  can use the second case.\n"
        "\n"
        "Options:\n"
        "  -h:  Print this help message.\n"
        "  -i:  Print helpful info derived from GridFloat header file.\n"
        "  -R:  Resolution of extraction. If a single integer is\n"
        "       supplied, then the resolution is the same in both\n"
        "       directions. Otherwise, the format is (by example):\n"
        "       '-R 128x256' where the first number is the resolution\n"
        "       in the x-direction (along lines of latitude).\n"
        "  -l:  Left bound for extraction.\n"
        "  -r:  Right bound for extraction.\n"
        "  -b:  Bottom bound for extraction.\n"
        "  -t:  Top bound for extraction.\n"
        "  -B:  Specify extraction bounds using a comma-separated\n"
        "       list of the form LEFT,RIGHT,BOTTOM,TOP. E.g.\n"
        "       '-B -123.112,-123.110,42.100,42.101'.\n"
        "  -n:  Longitude midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-n 42'.\n"
        "  -w:  Latitude midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-w 123' (notice there is no minus\n"
        "       sign here).\n"
        "  -p:  Lat/Lng midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-p -123,42'.\n"
        "  -s:  Size of box (in degrees) around midpoint. Used with '-p'\n"
        "       and '-n','-w' options. Examples: '-s 1.0x1.0' or just '-s 1'.\n"
        "       If a rectangular size is requested, the first number refers\n"
        "       to the width of the box (along x; i.e. along lines of\n"
        "       latitude).\n"
        "  -T:  Transpose and invert along y before printing the array\n"
        "       (so that a[i, j] gives longitude increasing with i and\n"
        "       latitude increasing with j).\n"
        "  -o:  Output subgrid data to a file. Detects output format based\n"
        "       on file extension. Supported: (.png, .stl). For a .png\n"
        "       extension, see \"PNG output options\" below. Otherwise,\n"
        "       gridfloat will assume you want to save another GridFloat\n"
        "       file. In this case, it will write the appropriate data\n"
        "       and header files, appending .flt and .hdr, respectively,\n"
        "       to the argument of -o.\n"
        "\n"
        "PNG output options:\n"
        "  When png output is specified, gridfloat automatically renders\n"
        "  a shaded relief map. The following options determine which\n"
        "  slopes are sunny.\n"
        "\n"
        "  -A:  Azimuthal angle (in degrees) of view toward sun (for\n"
        "       relief shading). 0 means sun is East, 90 North, etc.\n"
        "       Default: 45 (NE).\n"
        "  -P:  Polar angle (in degrees) of view toward sun (for\n"
        "       relief shading). 0 means sun is on horizon, 90 when\n"
        "       directly overhead. Default: 30.\n"
        "\n"
        "Examples:\n"
        "  All of the following are equivalent and simply print data\n"
        "  to stdout.\n"
        "\n"
        "  gridfloat -l -123 -r -122 -b 42 -t 43 file.{hdr,flt}\n"
        "  gridfloat -B -123,-122,42,43 file.{hdr,flt}\n"
        "  gridfloat -p -122.5,42.5 -s 1 file.{hdr,flt}\n"
        "  gridfloat -w 122.5 -n 42.5 -s 1x1 file.{hdr,flt}\n"
        "\n"
    );
}

canonical_original_code:
void print_usage() {
    fprintf(stdout,
        "Summary:\n"
        "  Extract subgrids of data from a GridFloat file. GridFloat\n"
        "  is a simple format commonly used by the USGS for packaging\n"
        "  elevation data. A header file with geolocation metadata is\n"
        "  required for making queries based on latitude/longitude.\n"
        "\n"
        "Usage:\n"
        "  gridfloat [options] FLOATFILE HEADERFILE\n"
        "  gridfloat [options] FLOAT_HEADER_PREFIX\n"
        "\n"
        "  where, for the first case, FLOATFILE should have\n"
        "  extension .flt and HEADERFILE .hdr. If both HEADERFILE\n"
        "  and FLOATFILE have the same filename prefix, then you\n"
        "  can use the second case.\n"
        "\n"
        "Options:\n"
        "  -h:  Print this help message.\n"
        "  -i:  Print helpful info derived from GridFloat header file.\n"
        "  -R:  Resolution of extraction. If a single integer is\n"
        "       supplied, then the resolution is the same in both\n"
        "       directions. Otherwise, the format is (by example):\n"
        "       '-R 128x256' where the first number is the resolution\n"
        "       in the x-direction (along lines of latitude).\n"
        "  -l:  Left bound for extraction.\n"
        "  -r:  Right bound for extraction.\n"
        "  -b:  Bottom bound for extraction.\n"
        "  -t:  Top bound for extraction.\n"
        "  -B:  Specify extraction bounds using a comma-separated\n"
        "       list of the form LEFT,RIGHT,BOTTOM,TOP. E.g.\n"
        "       '-B -123.112,-123.110,42.100,42.101'.\n"
        "  -n:  Longitude midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-n 42'.\n"
        "  -w:  Latitude midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-w 123' (notice there is no minus\n"
        "       sign here).\n"
        "  -p:  Lat/Lng midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-p -123,42'.\n"
        "  -s:  Size of box (in degrees) around midpoint. Used with '-p'\n"
        "       and '-n','-w' options. Examples: '-s 1.0x1.0' or just '-s 1'.\n"
        "       If a rectangular size is requested, the first number refers\n"
        "       to the width of the box (along x; i.e. along lines of\n"
        "       latitude).\n"
        "  -T:  Transpose and invert along y before printing the array\n"
        "       (so that a[i, j] gives longitude increasing with i and\n"
        "       latitude increasing with j).\n"
        "  -o:  Output subgrid data to a file. Detects output format based\n"
        "       on file extension. Supported: (.png, .stl). For a .png\n"
        "       extension, see \"PNG output options\" below. Otherwise,\n"
        "       gridfloat will assume you want to save another GridFloat\n"
        "       file. In this case, it will write the appropriate data\n"
        "       and header files, appending .flt and .hdr, respectively,\n"
        "       to the argument of -o.\n"
        "\n"
        "PNG output options:\n"
        "  When png output is specified, gridfloat automatically renders\n"
        "  a shaded relief map. The following options determine which\n"
        "  slopes are sunny.\n"
        "\n"
        "  -A:  Azimuthal angle (in degrees) of view toward sun (for\n"
        "       relief shading). 0 means sun is East, 90 North, etc.\n"
        "       Default: 45 (NE).\n"
        "  -P:  Polar angle (in degrees) of view toward sun (for\n"
        "       relief shading). 0 means sun is on horizon, 90 when\n"
        "       directly overhead. Default: 30.\n"
        "\n"
        "Examples:\n"
        "  All of the following are equivalent and simply print data\n"
        "  to stdout.\n"
        "\n"
        "  gridfloat -l -123 -r -122 -b 42 -t 43 file.{hdr,flt}\n"
        "  gridfloat -B -123,-122,42,43 file.{hdr,flt}\n"
        "  gridfloat -p -122.5,42.5 -s 1 file.{hdr,flt}\n"
        "  gridfloat -w 122.5 -n 42.5 -s 1x1 file.{hdr,flt}\n"
        "\n"
    );
}


repo: bauerca/gridfloat

original_code:
int gf_bilinear_interpolate_kernel(gf_float *quad, const gf_grid *from_grid, double *w, double *latlng, void *xtras, void *data_ptr) {
    gf_float *dptr = (gf_float *)data_ptr;
    dptr[0] = (1.0 - w[0]) * (1.0 - w[1]) * quad[0] +
              (1.0 - w[0]) * w[1] * quad[1] +
                     w[0] * (1.0 - w[1]) * quad[2] +
                     w[0] * w[1] * quad[3];
    return 0;
}

canonical_original_code:
int gf_bilinear_interpolate_kernel(float *quad, struct gf_grid *from_grid, double *w, double *latlng, void *xtras, void *data_ptr) {
    float *dptr = (gf_float *)data_ptr;
    dptr[0] = (1.0 - w[0]) * (1.0 - w[1]) * quad[0] +
              (1.0 - w[0]) * w[1] * quad[1] +
                     w[0] * (1.0 - w[1]) * quad[2] +
                     w[0] * w[1] * quad[3];
    return 0;
}

variable_types:
quad
float *

variable_types: struct gf_grid { int nx; int ny; double dx; double dy; double left; double right; double bottom; double top; } *

variable_types:
w
double *

variable_types:
latlng
double *

variable_types:
xtras
void *

variable_types:
dptr
float *

return_type: int


original_code:
int gf_bilinear_gradient_kernel(gf_float *quad, const gf_grid *from_grid, double *w, double *latlng, void *xtras, void *data_ptr) {
    double *grad_ptr = (double *)data_ptr;
    double dx_m = -1, dy_m = -1;
    gf_lengths(latlng[0], latlng[1], from_grid->dy, from_grid->dx, 0.0, &dy_m, &dx_m);
    grad_ptr[0] = (((1.0 - w[0]) * quad[1] + w[0] * quad[3]) -
                   ((1.0 - w[0]) * quad[0] + w[0] * quad[2])) / dx_m;
    grad_ptr[1] = (((1.0 - w[1]) * quad[0] + w[1] * quad[2]) -
                   ((1.0 - w[1]) * quad[1] + w[1] * quad[3])) / dy_m;
    return 0;
}

canonical_original_code:
int gf_bilinear_gradient_kernel(float *quad, struct gf_grid *from_grid, double *w, double *latlng, void *xtras, void *data_ptr) {
    double *grad_ptr = (double *)data_ptr;
    double dx_m = -1; double dy_m = -1;
    gf_lengths(latlng[0], latlng[1], from_grid->dy, from_grid->dx, 0.0, &dy_m, &dx_m);
    grad_ptr[0] = (((1.0 - w[0]) * quad[1] + w[0] * quad[3]) -
                   ((1.0 - w[0]) * quad[0] + w[0] * quad[2])) / dx_m;
    grad_ptr[1] = (((1.0 - w[1]) * quad[0] + w[1] * quad[2]) -
                   ((1.0 - w[1]) * quad[1] + w[1] * quad[3])) / dy_m;
    return 0;
}

user_defined_types: struct gf_grid { int nx; int ny; double dx; double dy; double left; double right; double bottom; double top; }


original_code:
static
void calc_normal(float v1[3], float v2[3], float v3[3], float normal[3]) {
    int i;
    float vec1[3], vec2[3];
    float norm;
    for (i = 0; i < 3; i++) {
        vec1[i] = v2[i] - v1[i];
        vec2[i] = v3[i] - v1[i];
    }
    normal[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
    normal[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
    normal[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
    norm = sqrt(
        normal[0] * normal[0] +
        normal[1] * normal[1] +
        normal[2] * normal[2]);
    for (i = 0; i < 3; i++) {
        normal[i] /= norm;
    }
}

canonical_original_code:
static void calc_normal(float v1[3], float v2[3], float v3[3], float normal[3]) {
    int i;
    float vec1[3]; float vec2[3];
    float norm;
    for (i = 0; i < 3; i++) {
        vec1[i] = v2[i] - v1[i];
        vec2[i] = v3[i] - v1[i];
    }
    normal[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
    normal[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
    normal[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
    norm = sqrt(
        normal[0] * normal[0] +
        normal[1] * normal[1] +
        normal[2] * normal[2]);
    for (i = 0; i < 3; i++) {
        normal[i] /= norm;
    }
}

variable_types:
normal
float [3]

variable_types: i int

variable_types: norm float

return_type: void


repo: bblum/landslide

decompiled_code:
int __fastcall open_fifo(__int64 a1, const char *a2, int a3)
{
int result; // eax

*(_QWORD *)(a1 + 8) = a2;
result = open(a2, a3 | 0x80000);
*(_DWORD *)a1 = result;
if ( result < 0 )
_assert_fail("f->fd >= 0 && \"failed open fifo file\"", "io.c", 0x7Eu, "open_fifo");
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, const char *a2, int a3)
{
int result; // eax

*(_QWORD *)(a1 + 8) = a2;
result = open(a2, a3 | 0x80000);
*(_DWORD *)a1 = result;
if ( result < 0 )
_assert_fail("f->fd >= 0 && \"failed open fifo file\"", "io.c", 0x7Eu, "open_fifo");
return result;
}

original_code:
void open_fifo(struct file *f, char *name, int flags)
{
 f->filename = name;
 f->fd = open(f->filename, flags | 02000000);
 ((f->fd >= 0 && "failed open fifo file") ? (void) (0) : __assert_fail ("f->fd >= 0 && \"failed open fifo file\"", "io.c", 126, __extension__ __PRETTY_FUNCTION__));
}

variable_types: struct file { int fd; char *filename; } *

variable_types:
name
char *

variable_types: flags int


decompiled_code:
int __fastcall unset_cloexec(int fd)
{
int v1; // eax
int result; // eax

v1 = fcntl(fd, 1);
if ( v1 == -1 )
_assert_fail("flags != -1 && \"couldn't get flags to unset cloexec\"", "io.c", 0x8Du, "unset_cloexec");
result = fcntl(fd, 2, v1 & 0xFFF7FFFF);
if ( result )
_assert_fail("result == 0 && \"couldn't set flags to unset cloexec\"", "io.c", 0x8Fu, "unset_cloexec");
return result;
}

canonical_decompiled_code:
int __fastcall func1(int fd)
{
int v1; // eax
int result; // eax

v1 = fcntl(fd, 1);
if ( v1 == -1 )
_assert_fail("flags != -1 && \"couldn't get flags to unset cloexec\"", "io.c", 0x8Du, "unset_cloexec");
result = fcntl(fd, 2, v1 & 0xFFF7FFFF);
if ( result )
_assert_fail("result == 0 && \"couldn't set flags to unset cloexec\"", "io.c", 0x8Fu, "unset_cloexec");
return result;
}

original_code:
void unset_cloexec(int fd)
{
 int flags = fcntl(fd, 1);
 ((flags != -1 && "couldn't get flags to unset cloexec") ? (void) (0) : __assert_fail ("flags != -1 && \"couldn't get flags to unset cloexec\"", "io.c", 141, __extension__ __PRETTY_FUNCTION__));
 int result = fcntl(fd, 2, flags & ~02000000);
 ((result == 0 && "couldn't set flags to unset cloexec") ? (void) (0) : __assert_fail ("result == 0 && \"couldn't set flags to unset cloexec\"", "io.c", 143, __extension__ __PRETTY_FUNCTION__));
}

variable_types: fd int

variable_types: result int


decompiled_code:
void log_msg(const char *a1, const char *a2, ...)
{
size_t v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[256]; // [rsp+20h] [rbp-2B8h] BYREF
char buf[256]; // [rsp+120h] [rbp-1B8h] BYREF

if ( logging_inited && logging_active )
{
va_start(arg, a2);
vsnprintf(s, 0x100uLL, a2, arg);
if ( a1 )
snprintf(buf, 0x100uLL, "[%s] %s", a1, s);
else
snprintf(buf, 0x100uLL, "%s", s);
v2 = strlen(buf);
if ( (int)write(log_file, buf, v2) < 0 )
fwrite("\x1B[01m\x1B[31mWARNING: couldn't write to log file\n", 1uLL, 0x2EuLL, stderr);
}
}

canonical_decompiled_code:
void func2(const char *a1, const char *a2, ...)
{
size_t v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[256]; // [rsp+20h] [rbp-2B8h] BYREF
char buf[256]; // [rsp+120h] [rbp-1B8h] BYREF

if ( logging_inited && logging_active )
{
va_start(arg, a2);
vsnprintf(s, 0x100uLL, a2, arg);
if ( a1 )
snprintf(buf, 0x100uLL, "[%s] %s", a1, s);
else
snprintf(buf, 0x100uLL, "%s", s);
v2 = strlen(buf);
if ( (int)write(log_file, buf, v2) < 0 )
fwrite("\x1B[01m\x1B[31mWARNING: couldn't write to log file\n", 1uLL, 0x2EuLL, stderr);
}
}

original_code:
void log_msg(const char *pfx, const char *format, ...)
{
 if (logging_inited && logging_active) {
  va_list ap;
  char line_buf[256];
  char line_buf2[256];
  __builtin_va_start(ap,format);
  vsnprintf(line_buf, 256, format, ap);
  __builtin_va_end(ap);
  if (pfx != ((void *)0)) {
   snprintf(line_buf2, 256, "[%s] %s", pfx, line_buf);
  } else {
   snprintf(line_buf2, 256, "%s", line_buf);
  }
  int ret = write(log_file.fd, line_buf2, strlen(line_buf2));
  if (ret < 0) {
   fprintf(stderr, "\033[01m" "\033[31m"
    "WARNING: couldn't write to log file\n");
  }
 }
}

canonical_original_code:
void log_msg(char *pfx, char *format, ...)
{
 if (logging_inited && logging_active) {
  __builtin_va_list ap;
  char line_buf[256];
  char line_buf2[256];
  __builtin_va_start(ap,format);
  vsnprintf(line_buf, 256, format, ap);
  __builtin_va_end(ap);
  if (pfx != ((void *)0)) {
   snprintf(line_buf2, 256, "[%s] %s", pfx, line_buf);
  } else {
   snprintf(line_buf2, 256, "%s", line_buf);
  }
  int ret = write(log_file.fd, line_buf2, strlen(line_buf2));
  if (ret < 0) {
   fprintf(stderr, "\033[01m" "\033[31m"
    "WARNING: couldn't write to log file\n");
  }
 }
}

variable_types:
pfx
char *

variable_types:
format
char *

variable_types: ret int


decompiled_code:
void __fastcall delete_file(unsigned int *a1, char a2)
{
int v2; // ebp
int *v3; // rax
int *v4; // r13
int v5; // ebp
char *v6; // rax
char *v7; // rax
int v8; // ebp
char *v9; // rax
char *v10; // rax

if ( !*((_QWORD *)a1 + 1) )
_assert_fail("f->filename != NULL", "io.c", 0x58u, "delete_file");
v2 = close(*a1);
v3 = _errno_location();
v4 = v3;
if ( v2 )
{
v5 = *v3;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed close fd %d\n", *a1);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "failed close fd %d\n", *a1);
v6 = strerror(v5);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v6);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v7 = strerror(v5);
log_msg("ERR", "Error: %s\n", v7);
}
if ( a2 && remove(*((const char **)a1 + 1)) )
{
v8 = *v4;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed remove '%s'\n", *((const char **)a1 + 1));
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "failed remove '%s'\n", *((const char **)a1 + 1));
v9 = strerror(v8);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v9);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v10 = strerror(v8);
log_msg("ERR", "Error: %s\n", v10);
}
free(*((void **)a1 + 1));
*((_QWORD *)a1 + 1) = 0LL;
}

canonical_decompiled_code:
void __fastcall func4(unsigned int *a1, char a2)
{
int v2; // ebp
int *v3; // rax
int *v4; // r13
int v5; // ebp
char *v6; // rax
char *v7; // rax
int v8; // ebp
char *v9; // rax
char *v10; // rax

if ( !*((_QWORD *)a1 + 1) )
_assert_fail("f->filename != NULL", "io.c", 0x58u, "delete_file");
v2 = close(*a1);
v3 = _errno_location();
v4 = v3;
if ( v2 )
{
v5 = *v3;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed close fd %d\n", *a1);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "failed close fd %d\n", *a1);
v6 = strerror(v5);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v6);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v7 = strerror(v5);
func2("ERR", "Error: %s\n", v7);
}
if ( a2 && remove(*((const char **)a1 + 1)) )
{
v8 = *v4;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed remove '%s'\n", *((const char **)a1 + 1));
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "failed remove '%s'\n", *((const char **)a1 + 1));
v9 = strerror(v8);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v9);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v10 = strerror(v8);
func2("ERR", "Error: %s\n", v10);
}
free(*((void **)a1 + 1));
*((_QWORD *)a1 + 1) = 0LL;
}

original_code:
void delete_file(struct file *f, _Bool do_remove)
{
 ((f->filename != ((void *)0)) ? (void) (0) : __assert_fail ("f->filename != NULL", "io.c", 88, __extension__ __PRETTY_FUNCTION__));
 do { int __ret = close(f->fd); do { int __last_errno = (*__errno_location ()); if (!(__ret == 0)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == 0"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "failed close fd %d\n", f->fd); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed close fd %d\n", f->fd); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); } while (0);
 if (do_remove) {
  do { int __ret = remove(f->filename); do { int __last_errno = (*__errno_location ()); if (!(__ret == 0)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == 0"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "failed remove '%s'\n", (f->filename)); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed remove '%s'\n", (f->filename)); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); } while (0);
 }
 free(f->filename);
 f->filename = ((void *)0);
}


decompiled_code:
char *__fastcall create_fifo(const char *a1, unsigned int a2)
{
__int64 v2; // rax
int v3; // ebp
int v4; // er13
char *v5; // rbx
int *v6; // rax
int *v7; // r12
int v8; // eax
int *v10; // rbx
char *v11; // rax
char *v12; // rax
int v13; // er15
char *v14; // rax
char *v15; // rax
int v16; // ebp
char *v17; // rax
char *v18; // rax
char v19[312]; // [rsp+0h] [rbp-138h] BYREF

v2 = timestamp();
snprintf(v19, 0x100uLL, "/dev/shm/%s-%u-%lu.fifo", a1, a2, v2);
if ( mkfifo(v19, 0x1C0u) )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "\x1B[01m\x1B[31mfailed to create a fifo file for communication with landslide: %s\n", v11);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v12 = strerror(*v10);
log_msg("ERR", "failed to create a fifo file for communication with landslide: %s\n", v12);
_assert_fail("ret == 0 && \"failed create fifo file\"", "io.c", 0x72u, "create_fifo");
}
v3 = strlen(v19);
v4 = v3 + 1;
v5 = (char *)malloc(v3 + 1);
v6 = _errno_location();
v7 = v6;
if ( !v5 )
{
v13 = *v6;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[01m\x1B[31mmalloc failed", 1uLL, 0x17uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "malloc failed");
v14 = strerror(v13);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v14);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v15 = strerror(v13);
log_msg("ERR", "Error: %s\n", v15);
}
v8 = snprintf(v5, v4, "%s", v19);
if ( v4 <= v8 )
v8 = v3 + 1;
if ( v8 != v3 )
{
v16 = *v7;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == __len");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == __len");
fwrite("\x1B[01m\x1B[31mscprintf failed", 1uLL, 0x19uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "scprintf failed");
v17 = strerror(v16);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v17);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v18 = strerror(v16);
log_msg("ERR", "Error: %s\n", v18);
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func5(const char *a1, unsigned int a2)
{
__int64 v2; // rax
int v3; // ebp
int v4; // er13
char *v5; // rbx
int *v6; // rax
int *v7; // r12
int v8; // eax
int *v10; // rbx
char *v11; // rax
char *v12; // rax
int v13; // er15
char *v14; // rax
char *v15; // rax
int v16; // ebp
char *v17; // rax
char *v18; // rax
char v19[312]; // [rsp+0h] [rbp-138h] BYREF

v2 = timestamp();
snprintf(v19, 0x100uLL, "/dev/shm/%s-%u-%lu.fifo", a1, a2, v2);
if ( mkfifo(v19, 0x1C0u) )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "\x1B[01m\x1B[31mfailed to create a fifo file for communication with landslide: %s\n", v11);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v12 = strerror(*v10);
func2("ERR", "failed to create a fifo file for communication with landslide: %s\n", v12);
_assert_fail("ret == 0 && \"failed create fifo file\"", "io.c", 0x72u, "create_fifo");
}
v3 = strlen(v19);
v4 = v3 + 1;
v5 = (char *)malloc(v3 + 1);
v6 = _errno_location();
v7 = v6;
if ( !v5 )
{
v13 = *v6;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[01m\x1B[31mmalloc failed", 1uLL, 0x17uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "malloc failed");
v14 = strerror(v13);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v14);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v15 = strerror(v13);
func2("ERR", "Error: %s\n", v15);
}
v8 = snprintf(v5, v4, "%s", v19);
if ( v4 <= v8 )
v8 = v3 + 1;
if ( v8 != v3 )
{
v16 = *v7;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == __len");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__ret == __len");
fwrite("\x1B[01m\x1B[31mscprintf failed", 1uLL, 0x19uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "scprintf failed");
v17 = strerror(v16);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v17);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v18 = strerror(v16);
func2("ERR", "Error: %s\n", v18);
}
return v5;
}

original_code:
char *create_fifo(const char *prefix, unsigned int id)
{
 char buf[256];
 ({ int __snprintf_ret = snprintf((buf), (256), "/dev/shm/" "%s-%u-%lu.fifo", prefix, id, timestamp()); if (__snprintf_ret > (int)(256)) { __snprintf_ret = (256); } __snprintf_ret; });
 int ret = mkfifo(buf, 0700);
 if (ret != 0) {
  do { fprintf(stderr, "\033[01m" "\033[31m" "failed to create a fifo file for communication with " "landslide: %s\n", strerror((*__errno_location ()))); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed to create a fifo file for communication with " "landslide: %s\n", strerror((*__errno_location ()))); } while (0);
 }
 ((ret == 0 && "failed create fifo file") ? (void) (0) : __assert_fail ("ret == 0 && \"failed create fifo file\"", "io.c", 114, __extension__ __PRETTY_FUNCTION__));
 return ({ char *__s = (buf); __s == ((void *)0) ? ((void *)0) : ({ int __len = strlen(__s); char *__buf = ({ __typeof__(char) *__xmalloc_ptr = malloc((__len + 1) * sizeof(char)); do { int __last_errno = (*__errno_location ()); if (!(__xmalloc_ptr != ((void *)0))) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "malloc failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "malloc failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __xmalloc_ptr; }); int __ret = ({ int __snprintf_ret = snprintf((__buf), (__len + 1), "%s", __s); if (__snprintf_ret > (int)(__len + 1)) { __snprintf_ret = (__len + 1); } __snprintf_ret; }); do { int __last_errno = (*__errno_location ()); if (!(__ret == __len)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == __len"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == __len"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "scprintf failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "scprintf failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __buf; }); });
}

canonical_original_code:
char *create_fifo(char *prefix, unsigned int id)
{
 char buf[256];
 ({ int __snprintf_ret = snprintf((buf), (256), "/dev/shm/" "%s-%u-%lu.fifo", prefix, id, timestamp()); if (__snprintf_ret > (int)(256)) { __snprintf_ret = (256); } __snprintf_ret; });
 int ret = mkfifo(buf, 0700);
 if (ret != 0) {
  do { fprintf(stderr, "\033[01m" "\033[31m" "failed to create a fifo file for communication with " "landslide: %s\n", strerror((*__errno_location ()))); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed to create a fifo file for communication with " "landslide: %s\n", strerror((*__errno_location ()))); } while (0);
 }
 ((ret == 0 && "failed create fifo file") ? (void) (0) : __assert_fail ("ret == 0 && \"failed create fifo file\"", "io.c", 114, __extension__ __PRETTY_FUNCTION__));
 return ({ char *__s = (buf); __s == ((void *)0) ? ((void *)0) : ({ int __len = strlen(__s); char *__buf = ({ __typeof__(char) *__xmalloc_ptr = malloc((__len + 1) * sizeof(char)); do { int __last_errno = (*__errno_location ()); if (!(__xmalloc_ptr != ((void *)0))) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "malloc failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "malloc failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __xmalloc_ptr; }); int __ret = ({ int __snprintf_ret = snprintf((__buf), (__len + 1), "%s", __s); if (__snprintf_ret > (int)(__len + 1)) { __snprintf_ret = (__len + 1); } __snprintf_ret; }); do { int __last_errno = (*__errno_location ()); if (!(__ret == __len)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == __len"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == __len"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "scprintf failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "scprintf failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __buf; }); });
}

variable_types:
prefix
char *

variable_types:
id
unsigned int

variable_types:
buf
char [256]

return_type: char *


decompiled_code:
void __fastcall delete_unused_fifo(void *ptr)
{
int v1; // ebp
char *v2; // rax
char *v3; // rax

if ( remove((const char *)ptr) )
{
v1 = *_errno_location();
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed remove '%s'\n", (const char *)ptr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "failed remove '%s'\n", (const char *)ptr);
v2 = strerror(v1);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v2);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v3 = strerror(v1);
log_msg("ERR", "Error: %s\n", v3);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
int v1; // ebp
char *v2; // rax
char *v3; // rax

if ( remove((const char *)ptr) )
{
v1 = *_errno_location();
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed remove '%s'\n", (const char *)ptr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "failed remove '%s'\n", (const char *)ptr);
v2 = strerror(v1);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v2);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v3 = strerror(v1);
func2("ERR", "Error: %s\n", v3);
}
free(ptr);
}

original_code:
void delete_unused_fifo(char *name)
{
 do { int __ret = remove(name); do { int __last_errno = (*__errno_location ()); if (!(__ret == 0)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == 0"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "failed remove '%s'\n", (name)); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed remove '%s'\n", (name)); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); } while (0);
 free(name);
}


decompiled_code:
void __fastcall move_file_to(__int64 a1, const char *a2)
{
int v2; // ebp
size_t v3; // r14
char *v4; // rbp
int *v5; // rax
int *v6; // r13
int v7; // er15
char *v8; // rax
char *v9; // rax
int v10; // er12
char *v11; // rax
char *v12; // rax

v2 = strlen(*(const char **)(a1 + 8));
v3 = v2 + (unsigned int)strlen(a2) + 2;
v4 = (char *)malloc(v3);
v5 = _errno_location();
v6 = v5;
if ( !v4 )
{
v7 = *v5;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[01m\x1B[31mmalloc failed", 1uLL, 0x17uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "malloc failed");
v8 = strerror(v7);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v8);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v9 = strerror(v7);
log_msg("ERR", "Error: %s\n", v9);
}
snprintf(v4, v3, "%s/%s", a2, *(const char **)(a1 + 8));
if ( rename(*(const char **)(a1 + 8), v4) )
{
v10 = *v6;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed rename '%s' to '%s'\n", *(const char **)(a1 + 8), v4);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "failed rename '%s' to '%s'\n", *(const char **)(a1 + 8), v4);
v11 = strerror(v10);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v11);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v12 = strerror(v10);
log_msg("ERR", "Error: %s\n", v12);
}
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = v4;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, const char *a2)
{
int v2; // ebp
size_t v3; // r14
char *v4; // rbp
int *v5; // rax
int *v6; // r13
int v7; // er15
char *v8; // rax
char *v9; // rax
int v10; // er12
char *v11; // rax
char *v12; // rax

v2 = strlen(*(const char **)(a1 + 8));
v3 = v2 + (unsigned int)strlen(a2) + 2;
v4 = (char *)malloc(v3);
v5 = _errno_location();
v6 = v5;
if ( !v4 )
{
v7 = *v5;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[01m\x1B[31mmalloc failed", 1uLL, 0x17uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "malloc failed");
v8 = strerror(v7);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v8);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v9 = strerror(v7);
func2("ERR", "Error: %s\n", v9);
}
snprintf(v4, v3, "%s/%s", a2, *(const char **)(a1 + 8));
if ( rename(*(const char **)(a1 + 8), v4) )
{
v10 = *v6;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed rename '%s' to '%s'\n", *(const char **)(a1 + 8), v4);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "failed rename '%s' to '%s'\n", *(const char **)(a1 + 8), v4);
v11 = strerror(v10);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v11);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v12 = strerror(v10);
func2("ERR", "Error: %s\n", v12);
}
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = v4;
}

original_code:
void move_file_to(struct file *f, const char *dirpath)
{
 unsigned int length = strlen(f->filename) + strlen(dirpath) + 2;
 char *new_filename = ({ __typeof__(char) *__xmalloc_ptr = malloc((length) * sizeof(char)); do { int __last_errno = (*__errno_location ()); if (!(__xmalloc_ptr != ((void *)0))) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "malloc failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "malloc failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __xmalloc_ptr; });
 ({ int __snprintf_ret = snprintf((new_filename), (length), "%s/%s", dirpath, f->filename); if (__snprintf_ret > (int)(length)) { __snprintf_ret = (length); } __snprintf_ret; });
 do { int __ret = rename((f->filename), (new_filename)); do { int __last_errno = (*__errno_location ()); if (!(__ret == 0)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == 0"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "failed rename '%s' to '%s'\n", (f->filename), (new_filename)); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed rename '%s' to '%s'\n", (f->filename), (new_filename)); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); } while (0);
 free(f->filename);
 f->filename = new_filename;
}

canonical_original_code:
void move_file_to(struct file *f, char *dirpath)
{
 unsigned int length = strlen(f->filename) + strlen(dirpath) + 2;
 char *new_filename = ({ __typeof__(char) *__xmalloc_ptr = malloc((length) * sizeof(char)); do { int __last_errno = (*__errno_location ()); if (!(__xmalloc_ptr != ((void *)0))) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "malloc failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "malloc failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __xmalloc_ptr; });
 ({ int __snprintf_ret = snprintf((new_filename), (length), "%s/%s", dirpath, f->filename); if (__snprintf_ret > (int)(length)) { __snprintf_ret = (length); } __snprintf_ret; });
 do { int __ret = rename((f->filename), (new_filename)); do { int __last_errno = (*__errno_location ()); if (!(__ret == 0)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == 0"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "failed rename '%s' to '%s'\n", (f->filename), (new_filename)); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed rename '%s' to '%s'\n", (f->filename), (new_filename)); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); } while (0);
 free(f->filename);
 f->filename = new_filename;
}

variable_types:
dirpath
char *

variable_types:
length
unsigned int


decompiled_code:
void __fastcall set_logging_options(char a1, const char *a2, const char *a3)
{
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

if ( logging_inited )
_assert_fail("!logging_inited && \"double log init\"", "io.c", 0xA4u, "set_logging_options");
logging_inited = 1;
logging_active = a1;
if ( a1 )
{
snprintf(v4, 0x100uLL, "%s.XXXXXX", a2);
create_file((__int64)&log_file, v4);
if ( *a3 )
move_file_to((__int64)&log_file, a3);
}
}

canonical_decompiled_code:
void __fastcall func8(char a1, const char *a2, const char *a3)
{
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

if ( logging_inited )
_assert_fail("!logging_inited && \"double log init\"", "io.c", 0xA4u, "set_logging_options");
logging_inited = 1;
logging_active = a1;
if ( a1 )
{
snprintf(v4, 0x100uLL, "%s.XXXXXX", a2);
func3((__int64)&log_file, v4);
if ( *a3 )
func7((__int64)&log_file, a3);
}
}

original_code:
void set_logging_options(_Bool use_log, char *filename, const char *log_dir)
{
 ((!logging_inited && "double log init") ? (void) (0) : __assert_fail ("!logging_inited && \"double log init\"", "io.c", 164, __extension__ __PRETTY_FUNCTION__));
 logging_inited = 1;
 if ((logging_active = use_log)) {
  char log_filename[256];
  ({ int __snprintf_ret = snprintf((log_filename), (256), "%s.XXXXXX", filename); if (__snprintf_ret > (int)(256)) { __snprintf_ret = (256); } __snprintf_ret; });
  create_file(&log_file, log_filename);
  if (log_dir[0] != 0) {
   move_file_to(&log_file, log_dir);
  }
 }
}

canonical_original_code:
void set_logging_options(_Bool use_log, char *filename, char *log_dir)
{
 ((!logging_inited && "double log init") ? (void) (0) : __assert_fail ("!logging_inited && \"double log init\"", "io.c", 164, __extension__ __PRETTY_FUNCTION__));
 logging_inited = 1;
 if ((logging_active = use_log)) {
  char log_filename[256];
  ({ int __snprintf_ret = snprintf((log_filename), (256), "%s.XXXXXX", filename); if (__snprintf_ret > (int)(256)) { __snprintf_ret = (256); } __snprintf_ret; });
  create_file(&log_file, log_filename);
  if (log_dir[0] != 0) {
   move_file_to(&log_file, log_dir);
  }
 }
}

variable_types:
filename
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rsi
unsigned __int64 v12; // rdi
unsigned __int64 v13; // rbx
unsigned __int64 v14; // rbp
unsigned __int64 v15; // rax
unsigned __int64 v16; // rdx
unsigned __int64 v17; // rbp
const char *v19; // rbx
__int64 v20; // rax
__int64 v21; // rax
__int64 v22; // rax
__int64 v23; // rax
char v24[56]; // [rsp+20h] [rbp-388h] BYREF
__int64 v25; // [rsp+58h] [rbp-350h] BYREF
unsigned __int8 v26; // [rsp+65h] [rbp-343h] BYREF
unsigned __int8 v27; // [rsp+66h] [rbp-342h] BYREF
unsigned __int8 v28; // [rsp+67h] [rbp-341h] BYREF
unsigned __int8 v29; // [rsp+68h] [rbp-340h] BYREF
unsigned __int8 v30; // [rsp+69h] [rbp-33Fh] BYREF
unsigned __int8 v31; // [rsp+6Ah] [rbp-33Eh] BYREF
unsigned __int8 v32; // [rsp+6Bh] [rbp-33Dh] BYREF
unsigned __int8 v33; // [rsp+6Ch] [rbp-33Ch] BYREF
unsigned __int8 v34; // [rsp+6Dh] [rbp-33Bh] BYREF
unsigned __int8 v35; // [rsp+6Eh] [rbp-33Ah] BYREF
unsigned __int8 v36; // [rsp+6Fh] [rbp-339h] BYREF
char v37[269]; // [rsp+70h] [rbp-338h] BYREF
unsigned __int8 v38; // [rsp+17Dh] [rbp-22Bh] BYREF
unsigned __int8 v39; // [rsp+17Eh] [rbp-22Ah] BYREF
unsigned __int8 v40; // [rsp+17Fh] [rbp-229h] BYREF
unsigned __int64 v41; // [rsp+180h] [rbp-228h] BYREF
__int64 v42; // [rsp+188h] [rbp-220h] BYREF
char v43[256]; // [rsp+190h] [rbp-218h] BYREF
char haystack[280]; // [rsp+290h] [rbp-118h] BYREF

if ( !(unsigned __int8)get_options(
argc,
argv,
haystack,
256LL,
&v42,
&v41,
&v40,
&v39,
&control_experiment,
&v38,
v37,
256LL,
&v36,
&v34,
&v33,
&v32,
&avoid_recompile,
&v31,
&v30,
&v29,
&v28,
&v27,
&v26,
&v35,
&v25,
v43,
256LL,
&eta_factor,
&eta_threshold) )
{
v19 = *argv;
if ( !strcmp(*argv, "./landslide-id") )
v19 = "./landslide";
usage(v19);
exit(2);
}
set_logging_options(v38, v37, v43);
if ( v40 )
{
fprintf(stderr, "\x1B[00m\x1B[36mwill run for at most %lu seconds\n", v42);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "will run for at most %lu seconds\n", v42);
set_job_options(haystack, v43, v40, v39, v36, v34, v33, v32, v31, v30, v29, v28, v27, v26, v35);
init_signal_handling();
start_time(1000000 * v42, (unsigned int)v41);
if ( !control_experiment && !v26 && haystack != strstr(haystack, "atomic_") )
{
v3 = create_pp_set(0LL);
v4 = new_job(v3, 0LL);
add_work(v4);
v5 = create_pp_set(4LL);
v6 = new_job(v5, 1LL);
add_work(v6);
v7 = create_pp_set(8LL);
v8 = new_job(v7, 1LL);
add_work(v8);
if ( (unsigned __int8)testing_pintos() )
{
v20 = create_pp_set(16LL);
v21 = new_job(v20, 1LL);
add_work(v21);
v22 = create_pp_set(32LL);
v23 = new_job(v22, 1LL);
add_work(v23);
}
}
v9 = create_pp_set(60LL);
v10 = new_job(v9, 1LL);
add_work(v10);
v11 = v25;
v12 = v41;
start_work(v41, v25);
wait_to_finish_work();
print_live_data_race_pps();
print_free_re_malloc_false_positives();
v13 = total_cpu_time();
v14 = 100 * (v13 / v41);
v15 = time_elapsed(v12, v11, v13 % v41);
v16 = v14 % v15;
v17 = v14 / v15;
human_friendly_time(v24, v11, v16);
printf("\x1B[01m\x1B[36mtotal CPU time consumed: ");
printf("\x1B[00m");
log_msg(0LL, "total CPU time consumed: ");
print_human_friendly_time(v24);
printf("\x1B[01m\x1B[36m (%lu usecs) (core saturation: %lu%%)\n", v13, v17);
printf("\x1B[00m");
log_msg(0LL, " (%lu usecs) (core saturation: %lu%%)\n", v13, v17);
return (unsigned __int8)found_any_bugs();
}

original_code:
int main(int argc, char **argv)
{
 char test_name[256];
 char trace_dir[256];
 unsigned long max_time;
 unsigned long num_cpus;
 _Bool verbose;
 _Bool leave_logs;
 _Bool use_wrapper_log;
 char wrapper_log[256];
 _Bool pintos;
 _Bool pathos;
 _Bool use_icb;
 _Bool preempt_everywhere;
 _Bool pure_hb;
 _Bool txn;
 _Bool txn_abort_codes;
 _Bool txn_dont_retry;
 _Bool txn_retry_sets;
 _Bool txn_weak_atomicity;
 _Bool verif_mode;
 unsigned long progress_interval;
 if (!get_options(argc, argv, test_name, 256, &max_time, &num_cpus,
    &verbose, &leave_logs, &control_experiment,
    &use_wrapper_log, wrapper_log, 256, &pintos,
    &use_icb, &preempt_everywhere, &pure_hb,
    &avoid_recompile,
    &txn, &txn_abort_codes, &txn_dont_retry,
    &txn_retry_sets, &txn_weak_atomicity,
    &verif_mode, &pathos, &progress_interval,
    trace_dir, 256, &eta_factor, &eta_threshold)) {
  usage(strcmp(argv[0], "./landslide-id") == 0 ? "./landslide" : argv[0]);
  exit(2);
 }
 set_logging_options(use_wrapper_log, wrapper_log, trace_dir);
 do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "will run for at most %lu seconds\n", max_time); fprintf(stderr, "\033[00m"); } log_msg("DBG", "will run for at most %lu seconds\n", max_time); } while (0);
 set_job_options(test_name, trace_dir, verbose, leave_logs, pintos, use_icb, preempt_everywhere, pure_hb, txn, txn_abort_codes, txn_dont_retry, txn_retry_sets, txn_weak_atomicity, verif_mode, pathos);
 init_signal_handling();
 start_time(max_time * 1000000, num_cpus);
 if (!control_experiment && !verif_mode &&
     !(strstr(test_name, "atomic_") == test_name)) {
  add_work(new_job(create_pp_set(((unsigned int)0x00)), 0));
  add_work(new_job(create_pp_set(((unsigned int)0x04)), 1));
  add_work(new_job(create_pp_set(((unsigned int)0x08)), 1));
  if (testing_pintos()) {
   add_work(new_job(create_pp_set(((unsigned int)0x10)), 1));
   add_work(new_job(create_pp_set(((unsigned int)0x20)), 1));
  }
 }
 add_work(new_job(create_pp_set(((unsigned int)0x04) | ((unsigned int)0x08) | ((unsigned int)0x10) | ((unsigned int)0x20)), 1));
 start_work(num_cpus, progress_interval);
 wait_to_finish_work();
 print_live_data_race_pps();
 print_free_re_malloc_false_positives();
 unsigned long cputime = total_cpu_time();
 unsigned long saturation = (cputime / num_cpus) * 100 / time_elapsed();
 struct human_friendly_time cputime_hft;
 human_friendly_time(cputime, &cputime_hft);
 do { printf("\033[01m" "\033[36m" "total CPU time consumed: "); printf("\033[00m"); log_msg(((void *)0), "total CPU time consumed: "); } while (0);
 print_human_friendly_time(&cputime_hft);
 do { printf("\033[01m" "\033[36m" " (%lu usecs) (core saturation: %lu%%)\n", cputime, saturation); printf("\033[00m"); log_msg(((void *)0), " (%lu usecs) (core saturation: %lu%%)\n", cputime, saturation); } while (0);
 return found_any_bugs() ? 1 : 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
cputime
unsigned long

variable_types:
saturation
unsigned long

variable_types: struct human_friendly_time { unsigned long secs; _Bool inf; }


decompiled_code:
void __noreturn handle_sigint()
{
unsigned int v0; // eax
unsigned int v1; // ebx

v0 = syscall(186LL);
v1 = v0;
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36mctrl-C press handled by thread %u\n", v0);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "ctrl-C press handled by thread %u\n", v1);
fwrite("\x1B[01m\x1B[31mctrl-C pressed, aborting...\n", 1uLL, 0x26uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "ctrl-C pressed, aborting...\n");
try_print_live_data_race_pps();
fwrite("\x1B[01m\x1B[33m\n", 1uLL, 0xBuLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("WARN", "\n");
fwrite(
"\x1B[01m\x1B[33msome landslide processes may be left hanging; please 'killall bochs'.\n",
1uLL,
0x50uLL,
stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("WARN", "some landslide processes may be left hanging; please 'killall bochs'.\n");
exit(3);
}

canonical_decompiled_code:
void __noreturn func0()
{
unsigned int v0; // eax
unsigned int v1; // ebx

v0 = syscall(186LL);
v1 = v0;
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36mctrl-C press handled by thread %u\n", v0);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "ctrl-C press handled by thread %u\n", v1);
fwrite("\x1B[01m\x1B[31mctrl-C pressed, aborting...\n", 1uLL, 0x26uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "ctrl-C pressed, aborting...\n");
try_print_live_data_race_pps();
fwrite("\x1B[01m\x1B[33m\n", 1uLL, 0xBuLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("WARN", "\n");
fwrite(
"\x1B[01m\x1B[33msome landslide processes may be left hanging; please 'killall bochs'.\n",
1uLL,
0x50uLL,
stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("WARN", "some landslide processes may be left hanging; please 'killall bochs'.\n");
exit(3);
}

original_code:
static void handle_sigint(int __attribute__((unused)) signum)
{
 pid_t me = syscall(186);
 do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "ctrl-C press handled by thread %u\n", me); fprintf(stderr, "\033[00m"); } log_msg("DBG", "ctrl-C press handled by thread %u\n", me); } while (0);
 do { fprintf(stderr, "\033[01m" "\033[31m" "ctrl-C pressed, aborting...\n"); fprintf(stderr, "\033[00m"); log_msg("ERR", "ctrl-C pressed, aborting...\n"); } while (0);
 try_print_live_data_race_pps();
 do { fprintf(stderr, "\033[01m" "\033[33m" "\n"); fprintf(stderr, "\033[00m"); log_msg("WARN", "\n"); } while (0);
 do { fprintf(stderr, "\033[01m" "\033[33m" "some landslide processes may be left hanging; please 'killall bochs'.\n"); fprintf(stderr, "\033[00m"); log_msg("WARN", "some landslide processes may be left hanging; please 'killall bochs'.\n"); } while (0);
 exit(3);
}

canonical_original_code:
static void handle_sigint(int signum)
{
 int me = syscall(186);
 do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "ctrl-C press handled by thread %u\n", me); fprintf(stderr, "\033[00m"); } log_msg("DBG", "ctrl-C press handled by thread %u\n", me); } while (0);
 do { fprintf(stderr, "\033[01m" "\033[31m" "ctrl-C pressed, aborting...\n"); fprintf(stderr, "\033[00m"); log_msg("ERR", "ctrl-C pressed, aborting...\n"); } while (0);
 try_print_live_data_race_pps();
 do { fprintf(stderr, "\033[01m" "\033[33m" "\n"); fprintf(stderr, "\033[00m"); log_msg("WARN", "\n"); } while (0);
 do { fprintf(stderr, "\033[01m" "\033[33m" "some landslide processes may be left hanging; please 'killall bochs'.\n"); fprintf(stderr, "\033[00m"); log_msg("WARN", "some landslide processes may be left hanging; please 'killall bochs'.\n"); } while (0);
 exit(3);
}

variable_types: signum int

variable_types: me int


decompiled_code:
__int64 init_signal_handling()
{
unsigned int v0; // eax
unsigned int v1; // ebx
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = (__sighandler_t)handle_sigint;
sigemptyset(&v3.sa_mask);
if ( sigaction(2, &v3, 0LL) )
_assert_fail("ret == 0 && \"failed init signal handling\"", "signals.c", 0x3Eu, "init_signal_handling");
v0 = syscall(186LL);
v1 = v0;
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36msignal handling inited by thread %u\n", v0);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
return log_msg("DBG", "signal handling inited by thread %u\n", v1);
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // eax
unsigned int v1; // ebx
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = (__sighandler_t)handle_sigint;
sigemptyset(&v3.sa_mask);
if ( sigaction(2, &v3, 0LL) )
_assert_fail("ret == 0 && \"failed init signal handling\"", "signals.c", 0x3Eu, "init_signal_handling");
v0 = syscall(186LL);
v1 = v0;
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36msignal handling inited by thread %u\n", v0);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
return log_msg("DBG", "signal handling inited by thread %u\n", v1);
}

original_code:
void init_signal_handling()
{
 struct sigaction act;
 act.__sigaction_handler.sa_handler = handle_sigint;
 sigemptyset(&act.sa_mask);
 int ret = sigaction(2, &act, ((void *)0));
 ((ret == 0 && "failed init signal handling") ? (void) (0) : __assert_fail ("ret == 0 && \"failed init signal handling\"", "signals.c", 62, __extension__ __PRETTY_FUNCTION__));
 pid_t me = syscall(186);
 do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "signal handling inited by thread %u\n", me); fprintf(stderr, "\033[00m"); } log_msg("DBG", "signal handling inited by thread %u\n", me); } while (0);
}

canonical_original_code:
void init_signal_handling()
{
 struct sigaction act;
 act.__sigaction_handler.sa_handler = handle_sigint;
 sigemptyset(&act.sa_mask);
 int ret = sigaction(2, &act, ((void *)0));
 ((ret == 0 && "failed init signal handling") ? (void) (0) : __assert_fail ("ret == 0 && \"failed init signal handling\"", "signals.c", 62, __extension__ __PRETTY_FUNCTION__));
 int me = syscall(186);
 do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "signal handling inited by thread %u\n", me); fprintf(stderr, "\033[00m"); } log_msg("DBG", "signal handling inited by thread %u\n", me); } while (0);
}

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


timestamp

decompiled_code:
__suseconds_t timestamp()
{
int v1; // ebx
char *v2; // rax
char *v3; // rax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v4, 0LL) )
{
v1 = *_errno_location();
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[01m\x1B[31mfailed gettimeofday", 1uLL, 0x1DuLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "failed gettimeofday");
v2 = strerror(v1);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v2);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v3 = strerror(v1);
log_msg("ERR", "Error: %s\n", v3);
}
return v4.tv_usec + 1000000 * v4.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func0()
{
int v1; // ebx
char *v2; // rax
char *v3; // rax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v4, 0LL) )
{
v1 = *_errno_location();
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[01m\x1B[31mfailed gettimeofday", 1uLL, 0x1DuLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "failed gettimeofday");
v2 = strerror(v1);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v2);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v3 = strerror(v1);
log_msg("ERR", "Error: %s\n", v3);
}
return v4.tv_usec + 1000000 * v4.tv_sec;
}

original_code:
unsigned long timestamp()
{
 struct timeval tv;
 do { int __ret = gettimeofday((&tv), ((void *)0)); do { int __last_errno = (*__errno_location ()); if (!(__ret == 0)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == 0"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "failed gettimeofday"); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed gettimeofday"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); } while (0);
 return (unsigned long)((tv.tv_sec * 1000000) + tv.tv_usec);
}

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

return_type: unsigned long


decompiled_code:
unsigned __int64 time_elapsed()
{
unsigned __int64 v0; // rax

if ( !start_timestamp )
_assert_fail("start_timestamp != 0", "time.c", 0x4Eu, "time_elapsed");
v0 = timestamp();
if ( start_timestamp > v0 )
_assert_fail("now >= start_timestamp && \"travelled back in time??\"", "time.c", 0x50u, "time_elapsed");
return v0 - start_timestamp;
}

canonical_decompiled_code:
unsigned __int64 func2()
{
unsigned __int64 v0; // rax

if ( !start_timestamp )
_assert_fail("start_timestamp != 0", "time.c", 0x4Eu, "time_elapsed");
v0 = func0();
if ( start_timestamp > v0 )
_assert_fail("now >= start_timestamp && \"travelled back in time??\"", "time.c", 0x50u, "time_elapsed");
return v0 - start_timestamp;
}

original_code:
unsigned long time_elapsed()
{
 ((start_timestamp != 0) ? (void) (0) : __assert_fail ("start_timestamp != 0", "time.c", 78, __extension__ __PRETTY_FUNCTION__));
 unsigned long now = timestamp();
 ((now >= start_timestamp && "travelled back in time??") ? (void) (0) : __assert_fail ("now >= start_timestamp && \"travelled back in time??\"", "time.c", 80, __extension__ __PRETTY_FUNCTION__));
 return now - start_timestamp;
}

variable_types:
now
unsigned long


decompiled_code:
unsigned __int64 time_remaining()
{
unsigned __int64 v0; // rdx
unsigned __int64 result; // rax

if ( !start_timestamp )
_assert_fail("start_timestamp != 0", "time.c", 0x56u, "time_remaining");
v0 = timestamp();
result = 0LL;
if ( v0 <= start_timestamp + budget )
result = start_timestamp + budget - v0;
return result;
}

canonical_decompiled_code:
unsigned __int64 func3()
{
unsigned __int64 v0; // rdx
unsigned __int64 result; // rax

if ( !start_timestamp )
_assert_fail("start_timestamp != 0", "time.c", 0x56u, "time_remaining");
v0 = func0();
result = 0LL;
if ( v0 <= start_timestamp + budget )
result = start_timestamp + budget - v0;
return result;
}

original_code:
unsigned long time_remaining()
{
 ((start_timestamp != 0) ? (void) (0) : __assert_fail ("start_timestamp != 0", "time.c", 86, __extension__ __PRETTY_FUNCTION__));
 unsigned long now = timestamp();
 unsigned long end_time = start_timestamp + budget;
 return end_time < now ? 0 : end_time - now;
}


decompiled_code:
int __fastcall start_using_cpu(unsigned int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
int result; // eax

if ( pthread_mutex_lock(&cpu_time_lock) )
_assert_fail("__ret == 0 && \"failed mx lock\"", "time.c", 0x5Eu, "start_using_cpu");
if ( !cpu_times )
_assert_fail("cpu_times != NULL", "time.c", 0x5Fu, "start_using_cpu");
if ( num_cpus <= a1 )
_assert_fail("which < num_cpus", "time.c", 0x60u, "start_using_cpu");
v1 = 24LL * a1;
if ( *(_BYTE *)(cpu_times + v1 + 8) )
_assert_fail("!cpu_times[which].running_now", "time.c", 0x61u, "start_using_cpu");
v2 = cpu_times + v1;
*(_QWORD *)(v2 + 16) = timestamp();
*(_BYTE *)(cpu_times + v1 + 8) = 1;
result = pthread_mutex_unlock(&cpu_time_lock);
if ( result )
_assert_fail("__ret == 0 && \"failed mx unlock\"", "time.c", 0x64u, "start_using_cpu");
return result;
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
int result; // eax

if ( pthread_mutex_lock(&cpu_time_lock) )
_assert_fail("__ret == 0 && \"failed mx lock\"", "time.c", 0x5Eu, "start_using_cpu");
if ( !cpu_times )
_assert_fail("cpu_times != NULL", "time.c", 0x5Fu, "start_using_cpu");
if ( num_cpus <= a1 )
_assert_fail("which < num_cpus", "time.c", 0x60u, "start_using_cpu");
v1 = 24LL * a1;
if ( *(_BYTE *)(cpu_times + v1 + 8) )
_assert_fail("!cpu_times[which].running_now", "time.c", 0x61u, "start_using_cpu");
v2 = cpu_times + v1;
*(_QWORD *)(v2 + 16) = func0();
*(_BYTE *)(cpu_times + v1 + 8) = 1;
result = pthread_mutex_unlock(&cpu_time_lock);
if ( result )
_assert_fail("__ret == 0 && \"failed mx unlock\"", "time.c", 0x64u, "start_using_cpu");
return result;
}

original_code:
void start_using_cpu(unsigned int which)
{
 do { int __ret = pthread_mutex_lock(&cpu_time_lock); ((__ret == 0 && "failed mx lock") ? (void) (0) : __assert_fail ("__ret == 0 && \"failed mx lock\"", "time.c", 94, __extension__ __PRETTY_FUNCTION__)); } while (0);
 ((cpu_times != ((void *)0)) ? (void) (0) : __assert_fail ("cpu_times != NULL", "time.c", 95, __extension__ __PRETTY_FUNCTION__));
 ((which < num_cpus) ? (void) (0) : __assert_fail ("which < num_cpus", "time.c", 96, __extension__ __PRETTY_FUNCTION__));
 ((!cpu_times[which].running_now) ? (void) (0) : __assert_fail ("!cpu_times[which].running_now", "time.c", 97, __extension__ __PRETTY_FUNCTION__));
 cpu_times[which].running_since = timestamp();
 cpu_times[which].running_now = 1;
 do { int __ret = pthread_mutex_unlock(&cpu_time_lock); ((__ret == 0 && "failed mx unlock") ? (void) (0) : __assert_fail ("__ret == 0 && \"failed mx unlock\"", "time.c", 100, __extension__ __PRETTY_FUNCTION__)); } while (0);
}

variable_types:
which
unsigned int


decompiled_code:
int __fastcall stop_using_cpu(unsigned int a1)
{
__int64 v1; // rbx
__suseconds_t v2; // rdx
__int64 v3; // rax
int result; // eax

if ( pthread_mutex_lock(&cpu_time_lock) )
_assert_fail("__ret == 0 && \"failed mx lock\"", "time.c", 0x69u, "stop_using_cpu");
if ( !cpu_times )
_assert_fail("cpu_times != NULL", "time.c", 0x6Au, "stop_using_cpu");
if ( num_cpus <= a1 )
_assert_fail("which < num_cpus", "time.c", 0x6Bu, "stop_using_cpu");
v1 = 24LL * a1;
if ( !*(_BYTE *)(cpu_times + v1 + 8) )
_assert_fail("cpu_times[which].running_now", "time.c", 0x6Cu, "stop_using_cpu");
v2 = timestamp();
v3 = cpu_times + v1;
*(_QWORD *)v3 = *(_QWORD *)(cpu_times + 24LL * a1) + v2 - *(_QWORD *)(cpu_times + 24LL * a1 + 16);
*(_BYTE *)(v3 + 8) = 0;
result = pthread_mutex_unlock(&cpu_time_lock);
if ( result )
_assert_fail("__ret == 0 && \"failed mx unlock\"", "time.c", 0x70u, "stop_using_cpu");
return result;
}

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

if ( pthread_mutex_lock(&cpu_time_lock) )
_assert_fail("__ret == 0 && \"failed mx lock\"", "time.c", 0x69u, "stop_using_cpu");
if ( !cpu_times )
_assert_fail("cpu_times != NULL", "time.c", 0x6Au, "stop_using_cpu");
if ( num_cpus <= a1 )
_assert_fail("which < num_cpus", "time.c", 0x6Bu, "stop_using_cpu");
v1 = 24LL * a1;
if ( !*(_BYTE *)(cpu_times + v1 + 8) )
_assert_fail("cpu_times[which].running_now", "time.c", 0x6Cu, "stop_using_cpu");
v2 = func0();
v3 = cpu_times + v1;
*(_QWORD *)v3 = *(_QWORD *)(cpu_times + 24LL * a1) + v2 - *(_QWORD *)(cpu_times + 24LL * a1 + 16);
*(_BYTE *)(v3 + 8) = 0;
result = pthread_mutex_unlock(&cpu_time_lock);
if ( result )
_assert_fail("__ret == 0 && \"failed mx unlock\"", "time.c", 0x70u, "stop_using_cpu");
return result;
}

original_code:
void stop_using_cpu(unsigned int which)
{
 do { int __ret = pthread_mutex_lock(&cpu_time_lock); ((__ret == 0 && "failed mx lock") ? (void) (0) : __assert_fail ("__ret == 0 && \"failed mx lock\"", "time.c", 105, __extension__ __PRETTY_FUNCTION__)); } while (0);
 ((cpu_times != ((void *)0)) ? (void) (0) : __assert_fail ("cpu_times != NULL", "time.c", 106, __extension__ __PRETTY_FUNCTION__));
 ((which < num_cpus) ? (void) (0) : __assert_fail ("which < num_cpus", "time.c", 107, __extension__ __PRETTY_FUNCTION__));
 ((cpu_times[which].running_now) ? (void) (0) : __assert_fail ("cpu_times[which].running_now", "time.c", 108, __extension__ __PRETTY_FUNCTION__));
 cpu_times[which].previous_total +=
  timestamp() - cpu_times[which].running_since;
 cpu_times[which].running_now = 0;
 do { int __ret = pthread_mutex_unlock(&cpu_time_lock); ((__ret == 0 && "failed mx unlock") ? (void) (0) : __assert_fail ("__ret == 0 && \"failed mx unlock\"", "time.c", 112, __extension__ __PRETTY_FUNCTION__)); } while (0);
}


decompiled_code:
__suseconds_t total_cpu_time()
{
__suseconds_t v0; // rsi
__int64 v1; // rax
__suseconds_t v2; // rbx

if ( pthread_mutex_lock(&cpu_time_lock) )
_assert_fail("__ret == 0 && \"failed mx lock\"", "time.c", 0x75u, "total_cpu_time");
if ( !cpu_times )
_assert_fail("cpu_times != NULL", "time.c", 0x76u, "total_cpu_time");
v0 = timestamp();
if ( num_cpus )
{
v1 = cpu_times;
v2 = 0LL;
do
{
v2 += *(_QWORD *)v1;
if ( *(_BYTE *)(v1 + 8) )
v2 = v2 - *(_QWORD *)(v1 + 16) + v0;
v1 += 24LL;
}
while ( v1 != cpu_times + 24LL * (unsigned int)(num_cpus - 1) + 24 );
}
else
{
v2 = 0LL;
}
if ( pthread_mutex_unlock(&cpu_time_lock) )
_assert_fail("__ret == 0 && \"failed mx unlock\"", "time.c", 0x7Fu, "total_cpu_time");
return v2;
}

canonical_decompiled_code:
__suseconds_t func6()
{
__suseconds_t v0; // rsi
__int64 v1; // rax
__suseconds_t v2; // rbx

if ( pthread_mutex_lock(&cpu_time_lock) )
_assert_fail("__ret == 0 && \"failed mx lock\"", "time.c", 0x75u, "total_cpu_time");
if ( !cpu_times )
_assert_fail("cpu_times != NULL", "time.c", 0x76u, "total_cpu_time");
v0 = func0();
if ( num_cpus )
{
v1 = cpu_times;
v2 = 0LL;
do
{
v2 += *(_QWORD *)v1;
if ( *(_BYTE *)(v1 + 8) )
v2 = v2 - *(_QWORD *)(v1 + 16) + v0;
v1 += 24LL;
}
while ( v1 != cpu_times + 24LL * (unsigned int)(num_cpus - 1) + 24 );
}
else
{
v2 = 0LL;
}
if ( pthread_mutex_unlock(&cpu_time_lock) )
_assert_fail("__ret == 0 && \"failed mx unlock\"", "time.c", 0x7Fu, "total_cpu_time");
return v2;
}

original_code:
unsigned long total_cpu_time()
{
 do { int __ret = pthread_mutex_lock(&cpu_time_lock); ((__ret == 0 && "failed mx lock") ? (void) (0) : __assert_fail ("__ret == 0 && \"failed mx lock\"", "time.c", 117, __extension__ __PRETTY_FUNCTION__)); } while (0);
 ((cpu_times != ((void *)0)) ? (void) (0) : __assert_fail ("cpu_times != NULL", "time.c", 118, __extension__ __PRETTY_FUNCTION__));
 unsigned long now = timestamp();
 unsigned long total = 0;
 for (unsigned int i = 0; i < num_cpus; i++) {
  total += cpu_times[i].previous_total;
  if (cpu_times[i].running_now) {
   total += now - cpu_times[i].running_since;
  }
 }
 do { int __ret = pthread_mutex_unlock(&cpu_time_lock); ((__ret == 0 && "failed mx unlock") ? (void) (0) : __assert_fail ("__ret == 0 && \"failed mx unlock\"", "time.c", 127, __extension__ __PRETTY_FUNCTION__)); } while (0);
 return total;
}

variable_types:
total
unsigned long

variable_types:
i
unsigned int


original_code:
void human_friendly_time(long double usecs, struct human_friendly_time *hft)
{
 long double secs = usecs / 1000000;
 if ((hft->inf = (secs > (long double)(18446744073709551615UL)))) {
  return;
 }
 hft->years = 0;
 hft->days = 0;
 hft->hours = 0;
 hft->mins = 0;
 hft->secs = (uint64_t)secs;
 if (hft->secs >= 60) {
  hft->mins = hft->secs / 60;
  hft->secs = hft->secs % 60;
 }
 if (hft->mins >= 60) {
  hft->hours = hft->mins / 60;
  hft->mins = hft->mins % 60;
 }
 if (hft->hours >= 24) {
  hft->days = hft->hours / 24;
  hft->hours = hft->hours % 24;
 }
 if (hft->days >= 365) {
  hft->years = hft->days / 365;
  hft->days = hft->days % 365;
 }
}

canonical_original_code:
void human_friendly_time(long double usecs, struct human_friendly_time *hft)
{
 long double secs = usecs / 1000000;
 if ((hft->inf = (secs > (long double)(18446744073709551615UL)))) {
  return;
 }
 hft->years = 0;
 hft->days = 0;
 hft->hours = 0;
 hft->mins = 0;
 hft->secs = (unsigned long)secs;
 if (hft->secs >= 60) {
  hft->mins = hft->secs / 60;
  hft->secs = hft->secs % 60;
 }
 if (hft->mins >= 60) {
  hft->hours = hft->mins / 60;
  hft->mins = hft->mins % 60;
 }
 if (hft->hours >= 24) {
  hft->days = hft->hours / 24;
  hft->hours = hft->hours % 24;
 }
 if (hft->days >= 365) {
  hft->years = hft->days / 365;
  hft->days = hft->days % 365;
 }
}

variable_types:
usecs
long double

variable_types: struct human_friendly_time { unsigned long secs; _Bool inf; } *

variable_types:
secs
long double


user_defined_types: struct human_friendly_time { unsigned long secs; _Bool inf; }


decompiled_code:
__int64 __fastcall dbg_human_friendly_time(_QWORD *a1)
{
__int64 v1; // rdx
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
__int64 result; // rax

if ( *((_BYTE *)a1 + 40) )
{
if ( verbose )
{
fwrite("\x1B[00m\x1B[36mINF", 1uLL, 0xDuLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
result = log_msg("DBG", "INF");
}
else
{
v1 = a1[4];
if ( v1 )
{
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36m%luy ", v1);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "%luy ", a1[4]);
}
v2 = a1[3];
if ( v2 )
{
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36m%lud ", v2);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "%lud ", a1[3]);
}
v3 = a1[2];
if ( v3 )
{
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36m%luh ", v3);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "%luh ", a1[2]);
}
v4 = a1[1];
if ( v4 )
{
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36m%lum ", v4);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "%lum ", a1[1]);
}
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36m%lus", *a1);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
result = log_msg("DBG", "%lus", *a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
__int64 v1; // rdx
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
__int64 result; // rax

if ( *((_BYTE *)a1 + 40) )
{
if ( verbose )
{
fwrite("\x1B[00m\x1B[36mINF", 1uLL, 0xDuLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
result = log_msg("DBG", "INF");
}
else
{
v1 = a1[4];
if ( v1 )
{
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36m%luy ", v1);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "%luy ", a1[4]);
}
v2 = a1[3];
if ( v2 )
{
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36m%lud ", v2);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "%lud ", a1[3]);
}
v3 = a1[2];
if ( v3 )
{
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36m%luh ", v3);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "%luh ", a1[2]);
}
v4 = a1[1];
if ( v4 )
{
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36m%lum ", v4);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "%lum ", a1[1]);
}
if ( verbose )
{
fprintf(stderr, "\x1B[00m\x1B[36m%lus", *a1);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
result = log_msg("DBG", "%lus", *a1);
}
return result;
}

original_code:
void dbg_human_friendly_time(struct human_friendly_time *hft)
{
 if (hft->inf) {
  do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "INF"); fprintf(stderr, "\033[00m"); } log_msg("DBG", "INF"); } while (0);
  return;
 }
 if (hft->years != 0)
  do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "%luy ", hft->years); fprintf(stderr, "\033[00m"); } log_msg("DBG", "%luy ", hft->years); } while (0);
 if (hft->days != 0)
  do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "%lud ", hft->days); fprintf(stderr, "\033[00m"); } log_msg("DBG", "%lud ", hft->days); } while (0);
 if (hft->hours != 0)
  do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "%luh ", hft->hours); fprintf(stderr, "\033[00m"); } log_msg("DBG", "%luh ", hft->hours); } while (0);
 if (hft->mins != 0)
  do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "%lum ", hft->mins); fprintf(stderr, "\033[00m"); } log_msg("DBG", "%lum ", hft->mins); } while (0);
 do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "%lus", hft->secs); fprintf(stderr, "\033[00m"); } log_msg("DBG", "%lus", hft->secs); } while (0);
}


decompiled_code:
__int64 __fastcall bug_already_found(__int64 a1)
{
char *v1; // rax
unsigned int v2; // ebp
unsigned int v3; // ebx

check_init();
if ( pthread_mutex_lock(&fab_lock) )
_assert_fail("__ret == 0 && \"failed mx lock\"", "bug.c", 0x58u, "bug_already_found");
v1 = (char *)ptr;
if ( fab_list )
{
v2 = 0;
do
{
v3 = pp_subset(*((_QWORD *)v1 + 1), a1);
if ( (_BYTE)v3 )
break;
v1 = (char *)ptr + 24 * ++v2;
}
while ( fab_list > v2 );
}
else
{
v3 = 0;
}
if ( pthread_mutex_unlock(&fab_lock) )
_assert_fail("__ret == 0 && \"failed mx unlock\"", "bug.c", 0x5Fu, "bug_already_found");
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
char *v1; // rax
unsigned int v2; // ebp
unsigned int v3; // ebx

func0();
if ( pthread_mutex_lock(&fab_lock) )
_assert_fail("__ret == 0 && \"failed mx lock\"", "bug.c", 0x58u, "bug_already_found");
v1 = (char *)ptr;
if ( fab_list )
{
v2 = 0;
do
{
v3 = pp_subset(*((_QWORD *)v1 + 1), a1);
if ( (_BYTE)v3 )
break;
v1 = (char *)ptr + 24 * ++v2;
}
while ( fab_list > v2 );
}
else
{
v3 = 0;
}
if ( pthread_mutex_unlock(&fab_lock) )
_assert_fail("__ret == 0 && \"failed mx unlock\"", "bug.c", 0x5Fu, "bug_already_found");
return v3;
}

original_code:
_Bool bug_already_found(struct pp_set *config)
{
 unsigned int i;
 struct bug_info *b;
 _Bool result = 0;
 check_init();
 do { int __ret = pthread_mutex_lock(&fab_lock); ((__ret == 0 && "failed mx lock") ? (void) (0) : __assert_fail ("__ret == 0 && \"failed mx lock\"", "bug.c", 88, __extension__ __PRETTY_FUNCTION__)); } while (0);
 for(i = 0, b = &(&fab_list)->array[i]; i < (&fab_list)->size; i++, b = &(&fab_list)->array[i]) {
  if (pp_subset(b->config, config)) {
   result = 1;
   break;
  }
 }
 do { int __ret = pthread_mutex_unlock(&fab_lock); ((__ret == 0 && "failed mx unlock") ? (void) (0) : __assert_fail ("__ret == 0 && \"failed mx unlock\"", "bug.c", 95, __extension__ __PRETTY_FUNCTION__)); } while (0);
 return result;
}

variable_types: struct bug_info { char *trace_filename; struct pp_set { unsigned int size; unsigned int capacity; _Bool array[]; } *config; char *log_filename; } *

user_defined_types: struct bug_info { char *trace_filename; struct pp_set *config; char *log_filename; }


decompiled_code:
__int64 found_any_bugs()
{
char *v0; // rbx
unsigned int v1; // ebp

check_init();
if ( pthread_mutex_lock(&fab_lock) )
_assert_fail("__ret == 0 && \"failed mx lock\"", "bug.c", 0x6Bu, "found_any_bugs");
v0 = (char *)ptr;
if ( fab_list )
{
v1 = 0;
do
{
printf("\x1B[01m\x1B[31mFound a bug - %s - with PPs: ", *(const char **)v0);
print_pp_set(*((_QWORD *)v0 + 1), 1LL);
printf(" (log file: id/%s)\n\x1B[00m", *((const char **)v0 + 2));
v0 = (char *)ptr + 24 * ++v1;
}
while ( fab_list > v1 );
if ( !pthread_mutex_unlock(&fab_lock) )
return 1LL;
LABEL_8:
_assert_fail("__ret == 0 && \"failed mx unlock\"", "bug.c", 0x74u, "found_any_bugs");
}
if ( pthread_mutex_unlock(&fab_lock) )
goto LABEL_8;
printf("\x1B[01m\x1B[32mNo bugs were found -- you survived!\n\x1B[00m");
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
char *v0; // rbx
unsigned int v1; // ebp

func0();
if ( pthread_mutex_lock(&fab_lock) )
_assert_fail("__ret == 0 && \"failed mx lock\"", "bug.c", 0x6Bu, "found_any_bugs");
v0 = (char *)ptr;
if ( fab_list )
{
v1 = 0;
do
{
printf("\x1B[01m\x1B[31mFound a bug - %s - with PPs: ", *(const char **)v0);
print_pp_set(*((_QWORD *)v0 + 1), 1LL);
printf(" (log file: id/%s)\n\x1B[00m", *((const char **)v0 + 2));
v0 = (char *)ptr + 24 * ++v1;
}
while ( fab_list > v1 );
if ( !pthread_mutex_unlock(&fab_lock) )
return 1LL;
LABEL_8:
_assert_fail("__ret == 0 && \"failed mx unlock\"", "bug.c", 0x74u, "found_any_bugs");
}
if ( pthread_mutex_unlock(&fab_lock) )
goto LABEL_8;
printf("\x1B[01m\x1B[32mNo bugs were found -- you survived!\n\x1B[00m");
return 0LL;
}

original_code:
_Bool found_any_bugs()
{
 unsigned int i;
 struct bug_info *b;
 _Bool any = 0;
 check_init();
 do { int __ret = pthread_mutex_lock(&fab_lock); ((__ret == 0 && "failed mx lock") ? (void) (0) : __assert_fail ("__ret == 0 && \"failed mx lock\"", "bug.c", 107, __extension__ __PRETTY_FUNCTION__)); } while (0);
 for(i = 0, b = &(&fab_list)->array[i]; i < (&fab_list)->size; i++, b = &(&fab_list)->array[i]) {
  printf("\033[01m" "\033[31m"
         "Found a bug - %s - with PPs: ", b->trace_filename);
  print_pp_set(b->config, 1);
  printf(" (log file: id/%s)\n" "\033[00m", b->log_filename);
  any = 1;
 }
 do { int __ret = pthread_mutex_unlock(&fab_lock); ((__ret == 0 && "failed mx unlock") ? (void) (0) : __assert_fail ("__ret == 0 && \"failed mx unlock\"", "bug.c", 116, __extension__ __PRETTY_FUNCTION__)); } while (0);
 if (!any) {
  printf("\033[01m" "\033[32m"
         "No bugs were found -- you survived!\n" "\033[00m");
 }
 return any;
}

user_defined_types: struct pp_set { unsigned int size; unsigned int capacity; _Bool array[]; }


decompiled_code:
unsigned __int64 __fastcall persistent_write(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rsi
int v7; // eax
ssize_t v8; // rax

if ( !a3 )
return 0LL;
v5 = 0LL;
v6 = 0LL;
while ( 1 )
{
v8 = write(fd, (const void *)(a2 + v6), a3 - v6);
if ( v8 == -1 )
break;
v5 += v8;
LABEL_5:
v6 = v5;
if ( v5 >= a3 )
return v5;
}
v7 = *__errno_location();
if ( v7 == 11 || v7 == 4 )
goto LABEL_5;
return -1LL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rsi
int v7; // eax
ssize_t v8; // rax

if ( !a3 )
return 0LL;
v5 = 0LL;
v6 = 0LL;
while ( 1 )
{
v8 = write(fd, (const void *)(a2 + v6), a3 - v6);
if ( v8 == -1 )
break;
v5 += v8;
LABEL_5:
v6 = v5;
if ( v5 >= a3 )
return v5;
}
v7 = *__errno_location();
if ( v7 == 11 || v7 == 4 )
goto LABEL_5;
return -1LL;
}

original_code:
static ssize_t persistent_write(int fd, const void *data, size_t size) {
    ssize_t res, written;
    written = 0;
    while (written < size) {
        res = write(fd, ((char*)data) + written, size - written);
        if (res == -1) {
            if ((*__errno_location ()) == 11 || (*__errno_location ()) == 4) continue;
            else return -1;
        }
        written += res;
    }
    return written;
}

canonical_original_code:
static long persistent_write(int fd, void *data, unsigned long size) {
    long res; long written;
    written = 0;
    while (written < size) {
        res = write(fd, ((char *)data) + written, size - written);
        if (res == -1) {
            if ((*__errno_location ()) == 11 || (*__errno_location ()) == 4) continue;
            else return -1;
        }
        written += res;
    }
    return written;
}

variable_types: fd int

variable_types:
data
void *

variable_types:
size
unsigned long

variable_types: res long

variable_types: written long

return_type: long


decompiled_code:
__int64 lb_connect()
{
int v0; // eax
unsigned int v1; // ebx
char buf; // [rsp+Fh] [rbp-49h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-48h] BYREF

v0 = open("/dev/ttyACM0", 258);
if ( v0 == -1 )
__assert_fail("ret != -1", "light_bar.c", 0x17u, "lb_connect");
v1 = v0;
if ( tcgetattr(v0, &termios_p) )
__assert_fail("res == 0", "light_bar.c", 0x1Bu, "lb_connect");
if ( cfsetspeed(&termios_p, 0x1002u) )
__assert_fail("res == 0", "light_bar.c", 0x1Fu, "lb_connect");
cfmakeraw(&termios_p);
if ( tcsetattr(v1, 0, &termios_p) )
__assert_fail("res == 0", "light_bar.c", 0x24u, "lb_connect");
buf = 0;
while ( (unsigned int)read(v1, &buf, 1uLL) != 1 )
;
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // eax
unsigned int v1; // ebx
char buf; // [rsp+Fh] [rbp-49h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-48h] BYREF

v0 = open("/dev/ttyACM0", 258);
if ( v0 == -1 )
__assert_fail("ret != -1", "light_bar.c", 0x17u, "lb_connect");
v1 = v0;
if ( tcgetattr(v0, &termios_p) )
__assert_fail("res == 0", "light_bar.c", 0x1Bu, "lb_connect");
if ( cfsetspeed(&termios_p, 0x1002u) )
__assert_fail("res == 0", "light_bar.c", 0x1Fu, "lb_connect");
cfmakeraw(&termios_p);
if ( tcsetattr(v1, 0, &termios_p) )
__assert_fail("res == 0", "light_bar.c", 0x24u, "lb_connect");
buf = 0;
while ( (unsigned int)read(v1, &buf, 1uLL) != 1 )
;
return v1;
}

original_code:
light_bar lb_connect() {
    int res;
    light_bar ret = open("/dev/ttyACM0", 02 | 0400);
    ((void) sizeof ((ret != -1) ? 1 : 0), __extension__ ({ if (ret != -1) ; else __assert_fail ("ret != -1", "light_bar.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    struct termios opts;
    res = tcgetattr(ret, &opts);
    ((void) sizeof ((res == 0) ? 1 : 0), __extension__ ({ if (res == 0) ; else __assert_fail ("res == 0", "light_bar.c", 27, __extension__ __PRETTY_FUNCTION__); }));
    res = cfsetspeed(&opts, 0010002);
    ((void) sizeof ((res == 0) ? 1 : 0), __extension__ ({ if (res == 0) ; else __assert_fail ("res == 0", "light_bar.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    cfmakeraw(&opts);
    res = tcsetattr(ret, 0, &opts);
    ((void) sizeof ((res == 0) ? 1 : 0), __extension__ ({ if (res == 0) ; else __assert_fail ("res == 0", "light_bar.c", 36, __extension__ __PRETTY_FUNCTION__); }));
    char ready = 0;
    while (res != 1) {
        res = read(ret, &ready, 1);
    }
    return ret;
}

canonical_original_code:
int lb_connect() {
    int res;
    int ret = open("/dev/ttyACM0", 02 | 0400);
    ((void) sizeof ((ret != -1) ? 1 : 0), __extension__ ({ if (ret != -1) ; else __assert_fail ("ret != -1", "light_bar.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    struct termios opts;
    res = tcgetattr(ret, &opts);
    ((void) sizeof ((res == 0) ? 1 : 0), __extension__ ({ if (res == 0) ; else __assert_fail ("res == 0", "light_bar.c", 27, __extension__ __PRETTY_FUNCTION__); }));
    res = cfsetspeed(&opts, 0010002);
    ((void) sizeof ((res == 0) ? 1 : 0), __extension__ ({ if (res == 0) ; else __assert_fail ("res == 0", "light_bar.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    cfmakeraw(&opts);
    res = tcsetattr(ret, 0, &opts);
    ((void) sizeof ((res == 0) ? 1 : 0), __extension__ ({ if (res == 0) ; else __assert_fail ("res == 0", "light_bar.c", 36, __extension__ __PRETTY_FUNCTION__); }));
    char ready = 0;
    while (res != 1) {
        res = read(ret, &ready, 1);
    }
    return ret;
}

variable_types: res int

variable_types: ret int

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

variable_types: ready char


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

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

original_code:
int lb_close(light_bar fd) {
    return close(fd);
}

canonical_original_code:
int lb_close(int fd) {
    return close(fd);
}


decompiled_code:
__int64 __fastcall lb_reset(unsigned int a1)
{
lb_write(a1, (__int64)&RESET, 4uLL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
func8(a1, (__int64)&RESET, 4uLL);
return a1;
}

original_code:
light_bar lb_reset(light_bar fd) {
    lb_write(fd, &RESET, 4);
    return fd;
}

canonical_original_code:
int lb_reset(int fd) {
    lb_write(fd, &RESET, 4);
    return fd;
}


decompiled_code:
__int64 __fastcall set_progress(unsigned int a1, int a2, int a3)
{
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a2;
v4 = a3;
lb_write(a1, (__int64)&PROGRESS, 4uLL);
lb_write(a1, (__int64)v5, 4uLL);
lb_write(a1, (__int64)&v4, 4uLL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, int a2, int a3)
{
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a2;
v4 = a3;
func8(a1, (__int64)&PROGRESS, 4uLL);
func8(a1, (__int64)v5, 4uLL);
func8(a1, (__int64)&v4, 4uLL);
return a1;
}

original_code:
light_bar set_progress(light_bar fd, uint32_t numerator, uint32_t denominator) {
    lb_write(fd, &PROGRESS, 4);
    lb_write(fd, &numerator, 4);
    lb_write(fd, &denominator, 4);
    return fd;
}

canonical_original_code:
int set_progress(int fd, unsigned int numerator, unsigned int denominator) {
    lb_write(fd, &PROGRESS, 4);
    lb_write(fd, &numerator, 4);
    lb_write(fd, &denominator, 4);
    return fd;
}

variable_types:
numerator
unsigned int

variable_types:
denominator
unsigned int


decompiled_code:
__int64 __fastcall set_random(unsigned int a1)
{
lb_write(a1, (__int64)&RANDOM, 4uLL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1)
{
func8(a1, (__int64)&RANDOM, 4uLL);
return a1;
}

original_code:
light_bar set_random(light_bar fd) {
    lb_write(fd, &RANDOM, 4);
    return fd;
}

canonical_original_code:
int set_random(int fd) {
    lb_write(fd, &RANDOM, 4);
    return fd;
}


decompiled_code:
__int64 __fastcall set_solid(unsigned int a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
lb_write(a1, (__int64)&SOLID, 4uLL);
lb_write(a1, (__int64)v3, 4uLL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
func8(a1, (__int64)&SOLID, 4uLL);
func8(a1, (__int64)v3, 4uLL);
return a1;
}

original_code:
light_bar set_solid(light_bar fd, uint32_t color) {
    lb_write(fd, &SOLID, 4);
    lb_write(fd, &color, 4);
    return fd;
}

canonical_original_code:
int set_solid(int fd, unsigned int color) {
    lb_write(fd, &SOLID, 4);
    lb_write(fd, &color, 4);
    return fd;
}

variable_types:
color
unsigned int


decompiled_code:
__int64 __fastcall set_custom(unsigned int a1, __int64 a2, __int64 a3)
{
__int64 v5; // rbp

lb_write(a1, (__int64)&CUSTOM, 4uLL);
if ( a3 )
{
v5 = 0LL;
do
{
lb_write(a1, a2, 4uLL);
++v5;
a2 += 4LL;
}
while ( a3 != v5 );
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1, __int64 a2, __int64 a3)
{
__int64 v5; // rbp

func8(a1, (__int64)&CUSTOM, 4uLL);
if ( a3 )
{
v5 = 0LL;
do
{
func8(a1, a2, 4uLL);
++v5;
a2 += 4LL;
}
while ( a3 != v5 );
}
return a1;
}

original_code:
light_bar set_custom(light_bar fd, uint32_t *colors, size_t size) {
    lb_write(fd, &CUSTOM, 4);
    for (size_t i = 0; i < size; ++i) {
        lb_write(fd, colors + i, 4);
    }
    return fd;
}

canonical_original_code:
int set_custom(int fd, unsigned int *colors, unsigned long size) {
    lb_write(fd, &CUSTOM, 4);
    for (unsigned long i = 0; i < size; ++i) {
        lb_write(fd, colors + i, 4);
    }
    return fd;
}

variable_types:
colors
unsigned int *

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall set_pixel(unsigned int a1, char a2, char a3)
{
char v4[4]; // [rsp+8h] [rbp-10h] BYREF
char v5[12]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a2;
v4[0] = a3;
lb_write(a1, (__int64)v5, 1uLL);
lb_write(a1, (__int64)v4, 1uLL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1, char a2, char a3)
{
char v4[4]; // [rsp+8h] [rbp-10h] BYREF
char v5[12]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a2;
v4[0] = a3;
func8(a1, (__int64)v5, 1uLL);
func8(a1, (__int64)v4, 1uLL);
return a1;
}

original_code:
light_bar set_pixel(light_bar fd, uint8_t pixel, uint8_t brightness) {
    lb_write(fd, &pixel, 1);
    lb_write(fd, &brightness, 1);
    return fd;
}

canonical_original_code:
int set_pixel(int fd, unsigned char pixel, unsigned char brightness) {
    lb_write(fd, &pixel, 1);
    lb_write(fd, &brightness, 1);
    return fd;
}

variable_types:
pixel
unsigned char

variable_types:
brightness
unsigned char


repo: bdauvergne/c-json-parser

decompiled_code:
__int64 __fastcall test_json_content(char *s, int a2, int a3)
{
size_t v4; // rax
__int64 result; // rax
__int16 v6[84]; // [rsp+0h] [rbp-A8h] BYREF

json_parser_init(v6);
v4 = strlen(s);
if ( a2 != (unsigned int)json_parser_execute(v6, s, v4, 100LL) )
__assert_fail("len_consumed == consumed", "test.c", 0x12u, "test_json_content");
result = (unsigned __int16)v6[0];
if ( (unsigned __int16)v6[0] != a3 )
__assert_fail("parser.state == state", "test.c", 0x13u, "test_json_content");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s, int a2, int a3)
{
size_t v4; // rax
__int64 result; // rax
__int16 v6[84]; // [rsp+0h] [rbp-A8h] BYREF

func15(v6);
v4 = strlen(s);
if ( a2 != (unsigned int)func14(v6, s, v4, 100LL) )
__assert_fail("len_consumed == consumed", "test.c", 0x12u, "test_json_content");
result = (unsigned __int16)v6[0];
if ( (unsigned __int16)v6[0] != a3 )
__assert_fail("parser.state == state", "test.c", 0x13u, "test_json_content");
return result;
}

original_code:
void test_json_content (const char *data, int len_consumed, int state) {
  json_parser parser;
  int consumed = 0;
  json_parser_init(&parser);
  consumed = json_parser_execute(&parser, data, strlen(data), 100);
  ((void) sizeof ((len_consumed == consumed) ? 1 : 0), __extension__ ({ if (len_consumed == consumed) ; else __assert_fail ("len_consumed == consumed", "test.c", 18, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((parser.state == state) ? 1 : 0), __extension__ ({ if (parser.state == state) ; else __assert_fail ("parser.state == state", "test.c", 19, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void test_json_content(char *data, int len_consumed, int state) {
  struct json_parser parser;
  int consumed = 0;
  json_parser_init(&parser);
  consumed = json_parser_execute(&parser, data, strlen(data), 100);
  ((void) sizeof ((len_consumed == consumed) ? 1 : 0), __extension__ ({ if (len_consumed == consumed) ; else __assert_fail ("len_consumed == consumed", "test.c", 18, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((parser.state == state) ? 1 : 0), __extension__ ({ if (parser.state == state) ; else __assert_fail ("parser.state == state", "test.c", 19, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
data
char *

variable_types: state int

variable_types: struct json_parser { unsigned short state; unsigned long stack_size; unsigned long nread; unsigned short stop_on_callback; unsigned short error; void *data; char *data_mark; unsigned long data_size; int (*on_array_begin)(struct json_parser *); int (*on_object_begin)(struct json_parser *); int (*on_string)(struct json_parser *, char *at, unsigned long length); int (*on_end)(struct json_parser *); int (*on_separator)(struct json_parser *); int (*on_minus)(struct json_parser *); int (*on_int)(struct json_parser *, char *at, unsigned long length); int (*on_frac)(struct json_parser *, char *at, unsigned long length); int (*on_exp)(struct json_parser *, char *at, unsigned long length); unsigned char stack[-1]; }

variable_types: consumed int