// File: supragya[P]DirectorySync/DirectorySync.cpp
// Function: reader(char*, int)
void reader(char *dirname, int new_socket) {
    std::cout << "#### Began thread [RECV]" <<std::endl;

    // Start receiving
    message *incoming = (message*)malloc(sizeof(message));
    int valread;
    char workCMD[WORKCMDLEN];
    while(1){
        valread = recv(new_socket ,(void*)incoming, sizeof(message), 0);
        if(incoming->valid == 0 || Transactions.already_processed(*incoming)){
            std::cout<<"[RECV] Recieved invalid/duplicate data packet. Probably the connection was closed. Quitting."<<std::endl;

            std::cout<<        "                                 +---------------------+\n";
            std::cout<<        "                                 | I am in sync. Yes   |\n";
            std::cout<<        "                                 +------------------+--+\n";
            std::cout<<        "                                                    |\n";
            std::cout<<        "                                                    |\n";
            std::cout<<        "  _                                                 |\n";
            std::cout<<        "  \\\\                                                |\n";
            std::cout<<        "   \\\\_          _.-._                               |\n";
            std::cout<<        "    X:\\        (_/ \\_)     <------------------------+\n";
            std::cout<<        "    \\::\\       ( ==  )\n";
            std::cout<<        "     \\::\\       \\== /\n";
            std::cout<<        "    /X:::\\   .-./`-'\\.--.\n";
            std::cout<<        "    \\\\/\\::\\ / /     (    l\n";
            std::cout<<        "     ~\\ \\::\\ /      `.   L.\n";
            std::cout<<        "       \\/:::|         `.'  `\n";
            std::cout<<        "       /:/\\:|          (    `.\n";
            std::cout<<        "       \\/`-'`.          >    )\n";
            std::cout<<        "              \\       //  .-'\n";
            std::cout<<        "               |     /(  .'\n";
            std::cout<<        "               `-..-'_ \\  \\\n";
            std::cout<<        "               __||/_ \\ `-'\n";
            std::cout<<        "              / _ \\ #  |\n";
            std::cout<<        "             |  #  |#  |   B-SD3 Security Droid\n";
            std::cout<<        "          LS |  #  |#  |      - Front View -\n";
            exit(0);
        }
        switch(incoming->FCType){
            case CREATE:
                if(incoming->FType == DIRECTORY){
                    if(!Transactions.record_message(*incoming)){
                        std::cout<<"[RECV] Cannot add transaction"<<std::endl;
                        exit(-1);
                    }
                    std::cout<<"[RECV]\tCreated\tDIR\t["<<incoming->FileName<<"]"<<std::endl;

                    strcpy(workCMD, "mkdir -p ");
                    strcat(workCMD, dirname);
                    strcat(workCMD, "/");
                    strcat(workCMD, incoming->FileName);

                    system(workCMD);

                    char *newintermediate = (char *)malloc(sizeof(char)*MAXFILENAMELEN);

                    strcpy(newintermediate, incoming->FileName);
                    std::thread currentrecv(reader, dirname, new_socket);
                    std::thread newfilewatcher(filewatcher, dirname, newintermediate, FCsock);
                    currentrecv.join();
                    newfilewatcher.join();

                }
                else if(incoming->FType == _FILE){
                    if(!Transactions.record_message(*incoming)){
                        std::cout<<"[RECV] Cannot add transaction"<<std::endl;
                        exit(-1);
                    }

                    std::cout<<"[RECV]\tCreated\tFIL\t["<<incoming->FileName<<"]"<<std::endl;

                    FileAccess.lock();
                    strcpy(workCMD, "touch ");
                    strcat(workCMD, dirname);
                    strcat(workCMD, "/");
                    strcat(workCMD, incoming->FileName);

                    system(workCMD);
                    FileAccess.unlock();

                }
                break;

            case MODIFY:
                if(incoming->FType == _FILE){
                    if(!Transactions.record_message(*incoming)){
                        std::cout<<"[RECV] Cannot add transaction"<<std::endl;
                        exit(-1);
                    }

                    std::cout<<"[RECV]\tModified\tFIL\t["<<incoming->FileName<<"] size = "<<incoming->FileSize<<" "<<std::endl;

                    FileAccess.lock();

                    strcpy(workCMD, dirname);
                    strcat(workCMD, "/");
                    strcat(workCMD, incoming->FileName);

                    std::ofstream filedump(workCMD, std::ios::binary);

                    char *filedata = (char *)malloc(incoming->FileSize);
                    read(new_socket, filedata, incoming->FileSize);
                    if(!filedump){
                        std::cout<<"[RECV] Error opening file "<<incoming->FileName<<std::endl;
                        exit(1);
                    }
                    filedump<<filedata;
                    free(filedata);
                    filedump.close();
                    incoming->FileSize = 0;
                    if(!Transactions.record_message(*incoming)){
                        std::cout<<"[RECV] Cannot add transaction"<<std::endl;
                        exit(-1);
                    }
                    FileAccess.unlock();

                }
                break;


            case DELETE:
                if(incoming->FType == DIRECTORY){
                    if(!Transactions.record_message(*incoming)){
                        std::cout<<"[RECV] Cannot add transaction"<<std::endl;
                        exit(-1);
                    }
                    std::cout<<"[RECV]\tDeleted\tDIR\t["<<incoming->FileName<<"]"<<std::endl;

                    strcpy(workCMD, "rm -r ");
                    strcat(workCMD, dirname);
                    strcat(workCMD, "/");
                    strcat(workCMD, incoming->FileName);

                    system(workCMD);
                }
                else if(incoming->FType == _FILE){
                    if(!Transactions.record_message(*incoming)){
                        std::cout<<"[RECV] Cannot add transaction"<<std::endl;
                        exit(-1);
                    }

                    std::cout<<"[RECV]\tDeleted\tFIL\t["<<incoming->FileName<<"]"<<std::endl;

                    strcpy(workCMD, "rm ");
                    strcat(workCMD, dirname);
                    strcat(workCMD, "/");
                    strcat(workCMD, incoming->FileName);

                    system(workCMD);

                }
                break;
            default:
                std::cout<<"[RECV] Unknown message received, QUIT"<<std::endl;
                exit(0);
        }

    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x49b0, %rsp           # imm = 0x49B0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq 0x8447(%rip), %rdi      # 0xafd0
leaq 0x47cb(%rip), %rsi      # 0x735b
callq 0x21d0
movq %rax, %rdi
movq 0x8419(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0x400, %edi            # imm = 0x400
callq 0x2260
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %edi
movq -0x18(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2c0d
movq -0x18(%rbp), %rsi
leaq -0x2b30(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rsp, %rdi
movl $0x80, %ecx
leaq -0x2b30(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x85f9(%rip), %rdi      # 0xb1f8
callq 0x4cf0
testb $0x1, %al
jne 0x2c0d
jmp 0x2dfe
movq 0x83bc(%rip), %rdi      # 0xafd0
leaq 0x4759(%rip), %rsi      # 0x7374
callq 0x21d0
movq %rax, %rdi
movq 0x838e(%rip), %rsi      # 0xafb8
callq 0x21f0
movq 0x839a(%rip), %rdi      # 0xafd0
leaq 0x4794(%rip), %rsi      # 0x73d1
callq 0x21d0
movq 0x8387(%rip), %rdi      # 0xafd0
leaq 0x47bb(%rip), %rsi      # 0x740b
callq 0x21d0
movq 0x8374(%rip), %rdi      # 0xafd0
leaq 0x47e2(%rip), %rsi      # 0x7445
callq 0x21d0
movq 0x8361(%rip), %rdi      # 0xafd0
leaq 0x4809(%rip), %rsi      # 0x747f
callq 0x21d0
movq 0x834e(%rip), %rdi      # 0xafd0
leaq 0x47f6(%rip), %rsi      # 0x747f
callq 0x21d0
movq 0x833b(%rip), %rdi      # 0xafd0
leaq 0x481a(%rip), %rsi      # 0x74b6
callq 0x21d0
movq 0x8328(%rip), %rdi      # 0xafd0
leaq 0x483e(%rip), %rsi      # 0x74ed
callq 0x21d0
movq 0x8315(%rip), %rdi      # 0xafd0
leaq 0x4862(%rip), %rsi      # 0x7524
callq 0x21d0
movq 0x8302(%rip), %rdi      # 0xafd0
leaq 0x4886(%rip), %rsi      # 0x755b
callq 0x21d0
movq 0x82ef(%rip), %rdi      # 0xafd0
leaq 0x48aa(%rip), %rsi      # 0x7592
callq 0x21d0
movq 0x82dc(%rip), %rdi      # 0xafd0
leaq 0x48af(%rip), %rsi      # 0x75aa
callq 0x21d0
movq 0x82c9(%rip), %rdi      # 0xafd0
leaq 0x48b3(%rip), %rsi      # 0x75c1
callq 0x21d0
movq 0x82b6(%rip), %rdi      # 0xafd0
leaq 0x48bb(%rip), %rsi      # 0x75dc
callq 0x21d0
movq 0x82a3(%rip), %rdi      # 0xafd0
leaq 0x48c4(%rip), %rsi      # 0x75f8
callq 0x21d0
movq 0x8290(%rip), %rdi      # 0xafd0
leaq 0x48ce(%rip), %rsi      # 0x7615
callq 0x21d0
movq 0x827d(%rip), %rdi      # 0xafd0
leaq 0x48d9(%rip), %rsi      # 0x7633
callq 0x21d0
movq 0x826a(%rip), %rdi      # 0xafd0
leaq 0x48e6(%rip), %rsi      # 0x7653
callq 0x21d0
movq 0x8257(%rip), %rdi      # 0xafd0
leaq 0x48f3(%rip), %rsi      # 0x7673
callq 0x21d0
movq 0x8244(%rip), %rdi      # 0xafd0
leaq 0x48ff(%rip), %rsi      # 0x7692
callq 0x21d0
movq 0x8231(%rip), %rdi      # 0xafd0
leaq 0x4909(%rip), %rsi      # 0x76af
callq 0x21d0
movq 0x821e(%rip), %rdi      # 0xafd0
leaq 0x4913(%rip), %rsi      # 0x76cc
callq 0x21d0
movq 0x820b(%rip), %rdi      # 0xafd0
leaq 0x491d(%rip), %rsi      # 0x76e9
callq 0x21d0
movq 0x81f8(%rip), %rdi      # 0xafd0
leaq 0x4924(%rip), %rsi      # 0x7703
callq 0x21d0
movq 0x81e5(%rip), %rdi      # 0xafd0
leaq 0x4942(%rip), %rsi      # 0x7734
callq 0x21d0
xorl %edi, %edi
callq 0x2230
movq -0x18(%rbp), %rax
movl 0x3ec(%rax), %eax
movl %eax, -0x4564(%rbp)
subl $0x1, %eax
je 0x3164
jmp 0x2e19
movl -0x4564(%rbp), %eax
subl $0x2, %eax
je 0x345d
jmp 0x2e2a
movl -0x4564(%rbp), %eax
subl $0x3, %eax
jne 0x367c
jmp 0x2e3b
movq -0x18(%rbp), %rax
cmpl $0x2, 0x3f0(%rax)
jne 0x303a
movq -0x18(%rbp), %rsi
leaq -0x2f30(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rsp, %rdi
movl $0x80, %ecx
leaq -0x2f30(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x837e(%rip), %rdi      # 0xb1f8
callq 0x4e10
testb $0x1, %al
jne 0x2eaf
movq 0x8146(%rip), %rdi      # 0xafd0
leaq 0x48d1(%rip), %rsi      # 0x7762
callq 0x21d0
movq %rax, %rdi
movq 0x8118(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2230
movq 0x811a(%rip), %rdi      # 0xafd0
leaq 0x48c3(%rip), %rsi      # 0x7780
callq 0x21d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x4995(%rip), %rsi      # 0x7871
callq 0x21d0
movq %rax, %rdi
movq 0x80cd(%rip), %rsi      # 0xafb8
callq 0x21f0
leaq 0x489e(%rip), %rsi      # 0x7795
leaq -0x2730(%rbp), %rdi
movq %rdi, -0x4578(%rbp)
callq 0x21b0
movq -0x4578(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x2350
movq -0x4578(%rbp), %rdi
leaq 0x4877(%rip), %rsi      # 0x779f
callq 0x2350
movq -0x4578(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x2350
movq -0x4578(%rbp), %rdi
callq 0x2180
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x2260
movq %rax, -0x2f38(%rbp)
movq -0x2f38(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x21b0
leaq -0x409(%rip), %rsi      # 0x2b70
leaq -0x2f40(%rbp), %rdi
leaq -0x8(%rbp), %rdx
movq %rdx, -0x4570(%rbp)
leaq -0xc(%rbp), %rcx
callq 0x4a80
movq -0x4570(%rbp), %rdx
leaq 0x71e(%rip), %rsi       # 0x36c0
leaq 0x21307(%rip), %r8      # 0x242b0
leaq -0x2f48(%rbp), %rdi
leaq -0x2f38(%rbp), %rcx
callq 0x4f30
jmp 0x2fbe
leaq -0x2f40(%rbp), %rdi
callq 0x2300
jmp 0x2fcc
leaq -0x2f48(%rbp), %rdi
callq 0x2300
jmp 0x2fda
leaq -0x2f48(%rbp), %rdi
callq 0x4cc0
leaq -0x2f40(%rbp), %rdi
callq 0x4cc0
jmp 0x315f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2f50(%rbp)
movl %eax, -0x2f54(%rbp)
jmp 0x3029
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2f50(%rbp)
movl %eax, -0x2f54(%rbp)
leaq -0x2f48(%rbp), %rdi
callq 0x4cc0
leaq -0x2f40(%rbp), %rdi
callq 0x4cc0
jmp 0x36aa
movq -0x18(%rbp), %rax
cmpl $0x1, 0x3f0(%rax)
jne 0x315d
movq -0x18(%rbp), %rsi
leaq -0x3358(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rsp, %rdi
movl $0x80, %ecx
leaq -0x3358(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x817f(%rip), %rdi      # 0xb1f8
callq 0x4e10
testb $0x1, %al
jne 0x30ae
movq 0x7f47(%rip), %rdi      # 0xafd0
leaq 0x46d2(%rip), %rsi      # 0x7762
callq 0x21d0
movq %rax, %rdi
movq 0x7f19(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2230
movq 0x7f1b(%rip), %rdi      # 0xafd0
leaq 0x46e5(%rip), %rsi      # 0x77a1
callq 0x21d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x4796(%rip), %rsi      # 0x7871
callq 0x21d0
movq %rax, %rdi
movq 0x7ece(%rip), %rsi      # 0xafb8
callq 0x21f0
leaq 0x21192(%rip), %rdi     # 0x24288
callq 0x5000
leaq -0x2730(%rbp), %rdi
leaq 0x46ad(%rip), %rsi      # 0x77b6
callq 0x21b0
leaq -0x2730(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x2350
leaq -0x2730(%rbp), %rdi
leaq 0x4673(%rip), %rsi      # 0x779f
callq 0x2350
leaq -0x2730(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x2350
leaq -0x2730(%rbp), %rdi
callq 0x2180
leaq 0x21130(%rip), %rdi     # 0x24288
callq 0x5030
jmp 0x315f
jmp 0x36a5
movq -0x18(%rbp), %rax
cmpl $0x1, 0x3f0(%rax)
jne 0x3458
movq -0x18(%rbp), %rsi
leaq -0x3758(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rsp, %rdi
movl $0x80, %ecx
leaq -0x3758(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x8055(%rip), %rdi      # 0xb1f8
callq 0x4e10
testb $0x1, %al
jne 0x31d8
movq 0x7e1d(%rip), %rdi      # 0xafd0
leaq 0x45a8(%rip), %rsi      # 0x7762
callq 0x21d0
movq %rax, %rdi
movq 0x7def(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2230
movq 0x7df1(%rip), %rdi      # 0xafd0
leaq 0x45d7(%rip), %rsi      # 0x77bd
callq 0x21d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x45ce(%rip), %rsi      # 0x77d3
callq 0x21d0
movq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x3f8(%rax), %rsi
callq 0x2060
movq %rax, %rdi
leaq 0x45b4(%rip), %rsi      # 0x77db
callq 0x21d0
movq %rax, %rdi
movq 0x7d82(%rip), %rsi      # 0xafb8
callq 0x21f0
leaq 0x21046(%rip), %rdi     # 0x24288
callq 0x5000
movq -0x8(%rbp), %rsi
leaq -0x2730(%rbp), %rdi
movq %rdi, -0x4580(%rbp)
callq 0x21b0
movq -0x4580(%rbp), %rdi
leaq 0x4533(%rip), %rsi      # 0x779f
callq 0x2350
movq -0x4580(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x2350
movq -0x4580(%rbp), %rsi
leaq -0x3958(%rbp), %rdi
movl $0x4, %edx
callq 0x2200
movq -0x18(%rbp), %rax
movq 0x3f8(%rax), %rdi
callq 0x2260
movq %rax, -0x3960(%rbp)
movl -0xc(%rbp), %edi
movq -0x3960(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x3f8(%rax), %rdx
callq 0x22b0
jmp 0x32d0
movq -0x3958(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x3958(%rbp,%rax), %rdi
callq 0x20e0
movb %al, -0x4581(%rbp)
jmp 0x32f0
movb -0x4581(%rbp), %al
testb $0x1, %al
jne 0x32fc
jmp 0x3377
movq 0x7ccd(%rip), %rdi      # 0xafd0
leaq 0x44d3(%rip), %rsi      # 0x77dd
callq 0x21d0
movq %rax, -0x4590(%rbp)
jmp 0x3318
movq -0x4590(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x21d0
movq %rax, -0x4598(%rbp)
jmp 0x3335
movq -0x4598(%rbp), %rdi
movq 0x7c75(%rip), %rsi      # 0xafb8
callq 0x21f0
jmp 0x334a
movl $0x1, %edi
callq 0x2230
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2f50(%rbp)
movl %eax, -0x2f54(%rbp)
leaq -0x3958(%rbp), %rdi
callq 0x22d0
jmp 0x36aa
movq -0x3960(%rbp), %rsi
leaq -0x3958(%rbp), %rdi
callq 0x21d0
jmp 0x338c
movq -0x3960(%rbp), %rdi
callq 0x2220
leaq -0x3958(%rbp), %rdi
callq 0x22a0
jmp 0x33a6
movq -0x18(%rbp), %rax
movq $0x0, 0x3f8(%rax)
movq -0x18(%rbp), %rsi
leaq -0x3d60(%rbp), %rdi
movq %rdi, -0x45a8(%rbp)
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq -0x45a8(%rbp), %rsi
movq %rsp, %rdi
movl $0x80, %ecx
rep  movsq (%rsi), %es:(%rdi)
leaq 0x7e0e(%rip), %rdi      # 0xb1f8
callq 0x4e10
movb %al, -0x4599(%rbp)
jmp 0x33f7
movb -0x4599(%rbp), %al
testb $0x1, %al
jne 0x343e
jmp 0x3403
movq 0x7bc6(%rip), %rdi      # 0xafd0
leaq 0x4351(%rip), %rsi      # 0x7762
callq 0x21d0
movq %rax, -0x45b0(%rbp)
jmp 0x341f
movq -0x45b0(%rbp), %rdi
movq 0x7b8b(%rip), %rsi      # 0xafb8
callq 0x21f0
jmp 0x3434
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2230
leaq 0x20e43(%rip), %rdi     # 0x24288
callq 0x5030
jmp 0x344c
leaq -0x3958(%rbp), %rdi
callq 0x22d0
jmp 0x36a5
movq -0x18(%rbp), %rax
cmpl $0x2, 0x3f0(%rax)
jne 0x356d
movq -0x18(%rbp), %rsi
leaq -0x4160(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rsp, %rdi
movl $0x80, %ecx
leaq -0x4160(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x7d5c(%rip), %rdi      # 0xb1f8
callq 0x4e10
testb $0x1, %al
jne 0x34d1
movq 0x7b24(%rip), %rdi      # 0xafd0
leaq 0x42af(%rip), %rsi      # 0x7762
callq 0x21d0
movq %rax, %rdi
movq 0x7af6(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2230
movq 0x7af8(%rip), %rdi      # 0xafd0
leaq 0x4319(%rip), %rsi      # 0x77f8
callq 0x21d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x4373(%rip), %rsi      # 0x7871
callq 0x21d0
movq %rax, %rdi
movq 0x7aab(%rip), %rsi      # 0xafb8
callq 0x21f0
leaq -0x2730(%rbp), %rdi
leaq 0x42ed(%rip), %rsi      # 0x780d
callq 0x21b0
leaq -0x2730(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x2350
leaq -0x2730(%rbp), %rdi
leaq 0x425c(%rip), %rsi      # 0x779f
callq 0x2350
leaq -0x2730(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x2350
leaq -0x2730(%rbp), %rdi
callq 0x2180
jmp 0x367a
movq -0x18(%rbp), %rax
cmpl $0x1, 0x3f0(%rax)
jne 0x3678
movq -0x18(%rbp), %rsi
leaq -0x4560(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rsp, %rdi
movl $0x80, %ecx
leaq -0x4560(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x7c4c(%rip), %rdi      # 0xb1f8
callq 0x4e10
testb $0x1, %al
jne 0x35e1
movq 0x7a14(%rip), %rdi      # 0xafd0
leaq 0x419f(%rip), %rsi      # 0x7762
callq 0x21d0
movq %rax, %rdi
movq 0x79e6(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2230
movq 0x79e8(%rip), %rdi      # 0xafd0
leaq 0x4225(%rip), %rsi      # 0x7814
callq 0x21d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0x4263(%rip), %rsi      # 0x7871
callq 0x21d0
movq %rax, %rdi
movq 0x799b(%rip), %rsi      # 0xafb8
callq 0x21f0
leaq -0x2730(%rbp), %rdi
leaq 0x41f9(%rip), %rsi      # 0x7829
callq 0x21b0
leaq -0x2730(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x2350
leaq -0x2730(%rbp), %rdi
leaq 0x414c(%rip), %rsi      # 0x779f
callq 0x2350
leaq -0x2730(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x2350
leaq -0x2730(%rbp), %rdi
callq 0x2180
jmp 0x367a
jmp 0x36a5
movq 0x794d(%rip), %rdi      # 0xafd0
leaq 0x41a3(%rip), %rsi      # 0x782d
callq 0x21d0
movq %rax, %rdi
movq 0x791f(%rip), %rsi      # 0xafb8
callq 0x21f0
xorl %edi, %edi
callq 0x2230
jmp 0x2bb2
movq -0x2f50(%rbp), %rdi
callq 0x2340
nopw %cs:(%rax,%rax)