decompiled_code:
const char *__fastcall err_to_string(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "No error";
break;
case 1:
result = "Send failed";
break;
case 2:
result = "Receive failed";
break;
case 3:
result = "Connection failed";
break;
case 4:
result = "Connection closed";
break;
case 5:
result = "Timeout";
break;
case 6:
result = "Read failure";
break;
case 7:
result = "Write failure";
break;
case 8:
result = "Variable does not exist";
break;
case 9:
result = "Not supported";
break;
case 10:
result = "Unknown";
break;
default:
_assert_fail("0", "lib/err.c", 0x20u, "err_to_string");
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "No error";
break;
case 1:
result = "Send failed";
break;
case 2:
result = "Receive failed";
break;
case 3:
result = "Connection failed";
break;
case 4:
result = "Connection closed";
break;
case 5:
result = "Timeout";
break;
case 6:
result = "Read failure";
break;
case 7:
result = "Write failure";
break;
case 8:
result = "Variable does not exist";
break;
case 9:
result = "Not supported";
break;
case 10:
result = "Unknown";
break;
default:
_assert_fail("0", "lib/err.c", 0x20u, "err_to_string");
}
return result;
}

original_code:
const char* err_to_string(const err_t err)
{
    switch (err)
    {
        case ERR_NONE:
            return "No error";
        case ERR_SEND_FAILED:
            return "Send failed";
        case ERR_RECV_FAILED:
            return "Receive failed";
        case ERR_CONNECTION_FAILED:
            return "Connection failed";
        case ERR_CONNECTION_CLOSED:
            return "Connection closed";
        case ERR_TIMEOUT:
            return "Timeout";
        case ERR_READ_FAILURE:
            return "Read failure";
        case ERR_WRITE_FAILURE:
            return "Write failure";
        case ERR_NO_SUCH_VALUE:
            return "Variable does not exist";
        case ERR_NOT_SUPPORTED:
            return "Not supported";
        case ERR_UNKNOWN:
            return "Unknown";
    }
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "lib/err.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    return ((void *)0);
}

canonical_original_code:
char *err_to_string(enum err_t err)
{
    switch (err)
    {
        case ERR_NONE:
            return "No error";
        case ERR_SEND_FAILED:
            return "Send failed";
        case ERR_RECV_FAILED:
            return "Receive failed";
        case ERR_CONNECTION_FAILED:
            return "Connection failed";
        case ERR_CONNECTION_CLOSED:
            return "Connection closed";
        case ERR_TIMEOUT:
            return "Timeout";
        case ERR_READ_FAILURE:
            return "Read failure";
        case ERR_WRITE_FAILURE:
            return "Write failure";
        case ERR_NO_SUCH_VALUE:
            return "Variable does not exist";
        case ERR_NOT_SUPPORTED:
            return "Not supported";
        case ERR_UNKNOWN:
            return "Unknown";
    }
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "lib/err.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    return ((void *)0);
}

variable_types: enum err_t { ERR_NONE=0, ERR_SEND_FAILED=1, ERR_RECV_FAILED=2, ERR_CONNECTION_FAILED=3, ERR_CONNECTION_CLOSED=4, ERR_TIMEOUT=5, ERR_READ_FAILURE=6, ERR_WRITE_FAILURE=7, ERR_NO_SUCH_VALUE=8, ERR_NOT_SUPPORTED=9, ERR_UNKNOWN=10 }


main

canonical_name: main

repo: kralljr/gibbs-truncnormal-mdl

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
__int64 v4; // r13
int v5; // er12
int v6; // eax
FILE *v7; // r15
const char *v8; // rsi
__int64 v9; // rbp
int v10; // ebx
int result; // eax
double v12; // [rsp+0h] [rbp-68h]
double v13; // [rsp+8h] [rbp-60h]
double v14; // [rsp+10h] [rbp-58h]
double v15; // [rsp+18h] [rbp-50h]
char *endptr[8]; // [rsp+28h] [rbp-40h] BYREF

v3 = 0LL;
v4 = 0LL;
v5 = 1;
opterr = 0;
v12 = 0.0;
v15 = 1.0;
v14 = -1.0;
v13 = 1.0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "n:m:s:a:b:o:r:h");
if ( v6 == -1 )
break;
endptr[0] = 0LL;
switch ( v6 )
{
case '?':
exit_invalid_flag_isra_0(*argv, (unsigned int)optopt);
return result;
case 'a':
v14 = checked_strtod(argv, 97LL, optarg);
break;
case 'b':
v15 = checked_strtod(argv, 98LL, optarg);
break;
case 'h':
exit_usage_isra_0(*argv);
return result;
case 'm':
v12 = checked_strtod(argv, 109LL, optarg);
break;
case 'n':
v5 = strtol(optarg, endptr, 10);
break;
case 'o':
v3 = optarg;
break;
case 'r':
v4 = strtol(optarg, endptr, 0);
break;
case 's':
v13 = checked_strtod(argv, 115LL, optarg);
break;
default:
continue;
}
}
if ( v3 )
{
v7 = fopen(v3, "wt");
if ( !v7 )
exit_eio(argv, v3);
v8 = (const char *)v4;
v9 = gsl_rng_alloc();
gsl_rng_set();
if ( v5 <= 0 )
goto LABEL_17;
}
else
{
v7 = (FILE *)stdout;
v8 = (const char *)v4;
v9 = gsl_rng_alloc();
gsl_rng_set();
if ( v5 <= 0 )
goto LABEL_18;
}
v10 = 0;
do
{
++v10;
ran_truncnormal(v9, v8, v14, v15, v12, v13);
v8 = "%0.16f\n";
fprintf(v7, "%0.16f\n", v14);
}
while ( v5 > v10 );
if ( v3 )
LABEL_17:
fclose(v7);
LABEL_18:
gsl_rng_free();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
__int64 v4; // r13
int v5; // er12
int v6; // eax
FILE *v7; // r15
const char *v8; // rsi
__int64 v9; // rbp
int v10; // ebx
int result; // eax
double v12; // [rsp+0h] [rbp-68h]
double v13; // [rsp+8h] [rbp-60h]
double v14; // [rsp+10h] [rbp-58h]
double v15; // [rsp+18h] [rbp-50h]
char *endptr[8]; // [rsp+28h] [rbp-40h] BYREF

v3 = 0LL;
v4 = 0LL;
v5 = 1;
opterr = 0;
v12 = 0.0;
v15 = 1.0;
v14 = -1.0;
v13 = 1.0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "n:m:s:a:b:o:r:h");
if ( v6 == -1 )
break;
endptr[0] = 0LL;
switch ( v6 )
{
case '?':
func10(*argv, (unsigned int)optopt);
return result;
case 'a':
v14 = func9(argv, 97LL, optarg);
break;
case 'b':
v15 = func9(argv, 98LL, optarg);
break;
case 'h':
func11(*argv);
return result;
case 'm':
v12 = func9(argv, 109LL, optarg);
break;
case 'n':
v5 = strtol(optarg, endptr, 10);
break;
case 'o':
v3 = optarg;
break;
case 'r':
v4 = strtol(optarg, endptr, 0);
break;
case 's':
v13 = func9(argv, 115LL, optarg);
break;
default:
continue;
}
}
if ( v3 )
{
v7 = fopen(v3, "wt");
if ( !v7 )
func7(argv, v3);
v8 = (const char *)v4;
v9 = gsl_rng_alloc();
gsl_rng_set();
if ( v5 <= 0 )
goto LABEL_17;
}
else
{
v7 = (FILE *)stdout;
v8 = (const char *)v4;
v9 = gsl_rng_alloc();
gsl_rng_set();
if ( v5 <= 0 )
goto LABEL_18;
}
v10 = 0;
do
{
++v10;
func19(v9, v8, v14, v15, v12, v13);
v8 = "%0.16f\n";
fprintf(v7, "%0.16f\n", v14);
}
while ( v5 > v10 );
if ( v3 )
LABEL_17:
fclose(v7);
LABEL_18:
gsl_rng_free();
return 0;
}

original_code:
int
main(int argc, char * const argv[])
{
    const char *data_filename;
    const char *mdls_filename;
    const char *output_filename;
    struct gibbs_problem p = {
        ((void *)0),
        ((void *)0),
        1000,
        0,
        1,
        0,
        ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
    gsl_matrix *data = ((void *)0);
    gsl_matrix *mdls = ((void *)0);
    int optflag;
    int exit_val = 0;
    opterr = 0;
    while ((optflag = getopt(argc, argv, "n:b:d:r:h")) != -1) {
        char *endptr = ((void *)0);
        switch (optflag) {
            case 'n':
                p.iterations = strtol(optarg, &endptr, 10);
                break;
            case 'b':
                p.burn = strtol(optarg, &endptr, 10);
                break;
            case 'd':
                p.draws = strtol(optarg, &endptr, 10);
                break;
            case 'r':
                p.seed = strtol(optarg, &endptr, 0);
                break;
            case 'h':
                print_usage(argv[0]);
                return 0;
            case '?':
                fprintf(stderr, "%s: invalid option or missing argument: -'%c'\n",
                        argv[0], optopt);
                print_usage(argv[0]);
                return 1;
        }
    }
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument DATA\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    data_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument MDLS\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    mdls_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument OUT\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    output_filename = argv[optind++];
    if (optind < argc) {
        fprintf(stderr, "%s: unexpected argument: %s\n", argv[0], argv[optind]);
        print_usage(argv[0]);
        return 1;
    }
    data = csv_load_file(data_filename);
    if (data == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], data_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    mdls = csv_load_file(mdls_filename);
    if (mdls == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], mdls_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    if (data->size1 != mdls->size1 || data->size2 != mdls->size2) {
        fprintf(stderr, "Non-matching `data' and `mdls' dimensions\n");
        exit_val = GSL_EBADLEN;
        goto exit;
    }
    p.data = data;
    p.mdls = mdls;
    gibbs_problem_exec(&p);
    ncdf_write_file(output_filename, &p);
    gibbs_problem_free(&p);
exit:
    if (data != ((void *)0)) {
        gsl_matrix_free(data);
    }
    if (mdls != ((void *)0)) {
        gsl_matrix_free(mdls);
    }
    return exit_val;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char *data_filename;
    char *mdls_filename;
    char *output_filename;
    struct gibbs_problem p = {
        ((void *)0),
        ((void *)0),
        1000,
        0,
        1,
        0,
        ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
    struct gsl_matrix *data = ((void *)0);
    struct gsl_matrix *mdls = ((void *)0);
    int optflag;
    int exit_val = 0;
    opterr = 0;
    while ((optflag = getopt(argc, argv, "n:b:d:r:h")) != -1) {
        char *endptr = ((void *)0);
        switch (optflag) {
            case 'n':
                p.iterations = strtol(optarg, &endptr, 10);
                break;
            case 'b':
                p.burn = strtol(optarg, &endptr, 10);
                break;
            case 'd':
                p.draws = strtol(optarg, &endptr, 10);
                break;
            case 'r':
                p.seed = strtol(optarg, &endptr, 0);
                break;
            case 'h':
                print_usage(argv[0]);
                return 0;
            case '?':
                fprintf(stderr, "%s: invalid option or missing argument: -'%c'\n",
                        argv[0], optopt);
                print_usage(argv[0]);
                return 1;
        }
    }
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument DATA\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    data_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument MDLS\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    mdls_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument OUT\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    output_filename = argv[optind++];
    if (optind < argc) {
        fprintf(stderr, "%s: unexpected argument: %s\n", argv[0], argv[optind]);
        print_usage(argv[0]);
        return 1;
    }
    data = csv_load_file(data_filename);
    if (data == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], data_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    mdls = csv_load_file(mdls_filename);
    if (mdls == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], mdls_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    if (data->size1 != mdls->size1 || data->size2 != mdls->size2) {
        fprintf(stderr, "Non-matching `data' and `mdls' dimensions\n");
        exit_val = GSL_EBADLEN;
        goto exit;
    }
    p.data = data;
    p.mdls = mdls;
    gibbs_problem_exec(&p);
    ncdf_write_file(output_filename, &p);
    gibbs_problem_free(&p);
exit:
    if (data != ((void *)0)) {
        gsl_matrix_free(data);
    }
    if (mdls != ((void *)0)) {
        gsl_matrix_free(mdls);
    }
    return exit_val;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct gibbs_problem { struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *data; struct gsl_matrix *mdls; unsigned long iterations; unsigned long burn; unsigned long draws; long seed; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; } *mthet; struct gsl_matrix *msig; struct gsl_matrix **ddata; unsigned long *dindexes; }

variable_types: optflag int

variable_types:
endptr
char *

return_type: int

user_defined_types: struct gibbs_problem { struct gsl_matrix *data; struct gsl_matrix *mdls; unsigned long iterations; unsigned long burn; unsigned long draws; long seed; struct gsl_vector *mthet; struct gsl_matrix *msig; struct gsl_matrix **ddata; unsigned long *dindexes; }

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


decompiled_code:
void __fastcall __noreturn exit_eio(const char **a1, const char *a2)
{
int *v2; // rax
char *v3; // rax

v2 = __errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s: can't open %s: %s\n", *a1, a2, v3);
exit(2);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char **a1, const char *a2)
{
int *v2; // rax
char *v3; // rax

v2 = __errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s: can't open %s: %s\n", *a1, a2, v3);
exit(2);
}

original_code:
static void
exit_eio(char *argv[], char *filename)
{
    fprintf(stderr, "%s: can't open %s: %s\n", argv[0], filename, strerror((*__errno_location ())));
    exit(2);
}

variable_types:
filename
char *

return_type: void


decompiled_code:
double __fastcall checked_strtod(const char **a1, char a2, const char *a3)
{
double result; // xmm0_8
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = 0LL;
result = strtod(a3, &endptr);
if ( endptr == a3 )
exit_invalid_argument_isra_0(*a1, a2, a3);
return result;
}

canonical_decompiled_code:
double __fastcall func9(const char **a1, char a2, const char *a3)
{
double result; // xmm0_8
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = 0LL;
result = strtod(a3, &endptr);
if ( endptr == a3 )
func8(*a1, a2, a3);
return result;
}

original_code:
static double
checked_strtod(char *argv[], char flag, char *s)
{
    double y;
    char *endptr = ((void *)0);
    y = strtod(s, &endptr);
    if (s == endptr) {
        exit_invalid_argument(argv, flag, s);
    }
    return y;
}

variable_types: flag char

variable_types:
s
char *

variable_types: y double

return_type: double


decompiled_code:
__int64 ran_left_utruncnormal_neg()
{
return gsl_ran_ugaussian();
}

canonical_decompiled_code:
__int64 func12()
{
return gsl_ran_ugaussian();
}

original_code:
static double
ran_left_utruncnormal_neg(const gsl_rng *r, double a)
{
    double y;
    do {
        y = gsl_ran_ugaussian(r);
    } while (y < a);
    return y;
}

canonical_original_code:
static double ran_left_utruncnormal_neg(struct gsl_rng *r, double a)
{
    double y;
    do {
        y = gsl_ran_ugaussian(r);
    } while (y < a);
    return y;
}

variable_types: struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *

variable_types: a double

user_defined_types: struct gsl_rng { struct gsl_rng_type *type; void *state; }


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

do
result = gsl_ran_ugaussian();
while ( a1 > a2 );
return result;
}

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

do
result = gsl_ran_ugaussian();
while ( a1 > a2 );
return result;
}

