#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;
  char *s_proto;
  char **s_aliases;
  int /*<<< orphan*/ s_port;
};

/* Variables and functions */
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void printit(struct servent *s) {
  int j;
  char **tmp;
  printf("name = %15s,    port = %5d,    proto = %4s\n", s->s_name,
         ntohs(s->s_port), s->s_proto);
  if (*s->s_aliases) {
    for (j = 0, tmp = s->s_aliases; *tmp != NULL; j++, tmp++)
      printf("  aliases[%d] = %s ", j, *tmp);
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<printit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%edi
call   1040 <ntohs@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
cmpq   $0x0,(%rax)
je     11d2 <printit+0xb2>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11c4 <printit+0xa4>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    1184 <printit+0x64>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printit>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%r14
mov    0x18(%rdi),%edi
call   1050 <ntohs@plt>
mov    0x8(%rbx),%rcx
lea    0xeb2(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%r15
mov    (%r15),%rdx
test   %rdx,%rdx
je     1199 <printit+0x69>
lea    0xebf(%rip),%r14
xor    %ebx,%ebx
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    1170 <printit+0x40>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.servent = type { i8*, i8*, i8**, i32 }
@.str = [44 x i8] c"name = %15s, port = %5d, proto = %4s\0A\00"
@.str.1 = [20 x i8] c" aliases[%d] = %s \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @printit(%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 3
%10 = load i32, i32* %9
%11 = call i32 @ntohs(i32 %10)
%12 = load %struct.servent*, %struct.servent** %2
%13 = getelementptr inbounds %struct.servent, %struct.servent* %12, i32 0, i32 1
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %11, i8* %14)
%16 = load %struct.servent*, %struct.servent** %2
%17 = getelementptr inbounds %struct.servent, %struct.servent* %16, i32 0, i32 2
%18 = load i8**, i8*** %17
%19 = load i8*, i8** %18
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %41
21: ; preds = %1
store i32 0, i32* %3
%22 = load %struct.servent*, %struct.servent** %2
%23 = getelementptr inbounds %struct.servent, %struct.servent* %22, i32 0, i32 2
%24 = load i8**, i8*** %23
store i8** %24, i8*** %4
br label %25
25: ; preds = %34, %21
%26 = load i8**, i8*** %4
%27 = load i8*, i8** %26
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %39
29: ; preds = %25
%30 = load i32, i32* %3
%31 = load i8**, i8*** %4
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %30, i8* %32)
br label %34
34: ; preds = %29
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
%37 = load i8**, i8*** %4
%38 = getelementptr inbounds i8*, i8** %37, i32 1
store i8** %38, i8*** %4
br label %25
39: ; preds = %25
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %1
ret void
}

LLVM IR (-O2):
%struct.servent = type { i8*, i8*, i8**, i32 }
@.str = [44 x i8] c"name = %15s, port = %5d, proto = %4s\0A\00"
@.str.1 = [20 x i8] c" aliases[%d] = %s \00"
define void @printit(%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 3
%5 = load i32, i32* %4
%6 = tail call i32 @ntohs(i32 %5)
%7 = getelementptr inbounds %struct.servent, %struct.servent* %0, i64 0, i32 1
%8 = load i8*, i8** %7
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %6, i8* %8)
%10 = getelementptr inbounds %struct.servent, %struct.servent* %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 %25, label %14
14: ; preds = %1, %14
%15 = phi i8** [ %20, %14 ], [ %11, %1 ]
%16 = phi i32 [ %19, %14 ], [ 0, %1 ]
%17 = phi i8* [ %21, %14 ], [ %12, %1 ]
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %17)
%19 = add nuw nsw i32 %16, 1
%20 = getelementptr inbounds i8*, i8** %15, i64 1
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %14
23: ; preds = %14
%24 = tail call i32 @putchar(i32 10)
br label %25
25: ; preds = %23, %1
ret void
}