#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 INET_ADDRSTRLEN;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ h_errno;
char *hstrerror(int /*<<< orphan*/);
char *inet_ntop(int, char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
char *skip(char *);
int main(int argc, char **argv) {
  char *ptr, **pptr;
  char str[INET_ADDRSTRLEN];
  struct hostent *hptr;
  while (--argc > 0) {
    ptr = *++argv;
    if ((hptr = gethostbyname(ptr)) == NULL) {
      printf("gethostbyname(%s)\n", hstrerror(h_errno));
      continue;
    }
    printf("offical hostname:%s\n", skip(hptr->h_name));
    for (pptr = hptr->h_aliases; *pptr != NULL; pptr++)
      printf("alias: %s\n", skip(*pptr));
    switch (hptr->h_addrtype) {
    case AF_INET:
      pptr = hptr->h_addr_list;
      for (; *pptr != NULL; pptr++)
        printf("address: %s\n",
               inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str)));
      break;
    default:
      printf("unknown address type\n");
      break;
    }
  }
  exit(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    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    12f7 <main+0x197>
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   1060 <gethostbyname@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    120a <main+0xaa>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1070 <hstrerror@plt>
mov    %rax,%rsi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11a6 <main+0x46>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1030 <skip@plt>
mov    %rax,%rsi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     126f <main+0x10f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <skip@plt>
mov    %rax,%rsi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1233 <main+0xd3>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%eax
sub    $0x80,%eax
jne    12e4 <main+0x184>
jmp    1286 <main+0x126>
mov    -0x38(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     12df <main+0x17f>
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    0x10(%rcx),%edi
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rsi
mov    %eax,%ecx
call   1040 <inet_ntop@plt>
mov    %rax,%rsi
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1292 <main+0x132>
jmp    12f2 <main+0x192>
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11a6 <main+0x46>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e50(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
lea    0xf(%rcx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rdx,%rsp
cmp    $0x2,%edi
jl     132b <main+0x1bb>
mov    %rsi,%rbx
lea    0xe81(%rip),%r13
lea    0xe6f(%rip),%r12
jmp    1203 <main+0x93>
nopl   0x0(%rax,%rax,1)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1080 <hstrerror@plt>
lea    0xe2b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rcx
mov    -0x38(%rbp),%rdx
lea    -0x1(%rdx),%eax
mov    -0x40(%rbp),%rbx
add    $0x8,%rbx
cmp    $0x2,%edx
mov    %eax,%edi
lea    0xe2b(%rip),%r12
jle    132b <main+0x1bb>
mov    %rdi,-0x38(%rbp)
mov    %rcx,%r14
mov    0x8(%rbx),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
mov    %rbx,-0x40(%rbp)
je     11c0 <main+0x50>
mov    %rax,%r15
mov    (%rax),%rdi
call   1030 <skip@plt>
lea    0xde5(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%r15),%rbx
mov    (%rbx),%rdi
test   %rdi,%rdi
je     126e <main+0xfe>
add    $0x8,%rbx
nopl   0x0(%rax,%rax,1)
call   1030 <skip@plt>
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1250 <main+0xe0>
cmpl   $0x80,0x10(%r15)
jne    1310 <main+0x1a0>
mov    0x18(%r15),%r12
mov    (%r12),%rsi
test   %rsi,%rsi
mov    %r14,%rcx
mov    -0x30(%rbp),%rbx
lea    0xd9e(%rip),%r13
je     11e2 <main+0x72>
mov    $0x80,%edi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1040 <inet_ntop@plt>
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rcx
mov    0x8(%r12),%rsi
test   %rsi,%rsi
je     11e2 <main+0x72>
add    $0x10,%r12
nopl   (%rax)
mov    0x10(%r15),%edi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1040 <inet_ntop@plt>
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rcx
mov    (%r12),%rsi
add    $0x8,%r12
test   %rsi,%rsi
jne    12d0 <main+0x160>
jmp    11e2 <main+0x72>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xd29(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rcx
lea    0xd0d(%rip),%r13
jmp    11e2 <main+0x72>
xor    %edi,%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
%struct.hostent = type { i8*, i8**, i32, i8** }
@INET_ADDRSTRLEN = global i32 0
@.str = [19 x i8] c"gethostbyname(%s)\0A\00"
@h_errno = global i32 0
@.str.1 = [21 x i8] c"offical 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 = [21 x i8] c"unknown address type\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @INET_ADDRSTRLEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %64
7: ; preds = %2, %19
%8 = phi i32 [ %10, %19 ], [ %0, %2 ]
%9 = phi i8** [ %11, %19 ], [ %1, %2 ]
%10 = add nsw i32 %8, -1
%11 = getelementptr inbounds i8*, i8** %9, i64 1
%12 = load i8*, i8** %11
%13 = call %struct.hostent* @gethostbyname(i8* %12)
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %21
15: ; preds = %7
%16 = load i32, i32* @h_errno
%17 = call i8* @hstrerror(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %53, %47, %62, %42, %15
%20 = icmp sgt i32 %8, 2
br i1 %20, label %7, label %64
21: ; preds = %7
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = call i8* @skip(i8* %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 1
%27 = load i8**, i8*** %26
%28 = load i8*, i8** %27
%29 = icmp eq i8* %28, null
br i1 %29, label %38, label %30
30: ; preds = %21, %30
%31 = phi i8* [ %36, %30 ], [ %28, %21 ]
%32 = phi i8** [ %35, %30 ], [ %27, %21 ]
%33 = call i8* @skip(i8* %31)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds i8*, i8** %32, i64 1
%36 = load i8*, i8** %35
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %30
38: ; preds = %30, %21
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 2
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 128
br i1 %41, label %42, label %62
42: ; preds = %38
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 3
%44 = load i8**, i8*** %43
%45 = load i8*, i8** %44
%46 = icmp eq i8* %45, null
br i1 %46, label %19, label %47
47: ; preds = %42
%48 = call i8* @inet_ntop(i32 128, i8* %45, i8* %5, i32 %3)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds i8*, i8** %44, i64 1
%51 = load i8*, i8** %50
%52 = icmp eq i8* %51, null
br i1 %52, label %19, label %53
53: ; preds = %47, %53
%54 = phi i8* [ %60, %53 ], [ %51, %47 ]
%55 = phi i8** [ %59, %53 ], [ %50, %47 ]
%56 = load i32, i32* %39
%57 = call i8* @inet_ntop(i32 %56, i8* %54, i8* %5, i32 %3)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = getelementptr inbounds i8*, i8** %55, i64 1
%60 = load i8*, i8** %59
%61 = icmp eq i8* %60, null
br i1 %61, label %19, label %53
62: ; preds = %38
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %19
64: ; preds = %19, %2
%65 = call i32 @exit(i32 0)
unreachable
}