#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 in_addr {
  int s_addr;
};
struct hostent {
  char *h_name;
  int h_length;
  char **h_aliases;
  int /*<<< orphan*/ h_addrtype;
  scalar_t__ h_addr_list;
};

/* Variables and functions */
char *addr_str(int /*<<< orphan*/, struct in_addr *);
char *addr_type(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void dump_host(struct hostent *h) {
  printf("host entry: \n"
         "  name: %s\n"
         "  addrtype: %s\n"
         "  addrlen: %d\n"
         "  aliases: \n",
         h->h_name, addr_type(h->h_addrtype), h->h_length);
  int i = 0;
  char **ptr = h->h_aliases;
  while (ptr[i] != 0) {
    printf("    alias[%d]: %s\n", i, ptr[i]);
    i++;
  }
  i = 0;
  struct in_addr **addr = (struct in_addr **)h->h_addr_list;
  while (addr[i] != 0) {
    printf("    addr[%d]: %s 0x%08x\n", i, addr_str(h->h_addrtype, addr[i]),
           addr[i]->s_addr);
    i++;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dump_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%edi
call   1030 <addr_type@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11c0 <dump_host+0x90>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1182 <dump_host+0x52>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1234 <dump_host+0x104>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%edi
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <addr_str@plt>
mov    -0x2c(%rbp),%esi
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%ecx
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d3 <dump_host+0xa3>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_host>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    (%rdi),%rbx
mov    0x18(%rdi),%edi
call   1030 <addr_type@plt>
mov    0x8(%r15),%ecx
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r15),%r12
mov    (%r12),%rdx
test   %rdx,%rdx
je     11aa <dump_host+0x6a>
lea    0xec0(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r12,%rbx,8),%rdx
add    $0x1,%rbx
test   %rdx,%rdx
jne    1190 <dump_host+0x50>
mov    0x20(%r15),%r12
mov    (%r12),%rsi
test   %rsi,%rsi
je     11ec <dump_host+0xac>
lea    0xe97(%rip),%r14
xor    %ebx,%ebx
mov    0x18(%r15),%edi
call   1060 <addr_str@plt>
mov    (%r12,%rbx,8),%rcx
mov    (%rcx),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r12,%rbx,8),%rsi
add    $0x1,%rbx
test   %rsi,%rsi
jne    11c0 <dump_host+0x80>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <putchar@plt>

LLVM IR (-O0):
%struct.hostent = type { i8*, i32, i8**, i32, i64 }
%struct.in_addr = type { i32 }
@.str = [66 x i8] c"host entry: \0A name: %s\0A addrtype: %s\0A addrlen: %d\0A aliases: \0A\00"
@.str.1 = [19 x i8] c" alias[%d]: %s\0A\00"
@.str.2 = [25 x i8] c" addr[%d]: %s 0x%08x\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @dump_host(%struct.hostent* %0) {
%2 = alloca %struct.hostent*
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.in_addr**
store %struct.hostent* %0, %struct.hostent** %2
%6 = load %struct.hostent*, %struct.hostent** %2
%7 = getelementptr inbounds %struct.hostent, %struct.hostent* %6, i32 0, i32 0
%8 = load i8*, i8** %7
%9 = load %struct.hostent*, %struct.hostent** %2
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %9, i32 0, i32 3
%11 = load i32, i32* %10
%12 = call i8* @addr_type(i32 %11)
%13 = load %struct.hostent*, %struct.hostent** %2
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %12, i32 %15)
store i32 0, i32* %3
%17 = load %struct.hostent*, %struct.hostent** %2
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i32 0, i32 2
%19 = load i8**, i8*** %18
store i8** %19, i8*** %4
br label %20
20: ; preds = %27, %1
%21 = load i8**, i8*** %4
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %37
27: ; preds = %20
%28 = load i32, i32* %3
%29 = load i8**, i8*** %4
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %28, i8* %33)
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %20
37: ; preds = %20
store i32 0, i32* %3
%38 = load %struct.hostent*, %struct.hostent** %2
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %38, i32 0, i32 4
%40 = load i64, i64* %39
%41 = inttoptr i64 %40 to %struct.in_addr**
store %struct.in_addr** %41, %struct.in_addr*** %5
br label %42
42: ; preds = %49, %37
%43 = load %struct.in_addr**, %struct.in_addr*** %5
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %43, i64 %45
%47 = load %struct.in_addr*, %struct.in_addr** %46
%48 = icmp ne %struct.in_addr* %47, null
br i1 %48, label %49, label %70
49: ; preds = %42
%50 = load i32, i32* %3
%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 = load %struct.in_addr**, %struct.in_addr*** %5
%55 = load i32, i32* %3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %54, i64 %56
%58 = load %struct.in_addr*, %struct.in_addr** %57
%59 = call i8* @addr_str(i32 %53, %struct.in_addr* %58)
%60 = load %struct.in_addr**, %struct.in_addr*** %5
%61 = load i32, i32* %3
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %60, i64 %62
%64 = load %struct.in_addr*, %struct.in_addr** %63
%65 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %64, i32 0, i32 0
%66 = load i32, i32* %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %50, i8* %59, i32 %66)
%68 = load i32, i32* %3
%69 = add nsw i32 %68, 1
store i32 %69, i32* %3
br label %42
70: ; preds = %42
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i32, i8**, i32, i64 }
%struct.in_addr = type { i32 }
@.str = [66 x i8] c"host entry: \0A name: %s\0A addrtype: %s\0A addrlen: %d\0A aliases: \0A\00"
@.str.1 = [19 x i8] c" alias[%d]: %s\0A\00"
@.str.2 = [25 x i8] c" addr[%d]: %s 0x%08x\0A\00"
define void @dump_host(%struct.hostent* nocapture %0) {
%2 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 0
%3 = load i8*, i8** %2
%4 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 3
%5 = load i32, i32* %4
%6 = tail call i8* @addr_type(i32 %5)
%7 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 1
%8 = load i32, i32* %7
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %6, i32 %8)
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 2
%11 = load i8**, i8*** %10
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %23, label %14
14: ; preds = %1, %14
%15 = phi i64 [ %19, %14 ], [ 0, %1 ]
%16 = phi i8* [ %21, %14 ], [ %12, %1 ]
%17 = trunc i64 %15 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %17, i8* %16)
%19 = add nuw i64 %15, 1
%20 = getelementptr inbounds i8*, i8** %11, i64 %19
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %14
23: ; preds = %14, %1
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 4
%25 = load i64, i64* %24
%26 = inttoptr i64 %25 to %struct.in_addr**
%27 = load %struct.in_addr*, %struct.in_addr** %26
%28 = icmp eq %struct.in_addr* %27, null
br i1 %28, label %44, label %29
29: ; preds = %23, %29
%30 = phi i64 [ %40, %29 ], [ 0, %23 ]
%31 = phi %struct.in_addr* [ %42, %29 ], [ %27, %23 ]
%32 = phi %struct.in_addr** [ %41, %29 ], [ %26, %23 ]
%33 = load i32, i32* %4
%34 = tail call i8* @addr_str(i32 %33, %struct.in_addr* %31)
%35 = load %struct.in_addr*, %struct.in_addr** %32
%36 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %35, i64 0, i32 0
%37 = load i32, i32* %36
%38 = trunc i64 %30 to i32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %38, i8* %34, i32 %37)
%40 = add nuw i64 %30, 1
%41 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %26, i64 %40
%42 = load %struct.in_addr*, %struct.in_addr** %41
%43 = icmp eq %struct.in_addr* %42, null
br i1 %43, label %44, label %29
44: ; preds = %29, %23
%45 = tail call i32 @putchar(i32 10)
ret void
}