// File: /workspace/github_c_makefile_star2_O0/GregorR[P]lstg/source/lst_socket_primitives.c
// Function: lstInetPrimitive
struct object *
lstInetPrimitive(int primitiveNumber, struct object *args, int *failed)
{
    struct object *returnedValue = nilObject;
    switch (integerValue(args->data[0])) {

        case 0: {   /* Inet firstIpStringFromHostname: hostName -> IPv4 address string */
            char hostname[256];
            lstGetString(hostname, sizeof(hostname), args->data[1]);
            struct hostent *h = gethostbyname(hostname);
            if (h && h->h_addrtype == AF_INET) {
                char addr[16];
                inet_ntop(h->h_addrtype, h->h_addr_list[0], addr, sizeof(addr));
                returnedValue = lstNewString(addr);
            }
            break;
        }

        case 1: {   /* Inet firstIpAddressFromHostname: hostName -> IPv4 in_addr binary */
            char hostname[256];
            lstGetString(hostname, sizeof(hostname), args->data[1]);
            struct hostent *h = gethostbyname(hostname);
            if (h && h->h_addrtype == AF_INET)
                returnedValue = lstNewBinary(h->h_addr_list[0], h->h_length);
            break;
        }

        case 2: {   /* Inet newIpAddressFromIpString: ipStr -> IPv4 in_addr binary */
            char ipStr[16];
            lstGetString(ipStr, sizeof(ipStr), args->data[1]);
            struct in_addr addr;
            int rc = inet_aton(ipStr, &addr);
            if (1 == rc)
                returnedValue = lstNewBinary(&addr, sizeof(addr));
            break;
        }

        case 3: {   /* Inet newSocketAddressFromIpAddress: in_addr port: port -> socketaddr_in binary */
            struct byteObject *addrObj = (struct byteObject *) args->data[1];
            struct sockaddr_in in;
            in.sin_family = AF_INET;
            in.sin_port = htons(integerValue(args->data[2]));
            memcpy(&in.sin_addr, addrObj->bytes, SIZE(addrObj));
            returnedValue = lstNewBinary(&in, sizeof(in));
            break;
        }

        case 4: {   /* Inet newSocketAddressFromIpString: ipStr port: port -> socketaddr_in binary */
            char ipStr[16];
            lstGetString(ipStr, sizeof(ipStr), args->data[1]);
            struct in_addr addr;
            int rc = inet_aton(ipStr, &addr);
            if (1 == rc) {
                struct sockaddr_in in;
                in.sin_family = AF_INET;
                in.sin_port = htons(integerValue(args->data[2]));
                memcpy(&in.sin_addr, &addr, sizeof(addr));
                returnedValue = lstNewBinary(&in, sizeof(in));
            }
            break;
        }

        case 5: {   /* Inet newSocketAddressFromHostname: host port: port -> socketaddr_in binary */
            char hostname[256];
            lstGetString(hostname, sizeof(hostname), args->data[1]);
            struct hostent *h = gethostbyname(hostname);
            if (h && h->h_addrtype == AF_INET) {
                struct sockaddr_in in;
                in.sin_family = AF_INET;
                in.sin_port = htons(integerValue(args->data[2]));
                memcpy(&in.sin_addr, h->h_addr_list[0], h->h_length);
                returnedValue = lstNewBinary(&in, sizeof(in));
            }
            break;
        }

    }
    return returnedValue;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3d0, %rsp            # imm = 0x3D0
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq 0x3fbeb(%rip), %rax     # 0x48938
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
sarq %rax
movq %rax, -0x3d0(%rbp)
subq $0x5, %rax
ja 0x906f
movq -0x3d0(%rbp), %rax
leaq 0x1a62(%rip), %rcx      # 0xa7e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x7280
leaq -0x120(%rbp), %rdi
callq 0x21d0
movq %rax, -0x128(%rbp)
cmpq $0x0, -0x128(%rbp)
je 0x8e03
movq -0x128(%rbp), %rax
cmpl $0x2, 0x10(%rax)
jne 0x8e03
movq -0x128(%rbp), %rax
movl 0x10(%rax), %edi
movq -0x128(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rsi
leaq -0x140(%rbp), %rdx
movl $0x10, %ecx
callq 0x2030
leaq -0x140(%rbp), %rdi
callq 0x7200
movq %rax, -0x20(%rbp)
jmp 0x906f
leaq -0x240(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x7280
leaq -0x240(%rbp), %rdi
callq 0x21d0
movq %rax, -0x248(%rbp)
cmpq $0x0, -0x248(%rbp)
je 0x8e6c
movq -0x248(%rbp), %rax
cmpl $0x2, 0x10(%rax)
jne 0x8e6c
movq -0x248(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
movq -0x248(%rbp), %rax
movl 0x14(%rax), %esi
callq 0x7310
movq %rax, -0x20(%rbp)
jmp 0x906f
leaq -0x260(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movl $0x10, %esi
callq 0x7280
leaq -0x260(%rbp), %rdi
leaq -0x264(%rbp), %rsi
callq 0x2220
movl %eax, -0x268(%rbp)
movl $0x1, %eax
cmpl -0x268(%rbp), %eax
jne 0x8ec5
leaq -0x264(%rbp), %rdi
movl $0x4, %esi
callq 0x7310
movq %rax, -0x20(%rbp)
jmp 0x906f
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x270(%rbp)
movw $0x2, -0x280(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
sarq %rax
movzwl %ax, %edi
callq 0x2120
movw %ax, -0x27e(%rbp)
leaq -0x280(%rbp), %rdi
addq $0x4, %rdi
movq -0x270(%rbp), %rsi
addq $0x10, %rsi
movq -0x270(%rbp), %rax
movl (%rax), %eax
shrl $0x2, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x2200
leaq -0x280(%rbp), %rdi
movl $0x10, %esi
callq 0x7310
movq %rax, -0x20(%rbp)
jmp 0x906f
leaq -0x290(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movl $0x10, %esi
callq 0x7280
leaq -0x290(%rbp), %rdi
leaq -0x294(%rbp), %rsi
callq 0x2220
movl %eax, -0x298(%rbp)
movl $0x1, %eax
cmpl -0x298(%rbp), %eax
jne 0x8fc4
movw $0x2, -0x2a8(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
sarq %rax
movzwl %ax, %edi
callq 0x2120
movw %ax, -0x2a6(%rbp)
movl -0x294(%rbp), %eax
movl %eax, -0x2a4(%rbp)
leaq -0x2a8(%rbp), %rdi
movl $0x10, %esi
callq 0x7310
movq %rax, -0x20(%rbp)
jmp 0x906f
leaq -0x3b0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x7280
leaq -0x3b0(%rbp), %rdi
callq 0x21d0
movq %rax, -0x3b8(%rbp)
cmpq $0x0, -0x3b8(%rbp)
je 0x906d
movq -0x3b8(%rbp), %rax
cmpl $0x2, 0x10(%rax)
jne 0x906d
movw $0x2, -0x3c8(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
sarq %rax
movzwl %ax, %edi
callq 0x2120
movw %ax, -0x3c6(%rbp)
leaq -0x3c8(%rbp), %rdi
addq $0x4, %rdi
movq -0x3b8(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rsi
movq -0x3b8(%rbp), %rax
movslq 0x14(%rax), %rdx
callq 0x2200
leaq -0x3c8(%rbp), %rdi
movl $0x10, %esi
callq 0x7310
movq %rax, -0x20(%rbp)
jmp 0x906f
movq -0x20(%rbp), %rax
addq $0x3d0, %rsp            # imm = 0x3D0
popq %rbp
retq