original_code:
static double
ran_two_utruncnormal_repeat(const gsl_rng *r, double a, double b)
{
    double y;
    do {
        y = gsl_ran_ugaussian(r);
    } while (y < a || y > b);
    return y;
}

canonical_original_code:
static double ran_two_utruncnormal_repeat(struct gsl_rng *r, double a, double b)
{
    double y;
    do {
        y = gsl_ran_ugaussian(r);
    } while (y < a || y > b);
    return y;
}

variable_types: b double

user_defined_types: struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); }


decompiled_code:
__int64 __fastcall ran_left_utruncnormal_pos(double a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
__int64 result; // rax
double v4; // [rsp+0h] [rbp-38h]
double v6; // [rsp+18h] [rbp-20h]

v1 = a1 * a1 + 4.0;
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
v6 = (v2 + a1) * 0.5;
do
{
gsl_ran_exponential();
v4 = exp(-((a1 + 1.0 / v6 - v6) * (a1 + 1.0 / v6 - v6)) * 0.5);
result = gsl_ran_flat();
}
while ( v4 < 0.0 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(double a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
__int64 result; // rax
double v4; // [rsp+0h] [rbp-38h]
double v6; // [rsp+18h] [rbp-20h]

v1 = a1 * a1 + 4.0;
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
v6 = (v2 + a1) * 0.5;
do
{
gsl_ran_exponential();
v4 = exp(-((a1 + 1.0 / v6 - v6) * (a1 + 1.0 / v6 - v6)) * 0.5);
result = gsl_ran_flat();
}
while ( v4 < 0.0 );
return result;
}

original_code:
static double
ran_left_utruncnormal_pos(const gsl_rng *r, double a)
{
    double astar;
    double z;
    double u;
    double rho;
    astar = (a + sqrt((a * a) + 4.0)) / 2.0;
    do {
        z = gsl_ran_exponential(r, 1.0 / astar) + a;
        rho = exp(-pow(z - astar, 2) / 2.0);
        u = gsl_ran_flat(r, 0.0, 1.0);
    } while (u > rho);
    return z;
}

canonical_original_code:
static double ran_left_utruncnormal_pos(struct gsl_rng *r, double a)
{
    double astar;
    double z;
    double u;
    double rho;
    astar = (a + sqrt((a * a) + 4.0)) / 2.0;
    do {
        z = gsl_ran_exponential(r, 1.0 / astar) + a;
        rho = exp(-pow(z - astar, 2) / 2.0);
        u = gsl_ran_flat(r, 0.0, 1.0);
    } while (u > rho);
    return z;
}

variable_types: astar double

variable_types: z double

variable_types: u double

variable_types: rho double


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

if ( a1 <= 0.0 )
result = ran_left_utruncnormal_neg();
else
result = ran_left_utruncnormal_pos(a1);
return result;
}

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

if ( a1 <= 0.0 )
result = func12();
else
result = func14(a1);
return result;
}

original_code:
static double
ran_left_utruncnormal(const gsl_rng *r, double a)
{
    return (a > 0) ? ran_left_utruncnormal_pos(r, a) :
                     ran_left_utruncnormal_neg(r, a);
}

canonical_original_code:
static double ran_left_utruncnormal(struct gsl_rng *r, double a)
{
    return (a > 0) ? ran_left_utruncnormal_pos(r, a) :
                     ran_left_utruncnormal_neg(r, a);
}


decompiled_code:
double __fastcall ran_two_utruncnormal_robert(double a1, double a2)
{
double v2; // xmm0_8
double v4; // [rsp+10h] [rbp-18h]

do
{
gsl_ran_flat();
if ( a2 < 0.0 )
{
v4 = exp((a2 * a2 - a1 * a1) * 0.5);
}
else
{
v2 = a1 * a1;
if ( a1 > 0.0 )
v4 = exp(0.5 * (a1 * a1 - v2));
else
v4 = exp(-v2 * 0.5);
}
gsl_ran_flat();
}
while ( v4 < 0.0 );
return a1;
}

canonical_decompiled_code:
double __fastcall func16(double a1, double a2)
{
double v2; // xmm0_8
double v4; // [rsp+10h] [rbp-18h]

do
{
gsl_ran_flat();
if ( a2 < 0.0 )
{
v4 = exp((a2 * a2 - a1 * a1) * 0.5);
}
else
{
v2 = a1 * a1;
if ( a1 > 0.0 )
v4 = exp(0.5 * (a1 * a1 - v2));
else
v4 = exp(-v2 * 0.5);
}
gsl_ran_flat();
}
while ( v4 < 0.0 );
return a1;
}

original_code:
static double
ran_two_utruncnormal_robert(const gsl_rng *r, double a, double b)
{
    double z;
    double u;
    double rho;
    do {
        z = gsl_ran_flat(r, a, b);
        if (b < 0) {
            rho = exp((b * b - z * z) / 2.0);
        } else if (a > 0) {
            rho = exp((a * a - z * z) / 2.0);
        } else {
            rho = exp(-(z * z) / 2.0);
        }
        u = gsl_ran_flat(r, 0.0, 1.0);
    } while (u > rho);
    return z;
}

canonical_original_code:
static double ran_two_utruncnormal_robert(struct gsl_rng *r, double a, double b)
{
    double z;
    double u;
    double rho;
    do {
        z = gsl_ran_flat(r, a, b);
        if (b < 0) {
            rho = exp((b * b - z * z) / 2.0);
        } else if (a > 0) {
            rho = exp((a * a - z * z) / 2.0);
        } else {
            rho = exp(-(z * z) / 2.0);
        }
        u = gsl_ran_flat(r, 0.0, 1.0);
    } while (u > rho);
    return z;
}


decompiled_code:
void __fastcall ran_two_utruncnormal(double a1, double a2)
{
double v2; // rbx

if ( a1 <= 0.0 )
{
if ( a2 < 0.0 )
{
v2 = -a2;
do
ran_left_utruncnormal_pos(v2);
while ( a1 > -v2 );
}
else if ( a2 - a1 >= 2.506628274631 )
{
ran_two_utruncnormal_repeat(a1, a2);
}
else
{
ran_two_utruncnormal_robert(a1, a2);
}
}
else
{
do
ran_left_utruncnormal_pos(a1);
while ( a1 > a2 );
}
}

original_code:
static double
ran_two_utruncnormal(const gsl_rng *r, double a, double b)
{
    double y;
    if (a > 0.0) {
        do {
            y = ran_left_utruncnormal_pos(r, a);
        } while (y > b);
    } else if (b < 0.0) {
        do {
            y = -ran_left_utruncnormal_pos(r, -b);
        } while (y < a);
    } else if (b - a < SQRT_TWO_PI) {
        y = ran_two_utruncnormal_robert(r, a, b);
    } else {
        y = ran_two_utruncnormal_repeat(r, a, b);
    }
    return y;
}

canonical_original_code:
static double ran_two_utruncnormal(struct gsl_rng *r, double a, double b)
{
    double y;
    if (a > 0.0) {
        do {
            y = ran_left_utruncnormal_pos(r, a);
        } while (y > b);
    } else if (b < 0.0) {
        do {
            y = -ran_left_utruncnormal_pos(r, -b);
        } while (y < a);
    } else if (b - a < SQRT_TWO_PI) {
        y = ran_two_utruncnormal_robert(r, a, b);
    } else {
        y = ran_two_utruncnormal_repeat(r, a, b);
    }
    return y;
}


decompiled_code:
void __fastcall ran_utruncnormal(double a1, double a2)
{
if ( (unsigned int)gsl_isinf() && (unsigned int)gsl_isinf() )
{
gsl_ran_ugaussian();
}
else if ( (unsigned int)gsl_isinf() )
{
ran_left_utruncnormal(-a2);
}
else if ( (unsigned int)gsl_isinf() )
{
ran_left_utruncnormal(a1);
}
else
{
ran_two_utruncnormal(a1, a2);
}
}

canonical_decompiled_code:
void __fastcall func18(double a1, double a2)
{
if ( (unsigned int)gsl_isinf() && (unsigned int)gsl_isinf() )
{
gsl_ran_ugaussian();
}
else if ( (unsigned int)gsl_isinf() )
{
func15(-a2);
}
else if ( (unsigned int)gsl_isinf() )
{
func15(a1);
}
else
{
func17(a1, a2);
}
}

original_code:
double
ran_utruncnormal(const gsl_rng *r, double a, double b)
{
    double y;
    if (gsl_isinf(a) && gsl_isinf(b)) {
        y = gsl_ran_ugaussian(r);
    } else if (gsl_isinf(a)) {
        y = -ran_left_utruncnormal(r, -b);
    } else if (gsl_isinf(b)) {
        y = ran_left_utruncnormal(r, a);
    } else {
        y = ran_two_utruncnormal(r, a, b);
    }
    return y;
}

canonical_original_code:
double ran_utruncnormal(struct gsl_rng *r, double a, double b)
{
    double y;
    if (gsl_isinf(a) && gsl_isinf(b)) {
        y = gsl_ran_ugaussian(r);
    } else if (gsl_isinf(a)) {
        y = -ran_left_utruncnormal(r, -b);
    } else if (gsl_isinf(b)) {
        y = ran_left_utruncnormal(r, a);
    } else {
        y = ran_two_utruncnormal(r, a, b);
    }
    return y;
}


original_code:
double
ran_truncnormal(const gsl_rng *r, double a, double b, double m, double s)
{
    double y;
    double am = (a - m) / s;
    double bm = (b - m) / s;
    y = ran_utruncnormal(r, am, bm);
    return s * y + m;
}

canonical_original_code:
double ran_truncnormal(struct gsl_rng *r, double a, double b, double m, double s)
{
    double y;
    double am = (a - m) / s;
    double bm = (b - m) / s;
    y = ran_utruncnormal(r, am, bm);
    return s * y + m;
}

variable_types: m double

variable_types: s double

variable_types: am double

variable_types: bm double


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v5; // ebx
int v6; // eax
int result; // eax
__int64 v8; // rax
double v9; // xmm0_8
__int64 v10; // r14
char *v11; // rsi
__int64 v12; // rcx
char **v13; // rdi
__int64 v14; // r12
__int64 v15; // r13
FILE *v16; // r15
__int64 v17; // r14
int i; // ebp
int *v19; // rax
char *v20; // rax
__int64 v21; // [rsp+8h] [rbp-C0h]
int v22; // [rsp+14h] [rbp-B4h]
char *filename; // [rsp+18h] [rbp-B0h]
void *ptr; // [rsp+28h] [rbp-A0h]
char v25; // [rsp+30h] [rbp-98h] BYREF
char *endptr[13]; // [rsp+60h] [rbp-68h] BYREF

