decompiled_code:
int __fastcall ab_handle_newval(int a1)
{
__int64 v1; // rsi
int result; // eax

if ( *(_DWORD *)from_clients != a1 )
_assert_fail("sock == from_clients->sock", "abmagic.c", 0x5Du, "ab_handle_newval");
if ( (int)udp_read_next_message() < 0 )
return puts("Dropping invalid client message");
v1 = *(unsigned int *)(from_clients + 28);
if ( (_DWORD)v1 != 32 )
return printf("Unknow msg type %d received\n", v1);
ab_store_value((void *)(from_clients + 32), *(_QWORD *)(from_clients + 20));
result = sendbuf_add_accept_ack(to_learners, accept_buffer);
++current_iid;
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
__int64 v1; // rsi
int result; // eax

if ( *(_DWORD *)from_clients != a1 )
_assert_fail("sock == from_clients->sock", "abmagic.c", 0x5Du, "ab_handle_newval");
if ( (int)udp_read_next_message() < 0 )
return puts("Dropping invalid client message");
v1 = *(unsigned int *)(from_clients + 28);
if ( (_DWORD)v1 != 32 )
return printf("Unknow msg type %d received\n", v1);
func2((void *)(from_clients + 32), *(_QWORD *)(from_clients + 20));
result = sendbuf_add_accept_ack(to_learners, accept_buffer);
++current_iid;
return result;
}

original_code:
static void
ab_handle_newval(int sock, short event, void *arg) {
    (sock = sock);;
    (event = event);;
    (arg = arg);;
    ((void) sizeof ((sock == from_clients->sock) ? 1 : 0), __extension__ ({ if (sock == from_clients->sock) ; else __assert_fail ("sock == from_clients->sock", "abmagic.c", 93, __extension__ __PRETTY_FUNCTION__); }));
    int valid = udp_read_next_message(from_clients);
    if (valid < 0) {
        printf("Dropping invalid client message\n");
        return;
    }
    paxos_msg * msg = (paxos_msg*) &from_clients->recv_buffer;
    switch(msg->type) {
        case submit: {
            ab_store_value(msg->data, msg->data_size);
            sendbuf_add_accept_ack(to_learners, accept_buffer);
            current_iid +=1;
        }
        break;
        default: {
            printf("Unknow msg type %d received\n", msg->type);
        }
    }
}

canonical_original_code:
static void ab_handle_newval(int sock, short event, void *arg) {
    (sock = sock);;
    (event = event);;
    (arg = arg);;
    ((void) sizeof ((sock == from_clients->sock) ? 1 : 0), __extension__ ({ if (sock == from_clients->sock) ; else __assert_fail ("sock == from_clients->sock", "abmagic.c", 93, __extension__ __PRETTY_FUNCTION__); }));
    int valid = udp_read_next_message(from_clients);
    if (valid < 0) {
        printf("Dropping invalid client message\n");
        return;
    }
    struct paxos_msg_t *msg = (paxos_msg*) &from_clients->recv_buffer;
    switch(msg->type) {
        case submit: {
            ab_store_value(msg->data, msg->data_size);
            sendbuf_add_accept_ack(to_learners, accept_buffer);
            current_iid +=1;
        }
        break;
        default: {
            printf("Unknow msg type %d received\n", msg->type);
        }
    }
}

variable_types: valid int

variable_types: struct paxos_msg_t { unsigned long data_size; enum pax_msg_code_e { prepare_reqs=1, prepare_acks=2, accept_reqs=4, accept_acks=8, repeat_reqs=16, submit=32, leader_announce=64, alive_ping=65 } type; char data[]; } *


repo: dgomezferro/libpaxos

decompiled_code:
__int64 __fastcall ab_handle_repeat_req_batch(__int16 *a1)
{
__int16 v1; // bx
__int64 v2; // rax

sendbuf_clear(to_learners, 8LL, 0LL);
if ( *a1 > 0 )
{
v1 = 0;
do
{
v2 = stablestorage_get_record(*(unsigned int *)&a1[2 * v1 + 2]);
if ( v2 && *(_QWORD *)(v2 + 16) )
sendbuf_add_accept_ack(to_learners, v2);
++v1;
}
while ( *a1 > v1 );
}
return sendbuf_flush(to_learners);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 *a1)
{
__int16 v1; // bx
__int64 v2; // rax

sendbuf_clear(to_learners, 8LL, 0LL);
if ( *a1 > 0 )
{
v1 = 0;
do
{
v2 = stablestorage_get_record(*(unsigned int *)&a1[2 * v1 + 2]);
if ( v2 && *(_QWORD *)(v2 + 16) )
sendbuf_add_accept_ack(to_learners, v2);
++v1;
}
while ( *a1 > v1 );
}
return sendbuf_flush(to_learners);
}

original_code:
static void
ab_handle_repeat_req_batch(repeat_req_batch * rrb) {
    if(0 >= 3) { printf("[%s] ", __func__) ; printf ("Repeating accept for %d instances\n", rrb->count) ;};
    sendbuf_clear(to_learners, accept_acks, 0);
    short int i;
    accept_ack * aa;
    for(i = 0; i < rrb->count; i++) {
        aa = stablestorage_get_record(rrb->requests[i]);
        if(aa != ((void *)0) && aa->value_size > 0) {
            sendbuf_add_accept_ack(to_learners, aa);
        } else {
            if(0 >= 3) { printf("[%s] ", __func__) ; printf ("Cannot retransmit iid:%lu no value accepted \n", aa->iid) ;};
        }
    }
    sendbuf_flush(to_learners);
}

canonical_original_code:
static void ab_handle_repeat_req_batch(struct repeat_req_batch_t *rrb) {
    if(0 >= 3) { printf("[%s] ", __func__) ; printf ("Repeating accept for %d instances\n", rrb->count) ;};
    sendbuf_clear(to_learners, accept_acks, 0);
    short i;
    struct accept_ack_t *aa;
    for(i = 0; i < rrb->count; i++) {
        aa = stablestorage_get_record(rrb->requests[i]);
        if(aa != ((void *)0) && aa->value_size > 0) {
            sendbuf_add_accept_ack(to_learners, aa);
        } else {
            if(0 >= 3) { printf("[%s] ", __func__) ; printf ("Cannot retransmit iid:%lu no value accepted \n", aa->iid) ;};
        }
    }
    sendbuf_flush(to_learners);
}

variable_types: struct repeat_req_batch_t { short count; unsigned int requests[]; } *

variable_types: i short

variable_types: struct accept_ack_t { unsigned int iid; unsigned int ballot; unsigned int value_ballot; short is_final; unsigned long value_size; char value[]; } *

return_type: void


decompiled_code:
int __fastcall ab_handle_leamsg(int a1)
{
__int64 v1; // rsi
int result; // eax

if ( *(_DWORD *)from_learners != a1 )
_assert_fail("sock == from_learners->sock", "abmagic.c", 0x99u, "ab_handle_leamsg");
if ( (int)udp_read_next_message() < 0 )
return puts("Dropping invalid learner message");
v1 = *(unsigned int *)(from_learners + 28);
if ( (_DWORD)v1 == 16 )
result = ab_handle_repeat_req_batch((__int16 *)(from_learners + 32));
else
result = printf("Unknow msg type %d received\n", v1);
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
__int64 v1; // rsi
int result; // eax

if ( *(_DWORD *)from_learners != a1 )
_assert_fail("sock == from_learners->sock", "abmagic.c", 0x99u, "ab_handle_leamsg");
if ( (int)udp_read_next_message() < 0 )
return puts("Dropping invalid learner message");
v1 = *(unsigned int *)(from_learners + 28);
if ( (_DWORD)v1 == 16 )
result = func4((__int16 *)(from_learners + 32));
else
result = printf("Unknow msg type %d received\n", v1);
return result;
}

original_code:
static void
ab_handle_leamsg(int sock, short event, void *arg) {
    (sock = sock);;
    (event = event);;
    (arg = arg);;
    ((void) sizeof ((sock == from_learners->sock) ? 1 : 0), __extension__ ({ if (sock == from_learners->sock) ; else __assert_fail ("sock == from_learners->sock", "abmagic.c", 153, __extension__ __PRETTY_FUNCTION__); }));
    int valid = udp_read_next_message(from_learners);
    if (valid < 0) {
        printf("Dropping invalid learner message\n");
        return;
    }
    paxos_msg * msg = (paxos_msg*) &from_learners->recv_buffer;
    switch(msg->type) {
        case repeat_reqs: {
            ab_handle_repeat_req_batch((repeat_req_batch*) msg->data);
        }
        break;
        default: {
            printf("Unknow msg type %d received\n", msg->type);
        }
    }
}

canonical_original_code:
static void ab_handle_leamsg(int sock, short event, void *arg) {
    (sock = sock);;
    (event = event);;
    (arg = arg);;
    ((void) sizeof ((sock == from_learners->sock) ? 1 : 0), __extension__ ({ if (sock == from_learners->sock) ; else __assert_fail ("sock == from_learners->sock", "abmagic.c", 153, __extension__ __PRETTY_FUNCTION__); }));
    int valid = udp_read_next_message(from_learners);
    if (valid < 0) {
        printf("Dropping invalid learner message\n");
        return;
    }
    struct paxos_msg_t *msg = (paxos_msg*) &from_learners->recv_buffer;
    switch(msg->type) {
        case repeat_reqs: {
            ab_handle_repeat_req_batch((struct repeat_req_batch_t *) msg->data);
        }
        break;
        default: {
            printf("Unknow msg type %d received\n", msg->type);
        }
    }
}

variable_types: sock int

variable_types: event short

variable_types:
arg
void *

user_defined_types: struct paxos_msg_t { unsigned long data_size; enum pax_msg_code_e type; char data[]; }

user_defined_types: struct repeat_req_batch_t { short count; unsigned int requests[]; }

user_defined_types: enum pax_msg_code_e { prepare_reqs=1, prepare_acks=2, accept_reqs=4, accept_acks=8, repeat_reqs=16, submit=32, leader_announce=64, alive_ping=65 }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

if ( (unsigned int)ab_init(argc, argv, envp) )
{
puts("Init failed!");
v3 = -1;
}
else
{
v3 = 0;
event_dispatch();
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

if ( (unsigned int)func0(argc, argv, envp) )
{
puts("Init failed!");
v3 = -1;
}
else
{
v3 = 0;
event_dispatch();
}
return v3;
}

original_code:
int main (int argc, char const *argv[]) {
    if (ab_init() != 0) {
        printf("Init failed!\n");
        return -1;
    }
    event_dispatch();
    return 0;
    argc = argc;
    argv = argv;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    if (ab_init() != 0) {
        printf("Init failed!\n");
        return -1;
    }
    event_dispatch();
    return 0;
    argc = argc;
    argv = argv;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


repo: dgonyeo/odd

original_code:
void volumeAnimation4(double *params, double totalTime, odd_led_t *color, double *storage)
{
    (void)params;
    (void)totalTime;
    SAMPLE rAvg = 0;
    SAMPLE gAvg = 0;
    SAMPLE bAvg = 0;
    SAMPLE soundBuffer[(1024)];
    runFFT(soundBuffer);
    const int lowMax = 4;
    const int midMax = 30;
    const int highMax = 107;
    for(int i = 0; i < lowMax; i++)
    {
        rAvg += soundBuffer[i];
    }
    for(int i = lowMax; i < midMax; i++)
    {
        gAvg += soundBuffer[i];
    }
    for(int i = midMax; i < highMax; i++)
    {
        bAvg += soundBuffer[i];
    }
    rAvg /= 800;
    while(rAvg > 1)
    {
        printf("rfuck\n");
        rAvg -= 1;
    }
    gAvg /= 800;
    while(gAvg > 1)
    {
        printf("gfuck\n");
        gAvg -= 1;
    }
    bAvg /= 800;
    while(bAvg > 1)
    {
        printf("bfuck\n");
        bAvg -= 1;
    }
    rAvg = logf(rAvg * 10 + 1) / logf(11);
    gAvg = logf(gAvg * 10 + 1) / logf(11);
    bAvg = logf(bAvg * 10 + 1) / logf(11);
    int rWidth = (int)(rAvg * (8 * 8) / 3);
    int gWidth = (int)(gAvg * (8 * 8) / 3);
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i,'r', 0);
        setTempLED(i,'g', 0);
        setTempLED(i,'b', 0);
    }
    for(int i = 0; i < rWidth; i++)
    {
        setTempLED(i,'r', 1000 * rAvg);
    }
    for(int i = (8 * 8) / 3; i < (8 * 8) / 3 + gWidth; i++)
    {
        setTempLED(i,'g', 1000 * gAvg);
    }
}

canonical_original_code:
void volumeAnimation4(double *params, double totalTime, struct odd_led_t *color, double *storage)
{
    (void)params;
    (void)totalTime;
    float rAvg = 0;
    float gAvg = 0;
    float bAvg = 0;
    float soundBuffer[-1];
    runFFT(soundBuffer);
    int lowMax = 4;
    int midMax = 30;
    int highMax = 107;
    for(int i = 0; i < lowMax; i++)
    {
        rAvg += soundBuffer[i];
    }
    for(int i = lowMax; i < midMax; i++)
    {
        gAvg += soundBuffer[i];
    }
    for(int i = midMax; i < highMax; i++)
    {
        bAvg += soundBuffer[i];
    }
    rAvg /= 800;
    while(rAvg > 1)
    {
        printf("rfuck\n");
        rAvg -= 1;
    }
    gAvg /= 800;
    while(gAvg > 1)
    {
        printf("gfuck\n");
        gAvg -= 1;
    }
    bAvg /= 800;
    while(bAvg > 1)
    {
        printf("bfuck\n");
        bAvg -= 1;
    }
    rAvg = logf(rAvg * 10 + 1) / logf(11);
    gAvg = logf(gAvg * 10 + 1) / logf(11);
    bAvg = logf(bAvg * 10 + 1) / logf(11);
    int rWidth = (int)(rAvg * (8 * 8) / 3);
    int gWidth = (int)(gAvg * (8 * 8) / 3);
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i,'r', 0);
        setTempLED(i,'g', 0);
        setTempLED(i,'b', 0);
    }
    for(int i = 0; i < rWidth; i++)
    {
        setTempLED(i,'r', 1000 * rAvg);
    }
    for(int i = (8 * 8) / 3; i < (8 * 8) / 3 + gWidth; i++)
    {
        setTempLED(i,'g', 1000 * gAvg);
    }
}

