joinChannel

decompiled_code:
void __fastcall joinChannel(__int64 a1, char *a2)
{
char *v2; // rax
const char *v3; // rbp

*(_DWORD *)a1 = 6;
*(_DWORD *)(a1 + 4) = getpid();
v2 = strtok(a2, " \t");
if ( v2 )
{
v3 = v2;
if ( strlen(v2) <= 0x31 )
{
strcpy((char *)(a1 + 8), v3);
}
else
{
safePrintf("channel name is too long, cutting...\n");
strncpy((char *)(a1 + 8), v3, 0x31uLL);
*(_BYTE *)(a1 + 57) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("join channel");
else
safePrintf("successfully joined channel %s\n", v3);
}
else
{
safePrintf("no channel name\n");
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, char *a2)
{
char *v2; // rax
const char *v3; // rbp

*(_DWORD *)a1 = 6;
*(_DWORD *)(a1 + 4) = getpid();
v2 = strtok(a2, " \t");
if ( v2 )
{
v3 = v2;
if ( strlen(v2) <= 0x31 )
{
strcpy((char *)(a1 + 8), v3);
}
else
{
safePrintf("channel name is too long, cutting...\n");
strncpy((char *)(a1 + 8), v3, 0x31uLL);
*(_BYTE *)(a1 + 57) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("join channel");
else
safePrintf("successfully joined channel %s\n", v3);
}
else
{
safePrintf("no channel name\n");
}
}

original_code:
static void joinChannel(Message *msgbuf, char *msg)
{
    msgbuf->type = JOIN_CHANNEL_MSG;
    msgbuf->data.chmsg.cid = getpid();
    char *channel = strtok(msg, " 	");
    if (! channel)
    {
        safePrintf("no channel name\n");
        return;
    }
    if (strlen(channel) >= 50)
    {
        safePrintf("channel name is too long, cutting...\n");
        strncpy(msgbuf->data.chmsg.channel_name, channel, 50 - 1);
        msgbuf->data.chmsg.channel_name[50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.chmsg.channel_name, channel);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("join channel");
        return;
    }
    safePrintf("successfully joined channel %s\n", channel);
}

canonical_original_code:
static void joinChannel(struct Message *msgbuf, char *msg)
{
    msgbuf->type = JOIN_CHANNEL_MSG;
    msgbuf->data.chmsg.cid = getpid();
    char *channel = strtok(msg, " 	");
    if (! channel)
    {
        safePrintf("no channel name\n");
        return;
    }
    if (strlen(channel) >= 50)
    {
        safePrintf("channel name is too long, cutting...\n");
        strncpy(msgbuf->data.chmsg.channel_name, channel, 50 - 1);
        msgbuf->data.chmsg.channel_name[50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.chmsg.channel_name, channel);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("join channel");
        return;
    }
    safePrintf("successfully joined channel %s\n", channel);
}

variable_types:
channel
char *


serverMessage

decompiled_code:
void __fastcall serverMessage(__int64 a1, const char *a2)
{
*(_DWORD *)a1 = 4;
*(_DWORD *)(a1 + 4) = getpid();
if ( strlen(a2) <= 0x7C5 )
{
strcpy((char *)(a1 + 8), a2);
}
else
{
safePrintf("server command is too long, cutting...\n");
strncpy((char *)(a1 + 8), a2, 0x7C5uLL);
*(_BYTE *)(a1 + 1997) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send server command");
else
safePrintf("successfully sent server command\n");
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, const char *a2)
{
*(_DWORD *)a1 = 4;
*(_DWORD *)(a1 + 4) = getpid();
if ( strlen(a2) <= 0x7C5 )
{
strcpy((char *)(a1 + 8), a2);
}
else
{
safePrintf("server command is too long, cutting...\n");
strncpy((char *)(a1 + 8), a2, 0x7C5uLL);
*(_BYTE *)(a1 + 1997) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send server command");
else
safePrintf("successfully sent server command\n");
}

original_code:
static void serverMessage(Message *msgbuf, char *command)
{
    msgbuf->type = SRV_MSG;
    msgbuf->data.srvmsg.cid = getpid();
    if (strlen(command) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("server command is too long, cutting...\n");
        strncpy(msgbuf->data.srvmsg.text, command, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.srvmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.srvmsg.text, command);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send server command");
        return;
    }
    safePrintf("successfully sent server command\n");
}

canonical_original_code:
static void serverMessage(struct Message *msgbuf, char *command)
{
    msgbuf->type = SRV_MSG;
    msgbuf->data.srvmsg.cid = getpid();
    if (strlen(command) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("server command is too long, cutting...\n");
        strncpy(msgbuf->data.srvmsg.text, command, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.srvmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.srvmsg.text, command);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send server command");
        return;
    }
    safePrintf("successfully sent server command\n");
}

variable_types: struct Message { enum MessageType { LOGIN_MSG=1, DISCONNECT_MSG=2, INFO_MSG=3, SRV_MSG=4, CONFIRM_MSG=5, JOIN_CHANNEL_MSG=6, LEAVE_CHANNEL_MSG=7, SEND_USER_MSG=8, SEND_CHANNEL_MSG=9, SHOW_USERS=10, SHOW_CHANNELS=11 } type; union { struct LoginMessage { int cid; char name[50]; char queueName[255]; } loginmsg; struct TextMessage { int cid; char name[50]; char text[-1]; } textmsg; struct DisconnectMessage { int cid; } discmsg; struct ServerMessage { int cid; char text[-1]; } srvmsg; struct ConfirmationMessage { int cid; int confirmed; char text[-1]; } confmsg; struct ChannelMessage { int cid; char channel_name[50]; } chmsg; } data; } *

variable_types:
command
char *

return_type: void

user_defined_types: struct Message { enum MessageType type; union { struct LoginMessage loginmsg; struct TextMessage textmsg; struct DisconnectMessage discmsg; struct ServerMessage srvmsg; struct ConfirmationMessage confmsg; struct ChannelMessage chmsg; } data; }


parseCommand

decompiled_code:
void __fastcall parseCommand(void *ptr, _DWORD *a2)
{
if ( !ptr )
LABEL_15:
quit(0);
if ( !strcmp((const char *)ptr, "quit") || !strcmp((const char *)ptr, "exit") )
{
free(ptr);
goto LABEL_15;
}
if ( *(_BYTE *)ptr )
{
if ( !memcmp(ptr, "chmsg ", 6uLL) )
{
sendChannelMessage((__int64)a2, (char *)ptr + 6);
}
else if ( !memcmp(ptr, "privmsg ", 8uLL) )
{
sendPrivateMessage((__int64)a2, (char *)ptr + 8);
}
else if ( !memcmp(ptr, "join ", 5uLL) )
{
joinChannel((__int64)a2, (char *)ptr + 5);
}
else if ( !strcmp((const char *)ptr, "leave") )
{
leaveChannel(a2);
}
else if ( !strcmp((const char *)ptr, "users") )
{
showUsers(a2);
}
else if ( !strcmp((const char *)ptr, "channels") )
{
showChannels(a2);
}
else if ( !strcmp((const char *)ptr, "info") )
{
requestInfo(a2);
}
else if ( !strcmp((const char *)ptr, "help") )
{
showHelp();
}
else
{
serverMessage((__int64)a2, (const char *)ptr);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr, _DWORD *a2)
{
if ( !ptr )
LABEL_15:
func6(0);
if ( !strcmp((const char *)ptr, "quit") || !strcmp((const char *)ptr, "exit") )
{
free(ptr);
goto LABEL_15;
}
if ( *(_BYTE *)ptr )
{
if ( !memcmp(ptr, "chmsg ", 6uLL) )
{
func7((__int64)a2, (char *)ptr + 6);
}
else if ( !memcmp(ptr, "privmsg ", 8uLL) )
{
func8((__int64)a2, (char *)ptr + 8);
}
else if ( !memcmp(ptr, "join ", 5uLL) )
{
func9((__int64)a2, (char *)ptr + 5);
}
else if ( !strcmp((const char *)ptr, "leave") )
{
func4(a2);
}
else if ( !strcmp((const char *)ptr, "users") )
{
func1(a2);
}
else if ( !strcmp((const char *)ptr, "channels") )
{
func2(a2);
}
else if ( !strcmp((const char *)ptr, "info") )
{
func3(a2);
}
else if ( !strcmp((const char *)ptr, "help") )
{
func5();
}
else
{
func10((__int64)a2, (const char *)ptr);
}
free(ptr);
}
}

original_code:
static void parseCommand(char *cmdstr, Message *msgbuf)
{
    if (! cmdstr ||
        strcmp(cmdstr, "quit") == 0 || strcmp(cmdstr, "exit") == 0)
    {
        if (cmdstr)
            free(cmdstr);
        quit(0);
    }
    if (*cmdstr == '\0')
        return;
    if (strncmp(cmdstr, "chmsg ", 6) == 0)
        sendChannelMessage(msgbuf, cmdstr + 6);
    else if (strncmp(cmdstr, "privmsg ", 8) == 0)
        sendPrivateMessage(msgbuf, cmdstr + 8);
    else if (strncmp(cmdstr, "join ", 5) == 0)
        joinChannel(msgbuf, cmdstr + 5);
    else if (strcmp(cmdstr, "leave") == 0)
        leaveChannel(msgbuf);
    else if (strcmp(cmdstr, "users") == 0)
        showUsers(msgbuf);
    else if (strcmp(cmdstr, "channels") == 0)
        showChannels(msgbuf);
    else if (strcmp(cmdstr, "info") == 0)
        requestInfo(msgbuf);
    else if (strcmp(cmdstr, "help") == 0)
        showHelp();
    else
        serverMessage(msgbuf, cmdstr);
    free(cmdstr);
}

canonical_original_code:
static void parseCommand(char *cmdstr, struct Message *msgbuf)
{
    if (! cmdstr ||
        strcmp(cmdstr, "quit") == 0 || strcmp(cmdstr, "exit") == 0)
    {
        if (cmdstr)
            free(cmdstr);
        quit(0);
    }
    if (*cmdstr == '\0')
        return;
    if (strncmp(cmdstr, "chmsg ", 6) == 0)
        sendChannelMessage(msgbuf, cmdstr + 6);
    else if (strncmp(cmdstr, "privmsg ", 8) == 0)
        sendPrivateMessage(msgbuf, cmdstr + 8);
    else if (strncmp(cmdstr, "join ", 5) == 0)
        joinChannel(msgbuf, cmdstr + 5);
    else if (strcmp(cmdstr, "leave") == 0)
        leaveChannel(msgbuf);
    else if (strcmp(cmdstr, "users") == 0)
        showUsers(msgbuf);
    else if (strcmp(cmdstr, "channels") == 0)
        showChannels(msgbuf);
    else if (strcmp(cmdstr, "info") == 0)
        requestInfo(msgbuf);
    else if (strcmp(cmdstr, "help") == 0)
        showHelp();
    else
        serverMessage(msgbuf, cmdstr);
    free(cmdstr);
}

variable_types:
cmdstr
char *

user_defined_types: enum MessageType { LOGIN_MSG=1, DISCONNECT_MSG=2, INFO_MSG=3, SRV_MSG=4, CONFIRM_MSG=5, JOIN_CHANNEL_MSG=6, LEAVE_CHANNEL_MSG=7, SEND_USER_MSG=8, SEND_CHANNEL_MSG=9, SHOW_USERS=10, SHOW_CHANNELS=11 }

user_defined_types: struct LoginMessage { int cid; char name[50]; char queueName[255]; }

user_defined_types: struct TextMessage { int cid; char name[50]; char text[-1]; }

user_defined_types: struct ServerMessage { int cid; char text[-1]; }

user_defined_types: struct ConfirmationMessage { int cid; int confirmed; char text[-1]; }

user_defined_types: struct ChannelMessage { int cid; char channel_name[50]; }


quit

decompiled_code:
void __fastcall __noreturn quit(int a1)
{
int v1[514]; // [rsp+0h] [rbp-808h] BYREF

puts("quiting...");
v1[0] = 2;
v1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, v1, 2048LL, 0LL) < 0 )
perror("send disconnect message");
if ( (int)mq_close((unsigned int)ClientQueue) < 0 )
perror("close client queue");
if ( (int)mq_unlink(ClientQueueName) < 0 )
perror("unlink client queue");
if ( (int)mq_close((unsigned int)GlobalQueue) < 0 )
perror("close global queue");
exit(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func6(int a1)
{
int v1[514]; // [rsp+0h] [rbp-808h] BYREF

puts("quiting...");
v1[0] = 2;
v1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, v1, 2048LL, 0LL) < 0 )
perror("send disconnect message");
if ( (int)mq_close((unsigned int)ClientQueue) < 0 )
perror("close client queue");
if ( (int)mq_unlink(ClientQueueName) < 0 )
perror("unlink client queue");
if ( (int)mq_close((unsigned int)GlobalQueue) < 0 )
perror("close global queue");
exit(a1);
}

original_code:
static void quit(int signum)
{
    printf("quiting...\n");
    Message msg;
    msg.type = DISCONNECT_MSG;
    msg.data.discmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)&msg, sizeof(Message), 0) < 0)
        perror("send disconnect message");
    if (mq_close(ClientQueue) < 0)
        perror("close client queue");
    if (mq_unlink(ClientQueueName) < 0)
        perror("unlink client queue");
    if (mq_close(GlobalQueue) < 0)
        perror("close global queue");
    exit(signum);
}

canonical_original_code:
static void quit(int signum)
{
    printf("quiting...\n");
    struct Message msg;
    msg.type = DISCONNECT_MSG;
    msg.data.discmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)&msg, sizeof(Message), 0) < 0)
        perror("send disconnect message");
    if (mq_close(ClientQueue) < 0)
        perror("close client queue");
    if (mq_unlink(ClientQueueName) < 0)
        perror("unlink client queue");
    if (mq_close(GlobalQueue) < 0)
        perror("close global queue");
    exit(signum);
}

