#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*/ ip;

/* 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 **p;
  struct hostent *host;
  char ip[32];
  char *name;
  name = argv[1];
  if ((host = gethostbyname(name)) == NULL) {
    printf("get host error!\n");
  }
  printf("name is %s,official name is %s\n", name, host->h_name);
  for (p = host->h_aliases; *p != NULL; p++) {
    printf("aliases %s\n", *p);
  }
  switch (host->h_addrtype) {
  case AF_INET:
  case AF_INET6:
    for (p = host->h_addr_list; *p != NULL; p++) {
      printf("address %s \n", inet_ntop(host->h_addrtype, *p, ip, sizeof(ip)));
    }
    break;
  default:
    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,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1177 <main+0x47>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11d0 <main+0xa0>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    119c <main+0x6c>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%eax
add    $0xffffff80,%eax
sub    $0x1,%eax
ja     1245 <main+0x115>
jmp    11e8 <main+0xb8>
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1240 <main+0x110>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    -0x40(%rbp),%rdx
mov    $0x20,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    11f4 <main+0xc4>
jmp    124a <main+0x11a>
jmp    124a <main+0x11a>
xor    %eax,%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),%r14
mov    %r14,%rdi
call   1060 <gethostbyname@plt>
mov    %rax,%r12
test   %rax,%rax
jne    116b <main+0x2b>
lea    0xed3(%rip),%rdi
call   1040 <puts@plt>
mov    (%r12),%rdx
lea    0xe8a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r12),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     11b6 <main+0x76>
add    $0x8,%rbx
lea    0xe88(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11a0 <main+0x60>
mov    0x10(%r12),%edi
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x80,%eax
jne    123b <main+0xfb>
mov    0x18(%r12),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     123b <main+0xfb>
mov    %rsp,%rdx
mov    $0x20,%ecx
call   1030 <inet_ntop@plt>
lea    0xe44(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rsi
test   %rsi,%rsi
je     123b <main+0xfb>
add    $0x10,%rbx
mov    %rsp,%r14
lea    0xe23(%rip),%r15
nopl   0x0(%rax)
mov    0x10(%r12),%edi
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
test   %rsi,%rsi
jne    1210 <main+0xd0>
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** }
@.str = [17 x i8] c"get host error!\0A\00"
@.str.1 = [32 x i8] c"name is %s,official name is %s\0A\00"
@.str.2 = [12 x i8] c"aliases %s\0A\00"
@.str.3 = [13 x i8] c"address %s \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca %struct.hostent*
%8 = alloca [32 x i8]
%9 = alloca 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** %9
%13 = load i8*, i8** %9
%14 = call %struct.hostent* @gethostbyname(i8* %13)
store %struct.hostent* %14, %struct.hostent** %7
%15 = icmp eq %struct.hostent* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = load i8*, i8** %9
%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 ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %22)
%24 = load %struct.hostent*, %struct.hostent** %7
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i32 0, i32 1
%26 = load i8**, i8*** %25
store i8** %26, i8*** %6
br label %27
27: ; preds = %35, %18
%28 = load i8**, i8*** %6
%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*** %6
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %31
%36 = load i8**, i8*** %6
%37 = getelementptr inbounds i8*, i8** %36, i32 1
store i8** %37, i8*** %6
br label %27
38: ; preds = %27
%39 = load %struct.hostent*, %struct.hostent** %7
%40 = getelementptr inbounds %struct.hostent, %struct.hostent* %39, i32 0, i32 2
%41 = load i32, i32* %40
switch i32 %41, label %63 [
i32 129, label %42
i32 128, label %42
]
42: ; preds = %38, %38
%43 = load %struct.hostent*, %struct.hostent** %7
%44 = getelementptr inbounds %struct.hostent, %struct.hostent* %43, i32 0, i32 3
%45 = load i8**, i8*** %44
store i8** %45, i8*** %6
br label %46
46: ; preds = %59, %42
%47 = load i8**, i8*** %6
%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** %7
%52 = getelementptr inbounds %struct.hostent, %struct.hostent* %51, i32 0, i32 2
%53 = load i32, i32* %52
%54 = load i8**, i8*** %6
%55 = load i8*, i8** %54
%56 = getelementptr inbounds [32 x i8], [32 x i8]* %8, 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*** %6
%61 = getelementptr inbounds i8*, i8** %60, i32 1
store i8** %61, i8*** %6
br label %46
62: ; preds = %46
br label %64
63: ; preds = %38
br label %64
64: ; preds = %63, %62
ret i32 0
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i8**, i32, i8** }
@.str.1 = [32 x i8] c"name is %s,official name is %s\0A\00"
@.str.2 = [12 x i8] c"aliases %s\0A\00"
@.str.3 = [13 x i8] c"address %s \0A\00"
@str = [16 x i8] c"get host error!\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 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %9, %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 ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %6, 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 ([12 x i8], [12 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 %51
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 %51, label %36
36: ; preds = %31
%37 = call i8* @inet_ntop(i32 %28, i8* %34, i8* %4, i32 32)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds i8*, i8** %33, i64 1
%40 = load i8*, i8** %39
%41 = icmp eq i8* %40, null
br i1 %41, label %51, label %42
42: ; preds = %36, %42
%43 = phi i8* [ %49, %42 ], [ %40, %36 ]
%44 = phi i8** [ %48, %42 ], [ %39, %36 ]
%45 = load i32, i32* %27
%46 = call i8* @inet_ntop(i32 %45, i8* %43, i8* %4, i32 32)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = getelementptr inbounds i8*, i8** %44, i64 1
%49 = load i8*, i8** %48
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %42
51: ; preds = %42, %36, %31, %26
ret i32 0
}