// File: /workspace/github_c_makefile_star2_O0/Arlu[P]RDMA-Hello-World/setup_ib.c
// Function: get_client_dest
int get_client_dest()
{
    int sockfd, connfd, len;
    struct sockaddr_in server_address, client_address;

    // Start connection:
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd == -1)
    {
        perror("Socket creation failed!\n");
        return 1;
    }

    memset(&server_address, 0, sizeof(server_address));
    server_address.sin_family = AF_INET;
    server_address.sin_addr.s_addr = htonl(INADDR_ANY);
    server_address.sin_port = htons(PORT);

    if (bind(sockfd, (struct sockaddr*)&server_address, sizeof(server_address)))
    {
        perror("Socket bind failed!\n");
        return 1;
    }

    if (listen(sockfd, 5))
    {
        perror("Listen failed...\n");
        return 1;
    }

    len = sizeof(client_address);

    connfd = accept(sockfd, (struct sockaddr*)&client_address, &len);
    if (connfd < 0)
    {
        perror("Server accept failed!\n");
        return 1;
    }

    // Get client details:
    {
        char *buf;
        buf = (char*)malloc(sizeof(struct IBDest));
        int offset = 0;

        // Get him details.
        while (offset < sizeof(struct IBDest))
            offset += read(connfd, buf + offset, sizeof(struct IBDest) - offset);

        memcpy(&remote_dest, buf, sizeof(struct IBDest));

        // Send my details:
        memset(buf, 0, sizeof(struct IBDest));
        offset = 0;

        memcpy(buf, &local_dest, sizeof(struct IBDest));
        write(connfd, buf, sizeof(struct IBDest));
    }

    // Finish connection:
    close(sockfd);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x22d0
movl %eax, -0x8(%rbp)
cmpl $-0x1, -0x8(%rbp)
jne 0x27ba
leaq 0x1922(%rip), %rdi      # 0x40cb
callq 0x2210
movl $0x1, -0x4(%rbp)
jmp 0x292a
leaq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2110
movw $0x2, -0x20(%rbp)
xorl %edi, %edi
callq 0x2100
movl %eax, -0x1c(%rbp)
movl $0x1f90, %edi           # imm = 0x1F90
callq 0x20c0
movw %ax, -0x1e(%rbp)
movl -0x8(%rbp), %edi
leaq -0x20(%rbp), %rsi
movl $0x10, %edx
callq 0x2200
cmpl $0x0, %eax
je 0x2816
leaq 0x18df(%rip), %rdi      # 0x40e4
callq 0x2210
movl $0x1, -0x4(%rbp)
jmp 0x292a
movl -0x8(%rbp), %edi
movl $0x5, %esi
callq 0x21b0
cmpl $0x0, %eax
je 0x2840
leaq 0x18ca(%rip), %rdi      # 0x40f9
callq 0x2210
movl $0x1, -0x4(%rbp)
jmp 0x292a
movl $0x10, -0x10(%rbp)
movl -0x8(%rbp), %edi
leaq -0x30(%rbp), %rsi
leaq -0x10(%rbp), %rdx
callq 0x2230
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jge 0x2878
leaq 0x18a4(%rip), %rdi      # 0x410b
callq 0x2210
movl $0x1, -0x4(%rbp)
jmp 0x292a
movl $0xc, %edi
callq 0x21a0
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movslq -0x3c(%rbp), %rax
cmpq $0xc, %rax
jae 0x28c5
movl -0xc(%rbp), %edi
movq -0x38(%rbp), %rsi
movslq -0x3c(%rbp), %rax
addq %rax, %rsi
movslq -0x3c(%rbp), %rax
movl $0xc, %edx
subq %rax, %rdx
callq 0x2140
movq %rax, %rcx
movslq -0x3c(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x3c(%rbp)
jmp 0x288d
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq %rcx, 0x38c9(%rip)      # 0x619c
movl 0x8(%rax), %eax
movl %eax, 0x38c8(%rip)      # 0x61a4
movq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x2110
movl $0x0, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movq 0x3892(%rip), %rcx      # 0x6190
movq %rcx, (%rax)
movl 0x3891(%rip), %ecx      # 0x6198
movl %ecx, 0x8(%rax)
movl -0xc(%rbp), %edi
movq -0x38(%rbp), %rsi
movl $0xc, %edx
callq 0x2070
movl -0x8(%rbp), %edi
callq 0x2120
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)