variable_types: signum int

variable_types: struct Message { enum MessageType { LOGIN_MSG=1, DISCONNECT_MSG=2, INFO_MSG=3, SRV_MSG=4, CONFIRM_MSG=5, JOIN_CHANNEL_MSG=6, LEAVE_CHANNEL_MSG=7, SEND_USER_MSG=8, SEND_CHANNEL_MSG=9, SHOW_USERS=10, SHOW_CHANNELS=11 } type; union { struct LoginMessage { int cid; char name[50]; char queueName[255]; } loginmsg; struct TextMessage { int cid; char name[50]; char text[-1]; } textmsg; struct DisconnectMessage { int cid; } discmsg; struct ServerMessage { int cid; char text[-1]; } srvmsg; struct ConfirmationMessage { int cid; int confirmed; char text[-1]; } confmsg; struct ChannelMessage { int cid; char channel_name[50]; } chmsg; } data; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rbx
char *v5; // rdi
__int64 i; // rcx
const char *v7; // rbp
const char *v8; // rax
char *v9; // rbp
void *v10; // rax
pthread_t newthread; // [rsp+8h] [rbp-860h] BYREF
int v12[2]; // [rsp+10h] [rbp-858h] BYREF
char dest[4]; // [rsp+18h] [rbp-850h] BYREF
char s[46]; // [rsp+1Ch] [rbp-84Ch] BYREF
char v15[1990]; // [rsp+4Ah] [rbp-81Eh] BYREF
char v16; // [rsp+810h] [rbp-58h] BYREF
__int64 v17; // [rsp+818h] [rbp-50h]
__int64 v18; // [rsp+820h] [rbp-48h]

GlobalQueue = mq_open("/irc-commmon-queue", 1LL, envp);
if ( GlobalQueue >= 0 )
{
v4 = (unsigned int)getpid();
sprintf(ClientQueueName, "/irc-client-%d", v4);
v5 = &v16;
for ( i = 16LL; i; --i )
{
*(_DWORD *)v5 = 0;
v5 += 4;
}
v17 = 10LL;
v18 = 2048LL;
ClientQueue = mq_open(ClientQueueName, 64LL, 438LL);
if ( ClientQueue >= 0 )
{
signal(2, (__sighandler_t)quit);
if ( argc > 1 )
{
v7 = argv[1];
initializePrompt();
strcpy(dest, v7);
while ( 1 )
{
v12[0] = 1;
v12[1] = v4;
strcpy(v15, ClientQueueName);
if ( (int)mq_send((unsigned int)GlobalQueue, v12, 2048LL, 0LL) < 0 )
break;
if ( mq_receive((unsigned int)ClientQueue, v12, 2048LL, 0LL) < 0 )
{
perror("receiving login confirmation");
}
else if ( v12[0] == 5 )
{
puts(s);
if ( *(_DWORD *)dest )
{
pthread_create(&newthread, 0LL, queueListen, 0LL);
while ( 1 )
{
v10 = (void *)readline("-> ");
parseCommand(v10, v12);
}
}
v8 = (const char *)readline("Choose other name: ");
v9 = (char *)v8;
if ( !v8 )
quit(0);
strcpy(dest, v8);
free(v9);
}
}
perror("send login msg");
quit(0);
}
printf("Usage: %s <login>\n", *argv);
quit(0);
}
printf("name - %s\n", ClientQueueName);
perror("open client queue");
quit(0);
}
perror("open global queue");
quit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rbx
char *v5; // rdi
__int64 i; // rcx
const char *v7; // rbp
const char *v8; // rax
char *v9; // rbp
void *v10; // rax
pthread_t newthread; // [rsp+8h] [rbp-860h] BYREF
int v12[2]; // [rsp+10h] [rbp-858h] BYREF
char dest[4]; // [rsp+18h] [rbp-850h] BYREF
char s[46]; // [rsp+1Ch] [rbp-84Ch] BYREF
char v15[1990]; // [rsp+4Ah] [rbp-81Eh] BYREF
char v16; // [rsp+810h] [rbp-58h] BYREF
__int64 v17; // [rsp+818h] [rbp-50h]
__int64 v18; // [rsp+820h] [rbp-48h]

GlobalQueue = mq_open("/irc-commmon-queue", 1LL, envp);
if ( GlobalQueue >= 0 )
{
v4 = (unsigned int)getpid();
sprintf(ClientQueueName, "/irc-client-%d", v4);
v5 = &v16;
for ( i = 16LL; i; --i )
{
*(_DWORD *)v5 = 0;
v5 += 4;
}
v17 = 10LL;
v18 = 2048LL;
ClientQueue = mq_open(ClientQueueName, 64LL, 438LL);
if ( ClientQueue >= 0 )
{
signal(2, (__sighandler_t)quit);
if ( argc > 1 )
{
v7 = argv[1];
initializePrompt();
strcpy(dest, v7);
while ( 1 )
{
v12[0] = 1;
v12[1] = v4;
strcpy(v15, ClientQueueName);
if ( (int)mq_send((unsigned int)GlobalQueue, v12, 2048LL, 0LL) < 0 )
break;
if ( mq_receive((unsigned int)ClientQueue, v12, 2048LL, 0LL) < 0 )
{
perror("receiving login confirmation");
}
else if ( v12[0] == 5 )
{
puts(s);
if ( *(_DWORD *)dest )
{
pthread_create(&newthread, 0LL, queueListen, 0LL);
while ( 1 )
{
v10 = (void *)readline("-> ");
func11(v10, v12);
}
}
v8 = (const char *)readline("Choose other name: ");
v9 = (char *)v8;
if ( !v8 )
func6(0);
strcpy(dest, v8);
free(v9);
}
}
perror("send login msg");
func6(0);
}
printf("Usage: %s <login>\n", *argv);
func6(0);
}
printf("name - %s\n", ClientQueueName);
perror("open client queue");
func6(0);
}
perror("open global queue");
func6(0);
}

