// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x40e0
testl %eax, %eax
js 0x9f52
movl %eax, %r14d
leaq 0x6c(%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
movl $0x2, %edi
callq 0x4630
testl %eax, %eax
jle 0x9f5b
leaq 0x68(%rsp), %rsi
movl %r14d, %edi
movl $0x10, %edx
callq 0x42b0
testl %eax, %eax
js 0x9f64
movl %ebx, 0x4(%rsp)
leaq 0x8b35(%rip), %rdi      # 0x12900
callq 0x4210
movq 0x81f9(%rip), %rbx      # 0x11fd0
leaq 0x362a(%rip), %rsi      # 0xd408
movl $0x15, %edx
movq %rbx, %rdi
callq 0x43c0
leaq 0x362c(%rip), %rsi      # 0xd41e
movl $0x18, %edx
movq %rbx, %rdi
callq 0x43c0
leaq 0x3631(%rip), %rsi      # 0xd437
movl $0x1a, %edx
movq %rbx, %rdi
callq 0x43c0
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %rbx, %rdi
callq 0x43c0
movq %rax, %rbx
leaq 0x32c5(%rip), %rsi      # 0xd0f2
movl $0x1, %edx
movq %rax, %rdi
callq 0x43c0
movq %rbx, %rdi
movl %r12d, %esi
callq 0x45b0
leaq 0x359a(%rip), %rsi      # 0xd3e6
movl $0x1, %edx
movq %rax, %rdi
callq 0x43c0
leaq 0x8aa0(%rip), %rdi      # 0x12900
callq 0x4580
leaq 0x24(%rsp), %rsi
movl $0x2, (%rsi)
movl $0x4, %edx
movl %r14d, %edi
xorl %ecx, %ecx
callq 0x41c0
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x74cc
leaq 0x8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0xa620
movq 0xc8(%rsp), %rax
leaq 0x58(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %r15
movq %r15, %rdi
callq 0x74cc
movl 0x4(%rsp), %r8d
movl 0xb8(%rsp), %eax
subq $0x8, %rsp
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %r9
movl %r14d, %edi
movl %ebp, %ecx
pushq %r15
pushq 0xd0(%rsp)
pushq %rax
callq 0x9fde
addq $0x20, %rsp
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x9f20
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4350
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x9f37
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x4350
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x9f4e
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4350
xorl %eax, %eax
jmp 0x9f75
leaq 0x35d8(%rip), %rdi      # 0xd531
jmp 0x9f6b
leaq 0x35a6(%rip), %rdi      # 0xd508
jmp 0x9f6b
leaq 0x3589(%rip), %rdi      # 0xd4f4
callq 0x44f0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x9fa3
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4350
jmp 0x9fa3
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x9fbf
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x4350
jmp 0x9fbf
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x9fd6
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4350
movq %rbx, %rdi
callq 0x45d0