// File: /workspace/github_cpp_makefile_star2_O2/girdhari9[P]mTORRENT/ClientConnection.cpp
// Function: clientConnection(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>>&, int, int, int, std::vector<int, std::allocator<int>>, int, std::basic_ofstream<char, std::char_traits<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int clientConnection(string IPaddress,int PORT,string &recvFileName, int FileSize, int LastPartSize, int TotalPacket, vector<int> BitMap1, int thread_n, ofstream &output, string SHA){
    int sock = 0; 
    struct sockaddr_in serv_addr;
    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
    { 
        printf("\n Socket creation error \n"); 
        return -1; 
    } 
    memset(&serv_addr, '0', sizeof(serv_addr)); 
    serv_addr.sin_family = AF_INET; 
    serv_addr.sin_port = htons(PORT); 
    
    if(inet_pton(AF_INET, IPaddress.c_str() , &serv_addr.sin_addr)<=0){ 
        printf("\nInvalid address/ Address not supported \n"); 
        return -1; 
    } 
   
    if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0){ 
        printf("\nConnection Failed \n"); 
        return -1; 
    }
    if(sock == -1){
        cout<<"Error in connection\n";
        exit(0);
    }
    else{
        sem_wait(&mutex1);
        cout<<"[+]system started...\n"; 
        cout<<"[+]system connecting...\n";
        cout<<"> You are connected with: "<<IPaddress<<":"<<PORT<<"\n";
        sem_post(&mutex1);
    }
    int DataRequest = 2;
    send(sock , &DataRequest , sizeof(int) , 0 );
    RecieveDataFromServer(sock,recvFileName,FileSize,LastPartSize,TotalPacket,BitMap1,thread_n, ref(output),SHA);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, %ebx
movl %r8d, %ebp
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, %r13
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x4100
testl %eax, %eax
js 0x833d
movl %eax, %r14d
leaq 0x4c(%rsp), %rdx
movabsq $0x3030303030303030, %rax # imm = 0x3030303030303030
movq %rax, (%rdx)
movl $0x30303030, 0x8(%rdx)  # imm = 0x30303030
movw $0x2, -0x4(%rdx)
movl %r12d, %eax
rolw $0x8, %ax
movw %ax, -0x2(%rdx)
movq (%r13), %rsi
pushq $0x2
popq %rdi
callq 0x4600
testl %eax, %eax
jle 0x8346
leaq 0x48(%rsp), %rsi
pushq $0x10
popq %rdx
movl %r14d, %edi
callq 0x42c0
testl %eax, %eax
js 0x834f
movl %ebx, 0x8(%rsp)
leaq 0x86cc(%rip), %rdi      # 0x108f0
callq 0x4220
movq 0x7d98(%rip), %rbx      # 0xffc8
leaq 0x31d1(%rip), %rsi      # 0xb408
movq %rbx, %rdi
callq 0x4330
leaq 0x31d8(%rip), %rsi      # 0xb41e
movq %rbx, %rdi
callq 0x4330
leaq 0x31e2(%rip), %rsi      # 0xb437
movq %rbx, %rdi
callq 0x4330
movq %rax, %rdi
movq %r13, %rsi
callq 0x4300
leaq 0x2e83(%rip), %rsi      # 0xb0f2
movq %rax, %rdi
callq 0x4330
movq %rax, %rdi
movl %r12d, %esi
callq 0x4590
leaq 0x315d(%rip), %rsi      # 0xb3e6
movq %rax, %rdi
callq 0x4330
leaq 0x8658(%rip), %rdi      # 0x108f0
callq 0x4560
leaq 0xc(%rsp), %rsi
movl $0x2, (%rsi)
pushq $0x4
popq %rdx
movl %r14d, %edi
xorl %ecx, %ecx
callq 0x41d0
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x4470
leaq 0x10(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0x89ba
movq 0xc8(%rsp), %rsi
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x4470
movl 0x8(%rsp), %r8d
movl 0xb8(%rsp), %eax
subq $0x8, %rsp
leaq 0x30(%rsp), %rsi
leaq 0x18(%rsp), %r9
movl %r14d, %edi
movl %ebp, %ecx
pushq %r15
pushq 0xd0(%rsp)
pushq %rax
callq 0x83a0
addq $0x20, %rsp
leaq 0x58(%rsp), %rdi
callq 0x4678
leaq 0x10(%rsp), %rdi
callq 0x8d38
leaq 0x28(%rsp), %rdi
callq 0x4678
xorl %eax, %eax
jmp 0x835e
leaq 0x31ed(%rip), %rdi      # 0xb531
jmp 0x8356
leaq 0x31bb(%rip), %rdi      # 0xb508
jmp 0x8356
leaq 0x319e(%rip), %rdi      # 0xb4f4
callq 0x44e0
pushq $-0x1
popq %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x4678
jmp 0x837f
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x8d38
jmp 0x838e
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4678
movq %rbx, %rdi
callq 0x45b0