#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_addr_list;
  char *h_name;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
struct hostent *zfor_gethostbyname(char *);
int main(int argc, char *argv[]) {
  struct hostent *h;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <hostname>\n", argv[0]);
    exit(1);
  }
  h = zfor_gethostbyname(argv[1]);
  if (h) {
    struct in_addr *ap;
    int got = 0;
    char **p = h->h_addr_list;
    while (*p) {
      got = 1;
      ap = (struct in_addr *)*p;
      printf("%s resolved to %s\n", h->h_name, inet_ntoa(*ap));
      p++;
    }
    if (!got) {
      printf("failed to resolve %s\n", argv[1]);
    }
  } else {
    printf("zfor_gethostbyname failed!\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1196 <main+0x46>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <zfor_gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1246 <main+0xf6>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     1221 <main+0xd1>
movl   $0x1,-0x24(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    11c4 <main+0x74>
cmpl   $0x0,-0x24(%rbp)
jne    1241 <main+0xf1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1254 <main+0x104>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11f7 <main+0x97>
mov    0x8(%r14),%rdi
call   1030 <zfor_gethostbyname@plt>
test   %rax,%rax
je     11c9 <main+0x69>
mov    %rax,%r15
mov    (%rax),%rbx
mov    (%rbx),%rax
test   %rax,%rax
je     11d7 <main+0x77>
add    $0x8,%rbx
lea    0xe7b(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    0x8(%r15),%r12
mov    (%rax),%edi
call   1050 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%rax
add    $0x8,%rbx
test   %rax,%rax
jne    11a0 <main+0x40>
jmp    11e9 <main+0x89>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
jmp    11e9 <main+0x89>
mov    0x8(%r14),%rsi
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdf6(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i8**, i8* }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <hostname>\0A\00"
@.str.1 = [19 x i8] c"%s resolved to %s\0A\00"
@.str.2 = [22 x i8] c"failed to resolve %s\0A\00"
@.str.3 = [28 x i8] c"zfor_gethostbyname failed!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
%7 = alloca %struct.in_addr*
%8 = alloca i32
%9 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call %struct.hostent* @zfor_gethostbyname(i8* %22)
store %struct.hostent* %23, %struct.hostent** %6
%24 = load %struct.hostent*, %struct.hostent** %6
%25 = icmp ne %struct.hostent* %24, null
br i1 %25, label %26, label %57
26: ; preds = %19
store i32 0, i32* %8
%27 = load %struct.hostent*, %struct.hostent** %6
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 0
%29 = load i8**, i8*** %28
store i8** %29, i8*** %9
br label %30
30: ; preds = %34, %26
%31 = load i8**, i8*** %9
%32 = load i8*, i8** %31
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %48
34: ; preds = %30
store i32 1, i32* %8
%35 = load i8**, i8*** %9
%36 = load i8*, i8** %35
%37 = bitcast i8* %36 to %struct.in_addr*
store %struct.in_addr* %37, %struct.in_addr** %7
%38 = load %struct.hostent*, %struct.hostent** %6
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %38, i32 0, i32 1
%40 = load i8*, i8** %39
%41 = load %struct.in_addr*, %struct.in_addr** %7
%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 ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* %44)
%46 = load i8**, i8*** %9
%47 = getelementptr inbounds i8*, i8** %46, i32 1
store i8** %47, i8*** %9
br label %30
48: ; preds = %30
%49 = load i32, i32* %8
%50 = icmp ne i32 %49, 0
br i1 %50, label %56, label %51
51: ; preds = %48
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %51, %48
br label %59
57: ; preds = %19
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %57, %56
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
%struct.hostent = type { i8**, i8* }
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <hostname>\0A\00"
@.str.1 = [19 x i8] c"%s resolved to %s\0A\00"
@.str.2 = [22 x i8] c"failed to resolve %s\0A\00"
@str = [27 x i8] c"zfor_gethostbyname failed!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call %struct.hostent* @zfor_gethostbyname(i8* %11)
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %35, label %14
14: ; preds = %9
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 0
%16 = load i8**, i8*** %15
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %32, label %19
19: ; preds = %14
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 1
br label %21
21: ; preds = %19, %21
%22 = phi i8* [ %17, %19 ], [ %30, %21 ]
%23 = phi i8** [ %16, %19 ], [ %29, %21 ]
%24 = load i8*, i8** %20
%25 = bitcast i8* %22 to i32*
%26 = load i32, i32* %25
%27 = tail call i8* @inet_ntoa(i32 %26)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %27)
%29 = getelementptr inbounds i8*, i8** %23, i64 1
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %37, label %21
32: ; preds = %14
%33 = load i8*, i8** %10
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %37
35: ; preds = %9
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %37
37: ; preds = %21, %32, %35
ret i32 0
}