#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;
  char *h_addr;
};
typedef int /*<<< orphan*/ str;

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
struct hostent *gethostbyname(char *);
char *inet_ntop(int, char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  char *ptr, **pptr;
  struct hostent *hptr;
  char str[32];
  ptr = argv[1];
  if ((hptr = gethostbyname(ptr)) == NULL) {
    printf(" gethostbyname error for host:%s\n", ptr);
    return 0;
  }
  printf("official hostname:%s\n", hptr->h_name);
  for (pptr = hptr->h_aliases; *pptr != NULL; pptr++)
    printf(" alias:%s\n", *pptr);
  switch (hptr->h_addrtype) {
  case AF_INET:
  case AF_INET6:
    pptr = hptr->h_addr_list;
    for (; *pptr != NULL; pptr++)
      printf(" address:%s\n",
             inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str)));
    printf(" first address: %s\n",
           inet_ntop(hptr->h_addrtype, hptr->h_addr, str, sizeof(str)));
    break;
  default:
    printf("unknown address type\n");
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1187 <main+0x57>
mov    -0x18(%rbp),%rsi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1294 <main+0x164>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11dc <main+0xac>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11a8 <main+0x78>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%eax
add    $0xffffff80,%eax
sub    $0x1,%eax
ja     127f <main+0x14f>
jmp    11f4 <main+0xc4>
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     124c <main+0x11c>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x20,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1200 <main+0xd0>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x28(%rbp),%rax
mov    0x20(%rax),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x20,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    128d <main+0x15d>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     1229 <main+0xe9>
mov    %rax,%r12
mov    (%rax),%rsi
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r12),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     11a6 <main+0x66>
add    $0x8,%rbx
lea    0xeac(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1190 <main+0x50>
mov    0x10(%r12),%edi
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x80,%eax
jne    123c <main+0xfc>
mov    0x18(%r12),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     120b <main+0xcb>
add    $0x8,%rbx
mov    %rsp,%r14
lea    0xe6d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdx
mov    $0x20,%ecx
call   1030 <inet_ntop@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
mov    0x10(%r12),%edi
test   %rsi,%rsi
jne    11e0 <main+0xa0>
mov    0x20(%r12),%rsi
mov    %rsp,%rdx
mov    $0x20,%ecx
call   1030 <inet_ntop@plt>
lea    0xe2c(%rip),%rdi
mov    %rax,%rsi
jmp    1233 <main+0xf3>
lea    0xdd0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1248 <main+0x108>
lea    0xe21(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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