#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 servent {
  char *s_name;
  int s_port;
  char *s_proto;
  char **s_aliases;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void dump_serv(struct servent *h) {
  printf("server entry: \n"
         "  name: %s\n"
         "  port: %d\n"
         "  protocol: %s\n"
         "  aliases: \n",
         h->s_name, h->s_port, h->s_proto);
  int i = 0;
  char **ptr = h->s_aliases;
  while (ptr[i] != 0) {
    printf("    alias[%d]: %s\n", i, ptr[i]);
    i++;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dump_serv>:
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
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1191 <dump_serv+0x81>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1153 <dump_serv+0x43>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_serv>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rsi
mov    0x8(%rdi),%edx
mov    0x10(%rdi),%rcx
lea    0xec7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%r15
mov    (%r15),%rdx
test   %rdx,%rdx
je     117a <dump_serv+0x5a>
lea    0xeee(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
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_serv+0x40>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

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