variable_types:
params
double *

variable_types: totalTime double

variable_types: struct odd_led_t { int R; int G; int B; struct odd_led_t *next; } *

variable_types:
storage
double *

variable_types: rAvg float

variable_types: gAvg float

variable_types: bAvg float

variable_types:
soundBuffer
float [-1]

variable_types: lowMax int

variable_types: midMax int

variable_types: highMax int

variable_types: i int

variable_types: rWidth int

variable_types: gWidth int


wave

original_code:
void wave(double *params, double totalTime, odd_led_t *color, double *storage) {
    double frequency = params[0];
    double strength = params[1];
    double speed = params[2];
    double time = totalTime * speed;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', 0);
        setTempLED(i, 'g', 0);
        setTempLED(i, 'b', 0);
    }
    double leds[(8 * 8)];
    memset(leds, 0, sizeof(double) * (8 * 8));
    for(int x = 0; x < frequency; x++)
    {
        double center = (fmod(time, 1.0 / frequency) + x / frequency) / 2
                            * (1.0 + (0.2 * strength));
        for(int i = 0; i < (8 * 8); i++)
        {
            double distanceToCenter = (center - i * 1.0 / (8 * 8)) / strength;
            if(distanceToCenter > 0 && distanceToCenter < 0.1) {
                distanceToCenter *= 10;
                double brightness = 0;
                if(distanceToCenter > 1.0/6.0)
                    brightness = sin(-1.0 * distanceToCenter * 3.141592653 * 6.0/5 - 4.0/3 * 3.141592653) / 2 + 0.5;
                else
                    brightness = 6 * distanceToCenter;
                leds[i] += brightness;
                if(leds[i] > 1)
                    leds[i] = 1;
            }
        }
    }
    for(int i = 0; i < (8 * 8)/2; i++) {
        setTempLED((8 * 8) / 2 - i - 1, 'r', leds[i] * color->R);
        setTempLED((8 * 8) / 2 - i - 1, 'g', leds[i] * color->G);
        setTempLED((8 * 8) / 2 - i - 1, 'b', leds[i] * color->B);
        setTempLED((8 * 8) / 2 + i, 'r', leds[i] * color->R);
        setTempLED((8 * 8) / 2 + i, 'g', leds[i] * color->G);
        setTempLED((8 * 8) / 2 + i, 'b', leds[i] * color->B);
    }
}

canonical_original_code:
void wave(double *params, double totalTime, struct odd_led_t *color, double *storage) {
    double frequency = params[0];
    double strength = params[1];
    double speed = params[2];
    double time = totalTime * speed;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', 0);
        setTempLED(i, 'g', 0);
        setTempLED(i, 'b', 0);
    }
    double leds[-1];
    memset(leds, 0, sizeof(double) * (8 * 8));
    for(int x = 0; x < frequency; x++)
    {
        double center = (fmod(time, 1.0 / frequency) + x / frequency) / 2
                            * (1.0 + (0.2 * strength));
        for(int i = 0; i < (8 * 8); i++)
        {
            double distanceToCenter = (center - i * 1.0 / (8 * 8)) / strength;
            if(distanceToCenter > 0 && distanceToCenter < 0.1) {
                distanceToCenter *= 10;
                double brightness = 0;
                if(distanceToCenter > 1.0/6.0)
                    brightness = sin(-1.0 * distanceToCenter * 3.141592653 * 6.0/5 - 4.0/3 * 3.141592653) / 2 + 0.5;
                else
                    brightness = 6 * distanceToCenter;
                leds[i] += brightness;
                if(leds[i] > 1)
                    leds[i] = 1;
            }
        }
    }
    for(int i = 0; i < (8 * 8)/2; i++) {
        setTempLED((8 * 8) / 2 - i - 1, 'r', leds[i] * color->R);
        setTempLED((8 * 8) / 2 - i - 1, 'g', leds[i] * color->G);
        setTempLED((8 * 8) / 2 - i - 1, 'b', leds[i] * color->B);
        setTempLED((8 * 8) / 2 + i, 'r', leds[i] * color->R);
        setTempLED((8 * 8) / 2 + i, 'g', leds[i] * color->G);
        setTempLED((8 * 8) / 2 + i, 'b', leds[i] * color->B);
    }
}

variable_types: frequency double

variable_types: strength double

variable_types: speed double

variable_types: time double

variable_types:
leds
double [-1]

variable_types: x int

variable_types: center double

variable_types: distanceToCenter double

variable_types: brightness double

user_defined_types: struct odd_led_t { int R; int G; int B; struct odd_led_t *next; }


invertTempLeds

