#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 protoent {
  char *p_name;
  int p_proto;
  char **p_aliases;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void dump_proto(struct protoent *h) {
  printf("protocol entry: \n"
         "  name: %s\n"
         "  proto: %d\n"
         "  aliases: \n",
         h->p_name, h->p_proto);
  int i = 0;
  char **ptr = h->p_aliases;
  while (ptr[i] != 0) {
    printf("    alias[%d]: %s\n", i, ptr[i]);
    i++;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dump_proto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <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     1189 <dump_proto+0x79>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <dump_proto+0x3b>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_proto>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rsi
mov    0x8(%rdi),%edx
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%r15
mov    (%r15),%rdx
test   %rdx,%rdx
je     117a <dump_proto+0x5a>
lea    0xee6(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r15,%rbx,8),%rdx
add    $0x1,%rbx
test   %rdx,%rdx
jne    1160 <dump_proto+0x40>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
%struct.protoent = type { i8*, i32, i8** }
@.str = [53 x i8] c"protocol entry: \0A name: %s\0A proto: %d\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_proto(%struct.protoent* %0) {
%2 = alloca %struct.protoent*
%3 = alloca i32
%4 = alloca i8**
store %struct.protoent* %0, %struct.protoent** %2
%5 = load %struct.protoent*, %struct.protoent** %2
%6 = getelementptr inbounds %struct.protoent, %struct.protoent* %5, i32 0, i32 0
%7 = load i8*, i8** %6
%8 = load %struct.protoent*, %struct.protoent** %2
%9 = getelementptr inbounds %struct.protoent, %struct.protoent* %8, i32 0, i32 1
%10 = load i32, i32* %9
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %10)
store i32 0, i32* %3
%12 = load %struct.protoent*, %struct.protoent** %2
%13 = getelementptr inbounds %struct.protoent, %struct.protoent* %12, i32 0, i32 2
%14 = load i8**, i8*** %13
store i8** %14, i8*** %4
br label %15
15: ; preds = %22, %1
%16 = load i8**, i8*** %4
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %32
22: ; preds = %15
%23 = load i32, i32* %3
%24 = load i8**, i8*** %4
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %23, i8* %28)
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %15
32: ; preds = %15
%33 = 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.protoent = type { i8*, i32, i8** }
@.str = [53 x i8] c"protocol entry: \0A name: %s\0A proto: %d\0A aliases: \0A\00"
@.str.1 = [19 x i8] c" alias[%d]: %s\0A\00"
define void @dump_proto(%struct.protoent* nocapture %0) {
%2 = getelementptr inbounds %struct.protoent, %struct.protoent* %0, i64 0, i32 0
%3 = load i8*, i8** %2
%4 = getelementptr inbounds %struct.protoent, %struct.protoent* %0, i64 0, i32 1
%5 = load i32, i32* %4
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %5)
%7 = getelementptr inbounds %struct.protoent, %struct.protoent* %0, i64 0, i32 2
%8 = load i8**, i8*** %7
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %20, label %11
11: ; preds = %1, %11
%12 = phi i64 [ %16, %11 ], [ 0, %1 ]
%13 = phi i8* [ %18, %11 ], [ %9, %1 ]
%14 = trunc i64 %12 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %14, i8* %13)
%16 = add nuw i64 %12, 1
%17 = getelementptr inbounds i8*, i8** %8, i64 %16
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %11
20: ; preds = %11, %1
%21 = tail call i32 @putchar(i32 10)
ret void
}