// File: supragya[P]DirectorySync/DirectorySync.cpp
// Function: filewatcher(char*, char*, int)
void filewatcher(char *dirname, char *intermediate, int sock) {

    std::cout << "#### Began thread [FILEWATCHER]"<<std::endl;


    // Initialise FileWatcher
    int fd, wd;
    char workCMD[WORKCMDLEN];

    strcpy(workCMD, dirname);
    if(strlen(intermediate) > 0)
        strcat(workCMD, "/");
    strcat(workCMD, intermediate);

    fd = inotify_init();
    if ( fd < 0 ) {
        std::cout<<"[FW: inotify] Could not initialise inotify, quitting"<<std::endl;
        exit(1);
    }
    wd = inotify_add_watch(fd, workCMD, IN_CREATE | IN_MODIFY | IN_DELETE);
    if (wd == -1){
        std::cout<<"[FW: inotify] Could not add watch to ["<<workCMD<<"], quitting\n";
        exit(1);
    }
    else
        std::cout<<"[FW: inotify] Started watching ["<<workCMD<<"]"<<std::endl;


    // Actual FileWatch system
    char *FWINBuffer[INOTIFYBUFLEN];
    int length;
    while(1) {
        int i = 0;
        length = read(fd, FWINBuffer, INOTIFYBUFLEN);
        if (length < 0)
            std::cout << "[FILEWATCHER] Read Error \n";
        while (i < length) {
            struct inotify_event *event = (struct inotify_event *) &FWINBuffer[i];
            if (event->len) {
                if (event->mask & IN_CREATE) {
                    if (event->mask & IN_ISDIR) {
                        strcpy(workCMD, intermediate);
                        if(strlen(intermediate) > 0)
                            strcat(workCMD, "/");
                        strcat(workCMD, event->name);
                        std::cout << "[FW: inotify]\tCreated\tDIR\t" << workCMD << std::endl;
                        message *message_packet = FormMessage(workCMD, CREATE, DIRECTORY, 0);
                        if (!Transactions.is_recorded(*message_packet)) {
                            int sent = send(sock, message_packet, sizeof(message), 0);
                            std::cout << "[FW: inotify]\tSent request to create [" << event->name << "] Directory"
                                      << std::endl;

                            char *newintermediate = (char *)malloc(sizeof(char)*MAXFILENAMELEN);
                            strcpy(newintermediate, workCMD);
                            std::thread currentfilewatcher(filewatcher, dirname, intermediate, sock);
                            std::thread newfilewatcher(filewatcher, dirname, newintermediate, sock);
                            currentfilewatcher.join();
                            newfilewatcher.join();

                        } else {
                            std::cout << "[FW: inotify]\tDirectory [" << event->name
                                      << "]  created due to incoming request, skip request send" << std::endl;
                        }

                        free(message_packet);
                    }
                    else {
                        strcpy(workCMD, intermediate);
                        if(strlen(intermediate) > 0)
                            strcat(workCMD, "/");
                        strcat(workCMD, event->name);
                        std::cout << "[FW: inotify]\tCreated\tFIL\t" << workCMD << std::endl;
                        message *message_packet = FormMessage(workCMD, CREATE, _FILE, 0);

                        if (!Transactions.is_recorded(*message_packet)) {
                            int sent = send(sock, message_packet, sizeof(message), 0);
                            std::cout << "[FW: inotify]\tSent request to create [" << workCMD << "] file"
                                      << std::endl;
                        } else {
                            std::cout << "[FW: inotify]\tFile [" << event->name
                                      << "]  created due to incoming request, skip request send" << std::endl;
                        }

                        free(message_packet);
                    }
                }
                else if (event->mask & IN_MODIFY) {
                    if(!(event->mask & IN_ISDIR)){


                        FileAccess.lock();
                        strcpy(workCMD, dirname);
                        strcat(workCMD, "/");
                        strcat(workCMD, intermediate);
                        if(strlen(intermediate) > 0)
                            strcat(workCMD, "/");
                        strcat(workCMD, event->name);
                        std::ifstream file(workCMD, std::ios::binary);
                        file.seekg(0, file.end);
                        std::cout << "[FW: inotify]\tModified\tFIL\t" << workCMD << std::endl;
                        unsigned int filesize = file.tellg();
                        file.close();
                        FileAccess.unlock();
                        strcpy(workCMD, intermediate);
                        if(strlen(intermediate) > 0)
                            strcat(workCMD, "/");
                        strcat(workCMD, event->name);
                        message *message_packet = FormMessage(workCMD, MODIFY, _FILE, filesize);

                        if(!Transactions.is_recorded(*message_packet)){
                            int sent = send(sock, message_packet, sizeof(message), 0);

                            FileAccess.lock();
                            strcpy(workCMD, dirname);
                            strcat(workCMD, "/");
                            strcat(workCMD, intermediate);
                            if(strlen(intermediate) > 0)
                                strcat(workCMD, "/");
                            strcat(workCMD, event->name);
                            std::cout << "[FW: inotify]\tSent request to modify [" << workCMD << "] filesize = "<< filesize
                                      << std::endl;
                            file.open(workCMD, std::ios::binary);
                            file.seekg(0, file.beg);
                            char *filedata = (char*)malloc(filesize);
                            file.read(filedata, filesize);
                            FileAccess.unlock();
                            send(sock, filedata, filesize, 0);
                            free(filedata);

                        }else{
                            std::cout << "[FW: inotify]\tFile [" << workCMD
                                      << "]  modified due to incoming request, skip request send" << std::endl;
                        }
                    }
                }
                else if (event->mask & IN_DELETE) {
                    if (event->mask & IN_ISDIR) {
                        strcpy(workCMD, intermediate);
                        if(strlen(intermediate) > 0)
                            strcat(workCMD, "/");
                        strcat(workCMD, event->name);
                        std::cout << "[FW: inotify]\tDeleted\tDIR\t" << workCMD << std::endl;
                        message *message_packet = FormMessage(workCMD, DELETE, DIRECTORY, 0);
                        if (!Transactions.is_recorded(*message_packet)) {
                            int sent = send(sock, message_packet, sizeof(message), 0);
                            std::cout << "[FW: inotify]\tSent request to delete [" << workCMD << "] Directory"
                                      << std::endl;
                        } else {
                            std::cout << "[FW: inotify]\tDirectory [" << event->name
                                      << "]  deleted due to incoming request, skip request send" << std::endl;
                        }

                        free(message_packet);
                    }
                    else {
                        strcpy(workCMD, intermediate);
                        if(strlen(intermediate) > 0)
                            strcat(workCMD, "/");
                        strcat(workCMD, event->name);
                        std::cout << "[FW: inotify]\tDeleted\tFIL\t" << workCMD << std::endl;
                        message *message_packet = FormMessage(workCMD, DELETE, _FILE, 0);

                        if (!Transactions.is_recorded(*message_packet)) {
                            int sent = send(sock, message_packet, sizeof(message), 0);
                            std::cout << "[FW: inotify]\tSent request to delete [" << workCMD << "] file"
                                      << std::endl;
                        } else {
                            std::cout << "[FW: inotify]\tFile [" << event->name
                                      << "]  delete due to incoming request, skip request send" << std::endl;
                        }

                        free(message_packet);
                    }
                }
            }
            i += EVENT_SIZE + event->len;
        }
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x61d0, %rsp           # imm = 0x61D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq 0x78f3(%rip), %rdi      # 0xafd0
leaq 0x416f(%rip), %rsi      # 0x7853
callq 0x21d0
movq %rax, %rdi
movq 0x78c5(%rip), %rsi      # 0xafb8
callq 0x21f0
leaq -0x2730(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x21b0
movq -0x10(%rbp), %rdi
callq 0x20d0
cmpq $0x0, %rax
jbe 0x372a
leaq -0x2730(%rbp), %rdi
leaq 0x407a(%rip), %rsi      # 0x779f
callq 0x2350
leaq -0x2730(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2350
callq 0x2370
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x3774
movq 0x7881(%rip), %rdi      # 0xafd0
leaq 0x411d(%rip), %rsi      # 0x7873
callq 0x21d0
movq %rax, %rdi
movq 0x7853(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0x1, %edi
callq 0x2230
movl -0x18(%rbp), %edi
leaq -0x2730(%rbp), %rsi
movl $0x302, %edx            # imm = 0x302
callq 0x2110
movl %eax, -0x1c(%rbp)
cmpl $-0x1, -0x1c(%rbp)
jne 0x37cc
movq 0x7838(%rip), %rdi      # 0xafd0
leaq 0x4109(%rip), %rsi      # 0x78a8
callq 0x21d0
movq %rax, %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x4112(%rip), %rsi      # 0x78cf
callq 0x21d0
movl $0x1, %edi
callq 0x2230
movq 0x77fd(%rip), %rdi      # 0xafd0
leaq 0x4102(%rip), %rsi      # 0x78dc
callq 0x21d0
movq %rax, %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x4079(%rip), %rsi      # 0x7871
callq 0x21d0
movq %rax, %rdi
movq 0x77b1(%rip), %rsi      # 0xafb8
callq 0x21f0
jmp 0x380e
movl $0x0, -0x4678(%rbp)
movl -0x18(%rbp), %edi
leaq -0x4670(%rbp), %rsi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x22b0
movl %eax, -0x4674(%rbp)
cmpl $0x0, -0x4674(%rbp)
jge 0x384e
movq 0x778e(%rip), %rdi      # 0xafd0
leaq 0x40b4(%rip), %rsi      # 0x78fd
callq 0x21d0
jmp 0x3850
movl -0x4678(%rbp), %eax
cmpl -0x4674(%rbp), %eax
jge 0x4514
movslq -0x4678(%rbp), %rcx
leaq -0x4670(%rbp), %rax
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x4680(%rbp)
movq -0x4680(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x44ef
movq -0x4680(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x3cd3
movq -0x4680(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x40000000, %eax       # imm = 0x40000000
cmpl $0x0, %eax
je 0x3b4b
leaq -0x2730(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq -0x10(%rbp), %rdi
callq 0x20d0
cmpq $0x0, %rax
jbe 0x38f1
leaq -0x2730(%rbp), %rdi
leaq 0x3eb3(%rip), %rsi      # 0x779f
callq 0x2350
leaq -0x2730(%rbp), %rdi
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
callq 0x2350
movq 0x76c1(%rip), %rdi      # 0xafd0
leaq 0x4002(%rip), %rsi      # 0x7918
callq 0x21d0
movq %rax, %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, %rdi
movq 0x7684(%rip), %rsi      # 0xafb8
callq 0x21f0
leaq -0x2730(%rbp), %rdi
movl $0x3, %esi
movl $0x2, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x47e0
movq %rax, -0x4688(%rbp)
movq -0x4688(%rbp), %rsi
leaq -0x4a88(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rsp, %rdi
movl $0x80, %ecx
leaq -0x4a88(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x786d(%rip), %rdi      # 0xb1f8
callq 0x5050
testb $0x1, %al
jne 0x3af6
movl -0x14(%rbp), %edi
movq -0x4688(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
xorl %ecx, %ecx
callq 0x2100
movl %eax, -0x4a8c(%rbp)
movq 0x7615(%rip), %rdi      # 0xafd0
leaq 0x3f71(%rip), %rsi      # 0x7933
callq 0x21d0
movq %rax, %rdi
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x3f76(%rip), %rsi      # 0x795a
callq 0x21d0
movq %rax, %rdi
movq 0x75c5(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x2260
movq %rax, -0x4a98(%rbp)
movq -0x4a98(%rbp), %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21b0
leaq -0x363(%rip), %rsi      # 0x36c0
movq %rsi, -0x5d38(%rbp)
leaq -0x4aa0(%rbp), %rdi
leaq -0x8(%rbp), %rdx
movq %rdx, -0x5d30(%rbp)
leaq -0x10(%rbp), %rcx
leaq -0x14(%rbp), %r8
movq %r8, -0x5d28(%rbp)
callq 0x4f30
movq -0x5d38(%rbp), %rsi
movq -0x5d30(%rbp), %rdx
movq -0x5d28(%rbp), %r8
leaq -0x4aa8(%rbp), %rdi
leaq -0x4a98(%rbp), %rcx
callq 0x4f30
jmp 0x3a7a
leaq -0x4aa0(%rbp), %rdi
callq 0x2300
jmp 0x3a88
leaq -0x4aa8(%rbp), %rdi
callq 0x2300
jmp 0x3a96
leaq -0x4aa8(%rbp), %rdi
callq 0x4cc0
leaq -0x4aa0(%rbp), %rdi
callq 0x4cc0
jmp 0x3b3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x4ab0(%rbp)
movl %eax, -0x4ab4(%rbp)
jmp 0x3ae5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x4ab0(%rbp)
movl %eax, -0x4ab4(%rbp)
leaq -0x4aa8(%rbp), %rdi
callq 0x4cc0
leaq -0x4aa0(%rbp), %rdi
callq 0x4cc0
jmp 0x4519
movq 0x74d3(%rip), %rdi      # 0xafd0
leaq 0x3e62(%rip), %rsi      # 0x7966
callq 0x21d0
movq %rax, %rdi
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x3e5a(%rip), %rsi      # 0x7980
callq 0x21d0
movq %rax, %rdi
movq 0x7483(%rip), %rsi      # 0xafb8
callq 0x21f0
movq -0x4688(%rbp), %rdi
callq 0x2220
jmp 0x3cce
leaq -0x2730(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq -0x10(%rbp), %rdi
callq 0x20d0
cmpq $0x0, %rax
jbe 0x3b7d
leaq -0x2730(%rbp), %rdi
leaq 0x3c27(%rip), %rsi      # 0x779f
callq 0x2350
leaq -0x2730(%rbp), %rdi
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
callq 0x2350
movq 0x7435(%rip), %rdi      # 0xafd0
leaq 0x3e14(%rip), %rsi      # 0x79b6
callq 0x21d0
movq %rax, %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, %rdi
movq 0x73f8(%rip), %rsi      # 0xafb8
callq 0x21f0
leaq -0x2730(%rbp), %rdi
movl $0x3, %esi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x47e0
movq %rax, -0x4ac0(%rbp)
movq -0x4ac0(%rbp), %rsi
leaq -0x4ec0(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rsp, %rdi
movl $0x80, %ecx
leaq -0x4ec0(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x75e1(%rip), %rdi      # 0xb1f8
callq 0x5050
testb $0x1, %al
jne 0x3c7e
movl -0x14(%rbp), %edi
movq -0x4ac0(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
xorl %ecx, %ecx
callq 0x2100
movl %eax, -0x4ec4(%rbp)
movq 0x738d(%rip), %rdi      # 0xafd0
leaq 0x3ce9(%rip), %rsi      # 0x7933
callq 0x21d0
movq %rax, %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x3d69(%rip), %rsi      # 0x79d1
callq 0x21d0
movq %rax, %rdi
movq 0x7341(%rip), %rsi      # 0xafb8
callq 0x21f0
jmp 0x3cc2
movq 0x734b(%rip), %rdi      # 0xafd0
leaq 0x3d4c(%rip), %rsi      # 0x79d8
callq 0x21d0
movq %rax, %rdi
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x3cd2(%rip), %rsi      # 0x7980
callq 0x21d0
movq %rax, %rdi
movq 0x72fb(%rip), %rsi      # 0xafb8
callq 0x21f0
movq -0x4ac0(%rbp), %rdi
callq 0x2220
jmp 0x44ed
movq -0x4680(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x41af
movq -0x4680(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x40000000, %eax       # imm = 0x40000000
cmpl $0x0, %eax
jne 0x41aa
leaq 0x20580(%rip), %rdi     # 0x24288
callq 0x5000
leaq -0x2730(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x21b0
leaq -0x2730(%rbp), %rdi
leaq 0x3a74(%rip), %rsi      # 0x779f
callq 0x2350
leaq -0x2730(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2350
movq -0x10(%rbp), %rdi
callq 0x20d0
cmpq $0x0, %rax
jbe 0x3d62
leaq -0x2730(%rbp), %rdi
leaq 0x3a42(%rip), %rsi      # 0x779f
callq 0x2350
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
leaq -0x2730(%rbp), %rdi
movq %rdi, -0x5d48(%rbp)
callq 0x2350
movq -0x5d48(%rbp), %rsi
leaq -0x50d0(%rbp), %rdi
movq %rdi, -0x5d40(%rbp)
movl $0x4, %edx
callq 0x2380
movq -0x5d40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x2280
jmp 0x3db6
movq 0x7213(%rip), %rdi      # 0xafd0
leaq 0x3c29(%rip), %rsi      # 0x79ed
callq 0x21d0
movq %rax, -0x5d50(%rbp)
jmp 0x3dd2
movq -0x5d50(%rbp), %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, -0x5d58(%rbp)
jmp 0x3dee
movq -0x5d58(%rbp), %rdi
movq 0x71bc(%rip), %rsi      # 0xafb8
callq 0x21f0
jmp 0x3e03
leaq -0x50d0(%rbp), %rdi
callq 0x2330
movq %rdx, -0x5d68(%rbp)
movq %rax, -0x5d60(%rbp)
jmp 0x3e1f
movq -0x5d68(%rbp), %rax
movq -0x5d60(%rbp), %rcx
movq %rcx, -0x50e8(%rbp)
movq %rax, -0x50e0(%rbp)
leaq -0x50e8(%rbp), %rdi
callq 0x5210
movq %rax, -0x5d70(%rbp)
jmp 0x3e50
movq -0x5d70(%rbp), %rax
movl %eax, -0x50d4(%rbp)
leaq -0x50d0(%rbp), %rdi
callq 0x2050
jmp 0x3e6b
leaq 0x20416(%rip), %rdi     # 0x24288
callq 0x5030
jmp 0x3e79
leaq -0x2730(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq -0x10(%rbp), %rdi
callq 0x20d0
cmpq $0x0, %rax
jbe 0x3ed0
leaq -0x2730(%rbp), %rdi
leaq 0x38f9(%rip), %rsi      # 0x779f
callq 0x2350
jmp 0x3ed0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x4ab0(%rbp)
movl %eax, -0x4ab4(%rbp)
leaq -0x50d0(%rbp), %rdi
callq 0x2080
jmp 0x4519
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
leaq -0x2730(%rbp), %rdi
movq %rdi, -0x5d80(%rbp)
callq 0x2350
movq -0x5d80(%rbp), %rdi
movl -0x50d4(%rbp), %eax
movl %eax, %ecx
movl $0x1, %edx
movl %edx, %esi
callq 0x47e0
movq %rax, -0x5d78(%rbp)
jmp 0x3f12
movq -0x5d78(%rbp), %rax
movq %rax, -0x50f0(%rbp)
movq -0x50f0(%rbp), %rsi
leaq -0x54f0(%rbp), %rdi
movq %rdi, -0x5d90(%rbp)
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq -0x5d90(%rbp), %rsi
movq %rsp, %rdi
movl $0x80, %ecx
rep  movsq (%rsi), %es:(%rdi)
leaq 0x72a0(%rip), %rdi      # 0xb1f8
callq 0x5050
movb %al, -0x5d81(%rbp)
jmp 0x3f65
movb -0x5d81(%rbp), %al
testb $0x1, %al
jne 0x4133
jmp 0x3f75
movl -0x14(%rbp), %edi
movq -0x50f0(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
xorl %ecx, %ecx
callq 0x2100
movq %rax, -0x5d98(%rbp)
jmp 0x3f94
movq -0x5d98(%rbp), %rax
movl %eax, -0x54f4(%rbp)
leaq 0x202e0(%rip), %rdi     # 0x24288
callq 0x5000
jmp 0x3faf
leaq -0x2730(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x21b0
leaq -0x2730(%rbp), %rdi
leaq 0x37d2(%rip), %rsi      # 0x779f
callq 0x2350
leaq -0x2730(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2350
movq -0x10(%rbp), %rdi
callq 0x20d0
cmpq $0x0, %rax
jbe 0x4004
leaq -0x2730(%rbp), %rdi
leaq 0x37a0(%rip), %rsi      # 0x779f
callq 0x2350
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
leaq -0x2730(%rbp), %rdi
callq 0x2350
movq 0x6fae(%rip), %rdi      # 0xafd0
leaq 0x39e0(%rip), %rsi      # 0x7a09
callq 0x21d0
movq %rax, -0x5da0(%rbp)
jmp 0x4037
movq -0x5da0(%rbp), %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, -0x5da8(%rbp)
jmp 0x4053
movq -0x5da8(%rbp), %rdi
leaq 0x39cf(%rip), %rsi      # 0x7a30
callq 0x21d0
movq %rax, -0x5db0(%rbp)
jmp 0x406f
movq -0x5db0(%rbp), %rdi
movl -0x50d4(%rbp), %esi
callq 0x2270
movq %rax, -0x5db8(%rbp)
jmp 0x408a
movq -0x5db8(%rbp), %rdi
movq 0x6f20(%rip), %rsi      # 0xafb8
callq 0x21f0
jmp 0x409f
leaq -0x50d0(%rbp), %rdi
leaq -0x2730(%rbp), %rsi
movl $0x4, %edx
callq 0x2130
jmp 0x40b9
xorl %edx, %edx
movl %edx, %esi
leaq -0x50d0(%rbp), %rdi
callq 0x2280
jmp 0x40cb
movl -0x50d4(%rbp), %eax
movl %eax, %edi
callq 0x2260
movq %rax, -0x5500(%rbp)
movq -0x5500(%rbp), %rsi
movl -0x50d4(%rbp), %eax
movl %eax, %edx
leaq -0x50d0(%rbp), %rdi
callq 0x2240
jmp 0x40fc
leaq 0x20185(%rip), %rdi     # 0x24288
callq 0x5030
jmp 0x410a
movl -0x14(%rbp), %edi
movq -0x5500(%rbp), %rsi
movl -0x50d4(%rbp), %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x2100
jmp 0x4125
movq -0x5500(%rbp), %rdi
callq 0x2220
jmp 0x419e
movq 0x6e96(%rip), %rdi      # 0xafd0
leaq 0x3897(%rip), %rsi      # 0x79d8
callq 0x21d0
movq %rax, -0x5dc0(%rbp)
jmp 0x414f
movq -0x5dc0(%rbp), %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, -0x5dc8(%rbp)
jmp 0x416b
movq -0x5dc8(%rbp), %rdi
leaq 0x38c5(%rip), %rsi      # 0x7a3e
callq 0x21d0
movq %rax, -0x5dd0(%rbp)
jmp 0x4187
movq -0x5dd0(%rbp), %rdi
movq 0x6e23(%rip), %rsi      # 0xafb8
callq 0x21f0
jmp 0x419c
jmp 0x419e
leaq -0x50d0(%rbp), %rdi
callq 0x2080
jmp 0x44eb
movq -0x4680(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x44e9
movq -0x4680(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x40000000, %eax       # imm = 0x40000000
cmpl $0x0, %eax
je 0x4364
leaq -0x2730(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq -0x10(%rbp), %rdi
callq 0x20d0
cmpq $0x0, %rax
jbe 0x4211
leaq -0x2730(%rbp), %rdi
leaq 0x3593(%rip), %rsi      # 0x779f
callq 0x2350
leaq -0x2730(%rbp), %rdi
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
callq 0x2350
movq 0x6da1(%rip), %rdi      # 0xafd0
leaq 0x383f(%rip), %rsi      # 0x7a75
callq 0x21d0
movq %rax, %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, %rdi
movq 0x6d64(%rip), %rsi      # 0xafb8
callq 0x21f0
leaq -0x2730(%rbp), %rdi
movl $0x2, %edx
xorl %eax, %eax
movl %eax, %ecx
movl %edx, %esi
callq 0x47e0
movq %rax, -0x5508(%rbp)
movq -0x5508(%rbp), %rsi
leaq -0x5908(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rsp, %rdi
movl $0x80, %ecx
leaq -0x5908(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x6f50(%rip), %rdi      # 0xb1f8
callq 0x5050
testb $0x1, %al
jne 0x430f
movl -0x14(%rbp), %edi
movq -0x5508(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
xorl %ecx, %ecx
callq 0x2100
movl %eax, -0x590c(%rbp)
movq 0x6cfc(%rip), %rdi      # 0xafd0
leaq 0x37b5(%rip), %rsi      # 0x7a90
callq 0x21d0
movq %rax, %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x3661(%rip), %rsi      # 0x795a
callq 0x21d0
movq %rax, %rdi
movq 0x6cb0(%rip), %rsi      # 0xafb8
callq 0x21f0
jmp 0x4353
movq 0x6cba(%rip), %rdi      # 0xafd0
leaq 0x3649(%rip), %rsi      # 0x7966
callq 0x21d0
movq %rax, %rdi
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x3778(%rip), %rsi      # 0x7ab7
callq 0x21d0
movq %rax, %rdi
movq 0x6c6a(%rip), %rsi      # 0xafb8
callq 0x21f0
movq -0x5508(%rbp), %rdi
callq 0x2220
jmp 0x44e7
leaq -0x2730(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq -0x10(%rbp), %rdi
callq 0x20d0
cmpq $0x0, %rax
jbe 0x4396
leaq -0x2730(%rbp), %rdi
leaq 0x340e(%rip), %rsi      # 0x779f
callq 0x2350
leaq -0x2730(%rbp), %rdi
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
callq 0x2350
movq 0x6c1c(%rip), %rdi      # 0xafd0
leaq 0x3732(%rip), %rsi      # 0x7aed
callq 0x21d0
movq %rax, %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, %rdi
movq 0x6bdf(%rip), %rsi      # 0xafb8
callq 0x21f0
leaq -0x2730(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x47e0
movq %rax, -0x5918(%rbp)
movq -0x5918(%rbp), %rsi
leaq -0x5d18(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rsp, %rdi
movl $0x80, %ecx
leaq -0x5d18(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x6dc8(%rip), %rdi      # 0xb1f8
callq 0x5050
testb $0x1, %al
jne 0x4497
movl -0x14(%rbp), %edi
movq -0x5918(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
xorl %ecx, %ecx
callq 0x2100
movl %eax, -0x5d1c(%rbp)
movq 0x6b74(%rip), %rdi      # 0xafd0
leaq 0x362d(%rip), %rsi      # 0x7a90
callq 0x21d0
movq %rax, %rdi
leaq -0x2730(%rbp), %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x3550(%rip), %rsi      # 0x79d1
callq 0x21d0
movq %rax, %rdi
movq 0x6b28(%rip), %rsi      # 0xafb8
callq 0x21f0
jmp 0x44db
movq 0x6b32(%rip), %rdi      # 0xafd0
leaq 0x3533(%rip), %rsi      # 0x79d8
callq 0x21d0
movq %rax, %rdi
movq -0x4680(%rbp), %rsi
addq $0x10, %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x3641(%rip), %rsi      # 0x7b08
callq 0x21d0
movq %rax, %rdi
movq 0x6ae2(%rip), %rsi      # 0xafb8
callq 0x21f0
movq -0x5918(%rbp), %rdi
callq 0x2220
jmp 0x44e9
jmp 0x44eb
jmp 0x44ed
jmp 0x44ef
movq -0x4680(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %ecx
addq $0x10, %rcx
movslq -0x4678(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x4678(%rbp)
jmp 0x3850
jmp 0x380e
movq -0x4ab0(%rbp), %rdi
callq 0x2340
nopw %cs:(%rax,%rax)