#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 in_addr {
  int /*<<< orphan*/ s_addr;
};
struct hostent {
  int h_length;
  int /*<<< orphan*/ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void stuff_net_addr(struct in_addr *p, char *hostname) {
  struct hostent *ntpserver;
  ntpserver = gethostbyname(hostname);
  if (ntpserver == NULL) {
    herror(hostname);
    exit(1);
  }
  if (ntpserver->h_length != 4) {
    fprintf(stderr, "oops %d\n", ntpserver->h_length);
    exit(1);
  }
  memcpy(&(p->s_addr), ntpserver->h_addr_list[0], 4);
}


x86 assembly (clang, -O0):
<stuff_net_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118b <stuff_net_addr+0x3b>
mov    -0x10(%rbp),%rdi
call   1060 <herror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x4,(%rax)
je     11bd <stuff_net_addr+0x6d>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe52(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    $0x4,%edx
call   1050 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stuff_net_addr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     1188 <stuff_net_addr+0x38>
mov    (%rax),%edx
cmp    $0x4,%edx
jne    119a <stuff_net_addr+0x4a>
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    %r14,%rdi
mov    $0x4,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <memcpy@plt>
mov    %rbx,%rdi
call   1060 <herror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32* }
@stderr = global i32 0
@.str = [9 x i8] c"oops %d\0A\00"
define void @stuff_net_addr(%struct.in_addr* %0, i8* %1) {
%3 = alloca %struct.in_addr*
%4 = alloca i8*
%5 = alloca %struct.hostent*
store %struct.in_addr* %0, %struct.in_addr** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call %struct.hostent* @gethostbyname(i8* %6)
store %struct.hostent* %7, %struct.hostent** %5
%8 = load %struct.hostent*, %struct.hostent** %5
%9 = icmp eq %struct.hostent* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @herror(i8* %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load %struct.hostent*, %struct.hostent** %5
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = icmp ne i32 %17, 4
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load %struct.hostent*, %struct.hostent** %5
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %14
%27 = load %struct.in_addr*, %struct.in_addr** %3
%28 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %27, i32 0, i32 0
%29 = load %struct.hostent*, %struct.hostent** %5
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i32 0, i32 1
%31 = load i32*, i32** %30
%32 = getelementptr inbounds i32, i32* %31, i64 0
%33 = load i32, i32* %32
%34 = call i32 @memcpy(i32* %28, i32 %33, i32 4)
ret void
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32* }
@stderr = global i32 0
@.str = [9 x i8] c"oops %d\0A\00"
define void @stuff_net_addr(%struct.in_addr* %0, i8* %1) {
%3 = tail call %struct.hostent* @gethostbyname(i8* %1)
%4 = icmp eq %struct.hostent* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @herror(i8* %1)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 4
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %0, i64 0, i32 0
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 1
%19 = load i32*, i32** %18
%20 = load i32, i32* %19
%21 = tail call i32 @memcpy(i32* %17, i32 %20, i32 4)
ret void
}