original_code:
int main(int argc, char **argv)
{
    GlobalQueue = mq_open("/irc-commmon-queue", 01);
    if (GlobalQueue < 0)
    {
        perror("open global queue");
        quit(0);
    }
    int pid = getpid();
    sprintf(ClientQueueName, "/irc-client-%d", pid);
    struct mq_attr attrs = { .mq_flags = 0, .mq_maxmsg = 10,
                             .mq_msgsize = 2048, .mq_curmsgs = 0 };
    ClientQueue = mq_open(ClientQueueName, 00 | 0100, 0666, &attrs);
    if (ClientQueue < 0)
    {
        printf("name - %s\n", ClientQueueName);
        perror("open client queue");
        quit(0);
    }
    signal(2, quit);
    if (argc < 2)
    {
        printf("Usage: %s <login>\n", argv[0]);
        quit(0);
    }
    Message message;
    char *username = argv[1];
    initializePrompt();
    strcpy(message.data.loginmsg.name, username);
    while (1)
    {
        message.type = LOGIN_MSG;
        message.data.loginmsg.cid = pid;
        strcpy(message.data.loginmsg.queueName, ClientQueueName);
        if (mq_send(GlobalQueue, (char *)&message, sizeof(Message), 0) < 0)
        {
            perror("send login msg");
            quit(0);
        }
        if (mq_receive(ClientQueue, (char *)&message, sizeof(Message), ((void *)0)) < 0)
            perror("receiving login confirmation");
        else
            if (message.type == CONFIRM_MSG)
            {
                puts(message.data.confmsg.text);
                if (message.data.confmsg.confirmed)
                    break;
                username = readline("Choose other name: ");
                if (! username)
                    quit(0);
                strcpy(message.data.loginmsg.name, username);
                free(username);
            }
    }
    pthread_t queueListenerThread;
    pthread_create(&queueListenerThread, ((void *)0), queueListen, ((void *)0));
    while (1)
    {
        char *input = readline("-> ");
        parseCommand(input, &message);
    }
}

canonical_original_code:
int main(int argc, char **argv)
{
    GlobalQueue = mq_open("/irc-commmon-queue", 01);
    if (GlobalQueue < 0)
    {
        perror("open global queue");
        quit(0);
    }
    int pid = getpid();
    sprintf(ClientQueueName, "/irc-client-%d", pid);
    struct mq_attr attrs = { .mq_flags = 0, .mq_maxmsg = 10,
                             .mq_msgsize = 2048, .mq_curmsgs = 0 };
    ClientQueue = mq_open(ClientQueueName, 00 | 0100, 0666, &attrs);
    if (ClientQueue < 0)
    {
        printf("name - %s\n", ClientQueueName);
        perror("open client queue");
        quit(0);
    }
    signal(2, quit);
    if (argc < 2)
    {
        printf("Usage: %s <login>\n", argv[0]);
        quit(0);
    }
    struct Message message;
    char *username = argv[1];
    initializePrompt();
    strcpy(message.data.loginmsg.name, username);
    while (1)
    {
        message.type = LOGIN_MSG;
        message.data.loginmsg.cid = pid;
        strcpy(message.data.loginmsg.queueName, ClientQueueName);
        if (mq_send(GlobalQueue, (char *)&message, sizeof(Message), 0) < 0)
        {
            perror("send login msg");
            quit(0);
        }
        if (mq_receive(ClientQueue, (char *)&message, sizeof(Message), ((void *)0)) < 0)
            perror("receiving login confirmation");
        else
            if (message.type == CONFIRM_MSG)
            {
                puts(message.data.confmsg.text);
                if (message.data.confmsg.confirmed)
                    break;
                username = readline("Choose other name: ");
                if (! username)
                    quit(0);
                strcpy(message.data.loginmsg.name, username);
                free(username);
            }
    }
    unsigned long queueListenerThread;
    pthread_create(&queueListenerThread, ((void *)0), queueListen, ((void *)0));
    while (1)
    {
        char *input = readline("-> ");
        parseCommand(input, &message);
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: pid int

variable_types: struct mq_attr { long mq_flags; long mq_maxmsg; long mq_msgsize; long mq_curmsgs; long __pad[4]; }

variable_types:
username
char *

variable_types:
queueListenerThread
unsigned long

variable_types:
input
char *

return_type: int


Randomize

decompiled_code:
void Randomize()
{
struct timespec v0; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v0);
srand(v0.tv_nsec);
}

canonical_decompiled_code:
void func0()
{
struct timespec v0; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v0);
srand(v0.tv_nsec);
}

original_code:
void Randomize()
{
    struct timespec ts;
    clock_gettime(0, &ts);
    srand(ts.tv_nsec);
}

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


decompiled_code:
void __fastcall __noreturn perror_die(const char *a1)
{
int *v1; // rax

perror(a1);
v1 = _errno_location();
exit(*v1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
int *v1; // rax

perror(a1);
v1 = _errno_location();
exit(*v1);
}

original_code:
void perror_die(char *msg)
{
    perror(msg);
    exit((*__errno_location ()));
}

variable_types:
msg
char *


safeNewline

decompiled_code:
__int64 __fastcall safeNewline(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebx

pthread_mutex_lock(&TerminalLock);
v2 = rl_newline(a1, a2);
pthread_mutex_unlock(&TerminalLock);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebx

pthread_mutex_lock(&TerminalLock);
v2 = rl_newline(a1, a2);
pthread_mutex_unlock(&TerminalLock);
return v2;
}

original_code:
int safeNewline(int count, int key)
{
    pthread_mutex_lock(&TerminalLock);
    int res = rl_newline(count, key);
    pthread_mutex_unlock(&TerminalLock);
    return res;
}

variable_types: count int

variable_types: key int

variable_types: res int


readlineStartupHook

decompiled_code:
__int64 readlineStartupHook()
{
rl_bind_key(10LL, safeNewline);
return rl_bind_key(13LL, safeNewline);
}

canonical_decompiled_code:
__int64 func1()
{
rl_bind_key(10LL, safeNewline);
return rl_bind_key(13LL, safeNewline);
}

original_code:
void readlineStartupHook()
{
    rl_bind_key(10, safeNewline);
    rl_bind_key(13, safeNewline);
}


safePrintf

decompiled_code:
int safePrintf(char *format, ...)
{
int result; // eax
int v2; // er12
void *v3; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( (rl_readline_state & 8) != 0 )
{
pthread_mutex_lock(&TerminalLock);
v2 = rl_point;
v3 = (void *)rl_copy_text(0LL, rl_end);
rl_save_prompt();
rl_replace_line(&unk_208, 0LL);
rl_redisplay();
va_start(arg, format);
vprintf(format, arg);
rl_restore_prompt();
rl_replace_line(v3, 0LL);
rl_point = v2;
rl_redisplay();
free(v3);
result = pthread_mutex_unlock(&TerminalLock);
}
else
{
va_start(arg, format);
result = vprintf(format, arg);
}
return result;
}

canonical_decompiled_code:
int func2(char *format, ...)
{
int result; // eax
int v2; // er12
void *v3; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( (rl_readline_state & 8) != 0 )
{
pthread_mutex_lock(&TerminalLock);
v2 = rl_point;
v3 = (void *)rl_copy_text(0LL, rl_end);
rl_save_prompt();
rl_replace_line(&unk_208, 0LL);
rl_redisplay();
va_start(arg, format);
vprintf(format, arg);
rl_restore_prompt();
rl_replace_line(v3, 0LL);
rl_point = v2;
rl_redisplay();
free(v3);
result = pthread_mutex_unlock(&TerminalLock);
}
else
{
va_start(arg, format);
result = vprintf(format, arg);
}
return result;
}

original_code:
void safePrintf(char *fmt, ...)
{
    int need_hack = (rl_readline_state & 0x0000008) > 0;
    char *saved_line;
    int saved_point;
    if (need_hack)
    {
        pthread_mutex_lock(&TerminalLock);
        saved_point = rl_point;
        saved_line = rl_copy_text(0, rl_end);
        rl_save_prompt();
        rl_replace_line("", 0);
        rl_redisplay();
    }
    va_list args;
    __builtin_va_start(args,fmt);
    vprintf(fmt, args);
    __builtin_va_end(args);
    if (need_hack)
    {
        rl_restore_prompt();
        rl_replace_line(saved_line, 0);
        rl_point = saved_point;
        rl_redisplay();
        free(saved_line);
        pthread_mutex_unlock(&TerminalLock);
    }
}

canonical_original_code:
void safePrintf(char *fmt, ...)
{
    int need_hack = (rl_readline_state & 0x0000008) > 0;
    char *saved_line;
    int saved_point;
    if (need_hack)
    {
        pthread_mutex_lock(&TerminalLock);
        saved_point = rl_point;
        saved_line = rl_copy_text(0, rl_end);
        rl_save_prompt();
        rl_replace_line("", 0);
        rl_redisplay();
    }
    __builtin_va_list args;
    __builtin_va_start(args,fmt);
    vprintf(fmt, args);
    __builtin_va_end(args);
    if (need_hack)
    {
        rl_restore_prompt();
        rl_replace_line(saved_line, 0);
        rl_point = saved_point;
        rl_redisplay();
        free(saved_line);
        pthread_mutex_unlock(&TerminalLock);
    }
}

variable_types:
fmt
char *


initializePrompt

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

result = pthread_mutex_init(&TerminalLock, 0LL);
rl_startup_hook = readlineStartupHook;
return result;
}

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

