// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r14
pushq %rbx
subq $0x20, %rsp
movl %edi, %ebx
movl $0x1, -0x18(%rbp)
movl $0x10, -0x14(%rbp)
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x2050
testl %eax, %eax
je 0x27b2
movl %eax, %r14d
pushq $0x1
popq %rsi
pushq $0xf
popq %rdx
leaq -0x18(%rbp), %rcx
pushq $0x4
popq %r8
movl %eax, %edi
callq 0x22d0
testl %eax, %eax
jne 0x27c2
leaq -0x28(%rbp), %rsi
movw $0x2, (%rsi)
andl $0x0, 0x4(%rsi)
movl %ebx, %eax
rolw $0x8, %ax
movw %ax, 0x2(%rsi)
pushq $0x10
popq %rdx
movl %r14d, %edi
callq 0x2030
testl %eax, %eax
js 0x27d2
pushq $0x3
popq %rsi
movl %r14d, %edi
callq 0x21b0
movq 0x4899(%rip), %rdi      # 0x6fd0
testl %eax, %eax
js 0x27e2
leaq 0x1ae6(%rip), %rsi      # 0x422c
callq 0x2180
movq %rax, %rdi
callq 0x20c0
leaq -0x28(%rbp), %rsi
leaq -0x14(%rbp), %rdx
movl %r14d, %edi
callq 0x2080
testl %eax, %eax
js 0x27eb
movl %eax, %r14d
movq 0x485b(%rip), %rdi      # 0x6fd0
leaq 0x1afc(%rip), %rsi      # 0x4278
callq 0x2180
movq %rax, %rdi
movl %ebx, %esi
callq 0x2290
leaq 0x1fee(%rip), %rsi      # 0x4780
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20c0
movl %r14d, 0x1dac3(%rip)    # 0x2026c
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq 0x4817(%rip), %rdi      # 0x6fd0
leaq 0x1a0c(%rip), %rsi      # 0x41cc
jmp 0x27f9
movq 0x4807(%rip), %rdi      # 0x6fd0
leaq 0x1a0f(%rip), %rsi      # 0x41df
jmp 0x27f9
movq 0x47f7(%rip), %rdi      # 0x6fd0
leaq 0x1a1f(%rip), %rsi      # 0x41ff
jmp 0x27f9
leaq 0x1a31(%rip), %rsi      # 0x421a
jmp 0x27f9
movq 0x47de(%rip), %rdi      # 0x6fd0
leaq 0x1a5f(%rip), %rsi      # 0x4258
callq 0x2180
movq %rax, %rdi
callq 0x20c0
pushq $0x1
popq %rdi
callq 0x21d0