decompiled_code:
__int64 invertTempLeds()
{
unsigned int i; // ebx
int v1; // eax
int v2; // eax
int v3; // eax
__int64 result; // rax

for ( i = 0; i != 64; ++i )
{
v1 = getTempLED(i, 114LL);
setTempLED(i, 114LL, (unsigned int)(4095 - v1));
v2 = getTempLED(i, 103LL);
setTempLED(i, 103LL, (unsigned int)(4095 - v2));
v3 = getTempLED(i, 98LL);
result = setTempLED(i, 98LL, (unsigned int)(4095 - v3));
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int i; // ebx
int v1; // eax
int v2; // eax
int v3; // eax
__int64 result; // rax

for ( i = 0; i != 64; ++i )
{
v1 = getTempLED(i, 114LL);
setTempLED(i, 114LL, (unsigned int)(4095 - v1));
v2 = getTempLED(i, 103LL);
setTempLED(i, 103LL, (unsigned int)(4095 - v2));
v3 = getTempLED(i, 98LL);
result = setTempLED(i, 98LL, (unsigned int)(4095 - v3));
}
return result;
}

original_code:
void invertTempLeds()
{
 for(int i = 0; i < (8 * 8); i++)
 {
        setTempLED(i, 'r', 4095 - getTempLED(i, 'r'));
        setTempLED(i, 'g', 4095 - getTempLED(i, 'g'));
        setTempLED(i, 'b', 4095 - getTempLED(i, 'b'));
 }
}


addLeds

decompiled_code:
__int64 addLeds()
{
unsigned int i; // ebx
int v1; // ebp
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // ebp
int v6; // eax
__int64 result; // rax
int v8; // ebp
int v9; // ebp
int v10; // ebp

for ( i = 0; i != 64; ++i )
{
v8 = getLED(i, 114LL);
if ( (int)(getTempLED(i, 114LL) + v8) <= 4095 )
{
v1 = getLED(i, 114LL);
v2 = getTempLED(i, 114LL);
setLED(i, 114LL, (unsigned int)(v1 + v2));
}
else
{
setLED(i, 114LL, 4095LL);
}
v9 = getLED(i, 103LL);
if ( (int)(getTempLED(i, 103LL) + v9) <= 4095 )
{
v3 = getLED(i, 103LL);
v4 = getTempLED(i, 103LL);
setLED(i, 103LL, (unsigned int)(v3 + v4));
}
else
{
setLED(i, 103LL, 4095LL);
}
v10 = getLED(i, 98LL);
if ( (int)(getTempLED(i, 98LL) + v10) <= 4095 )
{
v5 = getLED(i, 98LL);
v6 = getTempLED(i, 98LL);
result = setLED(i, 98LL, (unsigned int)(v5 + v6));
}
else
{
result = setLED(i, 98LL, 4095LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int i; // ebx
int v1; // ebp
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // ebp
int v6; // eax
__int64 result; // rax
int v8; // ebp
int v9; // ebp
int v10; // ebp

for ( i = 0; i != 64; ++i )
{
v8 = getLED(i, 114LL);
if ( (int)(getTempLED(i, 114LL) + v8) <= 4095 )
{
v1 = getLED(i, 114LL);
v2 = getTempLED(i, 114LL);
setLED(i, 114LL, (unsigned int)(v1 + v2));
}
else
{
setLED(i, 114LL, 4095LL);
}
v9 = getLED(i, 103LL);
if ( (int)(getTempLED(i, 103LL) + v9) <= 4095 )
{
v3 = getLED(i, 103LL);
v4 = getTempLED(i, 103LL);
setLED(i, 103LL, (unsigned int)(v3 + v4));
}
else
{
setLED(i, 103LL, 4095LL);
}
v10 = getLED(i, 98LL);
if ( (int)(getTempLED(i, 98LL) + v10) <= 4095 )
{
v5 = getLED(i, 98LL);
v6 = getTempLED(i, 98LL);
result = setLED(i, 98LL, (unsigned int)(v5 + v6));
}
else
{
result = setLED(i, 98LL, 4095LL);
}
}
return result;
}

original_code:
void addLeds(odd_led_t* leds[(8 * 8)], odd_led_t* tempLeds[(8 * 8)])
{
 for(int i = 0; i < (8 * 8); i++)
 {
  if(getLED(i, 'r') + getTempLED(i, 'r') > 4095)
            setLED(i, 'r', 4095);
  else
            setLED(i, 'r', getLED(i, 'r') + getTempLED(i, 'r'));
  if(getLED(i, 'g') + getTempLED(i, 'g') > 4095)
            setLED(i, 'g', 4095);
  else
            setLED(i, 'g', getLED(i, 'g') + getTempLED(i, 'g'));
  if(getLED(i, 'b') + getTempLED(i, 'b') > 4095)
            setLED(i, 'b', 4095);
  else
            setLED(i, 'b', getLED(i, 'b') + getTempLED(i, 'b'));
 }
}

canonical_original_code:
void addLeds(struct odd_led_t *leds[-1], struct odd_led_t *tempLeds[-1])
{
 for(int i = 0; i < (8 * 8); i++)
 {
  if(getLED(i, 'r') + getTempLED(i, 'r') > 4095)
            setLED(i, 'r', 4095);
  else
            setLED(i, 'r', getLED(i, 'r') + getTempLED(i, 'r'));
  if(getLED(i, 'g') + getTempLED(i, 'g') > 4095)
            setLED(i, 'g', 4095);
  else
            setLED(i, 'g', getLED(i, 'g') + getTempLED(i, 'g'));
  if(getLED(i, 'b') + getTempLED(i, 'b') > 4095)
            setLED(i, 'b', 4095);
  else
            setLED(i, 'b', getLED(i, 'b') + getTempLED(i, 'b'));
 }
}

variable_types: struct odd_led_t { int R; int G; int B; struct odd_led_t *next; } *[-1]

variable_types:
tempLeds
struct odd_led_t *[-1]


subtractLeds

decompiled_code:
__int64 subtractLeds()
{
unsigned int i; // ebx
int v1; // ebp
int v2; // eax
__int64 result; // rax
int v4; // ebp
int v5; // ebp
int v6; // eax
int v7; // ebp
int v8; // ebp
int v9; // eax
int v10; // ebp

for ( i = 0; i != 64; ++i )
{
v4 = getLED(i, 114LL);
if ( (int)(v4 - getTempLED(i, 114LL)) < 0 )
{
setLED(i, 114LL, 0LL);
}
else
{
v5 = getLED(i, 114LL);
v6 = getTempLED(i, 114LL);
setLED(i, 114LL, (unsigned int)(v5 - v6));
}
v7 = getLED(i, 103LL);
if ( (int)(v7 - getTempLED(i, 103LL)) < 0 )
{
setLED(i, 103LL, 0LL);
}
else
{
v8 = getLED(i, 103LL);
v9 = getTempLED(i, 103LL);
setLED(i, 103LL, (unsigned int)(v8 - v9));
}
v10 = getLED(i, 98LL);
if ( (int)(v10 - getTempLED(i, 98LL)) >= 0 )
{
v1 = getLED(i, 98LL);
v2 = getTempLED(i, 98LL);
result = setLED(i, 98LL, (unsigned int)(v1 - v2));
}
else
{
result = setLED(i, 98LL, 0LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int i; // ebx
int v1; // ebp
int v2; // eax
__int64 result; // rax
int v4; // ebp
int v5; // ebp
int v6; // eax
int v7; // ebp
int v8; // ebp
int v9; // eax
int v10; // ebp

for ( i = 0; i != 64; ++i )
{
v4 = getLED(i, 114LL);
if ( (int)(v4 - getTempLED(i, 114LL)) < 0 )
{
setLED(i, 114LL, 0LL);
}
else
{
v5 = getLED(i, 114LL);
v6 = getTempLED(i, 114LL);
setLED(i, 114LL, (unsigned int)(v5 - v6));
}
v7 = getLED(i, 103LL);
if ( (int)(v7 - getTempLED(i, 103LL)) < 0 )
{
setLED(i, 103LL, 0LL);
}
else
{
v8 = getLED(i, 103LL);
v9 = getTempLED(i, 103LL);
setLED(i, 103LL, (unsigned int)(v8 - v9));
}
v10 = getLED(i, 98LL);
if ( (int)(v10 - getTempLED(i, 98LL)) >= 0 )
{
v1 = getLED(i, 98LL);
v2 = getTempLED(i, 98LL);
result = setLED(i, 98LL, (unsigned int)(v1 - v2));
}
else
{
result = setLED(i, 98LL, 0LL);
}
}
return result;
}

original_code:
void subtractLeds(odd_led_t* leds[(8 * 8)], odd_led_t* tempLeds[(8 * 8)])
{
 for(int i = 0; i < (8 * 8); i++)
 {
  if(getLED(i, 'r') - getTempLED(i, 'r') < 0)
            setLED(i, 'r', 0);
  else
            setLED(i, 'r', getLED(i, 'r') - getTempLED(i, 'r'));
  if(getLED(i, 'g') - getTempLED(i, 'g') < 0)
            setLED(i, 'g', 0);
  else
            setLED(i, 'g', getLED(i, 'g') - getTempLED(i, 'g'));
  if(getLED(i, 'b') - getTempLED(i, 'b') < 0)
            setLED(i, 'b', 0);
  else
            setLED(i, 'b', getLED(i, 'b') - getTempLED(i, 'b'));
 }
}

canonical_original_code:
void subtractLeds(struct odd_led_t *leds[-1], struct odd_led_t *tempLeds[-1])
{
 for(int i = 0; i < (8 * 8); i++)
 {
  if(getLED(i, 'r') - getTempLED(i, 'r') < 0)
            setLED(i, 'r', 0);
  else
            setLED(i, 'r', getLED(i, 'r') - getTempLED(i, 'r'));
  if(getLED(i, 'g') - getTempLED(i, 'g') < 0)
            setLED(i, 'g', 0);
  else
            setLED(i, 'g', getLED(i, 'g') - getTempLED(i, 'g'));
  if(getLED(i, 'b') - getTempLED(i, 'b') < 0)
            setLED(i, 'b', 0);
  else
            setLED(i, 'b', getLED(i, 'b') - getTempLED(i, 'b'));
 }
}


inverseSubtractLeds

decompiled_code:
__int64 __fastcall inverseSubtractLeds(__int64 a1, __int64 a2)
{
((void (*)(void))invertTempLeds)();
subtractLeds(a1, a2);
return invertTempLeds(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
((void (*)(void))invertTempLeds)();
func2(a1, a2);
return func0(a1, a2);
}

original_code:
void inverseSubtractLeds(odd_led_t* leds[(8 * 8)], odd_led_t* tempLeds[(8 * 8)])
{
 invertTempLeds(leds, tempLeds);
 subtractLeds(leds, tempLeds);
 invertTempLeds(leds, tempLeds);
}

canonical_original_code:
void inverseSubtractLeds(struct odd_led_t *leds[-1], struct odd_led_t *tempLeds[-1])
{
 invertTempLeds(leds, tempLeds);
 subtractLeds(leds, tempLeds);
 invertTempLeds(leds, tempLeds);
}


multiplyLeds

decompiled_code:
__int64 multiplyLeds()
{
unsigned int i; // ebx
int v1; // ebp
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // ebp
int v6; // eax
__int64 result; // rax
int v8; // ebp
int v9; // ebp
int v10; // ebp

for ( i = 0; i != 64; ++i )
{
v8 = getLED(i, 114LL);
if ( (int)(getTempLED(i, 114LL) * v8) <= 4095 )
{
v1 = getLED(i, 114LL);
v2 = getTempLED(i, 114LL);
setLED(i, 114LL, (unsigned int)(v2 * v1));
}
else
{
setLED(i, 114LL, 4095LL);
}
v9 = getLED(i, 103LL);
if ( (int)(getTempLED(i, 103LL) * v9) <= 4095 )
{
v3 = getLED(i, 103LL);
v4 = getTempLED(i, 103LL);
setLED(i, 103LL, (unsigned int)(v4 * v3));
}
else
{
setLED(i, 103LL, 4095LL);
}
v10 = getLED(i, 98LL);
if ( (int)(getTempLED(i, 98LL) * v10) <= 4095 )
{
v5 = getLED(i, 98LL);
v6 = getTempLED(i, 98LL);
result = setLED(i, 98LL, (unsigned int)(v6 * v5));
}
else
{
result = setLED(i, 98LL, 4095LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int i; // ebx
int v1; // ebp
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // ebp
int v6; // eax
__int64 result; // rax
int v8; // ebp
int v9; // ebp
int v10; // ebp

for ( i = 0; i != 64; ++i )
{
v8 = getLED(i, 114LL);
if ( (int)(getTempLED(i, 114LL) * v8) <= 4095 )
{
v1 = getLED(i, 114LL);
v2 = getTempLED(i, 114LL);
setLED(i, 114LL, (unsigned int)(v2 * v1));
}
else
{
setLED(i, 114LL, 4095LL);
}
v9 = getLED(i, 103LL);
if ( (int)(getTempLED(i, 103LL) * v9) <= 4095 )
{
v3 = getLED(i, 103LL);
v4 = getTempLED(i, 103LL);
setLED(i, 103LL, (unsigned int)(v4 * v3));
}
else
{
setLED(i, 103LL, 4095LL);
}
v10 = getLED(i, 98LL);
if ( (int)(getTempLED(i, 98LL) * v10) <= 4095 )
{
v5 = getLED(i, 98LL);
v6 = getTempLED(i, 98LL);
result = setLED(i, 98LL, (unsigned int)(v6 * v5));
}
else
{
result = setLED(i, 98LL, 4095LL);
}
}
return result;
}

original_code:
void multiplyLeds(odd_led_t* leds[(8 * 8)], odd_led_t* tempLeds[(8 * 8)])
{
 for(int i = 0; i < (8 * 8); i++)
 {
  if(getLED(i, 'r') * getTempLED(i, 'r') > 4095)
            setLED(i, 'r', 4095);
  else
            setLED(i, 'r', getLED(i, 'r') * getTempLED(i, 'r'));
  if(getLED(i, 'g') * getTempLED(i, 'g') > 4095)
            setLED(i, 'g', 4095);
  else
            setLED(i, 'g', getLED(i, 'g') * getTempLED(i, 'g'));
  if(getLED(i, 'b') * getTempLED(i, 'b') > 4095)
            setLED(i, 'b', 4095);
  else
            setLED(i, 'b', getLED(i, 'b') * getTempLED(i, 'b'));
 }
}

canonical_original_code:
void multiplyLeds(struct odd_led_t *leds[-1], struct odd_led_t *tempLeds[-1])
{
 for(int i = 0; i < (8 * 8); i++)
 {
  if(getLED(i, 'r') * getTempLED(i, 'r') > 4095)
            setLED(i, 'r', 4095);
  else
            setLED(i, 'r', getLED(i, 'r') * getTempLED(i, 'r'));
  if(getLED(i, 'g') * getTempLED(i, 'g') > 4095)
            setLED(i, 'g', 4095);
  else
            setLED(i, 'g', getLED(i, 'g') * getTempLED(i, 'g'));
  if(getLED(i, 'b') * getTempLED(i, 'b') > 4095)
            setLED(i, 'b', 4095);
  else
            setLED(i, 'b', getLED(i, 'b') * getTempLED(i, 'b'));
 }
}


smoothStrobe

decompiled_code:
__int64 __fastcall smoothStrobe(double *a1, int *a2, double a3)
{
double v3; // xmm0_8
double v4; // xmm0_8
unsigned int i; // ebx
__int64 result; // rax
double v7; // [rsp+8h] [rbp-20h]

v3 = a3 * *a1;
if ( (int)v3 % 2 == 1 )
v4 = fmod(v3, 1.0);
else
v4 = 1.0 - fmod(v3, 1.0);
v7 = odd_pow(v4, 2.0) * 1.5 - 0.5;
if ( v7 < 0.0 )
v7 = 0.0;
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, (unsigned int)(int)((double)*a2 * v7));
setTempLED(i, 103LL, (unsigned int)(int)((double)a2[1] * v7));
result = setTempLED(i, 98LL, (unsigned int)(int)((double)a2[2] * v7));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double *a1, int *a2, double a3)
{
double v3; // xmm0_8
double v4; // xmm0_8
unsigned int i; // ebx
__int64 result; // rax
double v7; // [rsp+8h] [rbp-20h]

v3 = a3 * *a1;
if ( (int)v3 % 2 == 1 )
v4 = fmod(v3, 1.0);
else
v4 = 1.0 - fmod(v3, 1.0);
v7 = odd_pow(v4, 2.0) * 1.5 - 0.5;
if ( v7 < 0.0 )
v7 = 0.0;
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, (unsigned int)(int)((double)*a2 * v7));
setTempLED(i, 103LL, (unsigned int)(int)((double)a2[1] * v7));
result = setTempLED(i, 98LL, (unsigned int)(int)((double)a2[2] * v7));
}
return result;
}

original_code:
void smoothStrobe(double *params, double totalTime, odd_led_t *color, double *storage)
{
    double speed = params[0];
    double time = totalTime * speed;
    double power = 0;
    if((int)time % 2 == 1)
        power = fmod(time, 1);
    else
        power = 1 - fmod(time, 1);
    power = odd_pow(power, 2);
    power *= 1.5;
    power -= 0.5;
    if(power < 0)
        power = 0;
    for(int i = 0; i < (8 * 8); i++) {
        setTempLED(i, 'r', color->R * power);
        setTempLED(i, 'g', color->G * power);
        setTempLED(i, 'b', color->B * power);
    }
}

canonical_original_code:
void smoothStrobe(double *params, double totalTime, struct odd_led_t *color, double *storage)
{
    double speed = params[0];
    double time = totalTime * speed;
    double power = 0;
    if((int)time % 2 == 1)
        power = fmod(time, 1);
    else
        power = 1 - fmod(time, 1);
    power = odd_pow(power, 2);
    power *= 1.5;
    power -= 0.5;
    if(power < 0)
        power = 0;
    for(int i = 0; i < (8 * 8); i++) {
        setTempLED(i, 'r', color->R * power);
        setTempLED(i, 'g', color->G * power);
        setTempLED(i, 'b', color->B * power);
    }
}

variable_types:
params
double *

variable_types: totalTime double

variable_types: struct odd_led_t { int R; int G; int B; struct odd_led_t *next; } *

variable_types:
storage
double *

variable_types: power double


cycle

original_code:
void cycle(double *params, double totalTime, odd_led_t *color, double *storage) {
    double speed = params[0];
    double radius = params[1];
    double num = params[2];
    double time = totalTime * speed;
    double center = 0.0;
    int numLeds = (8 * 8) - 1;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', 0);
        setTempLED(i, 'g', 0);
        setTempLED(i, 'b', 0);
    }
    center = fmod(time, 1);
    if(center < 0) center += 1;
    center *= numLeds;
    for(int x = 0; x < num; x++)
    {
        double tempcenter = center + (x * 1.0 / num) * (8 * 8);
        if(tempcenter > (8 * 8)) tempcenter -= (8 * 8);
        double ledDistances[(8 * 8)];
        for(int i = 0; i < (8 * 8); i++) ledDistances[i] = 0;
        for(int i = tempcenter - radius; i <= tempcenter + radius; i++)
        {
            int index = i;
            if(index >= (8 * 8)) index -= (8 * 8);
            if(index < 0) index += (8 * 8);
            if(tempcenter - i > 0)
                ledDistances[index] = tempcenter - i;
            else
                ledDistances[index] = i - tempcenter;
            ledDistances[index] =
                    (radius - ledDistances[index]) / radius;
        }
        odd_led_t *color2 = color->next;
        if(color2 == ((void *)0))
        {
            for(int i = 0; i < (8 * 8); i++)
            {
                setTempLED(i, 'r',
                        color->R * ledDistances[i] + getTempLED(i, 'r'));
                setTempLED(i, 'g',
                        color->G * ledDistances[i] + getTempLED(i, 'g'));
                setTempLED(i, 'b',
                        color->B * ledDistances[i] + getTempLED(i, 'b'));
            }
        }
        else
        {
            for(int i = 0; i < (8 * 8); i++)
            {
                double colorDistance = pow(ledDistances[i], 1);
                odd_led_t colorTemp;
                colorTemp.R = color->R * colorDistance +
                              color2->R * (0.1 / colorDistance);
                colorTemp.G = color->G * colorDistance +
                              color2->G * (0.1 / colorDistance);
                colorTemp.B = color->B * colorDistance +
                              color2->B * (0.1 / colorDistance);
                double colorStrength = (16/3) *
                    (pow(((1.0 - ledDistances[i]) * 2) + 2, -2)
                      - (1.0 / 15.5));
                setTempLED(i, 'r',
                        colorTemp.R * colorStrength + getTempLED(i, 'r'));
                setTempLED(i, 'g',
                        colorTemp.G * colorStrength + getTempLED(i, 'r'));
                setTempLED(i, 'b',
                        colorTemp.B * colorStrength + getTempLED(i, 'r'));
            }
        }
    }
}

canonical_original_code:
void cycle(double *params, double totalTime, struct odd_led_t *color, double *storage) {
    double speed = params[0];
    double radius = params[1];
    double num = params[2];
    double time = totalTime * speed;
    double center = 0.0;
    int numLeds = (8 * 8) - 1;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', 0);
        setTempLED(i, 'g', 0);
        setTempLED(i, 'b', 0);
    }
    center = fmod(time, 1);
    if(center < 0) center += 1;
    center *= numLeds;
    for(int x = 0; x < num; x++)
    {
        double tempcenter = center + (x * 1.0 / num) * (8 * 8);
        if(tempcenter > (8 * 8)) tempcenter -= (8 * 8);
        double ledDistances[-1];
        for(int i = 0; i < (8 * 8); i++) ledDistances[i] = 0;
        for(int i = tempcenter - radius; i <= tempcenter + radius; i++)
        {
            int index = i;
            if(index >= (8 * 8)) index -= (8 * 8);
            if(index < 0) index += (8 * 8);
            if(tempcenter - i > 0)
                ledDistances[index] = tempcenter - i;
            else
                ledDistances[index] = i - tempcenter;
            ledDistances[index] =
                    (radius - ledDistances[index]) / radius;
        }
        struct odd_led_t *color2 = color->next;
        if(color2 == ((void *)0))
        {
            for(int i = 0; i < (8 * 8); i++)
            {
                setTempLED(i, 'r',
                        color->R * ledDistances[i] + getTempLED(i, 'r'));
                setTempLED(i, 'g',
                        color->G * ledDistances[i] + getTempLED(i, 'g'));
                setTempLED(i, 'b',
                        color->B * ledDistances[i] + getTempLED(i, 'b'));
            }
        }
        else
        {
            for(int i = 0; i < (8 * 8); i++)
            {
                double colorDistance = pow(ledDistances[i], 1);
                struct odd_led_t colorTemp;
                colorTemp.R = color->R * colorDistance +
                              color2->R * (0.1 / colorDistance);
                colorTemp.G = color->G * colorDistance +
                              color2->G * (0.1 / colorDistance);
                colorTemp.B = color->B * colorDistance +
                              color2->B * (0.1 / colorDistance);
                double colorStrength = (16/3) *
                    (pow(((1.0 - ledDistances[i]) * 2) + 2, -2)
                      - (1.0 / 15.5));
                setTempLED(i, 'r',
                        colorTemp.R * colorStrength + getTempLED(i, 'r'));
                setTempLED(i, 'g',
                        colorTemp.G * colorStrength + getTempLED(i, 'r'));
                setTempLED(i, 'b',
                        colorTemp.B * colorStrength + getTempLED(i, 'r'));
            }
        }
    }
}

variable_types: radius double

variable_types: num double

variable_types: numLeds int

variable_types: i int

variable_types: tempcenter double

variable_types:
ledDistances
double [-1]

variable_types: index int

variable_types: colorDistance double

variable_types: struct odd_led_t { int R; int G; int B; struct odd_led_t *next; }

variable_types: colorStrength double


cylonEye

decompiled_code:
__int64 __fastcall cylonEye(double *a1, __int64 a2, double a3)
{
unsigned int i; // ebx
double v4; // xmm0_8
double v5; // xmm2_8
char *v6; // rax
int v7; // eax
double v8; // xmm0_8
__int64 result; // rax
int *v10; // r14
__int64 v11; // rbp
__int64 j; // rbx
double v13; // rbp
double v14; // xmm1_8
int v15; // er15
double v16; // xmm0_8
double v17; // xmm1_8
double v18; // xmm1_8
double v19; // rbx
double v20; // [rsp+0h] [rbp-248h]
int v21; // [rsp+0h] [rbp-248h]
double x; // [rsp+8h] [rbp-240h]
double v23[64]; // [rsp+10h] [rbp-238h] BYREF
char v24; // [rsp+210h] [rbp-38h] BYREF

v20 = a1[1];
x = a3 * *a1;
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, 0LL);
setTempLED(i, 103LL, 0LL);
setTempLED(i, 98LL, 0LL);
}
if ( (int)x % 2 == 1 )
v4 = fmod(x, 1.0);
else
v4 = 1.0 - fmod(x, 1.0);
v5 = odd_sin(v4) * 63.0;
v6 = (char *)v23;
do
{
*(_QWORD *)v6 = 0LL;
v6 += 8;
}
while ( v6 != &v24 );
v7 = (int)(v5 - v20);
v8 = (double)v7;
for ( result = v7 + 1; v20 + v5 >= v8; ++result )
{
if ( (unsigned int)(result - 2) <= 0x3E )
{
v14 = v5 - v8;
if ( v5 - v8 <= 0.0 )
v14 = v8 - v5;
*(&x + result) = (v20 - v14) / v20;
}
v8 = (double)(int)result;
}
v10 = *(int **)(a2 + 16);
v11 = 0LL;
if ( v10 )
{
do
{
v19 = v23[v11];
if ( v19 != 0.0 )
{
v15 = (int)((double)v10[1] * (1.0 / v19) + (double)*(int *)(a2 + 4) * v19);
v21 = (int)((double)v10[2] * (1.0 / v19) + (double)*(int *)(a2 + 8) * v19);
x = (double)(int)((double)*(int *)a2 * v19 + 1.0 / v19 * (double)*v10);
v16 = pow(v19, 4.0);
setTempLED((unsigned int)v11, 114LL, (unsigned int)(int)(v16 * x));
v17 = pow(v19, 4.0);
setTempLED((unsigned int)v11, 103LL, (unsigned int)(int)((double)v15 * v17));
v18 = pow(v19, 4.0);
result = setTempLED((unsigned int)v11, 98LL, (unsigned int)(int)((double)v21 * v18));
}
++v11;
}
while ( v11 != 64 );
}
else
{
for ( j = 0LL; j != 64; ++j )
{
v13 = v23[j];
setTempLED((unsigned int)j, 114LL, (unsigned int)(int)((double)*(int *)a2 * v13));
setTempLED((unsigned int)j, 103LL, (unsigned int)(int)((double)*(int *)(a2 + 4) * v13));
result = setTempLED((unsigned int)j, 98LL, (unsigned int)(int)((double)*(int *)(a2 + 8) * v13));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double *a1, __int64 a2, double a3)
{
unsigned int i; // ebx
double v4; // xmm0_8
double v5; // xmm2_8
char *v6; // rax
int v7; // eax
double v8; // xmm0_8
__int64 result; // rax
int *v10; // r14
__int64 v11; // rbp
__int64 j; // rbx
double v13; // rbp
double v14; // xmm1_8
int v15; // er15
double v16; // xmm0_8
double v17; // xmm1_8
double v18; // xmm1_8
double v19; // rbx
double v20; // [rsp+0h] [rbp-248h]
int v21; // [rsp+0h] [rbp-248h]
double x; // [rsp+8h] [rbp-240h]
double v23[64]; // [rsp+10h] [rbp-238h] BYREF
char v24; // [rsp+210h] [rbp-38h] BYREF

v20 = a1[1];
x = a3 * *a1;
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, 0LL);
setTempLED(i, 103LL, 0LL);
setTempLED(i, 98LL, 0LL);
}
if ( (int)x % 2 == 1 )
v4 = fmod(x, 1.0);
else
v4 = 1.0 - fmod(x, 1.0);
v5 = odd_sin(v4) * 63.0;
v6 = (char *)v23;
do
{
*(_QWORD *)v6 = 0LL;
v6 += 8;
}
while ( v6 != &v24 );
v7 = (int)(v5 - v20);
v8 = (double)v7;
for ( result = v7 + 1; v20 + v5 >= v8; ++result )
{
if ( (unsigned int)(result - 2) <= 0x3E )
{
v14 = v5 - v8;
if ( v5 - v8 <= 0.0 )
v14 = v8 - v5;
*(&x + result) = (v20 - v14) / v20;
}
v8 = (double)(int)result;
}
v10 = *(int **)(a2 + 16);
v11 = 0LL;
if ( v10 )
{
do
{
v19 = v23[v11];
if ( v19 != 0.0 )
{
v15 = (int)((double)v10[1] * (1.0 / v19) + (double)*(int *)(a2 + 4) * v19);
v21 = (int)((double)v10[2] * (1.0 / v19) + (double)*(int *)(a2 + 8) * v19);
x = (double)(int)((double)*(int *)a2 * v19 + 1.0 / v19 * (double)*v10);
v16 = pow(v19, 4.0);
setTempLED((unsigned int)v11, 114LL, (unsigned int)(int)(v16 * x));
v17 = pow(v19, 4.0);
setTempLED((unsigned int)v11, 103LL, (unsigned int)(int)((double)v15 * v17));
v18 = pow(v19, 4.0);
result = setTempLED((unsigned int)v11, 98LL, (unsigned int)(int)((double)v21 * v18));
}
++v11;
}
while ( v11 != 64 );
}
else
{
for ( j = 0LL; j != 64; ++j )
{
v13 = v23[j];
setTempLED((unsigned int)j, 114LL, (unsigned int)(int)((double)*(int *)a2 * v13));
setTempLED((unsigned int)j, 103LL, (unsigned int)(int)((double)*(int *)(a2 + 4) * v13));
result = setTempLED((unsigned int)j, 98LL, (unsigned int)(int)((double)*(int *)(a2 + 8) * v13));
}
}
return result;
}

original_code:
void cylonEye(double *params, double totalTime, odd_led_t *color, double *storage) {
    double speed = params[0];
    double radius = params[1];
    double time = totalTime * speed;
    double center = 0.0;
    int numLeds = (8 * 8) - 1;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', 0);
        setTempLED(i, 'g', 0);
        setTempLED(i, 'b', 0);
    }
    if((int)time % 2 == 1)
        center = fmod(time, 1);
    else
        center = 1 - fmod(time, 1);
    center = odd_sin(center);
    center *= numLeds;
    double ledDistances[(8 * 8)];
    for(int i = 0; i < (8 * 8); i++) ledDistances[i] = 0;
    for(int i = center - radius; i <= center + radius; i++)
    {
        if(i > 0 && i < (8 * 8))
        {
            if(center - i > 0)
                ledDistances[i] = center - i;
            else
                ledDistances[i] = i - center;
            ledDistances[i] =
                    (radius - ledDistances[i]) / radius;
        }
    }
    odd_led_t *color2 = color->next;
    if(color2 == ((void *)0))
    {
        for(int i = 0; i < (8 * 8); i++)
        {
            setTempLED(i, 'r', color->R * ledDistances[i]);
            setTempLED(i, 'g', color->G * ledDistances[i]);
            setTempLED(i, 'b', color->B * ledDistances[i]);
        }
    }
    else
    {
        for(int i = 0; i < (8 * 8); i++)
        {
            if(ledDistances[i] != 0)
            {
                double colorDistance = ledDistances[i];
                odd_led_t colorTemp;
                colorTemp.R = color->R * colorDistance +
                              color2->R * (1 / colorDistance);
                colorTemp.G = color->G * colorDistance +
                              color2->G * (1 / colorDistance);
                colorTemp.B = color->B * colorDistance +
                              color2->B * (1 / colorDistance);
                setTempLED(i, 'r', colorTemp.R * pow(colorDistance, 4));
                setTempLED(i, 'g', colorTemp.G * pow(colorDistance, 4));
                setTempLED(i, 'b', colorTemp.B * pow(colorDistance, 4));
            }
        }
    }
}

canonical_original_code:
void cylonEye(double *params, double totalTime, struct odd_led_t *color, double *storage) {
    double speed = params[0];
    double radius = params[1];
    double time = totalTime * speed;
    double center = 0.0;
    int numLeds = (8 * 8) - 1;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', 0);
        setTempLED(i, 'g', 0);
        setTempLED(i, 'b', 0);
    }
    if((int)time % 2 == 1)
        center = fmod(time, 1);
    else
        center = 1 - fmod(time, 1);
    center = odd_sin(center);
    center *= numLeds;
    double ledDistances[-1];
    for(int i = 0; i < (8 * 8); i++) ledDistances[i] = 0;
    for(int i = center - radius; i <= center + radius; i++)
    {
        if(i > 0 && i < (8 * 8))
        {
            if(center - i > 0)
                ledDistances[i] = center - i;
            else
                ledDistances[i] = i - center;
            ledDistances[i] =
                    (radius - ledDistances[i]) / radius;
        }
    }
    struct odd_led_t *color2 = color->next;
    if(color2 == ((void *)0))
    {
        for(int i = 0; i < (8 * 8); i++)
        {
            setTempLED(i, 'r', color->R * ledDistances[i]);
            setTempLED(i, 'g', color->G * ledDistances[i]);
            setTempLED(i, 'b', color->B * ledDistances[i]);
        }
    }
    else
    {
        for(int i = 0; i < (8 * 8); i++)
        {
            if(ledDistances[i] != 0)
            {
                double colorDistance = ledDistances[i];
                struct odd_led_t colorTemp;
                colorTemp.R = color->R * colorDistance +
                              color2->R * (1 / colorDistance);
                colorTemp.G = color->G * colorDistance +
                              color2->G * (1 / colorDistance);
                colorTemp.B = color->B * colorDistance +
                              color2->B * (1 / colorDistance);
                setTempLED(i, 'r', colorTemp.R * pow(colorDistance, 4));
                setTempLED(i, 'g', colorTemp.G * pow(colorDistance, 4));
                setTempLED(i, 'b', colorTemp.B * pow(colorDistance, 4));
            }
        }
    }
}

variable_types: speed double

variable_types: time double

variable_types: center double


decompiled_code:
void __fastcall odd_pow(double a1, double a2)
{
if ( a2 > 0.0 )
odd_pow(a1, a2 - 1.0);
}

canonical_decompiled_code:
void __fastcall func0(double a1, double a2)
{
if ( a2 > 0.0 )
func0(a1, a2 - 1.0);
}

original_code:
double odd_pow(double x, double y)
{
 if(y > 0)
  return odd_pow(x, y - 1) * x;
 else
  return 1.0;
}

variable_types: x double

variable_types: y double

return_type: double


decompiled_code:
float __fastcall hann_window(int a1, int a2)
{
return (1.0 - cos((double)a1 * 6.283185306 / (double)(a2 - 1))) * 0.5;
}

canonical_decompiled_code:
float __fastcall func2(int a1, int a2)
{
return (1.0 - cos((double)a1 * 6.283185306 / (double)(a2 - 1))) * 0.5;
}

original_code:
float hann_window(int sample, int num_samples)
{
    return 0.5 * (1 - cos((2 * 3.141592653 * sample) / (num_samples - 1)));
}

variable_types: sample int

return_type: float


formatTime

original_code:
double formatTime(long int seconds, long int useconds)
{
 long double time = seconds % 10000 + (useconds - useconds % 1000) / 1000000.0;
 if(time > 100000)
  time = fmod(time, 100000);
 return time;
}

canonical_original_code:
double formatTime(long seconds, long useconds)
{
 long double time = seconds % 10000 + (useconds - useconds % 1000) / 1000000.0;
 if(time > 100000)
  time = fmod(time, 100000);
 return time;
}

variable_types: seconds long

variable_types: useconds long

variable_types:
time
long double


rain

decompiled_code:
__int64 __fastcall rain(double *a1, int *a2, double a3)
{
unsigned int i; // ebx
int v4; // ebx
int v5; // er13
__int64 j; // rbx
double v7; // rbp
__int64 result; // rax
double v9; // [rsp+8h] [rbp-240h]
double v10; // [rsp+10h] [rbp-238h]
double v11; // [rsp+18h] [rbp-230h]
double v12[69]; // [rsp+20h] [rbp-228h] BYREF

v10 = a1[2];
v11 = a3 * *a1;
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, 0LL);
setTempLED(i, 103LL, 0LL);
setTempLED(i, 98LL, 0LL);
}
memset(v12, 0, 0x200uLL);
v9 = (double)(int)v10;
if ( v10 > v9 )
v9 = (double)(int)v10 + 1.0;
v4 = 0;
if ( v9 > 0.0 )
{
v5 = (int)v11;
do
{
srand(v5 - v4);
v12[(int)((double)rand() / 2147483647.0 * 63.0)] = 1.0 - (v11 - (double)(v5 - v4++)) / v10;
}
while ( v9 > (double)v4 );
}
for ( j = 0LL; j != 64; ++j )
{
v7 = v12[j];
setTempLED((unsigned int)j, 114LL, (unsigned int)(int)((double)*a2 * v7));
setTempLED((unsigned int)j, 103LL, (unsigned int)(int)((double)a2[1] * v7));
result = setTempLED((unsigned int)j, 98LL, (unsigned int)(int)((double)a2[2] * v7));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double *a1, int *a2, double a3)
{
unsigned int i; // ebx
int v4; // ebx
int v5; // er13
__int64 j; // rbx
double v7; // rbp
__int64 result; // rax
double v9; // [rsp+8h] [rbp-240h]
double v10; // [rsp+10h] [rbp-238h]
double v11; // [rsp+18h] [rbp-230h]
double v12[69]; // [rsp+20h] [rbp-228h] BYREF

v10 = a1[2];
v11 = a3 * *a1;
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, 0LL);
setTempLED(i, 103LL, 0LL);
setTempLED(i, 98LL, 0LL);
}
memset(v12, 0, 0x200uLL);
v9 = (double)(int)v10;
if ( v10 > v9 )
v9 = (double)(int)v10 + 1.0;
v4 = 0;
if ( v9 > 0.0 )
{
v5 = (int)v11;
do
{
srand(v5 - v4);
v12[(int)((double)rand() / 2147483647.0 * 63.0)] = 1.0 - (v11 - (double)(v5 - v4++)) / v10;
}
while ( v9 > (double)v4 );
}
for ( j = 0LL; j != 64; ++j )
{
v7 = v12[j];
setTempLED((unsigned int)j, 114LL, (unsigned int)(int)((double)*a2 * v7));
setTempLED((unsigned int)j, 103LL, (unsigned int)(int)((double)a2[1] * v7));
result = setTempLED((unsigned int)j, 98LL, (unsigned int)(int)((double)a2[2] * v7));
}
return result;
}