result = pthread_mutex_init(&TerminalLock, 0LL);
rl_startup_hook = readlineStartupHook;
return result;
}

original_code:
void initializePrompt()
{
    pthread_mutex_init(&TerminalLock, ((void *)0));
    rl_startup_hook = (rl_hook_func_t *)readlineStartupHook;
}

canonical_original_code:
void initializePrompt()
{
    pthread_mutex_init(&TerminalLock, ((void *)0));
    rl_startup_hook = (int (*)())readlineStartupHook;
}


flute

repo: kffaxen/wool

decompiled_code:
int __fastcall flute(int a1, const char **a2, int a3, int *a4)
{
int v6; // ebx
int *v7; // rax
int v8; // esi
int v9; // edx

if ( a1 <= 0 )
{
fwrite("Params for flute: <coeff> [<power>]\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
v6 = 1;
if ( a1 > 1 )
v6 = atoi(a2[1]);
LODWORD(v7) = atoi(*a2);
v8 = (int)v7;
if ( a3 > 0 )
{
v7 = a4;
v9 = 0;
do
{
*v7 = v6 ^ v9;
v9 += v8;
++v7;
}
while ( v7 != &a4[a3 - 1 + 1] );
}
return (int)v7;
}

canonical_decompiled_code:
int __fastcall func2(int a1, const char **a2, int a3, int *a4)
{
int v6; // ebx
int *v7; // rax
int v8; // esi
int v9; // edx

if ( a1 <= 0 )
{
fwrite("Params for flute: <coeff> [<power>]\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
v6 = 1;
if ( a1 > 1 )
v6 = atoi(a2[1]);
LODWORD(v7) = atoi(*a2);
v8 = (int)v7;
if ( a3 > 0 )
{
v7 = a4;
v9 = 0;
do
{
*v7 = v6 ^ v9;
v9 += v8;
++v7;
}
while ( v7 != &a4[a3 - 1 + 1] );
}
return (int)v7;
}

original_code:
void flute( int argc, char** argv, int n, int* delays )
{
  int coeff, power;
  if( argc < 1 ) {
    fprintf( stderr, "Params for flute: <coeff> [<power>]\n" );
    exit(1);
  } else if( argc < 2 ) {
    power = 1;
  } else {
    power = atoi( argv[1] );
  }
  coeff = atoi( argv[0] );
  for( int i = 0; i < n; i++ ) {
    delays[i] = coeff * i^power;
  }
}

canonical_original_code:
void flute(int argc, char **argv, int n, int *delays)
{
  int coeff; int power;
  if( argc < 1 ) {
    fprintf( stderr, "Params for flute: <coeff> [<power>]\n" );
    exit(1);
  } else if( argc < 2 ) {
    power = 1;
  } else {
    power = atoi( argv[1] );
  }
  coeff = atoi( argv[0] );
  for( int i = 0; i < n; i++ ) {
    delays[i] = coeff * i^power;
  }
}

variable_types: n int

variable_types:
delays
int *

variable_types: coeff int

variable_types: power int

variable_types: i int


decompiled_code:
unsigned __int64 __fastcall tloop_TREE_CALL(_QWORD *a1, signed int a2, signed int a3, __int64 a4)
{
unsigned int v4; // ebx
unsigned __int64 result; // rax
unsigned int v8; // er14
unsigned __int64 v9; // rsi
__int64 v10; // rsi
unsigned __int64 v11; // rsi

v4 = a2;
result = a3 - a2;
if ( result <= 1 )
{
if ( a2 < a3 )
{
do
result = tloop_LOOP((__int64)a1, v4++, a4);
while ( a3 != v4 );
}
}
else
{
v8 = (a2 + a3) / 2;
v9 = a1[62];
*(_DWORD *)(v9 + 32) = v8;
*(_DWORD *)(v9 + 36) = a3;
*(_QWORD *)(v9 + 40) = a4;
if ( v9 >= a1[54] )
{
v10 = wool_slow_spawn(a1, v9, &tloop_TREE_DICT);
}
else
{
*(_QWORD *)v9 = &tloop_TREE_DICT;
v10 = v9 + 128;
}
a1[62] = v10;
tloop_TREE_CALL(a1, v4, v8, a4);
v11 = a1[62];
if ( a1[53] >= v11 )
{
result = tloop_TREE_PUB(a1);
}
else
{
a1[62] = v11 - 128;
result = tloop_TREE_CALL(a1, *(unsigned int *)(v11 - 96), *(unsigned int *)(v11 - 92), *(_QWORD *)(v11 - 88));
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(_QWORD *a1, signed int a2, signed int a3, __int64 a4)
{
unsigned int v4; // ebx
unsigned __int64 result; // rax
unsigned int v8; // er14
unsigned __int64 v9; // rsi
__int64 v10; // rsi
unsigned __int64 v11; // rsi

v4 = a2;
result = a3 - a2;
if ( result <= 1 )
{
if ( a2 < a3 )
{
do
result = func1((__int64)a1, v4++, a4);
while ( a3 != v4 );
}
}
else
{
v8 = (a2 + a3) / 2;
v9 = a1[62];
*(_DWORD *)(v9 + 32) = v8;
*(_DWORD *)(v9 + 36) = a3;
*(_QWORD *)(v9 + 40) = a4;
if ( v9 >= a1[54] )
{
v10 = wool_slow_spawn(a1, v9, &tloop_TREE_DICT);
}
else
{
*(_QWORD *)v9 = &tloop_TREE_DICT;
v10 = v9 + 128;
}
a1[62] = v10;
func3(a1, v4, v8, a4);
v11 = a1[62];
if ( a1[53] >= v11 )
{
result = func6(a1);
}
else
{
a1[62] = v11 - 128;
result = func3(a1, *(unsigned int *)(v11 - 96), *(unsigned int *)(v11 - 92), *(_QWORD *)(v11 - 88));
}
}
return result;
}

original_code: void tloop_TREE_CALL(Worker *_wool_self , int a1, int a2, int* a3){ return tloop_TREE_WRK( _wool_self, 1 , a1, a2, a3 ); }

canonical_original_code: void tloop_TREE_CALL(struct _Worker *_wool_self, int a1, int a2, int *a3){ return tloop_TREE_WRK( _wool_self, 1 , a1, a2, a3 ); }

variable_types: struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task { struct _wool_dict_t { struct _Task *(*f)(struct _Worker *, struct _Task *); int size; } *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *

user_defined_types: struct _Worker { struct _Worker_private pr; char pad1[-1]; struct _Worker_public pu; char pad2[-1]; }

user_defined_types: struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; }

user_defined_types: struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t work_available; void *(*fun)(void *); void *fun_arg; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; }

user_defined_types: struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall tloop_TREE_WRAP_AUX(_QWORD *a1, __int64 a2, signed int a3, signed int a4, __int64 a5)
{
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

v8 = a2;
*(_DWORD *)(a2 + 40) = 0;
*(_QWORD *)(v8 + 8) = &v8;
tloop_TREE_CALL(a1, a3, a4, a5);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v6 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
}
}
result = v8;
if ( a2 == v8 )
*(_QWORD *)(v8 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2, signed int a3, signed int a4, __int64 a5)
{
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

v8 = a2;
*(_DWORD *)(a2 + 40) = 0;
*(_QWORD *)(v8 + 8) = &v8;
func3(a1, a3, a4, a5);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v6 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
}
}
result = v8;
if ( a2 == v8 )
*(_QWORD *)(v8 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

original_code: Task* tloop_TREE_WRAP_AUX(Worker *__self, tloop_TREE_TD *t , int a1, int a2, int* a3){ tloop_TREE_TD *post_eval_task; tloop_TREE_TD *volatile v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (Task**) &v_t ); tloop_TREE_CALL( __self , a1, a2, a3 ); post_eval_task = (tloop_TREE_TD*) _wool_swap_link( (Task *volatile *) &v_t, (Task *) t ); return (Task *) post_eval_task; }

canonical_original_code: struct _Task *tloop_TREE_WRAP_AUX(struct _Worker *__self, struct _tloop_TREE_TD *t, int a1, int a2, int *a3){ struct _tloop_TREE_TD *post_eval_task; struct _tloop_TREE_TD *v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (struct _Task **) &v_t ); tloop_TREE_CALL( __self , a1, a2, a3 ); post_eval_task = (struct _tloop_TREE_TD *) _wool_swap_link( (struct _Task **) &v_t, (struct _Task *) t ); return (struct _Task *) post_eval_task; }

variable_types: struct _tloop_TREE_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *

variable_types: struct _tloop_TREE_TD { struct _wool_dict_t { struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *

return_type: struct _Task { struct _wool_dict_t { struct _Task *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *

user_defined_types: struct _wool_dict_t { struct _Task *(*f)(struct _Worker *, struct _Task *); int size; }


decompiled_code:
__int64 __fastcall tloop_TREE_WRAP(_QWORD *a1, __int64 a2)
{
return tloop_TREE_WRAP_AUX(a1, a2, *(_DWORD *)(a2 + 32), *(_DWORD *)(a2 + 36), *(_QWORD *)(a2 + 40));
}

original_code: Task* tloop_TREE_WRAP(Worker *__self, tloop_TREE_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int*), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); return tloop_TREE_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int* *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int*) - 1) & ~( __alignof__(int*) - 1 )) ) );}