v3 = 0LL;
v5 = 1;
opterr = 0;
v22 = 0;
filename = 0LL;
v21 = 0x3FF0000000000000LL;
while ( 2 )
{
v6 = getopt(argc, (char *const *)argv, "n:d:s:o:r:ih");
if ( v6 == -1 )
{
if ( !v3 )
{
fprintf(stderr, "%s: missing scale\n", *argv);
print_usage(*argv);
return 3;
}
v8 = csv_count_fields(v3);
if ( v8 < 0 )
v9 = (double)(int)(v8 & 1 | ((unsigned __int64)v8 >> 1)) + (double)(int)(v8 & 1 | ((unsigned __int64)v8 >> 1));
else
v9 = (double)(int)v8;
v10 = (int)sqrt(v9);
ptr = calloc(v10 * v10, 8uLL);
csv_read_double_fields(ptr, v10 * v10, v3);
gsl_matrix_view_array();
v11 = &v25;
v12 = 12LL;
v13 = endptr;
while ( v12 )
{
*(_DWORD *)v13 = *(_DWORD *)v11;
v11 += 4;
v13 = (char **)((char *)v13 + 4);
--v12;
}
v14 = gsl_matrix_alloc();
v15 = gsl_matrix_alloc();
if ( filename )
{
v16 = fopen(filename, "wt");
if ( !v16 )
{
v19 = __errno_location();
v20 = strerror(*v19);
fprintf(stderr, "%s: can't open %s: %s\n", *argv, filename, v20);
return 2;
}
v17 = gsl_rng_alloc();
gsl_rng_set();
if ( v5 <= 0 )
{
LABEL_27:
fclose(v16);
LABEL_28:
free(ptr);
gsl_matrix_free();
gsl_matrix_free();
gsl_rng_free();
return 0;
}
}
else
{
v16 = (FILE *)_bss_start;
v17 = gsl_rng_alloc();
gsl_rng_set();
if ( v5 <= 0 )
goto LABEL_28;
}
for ( i = 0; i < v5; ++i )
{
gsl_matrix_memcpy();
if ( v22 )
ran_invwishart(v17, v14, v15, *(double *)&v21);
else
ran_wishart(v17, v14, v15, *(double *)&v21);
print_matrix(v16);
}
if ( !filename )
goto LABEL_28;
goto LABEL_27;
}
endptr[0] = 0LL;
switch ( v6 )
{
case '?':
fprintf(stderr, "%s: invalid option or missing argument: -%c\n", *argv, (unsigned int)optopt);
print_usage(*argv);
result = 1;
break;
case 'd':
v21 = strtod(optarg, endptr);
continue;
case 'h':
print_usage(*argv);
result = 0;
break;
case 'i':
v22 = 1;
continue;
case 'n':
v5 = strtol(optarg, endptr, 10);
continue;
case 'o':
filename = optarg;
continue;
case 'r':
strtol(optarg, endptr, 0);
continue;
case 's':
v3 = optarg;
continue;
default:
continue;
}
return result;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v5; // ebx
int v6; // eax
int result; // eax
__int64 v8; // rax
double v9; // xmm0_8
__int64 v10; // r14
char *v11; // rsi
__int64 v12; // rcx
char **v13; // rdi
__int64 v14; // r12
__int64 v15; // r13
FILE *v16; // r15
__int64 v17; // r14
int i; // ebp
int *v19; // rax
char *v20; // rax
__int64 v21; // [rsp+8h] [rbp-C0h]
int v22; // [rsp+14h] [rbp-B4h]
char *filename; // [rsp+18h] [rbp-B0h]
void *ptr; // [rsp+28h] [rbp-A0h]
char v25; // [rsp+30h] [rbp-98h] BYREF
char *endptr[13]; // [rsp+60h] [rbp-68h] BYREF

v3 = 0LL;
v5 = 1;
opterr = 0;
v22 = 0;
filename = 0LL;
v21 = 0x3FF0000000000000LL;
while ( 2 )
{
v6 = getopt(argc, (char *const *)argv, "n:d:s:o:r:ih");
if ( v6 == -1 )
{
if ( !v3 )
{
fprintf(stderr, "%s: missing scale\n", *argv);
func7(*argv);
return 3;
}
v8 = func9(v3);
if ( v8 < 0 )
v9 = (double)(int)(v8 & 1 | ((unsigned __int64)v8 >> 1)) + (double)(int)(v8 & 1 | ((unsigned __int64)v8 >> 1));
else
v9 = (double)(int)v8;
v10 = (int)sqrt(v9);
ptr = calloc(v10 * v10, 8uLL);
func10(ptr, v10 * v10, v3);
gsl_matrix_view_array();
v11 = &v25;
v12 = 12LL;
v13 = endptr;
while ( v12 )
{
*(_DWORD *)v13 = *(_DWORD *)v11;
v11 += 4;
v13 = (char **)((char *)v13 + 4);
--v12;
}
v14 = gsl_matrix_alloc();
v15 = gsl_matrix_alloc();
if ( filename )
{
v16 = fopen(filename, "wt");
if ( !v16 )
{
v19 = __errno_location();
v20 = strerror(*v19);
fprintf(stderr, "%s: can't open %s: %s\n", *argv, filename, v20);
return 2;
}
v17 = gsl_rng_alloc();
gsl_rng_set();
if ( v5 <= 0 )
{
LABEL_27:
fclose(v16);
LABEL_28:
free(ptr);
gsl_matrix_free();
gsl_matrix_free();
gsl_rng_free();
return 0;
}
}
else
{
v16 = (FILE *)_bss_start;
v17 = gsl_rng_alloc();
gsl_rng_set();
if ( v5 <= 0 )
goto LABEL_28;
}
for ( i = 0; i < v5; ++i )
{
gsl_matrix_memcpy();
if ( v22 )
func12(v17, v14, v15, *(double *)&v21);
else
func11(v17, v14, v15, *(double *)&v21);
func8(v16);
}
if ( !filename )
goto LABEL_28;
goto LABEL_27;
}
endptr[0] = 0LL;
switch ( v6 )
{
case '?':
fprintf(stderr, "%s: invalid option or missing argument: -%c\n", *argv, (unsigned int)optopt);
func7(*argv);
result = 1;
break;
case 'd':
v21 = strtod(optarg, endptr);
continue;
case 'h':
func7(*argv);
result = 0;
break;
case 'i':
v22 = 1;
continue;
case 'n':
v5 = strtol(optarg, endptr, 10);
continue;
case 'o':
filename = optarg;
continue;
case 'r':
strtol(optarg, endptr, 0);
continue;
case 's':
v3 = optarg;
continue;
default:
continue;
}
return result;
}
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct gibbs_problem { struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *data; struct gsl_matrix *mdls; unsigned long iterations; unsigned long burn; unsigned long draws; long seed; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; } *mthet; struct gsl_matrix *msig; struct gsl_matrix **ddata; unsigned long *dindexes; }

variable_types: optflag int


decompiled_code:
__int64 __fastcall csv_count_fields(char *a1)
{
char v1; // al
__int64 i; // r8

v1 = *a1;
for ( i = 1LL; *a1; v1 = *a1 )
{
++a1;
i += v1 == 44;
}
return i;
}

original_code:
size_t
csv_count_fields(const char *s)
{
    size_t i = 1;
    const char *c;
    for (c = s; *c != '\0'; c++) {
        if (*c == ',') {
            i++;
        }
    }
    return i;
}

canonical_original_code:
unsigned long csv_count_fields(char *s)
{
    unsigned long i = 1;
    char *c;
    for (c = s; *c != '\0'; c++) {
        if (*c == ',') {
            i++;
        }
    }
    return i;
}

variable_types:
s
char *

variable_types:
i
unsigned long

variable_types:
c
char *

return_type: unsigned long


decompiled_code:
const char *__fastcall csv_read_double_fields(__int64 a1, unsigned __int64 a2, const char *a3)
{
unsigned __int64 v4; // rbx
double v5; // xmm0_8
char *v6; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

endptr = 0LL;
if ( !a2 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = strtod(a3, &endptr);
v6 = endptr;
*(double *)(a1 + 8 * v4) = v5;
if ( v6 == a3 )
break;
++v4;
if ( !*v6 )
{
if ( a2 > v4 )
return a3;
return 0LL;
}
a3 = v6 + 1;
if ( a2 == v4 )
return 0LL;
}
return a3;
}

canonical_decompiled_code:
const char *__fastcall func10(__int64 a1, unsigned __int64 a2, const char *a3)
{
unsigned __int64 v4; // rbx
double v5; // xmm0_8
char *v6; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

endptr = 0LL;
if ( !a2 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = strtod(a3, &endptr);
v6 = endptr;
*(double *)(a1 + 8 * v4) = v5;
if ( v6 == a3 )
break;
++v4;
if ( !*v6 )
{
if ( a2 > v4 )
return a3;
return 0LL;
}
a3 = v6 + 1;
if ( a2 == v4 )
return 0LL;
}
return a3;
}

original_code:
const char *
csv_read_double_fields(double *y, size_t n, const char *s)
{
    const char *curptr = s;
    char *endptr = ((void *)0);
    size_t i;
    for (i = 0, curptr = s, endptr = ((void *)0); i < n; i++) {
        y[i] = strtod(curptr, &endptr);
        if (curptr == endptr) {
            return curptr;
        } else if (*endptr == '\0' && i + 1 < n) {
            return curptr;
        } else {
            curptr = endptr + 1;
        }
    }
    return ((void *)0);
}

canonical_original_code:
char *csv_read_double_fields(double *y, unsigned long n, char *s)
{
    char *curptr = s;
    char *endptr = ((void *)0);
    unsigned long i;
    for (i = 0, curptr = s, endptr = ((void *)0); i < n; i++) {
        y[i] = strtod(curptr, &endptr);
        if (curptr == endptr) {
            return curptr;
        } else if (*endptr == '\0' && i + 1 < n) {
            return curptr;
        } else {
            curptr = endptr + 1;
        }
    }
    return ((void *)0);
}

variable_types:
y
double *

variable_types:
n
unsigned long

variable_types:
curptr
char *

variable_types:
endptr
char *

return_type: char *


decompiled_code:
__int64 __fastcall ran_wishart(double a1, __int64 a2, __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v6; // rbp
double v7; // xmm1_8
double v8; // xmm0_8
unsigned __int64 v9; // rax
__int64 v10; // rbp
unsigned __int64 i; // r14
__int64 v12; // rbx

gsl_linalg_cholesky_decomp();
gsl_matrix_set_zero();
if ( *a4 )
{
v6 = 1LL;
do
{
if ( (v6 & 0x8000000000000000LL) == 0LL )
v7 = (double)(int)v6;
else
v7 = (double)(int)(v6 & 1 | (v6 >> 1)) + (double)(int)(v6 & 1 | (v6 >> 1));
v8 = (a1 - v7 + 1.0) * 0.5;
gsl_ran_gamma();
if ( v8 < 0.0 )
sqrt(v8);
++v6;
gsl_matrix_set();
v9 = *a4;
}
while ( *a4 >= v6 );
if ( v9 )
{
v10 = 1LL;
for ( i = 2LL; v9 >= i; ++i )
{
if ( i > 1 )
{
v12 = 0LL;
do
{
gsl_ran_ugaussian();
gsl_matrix_set();
++v12;
}
while ( v10 != v12 );
v9 = *a4;
}
v10 = i;
}
}
}
gsl_blas_dtrmm();
gsl_matrix_memcpy();
return gsl_blas_dtrmm();
}

canonical_decompiled_code:
__int64 __fastcall func11(double a1, __int64 a2, __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v6; // rbp
double v7; // xmm1_8
double v8; // xmm0_8
unsigned __int64 v9; // rax
__int64 v10; // rbp
unsigned __int64 i; // r14
__int64 v12; // rbx

gsl_linalg_cholesky_decomp();
gsl_matrix_set_zero();
if ( *a4 )
{
v6 = 1LL;
do
{
if ( (v6 & 0x8000000000000000LL) == 0LL )
v7 = (double)(int)v6;
else
v7 = (double)(int)(v6 & 1 | (v6 >> 1)) + (double)(int)(v6 & 1 | (v6 >> 1));
v8 = (a1 - v7 + 1.0) * 0.5;
gsl_ran_gamma();
if ( v8 < 0.0 )
sqrt(v8);
++v6;
gsl_matrix_set();
v9 = *a4;
}
while ( *a4 >= v6 );
if ( v9 )
{
v10 = 1LL;
for ( i = 2LL; v9 >= i; ++i )
{
if ( i > 1 )
{
v12 = 0LL;
do
{
gsl_ran_ugaussian();
gsl_matrix_set();
++v12;
}
while ( v10 != v12 );
v9 = *a4;
}
v10 = i;
}
}
}
gsl_blas_dtrmm();
gsl_matrix_memcpy();
return gsl_blas_dtrmm();
}

original_code:
void
ran_wishart(const gsl_rng *r, double nu, gsl_matrix *scale, gsl_matrix *rwish)
{
    size_t i;
    size_t j;
    gsl_linalg_cholesky_decomp(scale);
    gsl_matrix_set_zero(rwish);
    for (i = 1; i <= rwish->size1; i++) {
        double y;
        y = sqrt(gsl_ran_gamma(r, (nu - i + 1) / 2.0, 2.0));
        gsl_matrix_set(rwish, i - 1, i - 1, y);
    }
    for (i = 1; i <= rwish->size1; i++) {
        for (j = 1; j < i; j++) {
            double y;
            y = gsl_ran_ugaussian(r);
            gsl_matrix_set(rwish, i - 1, j - 1, y);
        }
    }
    gsl_blas_dtrmm(CblasLeft, CblasLower, CblasNoTrans, CblasNonUnit, 1.0,
            scale, rwish);
    gsl_matrix_memcpy(scale, rwish);
    gsl_blas_dtrmm(CblasRight, CblasLower, CblasTrans, CblasNonUnit, 1.0,
            scale, rwish);
}

canonical_original_code:
void ran_wishart(struct gsl_rng *r, double nu, struct gsl_matrix *scale, struct gsl_matrix *rwish)
{
    unsigned long i;
    unsigned long j;
    gsl_linalg_cholesky_decomp(scale);
    gsl_matrix_set_zero(rwish);
    for (i = 1; i <= rwish->size1; i++) {
        double y;
        y = sqrt(gsl_ran_gamma(r, (nu - i + 1) / 2.0, 2.0));
        gsl_matrix_set(rwish, i - 1, i - 1, y);
    }
    for (i = 1; i <= rwish->size1; i++) {
        for (j = 1; j < i; j++) {
            double y;
            y = gsl_ran_ugaussian(r);
            gsl_matrix_set(rwish, i - 1, j - 1, y);
        }
    }
    gsl_blas_dtrmm(CblasLeft, CblasLower, CblasNoTrans, CblasNonUnit, 1.0,
            scale, rwish);
    gsl_matrix_memcpy(scale, rwish);
    gsl_blas_dtrmm(CblasRight, CblasLower, CblasTrans, CblasNonUnit, 1.0,
            scale, rwish);
}

variable_types: struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *

variable_types: nu double

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

variable_types:
rwish
struct gsl_matrix *

variable_types:
j
unsigned long

variable_types: y double


decompiled_code:
__int64 __fastcall ran_invwishart(__int64 a1, __int64 a2, unsigned __int64 *a3, double a4)
{
gsl_linalg_cholesky_decomp();
gsl_linalg_cholesky_invert();
ran_wishart(a4, a1, a2, a3);
gsl_linalg_cholesky_decomp();
return gsl_linalg_cholesky_invert();
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, unsigned __int64 *a3, double a4)
{
gsl_linalg_cholesky_decomp();
gsl_linalg_cholesky_invert();
func11(a4, a1, a2, a3);
gsl_linalg_cholesky_decomp();
return gsl_linalg_cholesky_invert();
}

original_code:
void
ran_invwishart(const gsl_rng *r, double nu, gsl_matrix *scale,
        gsl_matrix *riwish)
{
    gsl_linalg_cholesky_decomp(scale);
    gsl_linalg_cholesky_invert(scale);
    ran_wishart(r, nu, scale, riwish);
    gsl_linalg_cholesky_decomp(riwish);
    gsl_linalg_cholesky_invert(riwish);
}

