#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;
  int h_addrtype;
  char **h_aliases;
  char **h_addr_list;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
char *inet_ntop(int, char *, char *, int);
int /*<<< orphan*/ printf(char *, char const *, ...);
void output_hostent(const char *call, struct hostent *hptr) {
  char **pptr;
  char buf[46];
  if (hptr == NULL)
    printf("Call: %s returned NULL\n", call);
  else {
    printf("Call: %s returned: name: %s, addr_type: %d\n", call, hptr->h_name,
           hptr->h_addrtype);
    if (hptr->h_aliases)
      for (pptr = hptr->h_aliases; *pptr != NULL; pptr++)
        printf("  alias: %s\n", *pptr);
    for (pptr = hptr->h_addr_list; *pptr != NULL; pptr++)
      printf("  ip: %s\n",
             inet_ntop(hptr->h_addrtype, *pptr, buf, sizeof(buf)));
  }
}


x86 assembly (clang, -O0):
<output_hostent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1152 <output_hostent+0x32>
mov    -0x8(%rbp),%rsi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1223 <output_hostent+0x103>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     11c6 <output_hostent+0xa6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11c1 <output_hostent+0xa1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    118d <output_hostent+0x6d>
jmp    11c6 <output_hostent+0xa6>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     121e <output_hostent+0xfe>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x2e,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    11d2 <output_hostent+0xb2>
jmp    1223 <output_hostent+0x103>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_hostent>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r12
mov    %rdi,%rsi
test   %r12,%r12
je     11e7 <output_hostent+0xc7>
mov    (%r12),%rdx
mov    0x8(%r12),%ecx
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rbx
test   %rbx,%rbx
je     1186 <output_hostent+0x66>
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1186 <output_hostent+0x66>
add    $0x8,%rbx
lea    0xed6(%rip),%r14
xchg   %ax,%ax
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1170 <output_hostent+0x50>
mov    0x18(%r12),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     11db <output_hostent+0xbb>
add    $0x8,%rbx
mov    %rsp,%r14
lea    0xeb0(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%r12),%edi
mov    %r14,%rdx
mov    $0x2e,%ecx
call   1030 <inet_ntop@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11b0 <output_hostent+0x90>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe12(%rip),%rdi
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
%struct.hostent = type { i8*, i32, i8**, i8** }
@.str = [24 x i8] c"Call: %s returned NULL\0A\00"
@.str.1 = [44 x i8] c"Call: %s returned: name: %s, addr_type: %d\0A\00"
@.str.2 = [13 x i8] c" alias: %s\0A\00"
@.str.3 = [10 x i8] c" ip: %s\0A\00"
define void @output_hostent(i8* %0, %struct.hostent* %1) {
%3 = alloca i8*
%4 = alloca %struct.hostent*
%5 = alloca i8**
%6 = alloca [46 x i8]
store i8* %0, i8** %3
store %struct.hostent* %1, %struct.hostent** %4
%7 = load %struct.hostent*, %struct.hostent** %4
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %62
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = load %struct.hostent*, %struct.hostent** %4
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = load %struct.hostent*, %struct.hostent** %4
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %16, i32 %19)
%21 = load %struct.hostent*, %struct.hostent** %4
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i32 0, i32 2
%23 = load i8**, i8*** %22
%24 = icmp ne i8** %23, null
br i1 %24, label %25, label %41
25: ; preds = %12
%26 = load %struct.hostent*, %struct.hostent** %4
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i32 0, i32 2
%28 = load i8**, i8*** %27
store i8** %28, i8*** %5
br label %29
29: ; preds = %37, %25
%30 = load i8**, i8*** %5
%31 = load i8*, i8** %30
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %40
33: ; preds = %29
%34 = load i8**, i8*** %5
%35 = load i8*, i8** %34
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %33
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i32 1
store i8** %39, i8*** %5
br label %29
40: ; preds = %29
br label %41
41: ; preds = %40, %12
%42 = load %struct.hostent*, %struct.hostent** %4
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i32 0, i32 3
%44 = load i8**, i8*** %43
store i8** %44, i8*** %5
br label %45
45: ; preds = %58, %41
%46 = load i8**, i8*** %5
%47 = load i8*, i8** %46
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %61
49: ; preds = %45
%50 = load %struct.hostent*, %struct.hostent** %4
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = load i8**, i8*** %5
%54 = load i8*, i8** %53
%55 = getelementptr inbounds [46 x i8], [46 x i8]* %6, i64 0, i64 0
%56 = call i8* @inet_ntop(i32 %52, i8* %54, i8* %55, i32 46)
%57 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %56)
br label %58
58: ; preds = %49
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i32 1
store i8** %60, i8*** %5
br label %45
61: ; preds = %45
br label %62
62: ; preds = %61, %9
ret void
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i32, i8**, i8** }
@.str = [24 x i8] c"Call: %s returned NULL\0A\00"
@.str.1 = [44 x i8] c"Call: %s returned: name: %s, addr_type: %d\0A\00"
@.str.2 = [13 x i8] c" alias: %s\0A\00"
@.str.3 = [10 x i8] c" ip: %s\0A\00"
define void @output_hostent(i8* %0, %struct.hostent* %1) {
%3 = alloca [46 x i8]
%4 = getelementptr inbounds [46 x i8], [46 x i8]* %3, i64 0, i64 0
%5 = icmp eq %struct.hostent* %1, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %41
8: ; preds = %2
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 0
%10 = load i8*, i8** %9
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 1
%12 = load i32, i32* %11
%13 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %10, i32 %12)
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 2
%15 = load i8**, i8*** %14
%16 = icmp eq i8** %15, null
br i1 %16, label %27, label %17
17: ; preds = %8
%18 = load i8*, i8** %15
%19 = icmp eq i8* %18, null
br i1 %19, label %27, label %20
20: ; preds = %17, %20
%21 = phi i8* [ %25, %20 ], [ %18, %17 ]
%22 = phi i8** [ %24, %20 ], [ %15, %17 ]
%23 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%24 = getelementptr inbounds i8*, i8** %22, i64 1
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %20
27: ; preds = %20, %17, %8
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 3
%29 = load i8**, i8*** %28
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %41, label %32
32: ; preds = %27, %32
%33 = phi i8* [ %39, %32 ], [ %30, %27 ]
%34 = phi i8** [ %38, %32 ], [ %29, %27 ]
%35 = load i32, i32* %11
%36 = call i8* @inet_ntop(i32 %35, i8* %33, i8* %4, i32 46)
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = getelementptr inbounds i8*, i8** %34, i64 1
%39 = load i8*, i8** %38
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %32
41: ; preds = %32, %27, %6
ret void
}