original_code:
void rain(double *params, double totalTime, odd_led_t *color, double *storage)
{
    double frequency = params[0];
    double strength = params[1];
    double speed = params[2];
    double time = totalTime * frequency;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', 0);
        setTempLED(i, 'g', 0);
        setTempLED(i, 'b', 0);
    }
    double leds[(8 * 8)];
    memset(leds, 0, sizeof(double) * (8 * 8));
    double numDrops = (int)speed;
    if(numDrops < speed)
        numDrops++;
    for(int i = 0; i < numDrops; i++) {
        srand((int)time - i);
        double locationDou = rand() * 1.0 / 2147483647;
        int location = locationDou * ((8 * 8) - 1);
        double progress = (time - ((int)time - i)) / speed;
        leds[location] = 1 - progress;
        double wavePoint = locationDou + (0.1 * progress);
    }
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R * leds[i]);
        setTempLED(i, 'g', color->G * leds[i]);
        setTempLED(i, 'b', color->B * leds[i]);
    }
}

canonical_original_code:
void rain(double *params, double totalTime, struct odd_led_t *color, double *storage)
{
    double frequency = params[0];
    double strength = params[1];
    double speed = params[2];
    double time = totalTime * frequency;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', 0);
        setTempLED(i, 'g', 0);
        setTempLED(i, 'b', 0);
    }
    double leds[-1];
    memset(leds, 0, sizeof(double) * (8 * 8));
    double numDrops = (int)speed;
    if(numDrops < speed)
        numDrops++;
    for(int i = 0; i < numDrops; i++) {
        srand((int)time - i);
        double locationDou = rand() * 1.0 / 2147483647;
        int location = locationDou * ((8 * 8) - 1);
        double progress = (time - ((int)time - i)) / speed;
        leds[location] = 1 - progress;
        double wavePoint = locationDou + (0.1 * progress);
    }
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R * leds[i]);
        setTempLED(i, 'g', color->G * leds[i]);
        setTempLED(i, 'b', color->B * leds[i]);
    }
}