canonical_original_code:
void ran_invwishart(struct gsl_rng *r, double nu, struct gsl_matrix *scale, struct gsl_matrix *riwish)
{
    gsl_linalg_cholesky_decomp(scale);
    gsl_linalg_cholesky_invert(scale);
    ran_wishart(r, nu, scale, riwish);
    gsl_linalg_cholesky_decomp(riwish);
    gsl_linalg_cholesky_invert(riwish);
}

variable_types:
riwish
struct gsl_matrix *

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


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return fprintf(
stderr,
"Usage: %s [OPTION]\n"
" -n int number of draws (default 1)\n"
" -d float degrees of freedom (default 1.0)\n"
" -s float,float,... scale\n"
" -o filename output file (default standard output)\n"
" -r int random seed (default 0)\n"
" -i draw from inverse Wishart\n"
" -h show this help\n",
a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return fprintf(
stderr,
"Usage: %s [OPTION]\n"
" -n int number of draws (default 1)\n"
" -d float degrees of freedom (default 1.0)\n"
" -s float,float,... scale\n"
" -o filename output file (default standard output)\n"
" -r int random seed (default 0)\n"
" -i draw from inverse Wishart\n"
" -h show this help\n",
a1);
}

original_code:
static void
print_usage(const char *progname)
{
    fprintf(stderr,
            "Usage: %s [OPTION] DATA MDLS OUT\n"
            "  -n int   number of iterations (default 1000)\n"
            "  -b int   number of iterations to burn-in (default 0)\n"
            "  -d int   number of random draws (default 1)\n"
            "  -r int   random seed (default 0)\n"
            "  -h       show this help\n"
            , progname);
}

canonical_original_code:
static void print_usage(char *progname)
{
    fprintf(stderr,
            "Usage: %s [OPTION] DATA MDLS OUT\n"
            "  -n int   number of iterations (default 1000)\n"
            "  -b int   number of iterations to burn-in (default 0)\n"
            "  -d int   number of random draws (default 1)\n"
            "  -r int   random seed (default 0)\n"
            "  -h       show this help\n"
            , progname);
}

variable_types:
progname
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
char *v4; // r13
int v5; // ebp
int v7; // eax
int result; // eax
size_t v9; // r12
char *v10; // rsi
__int64 v11; // rcx
char *v12; // rdi
__int64 v13; // rcx
char **v14; // rdi
char *v15; // rsi
__int64 v16; // r12
FILE *v17; // r13
__int64 v18; // rbx
int v19; // eax
int *v20; // rax
char *v21; // rax
int v22; // [rsp+0h] [rbp-118h]
char *filename; // [rsp+8h] [rbp-110h]
void *ptr; // [rsp+10h] [rbp-108h]
void *v25; // [rsp+18h] [rbp-100h]
char v26; // [rsp+20h] [rbp-F8h] BYREF
char v27; // [rsp+50h] [rbp-C8h] BYREF
char v28[48]; // [rsp+80h] [rbp-98h] BYREF
char *endptr[13]; // [rsp+B0h] [rbp-68h] BYREF

v3 = 0LL;
v4 = 0LL;
v5 = 1;
opterr = 0;
filename = 0LL;
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "n:m:c:o:r:h");
if ( v7 == -1 )
{
if ( v3 )
{
if ( v4 )
{
v9 = csv_count_fields(v3);
ptr = calloc(v9, 8uLL);
csv_read_double_fields(ptr, v9, v3);
gsl_vector_view_array();
v10 = &v27;
v11 = 10LL;
v12 = v28;
while ( v11 )
{
*(_DWORD *)v12 = *(_DWORD *)v10;
v10 += 4;
v12 += 4;
--v11;
}
v25 = calloc(v9 * v9, 8uLL);
csv_read_double_fields(v25, v9 * v9, v4);
gsl_matrix_view_array();
v13 = 12LL;
v14 = endptr;
v15 = &v26;
while ( v13 )
{
*(_DWORD *)v14 = *(_DWORD *)v15;
v15 += 4;
v14 = (char **)((char *)v14 + 4);
--v13;
}
v16 = gsl_vector_alloc();
if ( filename )
{
v17 = fopen(filename, "wt");
if ( !v17 )
{
v20 = __errno_location();
v21 = strerror(*v20);
fprintf(stderr, "%s: can't open %s: %s\n", *argv, filename, v21);
return 2;
}
v18 = gsl_rng_alloc();
gsl_rng_set();
ran_multivariate_normal(v18, v28, endptr, v16);
print_vector(v17);
if ( v5 <= 1 )
{
LABEL_25:
fclose(v17);
LABEL_26:
free(ptr);
free(v25);
gsl_vector_free();
gsl_rng_free();
return 0;
}
}
else
{
v17 = stdout;
v18 = gsl_rng_alloc();
gsl_rng_set();
ran_multivariate_normal(v18, v28, endptr, v16);
print_vector(v17);
if ( v5 <= 1 )
goto LABEL_26;
}
v19 = 1;
do
{
v22 = v19;
ran_multivariate_normal_chol(v18, v28, endptr, v16);
print_vector(v17);
v19 = v22 + 1;
}
while ( v5 > v22 + 1 );
if ( !filename )
goto LABEL_26;
goto LABEL_25;
}
fprintf(stderr, "%s: missing covariance\n", *argv);
}
else
{
fprintf(stderr, "%s: missing mean\n", *argv);
}
print_usage(*argv);
return 3;
}
endptr[0] = 0LL;
switch ( v7 )
{
case '?':
fprintf(stderr, "%s: invalid option or missing argument: -%c\n", *argv, (unsigned int)optopt);
print_usage(*argv);
result = 1;
break;
case 'c':
v4 = optarg;
continue;
case 'h':
print_usage(*argv);
result = 0;
break;
case 'm':
v3 = optarg;
continue;
case 'n':
v5 = strtol(optarg, endptr, 10);
continue;
case 'o':
filename = optarg;
continue;
case 'r':
strtol(optarg, endptr, 0);
continue;
default:
continue;
}
return result;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
char *v4; // r13
int v5; // ebp
int v7; // eax
int result; // eax
size_t v9; // r12
char *v10; // rsi
__int64 v11; // rcx
char *v12; // rdi
__int64 v13; // rcx
char **v14; // rdi
char *v15; // rsi
__int64 v16; // r12
FILE *v17; // r13
__int64 v18; // rbx
int v19; // eax
int *v20; // rax
char *v21; // rax
int v22; // [rsp+0h] [rbp-118h]
char *filename; // [rsp+8h] [rbp-110h]
void *ptr; // [rsp+10h] [rbp-108h]
void *v25; // [rsp+18h] [rbp-100h]
char v26; // [rsp+20h] [rbp-F8h] BYREF
char v27; // [rsp+50h] [rbp-C8h] BYREF
char v28[48]; // [rsp+80h] [rbp-98h] BYREF
char *endptr[13]; // [rsp+B0h] [rbp-68h] BYREF

v3 = 0LL;
v4 = 0LL;
v5 = 1;
opterr = 0;
filename = 0LL;
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "n:m:c:o:r:h");
if ( v7 == -1 )
{
if ( v3 )
{
if ( v4 )
{
v9 = func9(v3);
ptr = calloc(v9, 8uLL);
func10(ptr, v9, v3);
gsl_vector_view_array();
v10 = &v27;
v11 = 10LL;
v12 = v28;
while ( v11 )
{
*(_DWORD *)v12 = *(_DWORD *)v10;
v10 += 4;
v12 += 4;
--v11;
}
v25 = calloc(v9 * v9, 8uLL);
func10(v25, v9 * v9, v4);
gsl_matrix_view_array();
v13 = 12LL;
v14 = endptr;
v15 = &v26;
while ( v13 )
{
*(_DWORD *)v14 = *(_DWORD *)v15;
v15 += 4;
v14 = (char **)((char *)v14 + 4);
--v13;
}
v16 = gsl_vector_alloc();
if ( filename )
{
v17 = fopen(filename, "wt");
if ( !v17 )
{
v20 = __errno_location();
v21 = strerror(*v20);
fprintf(stderr, "%s: can't open %s: %s\n", *argv, filename, v21);
return 2;
}
v18 = gsl_rng_alloc();
gsl_rng_set();
func12(v18, v28, endptr, v16);
func8(v17);
if ( v5 <= 1 )
{
LABEL_25:
fclose(v17);
LABEL_26:
free(ptr);
free(v25);
gsl_vector_free();
gsl_rng_free();
return 0;
}
}
else
{
v17 = stdout;
v18 = gsl_rng_alloc();
gsl_rng_set();
func12(v18, v28, endptr, v16);
func8(v17);
if ( v5 <= 1 )
goto LABEL_26;
}
v19 = 1;
do
{
v22 = v19;
func11(v18, v28, endptr, v16);
func8(v17);
v19 = v22 + 1;
}
while ( v5 > v22 + 1 );
if ( !filename )
goto LABEL_26;
goto LABEL_25;
}
fprintf(stderr, "%s: missing covariance\n", *argv);
}
else
{
fprintf(stderr, "%s: missing mean\n", *argv);
}
func7(*argv);
return 3;
}
endptr[0] = 0LL;
switch ( v7 )
{
case '?':
fprintf(stderr, "%s: invalid option or missing argument: -%c\n", *argv, (unsigned int)optopt);
func7(*argv);
result = 1;
break;
case 'c':
v4 = optarg;
continue;
case 'h':
func7(*argv);
result = 0;
break;
case 'm':
v3 = optarg;
continue;
case 'n':
v5 = strtol(optarg, endptr, 10);
continue;
case 'o':
filename = optarg;
continue;
case 'r':
strtol(optarg, endptr, 0);
continue;
default:
continue;
}
return result;
}
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct gibbs_problem { struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *data; struct gsl_matrix *mdls; unsigned long iterations; unsigned long burn; unsigned long draws; long seed; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; } *mthet; struct gsl_matrix *msig; struct gsl_matrix **ddata; unsigned long *dindexes; }


decompiled_code:
__int64 __fastcall ran_multivariate_normal_chol(__int64 a1, __int64 a2, __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v5; // rbx

if ( *a4 )
{
v5 = 0LL;
do
{
gsl_ran_gaussian();
++v5;
gsl_vector_set();
}
while ( *a4 > v5 );
}
gsl_blas_dtrmv();
return gsl_vector_add();
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v5; // rbx

if ( *a4 )
{
v5 = 0LL;
do
{
gsl_ran_gaussian();
++v5;
gsl_vector_set();
}
while ( *a4 > v5 );
}
gsl_blas_dtrmv();
return gsl_vector_add();
}

original_code:
void
ran_multivariate_normal_chol(const gsl_rng *rng, const gsl_vector *mean,
        const gsl_matrix *sigmachol, gsl_vector *z)
{
    size_t i;
    for (i = 0; i < z->size; i++) {
        double r;
        r = gsl_ran_gaussian(rng, 1.0);
        gsl_vector_set(z, i, r);
    }
    gsl_blas_dtrmv(CblasLower, CblasNoTrans, CblasNonUnit, sigmachol, z);
    gsl_vector_add(z, mean);
}

canonical_original_code:
void ran_multivariate_normal_chol(struct gsl_rng *rng, struct gsl_vector *mean, struct gsl_matrix *sigmachol, struct gsl_vector *z)
{
    unsigned long i;
    for (i = 0; i < z->size; i++) {
        double r;
        r = gsl_ran_gaussian(rng, 1.0);
        gsl_vector_set(z, i, r);
    }
    gsl_blas_dtrmv(CblasLower, CblasNoTrans, CblasNonUnit, sigmachol, z);
    gsl_vector_add(z, mean);
}

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

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

variable_types:
z
struct gsl_vector *

variable_types:
i
unsigned long

variable_types: r double

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


