#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_addr;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ *h_addr_list;
};
typedef int /*<<< orphan*/ s_in;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
struct hostent *xgethostbyname(char *);
struct sockaddr_in *lookup_host(char *host) {
  static struct sockaddr_in s_in;
  struct hostent *hp;
  memset(&s_in, 0, sizeof(s_in));
  s_in.sin_family = AF_INET;
  hp = xgethostbyname(host);
  memcpy(&s_in.sin_addr, hp->h_addr_list[0], hp->h_length);
  return &s_in;
}


x86 assembly (clang, -O0):
<lookup_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2ef9(%rip),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2ee2(%rip)
mov    -0x8(%rbp),%rdi
call   1050 <xgethostbyname@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0x2eba(%rip),%rdi
call   1040 <memcpy@plt>
lea    0x2eae(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup_host>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x2efe(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2ee4(%rip)
mov    %rbx,%rdi
call   1050 <xgethostbyname@plt>
mov    0x8(%rax),%rcx
mov    (%rcx),%esi
mov    (%rax),%edx
mov    %r14,%rdi
call   1040 <memcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.hostent = type { i32, i32* }
@lookup_host.s_in = internal global %struct.sockaddr_in zeroinitializer
@AF_INET = global i32 0
define %struct.sockaddr_in* @lookup_host(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.hostent*
store i8* %0, i8** %2
%4 = call i32 @memset(%struct.sockaddr_in* @lookup_host.s_in, i32 0, i32 8)
%5 = load i32, i32* @AF_INET
store i32 %5, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @lookup_host.s_in, i32 0, i32 1)
%6 = load i8*, i8** %2
%7 = call %struct.hostent* @xgethostbyname(i8* %6)
store %struct.hostent* %7, %struct.hostent** %3
%8 = load %struct.hostent*, %struct.hostent** %3
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i32 0, i32 1
%10 = load i32*, i32** %9
%11 = getelementptr inbounds i32, i32* %10, i64 0
%12 = load i32, i32* %11
%13 = load %struct.hostent*, %struct.hostent** %3
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @memcpy(i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @lookup_host.s_in, i32 0, i32 0), i32 %12, i32 %15)
ret %struct.sockaddr_in* @lookup_host.s_in
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.hostent = type { i32, i32* }
@lookup_host.s_in = internal global %struct.sockaddr_in zeroinitializer
@AF_INET = global i32 0
define %struct.sockaddr_in* @lookup_host(i8* %0) {
%2 = tail call i32 @memset(%struct.sockaddr_in* @lookup_host.s_in, i32 0, i32 8)
%3 = load i32, i32* @AF_INET
store i32 %3, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @lookup_host.s_in, i64 0, i32 1)
%4 = tail call %struct.hostent* @xgethostbyname(i8* %0)
%5 = getelementptr inbounds %struct.hostent, %struct.hostent* %4, i64 0, i32 1
%6 = load i32*, i32** %5
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %4, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @memcpy(i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @lookup_host.s_in, i64 0, i32 0), i32 %7, i32 %9)
ret %struct.sockaddr_in* @lookup_host.s_in
}