canonical_original_code: struct _Task *tloop_TREE_WRAP(struct _Worker *__self, struct _tloop_TREE_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int*), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); return tloop_TREE_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int **)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int *) - 1) & ~( __alignof__(int *) - 1 )) ) );}

user_defined_types: struct _tloop_TREE_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; }

user_defined_types: struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


original_code: Task *tloop_TREE_PUB(Worker *self, Task *top, Task *jfp ) { unsigned long ps = self->pr.public_size; int us; grab_res_t res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { tloop_TREE_TD *t = (tloop_TREE_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int*), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); self->pr.pr_top = top; ; tloop_TREE_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int* *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int*) - 1) & ~( __alignof__(int*) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

canonical_original_code: struct _Task *tloop_TREE_PUB(struct _Worker *self, struct _Task *top, struct _Task *jfp) { unsigned long ps = self->pr.public_size; int us; int res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { struct _tloop_TREE_TD *t = (tloop_TREE_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int*), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); self->pr.pr_top = top; ; tloop_TREE_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int **)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int *) - 1) & ~( __alignof__(int *) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

variable_types:
self
struct _Worker *

variable_types:
top
struct _Task *

variable_types:
jfp
struct _Task *

variable_types:
ps
unsigned long

variable_types: us int


decompiled_code:
__int64 __fastcall main_CALL(_QWORD *a1, int a2, const char **a3)
{
const char *v4; // r15
int v5; // er12
int v6; // ebp
int *v7; // rbx
int v8; // er14

if ( a2 <= 3 )
{
fwrite("Usage: dynamic-loop <model> <reps> <trip> <params...>\n", 1uLL, 0x36uLL, stderr);
exit(1);
}
v4 = a3[1];
v5 = atoi(a3[2]);
v6 = atoi(a3[3]);
v7 = (int *)malloc(4LL * v6);
if ( !strcmp(v4, "flute") )
flute(a2 - 5, a3 + 5, v6, v7);
else
fprintf(stderr, "Unknown model: %s\n", v4);
v8 = 0;
if ( v5 > 0 )
{
do
{
tloop_TREE_CALL(a1, 0, v6, (__int64)v7);
++v8;
}
while ( v5 != v8 );
}
free(v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2, const char **a3)
{
const char *v4; // r15
int v5; // er12
int v6; // ebp
int *v7; // rbx
int v8; // er14

if ( a2 <= 3 )
{
fwrite("Usage: dynamic-loop <model> <reps> <trip> <params...>\n", 1uLL, 0x36uLL, stderr);
exit(1);
}
v4 = a3[1];
v5 = atoi(a3[2]);
v6 = atoi(a3[3]);
v7 = (int *)malloc(4LL * v6);
if ( !strcmp(v4, "flute") )
func2(a2 - 5, a3 + 5, v6, v7);
else
fprintf(stderr, "Unknown model: %s\n", v4);
v8 = 0;
if ( v5 > 0 )
{
do
{
func3(a1, 0, v6, (__int64)v7);
++v8;
}
while ( v5 != v8 );
}
free(v7);
return 0LL;
}

original_code: int main_CALL(Worker *_wool_self , int a1, char ** a2) { return main_WRK( _wool_self, 1 , a1, a2 ); }

canonical_original_code: int main_CALL(struct _Worker *_wool_self, int a1, char **a2) { return main_WRK( _wool_self, 1 , a1, a2 ); }


decompiled_code:
__int64 __fastcall main_WRAP_AUX(_QWORD *a1, __int64 a2, int a3, const char **a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

v8 = a2;
*(_DWORD *)(a2 + 40) = 56;
*(_QWORD *)(v8 + 8) = &v8;
v4 = main_CALL(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v6 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
}
}
result = v8;
if ( a2 == v8 )
*(_QWORD *)(v8 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2, int a3, const char **a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

v8 = a2;
*(_DWORD *)(a2 + 40) = 56;
*(_QWORD *)(v8 + 8) = &v8;
v4 = func7(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v6 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
}
}
result = v8;
if ( a2 == v8 )
*(_QWORD *)(v8 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}

original_code: Task* main_WRAP_AUX(Worker *__self, main_TD *t , int a1, char ** a2){ main_TD *post_eval_task; main_TD *volatile v_t = t; int res; t->info.size = sizeof(main_TD); asm volatile( "" ); _wool_save_link( (Task**) &v_t ); res = main_CALL( __self , a1, a2 ); post_eval_task = (main_TD*) _wool_swap_link( (Task *volatile *) &v_t, (Task *) t ); post_eval_task->d.res = res; return (Task *) post_eval_task; }

canonical_original_code: struct _Task *main_WRAP_AUX(struct _Worker *__self, struct _main_TD *t, int a1, char **a2){ struct _main_TD *post_eval_task; struct _main_TD *v_t = t; int res; t->info.size = sizeof(main_TD); asm volatile( "" ); _wool_save_link( (struct _Task **) &v_t ); res = main_CALL( __self , a1, a2 ); post_eval_task = (struct _main_TD *) _wool_swap_link( (struct _Task **) &v_t, (struct _Task *) t ); post_eval_task->d.res = res; return (struct _Task *) post_eval_task; }

variable_types: struct _main_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { int res; } d; } *

variable_types: struct _main_TD { struct _wool_dict_t { struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { int res; } d; } *


decompiled_code:
__int64 __fastcall main_WRAP(_QWORD *a1, __int64 a2)
{
return main_WRAP_AUX(a1, a2, *(_DWORD *)(a2 + 32), *(const char ***)(a2 + 40));
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 a2)
{
return func8(a1, a2, *(_DWORD *)(a2 + 32), *(const char ***)(a2 + 40));
}

original_code: Task* main_WRAP(Worker *__self, main_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(char **), _wool_max( __alignof__(int), 1 ) ) ); return main_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(char ** *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(char **) - 1) & ~( __alignof__(char **) - 1 )) ) );}

canonical_original_code: struct _Task *main_WRAP(struct _Worker *__self, struct _main_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(char **), _wool_max( __alignof__(int), 1 ) ) ); return main_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(char ***)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(char **) - 1) & ~( __alignof__(char **) - 1 )) ) );}

user_defined_types: struct _main_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { int res; } d; }


