// File: /workspace/github_c_makefile_star2_O3/Ziddykins[P]Dawn/src/main.c
// Function: main
int main (int argc, char **argv) {
    //For getops();
    int opt;

    //Default settings for the bot
    //These will be overwritten if a configuration file is found
    //or values are specified on the command line
    char *monsters = "monsters.raw";
    char *port     = "6667";
    char *server   = "irc.dal.net";
    //char *password = "none";
    int mflag, sflag, pflag;
    mflag = sflag = pflag = 0;

    //The bot structure it self
    CALLEXIT(!(dawn = calloc(1, sizeof *dawn)))

    //Initial settings
    strncpy(dawn->nickname, "Dawn-19", MAX_NICK_LENGTH);
    strcpy(dawn->realname, "dongs");
    strcpy(dawn->ident,    "hehe");
    strcpy(dawn->password, "temp");
    strncpy(dawn->active_room, "#stacked", MAX_CHANNEL_LENGTH);

    //Load players
    persistent_load();

    while ((opt = getopt(argc, argv, "hm:n:p:r:s:")) != -1) {
        switch (opt) {
            case 'h': //print help
                print_usage(argv);
                return 0;
            case 'm': //raw monsters file
                CALLEXIT(!(monsters = malloc(strlen(optarg) + 1)))
                strcpy(monsters, optarg);
                mflag = 1;
                break;
            case 'n': //bot's nickname
                strncpy(dawn->nickname, optarg, MAX_NICK_LENGTH-1);
                break;
            case 'p': //server port
                CALLEXIT(!(port = malloc(strlen(optarg) + 1)))
                strcpy(port, optarg);
                pflag = 1;
                break;
            case 'r': //room to join
                dawn->active_room[0] = '#';
                strncpy(dawn->active_room+1, optarg, MAX_CHANNEL_LENGTH-2);
                break;
            case 's': //server to connect to
                CALLEXIT(!(server = malloc(16))) //do we need IPV6 support?
                hostname_to_ip(optarg, server);  //network.c
                sflag = 1;
                break;
            case 'w': //nickserv password
                strncpy(dawn->password, optarg, 64-1);
                break;
            default:
                print_usage(argv);
                return 1;
        }
    }

    FILE *urandom;
    CALLEXIT(!(urandom = fopen("/dev/urandom", "r")))

    unsigned int seed;
    CALLEXIT(!(fread(&seed, sizeof (seed), 1, urandom)))
    srand(seed);
    fclose(urandom);

    FILE *auth_key_file;
    CALLEXIT(!(auth_key_file = fopen("auth_key.txt", "w")))
    CALLEXIT(!(auth_key = calloc(AUTH_KEY_LEN+1, 1)))

    for(size_t i = 0; i < AUTH_KEY_LEN; i++) {
        do {
            auth_key[i] = (char)(rand() % 32);
        } while(auth_key[i] >= 26);

        if (rand()%2) {
            auth_key[i] += 'a';
        } else {
            auth_key[i] += 'A';
        }
    }

    CALLEXIT(!(fwrite(auth_key, AUTH_KEY_LEN, sizeof *auth_key, auth_key_file)))

    fclose(auth_key_file);

    printf(INFO "auth_key: %s\n", auth_key);
    auth_key_valid = 1;

    int match;
    ssize_t len;

    if (access(monsters, F_OK) != -1) {
        FILE *file = fopen(monsters, "r");
        char line[MAX_MESSAGE_BUFFER];
        char name[MAX_MONSTER_LENGTH];
        int count = 0;
        int hp, str, def, intel, mdef, gold, exp, mhp, drop_level;

        if (!file) {
            fprintf(stderr, ERR "Error opening raw monsters\n");
            return 1;
        }
        while (fgets(line, sizeof(line), file)) {
            //TODO: Add ranges to raw files
            if (sscanf(line, "%[^:]:%d:%d:%d:%d:%d:%d:%d:%d:%d",
                    name, &hp, &str, &def, &intel, &mdef, &gold, &exp, &mhp, &drop_level) != 10) {
                fprintf(stderr, ERR "main: Malformed monster file at line %d\n", count);
                return 1;
            }
            strncpy(dawn->monsters[count].name, name, 64);
            dawn->monsters[count].hp         = hp;
            dawn->monsters[count].str        = str;
            dawn->monsters[count].def        = def;
            dawn->monsters[count].intel      = intel;
            dawn->monsters[count].mdef       = mdef;
            dawn->monsters[count].gold       = gold;
            dawn->monsters[count].exp        = exp;
            dawn->monsters[count].mhp        = mhp;
            dawn->monsters[count].drop_level = drop_level;
            dawn->monsters[count].slay_cost  = gold;
            dawn->monsters[count].active     = 0;
            dawn->monsters[count].type       = DEFMON;
            dawn->monsters[count].alignment  = NEUTRAL;
            count++;
        }
        fclose(file);
    }

    dawn->login_sent = 0;
    dawn->in_rooms   = 0;

    init_send_queue();
    init_cmds();

    if (init_connect_server(server, port) == 0) {
        while ((len = recv(con_socket, buffer, MAX_RECV_BUFFER, 0)) != -1) {
            char out[MAX_MESSAGE_BUFFER];
            buffer[len] = '\0';

            //Handle keepalive pings from the server
            if (matches_regex(buffer, "PING :(.*)")) {
                printf("PONG: %s\n", regex_group[1]);
                sprintf(out, "PONG :%s\r\n", regex_group[1]);
                add_msg(out, strlen(out));
            }

            //Connected to the server, send nick/user details
            if (dawn->login_sent == 0) {
                match = matches_regex(buffer, "AUTH") || matches_regex(buffer, "Looking up your hostname...");
                if (match) {
                    printf(INFO "Server checking for AUTH, sending nick/user\n");
                    handle_login(dawn->nickname, dawn->password, dawn->realname, dawn->ident);
                    dawn->login_sent = 1;
                }
            }

            //Nickname is in use, add a random suffix
            if (matches_regex(buffer, ":.*?\\s433\\s*\\s.*")) {
                int rand_suffix = rand() % 10;
                size_t nicklen = strlen(dawn->nickname);

                fprintf(stderr, WARN "Username %s in use\n", dawn->nickname);
                snprintf(dawn->nickname+nicklen, MAX_NICK_LENGTH-nicklen, "%d", rand_suffix);
                handle_login(dawn->nickname, dawn->password, dawn->realname, dawn->ident);
            }


            //If we're logged in and we're received a
            //welcome message, join the rooms
            if (!dawn->in_rooms && dawn->login_sent == 1) {
                match = matches_regex(buffer, ":(.*?)\\s001(.*)");

                if (match) {
                    printf(INFO "Got welcome message from server, joining rooms\n");
                    sprintf(out, "JOIN %s\r\n", dawn->active_room);
                    fluctuate_market();
                    add_msg(out, strlen(out));
                    dawn->in_rooms = 1;
                }
            }

            //Upon joining rooms the bot will search for status 353, which is names, and will
            //iterate through the online people, setting their status to available if they
            //have an account on the bot
            if (dawn->in_rooms) {
                struct Message message;

                //Set lengths based on server rather than assuming
                if (matches_regex(buffer, ":.*?005.*?CHANNELLEN=(\\d+)\\s.*?NICKLEN=(\\d+)")) {
                    MAX_CHANNEL_LENGTH = (unsigned int)strtoul(regex_group[1], 0, 10) + 1;
                    MAX_NICK_LENGTH    = (unsigned int)strtoul(regex_group[2], 0, 10) + 1;
                    dawn->nickname[MAX_NICK_LENGTH] = '\0';
                    dawn->active_room[MAX_CHANNEL_LENGTH] = '\0';
                }

                //Check if user is identified
                if (matches_regex(buffer, ":(.*?)\\s307\\s(.*?)\\s(.*?)\\s:")) {
                    int pindex = get_pindex(regex_group[3]);

                    if (pindex != -1 && (dawn->players[pindex].max_auth > AL_USER || dawn->players[pindex].auth_level > AL_NOAUTH)) {
                        if (dawn->players[pindex].max_auth < AL_REG) { //upgrade
                            dawn->players[pindex].max_auth = AL_REG;
                        }

                        if (dawn->players[pindex].auth_level < dawn->players[pindex].max_auth) {
                            dawn->players[pindex].auth_level = dawn->players[pindex].max_auth;
                            snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s has been verified. (%s)\r\n",
                                dawn->active_room,
                                dawn->players[pindex].username,
                                auth_level_to_str((enum auth_level)(dawn->players[pindex].auth_level)));
                            add_msg(out, strlen(out));
                        } else {
                            snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s is already verified. (%s)\r\n",
                                dawn->active_room,
                                dawn->players[pindex].username,
                                auth_level_to_str((enum auth_level)(dawn->players[pindex].auth_level)));
                            add_msg(out, strlen(out));
                        }
                    }
                }

                //NAMES (Status 353)
                //This will split up the received users in the room and set
                //their status availability to 1, stripping their name of status symbols
                //and converting their username to lowercase
                if (matches_regex(buffer, ":(.*?)\\s353\\s(.*?)\\s@\\s(.*?)\\s:(.*)")) {
                    char *ch_ptr;
                    ch_ptr = strtok(regex_group[4], " @&+");
                    while (ch_ptr != NULL) {
                        int index = get_pindex(to_lower(ch_ptr));
                        if (index != -1){
                            dawn->players[index].available = 1;
                            dawn->players[index].auth_level = AL_NOAUTH;
                            sprintf(out, "WHOIS %s\r\n", dawn->players[index].username);
                            add_msg(out, strlen(out));
                        }
                        ch_ptr = strtok(NULL, " @&+\r\n");
                    }
                }

                //Kicks
                if (matches_regex(buffer, ":(.*?)!~?(.*?)@(.*?)\\s(\\w+)\\s(.*?)\\s(.*?)\\s:(.*)")) {
                    if (strcmp(regex_group[4], "KICK") == 0) {
                        int index = get_pindex(to_lower(regex_group[6]));
                        if (index != -1) {
                            dawn->players[index].available = 0;
                            dawn->players[index].auth_level = AL_NOAUTH;
                        }
                    }
                }

                //Nick changes
                if (matches_regex(buffer, ":(.*?)!~?.*?@.*?\\sNICK\\s:(.*?)\r\n")) {
                    int oldindex = get_pindex(to_lower(regex_group[1]));
                    int newindex = get_pindex(to_lower(regex_group[2]));
                    if (oldindex != -1) {
                        dawn->players[oldindex].available = 0;
                        dawn->players[oldindex].auth_level = AL_NOAUTH;
                    }
                    if (newindex != -1) {
                        dawn->players[newindex].available = 1;
                        dawn->players[newindex].auth_level = AL_NOAUTH;
                    }
                }

                //Parting and joining
                if (matches_regex(buffer, ":(.*?)!~?(.*?)@(.*?)\\s(.*?)\\s(.*?)")) {
                    int pindex = get_pindex(to_lower(regex_group[1]));
                    if (pindex != -1) {
                        if (strcmp(regex_group[4], "PART") == 0) {
                            dawn->players[pindex].available = 0;
                            dawn->players[pindex].auth_level = AL_NOAUTH;
                        } else if (strcmp(regex_group[4], "JOIN") == 0) {
                            dawn->players[pindex].available = 1;
                            dawn->players[pindex].auth_level = AL_NOAUTH;
                            sprintf(out, "WHOIS %s\r\n", regex_group[1]);
                            add_msg(out, strlen(out));
                        } else if (strcmp(regex_group[4], "QUIT") == 0) {
                            dawn->players[pindex].available = 0;
                        }
                    }
                    if (dawn->player_count == 0) {
                        struct Message temp;
                        strncpy(temp.sender_nick, dawn->nickname, MAX_NICK_LENGTH);
                        strncpy(temp.sender_hostmask, regex_group[3], MAX_HOSTNAME_LENGTH);
                        init_new_character(&temp);
                    }
                }

                //Regular messages and notices
                if (matches_regex(buffer, ":(.*?)!~?(.*?)@(.*?)\\s(.*?)\\s(.*?)\\s:(.*)\r\n")) {
                    strncpy(message.sender_nick,     to_lower(regex_group[1]), MAX_NICK_LENGTH);
                    strncpy(message.sender_ident,    regex_group[2], MAX_IDENT_LENGTH);
                    strncpy(message.sender_hostmask, regex_group[3], MAX_HOSTNAME_LENGTH);
                    strncpy(message.receiver,        regex_group[5], MAX_NICK_LENGTH);
                    strncpy(message.message,         regex_group[6], MAX_MESSAGE_BUFFER);

                    if (strcmp(regex_group[4], "PRIVMSG") == 0) {
                        if (matches_regex(message.message, CMD_LIT)) {
                            if (message.receiver[0] == '#') {
                                invoke_cmd(0, get_pindex(message.sender_nick), regex_group[0], &message, CMD_EXEC);
                            } else {
                                parse_private_message(&message);
                            }
                        }
                    } else if (strcmp(regex_group[4], "NOTICE") == 0) {
                    //    parse_notice_message(&message);
                    }
                }
            }
            bzero(buffer, MAX_MESSAGE_BUFFER);
        }
    } else {
        perror(ERR "main: Failed to connect");
        close(con_socket);
        return 1;
    }

    if (len != -1) {
        close(con_socket);
    }

    if (sflag) {
         free(server);
    }

    if (pflag) {
        free(port);
    }

    if (mflag) {
        free(monsters);
    }

    free_msg_hist_list();
    free_msg_list();
    free_event_list();
    free_cmds();
    free_map();
    free(dawn);

    if (auth_key_valid || auth_key) {
        free(auth_key);
    }

    printf(INFO "Program exiting normally [%s]\n", timestamp());

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1408, %rsp           # imm = 0x1408
movq %rsi, %rbx
movl %edi, %ebp
movl $0x1, %edi
movl $0xf2eb8, %esi          # imm = 0xF2EB8
callq 0x2110
leaq 0x18fa0(%rip), %r15     # 0x21a80
movq %rax, (%r15)
testq %rax, %rax
je 0x97fc
movq %rax, %r14
movl 0x1676f(%rip), %edx     # 0x1f264
leaq 0xbd0e(%rip), %rsi      # 0x1480a
movq %rax, %rdi
callq 0x20e0
movl $0x676e6f64, 0x40(%r14) # imm = 0x676E6F64
movw $0x73, 0x44(%r14)
xorl %eax, %eax
movb %al, 0x84(%r14)
movl $0x65686568, 0x80(%r14) # imm = 0x65686568
movl $0x0, (%rsp)
movb %al, 0xc4(%r14)
movl $0x706d6574, 0xc0(%r14) # imm = 0x706D6574
addq $0x100, %r14            # imm = 0x100
movl 0x16713(%rip), %edx     # 0x1f260
leaq 0xbcce(%rip), %rsi      # 0x14822
movq %r14, %rdi
callq 0x20e0
callq 0xda43
leaq 0xbc40(%rip), %rax      # 0x147a8
movq %rax, 0x10(%rsp)
leaq 0xbc41(%rip), %rax      # 0x147b5
movq %rax, 0x18(%rsp)
leaq 0xbc3a(%rip), %rax      # 0x147ba
movq %rax, 0x20(%rsp)
movb $0x1, %al
movl %eax, 0x4(%rsp)
leaq 0xbc99(%rip), %r14      # 0x1482b
leaq 0xbbcf(%rip), %r13      # 0x14768
movq 0x16420(%rip), %r12     # 0x1efc0
movl $0x0, 0x8(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2060
leal -0x68(%rax), %ecx
cmpl $0xf, %ecx
ja 0x8cd5
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movq (%r15), %rdi
movq (%r12), %rsi
movl 0x1668c(%rip), %edx     # 0x1f264
decl %edx
callq 0x20e0
jmp 0x8ba8
movq (%r15), %rdi
movb $0x23, 0x100(%rdi)
addq $0x101, %rdi            # imm = 0x101
movq (%r12), %rsi
movl 0x16664(%rip), %edx     # 0x1f260
addl $-0x2, %edx
callq 0x20e0
jmp 0x8ba8
movq (%r15), %rdi
movl $0xc0, %eax
addq %rax, %rdi
movq (%r12), %rsi
movl $0x3f, %edx
callq 0x20e0
jmp 0x8ba8
movq (%r12), %r15
movq %r15, %rdi
callq 0x20c0
leaq 0x1(%rax), %rdi
callq 0x22b0
testq %rax, %rax
je 0x9806
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq %r15, %rsi
callq 0x21c0
movl $0x0, 0x4(%rsp)
leaq 0x18e22(%rip), %r15     # 0x21a80
jmp 0x8ba8
movq (%r12), %r15
movq %r15, %rdi
callq 0x20c0
leaq 0x1(%rax), %rdi
callq 0x22b0
testq %rax, %rax
je 0x980b
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r15, %rsi
callq 0x21c0
movl $0x1, 0x8(%rsp)
leaq 0x18de0(%rip), %r15     # 0x21a80
jmp 0x8ba8
movl $0x10, %edi
callq 0x22b0
testq %rax, %rax
je 0x9801
movq (%r12), %rdi
movq %rax, 0x20(%rsp)
movq %rax, %rsi
callq 0xd1b3
movl $0x1, (%rsp)
jmp 0x8ba8
cmpl $-0x1, %eax
jne 0x96ff
leaq 0xbc1d(%rip), %rdi      # 0x14902
leaq 0xb707(%rip), %rsi      # 0x143f3
callq 0x2230
testq %rax, %rax
je 0x9810
movq %rax, %rbx
leaq 0x44(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x2320
testq %rax, %rax
je 0x9815
movl 0x44(%rsp), %edi
callq 0x21d0
movq %rbx, %rdi
callq 0x21f0
leaq 0xbc71(%rip), %rdi      # 0x149a6
leaq 0xba77(%rip), %rsi      # 0x147b3
callq 0x2230
testq %rax, %rax
je 0x981a
movq %rax, %rbx
movl $0x19, %edi
movl $0x1, %esi
callq 0x2110
movq %rax, 0x16525(%rip)     # 0x1f288
testq %rax, %rax
je 0x981f
xorl %r14d, %r14d
callq 0x2080
leal 0x1f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $0xe0, %ecx
subl %ecx, %eax
movq 0x164fd(%rip), %rcx     # 0x1f288
movb %al, (%rcx,%r14)
movq 0x164f2(%rip), %rax     # 0x1f288
cmpb $0x19, (%rax,%r14)
jg 0x8d6f
callq 0x2080
movq 0x164df(%rip), %rcx     # 0x1f288
andb $0x1, %al
shlb $0x5, %al
addb (%rcx,%r14), %al
addb $0x41, %al
movb %al, (%rcx,%r14)
incq %r14
cmpq $0x18, %r14
jne 0x8d6f
movq 0x164c0(%rip), %rdi     # 0x1f288
movl $0x18, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2480
testq %rax, %rax
je 0x9824
movq %rbx, %rdi
callq 0x21f0
movq 0x16496(%rip), %rsi     # 0x1f288
leaq 0xbcba(%rip), %rdi      # 0x14ab3
xorl %eax, %eax
callq 0x2040
leaq 0x16479(%rip), %rax     # 0x1f280
movl $0x1, (%rax)
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x23d0
cmpl $-0x1, %eax
je 0x8f8e
leaq 0xb5ca(%rip), %rsi      # 0x143f3
movq 0x10(%rsp), %rdi
callq 0x2230
testq %rax, %rax
je 0x97d3
movq %rax, %rbx
leaq 0x200(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rax, %rdx
callq 0x2380
testq %rax, %rax
je 0x8f7f
movl $0xf1b40, %r12d         # imm = 0xF1B40
leaq 0x200(%rsp), %r15
leaq 0xb00(%rsp), %r14
xorl %ebp, %ebp
movq %r15, %rdi
leaq 0xbc84(%rip), %rsi      # 0x14b03
movq %r14, %rdx
leaq 0x70(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x3c(%rsp), %r9
xorl %eax, %eax
leaq 0x28(%rsp), %r10
pushq %r10
leaq 0x34(%rsp), %r10
pushq %r10
leaq 0x40(%rsp), %r10
pushq %r10
leaq 0x24(%rsp), %r10
pushq %r10
leaq 0x54(%rsp), %r10
pushq %r10
leaq 0x60(%rsp), %r10
pushq %r10
callq 0x21e0
addq $0x30, %rsp
cmpl $0xa, %eax
jne 0x97dd
leaq 0x18baa(%rip), %r13     # 0x21a80
movq (%r13), %rdi
addq %r12, %rdi
movl $0x40, %edx
movq %r14, %rsi
callq 0x20e0
movl 0x70(%rsp), %eax
movq (%r13), %rcx
movl %eax, 0x40(%rcx,%r12)
movl 0x40(%rsp), %eax
movl %eax, 0x4c(%rcx,%r12)
movl 0x3c(%rsp), %eax
movl %eax, 0x48(%rcx,%r12)
movl 0x38(%rsp), %eax
movl %eax, 0x50(%rcx,%r12)
movl 0x34(%rsp), %eax
movl %eax, 0x54(%rcx,%r12)
movl 0xc(%rsp), %eax
movl %eax, 0x58(%rcx,%r12)
movl 0x30(%rsp), %eax
movl %eax, 0x5c(%rcx,%r12)
movl 0x2c(%rsp), %eax
movl %eax, 0x44(%rcx,%r12)
movl 0x28(%rsp), %eax
movl %eax, 0x60(%rcx,%r12)
movl 0xc(%rsp), %eax
movl %eax, 0x68(%rcx,%r12)
movl $0x0, 0x64(%rcx,%r12)
movabsq $0x200000005, %rax      # imm = 0x200000005
movq %rax, 0x70(%rcx,%r12)
movq %r15, %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rdx
callq 0x2380
incl %ebp
addq $0x78, %r12
testq %rax, %rax
jne 0x8e75
movq %rbx, %rdi
callq 0x21f0
leaq 0x18af2(%rip), %r15     # 0x21a80
movq (%r15), %rax
movq $0x0, 0x140(%rax)
callq 0xcc40
callq 0x4d7c
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xccbb
testl %eax, %eax
jne 0x97c9
leaq 0x162fc(%rip), %rax     # 0x1f2c0
movl (%rax), %edi
leaq 0x16303(%rip), %rbx     # 0x1f2d0
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x20a0
cmpq $-0x1, %rax
je 0x9720
movl $0x80, %edx
leaq 0xb00(%rsp), %rcx
addq %rdx, %rcx
movq %rcx, 0x58(%rsp)
leaq 0x200(%rsp), %rcx
addq %rcx, %rdx
movq %rdx, 0x68(%rsp)
movl $0x4b0, %ecx            # imm = 0x4B0
addq 0x15fc9(%rip), %rcx     # 0x1efe0
movq %rcx, 0x48(%rsp)
movl $0x960, %ecx            # imm = 0x960
addq 0x15fb8(%rip), %rcx     # 0x1efe0
movq %rcx, 0x50(%rsp)
movl $0x640, %ecx            # imm = 0x640
addq 0x15fa7(%rip), %rcx     # 0x1efe0
movq %rcx, 0x60(%rsp)
leaq 0x70(%rsp), %rbp
leaq 0x17296(%rip), %r13     # 0x202e0
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
leaq 0xbb08(%rip), %rsi      # 0x14b60
callq 0xd3aa
testl %eax, %eax
je 0x90a2
movl $0x190, %eax            # imm = 0x190
leaq (%rax,%r13), %r14
leaq 0xbafa(%rip), %rdi      # 0x14b6b
movq %r14, %rsi
xorl %eax, %eax
callq 0x2040
movq %rbp, %rdi
leaq 0xbaf0(%rip), %rsi      # 0x14b75
movq %r14, %rdx
xorl %eax, %eax
callq 0x2050
movq %rbp, %rdi
callq 0x20c0
movq %rbp, %rdi
movq %rax, %rsi
callq 0xcefe
movq (%r15), %rax
cmpl $0x0, 0x140(%rax)
jne 0x9107
movq %rbx, %rdi
leaq 0xeb64(%rip), %rsi      # 0x17c1c
callq 0xd3aa
testl %eax, %eax
jne 0x90d4
movq %rbx, %rdi
leaq 0xbab5(%rip), %rsi      # 0x14b80
callq 0xd3aa
testl %eax, %eax
je 0x9107
leaq 0xbd0a(%rip), %rdi      # 0x14de5
callq 0x2330
movq (%r15), %rdi
leaq 0xc0(%rdi), %rsi
leaq 0x40(%rdi), %rdx
leaq 0x80(%rdi), %rcx
callq 0xd4d2
movq (%r15), %rax
movl $0x1, 0x140(%rax)
movq %rbx, %rdi
leaq 0xba8b(%rip), %rsi      # 0x14b9c
callq 0xd3aa
testl %eax, %eax
jne 0x96f5
movq (%r15), %rax
cmpl $0x0, 0x144(%rax)
je 0x9497
movq %rbx, %rdi
leaq 0xbab6(%rip), %rsi      # 0x14bee
callq 0xd3aa
testl %eax, %eax
je 0x918f
leaq 0x190(%r13), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x2090
incl %eax
movl %eax, 0x16104(%rip)     # 0x1f260
leaq 0x320(%r13), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x2090
incl %eax
movl %eax, 0x160ed(%rip)     # 0x1f264
movq (%r15), %rcx
xorl %edx, %edx
movb %dl, (%rcx,%rax)
movq (%r15), %rax
movl 0x160d8(%rip), %ecx     # 0x1f260
movb %dl, 0x100(%rax,%rcx)
movq %r13, %r12
movq %rbx, %rdi
leaq 0xba7f(%rip), %rsi      # 0x14c1b
callq 0xd3aa
testl %eax, %eax
je 0x925f
movq 0x48(%rsp), %rdi
callq 0xda6c
cmpl $-0x1, %eax
je 0x925f
movq (%r15), %r14
cltq
imulq $0x26a8, %rax, %rcx     # imm = 0x26A8
leaq (%r14,%rcx), %r13
addq $0x1a0, %r13            # imm = 0x1A0
movb 0x26a1(%r13), %al
cmpb $0x1, %al
ja 0x91f9
cmpb $0x0, 0x26a0(%r13)
je 0x925f
leaq 0x1a0(%r14), %rax
movb $0x2, 0x26a1(%rax,%rcx)
movb $0x2, %al
movb 0x26a0(%r13), %cl
leaq 0xba31(%rip), %r15      # 0x14c38
cmpb %al, %cl
jae 0x921b
movb %al, 0x26a0(%r13)
movl %eax, %ecx
leaq 0x97dd(%rip), %r15      # 0x129f8
addq $0x100, %r14            # imm = 0x100
movzbl %cl, %edi
callq 0xe737
movl $0x190, %esi            # imm = 0x190
movq %rbp, %rdi
movq %r15, %rdx
movq %r14, %rcx
movq %r13, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x2390
movq %rbp, %rdi
callq 0x20c0
movq %rbp, %rdi
movq %rax, %rsi
callq 0xcefe
leaq 0x18821(%rip), %r15     # 0x21a80
movq %rbx, %rdi
leaq 0xb9fa(%rip), %rsi      # 0x14c63
callq 0xd3aa
testl %eax, %eax
movq %r12, %r13
leaq 0x96ec(%rip), %r12      # 0x12966
leaq 0xba0b(%rip), %r14      # 0x14c8c
je 0x92fd
movq 0x60(%rsp), %rdi
leaq 0xb9f8(%rip), %rsi      # 0x14c87
callq 0x2370
testq %rax, %rax
je 0x92fd
movq %rax, %rdi
callq 0xd1f8
movq %rax, %rdi
callq 0xda6c
cmpl $-0x1, %eax
je 0x92f6
movq (%r15), %rcx
cltq
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
leaq (%rcx,%rax), %rdx
addq $0x1a0, %rdx            # imm = 0x1A0
movl $0x1, 0x2664(%rdx)
movb $0x0, 0x26a0(%rdx)
movq %rbp, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x2050
movq %rbp, %rdi
callq 0x20c0
movq %rbp, %rdi
movq %rax, %rsi
callq 0xcefe
xorl %edi, %edi
movq %r14, %rsi
jmp 0x928f
movq %rbx, %rdi
leaq 0xb98c(%rip), %rsi      # 0x14c93
callq 0xd3aa
testl %eax, %eax
je 0x9360
movl 0x640(%r13), %eax
movl $0x4b43494b, %ecx       # imm = 0x4B43494B
xorl %ecx, %eax
movzbl 0x644(%r13), %ecx
orl %eax, %ecx
jne 0x9360
movq 0x50(%rsp), %rdi
callq 0xd1f8
movq %rax, %rdi
callq 0xda6c
cmpl $-0x1, %eax
je 0x9360
movq (%r15), %rcx
cltq
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
movl $0x0, 0x2804(%rcx,%rax)
movb $0x0, 0x2840(%rcx,%rax)
movq %rbx, %rdi
leaq 0xb95f(%rip), %rsi      # 0x14cc9
callq 0xd3aa
testl %eax, %eax
je 0x93e8
leaq 0x190(%r13), %rdi
callq 0xd1f8
movq %rax, %rdi
callq 0xda6c
movl %eax, %r14d
leaq 0x320(%r13), %rdi
callq 0xd1f8
movq %rax, %rdi
callq 0xda6c
cmpl $-0x1, %r14d
je 0x93c4
movq (%r15), %rcx
movslq %r14d, %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
movl $0x0, 0x2804(%rcx,%rdx)
movb $0x0, 0x2840(%rcx,%rdx)
cmpl $-0x1, %eax
je 0x93e8
movq (%r15), %rcx
cltq
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
movl $0x1, 0x2804(%rcx,%rax)
movb $0x0, 0x2840(%rcx,%rax)
movq %rbx, %rdi
leaq 0xb8f8(%rip), %rsi      # 0x14cea
callq 0xd3aa
testl %eax, %eax
je 0x95ae
movl $0x190, %eax            # imm = 0x190
leaq (%rax,%r13), %r14
movq %r14, %rdi
callq 0xd1f8
movq %rax, %rdi
callq 0xda6c
cmpl $-0x1, %eax
je 0x9570
movl 0x640(%r13), %ecx
movl $0x54524150, %edx       # imm = 0x54524150
xorl %edx, %ecx
movzbl 0x644(%r13), %edx
orl %ecx, %edx
je 0x950d
movl 0x640(%r13), %ecx
movl $0x4e494f4a, %edx       # imm = 0x4E494F4A
xorl %edx, %ecx
movzbl 0x644(%r13), %edx
orl %ecx, %edx
je 0x952e
movl 0x640(%r13), %ecx
movl $0x54495551, %edx       # imm = 0x54495551
xorl %edx, %ecx
movzbl 0x644(%r13), %edx
orl %ecx, %edx
jne 0x9570
movq (%r15), %rcx
cltq
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
movl $0x0, 0x2804(%rcx,%rax)
jmp 0x9570
cmpl $0x1, 0x140(%rax)
jne 0x96c2
movq %rbx, %rdi
leaq 0xb726(%rip), %rsi      # 0x14bd4
callq 0xd3aa
testl %eax, %eax
je 0x96b2
leaq 0xb962(%rip), %rdi      # 0x14e24
callq 0x2330
movq (%r15), %rdx
movl $0x100, %eax            # imm = 0x100
addq %rax, %rdx
movq %rbp, %rdi
leaq 0xb708(%rip), %rsi      # 0x14be4
xorl %eax, %eax
callq 0x2050
callq 0xb5b0
movq %rbp, %rdi
callq 0x20c0
movq %rbp, %rdi
movq %rax, %rsi
callq 0xcefe
movq (%r15), %rax
movl $0x1, 0x144(%rax)
jmp 0x912e
movq (%r15), %rcx
cltq
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
movl $0x0, 0x2804(%rcx,%rax)
movb $0x0, 0x2840(%rcx,%rax)
jmp 0x9570
movq (%r15), %rcx
cltq
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
movl $0x1, 0x2804(%rcx,%rax)
movb $0x0, 0x2840(%rcx,%rax)
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2050
movq %rbp, %rdi
callq 0x20c0
movq %rbp, %rdi
movq %rax, %rsi
callq 0xcefe
movq (%r15), %rsi
cmpl $0x0, 0x148(%rsi)
jne 0x95ae
movl 0x15ce2(%rip), %edx     # 0x1f264
leaq 0xb00(%rsp), %r14
movq %r14, %rdi
callq 0x20e0
movl $0x3f, %edx
movq 0x58(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x20e0
movq %r14, %rdi
callq 0xdb28
movq %rbx, %rdi
leaq 0xb764(%rip), %rsi      # 0x14d1c
callq 0xd3aa
testl %eax, %eax
je 0x96c2
leaq 0x190(%r13), %rdi
callq 0xd1f8
movl 0x15c8c(%rip), %r14d    # 0x1f264
leaq 0x200(%rsp), %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x20e0
leaq 0x320(%r13), %rsi
movl $0xa, %edx
leaq 0x240(%rsp), %rdi
callq 0x20e0
leaq 0x4b0(%r13), %rsi
movl $0x3f, %edx
movq 0x68(%rsp), %rdi
callq 0x20e0
leaq 0x7d0(%r13), %rsi
leaq 0x2c0(%rsp), %rdi
movq %r14, %rdx
callq 0x20e0
leaq 0x960(%r13), %rsi
movl $0x190, %edx            # imm = 0x190
leaq 0x300(%rsp), %rdi
callq 0x20e0
movabsq $0x47534d56495250, %rax # imm = 0x47534D56495250
cmpq %rax, 0x640(%r13)
jne 0x96c2
leaq 0x300(%rsp), %rdi
leaq 0x93d5(%rip), %rsi      # 0x12a41
callq 0xd3aa
testl %eax, %eax
je 0x96c2
cmpb $0x23, 0x2c0(%rsp)
jne 0x96a3
leaq 0x200(%rsp), %r14
movq %r14, %rdi
callq 0xda6c
xorl %edi, %edi
movl %eax, %esi
movq %r13, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x42ec
jmp 0x96c2
leaq 0x200(%rsp), %rdi
callq 0xd545
jmp 0x96c2
movq (%r15), %rax
cmpl $0x0, 0x144(%rax)
jne 0x912e
movl $0x190, %edx            # imm = 0x190
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20f0
leaq 0x15be8(%rip), %rax     # 0x1f2c0
movl (%rax), %edi
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x20a0
cmpq $-0x1, %rax
jne 0x904a
jmp 0x9720
callq 0x28dc
jmp 0x911e
movq %rbx, %rdi
callq 0x9829
movl $0x1, %ebx
jmp 0x97b5
movq %rbx, %rdi
callq 0x9829
xorl %ebx, %ebx
jmp 0x97b5
cmpl $0x0, (%rsp)
je 0x9730
movq 0x20(%rsp), %rdi
callq 0x2240
testb $0x1, 0x4(%rsp)
leaq 0x15b44(%rip), %rbx     # 0x1f280
jne 0x9748
movq 0x18(%rsp), %rdi
callq 0x2240
cmpl $0x0, 0x8(%rsp)
je 0x9759
movq 0x10(%rsp), %rdi
callq 0x2240
callq 0xcdb5
callq 0xcead
callq 0xfa5d
callq 0x7076
callq 0xafd9
movq (%r15), %rdi
callq 0x2240
cmpl $0x0, (%rbx)
setne %al
movq 0x15b01(%rip), %rdi     # 0x1f288
testq %rdi, %rdi
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x9799
callq 0x2240
callq 0x9890
leaq 0xb5ce(%rip), %rdi      # 0x14d73
leaq 0x15ae4(%rip), %rsi     # 0x1f290
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2040
movl %ebx, %eax
addq $0x1408, %rsp           # imm = 0x1408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x28bc
jmp 0x9707
callq 0x28a0
jmp 0x9707
movq 0x157f4(%rip), %rax     # 0x1efd8
movq (%rax), %rdi
leaq 0xb336(%rip), %rsi      # 0x14b24
movl %ebp, %edx
xorl %eax, %eax
callq 0x2310
jmp 0x9707
callq 0x29d2
callq 0x2861
callq 0x2876
callq 0x288b
callq 0x29bd
callq 0x29a8
callq 0x2993
callq 0x297e
callq 0x2969