#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 */
typedef int /*<<< orphan*/ uint16_t;
struct servent {
  char *s_name;
  char *s_proto;
  char **s_aliases;
  scalar_t__ s_port;
};

/* Variables and functions */
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void pserv(const struct servent *svp) {
  char **pp;
  printf("name=%s, port=%d, proto=%s, aliases=", svp->s_name,
         ntohs((uint16_t)svp->s_port), svp->s_proto);
  for (pp = svp->s_aliases; *pp; pp++)
    printf("%s ", *pp);
  printf("\n");
}


x86 assembly (clang, -O0):
<pserv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rax
mov    %eax,%edi
call   1040 <ntohs@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11a2 <pserv+0x82>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    116e <pserv+0x4e>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pserv>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%r14
mov    0x18(%rdi),%edi
call   1050 <ntohs@plt>
mov    0x8(%rbx),%rcx
lea    0xeb3(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1186 <pserv+0x56>
add    $0x8,%rbx
lea    0xeb5(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1170 <pserv+0x40>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>

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