original_code: Task *main_PUB(Worker *self, Task *top, Task *jfp ) { unsigned long ps = self->pr.public_size; int us; grab_res_t res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { main_TD *t = (main_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(char **), _wool_max( __alignof__(int), 1 ) ) ); self->pr.pr_top = top; ; t->d.res = main_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(char ** *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(char **) - 1) & ~( __alignof__(char **) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

canonical_original_code: struct _Task *main_PUB(struct _Worker *self, struct _Task *top, struct _Task *jfp) { unsigned long ps = self->pr.public_size; int us; int res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { struct _main_TD *t = (main_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(char **), _wool_max( __alignof__(int), 1 ) ) ); self->pr.pr_top = top; ; t->d.res = main_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(char ***)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(char **) - 1) & ~( __alignof__(char **) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

variable_types: res int


work

original_code:
static int work( int leaf_size, int width )
{
  long int *arr = malloc( sizeof(long int) * width );
  long int sum = 0;
  for( int i = 0; i < width; i++ ) {
    ( fanout_SPAWN_DSP( (Worker *) __self, _wool_in_task , leaf_size, arr+i ) );
    loop(1000);
  }
  for( int i = 0; i < width; i++ ) {
    ( fanout_SYNC_DSP( (Worker *) __self, _wool_in_task ) );
  }
  for( int i = 0; i < width; i++ ) {
    sum += arr[i];
  }
  free(arr);
  return sum;
}

canonical_original_code:
static int work(int leaf_size, int width)
{
  long *arr = malloc( sizeof(long int) * width );
  long sum = 0;
  for( int i = 0; i < width; i++ ) {
    ( fanout_SPAWN_DSP( (struct _Worker *) __self, _wool_in_task , leaf_size, arr+i ) );
    loop(1000);
  }
  for( int i = 0; i < width; i++ ) {
    ( fanout_SYNC_DSP( (struct _Worker *) __self, _wool_in_task ) );
  }
  for( int i = 0; i < width; i++ ) {
    sum += arr[i];
  }
  free(arr);
  return sum;
}

variable_types: width int

variable_types:
arr
long *

variable_types: sum long


decompiled_code:
__int64 __fastcall fanout_WRAP_AUX(__int64 a1, __int64 a2, unsigned int a3, _BOOL8 *a4)
{
__int32 v4; // ebx
__int64 v5; // rax
__int64 result; // rax
__int64 v7; // [rsp+8h] [rbp-30h] BYREF

v7 = a2;
*(_DWORD *)(a2 + 40) = 0;
*(_QWORD *)(v7 + 8) = &v7;
fanout_CALL(a1, a3, a4);
v4 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v5 = 1LL;
while ( v4 == 1 )
{
v4 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v5 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v5 = 0LL;
}
}
result = v7;
if ( a2 == v7 )
*(_QWORD *)(v7 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3, _BOOL8 *a4)
{
__int32 v4; // ebx
__int64 v5; // rax
__int64 result; // rax
__int64 v7; // [rsp+8h] [rbp-30h] BYREF

v7 = a2;
*(_DWORD *)(a2 + 40) = 0;
*(_QWORD *)(v7 + 8) = &v7;
func3(a1, a3, a4);
v4 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v5 = 1LL;
while ( v4 == 1 )
{
v4 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v5 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v5 = 0LL;
}
}
result = v7;
if ( a2 == v7 )
*(_QWORD *)(v7 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

original_code: Task* fanout_WRAP_AUX(Worker *__self, fanout_TD *t , int a1, long int * a2){ fanout_TD *post_eval_task; fanout_TD *volatile v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (Task**) &v_t ); fanout_CALL( __self , a1, a2 ); post_eval_task = (fanout_TD*) _wool_swap_link( (Task *volatile *) &v_t, (Task *) t ); return (Task *) post_eval_task; }

canonical_original_code: struct _Task *fanout_WRAP_AUX(struct _Worker *__self, struct _fanout_TD *t, int a1, long *a2){ struct _fanout_TD *post_eval_task; struct _fanout_TD *v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (struct _Task **) &v_t ); fanout_CALL( __self , a1, a2 ); post_eval_task = (struct _fanout_TD *) _wool_swap_link( (struct _Task **) &v_t, (struct _Task *) t ); return (struct _Task *) post_eval_task; }

variable_types: struct _fanout_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *

variable_types: struct _fanout_TD { struct _wool_dict_t { struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *


decompiled_code:
__int64 __fastcall fanout_WRAP(__int64 a1, __int64 a2)
{
return fanout_WRAP_AUX(a1, a2, *(_DWORD *)(a2 + 32), *(_BOOL8 **)(a2 + 40));
}

original_code: Task* fanout_WRAP(Worker *__self, fanout_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(long int *), _wool_max( __alignof__(int), 1 ) ) ); return fanout_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(long int * *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(long int *) - 1) & ~( __alignof__(long int *) - 1 )) ) );}

canonical_original_code: struct _Task *fanout_WRAP(struct _Worker *__self, struct _fanout_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(long int *), _wool_max( __alignof__(int), 1 ) ) ); return fanout_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(long **)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(long *) - 1) & ~( __alignof__(long *) - 1 )) ) );}

user_defined_types: struct _fanout_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; }


original_code: Task *fanout_PUB(Worker *self, Task *top, Task *jfp ) { unsigned long ps = self->pr.public_size; int us; grab_res_t res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { fanout_TD *t = (fanout_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(long int *), _wool_max( __alignof__(int), 1 ) ) ); self->pr.pr_top = top; ; fanout_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(long int * *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(long int *) - 1) & ~( __alignof__(long int *) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

canonical_original_code: struct _Task *fanout_PUB(struct _Worker *self, struct _Task *top, struct _Task *jfp) { unsigned long ps = self->pr.public_size; int us; int res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { struct _fanout_TD *t = (fanout_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(long int *), _wool_max( __alignof__(int), 1 ) ) ); self->pr.pr_top = top; ; fanout_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(long **)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(long *) - 1) & ~( __alignof__(long *) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er14
int v5; // er12
int v6; // ebx
unsigned int v7; // ebp
int result; // eax

if ( (int)wool_init(argc, argv, envp) <= 3 )
{
fwrite("Usage: fanout [<wool opts>] <grain> <width> <reps>\n", 1uLL, 0x33uLL, stderr);
result = 1;
}
else
{
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = atoi(argv[3]);
if ( v5 <= 0 )
{
v7 = 0;
}
else
{
v6 = 0;
v7 = 0;
do
{
v7 += work(v3, v4);
++v6;
}
while ( v5 != v6 );
}
printf("Number of leaves = %d\n", v7);
wool_fini();
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er14
int v5; // er12
int v6; // ebx
unsigned int v7; // ebp
int result; // eax

if ( (int)wool_init(argc, argv, envp) <= 3 )
{
fwrite("Usage: fanout [<wool opts>] <grain> <width> <reps>\n", 1uLL, 0x33uLL, stderr);
result = 1;
}
else
{
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = atoi(argv[3]);
if ( v5 <= 0 )
{
v7 = 0;
}
else
{
v6 = 0;
v7 = 0;
do
{
v7 += func7(v3, v4);
++v6;
}
while ( v5 != v6 );
}
printf("Number of leaves = %d\n", v7);
wool_fini();
result = 0;
}
return result;
}

original_code:
int main( int argc, char **argv )
{
  argc = wool_init( argc, argv );
  if( argc < 4 ) {
    fprintf( stderr, "Usage: fanout [<wool opts>] <grain> <width> <reps>\n" );
    return 1;
  }
  int n = atoi( argv[1] );
  int w = atoi( argv[2] );
  int m = atoi( argv[3] );
  int s = 0;
  for( int i=0; i<m; i++) {
    s += work( n, w );
  }
  printf( "Number of leaves = %d\n", s );
  wool_fini();
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  argc = wool_init( argc, argv );
  if( argc < 4 ) {
    fprintf( stderr, "Usage: fanout [<wool opts>] <grain> <width> <reps>\n" );
    return 1;
  }
  int n = atoi( argv[1] );
  int w = atoi( argv[2] );
  int m = atoi( argv[3] );
  int s = 0;
  for( int i = 0; i<m; i++) {
    s += work( n, w );
  }
  printf( "Number of leaves = %d\n", s );
  wool_fini();
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: n int

variable_types: w int

variable_types: m int

variable_types: s int

variable_types: i int


decompiled_code:
unsigned __int64 __fastcall work_TREE_CALL(_QWORD *a1, int a2, int a3, unsigned int a4)
{
unsigned int v4; // ebx
unsigned __int64 result; // rax
unsigned int v8; // er14
unsigned __int64 v9; // rsi
__int64 v10; // rsi
unsigned __int64 v11; // rsi

v4 = a2;
result = a3 - a2;
if ( result <= 1 )
{
if ( a2 < a3 )
{
do
result = work_LOOP((__int64)a1, v4++, a4);
while ( a3 != v4 );
}
}
else
{
v8 = (a2 + a3) / 2;
v9 = a1[62];
*(_DWORD *)(v9 + 32) = v8;
*(_DWORD *)(v9 + 36) = a3;
*(_DWORD *)(v9 + 40) = a4;
if ( v9 >= a1[54] )
{
v10 = wool_slow_spawn(a1, v9, &work_TREE_DICT);
}
else
{
*(_QWORD *)v9 = &work_TREE_DICT;
v10 = v9 + 128;
}
a1[62] = v10;
work_TREE_CALL(a1, v4, v8, a4);
v11 = a1[62];
if ( a1[53] >= v11 )
{
result = work_TREE_PUB(a1);
}
else
{
a1[62] = v11 - 128;
result = work_TREE_CALL(a1, *(unsigned int *)(v11 - 96), *(unsigned int *)(v11 - 92), *(unsigned int *)(v11 - 88));
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(_QWORD *a1, int a2, int a3, unsigned int a4)
{
unsigned int v4; // ebx
unsigned __int64 result; // rax
unsigned int v8; // er14
unsigned __int64 v9; // rsi
__int64 v10; // rsi
unsigned __int64 v11; // rsi

v4 = a2;
result = a3 - a2;
if ( result <= 1 )
{
if ( a2 < a3 )
{
do
result = func1((__int64)a1, v4++, a4);
while ( a3 != v4 );
}
}
else
{
v8 = (a2 + a3) / 2;
v9 = a1[62];
*(_DWORD *)(v9 + 32) = v8;
*(_DWORD *)(v9 + 36) = a3;
*(_DWORD *)(v9 + 40) = a4;
if ( v9 >= a1[54] )
{
v10 = wool_slow_spawn(a1, v9, &work_TREE_DICT);
}
else
{
*(_QWORD *)v9 = &work_TREE_DICT;
v10 = v9 + 128;
}
a1[62] = v10;
func2(a1, v4, v8, a4);
v11 = a1[62];
if ( a1[53] >= v11 )
{
result = func5(a1);
}
else
{
a1[62] = v11 - 128;
result = func2(a1, *(unsigned int *)(v11 - 96), *(unsigned int *)(v11 - 92), *(unsigned int *)(v11 - 88));
}
}
return result;
}

original_code: void work_TREE_CALL(Worker *_wool_self , int a1, int a2, int a3){ return work_TREE_WRK( _wool_self, 1 , a1, a2, a3 ); }

canonical_original_code: void work_TREE_CALL(struct _Worker *_wool_self, int a1, int a2, int a3){ return work_TREE_WRK( _wool_self, 1 , a1, a2, a3 ); }

variable_types: struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task { struct _wool_dict_t { struct _Task *(*f)(struct _Worker *, struct _Task *); int size; } *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *


decompiled_code:
__int64 __fastcall work_TREE_WRAP_AUX(_QWORD *a1, __int64 a2, int a3, int a4, unsigned int a5)
{
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

v8 = a2;
*(_DWORD *)(a2 + 40) = 0;
*(_QWORD *)(v8 + 8) = &v8;
work_TREE_CALL(a1, a3, a4, a5);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v6 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
}
}
result = v8;
if ( a2 == v8 )
*(_QWORD *)(v8 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2, int a3, int a4, unsigned int a5)
{
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

v8 = a2;
*(_DWORD *)(a2 + 40) = 0;
*(_QWORD *)(v8 + 8) = &v8;
func2(a1, a3, a4, a5);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v6 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
}
}
result = v8;
if ( a2 == v8 )
*(_QWORD *)(v8 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

original_code: Task* work_TREE_WRAP_AUX(Worker *__self, work_TREE_TD *t , int a1, int a2, int a3){ work_TREE_TD *post_eval_task; work_TREE_TD *volatile v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (Task**) &v_t ); work_TREE_CALL( __self , a1, a2, a3 ); post_eval_task = (work_TREE_TD*) _wool_swap_link( (Task *volatile *) &v_t, (Task *) t ); return (Task *) post_eval_task; }

canonical_original_code: struct _Task *work_TREE_WRAP_AUX(struct _Worker *__self, struct _work_TREE_TD *t, int a1, int a2, int a3){ struct _work_TREE_TD *post_eval_task; struct _work_TREE_TD *v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (struct _Task **) &v_t ); work_TREE_CALL( __self , a1, a2, a3 ); post_eval_task = (struct _work_TREE_TD *) _wool_swap_link( (struct _Task **) &v_t, (struct _Task *) t ); return (struct _Task *) post_eval_task; }

variable_types: struct _work_TREE_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *

variable_types: struct _work_TREE_TD { struct _wool_dict_t { struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *


decompiled_code:
__int64 __fastcall work_TREE_WRAP(_QWORD *a1, __int64 a2)
{
return work_TREE_WRAP_AUX(a1, a2, *(_DWORD *)(a2 + 32), *(_DWORD *)(a2 + 36), *(_DWORD *)(a2 + 40));
}

original_code: Task* work_TREE_WRAP(Worker *__self, work_TREE_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); return work_TREE_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ) );}

canonical_original_code: struct _Task *work_TREE_WRAP(struct _Worker *__self, struct _work_TREE_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); return work_TREE_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ) );}

user_defined_types: struct _work_TREE_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; }


