#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 *, char const *, ...);
void output_servent(const char *call, struct servent *sptr) {
  char **pptr;
  if (sptr == NULL)
    printf("Call: %s returned NULL\n", call);
  else {
    printf("Call: %s, returned: s_name: %s, s_port: %d, s_proto: %s\n", call,
           sptr->s_name, ntohs(sptr->s_port), sptr->s_proto);
    for (pptr = sptr->s_aliases; *pptr != NULL; pptr++)
      printf("  alias: %s\n", *pptr);
  }
}


x86 assembly (clang, -O0):
<output_servent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1152 <output_servent+0x32>
mov    -0x8(%rbp),%rsi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d6 <output_servent+0xb6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%edi
call   1040 <ntohs@plt>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11d1 <output_servent+0xb1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    119d <output_servent+0x7d>
jmp    11d6 <output_servent+0xb6>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_servent>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     118c <output_servent+0x6c>
mov    %rsi,%rbx
mov    (%rsi),%r15
mov    0x18(%rsi),%edi
call   1040 <ntohs@plt>
mov    0x8(%rbx),%r8
lea    0xed2(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rbx),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1186 <output_servent+0x66>
add    $0x8,%rbx
lea    0xee5(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1170 <output_servent+0x50>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe6d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.servent = type { i8*, i8*, i8**, i32 }
@.str = [24 x i8] c"Call: %s returned NULL\0A\00"
@.str.1 = [57 x i8] c"Call: %s, returned: s_name: %s, s_port: %d, s_proto: %s\0A\00"
@.str.2 = [13 x i8] c" alias: %s\0A\00"
define void @output_servent(i8* %0, %struct.servent* %1) {
%3 = alloca i8*
%4 = alloca %struct.servent*
%5 = alloca i8**
store i8* %0, i8** %3
store %struct.servent* %1, %struct.servent** %4
%6 = load %struct.servent*, %struct.servent** %4
%7 = icmp eq %struct.servent* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %39
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load %struct.servent*, %struct.servent** %4
%14 = getelementptr inbounds %struct.servent, %struct.servent* %13, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = load %struct.servent*, %struct.servent** %4
%17 = getelementptr inbounds %struct.servent, %struct.servent* %16, i32 0, i32 3
%18 = load i32, i32* %17
%19 = call i32 @ntohs(i32 %18)
%20 = load %struct.servent*, %struct.servent** %4
%21 = getelementptr inbounds %struct.servent, %struct.servent* %20, i32 0, i32 1
%22 = load i8*, i8** %21
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %15, i32 %19, i8* %22)
%24 = load %struct.servent*, %struct.servent** %4
%25 = getelementptr inbounds %struct.servent, %struct.servent* %24, i32 0, i32 2
%26 = load i8**, i8*** %25
store i8** %26, i8*** %5
br label %27
27: ; preds = %35, %11
%28 = load i8**, i8*** %5
%29 = load i8*, i8** %28
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %38
31: ; preds = %27
%32 = load i8**, i8*** %5
%33 = load i8*, i8** %32
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %31
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i32 1
store i8** %37, i8*** %5
br label %27
38: ; preds = %27
br label %39
39: ; preds = %38, %8
ret void
}

LLVM IR (-O2):
%struct.servent = type { i8*, i8*, i8**, i32 }
@.str = [24 x i8] c"Call: %s returned NULL\0A\00"
@.str.1 = [57 x i8] c"Call: %s, returned: s_name: %s, s_port: %d, s_proto: %s\0A\00"
@.str.2 = [13 x i8] c" alias: %s\0A\00"
define void @output_servent(i8* %0, %struct.servent* %1) {
%3 = icmp eq %struct.servent* %1, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %26
6: ; preds = %2
%7 = getelementptr inbounds %struct.servent, %struct.servent* %1, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = getelementptr inbounds %struct.servent, %struct.servent* %1, i64 0, i32 3
%10 = load i32, i32* %9
%11 = tail call i32 @ntohs(i32 %10)
%12 = getelementptr inbounds %struct.servent, %struct.servent* %1, i64 0, i32 1
%13 = load i8*, i8** %12
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %8, i32 %11, i8* %13)
%15 = getelementptr inbounds %struct.servent, %struct.servent* %1, i64 0, i32 2
%16 = load i8**, i8*** %15
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %26, label %19
19: ; preds = %6, %19
%20 = phi i8* [ %24, %19 ], [ %17, %6 ]
%21 = phi i8** [ %23, %19 ], [ %16, %6 ]
%22 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%23 = getelementptr inbounds i8*, i8** %21, i64 1
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %19
26: ; preds = %19, %6, %4
ret void
}