#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 */

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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ bcopy(void *, void *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(void *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int make_internet_address(char *hostname, int port, struct sockaddr_in *addrp) {
  struct hostent *hp;
  bzero((void *)addrp, sizeof(struct sockaddr_in));
  hp = gethostbyname(hostname);
  if (hp == NULL)
    return -1;
  bcopy((void *)hp->h_addr, (void *)&addrp->sin_addr, hp->h_length);
  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   1060 <bzero@plt>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1185 <make_internet_address+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <make_internet_address+0x87>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
add    $0x8,%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   1050 <bcopy@plt>
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    0x2e30(%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   1060 <bzero@plt>
mov    %rbp,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1190 <make_internet_address+0x50>
mov    0x8(%rax),%rsi
lea    0x8(%rbx),%rdi
mov    (%rax),%edx
call   1050 <memmove@plt>
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
xor    %eax,%eax
jmp    1195 <make_internet_address+0x55>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
@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 = bitcast %struct.sockaddr_in* %9 to i8*
%11 = call i32 @bzero(i8* %10, i32 12)
%12 = load i8*, i8** %5
%13 = call %struct.hostent* @gethostbyname(i8* %12)
store %struct.hostent* %13, %struct.hostent** %8
%14 = load %struct.hostent*, %struct.hostent** %8
%15 = icmp eq %struct.hostent* %14, null
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %36
17: ; preds = %3
%18 = load %struct.hostent*, %struct.hostent** %8
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i32 0, i32 1
%20 = load i64, i64* %19
%21 = inttoptr i64 %20 to i8*
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 2
%24 = bitcast i32* %23 to i8*
%25 = load %struct.hostent*, %struct.hostent** %8
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @bcopy(i8* %21, i8* %24, i32 %27)
%29 = load i32, i32* %6
%30 = call i32 @htons(i32 %29)
%31 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %31, i32 0, i32 1
store i32 %30, i32* %32
%33 = load i32, i32* @AF_INET
%34 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %34, i32 0, i32 0
store i32 %33, i32* %35
store i32 0, i32* %4
br label %36
36: ; preds = %17, %16
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
@AF_INET = global i32 0
define i32 @make_internet_address(i8* %0, i32 %1, %struct.sockaddr_in* nocapture writeonly %2) {
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = tail call i32 @bzero(i8* %4, i32 12)
%6 = tail call %struct.hostent* @gethostbyname(i8* %0)
%7 = icmp eq %struct.hostent* %6, null
br i1 %7, label %20, label %8
8: ; preds = %3
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %6, i64 0, i32 1
%10 = load i64, i64* %9
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
%13 = bitcast i32* %12 to i8*
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %6, i64 0, i32 0
%15 = load i32, i32* %14
tail call void @llvm.memmove.p0i8.p0i8.i32(i8* align 1 %13, i8* align 1 %11, i32 %15, i1 false)
%16 = tail call i32 @htons(i32 %1)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %18, i32* %19
br label %20
20: ; preds = %3, %8
%21 = phi i32 [ 0, %8 ], [ -1, %3 ]
ret i32 %21
}