// File: /workspace/github_c_makefile_star2_O0/Arlu[P]RDMA-Hello-World/setup_ib.c
// Function: get_server_dest
int get_server_dest()
{
    int sockfd;
    struct addrinfo hints, *result, *rp;

    memset(&hints, 0, sizeof(struct addrinfo));
    hints.ai_family = AF_UNSPEC; // Allow IPv4 or IPv6.
    hints.ai_socktype = SOCK_STREAM; // TCP

    if (getaddrinfo(server_name, PORT_STR, &hints, &result))
    {
        perror("Found address failed!\n");
        return 1;
    }

    // Start connection:
    for (rp = result; rp; rp = rp->ai_next)
    {
        sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);

        if (sockfd == -1)
            continue;

        if (!connect(sockfd, rp->ai_addr, rp->ai_addrlen))
            break; // Success.

        close(sockfd);
    }

    if (!rp)
    {
        perror("Connection with the server failed.\n");
        return 1;
    }

    freeaddrinfo(result);

    // Get server details:
    {
        char *buf;
        buf = (char *)malloc(sizeof(struct IBDest));
        int offset = 0;

        // Send my details:
        memcpy(buf, &local_dest, sizeof(struct IBDest));
        write(sockfd, buf, sizeof(struct IBDest));

        // Get him details:
        memset(buf, 0, sizeof(struct IBDest));
        offset = 0;

        while (offset < sizeof(struct IBDest))
            offset += read(sockfd, buf + offset, sizeof(struct IBDest) - offset);

        memcpy(&remote_dest, buf, sizeof(struct IBDest));
    }

    // Finish connection:
    close(sockfd);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x2110
movl $0x0, -0x34(%rbp)
movl $0x1, -0x30(%rbp)
movq 0x3b8b(%rip), %rdi      # 0x6188
leaq 0x1a87(%rip), %rsi      # 0x408b
leaq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x22a0
cmpl $0x0, %eax
je 0x262e
leaq 0x1a73(%rip), %rdi      # 0x4090
callq 0x2210
movl $0x1, -0x4(%rbp)
jmp 0x2770
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x2696
movq -0x48(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x48(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x48(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x22d0
movl %eax, -0x8(%rbp)
cmpl $-0x1, -0x8(%rbp)
jne 0x2662
jmp 0x2688
movl -0x8(%rbp), %edi
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x48(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x2250
cmpl $0x0, %eax
jne 0x2680
jmp 0x2696
movl -0x8(%rbp), %edi
callq 0x2120
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x2636
cmpq $0x0, -0x48(%rbp)
jne 0x26b5
leaq 0x1a03(%rip), %rdi      # 0x40a7
callq 0x2210
movl $0x1, -0x4(%rbp)
jmp 0x2770
movq -0x40(%rbp), %rdi
callq 0x22c0
movl $0xc, %edi
callq 0x21a0
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x50(%rbp), %rax
movq 0x3ab2(%rip), %rcx      # 0x6190
movq %rcx, (%rax)
movl 0x3ab1(%rip), %ecx      # 0x6198
movl %ecx, 0x8(%rax)
movl -0x8(%rbp), %edi
movq -0x50(%rbp), %rsi
movl $0xc, %edx
callq 0x2070
movq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x2110
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
cmpq $0xc, %rax
jae 0x274a
movl -0x8(%rbp), %edi
movq -0x50(%rbp), %rsi
movslq -0x54(%rbp), %rax
addq %rax, %rsi
movslq -0x54(%rbp), %rax
movl $0xc, %edx
subq %rax, %rdx
callq 0x2140
movq %rax, %rcx
movslq -0x54(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x54(%rbp)
jmp 0x2712
movq -0x50(%rbp), %rax
movq (%rax), %rcx
movq %rcx, 0x3a44(%rip)      # 0x619c
movl 0x8(%rax), %eax
movl %eax, 0x3a43(%rip)      # 0x61a4
movl -0x8(%rbp), %edi
callq 0x2120
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)