#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;
  scalar_t__ h_addrtype;
  int h_length;
  char **h_addr_list;
};
typedef int /*<<< orphan*/ ipstr;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ assert(struct hostent *);
char *inet_ntop(scalar_t__, char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
void show_hostent(struct hostent *host) {
  char **cpp;
  char ipstr[INET6_ADDRSTRLEN];
  assert(host);
  printf("host name: %s\n", host->h_name);
  printf("host aliases: ");
  for (cpp = host->h_aliases; *cpp; cpp++)
    printf("%s ", *cpp);
  printf("\n");
  printf("host addrtype: %s\n", host->h_addrtype == AF_INET    ? "ipv4"
                                : host->h_addrtype == AF_INET6 ? "ipv6"
                                                               : "unknown");
  printf("host length: %d\n", host->h_length);
  if (host->h_addrtype != AF_INET && host->h_addrtype != AF_INET6)
    return;
  printf("host addr list: ", *host->h_addr_list);
  for (cpp = host->h_addr_list; *cpp; cpp++)
    printf("%s ", inet_ntop(host->h_addrtype, *cpp, ipstr, sizeof(ipstr)));
  printf("\n");
}


x86 assembly (clang, -O0):
<show_hostent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11d8 <show_hostent+0xa8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11a4 <show_hostent+0x74>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x2deb(%rip),%rcx
cmp    (%rcx),%rax
jne    120e <show_hostent+0xde>
lea    0xe30(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    1239 <show_hostent+0x109>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rdx
mov    0x2dbb(%rip),%rax
mov    (%rax),%rsi
lea    0xe18(%rip),%rax
lea    0xe0c(%rip),%rcx
cmp    %rsi,%rdx
cmove  %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x2d71(%rip),%rcx
cmp    (%rcx),%rax
je     129c <show_hostent+0x16c>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x2d51(%rip),%rcx
cmp    (%rcx),%rax
je     129c <show_hostent+0x16c>
movl   $0x1,-0x24(%rbp)
jmp    1324 <show_hostent+0x1f4>
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%rax
mov    (%rax),%rsi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     130f <show_hostent+0x1df>
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    0x10(%rcx),%rdi
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
lea    0xd27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    12c1 <show_hostent+0x191>
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_hostent>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
mov    0x2e90(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r15
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
call   1060 <assert@plt>
mov    0x0(%r13),%rsi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r13),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     11c6 <show_hostent+0x86>
add    $0x8,%rbx
lea    0xe76(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11b0 <show_hostent+0x70>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0x10(%r13),%rax
mov    0x2e05(%rip),%rbx
mov    0x2df6(%rip),%r12
cmp    (%r12),%rax
lea    0xe4d(%rip),%rcx
lea    0xe4b(%rip),%rdx
cmove  %rcx,%rdx
cmp    (%rbx),%rax
lea    0xe33(%rip),%rsi
cmovne %rdx,%rsi
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%r13),%esi
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r13),%rax
cmp    (%rbx),%rax
je     1235 <show_hostent+0xf5>
cmp    (%r12),%rax
jne    12a2 <show_hostent+0x162>
mov    0x20(%r13),%rax
mov    (%rax),%rsi
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%r13),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1298 <show_hostent+0x158>
add    $0x8,%rbx
lea    0xdbd(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x10(%r13),%rdi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1270 <show_hostent+0x130>
mov    $0xa,%edi
call   1040 <putchar@plt>
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**, i64, i32, i8** }
@INET6_ADDRSTRLEN = global i32 0
@.str = [15 x i8] c"host name: %s\0A\00"
@.str.1 = [15 x i8] c"host aliases: \00"
@.str.2 = [4 x i8] c"%s \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [19 x i8] c"host addrtype: %s\0A\00"
@AF_INET = global i64 0
@.str.5 = [5 x i8] c"ipv4\00"
@AF_INET6 = global i64 0
@.str.6 = [5 x i8] c"ipv6\00"
@.str.7 = [8 x i8] c"unknown\00"
@.str.8 = [17 x i8] c"host length: %d\0A\00"
@.str.9 = [17 x i8] c"host addr list: \00"
define void @show_hostent(%struct.hostent* %0) {
%2 = alloca %struct.hostent*
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store %struct.hostent* %0, %struct.hostent** %2
%7 = load i32, i32* @INET6_ADDRSTRLEN
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %4
%10 = alloca i8, i64 %8
store i64 %8, i64* %5
%11 = load %struct.hostent*, %struct.hostent** %2
%12 = call i32 @assert(%struct.hostent* %11)
%13 = load %struct.hostent*, %struct.hostent** %2
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%18 = load %struct.hostent*, %struct.hostent** %2
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i32 0, i32 1
%20 = load i8**, i8*** %19
store i8** %20, i8*** %3
br label %21
21: ; preds = %29, %1
%22 = load i8**, i8*** %3
%23 = load i8*, i8** %22
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i8**, i8*** %3
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %25
%30 = load i8**, i8*** %3
%31 = getelementptr inbounds i8*, i8** %30, i32 1
store i8** %31, i8*** %3
br label %21
32: ; preds = %21
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%34 = load %struct.hostent*, %struct.hostent** %2
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i32 0, i32 2
%36 = load i64, i64* %35
%37 = load i64, i64* @AF_INET
%38 = icmp eq i64 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %32
br label %48
40: ; preds = %32
%41 = load %struct.hostent*, %struct.hostent** %2
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %41, i32 0, i32 2
%43 = load i64, i64* %42
%44 = load i64, i64* @AF_INET6
%45 = icmp eq i64 %43, %44
%46 = zext i1 %45 to i64
%47 = select i1 %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0)
br label %48
48: ; preds = %40, %39
%49 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %39 ], [ %47, %40 ]
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %49)
%51 = load %struct.hostent*, %struct.hostent** %2
%52 = getelementptr inbounds %struct.hostent, %struct.hostent* %51, i32 0, i32 3
%53 = load i32, i32* %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %53)
%55 = load %struct.hostent*, %struct.hostent** %2
%56 = getelementptr inbounds %struct.hostent, %struct.hostent* %55, i32 0, i32 2
%57 = load i64, i64* %56
%58 = load i64, i64* @AF_INET
%59 = icmp ne i64 %57, %58
br i1 %59, label %60, label %67
60: ; preds = %48
%61 = load %struct.hostent*, %struct.hostent** %2
%62 = getelementptr inbounds %struct.hostent, %struct.hostent* %61, i32 0, i32 2
%63 = load i64, i64* %62
%64 = load i64, i64* @AF_INET6
%65 = icmp ne i64 %63, %64
br i1 %65, label %66, label %67
66: ; preds = %60
store i32 1, i32* %6
br label %94
67: ; preds = %60, %48
%68 = load %struct.hostent*, %struct.hostent** %2
%69 = getelementptr inbounds %struct.hostent, %struct.hostent* %68, i32 0, i32 4
%70 = load i8**, i8*** %69
%71 = load i8*, i8** %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i8* %71)
%73 = load %struct.hostent*, %struct.hostent** %2
%74 = getelementptr inbounds %struct.hostent, %struct.hostent* %73, i32 0, i32 4
%75 = load i8**, i8*** %74
store i8** %75, i8*** %3
br label %76
76: ; preds = %89, %67
%77 = load i8**, i8*** %3
%78 = load i8*, i8** %77
%79 = icmp ne i8* %78, null
br i1 %79, label %80, label %92
80: ; preds = %76
%81 = load %struct.hostent*, %struct.hostent** %2
%82 = getelementptr inbounds %struct.hostent, %struct.hostent* %81, i32 0, i32 2
%83 = load i64, i64* %82
%84 = load i8**, i8*** %3
%85 = load i8*, i8** %84
%86 = trunc i64 %8 to i32
%87 = call i8* @inet_ntop(i64 %83, i8* %85, i8* %10, i32 %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %87)
br label %89
89: ; preds = %80
%90 = load i8**, i8*** %3
%91 = getelementptr inbounds i8*, i8** %90, i32 1
store i8** %91, i8*** %3
br label %76
92: ; preds = %76
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %94
94: ; preds = %92, %66
%95 = load i8*, i8** %4
%96 = load i32, i32* %6
switch i32 %96, label %98 [
i32 0, label %97
i32 1, label %97
]
97: ; preds = %94, %94
ret void
98: ; preds = %94
unreachable
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i8**, i64, i32, i8** }
@INET6_ADDRSTRLEN = global i32 0
@.str = [15 x i8] c"host name: %s\0A\00"
@.str.1 = [15 x i8] c"host aliases: \00"
@.str.2 = [4 x i8] c"%s \00"
@.str.4 = [19 x i8] c"host addrtype: %s\0A\00"
@AF_INET = global i64 0
@.str.5 = [5 x i8] c"ipv4\00"
@AF_INET6 = global i64 0
@.str.6 = [5 x i8] c"ipv6\00"
@.str.7 = [8 x i8] c"unknown\00"
@.str.8 = [17 x i8] c"host length: %d\0A\00"
@.str.9 = [17 x i8] c"host addr list: \00"
define void @show_hostent(%struct.hostent* %0) {
%2 = load i32, i32* @INET6_ADDRSTRLEN
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32 @assert(%struct.hostent* %0)
%6 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 0
%7 = load i8*, i8** %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 1
%11 = load i8**, i8*** %10
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %21, label %14
14: ; preds = %1, %14
%15 = phi i8* [ %19, %14 ], [ %12, %1 ]
%16 = phi i8** [ %18, %14 ], [ %11, %1 ]
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%18 = getelementptr inbounds i8*, i8** %16, i64 1
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %14
21: ; preds = %14, %1
%22 = tail call i32 @putchar(i32 10)
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 2
%24 = load i64, i64* %23
%25 = load i64, i64* @AF_INET
%26 = icmp eq i64 %24, %25
%27 = load i64, i64* @AF_INET6
%28 = icmp eq i64 %24, %27
%29 = select i1 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0)
%30 = select i1 %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 3
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %33)
%35 = load i64, i64* %23
%36 = load i64, i64* @AF_INET
%37 = icmp eq i64 %35, %36
%38 = load i64, i64* @AF_INET6
%39 = icmp eq i64 %35, %38
%40 = select i1 %37, i1 true, i1 %39
br i1 %40, label %41, label %60
41: ; preds = %21
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 4
%43 = load i8**, i8*** %42
%44 = load i8*, i8** %43
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i8* %44)
%46 = load i8**, i8*** %42
%47 = load i8*, i8** %46
%48 = icmp eq i8* %47, null
br i1 %48, label %58, label %49
49: ; preds = %41, %49
%50 = phi i8* [ %56, %49 ], [ %47, %41 ]
%51 = phi i8** [ %55, %49 ], [ %46, %41 ]
%52 = load i64, i64* %23
%53 = call i8* @inet_ntop(i64 %52, i8* %50, i8* %4, i32 %2)
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %53)
%55 = getelementptr inbounds i8*, i8** %51, i64 1
%56 = load i8*, i8** %55
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %49
58: ; preds = %49, %41
%59 = call i32 @putchar(i32 10)
br label %60
60: ; preds = %21, %58
ret void
}