#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(argv[1])) == 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    1254 <main+0x104>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c4 <main+0x74>
lea    0xe63(%rip),%rdi
call   1070 <herror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1254 <main+0x104>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5a(%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     123f <main+0xef>
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    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11fa <main+0xaa>
lea    0xdce(%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>
mov    0x8(%rsi),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     120a <main+0xaa>
mov    %rax,%rbx
mov    (%rax),%rsi
lea    0xe98(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9d(%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    0xe91(%rip),%rbx
nopl   0x0(%rax)
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    0xe05(%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 = [14 x i8] c"gethostbyname\00"
@.str.2 = [22 x i8] c"Official name is: %s\0A\00"
@.str.3 = [19 x i8] c" IP addresses: \00"
@.str.4 = [4 x i8] c"%s \00"
@.str.5 = [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 %54
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call %struct.hostent* @gethostbyname(i8* %17)
store %struct.hostent* %18, %struct.hostent** %7
%19 = icmp eq %struct.hostent* %18, null
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %54
22: ; preds = %14
%23 = load %struct.hostent*, %struct.hostent** %7
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%28 = load %struct.hostent*, %struct.hostent** %7
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i32 0, i32 1
%30 = load i64, i64* %29
%31 = inttoptr i64 %30 to %struct.in_addr**
store %struct.in_addr** %31, %struct.in_addr*** %8
store i32 0, i32* %6
br label %32
32: ; preds = %49, %22
%33 = load %struct.in_addr**, %struct.in_addr*** %8
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %33, i64 %35
%37 = load %struct.in_addr*, %struct.in_addr** %36
%38 = icmp ne %struct.in_addr* %37, null
br i1 %38, label %39, label %52
39: ; preds = %32
%40 = load %struct.in_addr**, %struct.in_addr*** %8
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %40, i64 %42
%44 = load %struct.in_addr*, %struct.in_addr** %43
%45 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i8* @inet_ntoa(i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %39
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %32
52: ; preds = %32
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %54
54: ; preds = %52, %20, %11
%55 = load i32, i32* %3
ret i32 %55
}

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 = [14 x i8] c"gethostbyname\00"
@.str.2 = [22 x i8] c"Official name is: %s\0A\00"
@.str.3 = [19 x i8] c" IP addresses: \00"
@.str.4 = [4 x i8] c"%s \00"
define i32 @main(i32 %0, i8** nocapture %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 %37
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call %struct.hostent* @gethostbyname(i8* %9)
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %37
14: ; preds = %7
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i64 0, i32 1
%20 = load i64, i64* %19
%21 = inttoptr i64 %20 to %struct.in_addr**
%22 = load %struct.in_addr*, %struct.in_addr** %21
%23 = icmp eq %struct.in_addr* %22, null
br i1 %23, label %35, label %24
24: ; preds = %14, %24
%25 = phi i64 [ %31, %24 ], [ 0, %14 ]
%26 = phi %struct.in_addr* [ %33, %24 ], [ %22, %14 ]
%27 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %26, i64 0, i32 0
%28 = load i32, i32* %27
%29 = tail call i8* @inet_ntoa(i32 %28)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = add nuw i64 %25, 1
%32 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %21, i64 %31
%33 = load %struct.in_addr*, %struct.in_addr** %32
%34 = icmp eq %struct.in_addr* %33, null
br i1 %34, label %35, label %24
35: ; preds = %24, %14
%36 = tail call i32 @putchar(i32 10)
br label %37
37: ; preds = %35, %12, %4
%38 = phi i32 [ 1, %4 ], [ 2, %12 ], [ 0, %35 ]
ret i32 %38
}