#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 hostent {
  char *h_name;
  char **h_aliases;
  int h_addrtype;
  char **h_addr_list;
};
typedef int /*<<< orphan*/ str;

/* Variables and functions */
#define AF_INET 128
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
char *inet_ntop(int, char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *ptr, **pptr;
  char str[100];
  struct hostent *hptr;
  while (--argc > 0) {
    ptr = *++argv;
    if ((hptr = gethostbyname(ptr)) == NULL) {
      fprintf(stderr, "gethost error for: %s\n", ptr);
      continue;
    }
    printf("official hostname: %s\n", hptr->h_name);
    for (pptr = hptr->h_aliases; *pptr != NULL; pptr++) {
      printf("\talias: %s\n", *pptr);
    }
    switch (hptr->h_addrtype) {
    case AF_INET:
      pptr = hptr->h_addr_list;
      for (; *pptr != NULL; pptr++) {
        printf("\taddress: %s\n",
               inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str)));
      }
      break;
    default:
      printf("\taddress: (UNKNOWN)\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    12a8 <main+0x168>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
jne    11ba <main+0x7a>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe50(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1159 <main+0x19>
mov    -0x98(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x98(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1215 <main+0xd5>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11e1 <main+0xa1>
mov    -0x98(%rbp),%rax
mov    0x10(%rax),%eax
sub    $0x80,%eax
jne    1295 <main+0x155>
jmp    122f <main+0xef>
mov    -0x98(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1290 <main+0x150>
mov    -0x98(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    -0x90(%rbp),%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    123e <main+0xfe>
jmp    12a3 <main+0x163>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1159 <main+0x19>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
cmp    $0x2,%edi
jl     12c1 <main+0x171>
mov    %rsi,%r14
lea    0x10(%rsp),%rbx
lea    0xec4(%rip),%rbp
lea    0xeb1(%rip),%r15
jmp    11b5 <main+0x65>
nop
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    %r13,%rdx
call   1070 <fprintf@plt>
mov    %rbp,%r13
mov    0x8(%rsp),%rcx
lea    -0x1(%rcx),%eax
add    $0x8,%r14
cmp    $0x2,%ecx
mov    %eax,%edi
mov    %r13,%rbp
jle    12c1 <main+0x171>
mov    %rdi,0x8(%rsp)
mov    0x8(%r14),%r13
mov    %r13,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     1180 <main+0x30>
mov    %rax,%r12
mov    %rbp,%r13
mov    (%rax),%rsi
lea    0xe3c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r12),%rbp
mov    0x0(%rbp),%rsi
test   %rsi,%rsi
je     1217 <main+0xc7>
add    $0x8,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    1200 <main+0xb0>
cmpl   $0x80,0x10(%r12)
jne    12b0 <main+0x160>
mov    0x18(%r12),%rbp
mov    0x0(%rbp),%rsi
test   %rsi,%rsi
je     119b <main+0x4b>
mov    $0x80,%edi
mov    %rbx,%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbp),%rsi
test   %rsi,%rsi
je     119b <main+0x4b>
add    $0x10,%rbp
nopl   0x0(%rax,%rax,1)
mov    0x10(%r12),%edi
mov    %rbx,%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    1270 <main+0x120>
jmp    119b <main+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xd91(%rip),%rdi
call   1040 <puts@plt>
jmp    119b <main+0x4b>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i8*, i8**, i32, i8** }
@stderr = global i32 0
@.str = [23 x i8] c"gethost error for: %s\0A\00"
@.str.1 = [23 x i8] c"official hostname: %s\0A\00"
@.str.2 = [12 x i8] c"\09alias: %s\0A\00"
@.str.3 = [14 x i8] c"\09address: %s\0A\00"
@.str.4 = [21 x i8] c"\09address: (UNKNOWN)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca [100 x i8]
%9 = alloca %struct.hostent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %10
10: ; preds = %71, %21, %2
%11 = load i32, i32* %4
%12 = add nsw i32 %11, -1
store i32 %12, i32* %4
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %72
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i32 1
store i8** %16, i8*** %5
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = call %struct.hostent* @gethostbyname(i8* %18)
store %struct.hostent* %19, %struct.hostent** %9
%20 = icmp eq %struct.hostent* %19, null
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %6
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %10
25: ; preds = %14
%26 = load %struct.hostent*, %struct.hostent** %9
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load %struct.hostent*, %struct.hostent** %9
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i32 0, i32 1
%32 = load i8**, i8*** %31
store i8** %32, i8*** %7
br label %33
33: ; preds = %41, %25
%34 = load i8**, i8*** %7
%35 = load i8*, i8** %34
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = load i8**, i8*** %7
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %37
%42 = load i8**, i8*** %7
%43 = getelementptr inbounds i8*, i8** %42, i32 1
store i8** %43, i8*** %7
br label %33
44: ; preds = %33
%45 = load %struct.hostent*, %struct.hostent** %9
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %45, i32 0, i32 2
%47 = load i32, i32* %46
switch i32 %47, label %69 [
i32 128, label %48
]
48: ; preds = %44
%49 = load %struct.hostent*, %struct.hostent** %9
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %49, i32 0, i32 3
%51 = load i8**, i8*** %50
store i8** %51, i8*** %7
br label %52
52: ; preds = %65, %48
%53 = load i8**, i8*** %7
%54 = load i8*, i8** %53
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %68
56: ; preds = %52
%57 = load %struct.hostent*, %struct.hostent** %9
%58 = getelementptr inbounds %struct.hostent, %struct.hostent* %57, i32 0, i32 2
%59 = load i32, i32* %58
%60 = load i8**, i8*** %7
%61 = load i8*, i8** %60
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%63 = call i8* @inet_ntop(i32 %59, i8* %61, i8* %62, i32 100)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %56
%66 = load i8**, i8*** %7
%67 = getelementptr inbounds i8*, i8** %66, i32 1
store i8** %67, i8*** %7
br label %52
68: ; preds = %52
br label %71
69: ; preds = %44
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %71
71: ; preds = %69, %68
br label %10
72: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i8**, i32, i8** }
@stderr = global i32 0
@.str = [23 x i8] c"gethost error for: %s\0A\00"
@.str.1 = [23 x i8] c"official hostname: %s\0A\00"
@.str.2 = [12 x i8] c"\09alias: %s\0A\00"
@.str.3 = [14 x i8] c"\09address: %s\0A\00"
@str = [20 x i8] c"\09address: (UNKNOWN)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %60
6: ; preds = %2, %17
%7 = phi i32 [ %9, %17 ], [ %0, %2 ]
%8 = phi i8** [ %10, %17 ], [ %1, %2 ]
%9 = add nsw i32 %7, -1
%10 = getelementptr inbounds i8*, i8** %8, i64 1
%11 = load i8*, i8** %10
%12 = call %struct.hostent* @gethostbyname(i8* %11)
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %14, label %19
14: ; preds = %6
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %17
17: ; preds = %49, %43, %58, %38, %14
%18 = icmp sgt i32 %7, 2
br i1 %18, label %6, label %60
19: ; preds = %6
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 1
%24 = load i8**, i8*** %23
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %34, label %27
27: ; preds = %19, %27
%28 = phi i8* [ %32, %27 ], [ %25, %19 ]
%29 = phi i8** [ %31, %27 ], [ %24, %19 ]
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%31 = getelementptr inbounds i8*, i8** %29, i64 1
%32 = load i8*, i8** %31
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %27
34: ; preds = %27, %19
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 2
%36 = load i32, i32* %35
%37 = icmp eq i32 %36, 128
br i1 %37, label %38, label %58
38: ; preds = %34
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 3
%40 = load i8**, i8*** %39
%41 = load i8*, i8** %40
%42 = icmp eq i8* %41, null
br i1 %42, label %17, label %43
43: ; preds = %38
%44 = call i8* @inet_ntop(i32 128, i8* %41, i8* %4, i32 100)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = getelementptr inbounds i8*, i8** %40, i64 1
%47 = load i8*, i8** %46
%48 = icmp eq i8* %47, null
br i1 %48, label %17, label %49
49: ; preds = %43, %49
%50 = phi i8* [ %56, %49 ], [ %47, %43 ]
%51 = phi i8** [ %55, %49 ], [ %46, %43 ]
%52 = load i32, i32* %35
%53 = call i8* @inet_ntop(i32 %52, i8* %50, i8* %4, i32 100)
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %53)
%55 = getelementptr inbounds i8*, i8** %51, i64 1
%56 = load i8*, i8** %55
%57 = icmp eq i8* %56, null
br i1 %57, label %17, label %49
58: ; preds = %34
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %17
60: ; preds = %17, %2
ret i32 0
}