#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_str;

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ h_errno;
char *hstrerror(int /*<<< orphan*/);
char *inet_ntop(int, char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *name_ptr = NULL, **alias_pptr = NULL;
  char **addr_list_pptr = NULL;
  struct hostent *host_ptr = NULL;
  char ip_str[32];
  if (argc != 2) {
    fprintf(stderr, "Usage: ./%s domain_name\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  name_ptr = argv[1];
  if ((host_ptr = gethostbyname((const char *)name_ptr)) == NULL) {
    fprintf(stderr, "gethostbyname() error:%s", hstrerror(h_errno));
    exit(EXIT_FAILURE);
  }
  printf("official hostname(hostent->h_name):%s\n", host_ptr->h_name);
  for (alias_pptr = host_ptr->h_aliases; *alias_pptr != NULL; alias_pptr++)
    printf("\talias hostname(hostent->h_aliases):%s\n", *alias_pptr);
  switch (host_ptr->h_addrtype) {
  case AF_INET:
  case AF_INET6:
    for (addr_list_pptr = host_ptr->h_addr_list; *addr_list_pptr != NULL;
         addr_list_pptr++)
      printf("\tIP :%s\n", inet_ntop(host_ptr->h_addrtype, *addr_list_pptr,
                                     ip_str, sizeof(ip_str)));
    break;
  default:
    printf("unknown address type(not AF_INET || AF_INET6)\n");
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ca <main+0x6a>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1227 <main+0xc7>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1070 <hstrerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xe05(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     127c <main+0x11c>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1248 <main+0xe8>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%eax
add    $0xffffff80,%eax
sub    $0x1,%eax
ja     12f1 <main+0x191>
jmp    1294 <main+0x134>
mov    -0x30(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     12ec <main+0x18c>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x20,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    12a0 <main+0x140>
jmp    12ff <main+0x19f>
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jne    1287 <main+0x117>
mov    0x8(%rsi),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     129c <main+0x12c>
mov    %rax,%r12
mov    (%rax),%rsi
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r12),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     11e6 <main+0x76>
add    $0x8,%rbx
lea    0xe97(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11d0 <main+0x60>
mov    0x10(%r12),%edi
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x80,%eax
jne    126d <main+0xfd>
mov    0x18(%r12),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1279 <main+0x109>
mov    %rsp,%rdx
mov    $0x20,%ecx
call   1030 <inet_ntop@plt>
lea    0xe69(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rsi
test   %rsi,%rsi
je     1279 <main+0x109>
add    $0x10,%rbx
mov    %rsp,%r14
lea    0xe48(%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    1240 <main+0xd0>
jmp    1279 <main+0x109>
lea    0xe16(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd66(%rip),%rsi
jmp    12bf <main+0x14f>
mov    0x2d35(%rip),%rax
mov    (%rax),%ebx
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   1080 <hstrerror@plt>
lea    0xd5f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
%struct.hostent = type { i8*, i8**, i32, i8** }
@stderr = global i32 0
@.str = [25 x i8] c"Usage: ./%s domain_name\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"gethostbyname() error:%s\00"
@h_errno = global i32 0
@.str.2 = [39 x i8] c"official hostname(hostent->h_name):%s\0A\00"
@.str.3 = [40 x i8] c"\09alias hostname(hostent->h_aliases):%s\0A\00"
@.str.4 = [9 x i8] c"\09IP :%s\0A\00"
@str = [46 x i8] c"unknown address type(not AF_INET || AF_INET6)\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 = icmp eq i32 %0, 2
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call %struct.hostent* @gethostbyname(i8* %14)
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i32, i32* @h_errno
%20 = tail call i8* @hstrerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %12
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%26 = load i8*, i8** %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 1
%29 = load i8**, i8*** %28
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %39, label %32
32: ; preds = %24, %32
%33 = phi i8* [ %37, %32 ], [ %30, %24 ]
%34 = phi i8** [ %36, %32 ], [ %29, %24 ]
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%36 = getelementptr inbounds i8*, i8** %34, i64 1
%37 = load i8*, i8** %36
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %32
39: ; preds = %32, %24
%40 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 2
%41 = load i32, i32* %40
%42 = and i32 %41, -2
%43 = icmp eq i32 %42, 128
br i1 %43, label %44, label %64
44: ; preds = %39
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 3
%46 = load i8**, i8*** %45
%47 = load i8*, i8** %46
%48 = icmp eq i8* %47, null
br i1 %48, label %66, label %49
49: ; preds = %44
%50 = call i8* @inet_ntop(i32 %41, i8* %47, i8* %4, i32 32)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = getelementptr inbounds i8*, i8** %46, i64 1
%53 = load i8*, i8** %52
%54 = icmp eq i8* %53, null
br i1 %54, label %66, label %55
55: ; preds = %49, %55
%56 = phi i8* [ %62, %55 ], [ %53, %49 ]
%57 = phi i8** [ %61, %55 ], [ %52, %49 ]
%58 = load i32, i32* %40
%59 = call i8* @inet_ntop(i32 %58, i8* %56, i8* %4, i32 32)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %59)
%61 = getelementptr inbounds i8*, i8** %57, i64 1
%62 = load i8*, i8** %61
%63 = icmp eq i8* %62, null
br i1 %63, label %66, label %55
64: ; preds = %39
%65 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %66
66: ; preds = %55, %49, %44, %64
ret i32 0
}