// File: supragya[P]DirectorySync/DirectorySync.cpp
// Function: set_reader_connection(int, char*)
void set_reader_connection(int portno, char* ipaddr){
    // Network
    int server_fd, new_socket;
    struct sockaddr_in address;
    int opt = 1, valread;
    int addrlen = sizeof(address);

    // Creating socket file descriptor
    if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0)
    {
        std::cout<<"[RC] Socket Failed"<<std::endl;
        exit(EXIT_FAILURE);
    }

    if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt)))
    {
        std::cout<<"[RC] Socket Failed (setsockopt)"<<std::endl;
        exit(EXIT_FAILURE);
    }

    address.sin_family = AF_INET;
    address.sin_addr.s_addr = INADDR_ANY;
    address.sin_port = htons( portno );

    // Forcefully attaching socket to the port
    if (bind(server_fd, (struct sockaddr *)&address,
             sizeof(address))<0)
    {
        std::cout<<"[RC] Socket Failed to bind"<<std::endl;
        exit(EXIT_FAILURE);
    }

    if (listen(server_fd, 3) < 0)
    {
        std::cout<<"[RC] Error Listen"<<std::endl;
        exit(EXIT_FAILURE);
    }

    std::cout<<"[RC] Ready to listen. Ping the other droid!"<<std::endl;

    if ((new_socket = accept(server_fd, (struct sockaddr *)&address, (socklen_t*)&addrlen))<0)
    {
        std::cout<<"[RC] Error accepting connection"<<std::endl;
        exit(EXIT_FAILURE);
    }

    std::cout<<"[RC] Accepted communication at [" <<portno<<"]"<<std::endl;

    RCsock = new_socket;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x2c(%rbp)
movl $0x10, -0x34(%rbp)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2070
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jne 0x2872
movq 0x8783(%rip), %rdi      # 0xafd0
leaq 0x4978(%rip), %rsi      # 0x71cc
callq 0x21d0
movq %rax, %rdi
movq 0x8755(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0x1, %edi
callq 0x2230
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0xf, %edx
leaq -0x2c(%rbp), %rcx
movl $0x4, %r8d
callq 0x2360
cmpl $0x0, %eax
je 0x28bf
movq 0x8736(%rip), %rdi      # 0xafd0
leaq 0x493e(%rip), %rsi      # 0x71df
callq 0x21d0
movq %rax, %rdi
movq 0x8708(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0x1, %edi
callq 0x2230
movw $0x2, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x4(%rbp), %eax
movzwl %ax, %edi
callq 0x2030
movw %ax, -0x26(%rbp)
movl -0x14(%rbp), %edi
leaq -0x28(%rbp), %rsi
movl $0x10, %edx
callq 0x2040
cmpl $0x0, %eax
jge 0x291d
movq 0x86d8(%rip), %rdi      # 0xafd0
leaq 0x4900(%rip), %rsi      # 0x71ff
callq 0x21d0
movq %rax, %rdi
movq 0x86aa(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0x1, %edi
callq 0x2230
movl -0x14(%rbp), %edi
movl $0x3, %esi
callq 0x2210
cmpl $0x0, %eax
jge 0x295b
movq 0x869a(%rip), %rdi      # 0xafd0
leaq 0x48dd(%rip), %rsi      # 0x721a
callq 0x21d0
movq %rax, %rdi
movq 0x866c(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0x1, %edi
callq 0x2230
movq 0x866e(%rip), %rdi      # 0xafd0
leaq 0x48c3(%rip), %rsi      # 0x722c
callq 0x21d0
movq %rax, %rdi
movq 0x8640(%rip), %rsi      # 0xafb8
callq 0x21f0
movl -0x14(%rbp), %edi
leaq -0x28(%rbp), %rsi
leaq -0x34(%rbp), %rdx
callq 0x20a0
movl %eax, -0x18(%rbp)
cmpl $0x0, %eax
jge 0x29c1
movq 0x8634(%rip), %rdi      # 0xafd0
leaq 0x48b5(%rip), %rsi      # 0x7258
callq 0x21d0
movq %rax, %rdi
movq 0x8606(%rip), %rsi      # 0xafb8
callq 0x21f0
movl $0x1, %edi
callq 0x2230
movq 0x8608(%rip), %rdi      # 0xafd0
leaq 0x48a9(%rip), %rsi      # 0x7278
callq 0x21d0
movq %rax, %rdi
movl -0x4(%rbp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x4e88(%rip), %rsi      # 0x7871
callq 0x21d0
movq %rax, %rdi
movq 0x85c0(%rip), %rsi      # 0xafb8
callq 0x21f0
movl -0x18(%rbp), %eax
movl %eax, 0x218ae(%rip)     # 0x242b4
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)