#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_list;
};
typedef int /*<<< orphan*/ saddrp;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(void *, void const *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
extern void make_internet_address(char *host, int portnum,
                                  struct sockaddr_in *saddrp) {
  struct hostent *hp = gethostbyname(host);
  memset((void *)saddrp, 0, sizeof(saddrp));
  memcpy((void *)&saddrp->sin_addr, (const void *)hp->h_addr_list[0],
         hp->h_length);
  saddrp->sin_port = htons(portnum);
  saddrp->sin_family = AF_INET;
}


x86 assembly (clang, -O0):
<make_internet_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
add    $0x8,%rdi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1060 <memcpy@plt>
mov    -0xc(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    0x2e42(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_internet_address>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
call   1050 <gethostbyname@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    0x8(%rbx),%rdi
mov    0x8(%rbp),%rax
mov    (%rax),%rsi
mov    0x0(%rbp),%edx
call   1060 <memcpy@plt>
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
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 void @make_internet_address(i8* %0, i32 %1, %struct.sockaddr_in* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.sockaddr_in*
%7 = alloca %struct.hostent*
store i8* %0, i8** %4
store i32 %1, i32* %5
store %struct.sockaddr_in* %2, %struct.sockaddr_in** %6
%8 = load i8*, i8** %4
%9 = call %struct.hostent* @gethostbyname(i8* %8)
store %struct.hostent* %9, %struct.hostent** %7
%10 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%11 = bitcast %struct.sockaddr_in* %10 to i8*
%12 = call i32 @memset(i8* %11, i32 0, i32 8)
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
%15 = bitcast i32* %14 to i8*
%16 = load %struct.hostent*, %struct.hostent** %7
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i32 0, i32 1
%18 = load i64*, i64** %17
%19 = getelementptr inbounds i64, i64* %18, i64 0
%20 = load i64, i64* %19
%21 = inttoptr i64 %20 to i8*
%22 = load %struct.hostent*, %struct.hostent** %7
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @memcpy(i8* %15, i8* %21, i32 %24)
%26 = load i32, i32* %5
%27 = call i32 @htons(i32 %26)
%28 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %28, i32 0, i32 1
store i32 %27, i32* %29
%30 = load i32, i32* @AF_INET
%31 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %31, i32 0, i32 0
store i32 %30, i32* %32
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64* }
@AF_INET = global i32 0
define void @make_internet_address(i8* %0, i32 %1, %struct.sockaddr_in* %2) {
%4 = tail call %struct.hostent* @gethostbyname(i8* %0)
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = tail call i32 @memset(i8* %5, i32 0, i32 8)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
%8 = bitcast i32* %7 to i8*
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %4, i64 0, i32 1
%10 = load i64*, i64** %9
%11 = load i64, i64* %10
%12 = inttoptr i64 %11 to i8*
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %4, i64 0, i32 0
%14 = load i32, i32* %13
%15 = tail call i32 @memcpy(i8* %8, i8* %12, i32 %14)
%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
ret void
}