// File: 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
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0xd0(%rbp)
movq 0x28(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x4130
movl %eax, -0x30(%rbp)
cmpl $0x0, %eax
jge 0xd16f
leaq 0x928b(%rip), %rdi      # 0x163e7
movb $0x0, %al
callq 0x4070
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd418
leaq -0x40(%rbp), %rdi
movl $0x30, %esi
movl $0x10, %edx
callq 0x4260
movw $0x2, -0x40(%rbp)
movl -0x14(%rbp), %eax
movzwl %ax, %edi
callq 0x4090
movq -0xd0(%rbp), %rdi
movw %ax, -0x3e(%rbp)
callq 0x41f0
movq %rax, %rsi
leaq -0x40(%rbp), %rdx
addq $0x4, %rdx
movl $0x2, %edi
callq 0x4760
cmpl $0x0, %eax
jg 0xd1d7
leaq 0x923d(%rip), %rdi      # 0x16401
movb $0x0, %al
callq 0x4070
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd418
movl -0x30(%rbp), %edi
leaq -0x40(%rbp), %rsi
movl $0x10, %edx
callq 0x4360
cmpl $0x0, %eax
jge 0xd207
leaq 0x9237(%rip), %rdi      # 0x1642b
movb $0x0, %al
callq 0x4070
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd418
cmpl $-0x1, -0x30(%rbp)
jne 0xd227
movq 0x13db4(%rip), %rdi     # 0x20fc8
leaq 0x9132(%rip), %rsi      # 0x1634d
callq 0x43f0
xorl %edi, %edi
callq 0x44e0
leaq 0x14782(%rip), %rdi     # 0x219b0
callq 0x4280
movq 0x13d8e(%rip), %rdi     # 0x20fc8
leaq 0x923a(%rip), %rsi      # 0x1647b
callq 0x43f0
movq 0x13d7b(%rip), %rdi     # 0x20fc8
leaq 0x923d(%rip), %rsi      # 0x16491
callq 0x43f0
movq 0x13d68(%rip), %rdi     # 0x20fc8
leaq 0x9243(%rip), %rsi      # 0x164aa
callq 0x43f0
movq -0xd0(%rbp), %rsi
movq %rax, %rdi
callq 0x43c0
movq %rax, %rdi
leaq 0x8e51(%rip), %rsi      # 0x160d6
callq 0x43f0
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x46e0
movq %rax, %rdi
leaq 0x919f(%rip), %rsi      # 0x1643e
callq 0x43f0
leaq 0x14705(%rip), %rdi     # 0x219b0
callq 0x46a0
movl $0x2, -0x44(%rbp)
movl -0x30(%rbp), %edi
leaq -0x44(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x4230
movl -0x30(%rbp), %eax
movl %eax, -0xe0(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x4200
movq -0xc0(%rbp), %rsi
movl -0x24(%rbp), %eax
movl %eax, -0xdc(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0xd8(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0xd4(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xdf60
jmp 0xd30d
movl 0x18(%rbp), %eax
movl %eax, -0xec(%rbp)
movq 0x20(%rbp), %rdi
callq 0xdd70
movq %rax, -0x98(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xe050
movq -0xc8(%rbp), %rsi
movq %rax, -0xe8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x4200
jmp 0xd34e
movl -0xd4(%rbp), %r8d
movl -0xd8(%rbp), %ecx
movl -0xdc(%rbp), %edx
movl -0xe0(%rbp), %edi
movl -0xec(%rbp), %esi
movq -0xe8(%rbp), %r9
movq %rsp, %rax
leaq -0xb8(%rbp), %r10
movq %r10, 0x10(%rax)
movq %r9, 0x8(%rax)
movl %esi, (%rax)
leaq -0x68(%rbp), %rsi
leaq -0x80(%rbp), %r9
callq 0xd430
jmp 0xd397
leaq -0xb8(%rbp), %rdi
callq 0x47e8
leaq -0x80(%rbp), %rdi
callq 0xdee0
leaq -0x68(%rbp), %rdi
callq 0x47e8
movl $0x0, -0x4(%rbp)
jmp 0xd418
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xd40d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xd404
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x47e8
leaq -0x80(%rbp), %rdi
callq 0xdee0
leaq -0x68(%rbp), %rdi
callq 0x47e8
jmp 0xd424
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x4700