#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 dummy;
};
struct hostent {
  char *h_name;
  scalar_t__ h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i;
  struct hostent *he;
  struct in_addr **addr_list;
  if (argc != 2) {
    fprintf(stderr, "usage: ghbn hostname\n");
    return 1;
  }
  if ((he = gethostbyname("www.google.com")) == NULL) {
    herror("gethostbyname");
    return 2;
  }
  printf("Official name is: %s\n", he->h_name);
  printf("    IP addresses: ");
  addr_list = (struct in_addr **)he->h_addr_list;
  for (i = 0; addr_list[i] != NULL; i++) {
    printf("%s ", inet_ntoa(*addr_list[i]));
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1191 <main+0x41>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1253 <main+0x103>
lea    0xe7e(%rip),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c3 <main+0x73>
lea    0xe73(%rip),%rdi
call   1070 <herror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1253 <main+0x103>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     123e <main+0xee>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f9 <main+0xa9>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11ed <main+0x8d>
lea    0xea2(%rip),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     120a <main+0xaa>
mov    %rax,%rbx
mov    (%rax),%rsi
lea    0xea4(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rbp
mov    0x0(%rbp),%rax
test   %rax,%rax
je     11e1 <main+0x81>
add    $0x8,%rbp
lea    0xe9d(%rip),%rbx
nop
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%rax
add    $0x8,%rbp
test   %rax,%rax
jne    11c0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    121c <main+0xbc>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%r14d
jmp    121c <main+0xbc>
lea    0xe14(%rip),%rdi
call   1080 <herror@plt>
mov    $0x2,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i8*, i64 }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"usage: ghbn hostname\0A\00"
@.str.1 = [15 x i8] c"www.google.com\00"
@.str.2 = [14 x i8] c"gethostbyname\00"
@.str.3 = [22 x i8] c"Official name is: %s\0A\00"
@.str.4 = [19 x i8] c" IP addresses: \00"
@.str.5 = [4 x i8] c"%s \00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca %struct.in_addr**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %51
14: ; preds = %2
%15 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store %struct.hostent* %15, %struct.hostent** %7
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %51
19: ; preds = %14
%20 = load %struct.hostent*, %struct.hostent** %7
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%25 = load %struct.hostent*, %struct.hostent** %7
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i32 0, i32 1
%27 = load i64, i64* %26
%28 = inttoptr i64 %27 to %struct.in_addr**
store %struct.in_addr** %28, %struct.in_addr*** %8
store i32 0, i32* %6
br label %29
29: ; preds = %46, %19
%30 = load %struct.in_addr**, %struct.in_addr*** %8
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %30, i64 %32
%34 = load %struct.in_addr*, %struct.in_addr** %33
%35 = icmp ne %struct.in_addr* %34, null
br i1 %35, label %36, label %49
36: ; preds = %29
%37 = load %struct.in_addr**, %struct.in_addr*** %8
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %37, i64 %39
%41 = load %struct.in_addr*, %struct.in_addr** %40
%42 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i8* @inet_ntoa(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %36
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %29
49: ; preds = %29
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %51
51: ; preds = %49, %17, %11
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i64 }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"usage: ghbn hostname\0A\00"
@.str.1 = [15 x i8] c"www.google.com\00"
@.str.2 = [14 x i8] c"gethostbyname\00"
@.str.3 = [22 x i8] c"Official name is: %s\0A\00"
@.str.4 = [19 x i8] c" IP addresses: \00"
@.str.5 = [4 x i8] c"%s \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %35
7: ; preds = %2
%8 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq %struct.hostent* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %35
12: ; preds = %7
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 1
%18 = load i64, i64* %17
%19 = inttoptr i64 %18 to %struct.in_addr**
%20 = load %struct.in_addr*, %struct.in_addr** %19
%21 = icmp eq %struct.in_addr* %20, null
br i1 %21, label %33, label %22
22: ; preds = %12, %22
%23 = phi i64 [ %29, %22 ], [ 0, %12 ]
%24 = phi %struct.in_addr* [ %31, %22 ], [ %20, %12 ]
%25 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %24, i64 0, i32 0
%26 = load i32, i32* %25
%27 = tail call i8* @inet_ntoa(i32 %26)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %27)
%29 = add nuw i64 %23, 1
%30 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %19, i64 %29
%31 = load %struct.in_addr*, %struct.in_addr** %30
%32 = icmp eq %struct.in_addr* %31, null
br i1 %32, label %33, label %22
33: ; preds = %22, %12
%34 = tail call i32 @putchar(i32 10)
br label %35
35: ; preds = %33, %10, %4
%36 = phi i32 [ 1, %4 ], [ 2, %10 ], [ 0, %33 ]
ret i32 %36
}