#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, int);
int make_internet_address(char *hostname, int port, struct sockaddr_in *addrp) {
  struct hostent *hp;
  bzero(addrp, sizeof(struct sockaddr_in));
  hp = gethostbyname(hostname);
  if (hp == NULL)
    return -1;
  bcopy(hp->h_addr, &addrp->sin_addr, hp->h_length);
  printf("local ip: %d\n", addrp->sin_addr.s_addr);
  addrp->sin_port = htons(port);
  addrp->sin_family = AF_INET;
  return 0;
}


x86 assembly (clang, -O0):
<make_internet_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1195 <make_internet_address+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <make_internet_address+0x99>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x20(%rbp),%rsi
add    $0x8,%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   1060 <bcopy@plt>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    0x2e0e(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_internet_address>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    %rdx,%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    %rbp,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     11ae <make_internet_address+0x5e>
mov    (%rax),%edx
mov    0x4(%rax),%edi
lea    0x8(%rbx),%rsi
call   1060 <bcopy@plt>
mov    0x8(%rbx),%esi
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
xor    %eax,%eax
jmp    11b3 <make_internet_address+0x63>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32 }
@.str = [14 x i8] c"local ip: %d\0A\00"
@AF_INET = global i32 0
define i32 @make_internet_address(i8* %0, i32 %1, %struct.sockaddr_in* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.sockaddr_in*
%8 = alloca %struct.hostent*
store i8* %0, i8** %5
store i32 %1, i32* %6
store %struct.sockaddr_in* %2, %struct.sockaddr_in** %7
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%10 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%11 = load i8*, i8** %5
%12 = call %struct.hostent* @gethostbyname(i8* %11)
store %struct.hostent* %12, %struct.hostent** %8
%13 = load %struct.hostent*, %struct.hostent** %8
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %38
16: ; preds = %3
%17 = load %struct.hostent*, %struct.hostent** %8
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 2
%22 = load %struct.hostent*, %struct.hostent** %8
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @bcopy(i32 %19, %struct.TYPE_2__* %21, i32 %24)
%26 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %26, i32 0, i32 2
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %6
%32 = call i32 @htons(i32 %31)
%33 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %33, i32 0, i32 1
store i32 %32, i32* %34
%35 = load i32, i32* @AF_INET
%36 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %36, i32 0, i32 0
store i32 %35, i32* %37
store i32 0, i32* %4
br label %38
38: ; preds = %16, %15
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32 }
@.str = [14 x i8] c"local ip: %d\0A\00"
@AF_INET = global i32 0
define i32 @make_internet_address(i8* %0, i32 %1, %struct.sockaddr_in* %2) {
%4 = tail call i32 @bzero(%struct.sockaddr_in* %2, i32 12)
%5 = tail call %struct.hostent* @gethostbyname(i8* %0)
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %21, label %7
7: ; preds = %3
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @bcopy(i32 %9, %struct.TYPE_2__* %10, i32 %12)
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %10, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = tail call i32 @htons(i32 %1)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %19, i32* %20
br label %21
21: ; preds = %3, %7
%22 = phi i32 [ 0, %7 ], [ -1, %3 ]
ret i32 %22
}