variable_types:
params
double *

variable_types: totalTime double

variable_types: struct odd_led_t { int R; int G; int B; struct odd_led_t *next; } *

variable_types:
storage
double *

variable_types: frequency double

variable_types: strength double

variable_types:
leds
double [-1]

variable_types: numDrops double

variable_types: locationDou double

variable_types: location int

variable_types: progress double

variable_types: wavePoint double


dammitAnimation

original_code:
void dammitAnimation(double *params, double totalTime, odd_led_t *color, double *storage)
{
    (void)params;
    SAMPLE soundBuffer[(1024)];
    memset(soundBuffer, 0, sizeof(*soundBuffer) * (1024));
    runFFT(soundBuffer);
    SAMPLE ledSums[(8 * 8)];
    memset(ledSums, 0, sizeof(*ledSums) * (8 * 8));
    for(int i = 0; i < (8 * 8) / 2; i++)
    {
        int low = pow(i + 1.0, 2) / pow((8 * 8) / 2.0, 2) * 160;
        int high = pow(i + 2.0, 2) / pow((8 * 8) / 2.0, 2) * 160;
        if(low == high)
            high++;
        for(int j = low; j < high; j++)
        {
            ledSums[i] += soundBuffer[j];
        }
        ledSums[i] /= 1000;
        if(ledSums[i] > 1)
            printf("%f\n", ledSums[i]);
        ledSums[i] = pow(ledSums[i], 2);
        ledSums[i] *= (logf(i + 15) / logf((8 * 8) + 15)) * 66;
    }
    if(color->next == ((void *)0))
        for(int i = 0; i < (8 * 8) / 2; i++)
        {
            setTempLED((8 * 8) / 2 - i - 1, 'r', ledSums[i] * color->R);
            setTempLED((8 * 8) / 2 - i - 1, 'g', ledSums[i] * color->G);
            setTempLED((8 * 8) / 2 - i - 1, 'b', ledSums[i] * color->B);
            setTempLED((8 * 8) / 2 + i, 'r', ledSums[i] * color->R);
            setTempLED((8 * 8) / 2 + i, 'g', ledSums[i] * color->G);
            setTempLED((8 * 8) / 2 + i, 'b', ledSums[i] * color->B);
        }
    else
        for(int i = 0; i < (8 * 8) / 2; i++)
        {
            float position = (i+0.0001) / ((8 * 8) / 2);
            int redChannel = color->R * position + color->next->R * (1 - position);
            int greenChannel = color->G * position + color->next->G * (1 - position);
            int blueChannel = color->B * position + color->next->B * (1 - position);
            setTempLED((8 * 8) / 2 - i - 1, 'r', ledSums[i] * redChannel);
            setTempLED((8 * 8) / 2 - i - 1, 'g', ledSums[i] * greenChannel);
            setTempLED((8 * 8) / 2 - i - 1, 'b', ledSums[i] * blueChannel);
            setTempLED((8 * 8) / 2 + i, 'r', ledSums[i] * redChannel);
            setTempLED((8 * 8) / 2 + i, 'g', ledSums[i] * greenChannel);
            setTempLED((8 * 8) / 2 + i, 'b', ledSums[i] * blueChannel);
        }
}

canonical_original_code:
void dammitAnimation(double *params, double totalTime, struct odd_led_t *color, double *storage)
{
    (void)params;
    float soundBuffer[-1];
    memset(soundBuffer, 0, sizeof(*soundBuffer) * (1024));
    runFFT(soundBuffer);
    float ledSums[-1];
    memset(ledSums, 0, sizeof(*ledSums) * (8 * 8));
    for(int i = 0; i < (8 * 8) / 2; i++)
    {
        int low = pow(i + 1.0, 2) / pow((8 * 8) / 2.0, 2) * 160;
        int high = pow(i + 2.0, 2) / pow((8 * 8) / 2.0, 2) * 160;
        if(low == high)
            high++;
        for(int j = low; j < high; j++)
        {
            ledSums[i] += soundBuffer[j];
        }
        ledSums[i] /= 1000;
        if(ledSums[i] > 1)
            printf("%f\n", ledSums[i]);
        ledSums[i] = pow(ledSums[i], 2);
        ledSums[i] *= (logf(i + 15) / logf((8 * 8) + 15)) * 66;
    }
    if(color->next == ((void *)0))
        for(int i = 0; i < (8 * 8) / 2; i++)
        {
            setTempLED((8 * 8) / 2 - i - 1, 'r', ledSums[i] * color->R);
            setTempLED((8 * 8) / 2 - i - 1, 'g', ledSums[i] * color->G);
            setTempLED((8 * 8) / 2 - i - 1, 'b', ledSums[i] * color->B);
            setTempLED((8 * 8) / 2 + i, 'r', ledSums[i] * color->R);
            setTempLED((8 * 8) / 2 + i, 'g', ledSums[i] * color->G);
            setTempLED((8 * 8) / 2 + i, 'b', ledSums[i] * color->B);
        }
    else
        for(int i = 0; i < (8 * 8) / 2; i++)
        {
            float position = (i+0.0001) / ((8 * 8) / 2);
            int redChannel = color->R * position + color->next->R * (1 - position);
            int greenChannel = color->G * position + color->next->G * (1 - position);
            int blueChannel = color->B * position + color->next->B * (1 - position);
            setTempLED((8 * 8) / 2 - i - 1, 'r', ledSums[i] * redChannel);
            setTempLED((8 * 8) / 2 - i - 1, 'g', ledSums[i] * greenChannel);
            setTempLED((8 * 8) / 2 - i - 1, 'b', ledSums[i] * blueChannel);
            setTempLED((8 * 8) / 2 + i, 'r', ledSums[i] * redChannel);
            setTempLED((8 * 8) / 2 + i, 'g', ledSums[i] * greenChannel);
            setTempLED((8 * 8) / 2 + i, 'b', ledSums[i] * blueChannel);
        }
}

variable_types:
soundBuffer
float [-1]

variable_types:
ledSums
float [-1]

variable_types: i int

variable_types: low int

variable_types: high int

variable_types: j int

variable_types: position float

variable_types: redChannel int

variable_types: greenChannel int

variable_types: blueChannel int


setAll

decompiled_code:
__int64 __fastcall setAll(__int64 a1, unsigned int *a2)
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, *a2);
setTempLED(i, 103LL, a2[1]);
result = setTempLED(i, 98LL, a2[2]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int *a2)
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, *a2);
setTempLED(i, 103LL, a2[1]);
result = setTempLED(i, 98LL, a2[2]);
}
return result;
}

original_code:
void setAll(double *params, double totalTime, odd_led_t *color, double *storage)
{
    (void)params;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R);
        setTempLED(i, 'g', color->G);
        setTempLED(i, 'b', color->B);
    }
}

canonical_original_code:
void setAll(double *params, double totalTime, struct odd_led_t *color, double *storage)
{
    (void)params;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R);
        setTempLED(i, 'g', color->G);
        setTempLED(i, 'b', color->B);
    }
}

variable_types:
params
double *

variable_types: totalTime double

variable_types: struct odd_led_t { int R; int G; int B; struct odd_led_t *next; } *

variable_types:
storage
double *


decompiled_code:
void __fastcall volumeAnimation2(__int64 a1, int *a2, double *a3)
{
float v4; // xmm5_4
unsigned int v5; // ebx
unsigned int v6; // ebx
float v7; // [rsp+8h] [rbp-20h]
float v8; // [rsp+Ch] [rbp-1Ch]

v7 = getAvgVolume();
if ( *a3 > v7 )
{
v4 = (v7 + *a3) * 0.5;
v7 = v4;
}
v8 = v7 * 64.0;
v5 = 0;
if ( (float)(v7 * 64.0) > 0.0 )
{
do
{
setTempLED(v5, 114LL, (unsigned int)(int)(float)((float)*a2 * v7));
setTempLED(v5, 103LL, (unsigned int)(int)(float)((float)a2[1] * v7));
setTempLED(v5++, 98LL, (unsigned int)(int)(float)((float)a2[2] * v7));
}
while ( v8 > (float)(int)v5 );
}
v6 = (int)v8;
if ( (int)v8 <= 63 )
{
do
{
setTempLED(v6, 114LL, 0LL);
setTempLED(v6, 103LL, 0LL);
setTempLED(v6++, 98LL, 0LL);
}
while ( v6 != 64 );
}
*a3 = v7;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int *a2, double *a3)
{
float v4; // xmm5_4
unsigned int v5; // ebx
unsigned int v6; // ebx
float v7; // [rsp+8h] [rbp-20h]
float v8; // [rsp+Ch] [rbp-1Ch]

v7 = getAvgVolume();
if ( *a3 > v7 )
{
v4 = (v7 + *a3) * 0.5;
v7 = v4;
}
v8 = v7 * 64.0;
v5 = 0;
if ( (float)(v7 * 64.0) > 0.0 )
{
do
{
setTempLED(v5, 114LL, (unsigned int)(int)(float)((float)*a2 * v7));
setTempLED(v5, 103LL, (unsigned int)(int)(float)((float)a2[1] * v7));
setTempLED(v5++, 98LL, (unsigned int)(int)(float)((float)a2[2] * v7));
}
while ( v8 > (float)(int)v5 );
}
v6 = (int)v8;
if ( (int)v8 <= 63 )
{
do
{
setTempLED(v6, 114LL, 0LL);
setTempLED(v6, 103LL, 0LL);
setTempLED(v6++, 98LL, 0LL);
}
while ( v6 != 64 );
}
*a3 = v7;
}