original_code: Task *work_TREE_PUB(Worker *self, Task *top, Task *jfp ) { unsigned long ps = self->pr.public_size; int us; grab_res_t res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { work_TREE_TD *t = (work_TREE_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); self->pr.pr_top = top; ; work_TREE_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

canonical_original_code: struct _Task *work_TREE_PUB(struct _Worker *self, struct _Task *top, struct _Task *jfp) { unsigned long ps = self->pr.public_size; int us; int res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { struct _work_TREE_TD *t = (work_TREE_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); self->pr.pr_top = top; ; work_TREE_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

variable_types:
self
struct _Worker *

variable_types:
top
struct _Task *

variable_types:
jfp
struct _Task *

variable_types:
ps
unsigned long

variable_types: us int

user_defined_types: struct _Worker { struct _Worker_private pr; char pad1[-1]; struct _Worker_public pu; char pad2[-1]; }


decompiled_code:
__int64 __fastcall main_CALL(_QWORD *a1, __int64 a2, const char **a3)
{
unsigned int v4; // er12
unsigned int v5; // er13
int v6; // ebp
int i; // ebx

v4 = atoi(a3[1]);
v5 = atoi(a3[2]);
v6 = atoi(a3[3]);
if ( v6 > 0 )
{
for ( i = 0; i != v6; ++i )
work_TREE_CALL(a1, 0, v5, v4);
}
printf("%d %d %d\n", v4, v5, (unsigned int)v6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2, const char **a3)
{
unsigned int v4; // er12
unsigned int v5; // er13
int v6; // ebp
int i; // ebx

v4 = atoi(a3[1]);
v5 = atoi(a3[2]);
v6 = atoi(a3[3]);
if ( v6 > 0 )
{
for ( i = 0; i != v6; ++i )
func2(a1, 0, v5, v4);
}
printf("%d %d %d\n", v4, v5, (unsigned int)v6);
return 0LL;
}

user_defined_types: struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; }


decompiled_code:
__int64 __fastcall main_WRAP_AUX(_QWORD *a1, __int64 a2, unsigned int a3, const char **a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

v8 = a2;
*(_DWORD *)(a2 + 40) = 56;
*(_QWORD *)(v8 + 8) = &v8;
v4 = main_CALL(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v6 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
}
}
result = v8;
if ( a2 == v8 )
*(_QWORD *)(v8 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, __int64 a2, unsigned int a3, const char **a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

v8 = a2;
*(_DWORD *)(a2 + 40) = 56;
*(_QWORD *)(v8 + 8) = &v8;
v4 = func6(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v6 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
}
}
result = v8;
if ( a2 == v8 )
*(_QWORD *)(v8 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}

variable_types: struct _main_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { int res; } d; } *

variable_types: struct _main_TD { struct _wool_dict_t { struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { int res; } d; } *

variable_types: res int

user_defined_types: struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t work_available; void *(*fun)(void *); void *fun_arg; }


canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
return func7(a1, a2, *(_DWORD *)(a2 + 32), *(const char ***)(a2 + 40));
}

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


fib

original_code:
static long fib( long n )
{
   if( n < 2 ) {
      return n;
   } else {
      long k = fib( n-2 );
      long m = fib( n-1 );
      return m+k;
   }
}

canonical_original_code:
static long fib(long n)
{
   if( n < 2 ) {
      return n;
   } else {
      long k = fib( n-2 );
      long m = fib( n-1 );
      return m+k;
   }
}

variable_types: n long

variable_types: k long

variable_types: m long

return_type: long


main

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

if ( argc <= 1 )
{
fwrite("Usage: seqfib <arg>\n", 1uLL, 0x14uLL, stderr);
exit(2);
}
v3 = atol(argv[1]);
v4 = fib(v3);
printf("%ld\n", v4);
return 0;
}

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

if ( argc <= 1 )
{
fwrite("Usage: seqfib <arg>\n", 1uLL, 0x14uLL, stderr);
exit(2);
}
v3 = atol(argv[1]);
v4 = func7(v3);
printf("%ld\n", v4);
return 0;
}