decompiled_code:
__int64 __fastcall ran_multivariate_normal(__int64 a1, __int64 a2, __int64 a3, unsigned __int64 *a4)
{
gsl_linalg_cholesky_decomp();
return ran_multivariate_normal_chol(a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3, unsigned __int64 *a4)
{
gsl_linalg_cholesky_decomp();
return func11(a1, a2, a3, a4);
}

original_code:
void
ran_multivariate_normal(const gsl_rng *rng, const gsl_vector *mean,
        gsl_matrix *sigma, gsl_vector *z)
{
    gsl_linalg_cholesky_decomp(sigma);
    ran_multivariate_normal_chol(rng, mean, sigma, z);
}

canonical_original_code:
void ran_multivariate_normal(struct gsl_rng *rng, struct gsl_vector *mean, struct gsl_matrix *sigma, struct gsl_vector *z)
{
    gsl_linalg_cholesky_decomp(sigma);
    ran_multivariate_normal_chol(rng, mean, sigma, z);
}


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return fprintf(
stderr,
"Usage: %s [OPTION]\n"
" -n int number of draws (default 1)\n"
" -m float,float,... mean\n"
" -c float,float,... covariance\n"
" -o filename output file (default standard output)\n"
" -r int random seed (default 0)\n"
" -h show this help\n",
a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return fprintf(
stderr,
"Usage: %s [OPTION]\n"
" -n int number of draws (default 1)\n"
" -m float,float,... mean\n"
" -c float,float,... covariance\n"
" -o filename output file (default standard output)\n"
" -r int random seed (default 0)\n"
" -h show this help\n",
a1);
}


decompiled_code:
unsigned __int64 __fastcall vector_remove_elem(unsigned __int64 *a1, __int64 a2, __int64 a3)
{
unsigned __int64 v4; // rcx
__int64 v5; // rdx
__int64 i; // rax
unsigned __int64 result; // rax
unsigned __int64 v8; // rsi
unsigned __int64 v9; // rcx
__int64 v10; // rdx

if ( a2 )
{
v4 = a1[2];
v5 = *(_QWORD *)(a3 + 16);
for ( i = 0LL; i != a2; ++i )
*(_QWORD *)(v5 + 8 * i) = *(_QWORD *)(v4 + 8 * i);
}
result = *a1;
v8 = a2 + 1;
if ( v8 < *a1 )
{
v9 = a1[2];
v10 = *(_QWORD *)(a3 + 16);
do
{
*(_QWORD *)(v10 + 8 * v8 - 8) = *(_QWORD *)(v9 + 8 * v8);
++v8;
}
while ( v8 != result );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 *a1, __int64 a2, __int64 a3)
{
unsigned __int64 v4; // rcx
__int64 v5; // rdx
__int64 i; // rax
unsigned __int64 result; // rax
unsigned __int64 v8; // rsi
unsigned __int64 v9; // rcx
__int64 v10; // rdx

if ( a2 )
{
v4 = a1[2];
v5 = *(_QWORD *)(a3 + 16);
for ( i = 0LL; i != a2; ++i )
*(_QWORD *)(v5 + 8 * i) = *(_QWORD *)(v4 + 8 * i);
}
result = *a1;
v8 = a2 + 1;
if ( v8 < *a1 )
{
v9 = a1[2];
v10 = *(_QWORD *)(a3 + 16);
do
{
*(_QWORD *)(v10 + 8 * v8 - 8) = *(_QWORD *)(v9 + 8 * v8);
++v8;
}
while ( v8 != result );
}
return result;
}

original_code:
void
vector_remove_elem(const gsl_vector *u, size_t i, gsl_vector *v)
{
    size_t j;
    for (j = 0; j < i; j++) {
        v->data[j] = u->data[j];
    }
    for (j = i + 1; j < u->size; j++) {
        v->data[j - 1] = u->data[j];
    }
}

canonical_original_code:
void vector_remove_elem(struct gsl_vector *u, unsigned long i, struct gsl_vector *v)
{
    unsigned long j;
    for (j = 0; j < i; j++) {
        v->data[j] = u->data[j];
    }
    for (j = i + 1; j < u->size; j++) {
        v->data[j - 1] = u->data[j];
    }
}

variable_types:
v
struct gsl_vector *


decompiled_code:
unsigned __int64 __fastcall matrix_row_remove_elem(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v7[9]; // [rsp+0h] [rbp-48h] BYREF

gsl_matrix_const_row(v7, a1, a2);
return vector_remove_elem(v7, a3, a4);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v7[9]; // [rsp+0h] [rbp-48h] BYREF

gsl_matrix_const_row(v7, a1, a2);
return func0(v7, a3, a4);
}

original_code:
void
matrix_row_remove_elem(const gsl_matrix *A, size_t i, size_t j, gsl_vector *v)
{
    gsl_vector_const_view u = gsl_matrix_const_row(A, i);
    vector_remove_elem(&u.vector, j, v);
}

canonical_original_code:
void matrix_row_remove_elem(struct gsl_matrix *A, unsigned long i, unsigned long j, struct gsl_vector *v)
{
    struct _gsl_vector_const_view u = gsl_matrix_const_row(A, i);
    vector_remove_elem(&u.vector, j, v);
}

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

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

user_defined_types: struct _gsl_vector_const_view { struct gsl_vector vector; }


decompiled_code:
unsigned __int64 __fastcall matrix_remove_rowcol(unsigned __int64 *a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 i; // rbx
__int64 v8; // rsi
unsigned __int64 result; // rax
unsigned __int64 v10; // rbx
unsigned __int64 v11; // r13
__int64 v12; // rsi
_BYTE v13[104]; // [rsp+0h] [rbp-68h] BYREF

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
gsl_matrix_row(v13, a4, i);
v8 = i;
matrix_row_remove_elem((__int64)a1, v8, a3, (__int64)v13);
}
result = a2;
}
else
{
result = 0LL;
}
v10 = a2 + 1;
if ( a2 + 1 < *a1 )
{
v11 = result + ~a2;
do
{
gsl_matrix_row(v13, a4, v11 + v10);
v12 = v10++;
result = matrix_row_remove_elem((__int64)a1, v12, a3, (__int64)v13);
}
while ( *a1 > v10 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 *a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 i; // rbx
__int64 v8; // rsi
unsigned __int64 result; // rax
unsigned __int64 v10; // rbx
unsigned __int64 v11; // r13
__int64 v12; // rsi
_BYTE v13[104]; // [rsp+0h] [rbp-68h] BYREF

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
gsl_matrix_row(v13, a4, i);
v8 = i;
func1((__int64)a1, v8, a3, (__int64)v13);
}
result = a2;
}
else
{
result = 0LL;
}
v10 = a2 + 1;
if ( a2 + 1 < *a1 )
{
v11 = result + ~a2;
do
{
gsl_matrix_row(v13, a4, v11 + v10);
v12 = v10++;
result = func1((__int64)a1, v12, a3, (__int64)v13);
}
while ( *a1 > v10 );
}
return result;
}

original_code:
void
matrix_remove_rowcol(const gsl_matrix *A, size_t r1, size_t r2, gsl_matrix *B)
{
    size_t i;
    size_t j = 0;
    for (i = 0; i < r1; i++, j++) {
        gsl_vector_view v = gsl_matrix_row(B, j);
        matrix_row_remove_elem(A, i, r2, &v.vector);
    }
    for (i = r1 + 1; i < A->size1; i++, j++) {
        gsl_vector_view v = gsl_matrix_row(B, j);
        matrix_row_remove_elem(A, i, r2, &v.vector);
    }
}

canonical_original_code:
void matrix_remove_rowcol(struct gsl_matrix *A, unsigned long r1, unsigned long r2, struct gsl_matrix *B)
{
    unsigned long i;
    unsigned long j = 0;
    for (i = 0; i < r1; i++, j++) {
        struct _gsl_vector_view v = gsl_matrix_row(B, j);
        matrix_row_remove_elem(A, i, r2, &v.vector);
    }
    for (i = r1 + 1; i < A->size1; i++, j++) {
        struct _gsl_vector_view v = gsl_matrix_row(B, j);
        matrix_row_remove_elem(A, i, r2, &v.vector);
    }
}

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

variable_types:
B
struct gsl_matrix *

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

user_defined_types: struct _gsl_vector_view { struct gsl_vector vector; }


