// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebx
movl $0x1, -0x20(%rbp)
movl $0x10, -0x1c(%rbp)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2060
testl %eax, %eax
je 0x2a00
movl %eax, %r14d
leaq -0x20(%rbp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0xf, %edx
movl $0x4, %r8d
callq 0x2310
testl %eax, %eax
jne 0x2a10
leaq -0x30(%rbp), %rsi
movw $0x2, (%rsi)
movl $0x0, 0x4(%rsi)
movl %ebx, %eax
rolw $0x8, %ax
movw %ax, 0x2(%rsi)
movl %r14d, %edi
movl $0x10, %edx
callq 0x2040
testl %eax, %eax
js 0x2a20
movl %r14d, %edi
movl $0x3, %esi
callq 0x21d0
testl %eax, %eax
js 0x2a30
movq 0x569b(%rip), %r15      # 0x7fd0
leaq 0x290c(%rip), %rsi      # 0x5248
movl $0x2b, %edx
movq %r15, %rdi
callq 0x21e0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
leaq -0x30(%rbp), %rsi
leaq -0x1c(%rbp), %rdx
movl %r14d, %edi
callq 0x2090
testl %eax, %eax
js 0x2a40
movl %eax, %r14d
movq 0x563e(%rip), %r15      # 0x7fd0
leaq 0x28fb(%rip), %rsi      # 0x5294
movl $0x20, %edx
movq %r15, %rdi
callq 0x21e0
movq %r15, %rdi
movl %ebx, %esi
callq 0x22d0
movq %rax, %rbx
leaq 0x2de2(%rip), %rsi      # 0x579c
movl $0x1, %edx
movq %rax, %rdi
callq 0x21e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
movl %r14d, 0x1e897(%rip)    # 0x2128c
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x55c9(%rip), %rdi      # 0x7fd0
leaq 0x27da(%rip), %rsi      # 0x51e8
jmp 0x2a4e
movq 0x55b9(%rip), %rdi      # 0x7fd0
leaq 0x27dd(%rip), %rsi      # 0x51fb
jmp 0x2a4e
movq 0x55a9(%rip), %rdi      # 0x7fd0
leaq 0x27ed(%rip), %rsi      # 0x521b
jmp 0x2a4e
movq 0x5599(%rip), %rdi      # 0x7fd0
leaq 0x27f8(%rip), %rsi      # 0x5236
jmp 0x2a4e
movq 0x5589(%rip), %rdi      # 0x7fd0
leaq 0x2826(%rip), %rsi      # 0x5274
callq 0x21b0
movq %rax, %rdi
callq 0x20d0
movl $0x1, %edi
callq 0x2200