#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*/ fprintf(int /*<<< orphan*/, char *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int stuff_net_addr(struct in_addr *p, char *hostname) {
  struct hostent *ntpserver;
  ntpserver = gethostbyname(hostname);
  if (ntpserver == NULL) {
    return 0;
  }
  if (ntpserver->h_length != 4) {
    fprintf(stderr, "oops %d\n", ntpserver->h_length);
    return 0;
  }
  memcpy(&(p->s_addr), ntpserver->h_addr_list[0], 4);
  return 1;
}


x86 assembly (clang, -O0):
<stuff_net_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1164 <stuff_net_addr+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <stuff_net_addr+0x87>
mov    -0x20(%rbp),%rax
cmpl   $0x4,(%rax)
je     1198 <stuff_net_addr+0x68>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <stuff_net_addr+0x87>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stuff_net_addr>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <gethostbyname@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     117c <stuff_net_addr+0x4c>
mov    (%rax),%edx
cmp    $0x4,%edx
jne    1167 <stuff_net_addr+0x37>
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    %r14,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    $0x1,%ebx
jmp    117c <stuff_net_addr+0x4c>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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 i32 @stuff_net_addr(%struct.in_addr* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.in_addr*
%5 = alloca i8*
%6 = alloca %struct.hostent*
store %struct.in_addr* %0, %struct.in_addr** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call %struct.hostent* @gethostbyname(i8* %7)
store %struct.hostent* %8, %struct.hostent** %6
%9 = load %struct.hostent*, %struct.hostent** %6
%10 = icmp eq %struct.hostent* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %32
12: ; preds = %2
%13 = load %struct.hostent*, %struct.hostent** %6
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = icmp ne i32 %15, 4
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load %struct.hostent*, %struct.hostent** %6
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 0, i32* %3
br label %32
23: ; preds = %12
%24 = load %struct.in_addr*, %struct.in_addr** %4
%25 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %24, i32 0, i32 0
%26 = load %struct.hostent*, %struct.hostent** %6
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i32 0, i32 1
%28 = load i32*, i32** %27
%29 = getelementptr inbounds i32, i32* %28, i64 0
%30 = load i32, i32* %29
%31 = call i32 @memcpy(i32* %25, i32 %30, i32 4)
store i32 1, i32* %3
br label %32
32: ; preds = %23, %17, %11
%33 = load i32, i32* %3
ret i32 %33
}

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 i32 @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 %18, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 4
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %18
12: ; preds = %5
%13 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %0, i64 0, i32 0
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 1
%15 = load i32*, i32** %14
%16 = load i32, i32* %15
%17 = tail call i32 @memcpy(i32* %13, i32 %16, i32 4)
br label %18
18: ; preds = %2, %12, %9
%19 = phi i32 [ 0, %9 ], [ 1, %12 ], [ 0, %2 ]
ret i32 %19
}