// File: /workspace/github_cpp_makefile_star2_O2/davidcairuz[P]network-internet-relay-chat/server.cpp
// Function: server_thread(void*)
void* server_thread(void* arg) {    
    int failed = 0;
    bool quit = false;
    int new_client = *((int*)arg);
    int pos = active->find(new_client);
    string nome = active->clients[pos].name;
    spread_message("A new client has joined us!", new_client);

    while (!quit) {
        string message = socket_server->Read(new_client);
        cout << message << endl;
        socket_server->Check();

        if (message.empty()) {
            failed++;
            
            if (failed >= Socket::max_retries) message = "/quit";
            else continue;
        } else {
            failed = 0;
        }

        if (message == "/quit") {
            spread_message("Someone left the server", new_client);
            active->remove(new_client);
            quit = true;

        } else if (message == "/ping") {
            send_message("pong!", new_client);

        } else if(message.size() >= 10 && message.substr(0, 9) == "/nickname") {
            string new_nickname = message.substr(10, message.size());
            int pos = active->find(new_client);
            active->clients[pos].name = new_nickname;
        
        } else if (message.size() >= 6 && message.substr(0, 5) == "/join") {
            string channel_name = message.substr(6, message.size());
            
            int pos = active->find(new_client);
            bool is_admin = (channels[channel_name] == 0);
            
            // Checa se cliente tem permissão para entrar no canal
            // isto é, se ele é admin ou foi convidado. O cliente
            // só pode estar em um canal por vez
            if(channel_name[0] == '&' and !is_admin){
                auto permissions = channels_permissions[channel_name];
                auto can_join = find(permissions.begin(), permissions.end(), new_client) != permissions.end();
                if (!can_join) {
                    send_message("You're not welcome here >:(", new_client);
                    continue;
                }
            }

            active->clients[pos].channel_name = channel_name;
            active->clients[pos].is_admin = is_admin;    
            
            send_message("Joined channel " + channel_name, new_client);

            if(is_admin) {
                channels[channel_name] = 1;
                channels_permissions[channel_name] = {};
                channels_permissions[channel_name].push_back(new_client);
                send_message("You own this ****!", new_client);
            }
            
            channels[channel_name]++;

        } else if (message.size() >= 6 && message.substr(0, 5) == "/kick") {
            // O /kick só pode ser utilizado pelo admin e expulsa um client
            // momentaneamente do canal. O client pode voltar ao canal sem problemas.

            int pos_client = active->find(new_client);
            
            if (active->clients[pos_client].is_admin == false) {
                send_message("You can't be that bad!", new_client);
                continue;
            }

            string to_be_kicked = message.substr(6, message.size());
            int pos = active->find(active->clients[pos_client].channel_name, to_be_kicked);

            if (active->clients[pos].channel_name != active->clients[pos_client].channel_name) {
                send_message("This user is not here", new_client);
                continue;
            }

            send_message("Admin hates you", active->clients[pos].conn);
            active->clients[pos].channel_name = "$";
            active->clients[pos].is_admin = false;
            channels[active->clients[pos_client].channel_name]--;
            
        } else if (message.size() >= 6 && message.substr(0, 5) == "/mute") {
            int pos_client = active->find(new_client);
            
            if (active->clients[pos_client].is_admin == false) {
                send_message("The Force is not with you!!", new_client);
                continue;
            } 
            
            string to_be_kicked = message.substr(6, message.size());
            int pos = active->find(active->clients[pos_client].channel_name, to_be_kicked);

            if (pos == -1 or active->clients[pos].channel_name != active->clients[pos_client].channel_name) {
                send_message("This user is not here", new_client);
                continue;
            }

            send_message("Admin can't stand you anymore", active->clients[pos].conn);
            active->clients[pos].is_muted = true;
            
        } else if (message.size() >= 8 && message.substr(0, 7) == "/unmute") {
            int pos_client = active->find(new_client);
            
            if (active->clients[pos_client].is_admin == false) {
                send_message("The Force is not with you!!", new_client);
                continue;
            }

            string to_be_kicked = message.substr(8, message.size());
            int pos = active->find(active->clients[pos_client].channel_name, to_be_kicked);

            if (pos == -1 or active->clients[pos].channel_name != active->clients[pos_client].channel_name) {
                send_message("This user is not here", new_client);
                continue;
            }

            send_message("You have your voice again, use it wisely", active->clients[pos].conn);
            active->clients[pos].is_muted = false;
               
        } else if (message.size() >= 7 && message.substr(0, 6) == "/whois") {
            int pos_client = active->find(new_client);
            
            if (active->clients[pos_client].is_admin == false) {
                send_message("The Force is not with you!!", new_client);
                continue;
            } 
            
            string to_be_found = message.substr(7, message.size());
            int pos = active->find(active->clients[pos_client].channel_name, to_be_found);
            
            if (pos == -1 or active->clients[pos].channel_name != active->clients[pos_client].channel_name) {
                send_message("This user is not here", new_client);
                continue;
            }

            send_message(active->clients[pos].name + " is " + active->clients[pos].ip, new_client);
            
        } else if (message.size() >= 8 && message.substr(0, 7) == "/invite") {
            int pos_client = active->find(new_client);
            
            if (active->clients[pos_client].is_admin == false) {
                send_message("The Force is not with you!!", new_client);
                continue;
            } 
            
            string to_be_found = message.substr(8, message.size());
            int pos = active->find(to_be_found);
            
            if (pos == -1) {
                send_message("This user doesn't exist", new_client);
                continue;
            }

            send_message("Admin wants to have the pleasure of your company at " + active->clients[pos_client].channel_name + ". To join this channel, type /join " + active->clients[pos_client].channel_name, active->clients[pos].conn);
            send_message("Invite sent!", new_client);
            
            // adiciona permissão para o cliente convidado entrar no canal
            // assim, ele pode entrar a qualquer momento após o convite
            channels_permissions[active->clients[pos_client].channel_name].push_back(active->clients[pos].conn);
        
        } else {
            spread_message(message, new_client);
        }

        message = "";
    }

    cout << nome << " has left us :(" << endl;
    pthread_exit(NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4d8, %rsp            # imm = 0x4D8
movl (%rdi), %ebx
movl %ebx, -0x2c(%rbp)
movq 0x6f59(%rip), %rdi      # 0xa2a0
movl %ebx, %esi
callq 0x4746
movq 0x6f4b(%rip), %rcx      # 0xa2a0
cltq
movq (%rcx), %rcx
imulq $0x78, %rax, %rax
leaq (%rcx,%rax), %rsi
addq $0x28, %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x22b0
leaq 0x2df1(%rip), %rsi      # 0x616a
leaq -0x180(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x271a
leaq -0x180(%rbp), %rdi
movl %ebx, %esi
callq 0x2f3d
leaq -0x180(%rbp), %rdi
callq 0x2110
xorl %r14d, %r14d
leaq -0x480(%rbp), %r12
leaq -0x460(%rbp), %rbx
xorl %r15d, %r15d
testb $0x1, %r14b
jne 0x41e1
movq 0x6e48(%rip), %rsi      # 0xa210
movl -0x2c(%rbp), %edx
leaq -0x80(%rbp), %r14
movq %r14, %rdi
callq 0x2bd6
movq 0x6bfa(%rip), %rdi      # 0x9fd8
movq %r14, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x2120
movq 0x6e1b(%rip), %rdi      # 0xa210
callq 0x2d62
movl $0x0, -0x84(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x342f
leal 0x1(%r15), %eax
movl %eax, -0x84(%rbp)
cmpl $0x4, %r15d
jl 0x3b12
leaq -0x80(%rbp), %rdi
leaq 0x2d5c(%rip), %rsi      # 0x6186
callq 0x23a0
leaq -0x80(%rbp), %r15
movq %r15, %rdi
leaq 0x2d49(%rip), %rsi      # 0x6186
callq 0x48b9
movl %eax, %r14d
testb %al, %al
je 0x3486
movq %r12, %r15
movq %r12, %rdi
leaq 0x2d36(%rip), %rsi      # 0x618c
leaq -0x60(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r15, %rdi
callq 0x2f3d
movq %r15, %rdi
callq 0x2110
movq 0x6e27(%rip), %rdi      # 0xa2a0
movl -0x2c(%rbp), %esi
callq 0x46fa
jmp 0x4033
movq %r15, %rdi
leaq 0x2d14(%rip), %rsi      # 0x61a4
callq 0x48b9
testb %al, %al
je 0x34bf
movq %rbx, %r15
movq %rbx, %rdi
leaq 0x2d04(%rip), %rsi      # 0x61aa
leaq -0x60(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r15, %rdi
callq 0x2e64
jmp 0x402b
movq -0x78(%rbp), %rax
cmpq $0xa, %rax
jb 0x354f
leaq -0x60(%rbp), %r13
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
xorl %edx, %edx
pushq $0x9
popq %rcx
callq 0x2240
movq %r13, %rdi
leaq 0x2cc4(%rip), %rsi      # 0x61b0
callq 0x48b9
movl %eax, %r15d
movq %r13, %rdi
callq 0x2110
testb %r15b, %r15b
je 0x354b
movq -0x78(%rbp), %rcx
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
pushq $0xa
popq %rdx
callq 0x2240
movq 0x6d85(%rip), %rdi      # 0xa2a0
movl -0x2c(%rbp), %esi
callq 0x4746
movq 0x6d76(%rip), %rcx      # 0xa2a0
cltq
movq (%rcx), %rcx
imulq $0x78, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x28, %rdi
movq %r13, %rsi
callq 0x2140
movq %r13, %rdi
jmp 0x402e
movq -0x78(%rbp), %rax
cmpq $0x6, %rax
jb 0x4009
leaq -0x60(%rbp), %r13
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
xorl %edx, %edx
pushq $0x5
popq %rcx
callq 0x2240
movq %r13, %rdi
leaq 0x2c42(%rip), %rsi      # 0x61ba
callq 0x48b9
movl %eax, %r15d
movq %r13, %rdi
callq 0x2110
movq -0x78(%rbp), %rcx
testb %r15b, %r15b
je 0x37b6
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
pushq $0x6
popq %rdx
callq 0x2240
movq 0x6cf5(%rip), %rdi      # 0xa2a0
movl -0x2c(%rbp), %esi
callq 0x4746
movl %eax, %r15d
leaq 0x6c83(%rip), %rdi      # 0xa240
movq %r13, %rsi
callq 0x49d8
movl %r15d, -0x38(%rbp)
movl (%rax), %r13d
testl %r13d, %r13d
sete %cl
movq -0x60(%rbp), %rax
cmpb $0x26, (%rax)
setne %al
movb %cl, -0x3c(%rbp)
orb %cl, %al
testb $0x1, %al
jne 0x36a1
leaq 0x6c80(%rip), %rdi      # 0xa270
leaq -0x60(%rbp), %rsi
callq 0x4a42
leaq -0xa8(%rbp), %rdi
movq %rax, %rsi
callq 0x4aac
movl %r13d, -0xac(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x5dea
movq -0xa0(%rbp), %rcx
movq %rax, %r13
xorl %r15d, %r15d
cmpq %rcx, %rax
movq %rcx, -0xc0(%rbp)
jne 0x3681
movq %r13, -0xb8(%rbp)
leaq -0x440(%rbp), %r15
movq %r15, %rdi
leaq 0x2b69(%rip), %rsi      # 0x61c0
leaq -0xe0(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r15, %rdi
callq 0x2e64
movq %r15, %rdi
callq 0x2110
pushq $0x2
popq %r15
movq -0xb8(%rbp), %r13
leaq -0xa8(%rbp), %rdi
callq 0x542e
cmpq -0xc0(%rbp), %r13
movl -0xac(%rbp), %r13d
je 0x379f
movq 0x6bf8(%rip), %rax      # 0xa2a0
movslq -0x38(%rbp), %rcx
movq (%rax), %rax
imulq $0x78, %rcx, %r15
leaq (%rax,%r15), %rdi
addq $0x50, %rdi
leaq -0x60(%rbp), %rsi
callq 0x2140
movq 0x6bd5(%rip), %rax      # 0xa2a0
movq (%rax), %rax
movb -0x3c(%rbp), %cl
movb %cl, 0x70(%rax,%r15)
leaq -0x1c0(%rbp), %rdi
leaq 0x2af8(%rip), %rsi      # 0x61dc
leaq -0x60(%rbp), %rdx
callq 0x4b03
movl -0x2c(%rbp), %esi
leaq -0x1c0(%rbp), %r15
movq %r15, %rdi
callq 0x2e64
movq %r15, %rdi
callq 0x2110
testl %r13d, %r13d
jne 0x378a
leaq 0x6b2d(%rip), %rdi      # 0xa240
leaq -0x60(%rbp), %rsi
callq 0x49d8
movl $0x1, (%rax)
leaq 0x6b47(%rip), %rdi      # 0xa270
leaq -0x60(%rbp), %rsi
callq 0x4a42
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5e78
leaq 0x6b2b(%rip), %rdi      # 0xa270
leaq -0x60(%rbp), %rsi
callq 0x4a42
movq %rax, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x4984
leaq -0x420(%rbp), %r15
movq %r15, %rdi
leaq 0x2a81(%rip), %rsi      # 0x61ec
leaq -0xa8(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r15, %rdi
callq 0x2e64
movq %r15, %rdi
callq 0x2110
leaq 0x6aaf(%rip), %rdi      # 0xa240
leaq -0x60(%rbp), %rsi
callq 0x49d8
incl (%rax)
xorl %r15d, %r15d
leaq -0x60(%rbp), %rdi
callq 0x2110
testl %r15d, %r15d
jne 0x3b12
jmp 0x4033
cmpq $0x6, %rcx
jb 0x4009
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
xorl %edx, %edx
pushq $0x5
popq %rcx
callq 0x2240
movq %r13, %rdi
leaq 0x2a24(%rip), %rsi      # 0x61ff
callq 0x48b9
movl %eax, %r15d
movq %r13, %rdi
callq 0x2110
testb %r15b, %r15b
je 0x38fc
movq 0x6aa5(%rip), %rdi      # 0xa2a0
movl -0x2c(%rbp), %esi
callq 0x4746
movq 0x6a96(%rip), %rcx      # 0xa2a0
cltq
movq (%rcx), %rcx
imulq $0x78, %rax, %r15
cmpb $0x0, 0x70(%rcx,%r15)
je 0x3a49
movq -0x78(%rbp), %rcx
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
pushq $0x6
popq %rdx
callq 0x2240
movq 0x6a66(%rip), %r13      # 0xa2a0
movq (%r13), %rax
movq %r15, -0x38(%rbp)
leaq (%rax,%r15), %rsi
addq $0x50, %rsi
leaq -0x160(%rbp), %rdi
callq 0x22b0
leaq -0x500(%rbp), %r15
movq %r15, %rdi
leaq -0x60(%rbp), %rsi
callq 0x22b0
movq %r13, %rdi
leaq -0x160(%rbp), %rsi
movq %r15, %rdx
callq 0x4b7a
movl %eax, %r13d
movq %r15, %rdi
callq 0x2110
leaq -0x160(%rbp), %rdi
callq 0x2110
movq 0x6a07(%rip), %rax      # 0xa2a0
movslq %r13d, %rcx
movq (%rax), %rax
imulq $0x78, %rcx, %r15
leaq (%rax,%r15), %rdi
addq $0x50, %rdi
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rsi
addq $0x50, %rsi
callq 0x4949
movb %al, -0x3c(%rbp)
testb %al, %al
je 0x3a7b
leaq -0x3e0(%rbp), %r15
movq %r15, %rdi
leaq 0x2944(%rip), %rsi      # 0x621c
leaq -0xa8(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r15, %rdi
callq 0x2e64
movq %r15, %rdi
callq 0x2110
jmp 0x3aff
cmpq $0x6, -0x78(%rbp)
jb 0x4009
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
xorl %edx, %edx
pushq $0x5
popq %rcx
callq 0x2240
movq %r13, %rdi
leaq 0x2920(%rip), %rsi      # 0x6242
callq 0x48b9
movl %eax, %r15d
movq %r13, %rdi
callq 0x2110
testb %r15b, %r15b
je 0x3b1a
movq 0x695e(%rip), %rdi      # 0xa2a0
movl -0x2c(%rbp), %esi
callq 0x4746
movq 0x694f(%rip), %rcx      # 0xa2a0
cltq
movq (%rcx), %rcx
imulq $0x78, %rax, %rax
movq %rax, -0x38(%rbp)
cmpb $0x0, 0x70(%rcx,%rax)
je 0x3c61
movq -0x78(%rbp), %rcx
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
pushq $0x6
popq %rdx
callq 0x2240
movq 0x691c(%rip), %r15      # 0xa2a0
movq (%r15), %rax
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rsi
addq $0x50, %rsi
leaq -0x140(%rbp), %rdi
callq 0x22b0
leaq -0x4e0(%rbp), %r13
movq %r13, %rdi
leaq -0x60(%rbp), %rsi
callq 0x22b0
movq %r15, %rdi
leaq -0x140(%rbp), %rsi
movq %r13, %rdx
callq 0x4b7a
movl %eax, %r15d
movq %r13, %rdi
callq 0x2110
leaq -0x140(%rbp), %rdi
callq 0x2110
cmpl $-0x1, %r15d
je 0x3a13
movq 0x68b8(%rip), %rax      # 0xa2a0
movslq %r15d, %rcx
movq (%rax), %rax
imulq $0x78, %rcx, %r15
leaq (%rax,%r15), %rdi
addq $0x50, %rdi
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rsi
addq $0x50, %rsi
callq 0x4949
testb %al, %al
je 0x3dd2
leaq -0x380(%rbp), %r14
movq %r14, %rdi
leaq 0x27f8(%rip), %rsi      # 0x621c
leaq -0xa8(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x2e64
movq %r14, %rdi
callq 0x2110
leaq -0x60(%rbp), %rdi
jmp 0x3a71
leaq -0x400(%rbp), %r14
movq %r14, %rdi
leaq 0x27ab(%rip), %rsi      # 0x6205
leaq -0x60(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x2e64
movq %r14, %rdi
callq 0x2110
jmp 0x3b12
leaq -0x3c0(%rbp), %r13
movq %r13, %rdi
leaq 0x27a6(%rip), %rsi      # 0x6232
leaq -0xa8(%rbp), %rdx
callq 0x271a
movq 0x6801(%rip), %rax      # 0xa2a0
movq (%rax), %rax
movl 0x4(%rax,%r15), %esi
movq %r13, %rdi
callq 0x2e64
movq %r13, %rdi
callq 0x2110
movq 0x67e2(%rip), %rax      # 0xa2a0
movq (%rax), %rax
leaq (%rax,%r15), %rdi
addq $0x50, %rdi
leaq 0x265c(%rip), %rsi      # 0x612c
callq 0x23a0
movq 0x67c4(%rip), %rax      # 0xa2a0
movq (%rax), %rax
movb $0x0, 0x70(%rax,%r15)
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rsi
addq $0x50, %rsi
leaq 0x6748(%rip), %rdi      # 0xa240
callq 0x49d8
decl (%rax)
leaq -0x60(%rbp), %rdi
callq 0x2110
cmpb $0x0, -0x3c(%rbp)
je 0x4033
xorl %r14d, %r14d
jmp 0x4043
movq -0x78(%rbp), %rax
cmpq $0x8, %rax
jb 0x3c8f
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
xorl %edx, %edx
pushq $0x7
popq %rcx
callq 0x2240
movq %r13, %rdi
leaq 0x273f(%rip), %rsi      # 0x6282
callq 0x48b9
movl %eax, %r15d
movq %r13, %rdi
callq 0x2110
testb %r15b, %r15b
je 0x3c8b
movq 0x673d(%rip), %rdi      # 0xa2a0
movl -0x2c(%rbp), %esi
callq 0x4746
movq 0x672e(%rip), %rcx      # 0xa2a0
cltq
movq (%rcx), %rcx
imulq $0x78, %rax, %rax
movq %rax, -0x38(%rbp)
cmpb $0x0, 0x70(%rcx,%rax)
je 0x405a
movq -0x78(%rbp), %rcx
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
pushq $0x8
popq %rdx
callq 0x2240
movq 0x66fb(%rip), %r15      # 0xa2a0
movq (%r15), %rax
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rsi
addq $0x50, %rsi
leaq -0x120(%rbp), %rdi
callq 0x22b0
leaq -0x4c0(%rbp), %r13
movq %r13, %rdi
leaq -0x60(%rbp), %rsi
callq 0x22b0
movq %r15, %rdi
leaq -0x120(%rbp), %rsi
movq %r13, %rdx
callq 0x4b7a
movl %eax, %r15d
movq %r13, %rdi
callq 0x2110
leaq -0x120(%rbp), %rdi
callq 0x2110
cmpl $-0x1, %r15d
je 0x3c34
movq 0x6697(%rip), %rax      # 0xa2a0
movslq %r15d, %rcx
movq (%rax), %rax
imulq $0x78, %rcx, %r15
leaq (%rax,%r15), %rdi
addq $0x50, %rdi
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rsi
addq $0x50, %rsi
callq 0x4949
testb %al, %al
je 0x40ae
leaq -0x320(%rbp), %r14
movq %r14, %rdi
leaq 0x25d7(%rip), %rsi      # 0x621c
leaq -0xa8(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x2e64
jmp 0x3a3b
leaq -0x3a0(%rbp), %r14
movq %r14, %rdi
leaq 0x25d6(%rip), %rsi      # 0x6248
leaq -0x60(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x2e64
jmp 0x3a6e
movq -0x78(%rbp), %rax
cmpq $0x7, %rax
jb 0x4009
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
xorl %edx, %edx
pushq $0x6
popq %rcx
callq 0x2240
movq %r13, %rdi
leaq 0x25ff(%rip), %rsi      # 0x62b3
callq 0x48b9
movl %eax, %r15d
movq %r13, %rdi
callq 0x2110
testb %r15b, %r15b
je 0x3e27
movq 0x65cc(%rip), %rdi      # 0xa2a0
movl -0x2c(%rbp), %esi
callq 0x4746
movq 0x65bd(%rip), %rcx      # 0xa2a0
cltq
movq (%rcx), %rcx
imulq $0x78, %rax, %rax
movq %rax, -0x38(%rbp)
cmpb $0x0, 0x70(%rcx,%rax)
je 0x4084
movq -0x78(%rbp), %rcx
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
pushq $0x7
popq %rdx
callq 0x2240
movq 0x658a(%rip), %r15      # 0xa2a0
movq (%r15), %rax
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rsi
addq $0x50, %rsi
leaq -0x100(%rbp), %rdi
callq 0x22b0
leaq -0x4a0(%rbp), %r13
movq %r13, %rdi
leaq -0x60(%rbp), %rsi
callq 0x22b0
movq %r15, %rdi
leaq -0x100(%rbp), %rsi
movq %r13, %rdx
callq 0x4b7a
movl %eax, %r15d
movq %r13, %rdi
callq 0x2110
leaq -0x100(%rbp), %rdi
callq 0x2110
cmpl $-0x1, %r15d
je 0x3da5
movq 0x6526(%rip), %rax      # 0xa2a0
movslq %r15d, %rcx
movq (%rax), %rax
imulq $0x78, %rcx, %r15
leaq (%rax,%r15), %rdi
addq $0x50, %rdi
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rsi
addq $0x50, %rsi
callq 0x4949
testb %al, %al
je 0x40ff
leaq -0x2c0(%rbp), %r14
movq %r14, %rdi
leaq 0x2466(%rip), %rsi      # 0x621c
leaq -0xa8(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x2e64
jmp 0x3a3b
leaq -0x360(%rbp), %r13
movq %r13, %rdi
leaq 0x2481(%rip), %rsi      # 0x6264
leaq -0xa8(%rbp), %rdx
callq 0x271a
movq 0x64aa(%rip), %rax      # 0xa2a0
movq (%rax), %rax
movl 0x4(%rax,%r15), %esi
movq %r13, %rdi
callq 0x2e64
movq %r13, %rdi
callq 0x2110
movq 0x648b(%rip), %rax      # 0xa2a0
movq (%rax), %rax
movb $0x1, 0x71(%rax,%r15)
leaq -0x60(%rbp), %rdi
jmp 0x402e
cmpq $0x8, -0x78(%rbp)
jb 0x4009
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
xorl %edx, %edx
pushq $0x7
popq %rcx
callq 0x2240
movq %r13, %rdi
leaq 0x2472(%rip), %rsi      # 0x62bf
callq 0x48b9
movl %eax, %r15d
movq %r13, %rdi
callq 0x2110
testb %r15b, %r15b
je 0x4009
movq 0x6433(%rip), %rdi      # 0xa2a0
movl -0x2c(%rbp), %esi
callq 0x4746
movq 0x6424(%rip), %rcx      # 0xa2a0
cltq
movq (%rcx), %rcx
imulq $0x78, %rax, %rax
movq %rax, -0x38(%rbp)
cmpb $0x0, 0x70(%rcx,%rax)
je 0x416f
movq -0x78(%rbp), %rcx
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
pushq $0x8
popq %rdx
callq 0x2240
movq 0x63f2(%rip), %r15      # 0xa2a0
leaq -0x260(%rbp), %rdi
movq %r13, %rsi
callq 0x22b0
movq %r15, %rdi
leaq -0x260(%rbp), %r15
movq %r15, %rsi
callq 0x4c28
movl %eax, %r13d
movq %r15, %rdi
callq 0x2110
cmpl $-0x1, %r13d
je 0x4199
movl %r13d, -0x3c(%rbp)
movq 0x63b1(%rip), %rax      # 0xa2a0
movq (%rax), %rax
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rdx
addq $0x50, %rdx
leaq -0xe0(%rbp), %r13
movq %r13, %rdi
leaq 0x23d0(%rip), %rsi      # 0x62df
callq 0x4b03
leaq -0xa8(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
leaq 0x23ec(%rip), %rdx      # 0x6314
callq 0x4787
movq 0x636c(%rip), %rax      # 0xa2a0
movq (%rax), %rax
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rdx
addq $0x50, %rdx
leaq -0x220(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x4bfe
movq 0x6344(%rip), %rax      # 0xa2a0
movslq -0x3c(%rbp), %rcx
movq (%rax), %rax
imulq $0x78, %rcx, %r15
movl 0x4(%rax,%r15), %esi
movq %r13, %rdi
callq 0x2e64
movq %r13, %rdi
callq 0x2110
leaq -0xa8(%rbp), %rdi
callq 0x2110
leaq -0xe0(%rbp), %rdi
callq 0x2110
leaq -0x200(%rbp), %r13
movq %r13, %rdi
leaq 0x2393(%rip), %rsi      # 0x6338
leaq -0xa8(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r13, %rdi
callq 0x2e64
movq %r13, %rdi
callq 0x2110
movq 0x62d5(%rip), %rax      # 0xa2a0
movq (%rax), %rax
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rsi
addq $0x50, %rsi
leaq 0x628f(%rip), %rdi      # 0xa270
callq 0x4a42
movl -0x3c(%rbp), %r13d
movq 0x62af(%rip), %rcx      # 0xa2a0
movq (%rcx), %rcx
leaq (%rcx,%r15), %rsi
addq $0x4, %rsi
movq %rax, %rdi
callq 0x4984
jmp 0x41c9
leaq -0x1a0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x22b0
movl -0x2c(%rbp), %esi
leaq -0x1a0(%rbp), %r15
movq %r15, %rdi
callq 0x2f3d
movq %r15, %rdi
callq 0x2110
leaq -0x80(%rbp), %rdi
leaq 0x20c1(%rip), %rsi      # 0x60ff
callq 0x23a0
leaq -0x80(%rbp), %rdi
callq 0x2110
movl -0x84(%rbp), %eax
movl %eax, %r15d
jmp 0x33b7
leaq -0x340(%rbp), %r14
movq %r14, %rdi
leaq 0x21dd(%rip), %rsi      # 0x6248
leaq -0x60(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x2e64
jmp 0x3a6e
leaq -0x2e0(%rbp), %r14
movq %r14, %rdi
leaq 0x21b3(%rip), %rsi      # 0x6248
leaq -0x60(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x2e64
jmp 0x3a6e
leaq -0x300(%rbp), %r13
movq %r13, %rdi
leaq 0x21cb(%rip), %rsi      # 0x628a
leaq -0xa8(%rbp), %rdx
callq 0x271a
movq 0x61ce(%rip), %rax      # 0xa2a0
movq (%rax), %rax
movl 0x4(%rax,%r15), %esi
movq %r13, %rdi
callq 0x2e64
movq %r13, %rdi
callq 0x2110
movq 0x61af(%rip), %rax      # 0xa2a0
movq (%rax), %rax
movb $0x0, 0x71(%rax,%r15)
jmp 0x3e1e
movq 0x619a(%rip), %rax      # 0xa2a0
movq (%rax), %rax
leaq (%rax,%r15), %rsi
addq $0x28, %rsi
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
leaq 0x2198(%rip), %rdx      # 0x62ba
callq 0x4821
movq 0x6172(%rip), %rax      # 0xa2a0
movq (%rax), %rax
leaq (%rax,%r15), %rdx
addq $0x8, %rdx
leaq -0x2a0(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x4bfe
movl -0x2c(%rbp), %esi
movq %r15, %rdi
callq 0x2e64
movq %r15, %rdi
callq 0x2110
leaq -0xa8(%rbp), %rdi
callq 0x2110
jmp 0x3e1e
leaq -0x280(%rbp), %r14
movq %r14, %rdi
leaq 0x20c8(%rip), %rsi      # 0x6248
leaq -0x60(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x2e64
jmp 0x3a6e
leaq -0x240(%rbp), %r15
movq %r15, %rdi
leaq 0x211d(%rip), %rsi      # 0x62c7
leaq -0xa8(%rbp), %rdx
callq 0x271a
movl -0x2c(%rbp), %esi
movq %r15, %rdi
callq 0x2e64
movq %r15, %rdi
callq 0x2110
leaq -0x60(%rbp), %rdi
callq 0x2110
cmpl $-0x1, %r13d
jne 0x4033
jmp 0x3b12
movq 0x5df0(%rip), %rdi      # 0x9fd8
leaq -0x1e0(%rbp), %rsi
callq 0x21e0
leaq 0x214a(%rip), %rsi      # 0x6345
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
callq 0x2120
xorl %edi, %edi
callq 0x2360
movq %rax, %rbx
leaq -0x240(%rbp), %rdi
jmp 0x443c
jmp 0x445b
movq %rax, %rbx
leaq -0x280(%rbp), %rdi
jmp 0x447c
jmp 0x4489
movq %rax, %rbx
leaq -0x200(%rbp), %rdi
jmp 0x443c
jmp 0x445b
movq %rax, %rbx
leaq -0x220(%rbp), %rdi
callq 0x2110
jmp 0x4262
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x2110
jmp 0x4273
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
jmp 0x443c
jmp 0x445b
jmp 0x4489
movq %rax, %rbx
jmp 0x42a2
jmp 0x445b
movq %rax, %rbx
leaq -0x2a0(%rbp), %rdi
callq 0x2110
leaq -0xa8(%rbp), %rdi
jmp 0x443c
movq %rax, %rbx
leaq -0x300(%rbp), %rdi
jmp 0x443c
jmp 0x445b
jmp 0x445b
movq %rax, %rbx
leaq -0x2e0(%rbp), %rdi
jmp 0x447c
jmp 0x4489
jmp 0x445b
movq %rax, %rbx
leaq -0x2c0(%rbp), %rdi
jmp 0x443c
movq %rax, %rbx
leaq -0x340(%rbp), %rdi
jmp 0x447c
jmp 0x4489
jmp 0x4489
movq %rax, %rbx
leaq -0x320(%rbp), %rdi
jmp 0x443c
jmp 0x445b
jmp 0x4489
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
jmp 0x443c
jmp 0x445b
jmp 0x445b
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
jmp 0x443c
jmp 0x4489
jmp 0x445b
movq %rax, %rbx
leaq -0x360(%rbp), %rdi
jmp 0x443c
movq %rax, %rbx
leaq -0x3a0(%rbp), %rdi
jmp 0x447c
jmp 0x4489
jmp 0x4489
movq %rax, %rbx
leaq -0x380(%rbp), %rdi
jmp 0x443c
jmp 0x445b
jmp 0x4489
jmp 0x445b
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
jmp 0x443c
jmp 0x4489
movq %rax, %rbx
leaq -0x3c0(%rbp), %rdi
jmp 0x443c
jmp 0x445b
jmp 0x445b
movq %rax, %rbx
leaq -0x3e0(%rbp), %rdi
jmp 0x443c
movq %rax, %rbx
leaq -0x400(%rbp), %rdi
jmp 0x447c
jmp 0x4489
jmp 0x4489
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
jmp 0x443c
jmp 0x4489
jmp 0x441f
movq %rax, %rbx
leaq -0x440(%rbp), %rdi
callq 0x2110
jmp 0x4422
movq %rax, %rbx
leaq -0x420(%rbp), %rdi
jmp 0x443c
jmp 0x445b
jmp 0x445b
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x542e
jmp 0x445e
jmp 0x4489
movq %rax, %rbx
leaq -0x1c0(%rbp), %rdi
callq 0x2110
jmp 0x445e
jmp 0x445b
jmp 0x4489
jmp 0x445b
jmp 0x4489
jmp 0x4489
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
jmp 0x447c
jmp 0x4489
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
jmp 0x447c
movq %rax, %rbx
leaq -0x460(%rbp), %rdi
jmp 0x447c
jmp 0x4489
movq %rax, %rbx
leaq -0x480(%rbp), %rdi
callq 0x2110
jmp 0x448c
jmp 0x4489
jmp 0x44a3
jmp 0x44a3
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
jmp 0x449c
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
callq 0x2110
jmp 0x44a6
movq %rax, %rbx
leaq -0x1e0(%rbp), %rdi
callq 0x2110
movq %rbx, %rdi
callq 0x2350