decompiled_code:
__int64 __fastcall matrix_update_const_diag(__int64 *a1, double a2, double a3, double a4, double a5, double a6, double a7)
{
__int64 result; // rax
unsigned __int64 v8; // rbx
unsigned __int64 v9; // rdx
unsigned __int64 v10; // rsi
double v11; // xmm5_8
unsigned __int64 v12; // rbx
double v13; // xmm0_8
unsigned __int64 v14; // rdx
unsigned __int64 v15; // rsi
unsigned __int64 v16; // rbx
double v17; // xmm0_8
unsigned __int64 v18; // rdx
unsigned __int64 v19; // rsi
double v20; // [rsp+0h] [rbp-28h]
double v21; // [rsp+8h] [rbp-20h]

result = *a1;
v21 = a2;
v20 = a3;
if ( a2 == 1.0 )
{
v8 = 0LL;
if ( result )
{
do
{
a2 = gsl_matrix_get(a1, v8, v8, a2, a3, a4, a5, a6, a7) + a3;
v9 = v8;
v10 = v8++;
result = gsl_matrix_set(a1, v10, v9, a2);
}
while ( *a1 > v8 );
}
}
else
{
v11 = a2;
if ( a2 == -1.0 )
{
if ( result )
{
v12 = 0LL;
do
{
v13 = gsl_matrix_get(a1, v12, v12, a2, a3, a4, a5, a6, v11);
v14 = v12;
v15 = v12;
a3 = v13;
++v12;
a2 = v20 - v13;
result = gsl_matrix_set(a1, v15, v14, a2);
}
while ( *a1 > v12 );
}
}
else
{
v16 = 0LL;
if ( result )
{
do
{
v17 = gsl_matrix_get(a1, v16, v16, a2, a3, a4, a5, a6, v11);
v18 = v16;
v19 = v16++;
a2 = v17 * v21 + a3;
result = gsl_matrix_set(a1, v19, v18, a2);
}
while ( *a1 > v16 );
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, double a2, double a3, double a4, double a5, double a6, double a7)
{
__int64 result; // rax
unsigned __int64 v8; // rbx
unsigned __int64 v9; // rdx
unsigned __int64 v10; // rsi
double v11; // xmm5_8
unsigned __int64 v12; // rbx
double v13; // xmm0_8
unsigned __int64 v14; // rdx
unsigned __int64 v15; // rsi
unsigned __int64 v16; // rbx
double v17; // xmm0_8
unsigned __int64 v18; // rdx
unsigned __int64 v19; // rsi
double v20; // [rsp+0h] [rbp-28h]
double v21; // [rsp+8h] [rbp-20h]

result = *a1;
v21 = a2;
v20 = a3;
if ( a2 == 1.0 )
{
v8 = 0LL;
if ( result )
{
do
{
a2 = gsl_matrix_get(a1, v8, v8, a2, a3, a4, a5, a6, a7) + a3;
v9 = v8;
v10 = v8++;
result = gsl_matrix_set(a1, v10, v9, a2);
}
while ( *a1 > v8 );
}
}
else
{
v11 = a2;
if ( a2 == -1.0 )
{
if ( result )
{
v12 = 0LL;
do
{
v13 = gsl_matrix_get(a1, v12, v12, a2, a3, a4, a5, a6, v11);
v14 = v12;
v15 = v12;
a3 = v13;
++v12;
a2 = v20 - v13;
result = gsl_matrix_set(a1, v15, v14, a2);
}
while ( *a1 > v12 );
}
}
else
{
v16 = 0LL;
if ( result )
{
do
{
v17 = gsl_matrix_get(a1, v16, v16, a2, a3, a4, a5, a6, v11);
v18 = v16;
v19 = v16++;
a2 = v17 * v21 + a3;
result = gsl_matrix_set(a1, v19, v18, a2);
}
while ( *a1 > v16 );
}
}
}
return result;
}

original_code:
void
matrix_update_const_diag(gsl_matrix *A, double alpha, double beta)
{
    size_t i;
    if (alpha == 1.0) {
        for (i = 0; i < A->size1; i++) {
            double y = gsl_matrix_get(A, i, i);
            gsl_matrix_set(A, i, i, y + beta);
        }
    } else if (alpha == -1.0) {
        for (i = 0; i < A->size1; i++) {
            double y = gsl_matrix_get(A, i, i);
            gsl_matrix_set(A, i, i, beta - y);
        }
    } else {
        for (i = 0; i < A->size1; i++) {
            double y = gsl_matrix_get(A, i, i);
            gsl_matrix_set(A, i, i, alpha * y + beta);
        }
    }
}

canonical_original_code:
void matrix_update_const_diag(struct gsl_matrix *A, double alpha, double beta)
{
    unsigned long i;
    if (alpha == 1.0) {
        for (i = 0; i < A->size1; i++) {
            double y = gsl_matrix_get(A, i, i);
            gsl_matrix_set(A, i, i, y + beta);
        }
    } else if (alpha == -1.0) {
        for (i = 0; i < A->size1; i++) {
            double y = gsl_matrix_get(A, i, i);
            gsl_matrix_set(A, i, i, beta - y);
        }
    } else {
        for (i = 0; i < A->size1; i++) {
            double y = gsl_matrix_get(A, i, i);
            gsl_matrix_set(A, i, i, alpha * y + beta);
        }
    }
}

variable_types: alpha double

variable_types: beta double

variable_types: y double


decompiled_code:
__int64 __fastcall matrix_invert_remove_rowcol(unsigned __int64 *a1, unsigned __int64 a2, __int64 a3, __int64 a4, double a5, double a6, double a7, double a8)
{
double v10; // xmm4_8
double v11; // xmm5_8
double v12; // xmm0_8

matrix_remove_rowcol(a1, a2, a2, a3);
matrix_row_remove_elem((__int64)a1, a2, a2, a4);
v12 = gsl_matrix_get(a1, a2, a2, a5, a6, a7, a8, v10, v11);
return gsl_blas_dger(a4, a4, a3, -1.0 / v12);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 *a1, unsigned __int64 a2, __int64 a3, __int64 a4, double a5, double a6, double a7, double a8)
{
double v10; // xmm4_8
double v11; // xmm5_8
double v12; // xmm0_8

func2(a1, a2, a2, a3);
func1((__int64)a1, a2, a2, a4);
v12 = gsl_matrix_get(a1, a2, a2, a5, a6, a7, a8, v10, v11);
return gsl_blas_dger(a4, a4, a3, -1.0 / v12);
}

original_code:
void
matrix_invert_remove_rowcol(const gsl_matrix *Ainv, size_t i, gsl_matrix *Binv,
        gsl_vector *work)
{
    matrix_remove_rowcol(Ainv, i, i, Binv);
    matrix_row_remove_elem(Ainv, i, i, work);
    gsl_blas_dger(-1.0 / gsl_matrix_get(Ainv, i, i), work, work, Binv);
}

canonical_original_code:
void matrix_invert_remove_rowcol(struct gsl_matrix *Ainv, unsigned long i, struct gsl_matrix *Binv, struct gsl_vector *work)
{
    matrix_remove_rowcol(Ainv, i, i, Binv);
    matrix_row_remove_elem(Ainv, i, i, work);
    gsl_blas_dger(-1.0 / gsl_matrix_get(Ainv, i, i), work, work, Binv);
}

variable_types:
Binv
struct gsl_matrix *


decompiled_code:
__int64 __fastcall multivariate_mean(__int64 *a1, __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rdx
__int64 v4; // rax
double v5; // xmm1_8
__int64 v7; // rdx
_BYTE v8[72]; // [rsp+0h] [rbp-48h] BYREF

gsl_vector_set_zero(a2);
if ( *a1 )
{
v2 = 0LL;
do
{
v3 = v2++;
gsl_matrix_const_row(v8, a1, v3);
gsl_vector_add(a2, v8);
v4 = *a1;
}
while ( *a1 > v2 );
if ( v4 < 0 )
{
v7 = *a1 & 1 | ((unsigned __int64)*a1 >> 1);
v5 = (double)(int)v7 + (double)(int)v7;
}
else
{
v5 = (double)(int)v4;
}
}
else
{
v5 = 0.0;
}
return gsl_vector_scale(a2, 1.0 / v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rdx
__int64 v4; // rax
double v5; // xmm1_8
__int64 v7; // rdx
_BYTE v8[72]; // [rsp+0h] [rbp-48h] BYREF

gsl_vector_set_zero(a2);
if ( *a1 )
{
v2 = 0LL;
do
{
v3 = v2++;
gsl_matrix_const_row(v8, a1, v3);
gsl_vector_add(a2, v8);
v4 = *a1;
}
while ( *a1 > v2 );
if ( v4 < 0 )
{
v7 = *a1 & 1 | ((unsigned __int64)*a1 >> 1);
v5 = (double)(int)v7 + (double)(int)v7;
}
else
{
v5 = (double)(int)v4;
}
}
else
{
v5 = 0.0;
}
return gsl_vector_scale(a2, 1.0 / v5);
}

original_code:
void
multivariate_mean(const gsl_matrix *A, gsl_vector *mu)
{
    size_t i;
    gsl_vector_set_zero(mu);
    for (i = 0; i < A->size1; i++) {
        gsl_vector_const_view row = gsl_matrix_const_row(A, i);
        gsl_vector_add(mu, &row.vector);
    }
    gsl_vector_scale(mu, 1.0 / A->size1);
}

canonical_original_code:
void multivariate_mean(struct gsl_matrix *A, struct gsl_vector *mu)
{
    unsigned long i;
    gsl_vector_set_zero(mu);
    for (i = 0; i < A->size1; i++) {
        struct _gsl_vector_const_view row = gsl_matrix_const_row(A, i);
        gsl_vector_add(mu, &row.vector);
    }
    gsl_vector_scale(mu, 1.0 / A->size1);
}


decompiled_code:
__int64 __fastcall multivariate_covariance(unsigned __int64 *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
unsigned __int64 v7; // r14
double v8; // xmm0_8
_BYTE v9[88]; // [rsp+0h] [rbp-58h] BYREF

result = gsl_matrix_set_zero(a3);
if ( *a1 )
{
v7 = 0LL;
do
{
gsl_matrix_const_row(v9, a1, v7);
gsl_vector_memcpy(a4, v9);
gsl_vector_sub(a4, a2);
if ( (*a1 & 0x8000000000000000LL) == 0LL )
v8 = (double)(int)*a1;
else
v8 = (double)(int)(*(_DWORD *)a1 & 1 | (*a1 >> 1)) + (double)(int)(*(_DWORD *)a1 & 1 | (*a1 >> 1));
++v7;
result = gsl_blas_dger(a4, a4, a3, 1.0 / v8);
}
while ( *a1 > v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
unsigned __int64 v7; // r14
double v8; // xmm0_8
_BYTE v9[88]; // [rsp+0h] [rbp-58h] BYREF

result = gsl_matrix_set_zero(a3);
if ( *a1 )
{
v7 = 0LL;
do
{
gsl_matrix_const_row(v9, a1, v7);
gsl_vector_memcpy(a4, v9);
gsl_vector_sub(a4, a2);
if ( (*a1 & 0x8000000000000000LL) == 0LL )
v8 = (double)(int)*a1;
else
v8 = (double)(int)(*(_DWORD *)a1 & 1 | (*a1 >> 1)) + (double)(int)(*(_DWORD *)a1 & 1 | (*a1 >> 1));
++v7;
result = gsl_blas_dger(a4, a4, a3, 1.0 / v8);
}
while ( *a1 > v7 );
}
return result;
}

original_code:
void
multivariate_covariance(const gsl_matrix *A, const gsl_vector *mu,
        gsl_matrix *S, gsl_vector *tmp)
{
    size_t i;
    gsl_matrix_set_zero(S);
    for (i = 0; i < A->size1; i++) {
        gsl_vector_const_view row = gsl_matrix_const_row(A, i);
        gsl_vector_memcpy(tmp, &row.vector);
        gsl_vector_sub(tmp, mu);
        gsl_blas_dger(1.0 / A->size1, tmp, tmp, S);
    }
}

canonical_original_code:
void multivariate_covariance(struct gsl_matrix *A, struct gsl_vector *mu, struct gsl_matrix *S, struct gsl_vector *tmp)
{
    unsigned long i;
    gsl_matrix_set_zero(S);
    for (i = 0; i < A->size1; i++) {
        struct _gsl_vector_const_view row = gsl_matrix_const_row(A, i);
        gsl_vector_memcpy(tmp, &row.vector);
        gsl_vector_sub(tmp, mu);
        gsl_blas_dger(1.0 / A->size1, tmp, tmp, S);
    }
}

variable_types:
S
struct gsl_matrix *

variable_types:
tmp
struct gsl_vector *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int result; // eax
int v6; // eax
const char *v7; // r13
__int64 v8; // rsi
const char *v9; // r12
const char *v10; // r14
_QWORD *v11; // rbp
_QWORD *v12; // rax
_QWORD *v13; // r13
int v14; // eax
int *v15; // rbp
char *v16; // rax
int *v17; // r13
char *v18; // rax
int v19; // [rsp+Ch] [rbp-8Ch]
int v20; // [rsp+Ch] [rbp-8Ch]
char *endptr; // [rsp+18h] [rbp-80h] BYREF
_QWORD *v22; // [rsp+20h] [rbp-78h] BYREF
_QWORD *v23; // [rsp+28h] [rbp-70h]
__int64 v24; // [rsp+30h] [rbp-68h]
__int64 v25; // [rsp+38h] [rbp-60h]
__int64 v26; // [rsp+40h] [rbp-58h]
__int64 v27; // [rsp+48h] [rbp-50h]
__int64 v28; // [rsp+50h] [rbp-48h]
__int64 v29; // [rsp+58h] [rbp-40h]
__int64 v30; // [rsp+60h] [rbp-38h]
__int64 v31; // [rsp+68h] [rbp-30h]

opterr = 0;
v22 = 0LL;
v23 = 0LL;
v24 = 1000LL;
v25 = 0LL;
v26 = 1LL;
v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v30 = 0LL;
v31 = 0LL;
while ( 2 )
{
v4 = getopt(argc, (char *const *)argv, "n:b:d:r:h");
if ( v4 != -1 )
{
endptr = 0LL;
if ( v4 == 63 )
{
fprintf(stderr, "%s: invalid option or missing argument: -'%c'\n", *argv, (unsigned int)optopt);
print_usage(*argv);
result = 1;
}
else
{
switch ( v4 )
{
case 'b':
v25 = strtol(optarg, &endptr, 10);
continue;
case 'd':
v26 = strtol(optarg, &endptr, 10);
continue;
case 'h':
print_usage(*argv);
result = 0;
break;
case 'n':
v24 = strtol(optarg, &endptr, 10);
continue;
case 'r':
v27 = strtol(optarg, &endptr, 0);
continue;
default:
continue;
}
}
return result;
}
break;
}
v6 = optind;
if ( optind == argc )
{
fprintf(stderr, "%s: missing argument DATA\n", *argv);
LABEL_24:
print_usage(*argv);
return 1;
}
++optind;
v7 = argv[v6];
v8 = v6;
if ( v6 + 1 == argc )
{
fprintf(stderr, "%s: missing argument MDLS\n", *argv);
goto LABEL_24;
}
v9 = argv[v8 + 1];
optind = v6 + 2;
if ( v6 + 2 == argc )
{
fprintf(stderr, "%s: missing argument OUT\n", *argv);
goto LABEL_24;
}
optind = v6 + 3;
if ( v6 + 3 < argc )
{
fprintf(stderr, "%s: unexpected argument: %s\n", *argv, argv[v8 + 3]);
print_usage(*argv);
result = 1;
}
else
{
v10 = argv[v8 + 2];
v11 = (_QWORD *)csv_load_file(v7);
if ( v11 )
{
v12 = (_QWORD *)csv_load_file(v9);
v13 = v12;
if ( v12 )
{
if ( *v11 == *v12 && v11[1] == v12[1] )
{
v22 = v11;
v23 = v12;
gibbs_problem_exec(&v22);
ncdf_write_file((__int64)v10, (__int64)&v22);
gibbs_problem_free(&v22);
v14 = 0;
}
else
{
fwrite("Non-matching `data' and `mdls' dimensions\n", 1uLL, 0x2AuLL, stderr);
v14 = 19;
}
v19 = v14;
gsl_matrix_free(v11);
gsl_matrix_free(v13);
result = v19;
}
else
{
v17 = _errno_location();
v18 = strerror(*v17);
fprintf(stderr, "%s: cannot read '%s': %s\n", *argv, v9, v18);
v20 = *v17;
gsl_matrix_free(v11);
result = v20;
}
}
else
{
v15 = _errno_location();
v16 = strerror(*v15);
fprintf(stderr, "%s: cannot read '%s': %s\n", *argv, v7, v16);
result = *v15;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int result; // eax
int v6; // eax
const char *v7; // r13
__int64 v8; // rsi
const char *v9; // r12
const char *v10; // r14
_QWORD *v11; // rbp
_QWORD *v12; // rax
_QWORD *v13; // r13
int v14; // eax
int *v15; // rbp
char *v16; // rax
int *v17; // r13
char *v18; // rax
int v19; // [rsp+Ch] [rbp-8Ch]
int v20; // [rsp+Ch] [rbp-8Ch]
char *endptr; // [rsp+18h] [rbp-80h] BYREF
_QWORD *v22; // [rsp+20h] [rbp-78h] BYREF
_QWORD *v23; // [rsp+28h] [rbp-70h]
__int64 v24; // [rsp+30h] [rbp-68h]
__int64 v25; // [rsp+38h] [rbp-60h]
__int64 v26; // [rsp+40h] [rbp-58h]
__int64 v27; // [rsp+48h] [rbp-50h]
__int64 v28; // [rsp+50h] [rbp-48h]
__int64 v29; // [rsp+58h] [rbp-40h]
__int64 v30; // [rsp+60h] [rbp-38h]
__int64 v31; // [rsp+68h] [rbp-30h]

opterr = 0;
v22 = 0LL;
v23 = 0LL;
v24 = 1000LL;
v25 = 0LL;
v26 = 1LL;
v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v30 = 0LL;
v31 = 0LL;
while ( 2 )
{
v4 = getopt(argc, (char *const *)argv, "n:b:d:r:h");
if ( v4 != -1 )
{
endptr = 0LL;
if ( v4 == 63 )
{
fprintf(stderr, "%s: invalid option or missing argument: -'%c'\n", *argv, (unsigned int)optopt);
func0(*argv);
result = 1;
}
else
{
switch ( v4 )
{
case 'b':
v25 = strtol(optarg, &endptr, 10);
continue;
case 'd':
v26 = strtol(optarg, &endptr, 10);
continue;
case 'h':
func0(*argv);
result = 0;
break;
case 'n':
v24 = strtol(optarg, &endptr, 10);
continue;
case 'r':
v27 = strtol(optarg, &endptr, 0);
continue;
default:
continue;
}
}
return result;
}
break;
}
v6 = optind;
if ( optind == argc )
{
fprintf(stderr, "%s: missing argument DATA\n", *argv);
LABEL_24:
func0(*argv);
return 1;
}
++optind;
v7 = argv[v6];
v8 = v6;
if ( v6 + 1 == argc )
{
fprintf(stderr, "%s: missing argument MDLS\n", *argv);
goto LABEL_24;
}
v9 = argv[v8 + 1];
optind = v6 + 2;
if ( v6 + 2 == argc )
{
fprintf(stderr, "%s: missing argument OUT\n", *argv);
goto LABEL_24;
}
optind = v6 + 3;
if ( v6 + 3 < argc )
{
fprintf(stderr, "%s: unexpected argument: %s\n", *argv, argv[v8 + 3]);
func0(*argv);
result = 1;
}
else
{
v10 = argv[v8 + 2];
v11 = (_QWORD *)func4(v7);
if ( v11 )
{
v12 = (_QWORD *)func4(v9);
v13 = v12;
if ( v12 )
{
if ( *v11 == *v12 && v11[1] == v12[1] )
{
v22 = v11;
v23 = v12;
gibbs_problem_exec(&v22);
func1((__int64)v10, (__int64)&v22);
gibbs_problem_free(&v22);
v14 = 0;
}
else
{
fwrite("Non-matching `data' and `mdls' dimensions\n", 1uLL, 0x2AuLL, stderr);
v14 = 19;
}
v19 = v14;
gsl_matrix_free(v11);
gsl_matrix_free(v13);
result = v19;
}
else
{
v17 = _errno_location();
v18 = strerror(*v17);
fprintf(stderr, "%s: cannot read '%s': %s\n", *argv, v9, v18);
v20 = *v17;
gsl_matrix_free(v11);
result = v20;
}
}
else
{
v15 = _errno_location();
v16 = strerror(*v15);
fprintf(stderr, "%s: cannot read '%s': %s\n", *argv, v7, v16);
result = *v15;
}
}
return result;
}

original_code:
int
main(int argc, char * const argv[])
{
    const char *data_filename;
    const char *mdls_filename;
    const char *output_filename;
    struct gibbs_problem p = {
        ((void *)0),
        ((void *)0),
        1000,
        0,
        1,
        0,
        ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
    gsl_matrix *data = ((void *)0);
    gsl_matrix *mdls = ((void *)0);
    int optflag;
    int exit_val = 0;
    opterr = 0;
    while ((optflag = getopt(argc, argv, "n:b:d:r:h")) != -1) {
        char *endptr = ((void *)0);
        switch (optflag) {
            case 'n':
                p.iterations = strtol(optarg, &endptr, 10);
                break;
            case 'b':
                p.burn = strtol(optarg, &endptr, 10);
                break;
            case 'd':
                p.draws = strtol(optarg, &endptr, 10);
                break;
            case 'r':
                p.seed = strtol(optarg, &endptr, 0);
                break;
            case 'h':
                print_usage(argv[0]);
                return 0;
            case '?':
                fprintf(stderr, "%s: invalid option or missing argument: -'%c'\n",
                        argv[0], optopt);
                print_usage(argv[0]);
                return 1;
        }
    }
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument DATA\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    data_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument MDLS\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    mdls_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument OUT\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    output_filename = argv[optind++];
    if (optind < argc) {
        fprintf(stderr, "%s: unexpected argument: %s\n", argv[0], argv[optind]);
        print_usage(argv[0]);
        return 1;
    }
    data = csv_load_file(data_filename);
    if (data == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], data_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    mdls = csv_load_file(mdls_filename);
    if (mdls == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], mdls_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    if (data->size1 != mdls->size1 || data->size2 != mdls->size2) {
        fprintf(stderr, "Non-matching `data' and `mdls' dimensions\n");
        exit_val = GSL_EBADLEN;
        goto exit;
    }
    p.data = data;
    p.mdls = mdls;
    gibbs_problem_exec(&p);
    ncdf_write_file(output_filename, &p);
    gibbs_problem_free(&p);
exit:
    if (data != ((void *)0)) {
        gsl_matrix_free(data);
    }
    if (mdls != ((void *)0)) {
        gsl_matrix_free(mdls);
    }
    return exit_val;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char *data_filename;
    char *mdls_filename;
    char *output_filename;
    struct gibbs_problem p = {
        ((void *)0),
        ((void *)0),
        1000,
        0,
        1,
        0,
        ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
    struct gsl_matrix *data = ((void *)0);
    struct gsl_matrix *mdls = ((void *)0);
    int optflag;
    int exit_val = 0;
    opterr = 0;
    while ((optflag = getopt(argc, argv, "n:b:d:r:h")) != -1) {
        char *endptr = ((void *)0);
        switch (optflag) {
            case 'n':
                p.iterations = strtol(optarg, &endptr, 10);
                break;
            case 'b':
                p.burn = strtol(optarg, &endptr, 10);
                break;
            case 'd':
                p.draws = strtol(optarg, &endptr, 10);
                break;
            case 'r':
                p.seed = strtol(optarg, &endptr, 0);
                break;
            case 'h':
                print_usage(argv[0]);
                return 0;
            case '?':
                fprintf(stderr, "%s: invalid option or missing argument: -'%c'\n",
                        argv[0], optopt);
                print_usage(argv[0]);
                return 1;
        }
    }
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument DATA\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    data_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument MDLS\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    mdls_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument OUT\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    output_filename = argv[optind++];
    if (optind < argc) {
        fprintf(stderr, "%s: unexpected argument: %s\n", argv[0], argv[optind]);
        print_usage(argv[0]);
        return 1;
    }
    data = csv_load_file(data_filename);
    if (data == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], data_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    mdls = csv_load_file(mdls_filename);
    if (mdls == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], mdls_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    if (data->size1 != mdls->size1 || data->size2 != mdls->size2) {
        fprintf(stderr, "Non-matching `data' and `mdls' dimensions\n");
        exit_val = GSL_EBADLEN;
        goto exit;
    }
    p.data = data;
    p.mdls = mdls;
    gibbs_problem_exec(&p);
    ncdf_write_file(output_filename, &p);
    gibbs_problem_free(&p);
exit:
    if (data != ((void *)0)) {
        gsl_matrix_free(data);
    }
    if (mdls != ((void *)0)) {
        gsl_matrix_free(mdls);
    }
    return exit_val;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct gibbs_problem { struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *data; struct gsl_matrix *mdls; unsigned long iterations; unsigned long burn; unsigned long draws; long seed; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; } *mthet; struct gsl_matrix *msig; struct gsl_matrix **ddata; unsigned long *dindexes; }

variable_types: optflag int

variable_types:
endptr
char *


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return fprintf(
stderr,
"Usage: %s [OPTION] DATA MDLS OUT\n"
" -n int number of iterations (default 1000)\n"
" -b int number of iterations to burn-in (default 0)\n"
" -d int number of random draws (default 1)\n"
" -r int random seed (default 0)\n"
" -h show this help\n",
a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(
stderr,
"Usage: %s [OPTION] DATA MDLS OUT\n"
" -n int number of iterations (default 1000)\n"
" -b int number of iterations to burn-in (default 0)\n"
" -d int number of random draws (default 1)\n"
" -r int random seed (default 0)\n"
" -h show this help\n",
a1);
}

variable_types:
progname
char *


clear

repo: kremlhi/tetris

decompiled_code:
int clear()
{
return printf("\x1B[2J");
}

canonical_decompiled_code:
int func0()
{
return printf("\x1B[2J");
}

original_code:
void
clear(void)
{
 printf("\033[" "2J");
}


posxy

decompiled_code:
int __fastcall posxy(int a1, int a2)
{
int result; // eax

if ( a2 > 3 )
result = printf("\x1B[%d;%dH", (unsigned int)(a2 - 3), (unsigned int)(2 * a1 + 27));
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2)
{
int result; // eax

if ( a2 > 3 )
result = printf("\x1B[%d;%dH", (unsigned int)(a2 - 3), (unsigned int)(2 * a1 + 27));
return result;
}

original_code:
void
posxy(int x, int y)
{
 if(y < 4)
  return;
 printf("\033[" "%d;%dH", y - 3, x*2 + 27);
}

variable_types: x int

variable_types: y int


drawpixel

decompiled_code:
int __fastcall drawpixel(int a1, int a2, unsigned int a3)
{
int result; // eax

if ( a2 > 3 )
{
posxy(a1, a2);
result = printf("\x1B[7;%dm \x1B[0m", a3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, int a2, unsigned int a3)
{
int result; // eax

if ( a2 > 3 )
{
func1(a1, a2);
result = printf("\x1B[7;%dm \x1B[0m", a3);
}
return result;
}

original_code:
void
drawpixel(int x, int y, enum colour_t colour)
{
 if(y < 4)
  return;
 posxy(x, y);
 printf("\033[" "7;%dm" "  " "\033[" "0m", colour);
}

variable_types: enum colour_t { NORMAL=0, INVERT=7, BGCOLOUR=30, RED=31, GREEN=32, YELLOW=33, BLUE=34, MAGENTA=35, CYAN=36, GREY=37 }


flush

decompiled_code:
int flush()
{
printf("\x1B[24;1H");
return fflush(stdout);
}

canonical_decompiled_code:
int func3()
{
printf("\x1B[24;1H");
return fflush(stdout);
}

original_code:
void
flush(void)
{
 printf("\033[" "24;1H");
 fflush(stdout);
}

canonical_original_code:
void flush()
{
 printf("\033[" "24;1H");
 fflush(stdout);
}


cleanexit

decompiled_code:
void __noreturn cleanexit()
{
tcsetattr(0, 0, &oldt);
exit(0);
}

canonical_decompiled_code:
void __noreturn func4()
{
tcsetattr(0, 0, &oldt);
exit(0);
}

original_code:
void
cleanexit(int sig)
{
 tcsetattr(0, 0, &oldt);
 exit(0);
}

variable_types: sig int


redraw

decompiled_code:
void redraw()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void
redraw(int sig)
{
}

canonical_original_code:
void redraw(int sig)
{
}


init

decompiled_code:
int init()
{
speed_t v0; // eax
int result; // eax

if ( tcgetattr(0, &oldt) == -1 )
err(1, "tcgetattr");
*(_QWORD *)&newt_1.c_cc[31] = *(_QWORD *)&oldt.c_cc[31];
v0 = oldt.c_ospeed;
*(__m128i *)&newt_1.c_iflag = _mm_load_si128((const __m128i *)&oldt);
*(__m128i *)&newt_1.c_line = _mm_load_si128((const __m128i *)&oldt.c_line);
newt_1.c_lflag &= 0xFFFFFFF5;
newt_1.c_ospeed = v0;
*(__m128i *)&newt_1.c_cc[15] = _mm_load_si128((const __m128i *)&oldt.c_cc[15]);
result = tcsetattr(0, 0, &newt_1);
if ( result == -1 )
err(1, "tcsetattr");
return result;
}

canonical_decompiled_code:
int func6()
{
speed_t v0; // eax
int result; // eax

if ( tcgetattr(0, &oldt) == -1 )
err(1, "tcgetattr");
*(_QWORD *)&newt_1.c_cc[31] = *(_QWORD *)&oldt.c_cc[31];
v0 = oldt.c_ospeed;
*(__m128i *)&newt_1.c_iflag = _mm_load_si128((const __m128i *)&oldt);
*(__m128i *)&newt_1.c_line = _mm_load_si128((const __m128i *)&oldt.c_line);
newt_1.c_lflag &= 0xFFFFFFF5;
newt_1.c_ospeed = v0;
*(__m128i *)&newt_1.c_cc[15] = _mm_load_si128((const __m128i *)&oldt.c_cc[15]);
result = tcsetattr(0, 0, &newt_1);
if ( result == -1 )
err(1, "tcsetattr");
return result;
}

original_code:
void
init(void)
{
 static struct termios newt;
 if(tcgetattr(0, &oldt) == -1)
  err(1, "tcgetattr");
 newt = oldt;
 newt.c_lflag &= ~(0000002 | 0000010);
 if(tcsetattr(0, 0, &newt) == -1)
  err(1, "tcsetattr");
}

canonical_original_code:
void init()
{
 static struct termios newt;
 if(tcgetattr(0, &oldt) == -1)
  err(1, "tcgetattr");
 newt = oldt;
 newt.c_lflag &= ~(0000002 | 0000010);
 if(tcsetattr(0, 0, &newt) == -1)
  err(1, "tcsetattr");
}

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


readch

decompiled_code:
__int64 readch()
{
__int64 result; // rax
unsigned __int8 buf; // [rsp+Dh] [rbp-Bh] BYREF
char v2; // [rsp+Eh] [rbp-Ah] BYREF
char v3; // [rsp+Fh] [rbp-9h]

read(0, &buf, 1uLL);
result = buf;
if ( buf == 27 )
{
read(0, &v2, 2uLL);
result = 0LL;
if ( v2 == 91 && (unsigned __int8)(v3 - 65) <= 3u )
result = (unsigned __int8)CSWTCH_10[(unsigned __int8)(v3 - 65)];
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
unsigned __int8 buf; // [rsp+Dh] [rbp-Bh] BYREF
char v2; // [rsp+Eh] [rbp-Ah] BYREF
char v3; // [rsp+Fh] [rbp-9h]

read(0, &buf, 1uLL);
result = buf;
if ( buf == 27 )
{
read(0, &v2, 2uLL);
result = 0LL;
if ( v2 == 91 && (unsigned __int8)(v3 - 65) <= 3u )
result = (unsigned __int8)CSWTCH_10[(unsigned __int8)(v3 - 65)];
}
return result;
}

original_code:
char
readch(void)
{
 char c, c2[2];
 read(0, &c, 1);
 if(c == "\033["[0]){
  read(0, c2, 2);
  if(c2[0] != "\033["[1])
   return '\0';
  switch(c2[1]){
  case 'A': return 'k';
  case 'B': return ' ';
  case 'C': return 'l';
  case 'D': return 'j';
  }
  return '\0';
 }
 return c;
}

canonical_original_code:
char readch()
{
 char c; char c2[2];
 read(0, &c, 1);
 if(c == "\033["[0]){
  read(0, c2, 2);
  if(c2[0] != "\033["[1])
   return '\0';
  switch(c2[1]){
  case 'A': return 'k';
  case 'B': return ' ';
  case 'C': return 'l';
  case 'D': return 'j';
  }
  return '\0';
 }
 return c;
}

variable_types: c char

return_type: char


drawtext

decompiled_code:
int drawtext(char *format, ...)
{
int v1; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
v1 = vsnprintf(buf_0, 0x50uLL, format, arg);
posxy(5 - v1 / 4, 12);
printf("%s", buf_0);
return flush();
}

canonical_decompiled_code:
int func8(char *format, ...)
{
int v1; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
v1 = vsnprintf(buf_0, 0x50uLL, format, arg);
func1(5 - v1 / 4, 12);
printf("%s", buf_0);
return func3();
}

original_code:
void
drawtext(char *fmt, ...)
{
 va_list ap;
 static char buf[80];
 int len;
 __builtin_va_start(ap,fmt);
 len = vsnprintf(buf, sizeof buf, fmt, ap);
 __builtin_va_end(ap);
 posxy(10/2 - len/4, (20 + 4)/2);
 printf("%s", buf);
 flush();
}

canonical_original_code:
void drawtext(char *fmt, ...)
{
 __builtin_va_list ap;
 static char buf[80];
 int len;
 __builtin_va_start(ap,fmt);
 len = vsnprintf(buf, sizeof buf, fmt, ap);
 __builtin_va_end(ap);
 posxy(10/2 - len/4, (20 + 4)/2);
 printf("%s", buf);
 flush();
}

variable_types:
fmt
char *

variable_types:
buf
char [80]

variable_types: len int


printUsage

repo: krendil/getverse

decompiled_code:
int printUsage()
{
return printf(
"Usage:\tgetverse -t <translation> [-f format] [<reference>]\n"
"\tgetverse [-h | -?]\n"
"Options:\n"
"\t-t\tA Bible translation you have installed in SWORD (e.g. KJV)\n"
"\t-f\tA format string that will determine the format of the output\n"
"\t\t Defaults to '%%p'\n"
"\t-h\n"
"\t-?\tDisplay this message and exit\n"
"Format variables:\n"
"\t%%p\tThe passage text\n"
"\t%%t\tThe translation name\n"
"\t%%r\tThe supplied reference\n"
"\t%%%%\tA literal %% character\n"
"\n"
"If no reference is supplied, getverse tries to read from stdin.\n");
}

canonical_decompiled_code:
int func0()
{
return printf(
"Usage:\tgetverse -t <translation> [-f format] [<reference>]\n"
"\tgetverse [-h | -?]\n"
"Options:\n"
"\t-t\tA Bible translation you have installed in SWORD (e.g. KJV)\n"
"\t-f\tA format string that will determine the format of the output\n"
"\t\t Defaults to '%%p'\n"
"\t-h\n"
"\t-?\tDisplay this message and exit\n"
"Format variables:\n"
"\t%%p\tThe passage text\n"
"\t%%t\tThe translation name\n"
"\t%%r\tThe supplied reference\n"
"\t%%%%\tA literal %% character\n"
"\n"
"If no reference is supplied, getverse tries to read from stdin.\n");
}

original_code:
void printUsage() {
    printf( "Usage:	getverse -t <translation> [-f format] [<reference>]\n" "	getverse [-h | -?]\n" "Options:\n" "	-t	A Bible translation you have installed in SWORD (e.g. KJV)\n" "	-f	A format string that will determine the format of the output\n" "		 Defaults to '%%p'\n" "	-h\n" "	-?	Display this message and exit" "\n" "Format variables:\n" "	%%p	The passage text\n" "	%%t	The translation name\n" "	%%r	The supplied reference\n" "	%%%%	A literal %% character\n" "\n" "If no reference is supplied, getverse tries to read from stdin.\n" );
}


setReference

decompiled_code:
char *__fastcall setReference(int a1, const char **a2)
{
const char *v2; // rbp
size_t v3; // rax
char *v4; // rax
char *v5; // rbp
const char **v6; // r13
int v7; // ebx
const char *v8; // r14

v2 = *a2;
v3 = strlen(*a2);
v4 = (char *)calloc(1uLL, v3);
v5 = strcat(v4, v2);
if ( a1 > 1 )
{
v6 = a2 + 1;
v7 = 0;
do
{
v8 = *v6++;
v7 += strlen(v8 + 1);
v5 = (char *)realloc(v5, v7);
*(_WORD *)&v5[strlen(v5)] = 32;
strcat(v5, v8);
}
while ( &a2[(unsigned int)(a1 - 2) + 2] != v6 );
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func1(int a1, const char **a2)
{
const char *v2; // rbp
size_t v3; // rax
char *v4; // rax
char *v5; // rbp
const char **v6; // r13
int v7; // ebx
const char *v8; // r14

v2 = *a2;
v3 = strlen(*a2);
v4 = (char *)calloc(1uLL, v3);
v5 = strcat(v4, v2);
if ( a1 > 1 )
{
v6 = a2 + 1;
v7 = 0;
do
{
v8 = *v6++;
v7 += strlen(v8 + 1);
v5 = (char *)realloc(v5, v7);
*(_WORD *)&v5[strlen(v5)] = 32;
strcat(v5, v8);
}
while ( &a2[(unsigned int)(a1 - 2) + 2] != v6 );
}
return v5;
}

original_code:
char * setReference( int count, char ** words ) {
    int size = 0;
    char * reference = (char*)calloc(1, strlen(words[0]));
    reference = strcat(reference, words[0]);
    for( int i = 1; i < count; i++ ) {
        size += strlen(words[i]+1);
        reference = (char*)realloc(reference, size);
        reference = strcat(strcat(reference, " "), words[i]);
    }
    return reference;
}

canonical_original_code:
char *setReference(int count, char **words) {
    int size = 0;
    char *reference = (char*)calloc(1, strlen(words[0]));
    reference = strcat(reference, words[0]);
    for( int i = 1; i < count; i++ ) {
        size += strlen(words[i]+1);
        reference = (char *)realloc(reference, size);
        reference = strcat(strcat(reference, " "), words[i]);
    }
    return reference;
}

variable_types: count int

variable_types:
words
char **

variable_types: size int

variable_types:
reference
char *

variable_types: i int


readReference

decompiled_code:
char *readReference()
{
char *v0; // rbp
size_t v1; // rbx
char *v2; // rax
int v3; // esi

v0 = 0LL;
v1 = 32LL;
do
{
v2 = (char *)realloc(v0, v1);
v3 = v1;
v1 += 32LL;
v0 = v2;
}
while ( !fgets(v2, v3, stdin) );
return v0;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // rbp
size_t v1; // rbx
char *v2; // rax
int v3; // esi

v0 = 0LL;
v1 = 32LL;
do
{
v2 = (char *)realloc(v0, v1);
v3 = v1;
v1 += 32LL;
v0 = v2;
}
while ( !fgets(v2, v3, stdin) );
return v0;
}

original_code:
char * readReference() {
    int size = 0;
    char * reference = ((void *)0);
    do {
         size += 32;
         reference = (char*)realloc(reference, size);
     } while (!fgets(reference, size, stdin));
     return reference;
}

canonical_original_code:
char *readReference() {
    int size = 0;
    char *reference = ((void *)0);
    do {
         size += 32;
         reference = (char *)realloc(reference, size);
     } while (!fgets(reference, size, stdin));
     return reference;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ecx
const char *v4; // rbp
const char *v5; // r12
__int64 v6; // rdx
const char *v7; // r8
char v8; // al
char *v9; // rdx
char *v10; // rax
__int64 *v11; // rsi
const char *v12; // rax
char *v13; // rbp
char *v14; // rdi
__int64 v15; // rdx
__int64 v16; // rcx
__int64 v18; // [rsp+0h] [rbp-38h] BYREF
char *s; // [rsp+8h] [rbp-30h]

if ( argc <= 1 )
goto LABEL_29;
v3 = 1;
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = v3;
v7 = argv[v6];
if ( *v7 != 45 )
break;
v8 = v7[1];
if ( v8 != 114 )
{
if ( v8 > 114 )
{
if ( v8 != 116 )
goto LABEL_15;
v5 = argv[v6 + 1];
++v3;
}
else
{
if ( v8 != 102 )
{
if ( v8 == 104 || v8 == 63 )
{
printUsage();
exit(0);
}
LABEL_15:
fprintf(stderr, "Unknown option %s\n", argv[v3]);
goto LABEL_16;
}
v4 = argv[v6 + 1];
++v3;
}
}
if ( argc <= ++v3 )
{
if ( v5 )
goto LABEL_13;
LABEL_29:
fwrite("Please specify a translation with the -t option\n", 1uLL, 0x30uLL, stderr);
exit(1);
}
}
v10 = setReference(argc - v3, &argv[v6]);
v9 = v10;
if ( !v5 )
goto LABEL_29;
if ( !v10 )
LABEL_13:
v9 = readReference();
v11 = (__int64 *)v5;
switch ( (unsigned int)getPassage(&v18, v5, v9, 0LL) )
{
case 0xFFFFFFFC:
fwrite("That chapter doesn't have that many verses.\n", 1uLL, 0x2CuLL, stderr);
exit(1);
case 0xFFFFFFFD:
fwrite("That book doesn't have that many chapters.\n", 1uLL, 0x2BuLL, stderr);
exit(1);
case 0xFFFFFFFE:
fwrite("That passage does not exist.\n", 1uLL, 0x1DuLL, stderr);
exit(1);
case 0xFFFFFFFF:
fprintf(stderr, "Could not find translation '%s'. Are you sure it is installed?\n", v5);
break;
case 0u:
if ( v4 )
{
v11 = &v18;
v12 = (const char *)formatPassage(v4, &v18);
v13 = (char *)v12;
if ( !v12 )
{
fwrite("Unknown variable in format string.\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
puts(v12);
v14 = v13;
free(v13);
}
else
{
v14 = s;
puts(s);
}
deletePassage(v14, v11, v15, v16);
exit(0);
default:
fwrite("Something when wrong. Not quit sure what.", 1uLL, 0x29uLL, stderr);
exit(1);
}
LABEL_16:
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ecx
const char *v4; // rbp
const char *v5; // r12
__int64 v6; // rdx
const char *v7; // r8
char v8; // al
char *v9; // rdx
char *v10; // rax
__int64 *v11; // rsi
const char *v12; // rax
char *v13; // rbp
char *v14; // rdi
__int64 v15; // rdx
__int64 v16; // rcx
__int64 v18; // [rsp+0h] [rbp-38h] BYREF
char *s; // [rsp+8h] [rbp-30h]

if ( argc <= 1 )
goto LABEL_29;
v3 = 1;
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = v3;
v7 = argv[v6];
if ( *v7 != 45 )
break;
v8 = v7[1];
if ( v8 != 114 )
{
if ( v8 > 114 )
{
if ( v8 != 116 )
goto LABEL_15;
v5 = argv[v6 + 1];
++v3;
}
else
{
if ( v8 != 102 )
{
if ( v8 == 104 || v8 == 63 )
{
func0();
exit(0);
}
LABEL_15:
fprintf(stderr, "Unknown option %s\n", argv[v3]);
goto LABEL_16;
}
v4 = argv[v6 + 1];
++v3;
}
}
if ( argc <= ++v3 )
{
if ( v5 )
goto LABEL_13;
LABEL_29:
fwrite("Please specify a translation with the -t option\n", 1uLL, 0x30uLL, stderr);
exit(1);
}
}
v10 = func1(argc - v3, &argv[v6]);
v9 = v10;
if ( !v5 )
goto LABEL_29;
if ( !v10 )
LABEL_13:
v9 = func2();
v11 = (__int64 *)v5;
switch ( (unsigned int)getPassage(&v18, v5, v9, 0LL) )
{
case 0xFFFFFFFC:
fwrite("That chapter doesn't have that many verses.\n", 1uLL, 0x2CuLL, stderr);
exit(1);
case 0xFFFFFFFD:
fwrite("That book doesn't have that many chapters.\n", 1uLL, 0x2BuLL, stderr);
exit(1);
case 0xFFFFFFFE:
fwrite("That passage does not exist.\n", 1uLL, 0x1DuLL, stderr);
exit(1);
case 0xFFFFFFFF:
fprintf(stderr, "Could not find translation '%s'. Are you sure it is installed?\n", v5);
break;
case 0u:
if ( v4 )
{
v11 = &v18;
v12 = (const char *)formatPassage(v4, &v18);
v13 = (char *)v12;
if ( !v12 )
{
fwrite("Unknown variable in format string.\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
puts(v12);
v14 = v13;
free(v13);
}
else
{
v14 = s;
puts(s);
}
deletePassage(v14, v11, v15, v16);
exit(0);
default:
fwrite("Something when wrong. Not quit sure what.", 1uLL, 0x29uLL, stderr);
exit(1);
}
LABEL_16:
exit(1);
}

original_code:
int main(int argc, char ** argv) {
    char * translation = ((void *)0);
    char * format = ((void *)0);
    char * reference = ((void *)0);
    int red = 0;
    for( int i = 1; i < argc; i++ ) {
        if( argv[i][0] != '-' ) {
            reference = setReference( argc - i, argv + i );
            break;
        }
        switch( argv[i][1] ) {
            case 'f':
                format = argv[++i];
                break;
            case 't':
                translation = argv[++i];
                break;
            case 'r':
                red = 1;
                break;
            case 'h':
            case '?':
                printUsage();
                exit(0);
                break;
            default:
                fprintf(stderr, "Unknown option %s\n", argv[i]);
                exit(1);
                break;
        }
    }
    if(translation == ((void *)0) ) {
        fprintf(stderr, "Please specify a translation with the -t option\n");
        exit(1);
    }
    if( reference == ((void *)0) ) {
        reference = readReference();
    }
    Passage result;
    int err = getPassage(&result, translation, reference, 0);
    switch(err) {
        case -1:
            fprintf(stderr, "Could not find translation '%s'. Are you sure it is installed?\n",
                    translation);
            exit(1); break;
        case -2:
            fprintf(stderr, "That passage does not exist.\n");
            exit(1); break;
        case -3:
            fprintf(stderr, "That book doesn't have that many chapters.\n");
            exit(1); break;
        case -4:
            fprintf(stderr, "That chapter doesn't have that many verses.\n");
            exit(1); break;
        case 0:
            if( format ) {
                char * out = formatPassage(format, &result);
                if(!out) {
                    fprintf(stderr, "Unknown variable in format string.\n");
                    exit(1);
                }
                printf("%s\n", out);
                free(out);
            } else {
                printf("%s\n", result.text);
            }
            deletePassage(result);
            exit(0); break;
        default:
            fprintf(stderr, "Something when wrong. Not quit sure what.");
            exit(1);
    }
}

canonical_original_code:
int main(int argc, char **argv) {
    char *translation = ((void *)0);
    char *format = ((void *)0);
    char *reference = ((void *)0);
    int red = 0;
    for( int i = 1; i < argc; i++ ) {
        if( argv[i][0] != '-' ) {
            reference = setReference( argc - i, argv + i );
            break;
        }
        switch( argv[i][1] ) {
            case 'f':
                format = argv[++i];
                break;
            case 't':
                translation = argv[++i];
                break;
            case 'r':
                red = 1;
                break;
            case 'h':
            case '?':
                printUsage();
                exit(0);
                break;
            default:
                fprintf(stderr, "Unknown option %s\n", argv[i]);
                exit(1);
                break;
        }
    }
    if(translation == ((void *)0) ) {
        fprintf(stderr, "Please specify a translation with the -t option\n");
        exit(1);
    }
    if( reference == ((void *)0) ) {
        reference = readReference();
    }
    struct Passage result;
    int err = getPassage(&result, translation, reference, 0);
    switch(err) {
        case -1:
            fprintf(stderr, "Could not find translation '%s'. Are you sure it is installed?\n",
                    translation);
            exit(1); break;
        case -2:
            fprintf(stderr, "That passage does not exist.\n");
            exit(1); break;
        case -3:
            fprintf(stderr, "That book doesn't have that many chapters.\n");
            exit(1); break;
        case -4:
            fprintf(stderr, "That chapter doesn't have that many verses.\n");
            exit(1); break;
        case 0:
            if( format ) {
                char *out = formatPassage(format, &result);
                if(!out) {
                    fprintf(stderr, "Unknown variable in format string.\n");
                    exit(1);
                }
                printf("%s\n", out);
                free(out);
            } else {
                printf("%s\n", result.text);
            }
            deletePassage(result);
            exit(0); break;
        default:
            fprintf(stderr, "Something when wrong. Not quit sure what.");
            exit(1);
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
translation
char *

variable_types:
format
char *

variable_types: red int

variable_types: struct Passage { char *reference; char *text; char *translation; }

variable_types: err int

variable_types:
out
char *