original_code:
void volumeAnimation2(double *params, double totalTime, odd_led_t *color, double *lastAvg)
{
    (void)params;
    (void)totalTime;
    SAMPLE avg = getAvgVolume();
    if(avg < *lastAvg)
        avg = (avg + *lastAvg) / 2;
    for(int i = 0; i < avg * (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R * avg);
        setTempLED(i, 'g', color->G * avg);
        setTempLED(i, 'b', color->B * avg);
    }
    for(int i = avg * (8 * 8); i < (8 * 8); i++)
    {
        setTempLED(i, 'r', 0);
        setTempLED(i, 'g', 0);
        setTempLED(i, 'b', 0);
    }
    *lastAvg = avg;
}

canonical_original_code:
void volumeAnimation2(double *params, double totalTime, struct odd_led_t *color, double *lastAvg)
{
    (void)params;
    (void)totalTime;
    float avg = getAvgVolume();
    if(avg < *lastAvg)
        avg = (avg + *lastAvg) / 2;
    for(int i = 0; i < avg * (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R * avg);
        setTempLED(i, 'g', color->G * avg);
        setTempLED(i, 'b', color->B * avg);
    }
    for(int i = avg * (8 * 8); i < (8 * 8); i++)
    {
        setTempLED(i, 'r', 0);
        setTempLED(i, 'g', 0);
        setTempLED(i, 'b', 0);
    }
    *lastAvg = avg;
}

variable_types:
lastAvg
double *

variable_types: avg float


strobe

decompiled_code:
__int64 __fastcall strobe(double *a1, int *a2, double a3)
{
unsigned int i; // ebx
__int64 result; // rax
double v5; // [rsp+8h] [rbp-20h]

v5 = 0.0;
if ( (int)(a3 * *a1) % 2 == 1 )
v5 = *(double *)&LC1;
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, (unsigned int)(int)((double)*a2 * v5));
setTempLED(i, 103LL, (unsigned int)(int)((double)a2[1] * v5));
result = setTempLED(i, 98LL, (unsigned int)(int)((double)a2[2] * v5));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double *a1, int *a2, double a3)
{
unsigned int i; // ebx
__int64 result; // rax
double v5; // [rsp+8h] [rbp-20h]

v5 = 0.0;
if ( (int)(a3 * *a1) % 2 == 1 )
v5 = *(double *)&LC1;
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, (unsigned int)(int)((double)*a2 * v5));
setTempLED(i, 103LL, (unsigned int)(int)((double)a2[1] * v5));
result = setTempLED(i, 98LL, (unsigned int)(int)((double)a2[2] * v5));
}
return result;
}

original_code:
void strobe(double *params, double totalTime, odd_led_t *color, double *storage)
{
    double speed = params[0];
    double time = totalTime * speed;
    double power = 0;
    if((int)time % 2 == 1)
        power = 1;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R * power);
        setTempLED(i, 'g', color->G * power);
        setTempLED(i, 'b', color->B * power);
    }
}

canonical_original_code:
void strobe(double *params, double totalTime, struct odd_led_t *color, double *storage)
{
    double speed = params[0];
    double time = totalTime * speed;
    double power = 0;
    if((int)time % 2 == 1)
        power = 1;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R * power);
        setTempLED(i, 'g', color->G * power);
        setTempLED(i, 'b', color->B * power);
    }
}

variable_types: speed double

variable_types: time double

variable_types: power double


decompiled_code:
int *__fastcall volumeAnimation5(__int64 a1, __int64 a2, double *a3)
{
char *v4; // rax
float v5; // xmm1_4
float v6; // xmm0_4
float v7; // xmm6_4
float v8; // xmm7_4
int v9; // er15
int v10; // er14
unsigned int v11; // er13
unsigned int j; // ebx
int *result; // rax
int v14; // ebx
unsigned int v15; // er15
unsigned int v16; // er14
float i; // [rsp+8h] [rbp-2040h]
float v18; // [rsp+Ch] [rbp-203Ch]
int v19[1024]; // [rsp+10h] [rbp-2038h] BYREF
char v20[4096]; // [rsp+1010h] [rbp-1038h] BYREF
char v21; // [rsp+2010h] [rbp-38h] BYREF

getSoundBuffer(v20);
runFFT(v19);
v4 = v20;
v5 = 0.0;
do
{
v6 = *(float *)v4;
if ( *(float *)v4 <= 0.0 )
v5 = v5 - v6;
else
v5 = v5 + v6;
v4 += 4;
}
while ( v4 != &v21 );
v7 = log((float)((float)((float)(v5 * 0.0009765625) * 100.0) + 1.0)) / 4.61512051684126;
v18 = v7;
for ( i = (float)((float)((float)((float)(*(float *)v19 + 0.0) + *(float *)&v19[1]) + *(float *)&v19[2])
+ *(float *)&v19[3])
/ 300.0; i > 1.0; i = i - 1.0 )
puts("bassfuck");
if ( *a3 > v7 )
{
v8 = (v7 + *a3) * 0.5;
v18 = v8;
}
v9 = (int)(float)(v18 * 64.0);
v10 = (64 - v9) / 2;
v11 = v10;
for ( j = 0; j != 64; ++j )
{
setTempLED(j, 114LL, 0LL);
setTempLED(j, 103LL, 0LL);
result = (int *)setTempLED(j, 98LL, 0LL);
}
v14 = v9 + v10;
if ( v10 < v9 + v10 )
{
do
{
result = *(int **)(a2 + 16);
if ( result )
{
v15 = (int)(float)((float)((float)result[1] * i) + (float)((float)((float)*(int *)(a2 + 4) * v18) / i));
v16 = (int)(float)((float)((float)result[2] * i) + (float)((float)((float)*(int *)(a2 + 8) * v18) / i));
setTempLED(
v11,
114LL,
(unsigned int)(int)(float)((float)((float)*result * i) + (float)((float)((float)*(int *)a2 * v18) / i)));
setTempLED(v11, 103LL, v15);
result = (int *)setTempLED(v11, 98LL, v16);
}
++v11;
}
while ( v11 != v14 );
}
*a3 = v18;
return result;
}

original_code:
void volumeAnimation5(double *params, double totalTime, odd_led_t *color, double *lastAvg)
{
    (void)params;
    (void)totalTime;
    SAMPLE avg = 0;
    SAMPLE bassAvg = 0;
    SAMPLE soundBuffer[(1024)];
    getSoundBuffer(soundBuffer);
    SAMPLE fftOutput[(1024)];
    runFFT(fftOutput);
    for(int i = 0; i < (1024); i++)
    {
        if(soundBuffer[i] > 0)
            avg += soundBuffer[i];
        else
            avg -= soundBuffer[i];
    }
    avg /= (1024);
    avg *= 100;
    avg = log(avg + 1) / log(101);
    for(int i = 0; i < 4; i++)
    {
        bassAvg += fftOutput[i];
    }
    bassAvg /= 300;
    while(bassAvg > 1)
    {
        printf("bassfuck\n");
        bassAvg -= 1;
    }
    if(avg < *lastAvg)
        avg = (avg + *lastAvg) / 2;
    int width = (int)(avg * (8 * 8));
    int gap = (int)(((8 * 8) - width) / 2);
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i,'r', 0);
        setTempLED(i,'g', 0);
        setTempLED(i,'b', 0);
    }
    for(int i = gap; i < gap+width; i++)
    {
        if(color->next != ((void *)0)) {
            int rVal = color->R * avg * 1 / bassAvg + color->next->R * bassAvg;
            int gVal = color->G * avg * 1 / bassAvg + color->next->G * bassAvg;
            int bVal = color->B * avg * 1 / bassAvg + color->next->B * bassAvg;
            setTempLED(i,'r', rVal);
            setTempLED(i,'g', gVal);
            setTempLED(i,'b', bVal);
        }
    }
    *lastAvg = avg;
}

canonical_original_code:
void volumeAnimation5(double *params, double totalTime, struct odd_led_t *color, double *lastAvg)
{
    (void)params;
    (void)totalTime;
    float avg = 0;
    float bassAvg = 0;
    float soundBuffer[-1];
    getSoundBuffer(soundBuffer);
    float fftOutput[-1];
    runFFT(fftOutput);
    for(int i = 0; i < (1024); i++)
    {
        if(soundBuffer[i] > 0)
            avg += soundBuffer[i];
        else
            avg -= soundBuffer[i];
    }
    avg /= (1024);
    avg *= 100;
    avg = log(avg + 1) / log(101);
    for(int i = 0; i < 4; i++)
    {
        bassAvg += fftOutput[i];
    }
    bassAvg /= 300;
    while(bassAvg > 1)
    {
        printf("bassfuck\n");
        bassAvg -= 1;
    }
    if(avg < *lastAvg)
        avg = (avg + *lastAvg) / 2;
    int width = (int)(avg * (8 * 8));
    int gap = (int)(((8 * 8) - width) / 2);
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i,'r', 0);
        setTempLED(i,'g', 0);
        setTempLED(i,'b', 0);
    }
    for(int i = gap; i < gap+width; i++)
    {
        if(color->next != ((void *)0)) {
            int rVal = color->R * avg * 1 / bassAvg + color->next->R * bassAvg;
            int gVal = color->G * avg * 1 / bassAvg + color->next->G * bassAvg;
            int bVal = color->B * avg * 1 / bassAvg + color->next->B * bassAvg;
            setTempLED(i,'r', rVal);
            setTempLED(i,'g', gVal);
            setTempLED(i,'b', bVal);
        }
    }
    *lastAvg = avg;
}

variable_types: bassAvg float

variable_types:
soundBuffer
float [-1]

variable_types:
fftOutput
float [-1]

variable_types: i int

variable_types: width int

variable_types: gap int

variable_types: rVal int

variable_types: gVal int

variable_types: bVal int


sinAnimation

decompiled_code:
__int64 __fastcall sinAnimation(double *a1, int *a2, double a3)
{
double v3; // xmm0_8
double v4; // xmm0_8
unsigned int i; // ebx
__int64 result; // rax
double v7; // [rsp+8h] [rbp-20h]

v3 = a3 * *a1;
if ( (int)v3 % 2 == 1 )
v4 = fmod(v3, 1.0);
else
v4 = 1.0 - fmod(v3, 1.0);
v7 = odd_sin(v4);
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, (unsigned int)(int)((double)*a2 * v7));
setTempLED(i, 103LL, (unsigned int)(int)((double)a2[1] * v7));
result = setTempLED(i, 98LL, (unsigned int)(int)((double)a2[2] * v7));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double *a1, int *a2, double a3)
{
double v3; // xmm0_8
double v4; // xmm0_8
unsigned int i; // ebx
__int64 result; // rax
double v7; // [rsp+8h] [rbp-20h]

v3 = a3 * *a1;
if ( (int)v3 % 2 == 1 )
v4 = fmod(v3, 1.0);
else
v4 = 1.0 - fmod(v3, 1.0);
v7 = odd_sin(v4);
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, (unsigned int)(int)((double)*a2 * v7));
setTempLED(i, 103LL, (unsigned int)(int)((double)a2[1] * v7));
result = setTempLED(i, 98LL, (unsigned int)(int)((double)a2[2] * v7));
}
return result;
}

original_code:
void sinAnimation(double *params, double totalTime, odd_led_t *color, double *storage)
{
    double speed = params[0];
    double time = totalTime * speed;
    double power = 0;
    if((int)time % 2 == 1)
        power = fmod(time, 1);
    else
        power = 1 - fmod(time, 1);
    power = odd_sin(power);
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R * power);
        setTempLED(i, 'g', color->G * power);
        setTempLED(i, 'b', color->B * power);
    }
}

canonical_original_code:
void sinAnimation(double *params, double totalTime, struct odd_led_t *color, double *storage)
{
    double speed = params[0];
    double time = totalTime * speed;
    double power = 0;
    if((int)time % 2 == 1)
        power = fmod(time, 1);
    else
        power = 1 - fmod(time, 1);
    power = odd_sin(power);
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R * power);
        setTempLED(i, 'g', color->G * power);
        setTempLED(i, 'b', color->B * power);
    }
}

variable_types:
params
double *

variable_types: totalTime double


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

result = a1;
if ( a1 )
{
if ( *(_QWORD *)(a1 + 8) != -1LL )
_InterlockedAdd64((volatile signed __int64 *)(a1 + 8), 1uLL);
}
return result;
}

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

result = a1;
if ( a1 )
{
if ( *(_QWORD *)(a1 + 8) != -1LL )
_InterlockedAdd64((volatile signed __int64 *)(a1 + 8), 1uLL);
}
return result;
}

original_code:
static inline
json_t *json_incref(json_t *json)
{
    if(json && json->refcount != (size_t)-1)
        __atomic_add_fetch(&json->refcount, 1, 2);
    return json;
}

canonical_original_code:
static inline struct json_t *json_incref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1)
        __atomic_add_fetch(&json->refcount, 1, 2);
    return json;
}

variable_types:
json
struct json_t *

return_type: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *

user_defined_types: struct json_t { enum json_type type; unsigned long refcount; }


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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

