#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 netent {
  int n_net;
  char *n_name;
  char **n_aliases;
  int /*<<< orphan*/ n_addrtype;
};
struct in_addr {
  int /*<<< orphan*/ s_addr;
};

/* Variables and functions */
char *addr_str(int /*<<< orphan*/, struct in_addr *);
char *addr_type(int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int);
int /*<<< orphan*/ printf(char *, ...);
void dump_net(struct netent *h) {
  struct in_addr addr;
  addr.s_addr = htonl(h->n_net);
  printf("net entry: \n"
         "  name: %s\n"
         "  addrtype: %s\n"
         "  net: %s 0x%08x\n"
         "  aliases: \n",
         h->n_name, addr_type(h->n_addrtype), addr_str(h->n_addrtype, &addr),
         h->n_net);
  int i = 0;
  char **ptr = h->n_aliases;
  while (ptr[i] != 0) {
    printf("    alias[%d]: %s\n", i, ptr[i]);
    i++;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dump_net>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%edi
call   1030 <addr_type@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%edi
lea    -0x10(%rbp),%rsi
call   1060 <addr_str@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    (%rax),%r8d
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11f7 <dump_net+0xb7>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b9 <dump_net+0x79>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_net>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    (%rdi),%edi
call   1060 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%r14
mov    0x18(%rbx),%edi
call   1030 <addr_type@plt>
mov    %rax,%r15
mov    0x18(%rbx),%edi
lea    0x8(%rsp),%rsi
call   1070 <addr_str@plt>
mov    (%rbx),%r8d
lea    0xe73(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%r15
mov    (%r15),%rdx
test   %rdx,%rdx
je     11da <dump_net+0x8a>
lea    0xe94(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r15,%rbx,8),%rdx
add    $0x1,%rbx
test   %rdx,%rdx
jne    11c0 <dump_net+0x70>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.netent = type { i32, i8*, i8**, i32 }
%struct.in_addr = type { i32 }
@.str = [68 x i8] c"net entry: \0A name: %s\0A addrtype: %s\0A net: %s 0x%08x\0A aliases: \0A\00"
@.str.1 = [19 x i8] c" alias[%d]: %s\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @dump_net(%struct.netent* %0) {
%2 = alloca %struct.netent*
%3 = alloca %struct.in_addr
%4 = alloca i32
%5 = alloca i8**
store %struct.netent* %0, %struct.netent** %2
%6 = load %struct.netent*, %struct.netent** %2
%7 = getelementptr inbounds %struct.netent, %struct.netent* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = call i32 @htonl(i32 %8)
%10 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
store i32 %9, i32* %10
%11 = load %struct.netent*, %struct.netent** %2
%12 = getelementptr inbounds %struct.netent, %struct.netent* %11, i32 0, i32 1
%13 = load i8*, i8** %12
%14 = load %struct.netent*, %struct.netent** %2
%15 = getelementptr inbounds %struct.netent, %struct.netent* %14, i32 0, i32 3
%16 = load i32, i32* %15
%17 = call i8* @addr_type(i32 %16)
%18 = load %struct.netent*, %struct.netent** %2
%19 = getelementptr inbounds %struct.netent, %struct.netent* %18, i32 0, i32 3
%20 = load i32, i32* %19
%21 = call i8* @addr_str(i32 %20, %struct.in_addr* %3)
%22 = load %struct.netent*, %struct.netent** %2
%23 = getelementptr inbounds %struct.netent, %struct.netent* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %17, i8* %21, i32 %24)
store i32 0, i32* %4
%26 = load %struct.netent*, %struct.netent** %2
%27 = getelementptr inbounds %struct.netent, %struct.netent* %26, i32 0, i32 2
%28 = load i8**, i8*** %27
store i8** %28, i8*** %5
br label %29
29: ; preds = %36, %1
%30 = load i8**, i8*** %5
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %46
36: ; preds = %29
%37 = load i32, i32* %4
%38 = load i8**, i8*** %5
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %37, i8* %42)
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %29
46: ; preds = %29
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.netent = type { i32, i8*, i8**, i32 }
%struct.in_addr = type { i32 }
@.str = [68 x i8] c"net entry: \0A name: %s\0A addrtype: %s\0A net: %s 0x%08x\0A aliases: \0A\00"
@.str.1 = [19 x i8] c" alias[%d]: %s\0A\00"
define void @dump_net(%struct.netent* nocapture %0) {
%2 = alloca %struct.in_addr
%3 = bitcast %struct.in_addr* %2 to i8*
%4 = getelementptr inbounds %struct.netent, %struct.netent* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = tail call i32 @htonl(i32 %5)
%7 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.netent, %struct.netent* %0, i64 0, i32 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds %struct.netent, %struct.netent* %0, i64 0, i32 3
%11 = load i32, i32* %10
%12 = tail call i8* @addr_type(i32 %11)
%13 = load i32, i32* %10
%14 = call i8* @addr_str(i32 %13, %struct.in_addr* %2)
%15 = load i32, i32* %4
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %12, i8* %14, i32 %15)
%17 = getelementptr inbounds %struct.netent, %struct.netent* %0, i64 0, i32 2
%18 = load i8**, i8*** %17
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %30, label %21
21: ; preds = %1, %21
%22 = phi i64 [ %26, %21 ], [ 0, %1 ]
%23 = phi i8* [ %28, %21 ], [ %19, %1 ]
%24 = trunc i64 %22 to i32
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* %23)
%26 = add nuw i64 %22, 1
%27 = getelementptr inbounds i8*, i8** %18, i64 %26
%28 = load i8*, i8** %27
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %21
30: ; preds = %21, %1
%31 = call i32 @putchar(i32 10)
ret void
}