original_code:
int main( int argc, char **argv )
{
   if( argc < 2 ) {
      fprintf( stderr, "Usage: seqfib <arg>\n" ),
      exit( 2 );
   }
   long n = atol( argv[ 1 ] );
   long m = fib( n );
   printf( "%ld\n", m );
   return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
   if( argc < 2 ) {
      fprintf( stderr, "Usage: seqfib <arg>\n" ),
      exit( 2 );
   }
   long n = atol( argv[ 1 ] );
   long m = fib( n );
   printf( "%ld\n", m );
   return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall main_CALL(_QWORD *a1, int a2, __int64 a3)
{
__int64 v3; // rax
__int64 v4; // rax

if ( a2 <= 1 )
{
fwrite("Usage: fib <woolopt>... <arg>\n", 1uLL, 0x1EuLL, stderr);
exit(2);
}
v3 = atol(*(const char **)(a3 + 8));
v4 = pfib_CALL(a1, v3);
printf("%ld\n", v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, int a2, __int64 a3)
{
__int64 v3; // rax
__int64 v4; // rax

if ( a2 <= 1 )
{
fwrite("Usage: fib <woolopt>... <arg>\n", 1uLL, 0x1EuLL, stderr);
exit(2);
}
v3 = atol(*(const char **)(a3 + 8));
v4 = func3(a1, v3);
printf("%ld\n", v4);
return 0LL;
}

user_defined_types: struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; }


decompiled_code:
__int64 __fastcall main_WRAP_AUX(_QWORD *a1, __int64 a2, int a3, __int64 a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

v8 = a2;
*(_DWORD *)(a2 + 40) = 56;
*(_QWORD *)(v8 + 8) = &v8;
v4 = main_CALL(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v6 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
}
}
result = v8;
if ( a2 == v8 )
*(_QWORD *)(v8 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 a2, int a3, __int64 a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

v8 = a2;
*(_DWORD *)(a2 + 40) = 56;
*(_QWORD *)(v8 + 8) = &v8;
v4 = func8(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
if ( ++v6 > 999999999 )
{
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
}
}
result = v8;
if ( a2 == v8 )
*(_QWORD *)(v8 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}

user_defined_types: struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; }


decompiled_code:
__int64 __fastcall main_WRAP(_QWORD *a1, __int64 a2)
{
return main_WRAP_AUX(a1, a2, *(_DWORD *)(a2 + 32), *(_QWORD *)(a2 + 40));
}

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }


user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


repo: kfprimm/craftcore

decompiled_code:
__int64 __fastcall cc_render_2d(int a1, int a2)
{
glDisable(2929LL);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(0.0, (double)a1, (double)a2, 0.0, 0.0, 1.0);
glMatrixMode(5888LL);
return glLoadIdentity();
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
glDisable(2929LL);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(0.0, (double)a1, (double)a2, 0.0, 0.0, 1.0);
glMatrixMode(5888LL);
return glLoadIdentity();
}

original_code:
void cc_render_2d(int width, int height)
{
 glDisable(0x0B71);
 glMatrixMode(0x1701);
 glLoadIdentity();
 glOrtho(0, width, height, 0, 0, 1);
 glMatrixMode (0x1700);
 glLoadIdentity();
}

variable_types: width int

variable_types: height int


decompiled_code:
__int64 cc_render_3d()
{
glEnable(2929LL);
glEnable(2884LL);
glEnable(3089LL);
glEnableClientState(32884LL);
glEnableClientState(32888LL);
glEnableClientState(32886LL);
glClearDepth(1.0);
glDepthFunc(515LL);
glHint(3152LL, 4354LL);
return glAlphaFunc(518LL, 0.5);
}

canonical_decompiled_code:
__int64 func1()
{
glEnable(2929LL);
glEnable(2884LL);
glEnable(3089LL);
glEnableClientState(32884LL);
glEnableClientState(32888LL);
glEnableClientState(32886LL);
glClearDepth(1.0);
glDepthFunc(515LL);
glHint(3152LL, 4354LL);
return glAlphaFunc(518LL, 0.5);
}

original_code:
void cc_render_3d()
{
 glEnable(0x0B71);
 glEnable(0x0B44);
 glEnable(0x0C11);
 glEnableClientState(0x8074);
 glEnableClientState(0x8078);
 glEnableClientState(0x8076);
 glClearDepth(1.0);
 glDepthFunc(0x0203);
 glHint(0x0C50, 0x1102);
 glAlphaFunc(0x0206,0.5f);
}


decompiled_code:
__int64 cc_startup_render()
{
return glewInit();
}

canonical_decompiled_code:
__int64 func2()
{
return glewInit();
}

original_code:
void cc_startup_render()
{
 glewInit();
}


original_code:
static void normalize2(float v[2])
{
 float s;
 s = sqrt(v[0] * v[0] + v[1] * v[1]);
 v[0] = v[0] / s;
 v[1] = v[1] / s;
}

variable_types:
v
float [2]

variable_types: s float


decompiled_code:
double __fastcall noise1(double a1)
{
__m128i v1; // xmm5
float v2; // ebx
int v3; // eax
float v4; // xmm0_4
float v5; // xmm4_4
float v6; // xmm1_4
float v7; // xmm0_4

v1 = 0LL;
*(float *)v1.m128i_i32 = a1;
v2 = COERCE_FLOAT(_mm_cvtsi128_si32(v1));
if ( start )
{
start = 0;
init();
}
v3 = (int)(float)(v2 + 4096.0);
v4 = (float)(v2 + 4096.0) - (float)v3;
v5 = v4 * g1[p[(unsigned __int8)v3]];
v6 = (float)((float)(v4 - 1.0) * g1[p[(unsigned __int8)(v3 + 1)]]) - v5;
v7 = (float)(v4 * v4) * (3.0 - (v4 + v4));
return (float)((float)(v7 * v6) + v5);
}

canonical_decompiled_code:
double __fastcall func3(double a1)
{
__m128i v1; // xmm5
float v2; // ebx
int v3; // eax
float v4; // xmm0_4
float v5; // xmm4_4
float v6; // xmm1_4
float v7; // xmm0_4

v1 = 0LL;
*(float *)v1.m128i_i32 = a1;
v2 = COERCE_FLOAT(_mm_cvtsi128_si32(v1));
if ( start )
{
start = 0;
func2();
}
v3 = (int)(float)(v2 + 4096.0);
v4 = (float)(v2 + 4096.0) - (float)v3;
v5 = v4 * g1[p[(unsigned __int8)v3]];
v6 = (float)((float)(v4 - 1.0) * g1[p[(unsigned __int8)(v3 + 1)]]) - v5;
v7 = (float)(v4 * v4) * (3.0 - (v4 + v4));
return (float)((float)(v7 * v6) + v5);
}

original_code:
double noise1(double arg)
{
 int bx0, bx1;
 float rx0, rx1, sx, t, u, v, vec[1];
 vec[0] = arg;
 if (start) {
  start = 0;
  init();
 }
 t = vec[0] + 0x1000; bx0 = ((int)t) & 0xff; bx1 = (bx0+1) & 0xff; rx0 = t - (int)t; rx1 = rx0 - 1.;;
 sx = ( rx0 * rx0 * (3. - 2. * rx0) );
 u = rx0 * g1[ p[ bx0 ] ];
 v = rx1 * g1[ p[ bx1 ] ];
 return ( u + sx * (v - u) );
}

canonical_original_code:
double noise1(double arg)
{
 int bx0; int bx1;
 float rx0; float rx1; float sx; float t; float u; float v; float vec[1];
 vec[0] = arg;
 if (start) {
  start = 0;
  init();
 }
 t = vec[0] + 0x1000; bx0 = ((int)t) & 0xff; bx1 = (bx0+1) & 0xff; rx0 = t - (int)t; rx1 = rx0 - 1.;;
 sx = ( rx0 * rx0 * (3. - 2. * rx0) );
 u = rx0 * g1[ p[ bx0 ] ];
 v = rx1 * g1[ p[ bx1 ] ];
 return ( u + sx * (v - u) );
}

variable_types: arg double

variable_types: sx float

variable_types: t float

variable_types: u float

variable_types: v float

variable_types:
vec
float [1]

return_type: double


canonical_original_code:
float noise2(float vec[2])
{
 int bx0; int bx1; int by0; int by1; int b00; int b10; int b01; int b11;
 float rx0; float rx1; float ry0; float ry1; float *q; float sx; float sy; float a; float b; float t; float u; float v;
 register int i; register int j;
 if (start) {
  start = 0;
  init();
 }
 t = vec[0] + 0x1000; bx0 = ((int)t) & 0xff; bx1 = (bx0+1) & 0xff; rx0 = t - (int)t; rx1 = rx0 - 1.;;
 t = vec[1] + 0x1000; by0 = ((int)t) & 0xff; by1 = (by0+1) & 0xff; ry0 = t - (int)t; ry1 = ry0 - 1.;;
 i = p[ bx0 ];
 j = p[ bx1 ];
 b00 = p[ i + by0 ];
 b10 = p[ j + by0 ];
 b01 = p[ i + by1 ];
 b11 = p[ j + by1 ];
 sx = ( rx0 * rx0 * (3. - 2. * rx0) );
 sy = ( ry0 * ry0 * (3. - 2. * ry0) );
 q = g2[ b00 ] ; u = ( rx0 * q[0] + ry0 * q[1] );
 q = g2[ b10 ] ; v = ( rx1 * q[0] + ry0 * q[1] );
 a = ( u + sx * (v - u) );
 q = g2[ b01 ] ; u = ( rx0 * q[0] + ry1 * q[1] );
 q = g2[ b11 ] ; v = ( rx1 * q[0] + ry1 * q[1] );
 b = ( u + sx * (v - u) );
 return ( a + sy * (b - a) );
}

variable_types:
vec
float [2]

variable_types:
q
float *

variable_types: sy float

variable_types: a float

variable_types: b float

variable_types: i int

variable_types: j int

return_type: float