// File: girdhari9[P]mTORRENT/ClientConnection.cpp
// Function: FunctionCalling(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int FunctionCalling(string filename, int RequestType,string SHA_TO_Add, string root_path){
    sem_init(&mutex1, 0, 1);
    int FileSize;
    string FileName, SHA;
    if(filename.size() > 9 && filename.substr(filename.size()-9) != ".mtorrent"){
        cout<<"\n> Please give name of mtorrent file!\n";
        return 0;
    }

    int TorrentFileD = open(filename.c_str(), O_RDONLY, O_SYNC);
    ReadFileByLine(TorrentFileD,1);

    int sock = TrackerConnection(mTorrentFileData[0],atoi(mTorrentFileData[1].c_str()));
    if(sock == -1){
        cout<<"Error in connection\n";
        exit(0);
    }
    else{
        cout<<"> Connected with Tracker: "<<mTorrentFileData[0]<<":"<<mTorrentFileData[1]<<"";
    }
    if(RequestType == 1){

        ReadFileByLine(TorrentFileD,0);
        ReadFileByLine(TorrentFileD,0);
        int FileSize = stoi(mTorrentFileData[0]);
        int TotalPacket = FileSize/DataSize;
        int LastPartSize = FileSize - TotalPacket * DataSize;
        if(LastPartSize) TotalPacket++;

        SendToSeederList(filename,SHA_TO_Add,sock,root_path,1);
        SetBitMap(TotalPacket, 1, SHA_TO_Add);
        close(sock);
        close(TorrentFileD);
        printf("> Connection closed!\n");
    }
    else if(RequestType == 2){
        ReadFileByLine(TorrentFileD,0);
        ReadFileByLine(TorrentFileD,0);
        ReadFileByLine(TorrentFileD,0);

        SHA = ReadSHA(TorrentFileD);
        SHA = SHA.substr(0,20);
        SendToSeederList(filename,SHA,sock,root_path,2);
        close(sock);
        close(TorrentFileD);
        printf("> Connection closed!\n");
    }
    else{
        ReadFileByLine(TorrentFileD,0);
        cout<<"> You are requesting to download: "<<mTorrentFileData[0];
        FileName = mTorrentFileData[0];

        ReadFileByLine(TorrentFileD,0);
        cout<<"> File Size: "<<mTorrentFileData[0];
        FileSize = stoi(mTorrentFileData[0]);

        ReadFileByLine(TorrentFileD,0);
        SHA = ReadSHA(TorrentFileD);
        SHA = SHA.substr(0,20);

        GetSeedersDetails(sock,SHA);
        
        SendToSeederList(filename,SHA,sock,root_path,1);

        close(sock);
        close(TorrentFileD);
        cout<<"> Tracker Connection Closed!\n";

        // Connections using multithreads
        int ConDetailIndex = 0;
        TotalConn = ConDetail.size()/3;

        int LastPartSize = 0;
        int TotalPacket = FileSize/DataSize;
        LastPartSize = FileSize - TotalPacket * DataSize;

        if(LastPartSize) TotalPacket++;

        SetBitMap(TotalPacket, 0, SHA);

        int BitMap[TotalPacket];
        memset(&BitMap, -1, sizeof(BitMap));

        thread *threadptr = new thread[TotalConn];
        for(int thread_n = 0; thread_n < TotalConn; thread_n++,ConDetailIndex+=3){
            threadptr[thread_n] = thread(BitVectorRequestToServers,ConDetail[ConDetailIndex],atoi(ConDetail[ConDetailIndex+1].c_str()),thread_n,TotalPacket,ref(SHA));
        }
        
        for(int thread_n=0; thread_n < TotalConn; thread_n++,ConDetailIndex++){
            threadptr[thread_n].join();
        }

        delete [] threadptr;

        PieceSelection(TotalPacket,TotalConn,BitMap);

        vector<int> BitMap1(BitMap, BitMap + sizeof(BitMap) / sizeof(BitMap[0]));

        ConDetailIndex = 0;
        ofstream output;
        string NewFileName = "new_" + FileName.substr(0,FileName.size()-1);
        output.open(NewFileName.c_str(), ofstream::binary);

        thread *Threadptr = new thread[TotalConn];
        for(int thread_n = 0; thread_n < TotalConn; thread_n++,ConDetailIndex+=3){
            Threadptr[thread_n] = thread(clientConnection,ConDetail[ConDetailIndex],atoi(ConDetail[ConDetailIndex+1].c_str()),ref(FileName),FileSize,LastPartSize,TotalPacket,BitMap1,thread_n,ref(output),ref(SHA));
        }
        
        for(int thread_n=0; thread_n < TotalConn; thread_n++,ConDetailIndex++){
            Threadptr[thread_n].join();
        }
        //End of MultithNewFileNameread
        output.close();
    }
    // RecieveData(sock,FileName,FileSize);
    sem_destroy(&mutex1);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x770, %rsp            # imm = 0x770