original_code:
static inline
void json_decref(json_t *json)
{
    if(json && json->refcount != (size_t)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

canonical_original_code:
static inline void json_decref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

variable_types: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *


networkListen

decompiled_code:
void __noreturn networkListen()
{
int v0; // eax
int v1; // ebp
unsigned int v2; // er12
int v3; // ebx
_DWORD *v4; // rax
pthread_t v5; // [rsp+0h] [rbp-48h] BYREF
int optval; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

thread_test();
animation_list_c = 15;
puts("Starting socket");
v0 = socket(2, 1, 0);
if ( v0 >= 0 )
{
v1 = v0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr("0.0.0.0");
*(_WORD *)addr.sa_data = _bswap_16(10001);
optval = 1;
if ( setsockopt(v1, 1, 2, &optval, 4u) != -1 )
{
puts("Binding to socket");
if ( bind(v1, &addr, 0x10u) >= 0 )
{
puts("Setting socket to listen");
v2 = 0;
if ( listen(v1, 1024) >= 0 )
{
while ( 1 )
{
puts("Accepting on socket");
v3 = accept(v1, 0LL, 0LL);
if ( v3 < 0 )
break;
printf("New connection: %d\n", v2);
v4 = malloc(4uLL);
*v4 = v3;
if ( pthread_create(&v5, 0LL, handleConnection, v4) )
{
perror("pthread_create");
exit(1);
}
++v2;
}
perror("accept");
exit(1);
}
puts("Error calling listen");
exit(1);
}
puts("Error calling bind");
exit(1);
}
puts("Error setting socket options");
exit(1);
}
puts("Error making listening socket");
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
int v0; // eax
int v1; // ebp
unsigned int v2; // er12
int v3; // ebx
_DWORD *v4; // rax
pthread_t v5; // [rsp+0h] [rbp-48h] BYREF
int optval; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

thread_test();
animation_list_c = 15;
puts("Starting socket");
v0 = socket(2, 1, 0);
if ( v0 >= 0 )
{
v1 = v0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr("0.0.0.0");
*(_WORD *)addr.sa_data = func0(10001);
optval = 1;
if ( setsockopt(v1, 1, 2, &optval, 4u) != -1 )
{
puts("Binding to socket");
if ( bind(v1, &addr, 0x10u) >= 0 )
{
puts("Setting socket to listen");
v2 = 0;
if ( listen(v1, 1024) >= 0 )
{
while ( 1 )
{
puts("Accepting on socket");
v3 = accept(v1, 0LL, 0LL);
if ( v3 < 0 )
break;
printf("New connection: %d\n", v2);
v4 = malloc(4uLL);
*v4 = v3;
if ( pthread_create(&v5, 0LL, handleConnection, v4) )
{
perror("pthread_create");
exit(1);
}
++v2;
}
perror("accept");
exit(1);
}
puts("Error calling listen");
exit(1);
}
puts("Error calling bind");
exit(1);
}
puts("Error setting socket options");
exit(1);
}
puts("Error making listening socket");
exit(1);
}

original_code:
void *networkListen()
{
    thread_test();
animation_list_c = 0;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
    int list_s;
    int conn_s;
    short int port = 10001;
    struct sockaddr_in servaddr;
    printf("Starting socket\n");
    if((list_s = socket(2, SOCK_STREAM, 0)) < 0)
    {
        printf("Error making listening socket\n");
        exit(1);
    }
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = inet_addr("0.0.0.0");
    servaddr.sin_port = htons(port);
    int yes = 1;
    if(setsockopt(list_s, 1, 2, &yes, sizeof(int)) == -1)
    {
        printf("Error setting socket options\n");
        exit(1);
    }
    printf("Binding to socket\n");
    if(bind(list_s, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0)
    {
        printf("Error calling bind\n");
        exit(1);
    }
    printf("Setting socket to listen\n");
    if(listen(list_s, (1024)) < 0)
    {
        printf("Error calling listen\n");
        exit(1);
    }
    int counter = 0;
    while(1)
    {
        printf("Accepting on socket\n");
        if((conn_s = accept(list_s, ((void *)0), ((void *)0))) < 0)
        {
            perror("accept");
            exit(1);
        }
        printf("New connection: %d\n", counter++);
        pthread_t handler;
        int *num = malloc(sizeof(int));
        *num = conn_s;
        int err = pthread_create(&handler,((void *)0),handleConnection,num);
        if(err != 0)
        {
            perror("pthread_create");
            exit(1);
        }
    }
}

canonical_original_code:
void *networkListen()
{
    thread_test();
animation_list_c = 0;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
animation_list_c++;
    int list_s;
    int conn_s;
    short port = 10001;
    struct sockaddr_in servaddr;
    printf("Starting socket\n");
    if((list_s = socket(2, SOCK_STREAM, 0)) < 0)
    {
        printf("Error making listening socket\n");
        exit(1);
    }
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = inet_addr("0.0.0.0");
    servaddr.sin_port = htons(port);
    int yes = 1;
    if(setsockopt(list_s, 1, 2, &yes, sizeof(int)) == -1)
    {
        printf("Error setting socket options\n");
        exit(1);
    }
    printf("Binding to socket\n");
    if(bind(list_s, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0)
    {
        printf("Error calling bind\n");
        exit(1);
    }
    printf("Setting socket to listen\n");
    if(listen(list_s, (1024)) < 0)
    {
        printf("Error calling listen\n");
        exit(1);
    }
    int counter = 0;
    while(1)
    {
        printf("Accepting on socket\n");
        if((conn_s = accept(list_s, ((void *)0), ((void *)0))) < 0)
        {
            perror("accept");
            exit(1);
        }
        printf("New connection: %d\n", counter++);
        unsigned long handler;
        int *num = malloc(sizeof(int));
        *num = conn_s;
        int err = pthread_create(&handler,((void *)0),handleConnection,num);
        if(err != 0)
        {
            perror("pthread_create");
            exit(1);
        }
    }
}

variable_types: port short

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

variable_types: yes int

variable_types: counter int

variable_types:
handler
unsigned long

variable_types:
num
int *

variable_types: err int

return_type: void *

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

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


getAvgVolume

original_code:
float getAvgVolume()
{
    SAMPLE avg = 0;
    SAMPLE soundBuffer[(1024)];
    getSoundBuffer(soundBuffer);
    for(int i = 0; i < (1024); i++)
    {
        if(soundBuffer[i] > 0)
            avg += soundBuffer[i];
        else
            avg -= soundBuffer[i];
    }
    avg /= (1024);
    avg *= 100;
    avg = log(avg + 1) / log(101);
    return avg;
}

canonical_original_code:
float getAvgVolume()
{
    float avg = 0;
    float soundBuffer[-1];
    getSoundBuffer(soundBuffer);
    for(int i = 0; i < (1024); i++)
    {
        if(soundBuffer[i] > 0)
            avg += soundBuffer[i];
        else
            avg -= soundBuffer[i];
    }
    avg /= (1024);
    avg *= 100;
    avg = log(avg + 1) / log(101);
    return avg;
}

variable_types: avg float

variable_types:
soundBuffer
float [-1]

variable_types: i int


decompiled_code:
__int64 __fastcall volumeAnimation1(__int64 a1, int *a2, double *a3)
{
float v4; // xmm3_4
unsigned int i; // ebx
__int64 result; // rax
float v7; // [rsp+Ch] [rbp-1Ch]

v7 = getAvgVolume();
if ( *a3 > v7 )
{
v4 = (v7 + *a3) * 0.5;
v7 = v4;
}
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, (unsigned int)(int)(float)((float)*a2 * v7));
setTempLED(i, 103LL, (unsigned int)(int)(float)((float)a2[1] * v7));
result = setTempLED(i, 98LL, (unsigned int)(int)(float)((float)a2[2] * v7));
}
*a3 = v7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int *a2, double *a3)
{
float v4; // xmm3_4
unsigned int i; // ebx
__int64 result; // rax
float v7; // [rsp+Ch] [rbp-1Ch]

v7 = getAvgVolume();
if ( *a3 > v7 )
{
v4 = (v7 + *a3) * 0.5;
v7 = v4;
}
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, (unsigned int)(int)(float)((float)*a2 * v7));
setTempLED(i, 103LL, (unsigned int)(int)(float)((float)a2[1] * v7));
result = setTempLED(i, 98LL, (unsigned int)(int)(float)((float)a2[2] * v7));
}
*a3 = v7;
return result;
}

original_code:
void volumeAnimation1(double *params, double totalTime, odd_led_t *color, double *lastAvg)
{
    (void)params;
    (void)totalTime;
    SAMPLE avg = getAvgVolume();
    if(avg < *lastAvg)
        avg = (avg + *lastAvg) / 2;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R * avg);
        setTempLED(i, 'g', color->G * avg);
        setTempLED(i, 'b', color->B * avg);
    }
    *lastAvg = avg;
}

canonical_original_code:
void volumeAnimation1(double *params, double totalTime, struct odd_led_t *color, double *lastAvg)
{
    (void)params;
    (void)totalTime;
    float avg = getAvgVolume();
    if(avg < *lastAvg)
        avg = (avg + *lastAvg) / 2;
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i, 'r', color->R * avg);
        setTempLED(i, 'g', color->G * avg);
        setTempLED(i, 'b', color->B * avg);
    }
    *lastAvg = avg;
}

variable_types: struct odd_led_t { int R; int G; int B; struct odd_led_t *next; } *

variable_types:
lastAvg
double *


getSoundBuffer

decompiled_code:
int __fastcall getSoundBuffer(__int64 a1)
{
__int64 i; // rbx
float v2; // ebp

pthread_mutex_lock(&storageLock);
for ( i = 0LL; i != 1024; ++i )
{
v2 = storage[i];
*(float *)(a1 + 4 * i) = v2 * hann_window((unsigned int)i, 1024LL);
}
return pthread_mutex_unlock(&storageLock);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
__int64 i; // rbx
float v2; // ebp

pthread_mutex_lock(&storageLock);
for ( i = 0LL; i != 1024; ++i )
{
v2 = storage[i];
*(float *)(a1 + 4 * i) = v2 * hann_window((unsigned int)i, 1024LL);
}
return pthread_mutex_unlock(&storageLock);
}

original_code:
void getSoundBuffer(SAMPLE* buf)
{
    pthread_mutex_lock(&storageLock);
    for(int i = 0; i < (1024); i++)
        buf[i] = storage[i] * hann_window(i, (1024));
    pthread_mutex_unlock(&storageLock);
}

canonical_original_code:
void getSoundBuffer(float *buf)
{
    pthread_mutex_lock(&storageLock);
    for(int i = 0; i < (1024); i++)
        buf[i] = storage[i] * hann_window(i, (1024));
    pthread_mutex_unlock(&storageLock);
}

variable_types:
buf
float *


decompiled_code:
__int64 __fastcall volumeAnimation3(__int64 a1, int *a2, double *a3)
{
float v4; // xmm3_4
int v5; // er15
int v6; // er14
unsigned int v7; // ebp
unsigned int i; // ebx
__int64 result; // rax
int v10; // er15
float v11; // [rsp+Ch] [rbp-3Ch]

v11 = getAvgVolume();
if ( *a3 > v11 )
{
v4 = (v11 + *a3) * 0.5;
v11 = v4;
}
v5 = (int)(float)(v11 * 64.0);
v6 = (64 - v5) / 2;
v7 = v6;
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, 0LL);
setTempLED(i, 103LL, 0LL);
result = setTempLED(i, 98LL, 0LL);
}
v10 = v6 + v5;
if ( v6 < v10 )
{
do
{
setTempLED(v7, 114LL, (unsigned int)(int)(float)((float)*a2 * v11));
setTempLED(v7, 103LL, (unsigned int)(int)(float)((float)a2[1] * v11));
result = setTempLED(v7++, 98LL, (unsigned int)(int)(float)((float)a2[2] * v11));
}
while ( v7 != v10 );
}
*a3 = v11;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int *a2, double *a3)
{
float v4; // xmm3_4
int v5; // er15
int v6; // er14
unsigned int v7; // ebp
unsigned int i; // ebx
__int64 result; // rax
int v10; // er15
float v11; // [rsp+Ch] [rbp-3Ch]

v11 = getAvgVolume();
if ( *a3 > v11 )
{
v4 = (v11 + *a3) * 0.5;
v11 = v4;
}
v5 = (int)(float)(v11 * 64.0);
v6 = (64 - v5) / 2;
v7 = v6;
for ( i = 0; i != 64; ++i )
{
setTempLED(i, 114LL, 0LL);
setTempLED(i, 103LL, 0LL);
result = setTempLED(i, 98LL, 0LL);
}
v10 = v6 + v5;
if ( v6 < v10 )
{
do
{
setTempLED(v7, 114LL, (unsigned int)(int)(float)((float)*a2 * v11));
setTempLED(v7, 103LL, (unsigned int)(int)(float)((float)a2[1] * v11));
result = setTempLED(v7++, 98LL, (unsigned int)(int)(float)((float)a2[2] * v11));
}
while ( v7 != v10 );
}
*a3 = v11;
return result;
}

original_code:
void volumeAnimation3(double *params, double totalTime, odd_led_t *color, double *lastAvg)
{
    (void)params;
    (void)totalTime;
    SAMPLE avg = getAvgVolume();
    if(avg < *lastAvg)
        avg = (avg + *lastAvg) / 2;
    int width = (int)(avg * (8 * 8));
    int gap = (int)(((8 * 8) - width) / 2);
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i,'r', 0);
        setTempLED(i,'g', 0);
        setTempLED(i,'b', 0);
    }
    for(int i = gap; i < gap+width; i++)
    {
        setTempLED(i,'r', color->R * avg);
        setTempLED(i,'g', color->G * avg);
        setTempLED(i,'b', color->B * avg);
    }
    *lastAvg = avg;
}

canonical_original_code:
void volumeAnimation3(double *params, double totalTime, struct odd_led_t *color, double *lastAvg)
{
    (void)params;
    (void)totalTime;
    float avg = getAvgVolume();
    if(avg < *lastAvg)
        avg = (avg + *lastAvg) / 2;
    int width = (int)(avg * (8 * 8));
    int gap = (int)(((8 * 8) - width) / 2);
    for(int i = 0; i < (8 * 8); i++)
    {
        setTempLED(i,'r', 0);
        setTempLED(i,'g', 0);
        setTempLED(i,'b', 0);
    }
    for(int i = gap; i < gap+width; i++)
    {
        setTempLED(i,'r', color->R * avg);
        setTempLED(i,'g', color->G * avg);
        setTempLED(i,'b', color->B * avg);
    }
    *lastAvg = avg;
}

variable_types:
params
double *

variable_types: width int

variable_types: gap int


repo: dgoulet/debind

