nCr

decompiled_code:
__int64 __fastcall nCr(int a1, int a2)
{
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rsi
__int64 v5; // rcx

LODWORD(v2) = a1 - a2 + 1;
if ( a1 < (int)v2 )
{
result = 1LL;
}
else
{
v2 = (int)v2;
result = 1LL;
do
result *= v2++;
while ( v2 != (unsigned int)(a2 - 1) + (__int64)(a1 - a2) + 2 );
}
if ( a2 > 0 )
{
v4 = (unsigned int)(a2 + 1);
v5 = 1LL;
do
result /= v5++;
while ( v4 != v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rsi
__int64 v5; // rcx

LODWORD(v2) = a1 - a2 + 1;
if ( a1 < (int)v2 )
{
result = 1LL;
}
else
{
v2 = (int)v2;
result = 1LL;
do
result *= v2++;
while ( v2 != (unsigned int)(a2 - 1) + (__int64)(a1 - a2) + 2 );
}
if ( a2 > 0 )
{
v4 = (unsigned int)(a2 + 1);
v5 = 1LL;
do
result /= v5++;
while ( v4 != v5 );
}
return result;
}

original_code:
long nCr(int n, int r)
{
    long ret = 1;
    int i;
    for(i = n-r+1; i <= n; i++) {
        ret *= i;
    }
    for(i = 1; i <= r; i++)
        ret /= i;
    return ret;
}

variable_types: r int

variable_types: ret long

return_type: long


main

canonical_name: main

repo: mchalek/euler

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // rbp
__int64 i; // rbx
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // rax
__int64 v10; // rsi
__int64 v11; // r8
__int64 v12; // rdx

v3 = 0LL;
v4 = 0LL;
for ( i = 2LL; i != 8; ++i )
{
v6 = build((unsigned int)i, 0LL, 20LL, 1LL);
v9 = nCr(7LL, (unsigned int)i, v7, v8, v6);
v10 = (unsigned int)i;
v3 += v9 * v11;
v12 = i;
v4 += v11 * v12 * v9;
printf("ways for n == %d: %ld\n", v10, v11);
}
printf("total sum: %ld\n", v4);
printf("expected: %ld / %ld == %.9f\n", v4, v3, (double)(int)v4 / (double)(int)v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // rbp
__int64 i; // rbx
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // rax
__int64 v10; // rsi
__int64 v11; // r8
__int64 v12; // rdx

v3 = 0LL;
v4 = 0LL;
for ( i = 2LL; i != 8; ++i )
{
v6 = func8((unsigned int)i, 0LL, 20LL, 1LL);
v9 = func7(7LL, (unsigned int)i, v7, v8, v6);
v10 = (unsigned int)i;
v3 += v9 * v11;
v12 = i;
v4 += v11 * v12 * v9;
printf("ways for n == %d: %ld\n", v10, v11);
}
printf("total sum: %ld\n", v4);
printf("expected: %ld / %ld == %.9f\n", v4, v3, (double)(int)v4 / (double)(int)v3);
return 0;
}

original_code:
int main()
{
    long S = 0;
    long S0 = 0;
    int n;
    for(n = 2; n <= 7; n++) {
        long Sn = build(n, 0, 20, 1);
        long ncr = nCr(7, n);
        S0 += Sn * ncr;
        S += n*Sn * ncr;
        printf("ways for n == %d: %ld\n", n, Sn);
    }
    printf("total sum: %ld\n", S);
    printf("expected: %ld / %ld == %.9f\n", S, S0, ((double) S) / S0);
    return 0;
}

variable_types: S long

variable_types: n int

variable_types: Sn long

variable_types: ncr long

return_type: int


build

original_code:
long build(int ncol, int depth, int rem, long weight)
{
    if(depth == ncol)
        return weight;
    int min = (((1) > (rem - 10*(ncol-depth-1))) ? (1) : (rem - 10*(ncol-depth-1)));
    int max = (((rem) < (10)) ? (rem) : (10));
    int count;
    long ret = 0;
    for(count = min; count <= max; count++) {
        ret += build(ncol, depth+1, rem - count, weight * nCr(10, count));
    }
    return ret;
}

variable_types: ncol int

variable_types: depth int

variable_types: rem int

variable_types: weight long

variable_types: min int

variable_types: max int

variable_types: count int


original_code:
int next_int(void) {
    if(++k < 56) {
        long k3 = (k*k*k) % 1000000;
        int result = (100003 - 200003*k + 300007*k3) % 1000000;
        S[read++] = result;
        read %= 55;
        return result;
    } else {
        int read_minus_24 = (read + 55 - 24) % 55;
        int read_minus_55 = read;
        int result = (S[read_minus_24] + S[read_minus_55]) % 1000000;
        S[read++] = result;
        read %= 55;
        return result;
    }
}

canonical_original_code:
int next_int() {
    if(++k < 56) {
        long k3 = (k*k*k) % 1000000;
        int result = (100003 - 200003*k + 300007*k3) % 1000000;
        S[read++] = result;
        read %= 55;
        return result;
    } else {
        int read_minus_24 = (read + 55 - 24) % 55;
        int read_minus_55 = read;
        int result = (S[read_minus_24] + S[read_minus_55]) % 1000000;
        S[read++] = result;
        read %= 55;
        return result;
    }
}

variable_types: result int


decompiled_code:
unsigned __int64 next_call()
{
int v0; // eax
__int64 v1; // r10

next_int();
v0 = next_int();
return v0 | (unsigned __int64)(v1 << 32);
}

canonical_decompiled_code:
unsigned __int64 func14()
{
int v0; // eax
__int64 v1; // r10

func13();
v0 = func13();
return v0 | (unsigned __int64)(v1 << 32);
}

original_code:
uint64_t next_call() {
    int c0 = next_int();
    int c1 = next_int();
    uint64_t result = c1;
    result |= ((uint64_t) c0) << 32;
    return result;
}

canonical_original_code:
unsigned long next_call() {
    int c0 = next_int();
    int c1 = next_int();
    unsigned long result = c1;
    result |= ((unsigned long) c0) << 32;
    return result;
}

variable_types:
result
unsigned long

return_type: unsigned long


original_code:
_Bool in_pm_net(int caller, uint64_t *is_friend) {
    int word = caller / 64;
    uint64_t bit = 1ul << (caller % 64);
    return is_friend[word] & bit;
}

canonical_original_code:
_Bool in_pm_net(int caller, unsigned long *is_friend) {
    int word = caller / 64;
    unsigned long bit = 1ul << (caller % 64);
    return is_friend[word] & bit;
}

variable_types: caller int

variable_types: word int

variable_types:
bit
unsigned long


original_code:
_Bool set_if_not(int caller, uint64_t *is_friend) {
    int word = caller / 64;
    uint64_t bit = 1ul << (caller % 64);
    _Bool state = is_friend[word] & bit;
    is_friend[word] |= bit;
    return state;
}

canonical_original_code:
_Bool set_if_not(int caller, unsigned long *is_friend) {
    int word = caller / 64;
    unsigned long bit = 1ul << (caller % 64);
    _Bool state = is_friend[word] & bit;
    is_friend[word] |= bit;
    return state;
}


decompiled_code:
__int64 __fastcall count_connected(unsigned __int64 *a1)
{
unsigned __int64 v2; // rdi
int v3; // eax
int v4; // er8
unsigned int v5; // er8
unsigned __int64 *v6; // r9

do
{
v2 = *a1++;
v3 = popcnt(v2);
v5 = v3 + v4;
}
while ( a1 != v6 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned __int64 *a1)
{
unsigned __int64 v2; // rdi
int v3; // eax
int v4; // er8
unsigned int v5; // er8
unsigned __int64 *v6; // r9

do
{
v2 = *a1++;
v3 = func8(v2);
v5 = v3 + v4;
}
while ( a1 != v6 );
return v5;
}

original_code:
int count_connected(uint64_t *words) {
    int ret = 0;
    int i;
    int num_words = (1000000 +63) / 64;
    for(i = 0; i < num_words; i++) {
        ret += _popcnt(words[i]);
    }
    return ret;
}

canonical_original_code:
int count_connected(unsigned long *words) {
    int ret = 0;
    int i;
    int num_words = (1000000 +63) / 64;
    for(i = 0; i < num_words; i++) {
        ret += _popcnt(words[i]);
    }
    return ret;
}

variable_types:
words
unsigned long *

variable_types: ret int

variable_types: i int


propagate

decompiled_code:
__int64 __fastcall propagate(int a1, __int64 a2, __int64 a3)
{
int v4; // er12
int *v5; // rax
int src[3]; // [rsp+Ch] [rbp-4Ch] BYREF
int v8; // [rsp+18h] [rbp-40h] BYREF
int v9; // [rsp+1Ch] [rbp-3Ch] BYREF
size_t v10[7]; // [rsp+20h] [rbp-38h] BYREF

src[0] = a1;
set_if_not(a1, a2);
queue_init_constprop_0_isra_0(v10);
enqueue_isra_0(src, v10);
while ( (unsigned __int8)dequeue(&v8, v10) )
{
v4 = 0;
v5 = (int *)(a3 + ((__int64)v8 << 10));
if ( *v5 > 0 )
{
do
{
v9 = v5[v4 + 1];
if ( !set_if_not(v9, a2) )
enqueue_isra_0(&v9, v10);
++v4;
v5 = (int *)(a3 + ((__int64)v8 << 10));
}
while ( *v5 > v4 );
}
}
return queue_cleanup_isra_0(v10);
}

original_code:
void propagate(int caller, uint64_t *is_friend, user_t *calls) {
    set_if_not(caller, is_friend);
    queue_t q;
    queue_init(sizeof(int), &q);
    enqueue(&caller, &q);
    int user;
    while(dequeue(&user, &q)) {
        int i;
        for(i = 0; i < calls[user].num_calls; i++) {
            int friend = calls[user].called[i];
            if(!set_if_not(friend, is_friend)) {
                enqueue(&friend, &q);
            }
        }
    }
    queue_cleanup(&q);
}

canonical_original_code:
void propagate(int caller, unsigned long *is_friend, struct user_t *calls) {
    set_if_not(caller, is_friend);
    struct queue_t q;
    queue_init(sizeof(int), &q);
    enqueue(&caller, &q);
    int user;
    while(dequeue(&user, &q)) {
        int i;
        for(i = 0; i < calls[user].num_calls; i++) {
            int friend = calls[user].called[i];
            if(!set_if_not(friend, is_friend)) {
                enqueue(&friend, &q);
            }
        }
    }
    queue_cleanup(&q);
}

variable_types: struct user_t { int num_calls; int called[255]; } *

variable_types: struct queue_t { long item_size; long num_items; struct _payload_t { void *item; struct _payload_t *next; struct _payload_t *prev; } *head; }

variable_types: user int

variable_types: friend int

return_type: void

user_defined_types: struct queue_t { long item_size; long num_items; struct _payload_t *head; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
void *v4; // r13
void *v5; // r15
int v6; // ebp
unsigned __int64 v7; // rax
unsigned int v8; // er12
unsigned __int64 v9; // rbx
char v10; // r9
char v12; // [rsp+Eh] [rbp-3Ah]
char v13; // [rsp+Fh] [rbp-39h]

v3 = 0;
v4 = calloc(0x3D09uLL, 8uLL);
set_if_not(0x7FFFFLL, v4);
v5 = calloc(0xF4240uLL, 0x400uLL);
v6 = count_connected(v4);
do
{
v7 = next_call();
v8 = v7;
v9 = HIDWORD(v7);
if ( HIDWORD(v7) != (_DWORD)v7 )
{
++v3;
insert(HIDWORD(v7), (unsigned int)v7, v5);
v12 = in_pm_net((unsigned int)v9, v4);
v10 = in_pm_net(v8, v4);
if ( __ROR4__(197912093 * v3, 5) <= 0xA7C5u )
{
v13 = v10;
printf("%d / %d connected after %d calls\n", (unsigned int)v6, 1000000LL, v3);
v10 = v13;
}
if ( v12 != v10 )
{
if ( v12 )
propagate(v8, v4, v5);
else
propagate((unsigned int)v9, v4, v5);
v6 = count_connected(v4);
}
}
}
while ( v6 <= 989999 );
printf("99%% coverage after %d calls!\n", v3);
printf("%d connected out of %d users\n", (unsigned int)v6, 1000000LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
void *v4; // r13
void *v5; // r15
int v6; // ebp
unsigned __int64 v7; // rax
unsigned int v8; // er12
unsigned __int64 v9; // rbx
char v10; // r9
char v12; // [rsp+Eh] [rbp-3Ah]
char v13; // [rsp+Fh] [rbp-39h]

v3 = 0;
v4 = calloc(0x3D09uLL, 8uLL);
func18(0x7FFFFLL, v4);
v5 = calloc(0xF4240uLL, 0x400uLL);
v6 = func19(v4);
do
{
v7 = func14();
v8 = v7;
v9 = HIDWORD(v7);
if ( HIDWORD(v7) != (_DWORD)v7 )
{
++v3;
func16(HIDWORD(v7), (unsigned int)v7, v5);
v12 = func17((unsigned int)v9, v4);
v10 = func17(v8, v4);
if ( __ROR4__(197912093 * v3, 5) <= 0xA7C5u )
{
v13 = v10;
printf("%d / %d connected after %d calls\n", (unsigned int)v6, 1000000LL, v3);
v10 = v13;
}
if ( v12 != v10 )
{
if ( v12 )
func20(v8, v4, v5);
else
func20((unsigned int)v9, v4, v5);
v6 = func19(v4);
}
}
}
while ( v6 <= 989999 );
printf("99%% coverage after %d calls!\n", v3);
printf("%d connected out of %d users\n", (unsigned int)v6, 1000000LL);
return 0;
}

original_code:
int main(void) {
    uint64_t *is_friend = calloc((1000000 +63) / 64, sizeof(uint64_t));
    set_if_not(524287, is_friend);
    user_t *calls = calloc(1000000, sizeof(user_t));
    int network_size = 1000000;
    int connected = count_connected(is_friend);
    int num_calls = 0;
    do {
        uint64_t this_call = next_call();
        int caller0 = this_call >> 32;
        int caller1 = this_call & 0xffffffff;
        if(caller0 == caller1)
            continue;
        num_calls++;
        insert(caller0, caller1, calls);
        _Bool c0_in_net = in_pm_net(caller0, is_friend);
        _Bool c1_in_net = in_pm_net(caller1, is_friend);
        if(!(num_calls % 100000))
            printf("%d / %d connected after %d calls\n", connected, network_size, num_calls);
        if(!(c0_in_net ^ c1_in_net))
            continue;
        if(c0_in_net) {
            propagate(caller1, is_friend, calls);
        } else {
            propagate(caller0, is_friend, calls);
        }
        connected = count_connected(is_friend);
    } while(connected < (network_size * 99) / 100);
    printf("99%% coverage after %d calls!\n", num_calls);
    printf("%d connected out of %d users\n", connected, network_size);
    return 0;
}

canonical_original_code:
int main() {
    unsigned long *is_friend = calloc((1000000 +63) / 64, sizeof(uint64_t));
    set_if_not(524287, is_friend);
    struct user_t *calls = calloc(1000000, sizeof(user_t));
    int network_size = 1000000;
    int connected = count_connected(is_friend);
    int num_calls = 0;
    do {
        unsigned long this_call = next_call();
        int caller0 = this_call >> 32;
        int caller1 = this_call & 0xffffffff;
        if(caller0 == caller1)
            continue;
        num_calls++;
        insert(caller0, caller1, calls);
        _Bool c0_in_net = in_pm_net(caller0, is_friend);
        _Bool c1_in_net = in_pm_net(caller1, is_friend);
        if(!(num_calls % 100000))
            printf("%d / %d connected after %d calls\n", connected, network_size, num_calls);
        if(!(c0_in_net ^ c1_in_net))
            continue;
        if(c0_in_net) {
            propagate(caller1, is_friend, calls);
        } else {
            propagate(caller0, is_friend, calls);
        }
        connected = count_connected(is_friend);
    } while(connected < (network_size * 99) / 100);
    printf("99%% coverage after %d calls!\n", num_calls);
    printf("%d connected out of %d users\n", connected, network_size);
    return 0;
}

variable_types: connected int

user_defined_types: struct user_t { int num_calls; int called[255]; }


dequeue

decompiled_code:
__int64 __fastcall dequeue(void *a1, size_t *a2)
{
size_t v2; // rbp
size_t v3; // rax

v2 = a2[2];
if ( !v2 )
return 0LL;
if ( a1 )
{
memcpy(a1, *(const void **)v2, *a2);
v2 = a2[2];
}
v3 = *(_QWORD *)(v2 + 8);
a2[2] = v3;
if ( v3 )
*(_QWORD *)(v3 + 16) = 0LL;
else
a2[3] = 0LL;
free(*(void **)v2);
free((void *)v2);
--a2[1];
return 1LL;
}

original_code:
static _Bool dequeue(void *item, queue_t *q) {
    if(q->head == ((void *)0)) {
        return 0;
    }
    if(item != ((void *)0))
        memcpy(item, q->head->item, q->item_size);
    payload_t *node = q->head;
    q->head = q->head->next;
    if(((void *)0) != q->head) {
        q->head->prev = ((void *)0);
    } else {
        q->tail = ((void *)0);
    }
    free(node->item);
    free(node);
    q->num_items--;
    return 1;
}

canonical_original_code:
static _Bool dequeue(void *item, struct queue_t *q) {
    if(q->head == ((void *)0)) {
        return 0;
    }
    if(item != ((void *)0))
        memcpy(item, q->head->item, q->item_size);
    struct _payload_t *node = q->head;
    q->head = q->head->next;
    if(((void *)0) != q->head) {
        q->head->prev = ((void *)0);
    } else {
        q->tail = ((void *)0);
    }
    free(node->item);
    free(node);
    q->num_items--;
    return 1;
}

variable_types:
item
void *

variable_types: struct queue_t { long item_size; long num_items; struct _payload_t { void *item; struct _payload_t *next; struct _payload_t *prev; } *head; } *


insert

decompiled_code:
__int64 __fastcall insert(int a1, int a2, __int64 a3)
{
int *v3; // r8
int v4; // er9
unsigned int v5; // er10

append_user(a1, (int *)(a3 + ((__int64)a2 << 10)));
append_user(v4, v3);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1, int a2, __int64 a3)
{
int *v3; // r8
int v4; // er9
unsigned int v5; // er10

func15(a1, (int *)(a3 + ((__int64)a2 << 10)));
func15(v4, v3);
return v5;
}

original_code:
int insert(int caller0, int caller1, user_t *calls) {
    int num_new_users = !calls[caller0].num_calls + !calls[caller1].num_calls;
    append_user(caller0, calls + caller1);
    append_user(caller1, calls + caller0);
    return num_new_users;
}

canonical_original_code:
int insert(int caller0, int caller1, struct user_t *calls) {
    int num_new_users = !calls[caller0].num_calls + !calls[caller1].num_calls;
    append_user(caller0, calls + caller1);
    append_user(caller1, calls + caller0);
    return num_new_users;
}


original_code:
int max_count(dsum_t *ds, int n, long ndiv, long div[])
{
    int ret = 0;
    int i;
    for(i = 0; i < ndiv; i++) {
        long d = div[i];
        if(d == 1)
            continue;
        if(d == n)
            ret++;
        else
            ret += ds[n / d].nsum;
    }
    return ret;
}

canonical_original_code:
int max_count(struct _ds *ds, int n, long ndiv, long div[])
{
    int ret = 0;
    int i;
    for(i = 0; i < ndiv; i++) {
        long d = div[i];
        if(d == 1)
            continue;
        if(d == n)
            ret++;
        else
            ret += ds[n / d].nsum;
    }
    return ret;
}

variable_types: struct _ds { int nsum; struct _sc { int sum; int count; } *sums; } *

variable_types: n int

variable_types: ndiv long

variable_types:
div
long []

variable_types: d long

user_defined_types: struct _ds { int nsum; struct _sc *sums; }


dedupe

original_code:
void dedupe(int *n, sumcount_t *items)
{
    qsort(items, *n, sizeof(sumcount_t), cmp);
    int i, j;
    j = 1;
    for(i = 1; i < *n; i++) {
        if(cmp(items + i, items + j - 1)) {
            items[j++] = items[i];
        }
    }
    *n = j;
}

canonical_original_code:
void dedupe(int *n, struct _sc *items)
{
    qsort(items, *n, sizeof(sumcount_t), cmp);
    int i; int j;
    j = 1;
    for(i = 1; i < *n; i++) {
        if(cmp(items + i, items + j - 1)) {
            items[j++] = items[i];
        }
    }
    *n = j;
}

variable_types:
n
int *

variable_types:
items
struct _sc { int sum; int count; } *

variable_types: j int


main

original_code:
int main()
{
    dsum_t *ds = calloc(1 + 14000, sizeof(dsum_t));
    ds[1].nsum = 0;
    ds[1].sums = malloc(sizeof(sumcount_t));
    ds[1].sums[0].sum = 0;
    ds[1].sums[0].count = 0;
    int *mps = calloc(1 + 12000, sizeof(int));
    int i;
    int filled = 0;
    long *div;
    div = malloc((1 + 14000)*sizeof(long));
    div[0] = 1;
    for(i = 2; i <= 14000 && filled < 12000 - 2 + 1; i++) {
        int j;
        long nd = 1;
        int max_j = (int) ceil(sqrt(i));
        for(j = 2; j <= max_j; j++) {
            if(!(i % j)) {
                div[nd++] = j;
                div[nd++] = i / j;
            }
        }
        div[nd++] = i;
        insert(ds, i, nd, div);
        for(j = 0; j < ds[i].nsum; j++) {
            int k = i - ds[i].sums[j].sum + ds[i].sums[j].count;
            if(k < 2 || k > 12000)
                continue;
            if(!mps[k]) {
                mps[k] = i;
                filled++;
            }
        }
    }
    for(i = 2; i <= 12000; i++)
        printf("k == %d: %d\n", i, mps[i]);
    return 0;
}

canonical_original_code:
int main()
{
    struct _ds *ds = calloc(1 + 14000, sizeof(dsum_t));
    ds[1].nsum = 0;
    ds[1].sums = malloc(sizeof(sumcount_t));
    ds[1].sums[0].sum = 0;
    ds[1].sums[0].count = 0;
    int *mps = calloc(1 + 12000, sizeof(int));
    int i;
    int filled = 0;
    long *div;
    div = malloc((1 + 14000)*sizeof(long));
    div[0] = 1;
    for(i = 2; i <= 14000 && filled < 12000 - 2 + 1; i++) {
        int j;
        long nd = 1;
        int max_j = (int) ceil(sqrt(i));
        for(j = 2; j <= max_j; j++) {
            if(!(i % j)) {
                div[nd++] = j;
                div[nd++] = i / j;
            }
        }
        div[nd++] = i;
        insert(ds, i, nd, div);
        for(j = 0; j < ds[i].nsum; j++) {
            int k = i - ds[i].sums[j].sum + ds[i].sums[j].count;
            if(k < 2 || k > 12000)
                continue;
            if(!mps[k]) {
                mps[k] = i;
                filled++;
            }
        }
    }
    for(i = 2; i <= 12000; i++)
        printf("k == %d: %d\n", i, mps[i]);
    return 0;
}

variable_types:
mps
int *

variable_types: filled int

variable_types:
div
long *

variable_types: nd long

variable_types: k int


cmp

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

result = (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
result = (unsigned int)(*((_DWORD *)a1 + 1) - *((_DWORD *)a2 + 1));
return result;
}

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

result = (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
result = (unsigned int)(*((_DWORD *)a1 + 1) - *((_DWORD *)a2 + 1));
return result;
}

original_code:
int cmp(const void *va, const void *vb)
{
    const sumcount_t *a = va;
    const sumcount_t *b = vb;
    if(a->sum == b->sum) {
        return a->count - b->count;
    } else {
        return a->sum - b->sum;
    }
}

canonical_original_code:
int cmp(void *va, void *vb)
{
    struct _sc *a = va;
    struct _sc *b = vb;
    if(a->sum == b->sum) {
        return a->count - b->count;
    } else {
        return a->sum - b->sum;
    }
}

variable_types:
va
void *

variable_types:
vb
void *

variable_types:
a
struct _sc { int sum; int count; } *

variable_types:
b
struct _sc { int sum; int count; } *


insert

original_code:
void insert(dsum_t *ds, int n, long ndiv, long div[]) {
    sumcount_t *tmp = malloc(max_count(ds, n, ndiv, div) * sizeof(sumcount_t));
    int c = 0;
    int i;
    for(i = 0; i < ndiv; i++) {
        long d = div[i];
        if(d == 1)
            continue;
        if(d == n) {
            tmp[c].sum = n;
            tmp[c++].count = 1;
        } else {
            int rem = n / d;
            int j;
            for(j = 0; j < ds[rem].nsum; j++) {
                tmp[c].sum = d + ds[rem].sums[j].sum;
                tmp[c++].count = 1 + ds[rem].sums[j].count;
            }
        }
    }
    dedupe(&c, tmp);
    ds[n].nsum = c;
    ds[n].sums = realloc(tmp, c*sizeof(sumcount_t));
}

canonical_original_code:
void insert(struct _ds *ds, int n, long ndiv, long div[]) {
    struct _sc *tmp = malloc(max_count(ds, n, ndiv, div) * sizeof(sumcount_t));
    int c = 0;
    int i;
    for(i = 0; i < ndiv; i++) {
        long d = div[i];
        if(d == 1)
            continue;
        if(d == n) {
            tmp[c].sum = n;
            tmp[c++].count = 1;
        } else {
            int rem = n / d;
            int j;
            for(j = 0; j < ds[rem].nsum; j++) {
                tmp[c].sum = d + ds[rem].sums[j].sum;
                tmp[c++].count = 1 + ds[rem].sums[j].count;
            }
        }
    }
    dedupe(&c, tmp);
    ds[n].nsum = c;
    ds[n].sums = realloc(tmp, c*sizeof(sumcount_t));
}

variable_types: struct _ds { int nsum; struct _sc { int sum; int count; } *sums; } *

variable_types:
tmp
struct _sc { int sum; int count; } *

variable_types: c int

variable_types: i int

variable_types: rem int


pairCmp

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

result = 0xFFFFFFFFLL;
if ( *(double *)a2 <= *(double *)a1 )
result = 1LL;
return result;
}

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

result = 0xFFFFFFFFLL;
if ( *(double *)a2 <= *(double *)a1 )
result = 1LL;
return result;
}

original_code:
int pairCmp(const void *A, const void *B)
{
    return (((struct arrpair *) A) -> sum < ((struct arrpair *) B) -> sum) ? -1 : 1;
}

canonical_original_code:
int pairCmp(void *A, void *B)
{
    return (((struct arrpair *) A) -> sum < ((struct arrpair *) B) -> sum) ? -1 : 1;
}

variable_types:
A
void *

variable_types:
B
void *


sumList

decompiled_code:
__int64 __fastcall sumList(int a1, int a2, int a3, int a4, int a5, int *a6, double a7, __int64 a8)
{
__int64 v12; // rbx
__int64 v13; // rsi
__int64 v14; // rax
int v15; // edx
__int64 result; // rax

if ( a4 <= a5 )
{
v12 = a4;
do
{
v13 = 1LL << ((unsigned __int8)v12++ - (unsigned __int8)a3);
sumList(a1, a2 | v13, a3, v12, a5, (_DWORD)a6, a8);
}
while ( a5 >= (int)v12 );
}
*(_DWORD *)(a8 + 16LL * *a6 + 8) = a2;
v14 = *a6;
v15 = v14 + 1;
result = 16 * v14;
*a6 = v15;
*(double *)(a8 + result) = a7;
return result;
}

original_code:
void sumList(const double logp[], int p, double sum, int zero, int n, int nstop, int *k, struct arrpair list[])
{
    if(n > nstop) {
        list[*k].p = p;
        list[(*k)++].sum = sum;
        return;
    }
    sumList(logp, p | (1l << (n-zero)), sum + logp[n], zero, n + 1, nstop, k, list);
    sumList(logp, p, sum, zero, n + 1, nstop, k, list);
    return;
}

canonical_original_code:
void sumList(double logp[], int p, double sum, int zero, int n, int nstop, int *k, struct arrpair list[])
{
    if(n > nstop) {
        list[*k].p = p;
        list[(*k)++].sum = sum;
        return;
    }
    sumList(logp, p | (1l << (n-zero)), sum + logp[n], zero, n + 1, nstop, k, list);
    sumList(logp, p, sum, zero, n + 1, nstop, k, list);
    return;
}

variable_types:
logp
double []

variable_types: p int

variable_types: sum double

variable_types: zero int

variable_types: n int

variable_types: nstop int

variable_types:
k
int *

variable_types: struct arrpair { double sum; int p; } []


findMax

decompiled_code:
const __m128i *__fastcall findMax(int a1, const __m128i *a2, __m128i *a3, double a4)
{
const __m128i *result; // rax
int v7; // ecx
int v8; // edx
double v9; // xmm0_8

result = &a2[a1 - 1];
if ( a4 > *(double *)result->m128i_i64 )
{
*a3 = _mm_loadu_si128(result);
}
else
{
if ( !a1 || (v7 = a1 / 2, a1 == 1) )
{
result = a2;
}
else
{
v8 = 0;
do
{
result = &a2[v7];
v9 = *(double *)result->m128i_i64;
if ( *(double *)result->m128i_i64 <= a4 )
{
if ( a4 > v9 )
v8 = v7;
}
else
{
if ( a4 > v9 )
goto LABEL_13;
a1 = v7;
}
if ( v8 == a1 )
goto LABEL_13;
v7 = (v8 + a1) / 2;
}
while ( v8 + 1 != a1 );
result = &a2[(v8 + a1) / 2];
}
LABEL_13:
*a3 = _mm_loadu_si128(result);
}
return result;
}

canonical_decompiled_code:
const __m128i *__fastcall func9(int a1, const __m128i *a2, __m128i *a3, double a4)
{
const __m128i *result; // rax
int v7; // ecx
int v8; // edx
double v9; // xmm0_8

result = &a2[a1 - 1];
if ( a4 > *(double *)result->m128i_i64 )
{
*a3 = _mm_loadu_si128(result);
}
else
{
if ( !a1 || (v7 = a1 / 2, a1 == 1) )
{
result = a2;
}
else
{
v8 = 0;
do
{
result = &a2[v7];
v9 = *(double *)result->m128i_i64;
if ( *(double *)result->m128i_i64 <= a4 )
{
if ( a4 > v9 )
v8 = v7;
}
else
{
if ( a4 > v9 )
goto LABEL_13;
a1 = v7;
}
if ( v8 == a1 )
goto LABEL_13;
v7 = (v8 + a1) / 2;
}
while ( v8 + 1 != a1 );
result = &a2[(v8 + a1) / 2];
}
LABEL_13:
*a3 = _mm_loadu_si128(result);
}
return result;
}

original_code:
void findMax(int k, struct arrpair *list, double limit, struct arrpair *res)
{
    int i0 = 0, i1 = k, ix;
    if(limit > list[k-1].sum) {
        *res = list[k-1];
        return;
    }
    while(i0 != i1) {
        ix = (i0 + i1) / 2;
        if(i0 + 1 == i1)
            break;
        if(list[ix].sum > limit)
            i1 = ix;
        if(list[ix].sum < limit)
            i0 = ix;
    }
    *res = list[ix];
    return;
}

canonical_original_code:
void findMax(int k, struct arrpair *list, double limit, struct arrpair *res)
{
    int i0 = 0; int i1 = k; int ix;
    if(limit > list[k-1].sum) {
        *res = list[k-1];
        return;
    }
    while(i0 != i1) {
        ix = (i0 + i1) / 2;
        if(i0 + 1 == i1)
            break;
        if(list[ix].sum > limit)
            i1 = ix;
        if(list[ix].sum < limit)
            i0 = ix;
    }
    *res = list[ix];
    return;
}

variable_types: k int

variable_types:
list
struct arrpair { double sum; int p; } *

variable_types: limit double

variable_types:
res
struct arrpair *

variable_types: ix int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // r15
__int64 v5; // rbx
double v6; // xmm0_8
double v7; // xmm0_8
void *v8; // r13
int *v9; // rbx
int v10; // er11
double v11; // xmm4_8
double v12; // xmm0_8
double v13; // xmm0_8
double v14; // xmm2_8
unsigned __int64 v15; // rbx
unsigned __int64 v16; // rbp
__int64 v17; // rcx
unsigned __int64 i; // rbx
__int64 v19; // rcx
double v21; // [rsp+18h] [rbp-1B0h]
double v22; // [rsp+18h] [rbp-1B0h]
unsigned int v23; // [rsp+28h] [rbp-1A0h] BYREF
int v24; // [rsp+2Ch] [rbp-19Ch] BYREF
double v25; // [rsp+30h] [rbp-198h] BYREF
int v26; // [rsp+38h] [rbp-190h]
double v27[49]; // [rsp+40h] [rbp-188h] BYREF

v5 = 0LL;
v23 = 0;
v24 = 0;
v21 = 0.0;
do
{
v6 = log10((double)p[v5]);
v27[v5] = v6;
v7 = v6 + v21;
++v5;
v21 = v7;
}
while ( v5 != 42 );
v8 = malloc(0x2000000uLL);
v9 = (int *)malloc(0x2000000uLL);
printf("Generating tables...");
sumList((unsigned int)v27, 0, 0, 0, 20, (unsigned int)&v24, (__int64)v9);
sumList((unsigned int)v27, 0, 21, 21, 41, (unsigned int)&v23, (__int64)v8);
printf("Done.\nSorting...");
fflush(_bss_start);
qsort(v9, v24, 0x10uLL, pairCmp);
qsort(v8, (int)v23, 0x10uLL, pairCmp);
printf("Done.\nSearching...");
fflush(_bss_start);
if ( v24 > 0 )
{
v22 = 0.5 * v7;
v10 = 0;
v11 = 0.0;
do
{
v14 = *(double *)v9;
if ( v22 <= *(double *)v9 )
{
v25 = 0.0;
v12 = 0.0;
}
else
{
findMax(v23, v8, &v25, v22 - v14);
v12 = v25;
v14 = *(double *)v9;
}
v13 = v12 + v14;
if ( v13 > v11 && v22 > v13 )
{
v3 = v26;
v4 = v9[2];
v11 = v13;
}
++v10;
v9 += 4;
}
while ( v24 > v10 );
}
v15 = 0LL;
v16 = 1LL;
printf("Done.\nresult:\n\t");
do
{
while ( !_bittest64(&v4, v15) )
{
if ( ++v15 == 21 )
goto LABEL_16;
}
printf("%d * ", (unsigned int)p[v15]);
v17 = p[v15++];
v16 = v16 * v17 % 0x2386F26FC10000LL;
}
while ( v15 != 21 );
LABEL_16:
for ( i = 0LL; i != 21; ++i )
{
while ( !_bittest64(&v3, i) )
{
if ( ++i == 21 )
goto LABEL_20;
}
printf("%d * ", (unsigned int)dword_4040B4[i]);
v19 = dword_4040B4[i];
v16 = v16 * v19 % 0x2386F26FC10000LL;
}
LABEL_20:
printf("== %llu\n", v16);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // r15
__int64 v5; // rbx
double v6; // xmm0_8
double v7; // xmm0_8
void *v8; // r13
int *v9; // rbx
int v10; // er11
double v11; // xmm4_8
double v12; // xmm0_8
double v13; // xmm0_8
double v14; // xmm2_8
unsigned __int64 v15; // rbx
unsigned __int64 v16; // rbp
__int64 v17; // rcx
unsigned __int64 i; // rbx
__int64 v19; // rcx
double v21; // [rsp+18h] [rbp-1B0h]
double v22; // [rsp+18h] [rbp-1B0h]
unsigned int v23; // [rsp+28h] [rbp-1A0h] BYREF
int v24; // [rsp+2Ch] [rbp-19Ch] BYREF
double v25; // [rsp+30h] [rbp-198h] BYREF
int v26; // [rsp+38h] [rbp-190h]
double v27[49]; // [rsp+40h] [rbp-188h] BYREF

v5 = 0LL;
v23 = 0;
v24 = 0;
v21 = 0.0;
do
{
v6 = log10((double)p[v5]);
v27[v5] = v6;
v7 = v6 + v21;
++v5;
v21 = v7;
}
while ( v5 != 42 );
v8 = malloc(0x2000000uLL);
v9 = (int *)malloc(0x2000000uLL);
printf("Generating tables...");
func8((unsigned int)v27, 0, 0, 0, 20, (unsigned int)&v24, (__int64)v9);
func8((unsigned int)v27, 0, 21, 21, 41, (unsigned int)&v23, (__int64)v8);
printf("Done.\nSorting...");
fflush(_bss_start);
qsort(v9, v24, 0x10uLL, pairCmp);
qsort(v8, (int)v23, 0x10uLL, pairCmp);
printf("Done.\nSearching...");
fflush(_bss_start);
if ( v24 > 0 )
{
v22 = 0.5 * v7;
v10 = 0;
v11 = 0.0;
do
{
v14 = *(double *)v9;
if ( v22 <= *(double *)v9 )
{
v25 = 0.0;
v12 = 0.0;
}
else
{
func9(v23, v8, &v25, v22 - v14);
v12 = v25;
v14 = *(double *)v9;
}
v13 = v12 + v14;
if ( v13 > v11 && v22 > v13 )
{
v3 = v26;
v4 = v9[2];
v11 = v13;
}
++v10;
v9 += 4;
}
while ( v24 > v10 );
}
v15 = 0LL;
v16 = 1LL;
printf("Done.\nresult:\n\t");
do
{
while ( !_bittest64(&v4, v15) )
{
if ( ++v15 == 21 )
goto LABEL_16;
}
printf("%d * ", (unsigned int)p[v15]);
v17 = p[v15++];
v16 = v16 * v17 % 0x2386F26FC10000LL;
}
while ( v15 != 21 );
LABEL_16:
for ( i = 0LL; i != 21; ++i )
{
while ( !_bittest64(&v3, i) )
{
if ( ++i == 21 )
goto LABEL_20;
}
printf("%d * ", (unsigned int)dword_4040B4[i]);
v19 = dword_4040B4[i];
v16 = v16 * v19 % 0x2386F26FC10000LL;
}
LABEL_20:
printf("== %llu\n", v16);
return 0;
}

original_code:
int main(void)
{
    double logp[42];
    struct arrpair *listlow, *listhi, maxPair;
    double maxsum = 0, sopt;
    int klo = 0, khi = 0;
    int i, phi, plo;
    unsigned long int ans = 1;
    for(i = 0; i < 42; i++) {
        logp[i] = log10(p[i]);
        maxsum += logp[i];
    }
    maxsum /= 2;
    listlow = (struct arrpair *) malloc(sizeof(struct arrpair) * (1l << 21));
    listhi = (struct arrpair *) malloc(sizeof(struct arrpair) * (1l << 21));
    printf("Generating tables...");
    sumList(logp, 0, 0.0, 0, 0, 42/2-1, &khi, listhi);
    sumList(logp, 0, 0.0, 42/2, 42/2, 42 -1, &klo, listlow);
    printf("Done.\nSorting...");
    fflush(stdout);
    qsort(listhi, khi, sizeof(struct arrpair), pairCmp);
    qsort(listlow, klo, sizeof(struct arrpair), pairCmp);
    printf("Done.\nSearching...");
    fflush(stdout);
    sopt = 0.0;
    for(i = 0; i < khi; i++) {
        if(maxsum > listhi[i].sum)
            findMax(klo, listlow, maxsum - listhi[i].sum, &maxPair);
        else
            maxPair.sum = 0;
        if(maxPair.sum + listhi[i].sum > sopt &&
                maxPair.sum + listhi[i].sum < maxsum) {
            sopt = maxPair.sum + listhi[i].sum;
            plo = maxPair.p;
            phi = listhi[i].p;
        }
    }
    printf("Done.\nresult:\n\t");
    for(i = 0; i < 21; i++)
        if(phi & (1l << i)) {
            printf("%d * ", p[i]);
            ans *= p[i];
            ans %= 10000000000000000;
        }
    for(i = 0; i < 21; i++)
        if(plo & (1l << i)) {
            printf("%d * ", p[i+21]);
            ans *= p[i+21];
            ans %= 10000000000000000;
        }
    printf("== %llu\n", ans);
    return 0;
}

canonical_original_code:
int main()
{
    double logp[42];
    struct arrpair *listlow; struct arrpair *listhi; struct arrpair maxPair;
    double maxsum = 0; double sopt;
    int klo = 0; int khi = 0;
    int i; int phi; int plo;
    unsigned long ans = 1;
    for(i = 0; i < 42; i++) {
        logp[i] = log10(p[i]);
        maxsum += logp[i];
    }
    maxsum /= 2;
    listlow = (struct arrpair *) malloc(sizeof(struct arrpair) * (1l << 21));
    listhi = (struct arrpair *) malloc(sizeof(struct arrpair) * (1l << 21));
    printf("Generating tables...");
    sumList(logp, 0, 0.0, 0, 0, 42/2-1, &khi, listhi);
    sumList(logp, 0, 0.0, 42/2, 42/2, 42 -1, &klo, listlow);
    printf("Done.\nSorting...");
    fflush(stdout);
    qsort(listhi, khi, sizeof(struct arrpair), pairCmp);
    qsort(listlow, klo, sizeof(struct arrpair), pairCmp);
    printf("Done.\nSearching...");
    fflush(stdout);
    sopt = 0.0;
    for(i = 0; i < khi; i++) {
        if(maxsum > listhi[i].sum)
            findMax(klo, listlow, maxsum - listhi[i].sum, &maxPair);
        else
            maxPair.sum = 0;
        if(maxPair.sum + listhi[i].sum > sopt &&
                maxPair.sum + listhi[i].sum < maxsum) {
            sopt = maxPair.sum + listhi[i].sum;
            plo = maxPair.p;
            phi = listhi[i].p;
        }
    }
    printf("Done.\nresult:\n\t");
    for(i = 0; i < 21; i++)
        if(phi & (1l << i)) {
            printf("%d * ", p[i]);
            ans *= p[i];
            ans %= 10000000000000000;
        }
    for(i = 0; i < 21; i++)
        if(plo & (1l << i)) {
            printf("%d * ", p[i+21]);
            ans *= p[i+21];
            ans %= 10000000000000000;
        }
    printf("== %llu\n", ans);
    return 0;
}

variable_types:
logp
double [42]

variable_types:
listlow
struct arrpair { double sum; int p; } *

variable_types:
listhi
struct arrpair { double sum; int p; } *

variable_types:
maxPair
struct arrpair { double sum; int p; }

variable_types: maxsum double

variable_types: sopt double

variable_types: klo int

variable_types: khi int

variable_types: i int

variable_types: phi int

variable_types: plo int

variable_types:
ans
unsigned long


decompiled_code:
__int64 __fastcall count_pieces(__int64 a1)
{
__int64 v1; // rdx
unsigned int i; // er8
char v3; // al
unsigned __int64 v4; // rdx
char v5; // al
unsigned __int64 v6; // rdx

v1 = a1;
for ( i = 0; v1; v1 = v6 >> v5 )
{
v3 = trailz(v1);
v5 = trailz(~(v4 >> v3));
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // rdx
unsigned int i; // er8
char v3; // al
unsigned __int64 v4; // rdx
char v5; // al
unsigned __int64 v6; // rdx

v1 = a1;
for ( i = 0; v1; v1 = v6 >> v5 )
{
v3 = func8(v1);
v5 = func8(~(v4 >> v3));
}
return i;
}

original_code:
static inline int count_pieces(uint64_t config) {
    int result = 0;
    while(config) {
        result++;
        config >>= _trailz(config);
        config >>= _trailz(~config);
    }
    return result;
}

canonical_original_code:
static inline int count_pieces(unsigned long config) {
    int result = 0;
    while(config) {
        result++;
        config >>= _trailz(config);
        config >>= _trailz(~config);
    }
    return result;
}

variable_types:
config
unsigned long

variable_types: result int


decompiled_code:
int *__fastcall random_shuffle(__int64 a1)
{
__int64 i; // rbx
int *result; // rax
int v3; // edx

for ( i = 0LL; i != 39; ++i )
{
result = (int *)(a1 + 4LL * ((int)i + rand() % (40 - (int)i)));
v3 = *result;
*result = *(_DWORD *)(a1 + 4 * i);
*(_DWORD *)(a1 + 4 * i) = v3;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func10(__int64 a1)
{
__int64 i; // rbx
int *result; // rax
int v3; // edx

for ( i = 0LL; i != 39; ++i )
{
result = (int *)(a1 + 4LL * ((int)i + rand() % (40 - (int)i)));
v3 = *result;
*result = *(_DWORD *)(a1 + 4 * i);
*(_DWORD *)(a1 + 4 * i) = v3;
}
return result;
}

original_code:
void random_shuffle(int items[]) {
    int i;
    for(i = 0; i < 40 -1; i++) {
        int ind = i + (rand() % (40 -i));
        int tmp = items[ind];
        items[ind] = items[i];
        items[i] = tmp;
    }
}

variable_types:
items
int []

variable_types: ind int

variable_types: tmp int


execute

decompiled_code:
__int64 execute()
{
__int64 i; // rax
char *v1; // rsi
__int64 v2; // r10
__int64 v3; // r11
int v4; // eax
unsigned int v5; // er9
int v7[40]; // [rsp+0h] [rbp-A8h] BYREF
char v8; // [rsp+A0h] [rbp-8h] BYREF

for ( i = 0LL; i != 40; ++i )
v7[i] = i;
random_shuffle((__int64)v7);
v1 = (char *)v7;
v2 = 0LL;
v3 = 1LL;
do
{
v4 = count_pieces((v3 << *(_DWORD *)v1) | v2);
if ( (int)v5 < v4 )
v5 = v4;
v1 += 4;
}
while ( v1 != &v8 );
return v5;
}

original_code:
int execute() {
    int i;
    int pieces[40];
    for(i = 0; i < 40; i++)
        pieces[i] = i;
    random_shuffle(pieces);
    uint64_t state = 0;
    int max_count = 0;
    for(i = 0; i < 40; i++) {
        state |= 1ul << pieces[i];
        int count = count_pieces(state);
        if(count > max_count) {
            max_count = count;
        }
    }
    return max_count;
}

canonical_original_code:
int execute() {
    int i;
    int pieces[40];
    for(i = 0; i < 40; i++)
        pieces[i] = i;
    random_shuffle(pieces);
    unsigned long state = 0;
    int max_count = 0;
    for(i = 0; i < 40; i++) {
        state |= 1ul << pieces[i];
        int count = count_pieces(state);
        if(count > max_count) {
            max_count = count;
        }
    }
    return max_count;
}

variable_types:
pieces
int [40]

variable_types:
state
unsigned long

variable_types: count int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
const char *v4; // rdi
__int64 i; // rbx

v3 = 1LL;
v4 = (const char *)time(0LL);
srand((unsigned int)v4);
for ( i = (int)execute(v4, argv); ; printf("after %ld iterations: %.6f\n", v3, (double)(int)i / (double)(int)v3) )
{
do
{
++v3;
i += (int)execute(v4, argv);
}
while ( __ROR8__(0x790FB65668C26139LL * v3, 6) > 0x10C6F7A0B5EDuLL );
argv = (const char **)v3;
v4 = "after %ld iterations: %.6f\n";
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
const char *v4; // rdi
__int64 i; // rbx

v3 = 1LL;
v4 = (const char *)time(0LL);
srand((unsigned int)v4);
for ( i = (int)func11(v4, argv); ; printf("after %ld iterations: %.6f\n", v3, (double)(int)i / (double)(int)v3) )
{
do
{
++v3;
i += (int)func11(v4, argv);
}
while ( __ROR8__(0x790FB65668C26139LL * v3, 6) > 0x10C6F7A0B5EDuLL );
argv = (const char **)v3;
v4 = "after %ld iterations: %.6f\n";
}
}

original_code:
int main(void) {
    long sum = 0l;
    long num_trials = 0l;
    srand(time(((void *)0)));
    while(1) {
        sum += execute();
        num_trials += 1;
        if(!(num_trials % 1000000)) {
            printf("after %ld iterations: %.6f\n", num_trials, ((double) sum) / num_trials);
        }
    }
    return 0;
}

canonical_original_code:
int main() {
    long sum = 0l;
    long num_trials = 0l;
    srand(time(((void *)0)));
    while(1) {
        sum += execute();
        num_trials += 1;
        if(!(num_trials % 1000000)) {
            printf("after %ld iterations: %.6f\n", num_trials, ((double) sum) / num_trials);
        }
    }
    return 0;
}

variable_types: sum long


mkprimes

original_code:
void mkprimes(int max_n, uint64_t **primes, int *np)
{
    _Bool *iscomp = calloc(1 + max_n, sizeof(_Bool));
    *primes = malloc((1 + max_n)*sizeof(uint64_t));
    int i;
    *np = 0;
    for(i = 2; i <= max_n; i++) {
        if(!iscomp[i]) {
            (*primes)[*np] = i;
            (*np)++;
            int j = 2*i;
            while(j <= max_n) {
                iscomp[j] = 1;
                j += i;
            }
        }
    }
    *primes = realloc(*primes, (*np)*sizeof(uint64_t));
}

canonical_original_code:
void mkprimes(int max_n, unsigned long **primes, int *np)
{
    _Bool *iscomp = calloc(1 + max_n, sizeof(_Bool));
    *primes = malloc((1 + max_n)*sizeof(unsigned long));
    int i;
    *np = 0;
    for(i = 2; i <= max_n; i++) {
        if(!iscomp[i]) {
            (*primes)[*np] = i;
            (*np)++;
            int j = 2*i;
            while(j <= max_n) {
                iscomp[j] = 1;
                j += i;
            }
        }
    }
    *primes = realloc(*primes, (*np)*sizeof(unsigned long));
}

variable_types:
primes
unsigned long **

variable_types:
np
int *

variable_types:
iscomp
_Bool *

variable_types: j int


setem

original_code:
void setem(uint64_t cur, uint64_t min, uint64_t *items, uint64_t factors[], int powers[], int nfact, uint64_t cumprod) {
    if(cur > (61ul*61ul*61ul))
        return;
    if(!nfact) {
        items[cur] = min;
        return;
    }
    uint64_t fact = factors[nfact-1];
    int i;
    uint64_t new_cur = cur;
    uint64_t rem_prod = cumprod;
    for(i = 0; i < powers[nfact-1]; i++)
        rem_prod /= fact;
    uint64_t min_cur = (1+min) / rem_prod;
    for(i = 0; i <= powers[nfact-1]; i++) {
        if(new_cur > (61ul*61ul*61ul))
            break;
        if(new_cur > min_cur)
            setem(new_cur, min, items, factors, powers, nfact-1, rem_prod);
        new_cur *= fact;
    }
    return;
}

canonical_original_code:
void setem(unsigned long cur, unsigned long min, unsigned long *items, unsigned long factors[], int powers[], int nfact, unsigned long cumprod) {
    if(cur > (61ul*61ul*61ul))
        return;
    if(!nfact) {
        items[cur] = min;
        return;
    }
    unsigned long fact = factors[nfact-1];
    int i;
    unsigned long new_cur = cur;
    unsigned long rem_prod = cumprod;
    for(i = 0; i < powers[nfact-1]; i++)
        rem_prod /= fact;
    unsigned long min_cur = (1+min) / rem_prod;
    for(i = 0; i <= powers[nfact-1]; i++) {
        if(new_cur > (61ul*61ul*61ul))
            break;
        if(new_cur > min_cur)
            setem(new_cur, min, items, factors, powers, nfact-1, rem_prod);
        new_cur *= fact;
    }
    return;
}

variable_types:
cur
unsigned long

variable_types:
min
unsigned long

variable_types:
items
unsigned long *

variable_types:
factors
unsigned long []

variable_types:
powers
int []

variable_types: nfact int

variable_types:
cumprod
unsigned long

variable_types:
fact
unsigned long

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
_QWORD *v4; // r12
int v5; // esi
__int64 v6; // r13
__int64 i; // rbx
__int64 v8; // rbp
__int64 v9; // rsi
__int64 v11; // [rsp-10h] [rbp-138h]
unsigned int v12; // [rsp+0h] [rbp-128h] BYREF
int v13; // [rsp+4h] [rbp-124h] BYREF
__int64 v14; // [rsp+8h] [rbp-120h] BYREF
char v15[80]; // [rsp+10h] [rbp-118h] BYREF
char v16[200]; // [rsp+60h] [rbp-C8h] BYREF

v3 = 3LL;
mkprimes(226981LL, &v14, &v12);
v4 = calloc(0x1312D01uLL, 8uLL);
while ( 1 )
{
factorize(v3 * v3 - 1, v16, v15, &v13, v14, v12);
fflush(_bss_start);
v5 = v3;
v11 = v3 * v3 - 1;
++v3;
setem(1, v5, (_DWORD)v4, (unsigned int)v16, (unsigned int)v15, v13, v11);
if ( v3 == 226982 )
break;
if ( __ROR8__(0x5D4E8FB00BCBE61DLL * v3, 5) <= 0xA7C5AC471B47uLL )
printf("z == %ld\n", v3);
}
v6 = 0LL;
for ( i = 3LL; i != 226982; ++i )
{
v8 = 1LL;
if ( v4[i] )
v8 = v4[i];
v9 = i;
v6 += v8;
printf("I(%ld) == %ld\n", v9, v8);
}
printf("SUM: %ld\n", v6);
free(v4);
return 0;
}

original_code:
int main(void) {
    uint64_t *primes;
    int nprimes;
    mkprimes((61ul*61ul*61ul), &primes, &nprimes);
    uint64_t *zz = calloc(20000001, sizeof(uint64_t));
    uint64_t z;
    uint64_t factors[20];
    int powers[20];
    int nfact;
    for(z = 3; z <= (61ul*61ul*61ul); z++) {
        if(!(z % 100000)) {
            printf("z == %ld\n", z);
        }
        uint64_t z2 = z*z-1ul;
        factorize(z2, factors, powers, &nfact, primes, nprimes);
        fflush(stdout);
        setem(1ul, z, zz, factors, powers, nfact, z2);
    }
    uint64_t sum = 0ul;
    for(z = 3; z <= (61ul*61ul*61ul); z++) {
        uint64_t I = zz[z] ? zz[z] : 1ul;
        printf("I(%ld) == %ld\n", z, I);
        sum += I;
    }
    printf("SUM: %ld\n", sum);
    free(zz);
    return 0;
}

canonical_original_code:
int main() {
    unsigned long *primes;
    int nprimes;
    mkprimes((61ul*61ul*61ul), &primes, &nprimes);
    unsigned long *zz = calloc(20000001, sizeof(uint64_t));
    unsigned long z;
    unsigned long factors[20];
    int powers[20];
    int nfact;
    for(z = 3; z <= (61ul*61ul*61ul); z++) {
        if(!(z % 100000)) {
            printf("z == %ld\n", z);
        }
        unsigned long z2 = z*z-1ul;
        factorize(z2, factors, powers, &nfact, primes, nprimes);
        fflush(stdout);
        setem(1ul, z, zz, factors, powers, nfact, z2);
    }
    unsigned long sum = 0ul;
    for(z = 3; z <= (61ul*61ul*61ul); z++) {
        unsigned long I = zz[z] ? zz[z] : 1ul;
        printf("I(%ld) == %ld\n", z, I);
        sum += I;
    }
    printf("SUM: %ld\n", sum);
    free(zz);
    return 0;
}

variable_types:
primes
unsigned long *

variable_types: nprimes int

variable_types:
zz
unsigned long *

variable_types:
z
unsigned long

variable_types:
factors
unsigned long [20]

variable_types:
powers
int [20]

variable_types:
sum
unsigned long

variable_types:
I
unsigned long


encode

decompiled_code:
__int64 __fastcall encode(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = a1 + 40;
LODWORD(result) = 0;
do
{
a1 += 4LL;
result = (unsigned int)(*(_DWORD *)(a1 - 4) + 3 * result);
}
while ( a1 != v1 );
return result;
}

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

v1 = a1 + 40;
LODWORD(result) = 0;
do
{
a1 += 4LL;
result = (unsigned int)(*(_DWORD *)(a1 - 4) + 3 * result);
}
while ( a1 != v1 );
return result;
}

original_code:
int encode(int dcounts[])
{
    int i;
    int ret = 0;
    for(i = 0; i < 10; i++) {
        ret *= 3;
        ret += dcounts[i];
    }
    return ret;
}

variable_types:
dcounts
int []

variable_types: ret int


decode

decompiled_code:
__int64 __fastcall decode(signed int a1, __int64 a2)
{
__int64 v2; // rsi
__int64 result; // rax

*(_QWORD *)(a2 + 32) = 0LL;
*(_OWORD *)a2 = 0LL;
*(_OWORD *)(a2 + 16) = 0LL;
if ( a1 )
{
v2 = a2 + 36;
do
{
v2 -= 4LL;
*(_DWORD *)(v2 + 4) = a1 % 3;
a1 /= 3;
result = (unsigned int)a1;
}
while ( a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(signed int a1, __int64 a2)
{
__int64 v2; // rsi
__int64 result; // rax

*(_QWORD *)(a2 + 32) = 0LL;
*(_OWORD *)a2 = 0LL;
*(_OWORD *)(a2 + 16) = 0LL;
if ( a1 )
{
v2 = a2 + 36;
do
{
v2 -= 4LL;
*(_DWORD *)(v2 + 4) = a1 % 3;
a1 /= 3;
result = (unsigned int)a1;
}
while ( a1 );
}
return result;
}

original_code:
void decode(int encoding, int dcounts[])
{
    memset(dcounts, 0, 10*sizeof(int));
    int i = 9;
    while(encoding) {
        dcounts[i] = encoding % 3;
        encoding /= 3;
        i--;
    }
}

variable_types: encoding int


complement

original_code:
int complement(int encoding)
{
    int dcounts[10];
    decode(encoding, dcounts);
    int ccounts[10];
    memset(ccounts, 0, sizeof(ccounts));
    int i;
    for(i = 0; i < 10; i++)
        ccounts[i] = 2 - dcounts[i];
    return encode(ccounts);
}

variable_types:
dcounts
int [10]

variable_types:
ccounts
int [10]


isvalid

decompiled_code:
_BOOL8 __fastcall isvalid(signed int a1)
{
int v1; // ecx
char *v2; // rax
int v3; // edx
_BYTE v5[40]; // [rsp+0h] [rbp-38h] BYREF
char v6; // [rsp+28h] [rbp-10h] BYREF

decode(a1, (__int64)v5);
v2 = v5;
while ( 1 )
{
v3 = *(_DWORD *)v2;
if ( *(int *)v2 > 2 )
break;
v2 += 4;
v1 += v3;
if ( v2 == &v6 )
return v1 == 10;
}
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(signed int a1)
{
int v1; // ecx
char *v2; // rax
int v3; // edx
_BYTE v5[40]; // [rsp+0h] [rbp-38h] BYREF
char v6; // [rsp+28h] [rbp-10h] BYREF

func8(a1, (__int64)v5);
v2 = v5;
while ( 1 )
{
v3 = *(_DWORD *)v2;
if ( *(int *)v2 > 2 )
break;
v2 += 4;
v1 += v3;
if ( v2 == &v6 )
return v1 == 10;
}
return 0LL;
}

original_code:
int isvalid(int encoding)
{
    int ndig[10];
    decode(encoding, ndig);
    int i;
    int sum = 0;
    for(i = 0; i < 10; i++) {
        if(ndig[i] > 2)
            return 0;
        sum += ndig[i];
    }
    return sum == 10;
}

variable_types:
ndig
int [10]

variable_types: sum int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // rax
__int64 v7; // rbx
char *v8; // r15
unsigned int v9; // eax
__int64 v10; // r12
__int64 v11; // rdx
char *v12; // r15
__int64 v13; // rdx
__int64 v14; // rax
unsigned __int64 v16; // [rsp+8h] [rbp-F0h]
__int64 v17; // [rsp+20h] [rbp-D8h]
__int64 v18; // [rsp+28h] [rbp-D0h]
__int128 v19[2]; // [rsp+30h] [rbp-C8h] BYREF
__int64 v20; // [rsp+50h] [rbp-A8h]
char v21[40]; // [rsp+60h] [rbp-98h] BYREF
char v22; // [rsp+88h] [rbp-70h] BYREF
char v23[40]; // [rsp+90h] [rbp-68h] BYREF
char v24; // [rsp+B8h] [rbp-40h] BYREF

v3 = 0LL;
encoding_counts_mod_11 = (__int64)malloc(0x58uLL);
v4 = encoding_counts_mod_11;
em11_lz = (__int64)malloc(0x58uLL);
v5 = em11_lz;
do
{
*(_QWORD *)(v4 + v3) = calloc(0xE5B7uLL, 8uLL);
*(_QWORD *)(v5 + v3) = calloc(0xE5B7uLL, 8uLL);
v3 += 8LL;
}
while ( v3 != 88 );
v19[0] = 0LL;
v19[1] = 0LL;
v20 = 0LL;
v6 = count(0LL, 0LL, v19);
printf("count: %ld\n", v6);
v18 = 0LL;
v17 = 0LL;
do
{
v7 = 0LL;
v16 = (11 - v18) % 0xBuLL;
do
{
while ( !(unsigned int)isvalid((unsigned int)v7) )
{
if ( ++v7 == 58807 )
goto LABEL_12;
}
v8 = v21;
decode((unsigned int)v7, v21);
v9 = complement((unsigned int)v7);
v10 = (int)v9;
decode(v9, v23);
do
{
v11 = *(unsigned int *)v8;
v8 += 4;
fprintf(stderr, "%d ", v11);
}
while ( v8 != &v22 );
v12 = v23;
fwrite("| ", 1uLL, 2uLL, stderr);
do
{
v13 = *(unsigned int *)v12;
v12 += 4;
fprintf(stderr, "%d ", v13);
}
while ( &v24 != v12 );
fputc(10, stderr);
fprintf(stderr, "(%d, %d) * (%ld, %d)\n", (unsigned int)v18, (unsigned int)v7, v16, (unsigned int)v10);
fprintf(
stderr,
"%ld lhs, %ld rhs\n",
*(_QWORD *)(*(_QWORD *)(encoding_counts_mod_11 + 8 * v18) + 8 * v7),
*(_QWORD *)(*(_QWORD *)(encoding_counts_mod_11 + 8 * v16) + 8 * v10));
v14 = *(_QWORD *)(*(_QWORD *)(encoding_counts_mod_11 + 8 * v18) + 8 * v7++)
* (*(_QWORD *)(*(_QWORD *)(em11_lz + 8 * v16) + 8 * v10)
+ *(_QWORD *)(*(_QWORD *)(encoding_counts_mod_11 + 8 * v16) + 8 * v10));
v17 += v14;
}
while ( v7 != 58807 );
LABEL_12:
++v18;
}
while ( v18 != 11 );
printf("result? %ld\n", v17);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // rax
__int64 v7; // rbx
char *v8; // r15
unsigned int v9; // eax
__int64 v10; // r12
__int64 v11; // rdx
char *v12; // r15
__int64 v13; // rdx
__int64 v14; // rax
unsigned __int64 v16; // [rsp+8h] [rbp-F0h]
__int64 v17; // [rsp+20h] [rbp-D8h]
__int64 v18; // [rsp+28h] [rbp-D0h]
__int128 v19[2]; // [rsp+30h] [rbp-C8h] BYREF
__int64 v20; // [rsp+50h] [rbp-A8h]
char v21[40]; // [rsp+60h] [rbp-98h] BYREF
char v22; // [rsp+88h] [rbp-70h] BYREF
char v23[40]; // [rsp+90h] [rbp-68h] BYREF
char v24; // [rsp+B8h] [rbp-40h] BYREF

v3 = 0LL;
encoding_counts_mod_11 = (__int64)malloc(0x58uLL);
v4 = encoding_counts_mod_11;
em11_lz = (__int64)malloc(0x58uLL);
v5 = em11_lz;
do
{
*(_QWORD *)(v4 + v3) = calloc(0xE5B7uLL, 8uLL);
*(_QWORD *)(v5 + v3) = calloc(0xE5B7uLL, 8uLL);
v3 += 8LL;
}
while ( v3 != 88 );
v19[0] = 0LL;
v19[1] = 0LL;
v20 = 0LL;
v6 = func10(0LL, 0LL, v19);
printf("count: %ld\n", v6);
v18 = 0LL;
v17 = 0LL;
do
{
v7 = 0LL;
v16 = (11 - v18) % 0xBuLL;
do
{
while ( !(unsigned int)func11((unsigned int)v7) )
{
if ( ++v7 == 58807 )
goto LABEL_12;
}
v8 = v21;
func8((unsigned int)v7, v21);
v9 = func9((unsigned int)v7);
v10 = (int)v9;
func8(v9, v23);
do
{
v11 = *(unsigned int *)v8;
v8 += 4;
fprintf(stderr, "%d ", v11);
}
while ( v8 != &v22 );
v12 = v23;
fwrite("| ", 1uLL, 2uLL, stderr);
do
{
v13 = *(unsigned int *)v12;
v12 += 4;
fprintf(stderr, "%d ", v13);
}
while ( &v24 != v12 );
fputc(10, stderr);
fprintf(stderr, "(%d, %d) * (%ld, %d)\n", (unsigned int)v18, (unsigned int)v7, v16, (unsigned int)v10);
fprintf(
stderr,
"%ld lhs, %ld rhs\n",
*(_QWORD *)(*(_QWORD *)(encoding_counts_mod_11 + 8 * v18) + 8 * v7),
*(_QWORD *)(*(_QWORD *)(encoding_counts_mod_11 + 8 * v16) + 8 * v10));
v14 = *(_QWORD *)(*(_QWORD *)(encoding_counts_mod_11 + 8 * v18) + 8 * v7++)
* (*(_QWORD *)(*(_QWORD *)(em11_lz + 8 * v16) + 8 * v10)
+ *(_QWORD *)(*(_QWORD *)(encoding_counts_mod_11 + 8 * v16) + 8 * v10));
v17 += v14;
}
while ( v7 != 58807 );
LABEL_12:
++v18;
}
while ( v18 != 11 );
printf("result? %ld\n", v17);
return 0;
}

original_code:
int main()
{
    encoding_counts_mod_11 = malloc(11*sizeof(long *));
    em11_lz = malloc(11*sizeof(long *));
    int i;
    for(i = 0; i < 11; i++) {
        encoding_counts_mod_11[i] = calloc(1 + 58806, sizeof(long));
        em11_lz[i] = calloc(1 + 58806, sizeof(long));
    }
    int dcounts[10];
    memset(dcounts, 0, sizeof(dcounts));
    long c = count(0, 0, dcounts);
    printf("count: %ld\n", c);
    long z = 10000000000l % 11;
    long result = 0;
    for(i = 0; i < 11; i++) {
        long lhs_mod_11 = (i * z) % 11;
        long mod_complement = (11 - lhs_mod_11) % 11;
        int j;
        for(j = 0; j <= 58806; j++) {
            if(!isvalid(j))
                continue;
            int jj[10], kk[10];
            decode(j, jj);
            int comp = complement(j);
            decode(comp, kk);
            int k;
            for(k = 0; k < 10; k++) {
                fprintf(stderr, "%d ", jj[k]);
            }
            fprintf(stderr, "| ");
            for(k = 0; k < 10; k++) {
                fprintf(stderr, "%d ", kk[k]);
            }
            fprintf(stderr, "\n");
            fprintf(stderr, "(%d, %d) * (%ld, %d)\n", i, j, mod_complement, comp);
            fprintf(stderr, "%ld lhs, %ld rhs\n", encoding_counts_mod_11[i][j], encoding_counts_mod_11[mod_complement][comp]);
            result += encoding_counts_mod_11[i][j] *
                (encoding_counts_mod_11[mod_complement][comp] + em11_lz[mod_complement][comp]);
        }
    }
    printf("result? %ld\n", result);
    return 0;
}

canonical_original_code:
int main()
{
    encoding_counts_mod_11 = malloc(11*sizeof(long *));
    em11_lz = malloc(11*sizeof(long *));
    int i;
    for(i = 0; i < 11; i++) {
        encoding_counts_mod_11[i] = calloc(1 + 58806, sizeof(long));
        em11_lz[i] = calloc(1 + 58806, sizeof(long));
    }
    int dcounts[10];
    memset(dcounts, 0, sizeof(dcounts));
    long c = count(0, 0, dcounts);
    printf("count: %ld\n", c);
    long z = 10000000000l % 11;
    long result = 0;
    for(i = 0; i < 11; i++) {
        long lhs_mod_11 = (i * z) % 11;
        long mod_complement = (11 - lhs_mod_11) % 11;
        int j;
        for(j = 0; j <= 58806; j++) {
            if(!isvalid(j))
                continue;
            int jj[10]; int kk[10];
            decode(j, jj);
            int comp = complement(j);
            decode(comp, kk);
            int k;
            for(k = 0; k < 10; k++) {
                fprintf(stderr, "%d ", jj[k]);
            }
            fprintf(stderr, "| ");
            for(k = 0; k < 10; k++) {
                fprintf(stderr, "%d ", kk[k]);
            }
            fprintf(stderr, "\n");
            fprintf(stderr, "(%d, %d) * (%ld, %d)\n", i, j, mod_complement, comp);
            fprintf(stderr, "%ld lhs, %ld rhs\n", encoding_counts_mod_11[i][j], encoding_counts_mod_11[mod_complement][comp]);
            result += encoding_counts_mod_11[i][j] *
                (encoding_counts_mod_11[mod_complement][comp] + em11_lz[mod_complement][comp]);
        }
    }
    printf("result? %ld\n", result);
    return 0;
}

variable_types: c long

variable_types: z long

variable_types: result long

variable_types: j int

variable_types:
jj
int [10]

variable_types:
kk
int [10]

variable_types: comp int

variable_types: k int


count

original_code:
long count(long num, int depth, int dcounts[]) {
    if(depth == 10) {
        long lead = num / 1000000000l;
        int e = encode(dcounts);
        long mod11 = num % 11;
        if(lead)
            encoding_counts_mod_11[mod11][e]++;
        else
            em11_lz[mod11][e]++;
        return 1;
    }
    long ret = 0;
    int dig;
    for(dig = 0; dig < 10; dig++) {
        if(dcounts[dig] == 2)
            continue;
        dcounts[dig]++;
        ret += count(num * 10 + dig, 1 + depth, dcounts);
        dcounts[dig]--;
    }
    return ret;
}

variable_types: num long

variable_types: depth int

variable_types: lead long

variable_types: e int

variable_types: ret long

variable_types: dig int


main

original_code:
int main(int argc, char *argv[])
{
    if(argc < 2) {
        printf("SYNTAX: %s ndig [ndig == 40 solves problem]\n", argv[0]);
        exit(0);
    }
    int max_length = atoi(argv[1]);
    long *hit_0 = calloc(10, sizeof(long));
    long *hit_9 = calloc(10, sizeof(long));
    long *hit_nil = calloc(10, sizeof(long));
    long *pandigital = calloc(10, sizeof(long));
    initialize(hit_0, hit_9, hit_nil, pandigital);
    int current_length;
    long result = 0;
    for(current_length = 1; current_length < max_length; current_length++) {
        int j;
        long *new_hit_0 = calloc(10, sizeof(long));
        long *new_hit_9 = calloc(10, sizeof(long));
        long *new_hit_nil = calloc(10, sizeof(long));
        long *new_pandigital = calloc(10, sizeof(long));
        new_hit_0[0] += hit_nil[1];
        new_hit_nil[2] += hit_nil[1];
        for(j = 2; j < 8; j++) {
           new_hit_nil[j-1] += hit_nil[j];
           new_hit_nil[j+1] += hit_nil[j];
        }
        new_hit_9[9] += hit_nil[8];
        new_hit_nil[7] += hit_nil[8];
        new_hit_0[1] += hit_0[0];
        for(j = 1; j < 8; j++) {
            new_hit_0[j-1] += hit_0[j];
            new_hit_0[j+1] += hit_0[j];
        }
        new_pandigital[9] += hit_0[8];
        new_hit_0[7] += hit_0[8];
        new_pandigital[0] += hit_9[1];
        new_hit_9[2] += hit_9[1];
        for(j = 2; j < 9; j++) {
            new_hit_9[j-1] += hit_9[j];
            new_hit_9[j+1] += hit_9[j];
        }
        new_hit_9[8] += hit_9[9];
        new_pandigital[1] += pandigital[0];
        for(j = 1; j < 9; j++) {
            new_pandigital[j-1] += pandigital[j];
            new_pandigital[j+1] += pandigital[j];
        }
        new_pandigital[8] += pandigital[9];
        for(j = 0; j < 10; j++) {
            result += new_pandigital[j];
        }
        free(hit_0);
        free(hit_9);
        free(hit_nil);
        free(pandigital);
        hit_0 = new_hit_0;
        hit_9 = new_hit_9;
        hit_nil = new_hit_nil;
        pandigital = new_pandigital;
    }
    printf("result: %ld\n", result);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
pandigital
long *


decompiled_code:
__int64 __fastcall is_present(int a1, __int64 a2, _DWORD *a3)
{
__int64 v3; // rax
unsigned int v4; // er8

v3 = 0LL;
while ( *(_DWORD *)(a2 + 4 * v3) != a1 )
{
if ( ++v3 == 5 )
return 0;
}
v4 = 1;
if ( !a3 )
return v4;
*a3 = v3;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, __int64 a2, _DWORD *a3)
{
__int64 v3; // rax
unsigned int v4; // er8

v3 = 0LL;
while ( *(_DWORD *)(a2 + 4 * v3) != a1 )
{
if ( ++v3 == 5 )
return 0;
}
v4 = 1;
if ( !a3 )
return v4;
*a3 = v3;
return 1LL;
}

original_code:
_Bool is_present(int draw, int mem[], int *pos) {
    int i;
    for(i = 0; i < 5; i++)
        if(mem[i] == draw) {
            if(pos)
                *pos = i;
            return 1;
        }
    return 0;
}

variable_types: draw int

variable_types:
mem
int []

variable_types:
pos
int *

variable_types: i int


original_code:
_Bool update_robin(int draw, int mem_0[], int mem_1[])
{
    _Bool hit = is_present(draw, mem_0, ((void *)0));
    if(hit) {
        memcpy(mem_1, mem_0, 5*sizeof(int));
        return 1;
    } else {
        memcpy(mem_1, mem_0, 4*sizeof(int));
        mem_1[4] = draw;
        return 0;
    }
}


original_code:
_Bool update_larry(int draw, int mem_0[], int mem_1[])
{
    int hit_pos;
    _Bool hit = is_present(draw, mem_0, &hit_pos);
    if(hit) {
        memcpy(mem_1, mem_0, hit_pos*sizeof(int));
        memcpy(mem_1 + hit_pos, mem_0 + hit_pos + 1, (5 - hit_pos - 1)*sizeof(int));
        mem_1[4] = draw;
        return 1;
    } else {
        memcpy(mem_1, mem_0, 4*sizeof(int));
        mem_1[4] = draw;
        return 0;
    }
}


original_code:
int main(void)
{
    state_t *larry = calloc(161051, sizeof(state_t));
    state_t *robin = calloc(161051, sizeof(state_t));
    larry[0].score[0] = 1;
    robin[0].score[0] = 1;
    int draw;
    for(draw = 0; draw < 50; draw++) {
        printf("doing draw %d\n", draw);
        state_t *larry_new = calloc(161051, sizeof(state_t));
        state_t *robin_new = calloc(161051, sizeof(state_t));
        int prev_state;
        for(prev_state = 0; prev_state < 161051; prev_state++) {
            int extracted[5];
            unpack(prev_state, extracted);
            int n;
            for(n = 1; n <= 10; n++) {
                int updated[5];
                int score = update_larry(n, extracted, updated);
                int updated_index = pack(updated);
                int i;
                for(i = 0; i + score < 50; i++) {
                    larry_new[updated_index].score[i+score] += larry[prev_state].score[i];
                }
                score = update_robin(n, extracted, updated);
                updated_index = pack(updated);
                for(i = 0; i + score < 50; i++) {
                    robin_new[updated_index].score[i + score] += robin[prev_state].score[i];
                }
            }
        }
        state_t *tmp = larry;
        larry = larry_new;
        free(tmp);
        tmp = robin;
        robin = robin_new;
        free(tmp);
    }
    return 0;
}

canonical_original_code:
int main()
{
    struct _state *larry = calloc(161051, sizeof(state_t));
    struct _state *robin = calloc(161051, sizeof(state_t));
    larry[0].score[0] = 1;
    robin[0].score[0] = 1;
    int draw;
    for(draw = 0; draw < 50; draw++) {
        printf("doing draw %d\n", draw);
        struct _state *larry_new = calloc(161051, sizeof(state_t));
        struct _state *robin_new = calloc(161051, sizeof(state_t));
        int prev_state;
        for(prev_state = 0; prev_state < 161051; prev_state++) {
            int extracted[5];
            unpack(prev_state, extracted);
            int n;
            for(n = 1; n <= 10; n++) {
                int updated[5];
                int score = update_larry(n, extracted, updated);
                int updated_index = pack(updated);
                int i;
                for(i = 0; i + score < 50; i++) {
                    larry_new[updated_index].score[i+score] += larry[prev_state].score[i];
                }
                score = update_robin(n, extracted, updated);
                updated_index = pack(updated);
                for(i = 0; i + score < 50; i++) {
                    robin_new[updated_index].score[i + score] += robin[prev_state].score[i];
                }
            }
        }
        struct _state *tmp = larry;
        larry = larry_new;
        free(tmp);
        tmp = robin;
        robin = robin_new;
        free(tmp);
    }
    return 0;
}

variable_types:
larry
struct _state { long score[50]; } *

variable_types:
robin
struct _state { long score[50]; } *

variable_types:
extracted
int [5]

variable_types: n int

variable_types:
updated
int [5]

variable_types: score int

variable_types:
tmp
struct _state { long score[50]; } *


unpack

decompiled_code:
unsigned int *__fastcall unpack(unsigned int a1, unsigned int *a2)
{
unsigned int *v2; // rdx
unsigned int *result; // rax

v2 = a2 + 4;
do
{
*v2 = a1 % 0xB;
a1 /= 0xBu;
result = v2--;
}
while ( result != a2 );
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func7(unsigned int a1, unsigned int *a2)
{
unsigned int *v2; // rdx
unsigned int *result; // rax

v2 = a2 + 4;
do
{
*v2 = a1 % 0xB;
a1 /= 0xBu;
result = v2--;
}
while ( result != a2 );
return result;
}

original_code:
static inline void unpack(int n, int state[5]) {
    int i = 0;
    for(i = 0; i < 5; i++) {
        state[4-i] = n % 11;
        n /= 11;
    }
}

variable_types:
state
int [5]


pack

decompiled_code:
__int64 __fastcall pack(__int64 a1)
{
__int64 v1; // rcx
__int64 result; // rax

v1 = a1 + 20;
LODWORD(result) = 0;
do
{
a1 += 4LL;
result = (unsigned int)(*(_DWORD *)(a1 - 4) + 11 * result);
}
while ( a1 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rcx
__int64 result; // rax

v1 = a1 + 20;
LODWORD(result) = 0;
do
{
a1 += 4LL;
result = (unsigned int)(*(_DWORD *)(a1 - 4) + 11 * result);
}
while ( a1 != v1 );
return result;
}

original_code:
static inline int pack(int state[5]) {
    int ret = 0;
    int i;
    for(i = 0; i < 5; i++) {
        ret *= 11;
        ret += state[i];
    }
    return ret;
}

variable_types: ret int


cube

original_code:
long cube(long x, long m)
{
    long xmod = x % m;
    long x3 = xmod*xmod*xmod;
    return x3 % m;
}

variable_types: x long

variable_types: m long

variable_types: xmod long


main

original_code:
int main()
{
    int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43};
    int np = sizeof(primes) / sizeof(int);
    long *cur_items = malloc(primes[np-1]*sizeof(long));
    int n_items = 0;
    long *tmp = ((void *)0);
    long i;
    for(i = 1; i < primes[np-1]; i++) {
        if(cube(i, primes[np-1]) == 1) {
            cur_items[n_items++] = i;
        }
    }
    uint64_t cur_modulus = primes[np-1];
    for(i = np-2; i >= 0; i--) {
        tmp = realloc(tmp, n_items*sizeof(long));
        int tmp_items = n_items;
        memcpy(tmp, cur_items, n_items*sizeof(long));
        cur_items = realloc(cur_items, n_items * primes[i] * sizeof(long));
        n_items = 0;
        int j;
        for(j = 0; j < tmp_items; j++) {
            int k;
            uint64_t test = tmp[j];
            for(k = 0; k < primes[i]; k++) {
                if(cube(test, primes[i]) == 1) {
                    cur_items[n_items++] = test;
                }
                test += cur_modulus;
            }
        }
        cur_modulus *= primes[i];
    }
    uint64_t sum = 0;
    for(i = 0; i < n_items; i++) {
        if(cur_items[i] > 1)
            sum += cur_items[i];
    }
    printf("S(%ld) == %ld\n", cur_modulus, sum);
    return 0;
}

canonical_original_code:
int main()
{
    int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43};
    int np = sizeof(primes) / sizeof(int);
    long *cur_items = malloc(primes[np-1]*sizeof(long));
    int n_items = 0;
    long *tmp = ((void *)0);
    long i;
    for(i = 1; i < primes[np-1]; i++) {
        if(cube(i, primes[np-1]) == 1) {
            cur_items[n_items++] = i;
        }
    }
    unsigned long cur_modulus = primes[np-1];
    for(i = np-2; i >= 0; i--) {
        tmp = realloc(tmp, n_items*sizeof(long));
        int tmp_items = n_items;
        memcpy(tmp, cur_items, n_items*sizeof(long));
        cur_items = realloc(cur_items, n_items * primes[i] * sizeof(long));
        n_items = 0;
        int j;
        for(j = 0; j < tmp_items; j++) {
            int k;
            unsigned long test = tmp[j];
            for(k = 0; k < primes[i]; k++) {
                if(cube(test, primes[i]) == 1) {
                    cur_items[n_items++] = test;
                }
                test += cur_modulus;
            }
        }
        cur_modulus *= primes[i];
    }
    unsigned long sum = 0;
    for(i = 0; i < n_items; i++) {
        if(cur_items[i] > 1)
            sum += cur_items[i];
    }
    printf("S(%ld) == %ld\n", cur_modulus, sum);
    return 0;
}

variable_types:
primes
int []

variable_types: np int

variable_types:
tmp
long *

variable_types: i long

variable_types: j int

variable_types: k int

variable_types:
test
unsigned long

variable_types:
sum
unsigned long


original_code:
d_t *find_closest(double x, d_t *pairs, int left, int right)
{
    if(left == right) {
        return pairs + left;
    }
    if(left + 1 == right) {
        if(fabs(x - pairs[left].fafb) < fabs(x - pairs[right].fafb))
            return pairs + left;
        else
            return pairs + right;
    }
    int mid = (left + right) / 2;
    double dmid = x - pairs[mid].fafb;
    if(dmid == 0.0)
        return pairs + mid;
    if(dmid < 0)
        return find_closest(x, pairs, left, mid);
    if(dmid > 0)
        return find_closest(x, pairs, mid, right);
    return ((void *)0);
}

canonical_original_code:
struct _d *find_closest(double x, struct _d *pairs, int left, int right)
{
    if(left == right) {
        return pairs + left;
    }
    if(left + 1 == right) {
        if(fabs(x - pairs[left].fafb) < fabs(x - pairs[right].fafb))
            return pairs + left;
        else
            return pairs + right;
    }
    int mid = (left + right) / 2;
    double dmid = x - pairs[mid].fafb;
    if(dmid == 0.0)
        return pairs + mid;
    if(dmid < 0)
        return find_closest(x, pairs, left, mid);
    if(dmid > 0)
        return find_closest(x, pairs, mid, right);
    return ((void *)0);
}

variable_types: x double

variable_types:
pairs
struct _d *

variable_types: left int

variable_types: right int

variable_types: mid int

variable_types: dmid double

return_type: struct _d { int a; double fafb; } *


original_code:
int main()
{
    double *f = malloc(((int) (1.43 * 10000))*sizeof(double));
    int i;
    for(i = 0; i < ((int) (1.43 * 10000)); i++) {
        f[i] = exp(((double) i) / 10000) - 1;
    }
    int n_pairs = (((int) (1.43 * 10000))*(((int) (1.43 * 10000)) + 1)) / 2;
    d_t *pairs = malloc(n_pairs * sizeof(d_t));
    int k = 0;
    for(i = 0; i < ((int) (1.43 * 10000)); i++) {
        int j;
        double fi = f[i];
        for(j = 0; j <= i; j++) {
            pairs[k].a = i;
            pairs[k].b = j;
            pairs[k].fafb = fi + f[j];
            k++;
        }
    }
    qsort(pairs, n_pairs, sizeof(d_t), cmp);
    for(i = 0; i < 100; i += 10) {
        printf("pairs[%d]: %d, %d, %g\n", i, pairs[i].a, pairs[i].b, pairs[i].fafb);
    }
    double min_dist = 20.0;
    int abcd[4] = {0, 0, 0, 0};
    for(i = 0; i < n_pairs; i++) {
        double remainder = 3.14159265358979323846 - pairs[i].fafb;
        d_t *best = find_closest(remainder, pairs, 0, n_pairs - 1);
        double dist = fabs(pairs[i].fafb + best->fafb - 3.14159265358979323846);
        if(dist < min_dist) {
            min_dist = dist;
            abcd[0] = pairs[i].a;
            abcd[1] = pairs[i].b;
            abcd[2] = best->a;
            abcd[3] = best->b;
        }
    }
    int a = abcd[0];
    int b = abcd[1];
    int c = abcd[2];
    int d = abcd[3];
    printf("best solution at (%d, %d, %d, %d) => %g\n", abcd[0], abcd[1], abcd[2], abcd[3], min_dist);
    printf("result: %d\n", a*a + b*b + c*c + d*d);
    return 0;
}

canonical_original_code:
int main()
{
    double *f = malloc(((int) (1.43 * 10000))*sizeof(double));
    int i;
    for(i = 0; i < ((int) (1.43 * 10000)); i++) {
        f[i] = exp(((double) i) / 10000) - 1;
    }
    int n_pairs = (((int) (1.43 * 10000))*(((int) (1.43 * 10000)) + 1)) / 2;
    struct _d *pairs = malloc(n_pairs * sizeof(d_t));
    int k = 0;
    for(i = 0; i < ((int) (1.43 * 10000)); i++) {
        int j;
        double fi = f[i];
        for(j = 0; j <= i; j++) {
            pairs[k].a = i;
            pairs[k].b = j;
            pairs[k].fafb = fi + f[j];
            k++;
        }
    }
    qsort(pairs, n_pairs, sizeof(d_t), cmp);
    for(i = 0; i < 100; i += 10) {
        printf("pairs[%d]: %d, %d, %g\n", i, pairs[i].a, pairs[i].b, pairs[i].fafb);
    }
    double min_dist = 20.0;
    int abcd[4] = {0, 0, 0, 0};
    for(i = 0; i < n_pairs; i++) {
        double remainder = 3.14159265358979323846 - pairs[i].fafb;
        struct _d *best = find_closest(remainder, pairs, 0, n_pairs - 1);
        double dist = fabs(pairs[i].fafb + best->fafb - 3.14159265358979323846);
        if(dist < min_dist) {
            min_dist = dist;
            abcd[0] = pairs[i].a;
            abcd[1] = pairs[i].b;
            abcd[2] = best->a;
            abcd[3] = best->b;
        }
    }
    int a = abcd[0];
    int b = abcd[1];
    int c = abcd[2];
    int d = abcd[3];
    printf("best solution at (%d, %d, %d, %d) => %g\n", abcd[0], abcd[1], abcd[2], abcd[3], min_dist);
    printf("result: %d\n", a*a + b*b + c*c + d*d);
    return 0;
}

variable_types:
f
double *

variable_types: i int

variable_types:
pairs
struct _d { int a; double fafb; } *

variable_types: fi double

variable_types:
abcd
int [4]

variable_types: remainder double

variable_types:
best
struct _d { int a; double fafb; } *

variable_types: dist double

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: d int


cmp

decompiled_code:
__int64 __fastcall cmp(const void *a1, const void *a2)
{
double v2; // xmm1_8
double v3; // xmm0_8
__int64 result; // rax

v2 = *((double *)a1 + 1);
v3 = *((double *)a2 + 1);
if ( v2 == v3 )
result = 0LL;
else
result = 2 * (unsigned int)(v2 > v3) - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
double v2; // xmm1_8
double v3; // xmm0_8
__int64 result; // rax

v2 = *((double *)a1 + 1);
v3 = *((double *)a2 + 1);
if ( v2 == v3 )
result = 0LL;
else
result = 2 * (unsigned int)(v2 > v3) - 1;
return result;
}

original_code:
int cmp(const void *va, const void *vb)
{
    d_t *a = (d_t *) va;
    d_t *b = (d_t *) vb;
    if(a->fafb == b->fafb)
        return 0;
    return 2*(a->fafb > b->fafb) - 1;
}

canonical_original_code:
int cmp(void *va, void *vb)
{
    struct _d *a = (d_t *) va;
    struct _d *b = (d_t *) vb;
    if(a->fafb == b->fafb)
        return 0;
    return 2*(a->fafb > b->fafb) - 1;
}

variable_types:
va
void *

variable_types:
vb
void *

variable_types:
a
struct _d { int a; double fafb; } *

variable_types:
b
struct _d { int a; double fafb; } *


original_code:
long sum_squarefree(long *values, int n, long *sqprimes, int num_primes) {
    int i;
    long ret = 0;
    for(i = 0; i < n; i++) {
        long value = values[i];
        int j;
        _Bool sqfree = 1;
        for(j = 0; j < num_primes; j++) {
            if(sqprimes[j] > value)
                break;
            if(!(value % sqprimes[j])) {
                sqfree = 0;
                break;
            }
        }
        ret += sqfree ? value : 0;
    }
    return ret;
}

variable_types:
values
long *

variable_types: n int

variable_types:
sqprimes
long *

variable_types: ret long

variable_types: value long

variable_types: j int


main

original_code:
int main(void) {
    int nalloc = 1000;
    long *values = malloc(nalloc*sizeof(long));
    char buf[256];
    int n = 0;
    long max = -1;
    while(((void *)0) != fgets(buf, sizeof(buf), stdin)) {
        values[n] = strtol(buf, ((void *)0), 10);
        if(values[n] > max) {
            max = values[n];
        }
        n++;
    }
    int max_prime = (int) ceil(sqrt(max));
    while(((long) max_prime) * ((long) max_prime) < max)
        max_prime++;
    long *sqprimes;
    int num_primes;
    get_primes(max_prime, &sqprimes, &num_primes);
    int i;
    for(i = 0; i < num_primes; i++)
        sqprimes[i] *= sqprimes[i];
    long result = sum_squarefree(values, n, sqprimes, num_primes);
    printf("result: %ld\n", result);
    return 0;
}

canonical_original_code:
int main() {
    int nalloc = 1000;
    long *values = malloc(nalloc*sizeof(long));
    char buf[256];
    int n = 0;
    long max = -1;
    while(((void *)0) != fgets(buf, sizeof(buf), stdin)) {
        values[n] = strtol(buf, ((void *)0), 10);
        if(values[n] > max) {
            max = values[n];
        }
        n++;
    }
    int max_prime = (int) ceil(sqrt(max));
    while(((long) max_prime) * ((long) max_prime) < max)
        max_prime++;
    long *sqprimes;
    int num_primes;
    get_primes(max_prime, &sqprimes, &num_primes);
    int i;
    for(i = 0; i < num_primes; i++)
        sqprimes[i] *= sqprimes[i];
    long result = sum_squarefree(values, n, sqprimes, num_primes);
    printf("result: %ld\n", result);
    return 0;
}

variable_types: nalloc int

variable_types:
buf
char [256]

variable_types: max long

variable_types: i int

variable_types: result long


decompiled_code:
__int64 __fastcall mr_isprime(unsigned __int64 a1)
{
__int64 v1; // r14
unsigned __int64 v2; // rbp
int v4; // eax
int v5; // er12
__int64 v6; // r15
__int64 v7; // rax
__int64 v8; // rax
unsigned __int64 v9; // rdi
int i; // er13
__int64 v11; // rax
int v13; // [rsp+0h] [rbp-3Ch]

if ( (a1 & 1) == 0 )
return 0LL;
v1 = 0x7FFFFFFFLL;
v2 = a1 - 1;
v4 = trailz(a1 - 1);
v13 = 5;
v5 = v4 - 1;
v6 = (a1 - 1) >> v4;
if ( a1 - 1 <= 0x7FFFFFFF )
v1 = a1 - 1;
while ( 1 )
{
v7 = rand_int_constprop_0(v1);
v8 = uipow(v7, v6, a1);
v9 = v8;
if ( v8 != 1 && v2 != v8 )
break;
LABEL_13:
if ( !--v13 )
return 1LL;
}
if ( v5 > 0 )
{
for ( i = 0; i != v5; ++i )
{
v11 = uipow(v9, 2LL, a1);
v9 = v11;
if ( v11 == 1 )
break;
if ( v2 == v11 )
goto LABEL_13;
}
}
return 0LL;
}

original_code:
_Bool mr_isprime(uint64_t n) {
    if(!(n & 1))
        return 0;
    uint64_t d = n-1;
    int r = _trailz(d);
    d >>= r;
    int i;
    _Bool possibly_prime = 1;
    for(i = 0; i < 5 && possibly_prime; i++) {
        uint64_t a = rand_int(2, (((2147483647) > (n-1)) ? (n-1) : (2147483647)));
        uint64_t x = uipow(a, d, n);
        if(x == 1ul || x == (n-1))
            continue;
        int j;
        possibly_prime = 0;
        for(j = 0; j < r-1; j++) {
            x = uipow(x, 2, n);
            if(x == 1ul) {
                possibly_prime = 0;
                break;
            }
            if(x == (n-1)) {
                possibly_prime = 1;
                break;
            }
        }
    }
    return possibly_prime;
}

canonical_original_code:
_Bool mr_isprime(unsigned long n) {
    if(!(n & 1))
        return 0;
    unsigned long d = n-1;
    int r = _trailz(d);
    d >>= r;
    int i;
    _Bool possibly_prime = 1;
    for(i = 0; i < 5 && possibly_prime; i++) {
        unsigned long a = rand_int(2, (((2147483647) > (n-1)) ? (n-1) : (2147483647)));
        unsigned long x = uipow(a, d, n);
        if(x == 1ul || x == (n-1))
            continue;
        int j;
        possibly_prime = 0;
        for(j = 0; j < r-1; j++) {
            x = uipow(x, 2, n);
            if(x == 1ul) {
                possibly_prime = 0;
                break;
            }
            if(x == (n-1)) {
                possibly_prime = 1;
                break;
            }
        }
    }
    return possibly_prime;
}

variable_types:
n
unsigned long

variable_types:
d
unsigned long

variable_types: r int

variable_types:
a
unsigned long

variable_types:
x
unsigned long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r15
unsigned __int64 v4; // r14
unsigned int v6; // [rsp+Ch] [rbp-3Ch]

v3 = 0LL;
v4 = 10LL;
v6 = 0;
while ( 0xAAAAAAAAAAAAAAABLL * v4 <= 0x5555555555555555LL
|| (unsigned __int64)((__int64)v4 % 7 - 3) > 1
|| v4 % 0xB - 2 <= 1
|| v4 % 0xB - 8 <= 1
|| v4 % 0xD - 5 <= 3
|| !(v4 % 0xD)
|| !(unsigned __int8)check(v4) )
{
v4 += 10LL;
if ( v4 == 150000000 )
goto LABEL_13;
LABEL_10:
if ( __ROR8__(0xE5032477AE8D46A5LL * v4, 7) <= 0x1AD7F29ABCAuLL )
printf("done with i == %ld\n", v4);
}
v3 += v4;
printf("hit for i == %ld\n", v4);
v4 += 10LL;
++v6;
if ( v4 != 150000000 )
goto LABEL_10;
LABEL_13:
printf("final i: %ld\n", 150000000LL);
printf("sum of target numbers: %ld\n", v3);
printf("%d primes of this form below %ld\n", v6, 150000000LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r15
unsigned __int64 v4; // r14
unsigned int v6; // [rsp+Ch] [rbp-3Ch]

v3 = 0LL;
v4 = 10LL;
v6 = 0;
while ( 0xAAAAAAAAAAAAAAABLL * v4 <= 0x5555555555555555LL
|| (unsigned __int64)((__int64)v4 % 7 - 3) > 1
|| v4 % 0xB - 2 <= 1
|| v4 % 0xB - 8 <= 1
|| v4 % 0xD - 5 <= 3
|| !(v4 % 0xD)
|| !(unsigned __int8)func12(v4) )
{
v4 += 10LL;
if ( v4 == 150000000 )
goto LABEL_13;
LABEL_10:
if ( __ROR8__(0xE5032477AE8D46A5LL * v4, 7) <= 0x1AD7F29ABCAuLL )
printf("done with i == %ld\n", v4);
}
v3 += v4;
printf("hit for i == %ld\n", v4);
v4 += 10LL;
++v6;
if ( v4 != 150000000 )
goto LABEL_10;
LABEL_13:
printf("final i: %ld\n", 150000000LL);
printf("sum of target numbers: %ld\n", v3);
printf("%d primes of this form below %ld\n", v6, 150000000LL);
return 0;
}

original_code:
int main()
{
    long i;
    long sum = 0l;
    int nz = 0;
    for(i = 10; i < 150000000l; i += 10) {
        if(!(i % 10000000))
            printf("done with i == %ld\n", i);
        if(!(i % 3))
            continue;
        long mod7 = i % 7;
        if(!(mod7 == 3 || mod7 == 4))
            continue;
        long mod11 = i % 11;
        if(mod11 == 2 || mod11 == 3 || mod11 == 8 || mod11 == 9)
            continue;
        long mod13 = i % 13;
        if((mod13 == 0) || (mod13 > 4 && mod13 < 9))
            continue;
        _Bool hit = check(i);
        if(hit) {
            printf("hit for i == %ld\n", i);
            sum += i;
            nz++;
        }
    }
    printf("final i: %ld\n", i);
    printf("sum of target numbers: %ld\n", sum);
    printf("%d primes of this form below %ld\n", nz, 150000000l);
    return 0;
}

variable_types: i long

variable_types: sum long

variable_types: nz int


check

decompiled_code:
__int64 __fastcall check(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
unsigned __int64 v3; // rbx
int v4; // er12
int v5; // ebp

v1 = a1 * a1;
if ( !(unsigned __int8)mr_isprime(a1 * a1 + 1) || !(unsigned __int8)mr_isprime(v1 + 3) )
return 0LL;
v3 = v1 + 5;
v4 = 0;
v5 = 5;
do
{
if ( seq[v4] == v5 )
{
result = mr_isprime(v3);
++v4;
}
else
{
result = (unsigned int)mr_isprime(v3) ^ 1;
}
v5 += 2;
v3 += 2LL;
}
while ( v5 <= 27 && (_BYTE)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
unsigned __int64 v3; // rbx
int v4; // er12
int v5; // ebp

v1 = a1 * a1;
if ( !(unsigned __int8)func11(a1 * a1 + 1) || !(unsigned __int8)func11(v1 + 3) )
return 0LL;
v3 = v1 + 5;
v4 = 0;
v5 = 5;
do
{
if ( seq[v4] == v5 )
{
result = func11(v3);
++v4;
}
else
{
result = (unsigned int)func11(v3) ^ 1;
}
v5 += 2;
v3 += 2LL;
}
while ( v5 <= 27 && (_BYTE)result );
return result;
}

original_code:
_Bool check(long n) {
    long n2 = n*n;
    _Bool hit = 0;
    if(mr_isprime(n2+1) && mr_isprime(n2+3)) {
        int j, k;
        hit = 1;
        k = 0;
        for(j = 5; hit && j <= 27; j += 2) {
            if(seq[k] == j) {
                hit &= mr_isprime(n2+j);
                k++;
            } else {
                hit &= !mr_isprime(n2+j);
            }
        }
    }
    return hit;
}

canonical_original_code:
_Bool check(long n) {
    long n2 = n*n;
    _Bool hit = 0;
    if(mr_isprime(n2+1) && mr_isprime(n2+3)) {
        int j; int k;
        hit = 1;
        k = 0;
        for(j = 5; hit && j <= 27; j += 2) {
            if(seq[k] == j) {
                hit &= mr_isprime(n2+j);
                k++;
            } else {
                hit &= !mr_isprime(n2+j);
            }
        }
    }
    return hit;
}

variable_types: n long

variable_types: k int


isprime

decompiled_code:
bool __fastcall prime::isprime(prime *this, int a2)
{
__int64 v2; // r10
__int64 v5; // r9
__int64 v6; // rdi
int v7; // ecx

v2 = *((int *)this + 5);
if ( (int)v2 > a2 )
return *(_BYTE *)(*(_QWORD *)this + a2) == 0;
v5 = *((_QWORD *)this + 1);
v6 = 0LL;
do
{
v7 = *(_DWORD *)(v5 + 4 * v6);
if ( !(a2 % v7) )
return 0;
if ( v7 * v7 >= a2 )
break;
++v6;
}
while ( *((_DWORD *)this + 4) > (int)v6 );
if ( v2 * v2 < a2 )
std::__ostream_insert<char,std::char_traits<char>>(
&std::cout,
"isprime() warning: number is too big to be certain!\n",
52LL);
return 1;
}

canonical_decompiled_code:
bool __fastcall prime::func3(prime *this, int a2)
{
__int64 v2; // r10
__int64 v5; // r9
__int64 v6; // rdi
int v7; // ecx

v2 = *((int *)this + 5);
if ( (int)v2 > a2 )
return *(_BYTE *)(*(_QWORD *)this + a2) == 0;
v5 = *((_QWORD *)this + 1);
v6 = 0LL;
do
{
v7 = *(_DWORD *)(v5 + 4 * v6);
if ( !(a2 % v7) )
return 0;
if ( v7 * v7 >= a2 )
break;
++v6;
}
while ( *((_DWORD *)this + 4) > (int)v6 );
if ( v2 * v2 < a2 )
std::__ostream_insert<char,std::char_traits<char>>(
&std::cout,
"isprime() warning: number is too big to be certain!\n",
52LL);
return 1;
}

original_code:
_Bool isprime(long x, long *p, long np)
{
    if(np < 1) {
        fprintf(stderr, "ERROR: no primes!\n");
        exit(-1);
    }
    if(x > p[np-1]*p[np-1]) {
        fprintf(stderr, "ERROR: %ld is beyond the maximum testable for primes up to %ld\n", x, p[np-1]);
        exit(-1);
    }
    if(x <= p[np-1])
        return ((void *)0) != bsearch(&x, p, np, sizeof(long), lcmp);
    if(!mr_isprime(x))
        return 0;
    long i = 0;
    for(i = 0; i < np; i++) {
        if(p[i]*p[i] >= x)
            break;
        if(0 == (x % p[i]))
            return 0;
    }
    return 1;
}

variable_types: x long

variable_types:
p
long *

variable_types: np long


repo: mckellyln/inotify-server

decompiled_code:
void __fastcall sig_hdlr(unsigned int a1)
{
if ( a1 == 10 )
{
dump_hash_info = 1;
}
else
{
if ( a1 != 12 )
{
if ( !background )
{
fflush(0LL);
fprintf(_bss_start, "\nexiting on signal %d ...\n\n", a1);
}
exit(0);
}
dump_hash_info = 2;
}
}

canonical_decompiled_code:
void __fastcall func7(unsigned int a1)
{
if ( a1 == 10 )
{
dump_hash_info = 1;
}
else
{
if ( a1 != 12 )
{
if ( !background )
{
fflush(0LL);
fprintf(_bss_start, "\nexiting on signal %d ...\n\n", a1);
}
exit(0);
}
dump_hash_info = 2;
}
}

original_code:
static void sig_hdlr(int sig)
{
    if (sig == 10) {
        dump_hash_info = 1;
    }else if (sig == 12) {
        dump_hash_info = 2;
    } else {
        if (!background) {
            fflush(((void *)0));
            fprintf(stderr,"\nexiting on signal %d ...\n\n", sig);
        }
        exit(0);
    }
    return;
}

variable_types: sig int


decompiled_code:
void __fastcall __noreturn work_loop(void *a1)
{
time_t v1; // r12
char *v2; // rbp
__int64 v3; // rbx
bool v4; // cc
int v5; // eax
int v6; // ebp
struct timespec v7; // [rsp+0h] [rbp-28h] BYREF

while ( 1 )
{
v1 = time(0LL);
pthread_rwlock_rdlock(&rwlock);
v2 = purge;
if ( !purge )
goto LABEL_11;
v3 = *((_QWORD *)purge + 41);
if ( *((__int64 *)purge + 38) > 1 )
goto LABEL_3;
LABEL_8:
if ( v3 )
break;
LABEL_11:
pthread_rwlock_unlock(&rwlock);
v7.tv_sec = 0LL;
v7.tv_nsec = 50000000LL;
nanosleep(&v7, 0LL);
}
while ( 1 )
{
v2 = (char *)v3;
v3 = *(_QWORD *)(v3 + 328);
if ( *((__int64 *)v2 + 38) > 1 )
break;
if ( !v3 )
goto LABEL_11;
}
LABEL_3:
if ( v1 - *((_QWORD *)v2 + 38) >= lifespan )
{
v4 = debug <= 1;
*((_QWORD *)v2 + 38) = 1LL;
if ( !v4 )
{
pthread_mutex_lock(&lock);
fprintf(_bss_start, "debug: purging <%s> from page cache ...\n", v2);
pthread_mutex_unlock(&lock);
}
v5 = open(v2, 0);
v6 = v5;
if ( v5 >= 0 )
{
posix_fadvise(v5, 0LL, 0LL, 4);
close(v6);
}
}
goto LABEL_8;
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
time_t v1; // r12
char *v2; // rbp
__int64 v3; // rbx
bool v4; // cc
int v5; // eax
int v6; // ebp
struct timespec v7; // [rsp+0h] [rbp-28h] BYREF

while ( 1 )
{
v1 = time(0LL);
pthread_rwlock_rdlock(&rwlock);
v2 = purge;
if ( !purge )
goto LABEL_11;
v3 = *((_QWORD *)purge + 41);
if ( *((__int64 *)purge + 38) > 1 )
goto LABEL_3;
LABEL_8:
if ( v3 )
break;
LABEL_11:
pthread_rwlock_unlock(&rwlock);
v7.tv_sec = 0LL;
v7.tv_nsec = 50000000LL;
nanosleep(&v7, 0LL);
}
while ( 1 )
{
v2 = (char *)v3;
v3 = *(_QWORD *)(v3 + 328);
if ( *((__int64 *)v2 + 38) > 1 )
break;
if ( !v3 )
goto LABEL_11;
}
LABEL_3:
if ( v1 - *((_QWORD *)v2 + 38) >= lifespan )
{
v4 = debug <= 1;
*((_QWORD *)v2 + 38) = 1LL;
if ( !v4 )
{
pthread_mutex_lock(&lock);
fprintf(_bss_start, "debug: purging <%s> from page cache ...\n", v2);
pthread_mutex_unlock(&lock);
}
v5 = open(v2, 0);
v6 = v5;
if ( v5 >= 0 )
{
posix_fadvise(v5, 0LL, 0LL, 4);
close(v6);
}
}
goto LABEL_8;
}

original_code:
static void *work_loop(void *bogus)
{
    struct timespec ts;
    PURGE *pp = ((void *)0);
    PURGE *ptmp = ((void *)0);
    while (1) {
        time_t time_now = time(((void *)0));
        pthread_rwlock_rdlock(&rwlock);
        for((pp)=(purge),(ptmp)=(__typeof(pp))((purge)?(purge)->hh.next:((void *)0)); pp; (pp)=(ptmp),(ptmp)=(__typeof(pp))((ptmp)?(ptmp)->hh.next:((void *)0))) {
            if ((pp->stime > 1) && ((time_now - pp->stime) >= lifespan)) {
                pp->stime = 1;
                if (debug > 1) {
                    pthread_mutex_lock(&lock);
                    fprintf(stderr,"debug: purging <%s> from page cache ...\n", pp->filename);
                    pthread_mutex_unlock(&lock);
                }
                int fd = open(pp->filename, 00);
                if (fd >= 0) {
                    posix_fadvise(fd, 0, 0, 4);
                    close(fd);
                }
            }
        }
        pthread_rwlock_unlock(&rwlock);
        ts.tv_sec = 0;
        ts.tv_nsec = 50000000;
        nanosleep(&ts, ((void *)0));
    }
    return ((void *)0);
}

canonical_original_code:
static void *work_loop(void *bogus)
{
    struct timespec ts;
    struct PURGE *pp = ((void *)0);
    struct PURGE *ptmp = ((void *)0);
    while (1) {
        long time_now = time(((void *)0));
        pthread_rwlock_rdlock(&rwlock);
        for((pp)=(purge),(ptmp)=(__typeof(pp))((purge)?(purge)->hh.next:((void *)0)); pp; (pp)=(ptmp),(ptmp)=(__typeof(pp))((ptmp)?(ptmp)->hh.next:((void *)0))) {
            if ((pp->stime > 1) && ((time_now - pp->stime) >= lifespan)) {
                pp->stime = 1;
                if (debug > 1) {
                    pthread_mutex_lock(&lock);
                    fprintf(stderr,"debug: purging <%s> from page cache ...\n", pp->filename);
                    pthread_mutex_unlock(&lock);
                }
                int fd = open(pp->filename, 00);
                if (fd >= 0) {
                    posix_fadvise(fd, 0, 0, 4);
                    close(fd);
                }
            }
        }
        pthread_rwlock_unlock(&rwlock);
        ts.tv_sec = 0;
        ts.tv_nsec = 50000000;
        nanosleep(&ts, ((void *)0));
    }
    return ((void *)0);
}

variable_types:
bogus
void *

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: struct PURGE { char filename[300]; long stime; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *

variable_types: fd int

return_type: void *

user_defined_types: struct PURGE { char filename[300]; long stime; struct UT_hash_handle hh; }

user_defined_types: struct UT_hash_handle { struct UT_hash_table *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; }

user_defined_types: struct UT_hash_table { struct UT_hash_bucket *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; }


main

original_code:
int main(int argc,char *argv[])
{
    char tfile[200] = { "testfile" };
    unlink(tfile);
    int fd = open(tfile, 0100|02, 0644);
    if (fd < 0) {
        fprintf(stderr,"unable to open test file %s, errno = %d\n", tfile, (*__errno_location ()));
        return 0;
    }
    char buf[200] = { "Now is the time for all good men ...\n" };
    int len = strlen(buf);
    if (write(fd, buf, len) != len) {
        fprintf(stderr,"unable to write out test file %s correctly\n", tfile);
        unlink(tfile);
        return 0;
    }
    int ret = close(fd);
    if (ret != 0)
        fprintf(stderr,"unable to close testfile, errno = %d\n", (*__errno_location ()));
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char tfile[200] = { "testfile" };
    unlink(tfile);
    int fd = open(tfile, 0100|02, 0644);
    if (fd < 0) {
        fprintf(stderr,"unable to open test file %s, errno = %d\n", tfile, (*__errno_location ()));
        return 0;
    }
    char buf[200] = { "Now is the time for all good men ...\n" };
    int len = strlen(buf);
    if (write(fd, buf, len) != len) {
        fprintf(stderr,"unable to write out test file %s correctly\n", tfile);
        unlink(tfile);
        return 0;
    }
    int ret = close(fd);
    if (ret != 0)
        fprintf(stderr,"unable to close testfile, errno = %d\n", (*__errno_location ()));
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
tfile
char [200]

variable_types:
buf
char [200]

variable_types: len int

variable_types: ret int


prefix

repo: mcpherrinm/webscale

decompiled_code:
_BOOL8 __fastcall prefix(char *s1, char *s2)
{
int v2; // ebx
int v3; // eax

v2 = strlen(s1);
v3 = strlen(s2);
if ( v3 >= v2 )
v3 = v2;
return strncmp(s1, s2, v3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(char *s1, char *s2)
{
int v2; // ebx
int v3; // eax

v2 = strlen(s1);
v3 = strlen(s2);
if ( v3 >= v2 )
v3 = v2;
return strncmp(s1, s2, v3) == 0;
}

original_code:
int prefix(const char *a, const char*b) {
  int la = strlen(a);
  int lb = strlen(b);
  return 0 == strncmp(a, b, la > lb ? lb : la);
}

canonical_original_code:
int prefix(char *a, char *b) {
  int la = strlen(a);
  int lb = strlen(b);
  return 0 == strncmp(a, b, la > lb ? lb : la);
}

variable_types:
a
char *

variable_types:
b
char *

variable_types: la int

variable_types: lb int


main

repo: mcsf/postman

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
setup(argc, argv, envp);
if ( (unsigned int)check_solvable() )
{
collect_cycles();
merge_cycles();
output();
}
else
{
puts("-1");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func16(argc, argv, envp);
if ( (unsigned int)func17() )
{
func19();
func20();
func21();
}
else
{
puts("-1");
}
return 0;
}

original_code:
int main() {
 setup();
 if (!check_solvable()) {
  printf("-1\n");
  return 0;
 }
 collect_cycles();
 merge_cycles();
 output();
 return 0;
}


decompiled_code:
_QWORD *lst_new()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
return result;
}

original_code:
list *lst_new() {
 list *l = (list *) malloc(sizeof(list));
 l->head = ((void *)0);
 return l;
}

canonical_original_code:
struct list *lst_new() {
 struct list *l = (list *) malloc(sizeof(list));
 l->head = ((void *)0);
 return l;
}

variable_types: struct list { struct _node { int value; struct _node *next; } *head; } *


decompiled_code:
void __fastcall lst_remove(_QWORD **a1, int a2)
{
_QWORD *v3; // rdi
_QWORD *v4; // rax

v3 = *a1;
if ( v3 )
{
if ( *(_DWORD *)v3 == a2 )
{
*a1 = (_QWORD *)v3[1];
free(v3);
}
else
{
while ( 1 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
if ( !v3 )
break;
if ( *(_DWORD *)v3 == a2 )
{
v4[1] = v3[1];
free(v3);
return;
}
}
}
}
}

original_code:
void lst_remove(list *l, int value) {
 node *pre, *cur;
 pre = cur = l->head;
 if (!cur) return;
 if (cur->value == value) {
  l->head = cur->next;
  free(cur);
  return;
 }
 while ((cur = cur->next)) {
  if (cur->value == value) {
   pre->next = cur->next;
   free(cur);
   return;
  }
  pre = cur;
 }
}

canonical_original_code:
void lst_remove(struct list *l, int value) {
 struct _node *pre; struct _node *cur;
 pre = cur = l->head;
 if (!cur) return;
 if (cur->value == value) {
  l->head = cur->next;
  free(cur);
  return;
 }
 while ((cur = cur->next)) {
  if (cur->value == value) {
   pre->next = cur->next;
   free(cur);
   return;
  }
  pre = cur;
 }
}

variable_types: value int

variable_types: struct _node { int value; struct _node *next; } *


decompiled_code:
_BOOL8 __fastcall lst_empty(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int lst_empty(list *l) {
 return (l->head == ((void *)0));
}

canonical_original_code:
int lst_empty(struct list *l) {
 return (l->head == ((void *)0));
}

user_defined_types: struct _node { int value; struct _node *next; }