// File: /workspace/github_c_makefile_star2_O0/pencode-lab[P]Shoit/shoit_network.c
// Function: shoit_network_connect_tcp
int shoit_network_connect_tcp(char * remoteHost,int remoteHostPort)
{
    #define USEC(st, fi) (((fi)->tv_sec-(st)->tv_sec)*1000000+((fi)->tv_usec-(st)->tv_usec))
    static struct sockaddr_in tcpServerAddr;
    int retval = 0;
    struct hostent *phe;
    struct timeval start, now;
    int tcpSockfd;

    /*Create a TCP connection */
    bzero((char *)&tcpServerAddr, sizeof(tcpServerAddr));
    tcpServerAddr.sin_family = AF_INET;

    if ((phe = gethostbyname(remoteHost)))
        memcpy(&tcpServerAddr.sin_addr, phe->h_addr, phe->h_length);
    else if ((tcpServerAddr.sin_addr.s_addr = inet_addr(remoteHost)) == INADDR_NONE)
    {
        perror("can't get host entry");
        return -1;
    }
    tcpServerAddr.sin_port = htons(remoteHostPort);
    if((tcpSockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    {
        perror("socket error");
        return -1;
    }
    gettimeofday(&start, NULL);
    do {
        retval = connect(tcpSockfd, (struct sockaddr *)&tcpServerAddr, sizeof(tcpServerAddr));
        gettimeofday(&now, NULL);
        if(retval<0) break;
    } while ((retval < 0) &&  (USEC(&start, &now) < 5000000));
    tcpSockfd = !retval ? tcpSockfd:-1;
    return tcpSockfd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
leaq 0x8cdf(%rip), %rdi      # 0xc28c
xorl %esi, %esi
movl $0x10, %edx
callq 0x21a0
movw $0x2, 0x8cca(%rip)      # 0xc28c
movq -0x10(%rbp), %rdi
callq 0x2240
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x35fa
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rsi
movq -0x20(%rbp), %rax
movslq 0x14(%rax), %rdx
leaq 0x8c9d(%rip), %rdi      # 0xc28c
addq $0x4, %rdi
callq 0x2280
jmp 0x3628
movq -0x10(%rbp), %rdi
callq 0x2220
movl %eax, 0x8c87(%rip)      # 0xc290
cmpl $-0x1, %eax
jne 0x3626
leaq 0x5eee(%rip), %rdi      # 0x9503
callq 0x2390
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3702
jmp 0x3628
movl -0x14(%rbp), %eax
movzwl %ax, %edi
callq 0x2100
movw %ax, 0x8c54(%rip)       # 0xc28e
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x24c0
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
jge 0x366b
leaq 0x5ebe(%rip), %rdi      # 0x9518
callq 0x2390
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3702
leaq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2180
movl -0x44(%rbp), %edi
leaq 0x8c0a(%rip), %rsi      # 0xc28c
movl $0x10, %edx
callq 0x2400
movl %eax, -0x18(%rbp)
leaq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2180
cmpl $0x0, -0x18(%rbp)
jge 0x36a4
jmp 0x36de
jmp 0x36a6
xorl %eax, %eax
cmpl $0x0, -0x18(%rbp)
movb %al, -0x45(%rbp)
jge 0x36d7
movq -0x40(%rbp), %rax
subq -0x30(%rbp), %rax
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
movq -0x38(%rbp), %rcx
subq -0x28(%rbp), %rcx
addq %rcx, %rax
cmpq $0x4c4b40, %rax         # imm = 0x4C4B40
setl %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
testb $0x1, %al
jne 0x3678
cmpl $0x0, -0x18(%rbp)
jne 0x36ec
movl -0x44(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x36f6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x4c(%rbp)
jmp 0x36f6
movl -0x4c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)