decompiled_code:
__int64 udp_create_socket()
{
int v0; // ebx

v0 = socket(2, 2, 17);
if ( v0 < 0 )
perror("socket udp");
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // ebx

v0 = socket(2, 2, 17);
if ( v0 < 0 )
perror("socket udp");
return (unsigned int)v0;
}

original_code:
int udp_create_socket(void)
{
 int sock;
 sock = socket(2, SOCK_DGRAM, IPPROTO_UDP);
 if (sock < 0) {
  perror("socket udp");
  goto error;
 }
error:
 return sock;
}

canonical_original_code:
int udp_create_socket()
{
 int sock;
 sock = socket(2, SOCK_DGRAM, IPPROTO_UDP);
 if (sock < 0) {
  perror("socket udp");
  goto error;
 }
error:
 return sock;
}

variable_types: sock int


decompiled_code:
__int64 __fastcall udp_bind_socket(int fd, __int16 a2, const char *a3)
{
int v4; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&v6.sa_family = 2LL;
*(_QWORD *)&v6.sa_data[6] = 0LL;
*(_WORD *)v6.sa_data = _bswap_16(a2);
if ( a3 )
*(_DWORD *)&v6.sa_data[2] = inet_addr(a3);
else
*(_DWORD *)&v6.sa_data[2] = _bswap_32(0x7F000001u);
v4 = bind(fd, &v6, 0x10u);
if ( v4 < 0 )
perror("bind udp");
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, __int16 a2, const char *a3)
{
int v4; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&v6.sa_family = 2LL;
*(_QWORD *)&v6.sa_data[6] = 0LL;
*(_WORD *)v6.sa_data = func0(a2);
if ( a3 )
*(_DWORD *)&v6.sa_data[2] = inet_addr(a3);
else
*(_DWORD *)&v6.sa_data[2] = func1(0x7F000001u);
v4 = bind(fd, &v6, 0x10u);
if ( v4 < 0 )
perror("bind udp");
return (unsigned int)v4;
}

original_code:
int udp_bind_socket(int sock, int port, char *ip)
{
 int ret = -1;
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(saddr));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if (ip != ((void *)0)) {
  saddr.sin_addr.s_addr = inet_addr(ip);
 } else {
  saddr.sin_addr.s_addr = htonl(((in_addr_t) 0x7f000001));
 }
 ret = bind(sock, (struct sockaddr *)&saddr, sizeof(saddr));
 if (ret < 0) {
  perror("bind udp");
  goto error;
 }
error:
 return ret;
}

canonical_original_code:
int udp_bind_socket(int sock, int port, char *ip)
{
 int ret = -1;
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(saddr));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if (ip != ((void *)0)) {
  saddr.sin_addr.s_addr = inet_addr(ip);
 } else {
  saddr.sin_addr.s_addr = htonl(((unsigned int) 0x7f000001));
 }
 ret = bind(sock, (struct sockaddr *)&saddr, sizeof(saddr));
 if (ret < 0) {
  perror("bind udp");
  goto error;
 }
error:
 return ret;
}

variable_types: port int

variable_types:
ip
char *

variable_types: ret int


decompiled_code:
ssize_t __fastcall udp_sendto(int a1, const void *a2, size_t a3, const struct sockaddr *a4, socklen_t a5)
{
ssize_t v5; // rbx

v5 = sendto(a1, a2, a3, 0, a4, a5);
if ( v5 < 0 )
{
perror("sendto");
}
else if ( opt_verbose )
{
fprintf(stderr, "DEBUG: UDP DNS reply sent to client [in %s() at src/udp.c:93]\n", "udp_sendto");
}
return v5;
}

canonical_decompiled_code:
ssize_t __fastcall func4(int a1, const void *a2, size_t a3, const struct sockaddr *a4, socklen_t a5)
{
ssize_t v5; // rbx

v5 = sendto(a1, a2, a3, 0, a4, a5);
if ( v5 < 0 )
{
perror("sendto");
}
else if ( opt_verbose )
{
fprintf(stderr, "DEBUG: UDP DNS reply sent to client [in %s() at src/udp.c:93]\n", "udp_sendto");
}
return v5;
}

original_code:
ssize_t udp_sendto(int sock, const void *buf, size_t len,
  const struct sockaddr *dest_addr, socklen_t addrlen)
{
 ssize_t ret;
 ret = sendto(sock, buf, len, 0, dest_addr, addrlen);
 if (ret < 0) {
  perror("sendto");
  goto error;
 }
 do { if (opt_verbose && (0x1 & 0x1)) { fprintf(stderr, "DEBUG: " "UDP DNS reply sent to client" " [in %s() at " "src/udp.c" ":" "93" "]\n", __func__); } else if (0x1 & 0x2) { fprintf(stderr, "DEBUG: " "UDP DNS reply sent to client" " [in %s() at " "src/udp.c" ":" "93" "]\n", __func__); } } while (0);;
error:
 return ret;
}

canonical_original_code:
long udp_sendto(int sock, void *buf, unsigned long len, struct sockaddr *dest_addr, unsigned int addrlen)
{
 long ret;
 ret = sendto(sock, buf, len, 0, dest_addr, addrlen);
 if (ret < 0) {
  perror("sendto");
  goto error;
 }
 do { if (opt_verbose && (0x1 & 0x1)) { fprintf(stderr, "DEBUG: " "UDP DNS reply sent to client" " [in %s() at " "src/udp.c" ":" "93" "]\n", __func__); } else if (0x1 & 0x2) { fprintf(stderr, "DEBUG: " "UDP DNS reply sent to client" " [in %s() at " "src/udp.c" ":" "93" "]\n", __func__); } } while (0);;
error:
 return ret;
}

variable_types:
buf
void *

variable_types:
len
unsigned long

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

variable_types:
addrlen
unsigned int

variable_types: ret long

return_type: long


decompiled_code:
ssize_t __fastcall udp_recvfrom(int a1, void *a2, size_t a3, struct sockaddr *a4)
{
ssize_t v4; // rax
ssize_t v5; // rbx
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
v4 = recvfrom(a1, a2, a3, 0, a4, addr_len);
if ( v4 < 0 )
{
perror("recvfrom");
v5 = -*_errno_location();
}
else
{
v5 = v4;
if ( opt_verbose )
fprintf(stderr, "DEBUG: UDP recvfrom size %ld [in %s() at src/udp.c:115]\n", v4, "udp_recvfrom");
}
return v5;
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1, void *a2, size_t a3, struct sockaddr *a4)
{
ssize_t v4; // rax
ssize_t v5; // rbx
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
v4 = recvfrom(a1, a2, a3, 0, a4, addr_len);
if ( v4 < 0 )
{
perror("recvfrom");
v5 = -*_errno_location();
}
else
{
v5 = v4;
if ( opt_verbose )
fprintf(stderr, "DEBUG: UDP recvfrom size %ld [in %s() at src/udp.c:115]\n", v4, "udp_recvfrom");
}
return v5;
}

original_code:
ssize_t udp_recvfrom(int sock, void *buf, size_t len,
  struct sockaddr *src_addr)
{
 ssize_t recv_size;
 socklen_t addrlen = sizeof(struct sockaddr);
 recv_size = recvfrom(sock, buf, len, 0, src_addr, &addrlen);
 if (recv_size < 0) {
  perror("recvfrom");
  recv_size = -(*__errno_location ());
  goto error;
 }
 do { if (opt_verbose && (0x1 & 0x1)) { fprintf(stderr, "DEBUG: " "UDP recvfrom size %ld" " [in %s() at " "src/udp.c" ":" "115" "]\n", recv_size, __func__); } else if (0x1 & 0x2) { fprintf(stderr, "DEBUG: " "UDP recvfrom size %ld" " [in %s() at " "src/udp.c" ":" "115" "]\n", recv_size, __func__); } } while (0);;
error:
 return recv_size;
}

canonical_original_code:
long udp_recvfrom(int sock, void *buf, unsigned long len, struct sockaddr *src_addr)
{
 long recv_size;
 unsigned int addrlen = sizeof(struct sockaddr);
 recv_size = recvfrom(sock, buf, len, 0, src_addr, &addrlen);
 if (recv_size < 0) {
  perror("recvfrom");
  recv_size = -(*__errno_location ());
  goto error;
 }
 do { if (opt_verbose && (0x1 & 0x1)) { fprintf(stderr, "DEBUG: " "UDP recvfrom size %ld" " [in %s() at " "src/udp.c" ":" "115" "]\n", recv_size, __func__); } else if (0x1 & 0x2) { fprintf(stderr, "DEBUG: " "UDP recvfrom size %ld" " [in %s() at " "src/udp.c" ":" "115" "]\n", recv_size, __func__); } } while (0);;
error:
 return recv_size;
}


decompiled_code:
__int64 netfilter_write_log()
{
return dns_log(log_file, pkt_buffer);
}

canonical_decompiled_code:
__int64 func4()
{
return dns_log(log_file, pkt_buffer);
}

original_code:
void netfilter_write_log(void)
{
 dns_log(log_file, pkt_buffer);
}

canonical_original_code:
void netfilter_write_log()
{
 dns_log(log_file, pkt_buffer);
}


decompiled_code:
__int64 netfilter_init()
{
__int64 v0; // rax
__int64 v1; // rdi
__int64 result; // rax

v0 = nfq_open();
handle = v0;
if ( v0 )
{
if ( (int)nfq_unbind_pf(v0, 2LL) < 0 )
{
fwrite("Error: error during nfq_unbind_pf()\n", 1uLL, 0x24uLL, stderr);
result = 0xFFFFFFFFLL;
}
else if ( (int)nfq_bind_pf(handle, 2LL) < 0 )
{
fwrite("Error: error during nfq_bind_pf()\n", 1uLL, 0x22uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v1 = nfq_create_queue(handle, 0LL, packet_handler, 0LL);
queue_handle = v1;
if ( v1 )
{
if ( (int)nfq_set_mode(v1, 2LL, 0xFFFFLL) < 0 )
{
fwrite("Error: can't set packet_copy mode\n", 1uLL, 0x22uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
result = nfq_fd(handle);
}
}
else
{
fwrite("Error: Error during nfq_create_queue\n", 1uLL, 0x25uLL, stderr);
result = 0xFFFFFFFFLL;
}
}
}
else
{
fwrite("Error: Error during nfq_open()\n", 1uLL, 0x1FuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax
__int64 v1; // rdi
__int64 result; // rax

v0 = nfq_open();
handle = v0;
if ( v0 )
{
if ( (int)nfq_unbind_pf(v0, 2LL) < 0 )
{
fwrite("Error: error during nfq_unbind_pf()\n", 1uLL, 0x24uLL, stderr);
result = 0xFFFFFFFFLL;
}
else if ( (int)nfq_bind_pf(handle, 2LL) < 0 )
{
fwrite("Error: error during nfq_bind_pf()\n", 1uLL, 0x22uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v1 = nfq_create_queue(handle, 0LL, packet_handler, 0LL);
queue_handle = v1;
if ( v1 )
{
if ( (int)nfq_set_mode(v1, 2LL, 0xFFFFLL) < 0 )
{
fwrite("Error: can't set packet_copy mode\n", 1uLL, 0x22uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
result = nfq_fd(handle);
}
}
else
{
fwrite("Error: Error during nfq_create_queue\n", 1uLL, 0x25uLL, stderr);
result = 0xFFFFFFFFLL;
}
}
}
else
{
fwrite("Error: Error during nfq_open()\n", 1uLL, 0x1FuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int netfilter_init(void)
{
 int ret;
 handle = nfq_open();
 if (handle == ((void *)0)) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "Error during nfq_open()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "Error during nfq_open()" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_unbind_pf(handle, 2);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "error during nfq_unbind_pf()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "error during nfq_unbind_pf()" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_bind_pf(handle, 2);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "error during nfq_bind_pf()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "error during nfq_bind_pf()" "\n"); } } while (0);;
  goto error;
 }
 queue_handle = nfq_create_queue(handle, 0, &packet_handler, ((void *)0));
 if (queue_handle == ((void *)0)) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "Error during nfq_create_queue" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "Error during nfq_create_queue" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_set_mode(queue_handle, NFQNL_COPY_PACKET, 0xffff);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "can't set packet_copy mode" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "can't set packet_copy mode" "\n"); } } while (0);;
  goto error;
 }
 return nfq_fd(handle);
error:
 return -1;
}

canonical_original_code:
int netfilter_init()
{
 int ret;
 handle = nfq_open();
 if (handle == ((void *)0)) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "Error during nfq_open()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "Error during nfq_open()" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_unbind_pf(handle, 2);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "error during nfq_unbind_pf()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "error during nfq_unbind_pf()" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_bind_pf(handle, 2);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "error during nfq_bind_pf()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "error during nfq_bind_pf()" "\n"); } } while (0);;
  goto error;
 }
 queue_handle = nfq_create_queue(handle, 0, &packet_handler, ((void *)0));
 if (queue_handle == ((void *)0)) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "Error during nfq_create_queue" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "Error during nfq_create_queue" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_set_mode(queue_handle, NFQNL_COPY_PACKET, 0xffff);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "can't set packet_copy mode" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "can't set packet_copy mode" "\n"); } } while (0);;
  goto error;
 }
 return nfq_fd(handle);
error:
 return -1;
}


decompiled_code:
int netfilter_clean()
{
int result; // eax

nfq_destroy_queue(queue_handle);
result = nfq_close(handle);
if ( log_file )
result = fclose(log_file);
return result;
}

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

nfq_destroy_queue(queue_handle);
result = nfq_close(handle);
if ( log_file )
result = fclose(log_file);
return result;
}

original_code:
void netfilter_clean(void)
{
 nfq_destroy_queue(queue_handle);
 nfq_close(handle);
 if (log_file) {
  fclose(log_file);
 }
}

canonical_original_code:
void netfilter_clean()
{
 nfq_destroy_queue(queue_handle);
 nfq_close(handle);
 if (log_file) {
  fclose(log_file);
 }
}