movq %rdi, -0x5d8(%rbp)
movq %rdx, -0x5e8(%rbp)
movq %rcx, -0x5e0(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
leaq 0x16c4a(%rip), %rdi     # 0x219b0
xorl %esi, %esi
movl $0x1, %edx
callq 0x4390
leaq -0x50(%rbp), %rdi
callq 0x45a0
leaq -0x70(%rbp), %rdi
callq 0x45a0
movq -0x5d8(%rbp), %rdi
callq 0x42f0
movq %rax, %rcx
movb $0x0, -0x9d(%rbp)
xorl %eax, %eax
cmpq $0x9, %rcx
movb %al, -0x5cd(%rbp)
jbe 0xae07
movq -0x5d8(%rbp), %rdi
callq 0x42f0
movq -0x5d8(%rbp), %rsi
movq %rax, %rdx
addq $-0x9, %rdx
leaq -0x90(%rbp), %rdi
movq $-0x1, %rcx
callq 0x4420
jmp 0xadd7
movb $0x1, -0x9d(%rbp)
leaq 0xb24a(%rip), %rsi      # 0x1602f
leaq -0x90(%rbp), %rdi
callq 0x7190
movb %al, -0x5e9(%rbp)
jmp 0xadf9
movb -0x5e9(%rbp), %al
movb %al, -0x5cd(%rbp)
jmp 0xae07
movb -0x5cd(%rbp), %al
movb %al, -0x5ea(%rbp)
testb $0x1, -0x9d(%rbp)
jne 0xae1e
jmp 0xae2a
leaq -0x90(%rbp), %rdi
callq 0x47e8
movb -0x5ea(%rbp), %al
testb $0x1, %al
jne 0xae36
jmp 0xaea6
movq 0x1618b(%rip), %rdi     # 0x20fc8
leaq 0xb4e2(%rip), %rsi      # 0x16326
callq 0x43f0
jmp 0xae4b
movl $0x0, -0x4(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0xbfe6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xc000
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
testb $0x1, -0x9d(%rbp)
jne 0xae95
jmp 0xaea1
leaq -0x90(%rbp), %rdi
callq 0x47e8
jmp 0xc000
movq -0x5d8(%rbp), %rdi
callq 0x41f0
movq %rax, %rdi
xorl %esi, %esi
movb %sil, %al
movl $0x101000, %edx         # imm = 0x101000
callq 0x4310
movl %eax, -0x5f0(%rbp)
jmp 0xaecc
movl -0x5f0(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0xa8(%rbp), %edi
movl $0x1, %esi
callq 0xc020
jmp 0xaeea
leaq 0x16aa7(%rip), %rdi     # 0x21998
xorl %eax, %eax
movl %eax, %esi
callq 0x72c0
movq %rax, %rsi
leaq -0xd0(%rbp), %rdi
callq 0x4200
jmp 0xaf0b
leaq 0x16a86(%rip), %rdi     # 0x21998
movl $0x1, %esi
callq 0x72c0
movq %rax, %rdi
callq 0x41f0
movq %rax, %rdi
callq 0x4620
movl %eax, %esi
leaq -0xd0(%rbp), %rdi
callq 0xc310
movl %eax, -0x5f4(%rbp)
jmp 0xaf42
leaq -0xd0(%rbp), %rdi
callq 0x47e8
movl -0x5f4(%rbp), %eax
movl %eax, -0xac(%rbp)
cmpl $-0x1, -0xac(%rbp)
jne 0xafa2
movq 0x1605e(%rip), %rdi     # 0x20fc8
leaq 0xb3dc(%rip), %rsi      # 0x1634d
callq 0x43f0
jmp 0xaf78
xorl %edi, %edi
callq 0x44e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x47e8
jmp 0xc000
movq 0x1601f(%rip), %rdi     # 0x20fc8
leaq 0xb3b2(%rip), %rsi      # 0x16362
callq 0x43f0
movq %rax, -0x600(%rbp)
jmp 0xafbe
leaq 0x169d3(%rip), %rdi     # 0x21998
xorl %eax, %eax
movl %eax, %esi
callq 0x72c0
movq -0x600(%rbp), %rdi
movq %rax, %rsi
callq 0x43c0
movq %rax, -0x608(%rbp)
jmp 0xafe6
movq -0x608(%rbp), %rdi
leaq 0xb0e2(%rip), %rsi      # 0x160d6
callq 0x43f0
movq %rax, -0x610(%rbp)
jmp 0xb002
leaq 0x1698f(%rip), %rdi     # 0x21998
movl $0x1, %esi
callq 0x72c0
movq -0x610(%rbp), %rdi
movq %rax, %rsi
callq 0x43c0
movq %rax, -0x618(%rbp)
jmp 0xb02b
movq -0x618(%rbp), %rdi
leaq 0xb406(%rip), %rsi      # 0x1643f
callq 0x43f0
jmp 0xb040
jmp 0xb042
cmpl $0x1, -0x14(%rbp)
jne 0xb27e
movl -0xa8(%rbp), %edi
xorl %esi, %esi
callq 0xc020
jmp 0xb05b
movl -0xa8(%rbp), %edi
xorl %esi, %esi
callq 0xc020
jmp 0xb06a
leaq 0x16927(%rip), %rdi     # 0x21998
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x628(%rbp)
callq 0x72c0
movq -0x628(%rbp), %rsi
movq %rax, %rdi
movl $0xa, %edx
callq 0x6e40
movl %eax, -0x61c(%rbp)
jmp 0xb09d
movl -0x61c(%rbp), %eax
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
movl $0x400, %ecx            # imm = 0x400
cltd
idivl %ecx
movl %eax, -0xd8(%rbp)
movl -0xd4(%rbp), %eax
movl -0xd8(%rbp), %ecx
shll $0xa, %ecx
subl %ecx, %eax
movl %eax, -0xdc(%rbp)
cmpl $0x0, -0xdc(%rbp)
je 0xb0ec
movl -0xd8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd8(%rbp)
movq -0x5d8(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x4200
jmp 0xb101
movq -0x5e8(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x4200
jmp 0xb116
movq -0x5e0(%rbp), %rsi
movl -0xac(%rbp), %eax
movl %eax, -0x62c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x4200
jmp 0xb137
movl -0x62c(%rbp), %edx
leaq -0x100(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x140(%rbp), %rcx
movl $0x1, %r8d
callq 0xc400
jmp 0xb15f
leaq -0x140(%rbp), %rdi
callq 0x47e8
leaq -0x120(%rbp), %rdi
callq 0x47e8
leaq -0x100(%rbp), %rdi
callq 0x47e8
movq -0x5e8(%rbp), %rsi
movl -0xd8(%rbp), %eax
movl %eax, -0x630(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x4200
jmp 0xb1a4
movl -0x630(%rbp), %edi
movl $0x1, %esi
leaq -0x160(%rbp), %rdx
callq 0x142c0
jmp 0xb1bd
leaq -0x160(%rbp), %rdi
callq 0x47e8
movl -0xac(%rbp), %edi
callq 0x47b0
jmp 0xb1d6
movl -0xa8(%rbp), %edi
callq 0x47b0
jmp 0xb1e3
leaq 0xb193(%rip), %rdi      # 0x1637d
xorl %eax, %eax
callq 0x4070
jmp 0xb1f3
jmp 0xbfc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xb24a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xb23e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x47e8
leaq -0x120(%rbp), %rdi
callq 0x47e8
leaq -0x100(%rbp), %rdi
callq 0x47e8
jmp 0xc000
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x47e8
jmp 0xc000
cmpl $0x2, -0x14(%rbp)
jne 0xb45a
movl -0xa8(%rbp), %edi
xorl %esi, %esi
callq 0xc020
jmp 0xb297
movl -0xa8(%rbp), %edi
xorl %esi, %esi
callq 0xc020
jmp 0xb2a6
movl -0xa8(%rbp), %edi
xorl %esi, %esi
callq 0xc020
jmp 0xb2b5
movl -0xa8(%rbp), %esi
leaq -0x180(%rbp), %rdi
callq 0xc600
jmp 0xb2c9
leaq -0x70(%rbp), %rdi
movq %rdi, -0x638(%rbp)
leaq -0x180(%rbp), %rsi
movq %rsi, -0x640(%rbp)
callq 0x44f0
movq -0x640(%rbp), %rdi
callq 0x47e8
movq -0x638(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x1a0(%rbp), %rdi
movl $0x14, %ecx
callq 0x4420
jmp 0xb311
leaq -0x70(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
movq %rsi, -0x648(%rbp)
callq 0x44f0
movq -0x648(%rbp), %rdi
callq 0x47e8
movq -0x5d8(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x4200
jmp 0xb349
leaq -0x1e0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4200
jmp 0xb35b
movq -0x5e0(%rbp), %rsi
movl -0xac(%rbp), %eax
movl %eax, -0x64c(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x4200
jmp 0xb37c
movl -0x64c(%rbp), %edx
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
leaq -0x200(%rbp), %rcx
movl $0x2, %r8d
callq 0xc400
jmp 0xb3a4
leaq -0x200(%rbp), %rdi
callq 0x47e8
leaq -0x1e0(%rbp), %rdi
callq 0x47e8
leaq -0x1c0(%rbp), %rdi
callq 0x47e8
movl -0xac(%rbp), %edi
callq 0x47b0
jmp 0xb3d5
movl -0xa8(%rbp), %edi
callq 0x47b0
jmp 0xb3e2
leaq 0xaf94(%rip), %rdi      # 0x1637d
xorl %eax, %eax
callq 0x4070
jmp 0xb3f2
jmp 0xbfc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xb449
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xb43d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x47e8
leaq -0x1e0(%rbp), %rdi
callq 0x47e8
leaq -0x1c0(%rbp), %rdi
callq 0x47e8
jmp 0xc000
movl -0xa8(%rbp), %edi
xorl %esi, %esi
callq 0xc020
jmp 0xb469
movq 0x15b58(%rip), %rdi     # 0x20fc8
leaq 0xaf1c(%rip), %rsi      # 0x16393
callq 0x43f0
movq %rax, -0x658(%rbp)
jmp 0xb485
leaq 0x1650c(%rip), %rdi     # 0x21998
xorl %eax, %eax
movl %eax, %esi
callq 0x72c0
movq -0x658(%rbp), %rdi
movq %rax, %rsi
callq 0x43c0
jmp 0xb4a6
leaq 0x164eb(%rip), %rdi     # 0x21998
xorl %eax, %eax
movl %eax, %esi
callq 0x72c0
movq %rax, %rsi
leaq -0x50(%rbp), %rdi
callq 0x4050
jmp 0xb4c4
movl -0xa8(%rbp), %edi
xorl %esi, %esi
callq 0xc020
jmp 0xb4d3
movq 0x15aee(%rip), %rdi     # 0x20fc8
leaq 0xaed5(%rip), %rsi      # 0x163b6
callq 0x43f0
movq %rax, -0x660(%rbp)
jmp 0xb4ef
leaq 0x164a2(%rip), %rdi     # 0x21998
xorl %eax, %eax
movl %eax, %esi
callq 0x72c0
movq -0x660(%rbp), %rdi
movq %rax, %rsi
callq 0x43c0
jmp 0xb510
leaq 0x16481(%rip), %rdi     # 0x21998
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x670(%rbp)
callq 0x72c0
movq -0x670(%rbp), %rsi
movq %rax, %rdi
movl $0xa, %edx
callq 0x6e40
movl %eax, -0x664(%rbp)
jmp 0xb543
movl -0x664(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0xa8(%rbp), %edi
xorl %esi, %esi
callq 0xc020
jmp 0xb55b
movl -0xa8(%rbp), %esi
leaq -0x220(%rbp), %rdi
callq 0xc600
jmp 0xb56f
leaq -0x70(%rbp), %rdi
movq %rdi, -0x678(%rbp)
leaq -0x220(%rbp), %rsi
movq %rsi, -0x680(%rbp)
callq 0x44f0
movq -0x680(%rbp), %rdi
callq 0x47e8
movq -0x678(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x240(%rbp), %rdi
movl $0x14, %ecx
callq 0x4420
jmp 0xb5b7
leaq -0x70(%rbp), %rdi
movq %rdi, -0x690(%rbp)
leaq -0x240(%rbp), %rsi
movq %rsi, -0x698(%rbp)
callq 0x44f0
movq -0x698(%rbp), %rdi
callq 0x47e8
movq -0x690(%rbp), %rsi
movl -0xac(%rbp), %eax
movl %eax, -0x684(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x4200
jmp 0xb602
movl -0x684(%rbp), %edi
leaq -0x260(%rbp), %rsi
callq 0xc720
jmp 0xb616
leaq -0x260(%rbp), %rdi
callq 0x47e8
movq -0x5d8(%rbp), %rsi
leaq -0x280(%rbp), %rdi
callq 0x4200
jmp 0xb637
leaq -0x2a0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4200
jmp 0xb649
movq -0x5e0(%rbp), %rsi
movl -0xac(%rbp), %eax
movl %eax, -0x69c(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x4200
jmp 0xb66a
movl -0x69c(%rbp), %edx
leaq -0x280(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
leaq -0x2c0(%rbp), %rcx
movl $0x1, %r8d
callq 0xc400
jmp 0xb692
leaq -0x2c0(%rbp), %rdi
callq 0x47e8
leaq -0x2a0(%rbp), %rdi
callq 0x47e8
leaq -0x280(%rbp), %rdi
callq 0x47e8
movl -0xac(%rbp), %edi
callq 0x47b0
jmp 0xb6c3
movl -0xa8(%rbp), %edi
callq 0x47b0
jmp 0xb6d0
movq 0x158f1(%rip), %rdi     # 0x20fc8
leaq 0xace6(%rip), %rsi      # 0x163c4
callq 0x43f0
jmp 0xb6e5
movl $0x0, -0x2c4(%rbp)
leaq 0x1628a(%rip), %rdi     # 0x21980
callq 0x72a0
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movl %eax, 0x162c5(%rip)     # 0x219d0
movl $0x0, -0x2c8(%rbp)
movl -0x2c(%rbp), %eax
movl $0x400, %ecx            # imm = 0x400
cltd
idivl %ecx
movl %eax, -0x2cc(%rbp)
movl -0x2c(%rbp), %eax
movl -0x2cc(%rbp), %ecx
shll $0xa, %ecx
subl %ecx, %eax
movl %eax, -0x2c8(%rbp)
cmpl $0x0, -0x2c8(%rbp)
je 0xb7e1
movl -0x2cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2cc(%rbp)
jmp 0xb7e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x47e8
jmp 0xc000
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xb7d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xb7c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x47e8
leaq -0x2a0(%rbp), %rdi
callq 0x47e8
leaq -0x280(%rbp), %rdi
callq 0x47e8
jmp 0xc000
movl -0x2cc(%rbp), %eax
movl %eax, -0x6a0(%rbp)
leaq -0x2f0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4200
jmp 0xb7ff
movl -0x6a0(%rbp), %edi
xorl %esi, %esi
leaq -0x2f0(%rbp), %rdx
callq 0x142c0
jmp 0xb815
leaq -0x2f0(%rbp), %rdi
callq 0x47e8
movl -0x2cc(%rbp), %eax
movq %rax, -0x6c0(%rbp)
movq %rsp, %rcx
movq %rcx, -0x2f8(%rbp)
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x6b8(%rbp)
movq %rdi, %rsp
movq %rax, %rdx
shlq $0x2, %rdx
movq %rax, -0x300(%rbp)
movl $0xff, %esi
callq 0x4260
movslq 0x1615d(%rip), %rax     # 0x219d0
movq %rax, -0x6b0(%rbp)
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
movq $-0x1, %rax
cmovbq %rax, %rdi
testb %cl, %cl
cmovneq %rax, %rdi
callq 0x4030
movq %rax, -0x6a8(%rbp)
jmp 0xb8ab
movq -0x6b0(%rbp), %rax
movq -0x6a8(%rbp), %rcx
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x6c8(%rbp)
cmpq $0x0, %rax
je 0xb924
movq -0x6c8(%rbp), %rax
movq -0x6b0(%rbp), %rdx
shlq $0x3, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x6d8(%rbp)
movq %rax, -0x6d0(%rbp)
movq -0x6d0(%rbp), %rdi
movq %rdi, -0x6e0(%rbp)
callq 0xdaf0
movq -0x6e0(%rbp), %rax
movq -0x6d8(%rbp), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
movq %rax, -0x6d0(%rbp)
jne 0xb8f3
movq -0x6c8(%rbp), %rax
movq %rax, -0x308(%rbp)
movl $0x0, -0x30c(%rbp)
movl -0x30c(%rbp), %eax
cmpl 0x16088(%rip), %eax     # 0x219d0
jge 0xba65
movslq -0x2c4(%rbp), %rsi
leaq 0x16024(%rip), %rdi     # 0x21980
movq %rdi, -0x6f0(%rbp)
callq 0x72c0
movq -0x6f0(%rbp), %rdi
movq %rax, -0x6e8(%rbp)
movl -0x2c4(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x72c0
movq %rax, %rdi
callq 0x41f0
movq %rax, %rdi
callq 0x4620
movl %eax, -0x31c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xdb10
movq -0x6e8(%rbp), %rdx
movq %rax, -0x328(%rbp)
subq $0x10, %rsp
movq %rsp, %rax
leaq -0x328(%rbp), %rcx
movq %rcx, (%rax)
leaq 0x1065(%rip), %rsi      # 0xca30
leaq -0x318(%rbp), %rdi
leaq -0x31c(%rbp), %rcx
leaq -0x30c(%rbp), %r8
leaq -0x2cc(%rbp), %r9
callq 0xdb40
addq $0x10, %rsp
jmp 0xb9f2
movq -0x308(%rbp), %rdi
movslq -0x30c(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x318(%rbp), %rsi
callq 0xdc20
leaq -0x318(%rbp), %rdi
callq 0x7160
movl -0x30c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30c(%rbp)
movl -0x2c4(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x2c4(%rbp)
jmp 0xb93c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x2f0(%rbp), %rdi
callq 0x47e8
jmp 0xc000
movl $0x0, -0x32c(%rbp)
movl -0x32c(%rbp), %eax
cmpl 0x15f55(%rip), %eax     # 0x219d0
jge 0xbab8
movq -0x308(%rbp), %rax
movslq -0x32c(%rbp), %rcx
leaq (%rax,%rcx,8), %rdi
callq 0x46c0
jmp 0xba96
jmp 0xba98
movl -0x32c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x32c(%rbp)
movl -0x2c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c4(%rbp)
jmp 0xba6f
movq -0x308(%rbp), %rax
movq %rax, -0x6f8(%rbp)
cmpq $0x0, %rax
je 0xbb52
movq -0x6f8(%rbp), %rcx
movq %rcx, %rax
addq $-0x8, %rax
movq %rax, -0x710(%rbp)
movq -0x8(%rcx), %rdx
movq %rdx, -0x708(%rbp)
shlq $0x3, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0x700(%rbp)
je 0xbb37
movq -0x700(%rbp), %rdi
addq $-0x8, %rdi
movq %rdi, -0x718(%rbp)
callq 0x7160
movq -0x6f8(%rbp), %rcx
movq -0x718(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x700(%rbp)
jne 0xbb06
movq -0x710(%rbp), %rdi
movq -0x708(%rbp), %rsi
shlq $0x3, %rsi
addq $0x8, %rsi
callq 0x4790
movq -0x6b8(%rbp), %rdx
movl -0x2cc(%rbp), %edi
movl 0x15e6b(%rip), %esi     # 0x219d0
callq 0xccc0
jmp 0xbb6c
movq -0x6b8(%rbp), %rax
movq -0x6c0(%rbp), %rcx
leaq (%rax,%rcx,4), %rax
movq %rax, -0x728(%rbp)
leaq -0x349(%rbp), %rdi
movq %rdi, -0x720(%rbp)
callq 0xdc60
movq -0x6b8(%rbp), %rsi
movq -0x728(%rbp), %rdx
movq -0x720(%rbp), %rcx
leaq -0x348(%rbp), %rdi
callq 0xdc80
jmp 0xbbbb
leaq -0x349(%rbp), %rdi
callq 0xdd00
movl $0x0, -0x2c4(%rbp)
leaq -0x550(%rbp), %rdi
callq 0x46b0
jmp 0xbbdf
leaq -0x50(%rbp), %rdi
movq %rdi, -0x730(%rbp)
callq 0x42f0
movq -0x730(%rbp), %rsi
movq %rax, %rcx
decq %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x590(%rbp), %rdi
callq 0x4420
jmp 0xbc0e
leaq 0xa7cd(%rip), %rsi      # 0x163e2
leaq -0x570(%rbp), %rdi
leaq -0x590(%rbp), %rdx
callq 0xdd20
jmp 0xbc2a
leaq -0x590(%rbp), %rdi
callq 0x47e8
leaq -0x570(%rbp), %rdi
callq 0x41f0
movq %rax, %rsi
leaq -0x550(%rbp), %rdi
movl $0x4, %edx
callq 0x4080
jmp 0xbc58
movslq 0x15d71(%rip), %rax     # 0x219d0
movq %rax, -0x740(%rbp)
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
movq $-0x1, %rax
cmovbq %rax, %rdi
testb %cl, %cl
cmovneq %rax, %rdi
callq 0x4030
movq %rax, -0x738(%rbp)
jmp 0xbc97
movq -0x740(%rbp), %rax
movq -0x738(%rbp), %rcx
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x748(%rbp)
cmpq $0x0, %rax
je 0xbd10
movq -0x748(%rbp), %rax
movq -0x740(%rbp), %rdx
shlq $0x3, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x758(%rbp)
movq %rax, -0x750(%rbp)
movq -0x750(%rbp), %rdi
movq %rdi, -0x760(%rbp)
callq 0xdaf0
movq -0x760(%rbp), %rax
movq -0x758(%rbp), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
movq %rax, -0x750(%rbp)
jne 0xbcdf
movq -0x748(%rbp), %rax
movq %rax, -0x598(%rbp)
movl $0x0, -0x59c(%rbp)
movl -0x59c(%rbp), %eax
cmpl 0x15c9c(%rip), %eax     # 0x219d0
jge 0xbf1c
movslq -0x2c4(%rbp), %rsi
leaq 0x15c38(%rip), %rdi     # 0x21980
movq %rdi, -0x770(%rbp)
callq 0x72c0
movq -0x770(%rbp), %rdi
movq %rax, -0x768(%rbp)
movl -0x2c4(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x72c0
movq %rax, %rdi
callq 0x41f0
movq %rax, %rdi
callq 0x4620
movl %eax, -0x5ac(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xdb10
movq %rax, -0x5b8(%rbp)
leaq -0x550(%rbp), %rdi
callq 0xdd70
movq %rax, -0x5c0(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xdb10
movq -0x768(%rbp), %rdx
movq %rax, -0x5c8(%rbp)
subq $0x30, %rsp
movq %rsp, %rax
leaq -0x5c8(%rbp), %rcx
movq %rcx, 0x28(%rax)
leaq -0x5c0(%rbp), %rcx
movq %rcx, 0x20(%rax)
leaq -0x59c(%rbp), %rcx
movq %rcx, 0x18(%rax)
leaq -0x348(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq -0x2cc(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0x2c8(%rbp), %rcx
movq %rcx, (%rax)
leaq 0x12df(%rip), %rsi      # 0xd0f0
leaq -0x5a8(%rbp), %rdi
leaq -0x5ac(%rbp), %rcx
leaq -0x5b8(%rbp), %r8
leaq -0x2c(%rbp), %r9
callq 0xdda0
addq $0x30, %rsp
jmp 0xbe35
movq -0x598(%rbp), %rdi
movslq -0x59c(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x5a8(%rbp), %rsi
callq 0xdc20
leaq -0x5a8(%rbp), %rdi
callq 0x7160
movl -0x59c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x59c(%rbp)
movl -0x2c4(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x2c4(%rbp)
jmp 0xbd28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x349(%rbp), %rdi
callq 0xdd00
jmp 0xc000
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xbfb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xbfad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x590(%rbp), %rdi
callq 0x47e8
jmp 0xbfad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x570(%rbp), %rdi
callq 0x47e8
jmp 0xbfad
movl $0x0, -0x5cc(%rbp)
movl -0x5cc(%rbp), %eax
cmpl 0x15a9e(%rip), %eax     # 0x219d0
jge 0xbf6f
movq -0x598(%rbp), %rax
movslq -0x5cc(%rbp), %rcx
leaq (%rax,%rcx,8), %rdi
callq 0x46c0
jmp 0xbf4d
jmp 0xbf4f
movl -0x5cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5cc(%rbp)
movl -0x2c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c4(%rbp)
jmp 0xbf26
leaq -0x550(%rbp), %rdi
callq 0x45b0
jmp 0xbf7d
leaq -0x570(%rbp), %rdi
callq 0x47e8
leaq -0x550(%rbp), %rdi
callq 0x45f0
leaq -0x348(%rbp), %rdi
callq 0xdee0
movq -0x2f8(%rbp), %rax
movq %rax, %rsp
jmp 0xbfc7
leaq -0x550(%rbp), %rdi
callq 0x45f0
leaq -0x348(%rbp), %rdi
callq 0xdee0
jmp 0xc000
jmp 0xbfc9
leaq 0x159e0(%rip), %rdi     # 0x219b0
callq 0x4750
movl $0x0, -0x4(%rbp)
movl $0x1, -0xa4(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x47e8
leaq -0x50(%rbp), %rdi
callq 0x47e8
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
leaq -0x70(%rbp), %rdi
callq 0x47e8
leaq -0x50(%rbp), %rdi
callq 0x47e8
movq -0x98(%rbp), %rdi
callq 0x4700
nop