#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ h_errno;
char *hstrerror(int /*<<< orphan*/);
int /*<<< orphan*/ *inet_ntop(int, char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
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) {
      fprintf(stderr, "gethostbyname() for %s failed: %s\n", ptr,
              hstrerror(h_errno));
      continue;
    }
    printf("official hostname: %s\n", hptr->h_name);
    for (pptr = hptr->h_aliases; *pptr != NULL; ++pptr)
      printf("\t aliases name: %s\n", *pptr);
    switch (hptr->h_addrtype) {
    case AF_INET:
      pptr = hptr->h_addr_list;
      for (; *pptr != NULL; ++pptr) {
        if (inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str)) == NULL)
          fprintf(stderr, "inet_ntop() failed: %s\n", strerror(errno));
        else
          printf("\t address: %s\n", str);
      }
      break;
    default:
      fprintf(stderr, "unknown address type\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)
mov    0x2e4b(%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    1348 <main+0x1e8>
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,-0x38(%rbp)
cmp    $0x0,%rax
jne    1225 <main+0xc5>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1070 <hstrerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    11a6 <main+0x46>
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1276 <main+0x116>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xdda(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1244 <main+0xe4>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%eax
sub    $0x80,%eax
jne    132c <main+0x1cc>
jmp    128d <main+0x12d>
mov    -0x38(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1327 <main+0x1c7>
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   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    1301 <main+0x1a1>
mov    0x2d03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xd59(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1311 <main+0x1b1>
mov    -0x40(%rbp),%rsi
lea    0xd5a(%rip),%rdi
call   1040 <printf@plt>
jmp    1316 <main+0x1b6>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1299 <main+0x139>
jmp    1343 <main+0x1e3>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
lea    0xd39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    11a6 <main+0x46>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

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),%eax
mov    %rsp,%r12
mov    %rax,-0x40(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmp    $0x2,%edi
jl     131c <main+0x1bc>
mov    %rsi,%rbx
lea    0xe98(%rip),%r13
jmp    11f9 <main+0x99>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2e21(%rip),%rax
mov    (%rax),%r14d
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1070 <hstrerror@plt>
mov    %r14d,%edi
lea    0xe2e(%rip),%rsi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rcx
lea    -0x1(%rcx),%eax
mov    -0x38(%rbp),%rbx
add    $0x8,%rbx
cmp    $0x2,%ecx
mov    %eax,%edi
jle    131c <main+0x1bc>
mov    %rdi,-0x30(%rbp)
mov    0x8(%rbx),%r15
mov    %r15,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
mov    %rbx,-0x38(%rbp)
je     11b0 <main+0x50>
mov    %rax,%r14
mov    (%rax),%rsi
lea    0xe04(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%r14),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1254 <main+0xf4>
add    $0x8,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
call   1040 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1240 <main+0xe0>
cmpl   $0x80,0x10(%r14)
jne    1300 <main+0x1a0>
mov    0x18(%r14),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     11df <main+0x7f>
add    $0x8,%rbx
mov    $0x80,%edi
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdx
mov    -0x40(%rbp),%rcx
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     12b0 <main+0x150>
lea    0xdce(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
jmp    12dc <main+0x17c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2d21(%rip),%rax
mov    (%rax),%r15d
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %r15d,%edi
lea    0xd7c(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%rsi
test   %rsi,%rsi
je     11df <main+0x7f>
mov    0x10(%r14),%edi
add    $0x8,%rbx
jmp    1280 <main+0x120>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11df <main+0x7f>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i8*, i8**, i32, i8** }
@INET_ADDRSTRLEN = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"gethostbyname() for %s failed: %s\0A\00"
@h_errno = global i32 0
@.str.1 = [23 x i8] c"official hostname: %s\0A\00"
@.str.2 = [20 x i8] c"\09 aliases name: %s\0A\00"
@.str.3 = [24 x i8] c"inet_ntop() failed: %s\0A\00"
@errno = global i32 0
@.str.4 = [15 x i8] c"\09 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 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 = %87, %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 %88
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 %32
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %6
%29 = load i32, i32* @h_errno
%30 = call i8* @hstrerror(i32 %29)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %30)
br label %15
32: ; preds = %19
%33 = load %struct.hostent*, %struct.hostent** %10
%34 = getelementptr inbounds %struct.hostent, %struct.hostent* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = load %struct.hostent*, %struct.hostent** %10
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %37, i32 0, i32 1
%39 = load i8**, i8*** %38
store i8** %39, i8*** %7
br label %40
40: ; preds = %48, %32
%41 = load i8**, i8*** %7
%42 = load i8*, i8** %41
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %51
44: ; preds = %40
%45 = load i8**, i8*** %7
%46 = load i8*, i8** %45
%47 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %44
%49 = load i8**, i8*** %7
%50 = getelementptr inbounds i8*, i8** %49, i32 1
store i8** %50, i8*** %7
br label %40
51: ; preds = %40
%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 %84 [
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 = %80, %55
%60 = load i8**, i8*** %7
%61 = load i8*, i8** %60
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %83
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 i32* @inet_ntop(i32 %66, i8* %68, i8* %14, i32 %69)
%71 = icmp eq i32* %70, null
br i1 %71, label %72, label %77
72: ; preds = %63
%73 = load i32, i32* @stderr
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %75)
br label %79
77: ; preds = %63
%78 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %14)
br label %79
79: ; preds = %77, %72
br label %80
80: ; preds = %79
%81 = load i8**, i8*** %7
%82 = getelementptr inbounds i8*, i8** %81, i32 1
store i8** %82, i8*** %7
br label %59
83: ; preds = %59
br label %87
84: ; preds = %51
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %87
87: ; preds = %84, %83
br label %15
88: ; preds = %15
store i32 0, i32* %3
%89 = load i8*, i8** %8
%90 = load i32, i32* %3
ret i32 %90
}

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