#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 */
struct servent *getservent();
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(int argc, char *argv[]) {
  struct servent *se;
  while ((se = getservent())) {
    int i;
    printf("name %s\tport %d\tproto %s\n", se->s_name, ntohs(se->s_port),
           se->s_proto);
    for (i = 0; i < 16; ++i) {
      if (!se->s_aliases[i])
        break;
      printf("  alias %s\n", se->s_aliases[i]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getservent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ec <main+0xbc>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%edi
call   1050 <ntohs@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    11e7 <main+0xb7>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11bb <main+0x8b>
jmp    11e7 <main+0xb7>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1195 <main+0x65>
jmp    1146 <main+0x16>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getservent@plt>
test   %rax,%rax
je     134d <main+0x21d>
mov    %rax,%r12
lea    0xeae(%rip),%r14
lea    0xec1(%rip),%r15
jmp    1173 <main+0x43>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getservent@plt>
mov    %rax,%r12
test   %rax,%rax
je     134d <main+0x21d>
mov    (%r12),%rbx
mov    0x18(%r12),%edi
call   1050 <ntohs@plt>
mov    0x8(%r12),%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x8(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x10(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x18(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x20(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x28(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x30(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x38(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x40(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x48(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x50(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x58(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x60(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x68(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x70(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%rax
mov    0x78(%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.servent = type { i8*, i8*, i8**, i32 }
@.str = [26 x i8] c"name %s\09port %d\09proto %s\0A\00"
@.str.1 = [12 x i8] c" alias %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.servent*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %48, %2
%9 = call %struct.servent* (...) @getservent()
store %struct.servent* %9, %struct.servent** %6
%10 = icmp ne %struct.servent* %9, null
br i1 %10, label %11, label %49
11: ; preds = %8
%12 = load %struct.servent*, %struct.servent** %6
%13 = getelementptr inbounds %struct.servent, %struct.servent* %12, i32 0, i32 0
%14 = load i8*, i8** %13
%15 = load %struct.servent*, %struct.servent** %6
%16 = getelementptr inbounds %struct.servent, %struct.servent* %15, i32 0, i32 3
%17 = load i32, i32* %16
%18 = call i32 @ntohs(i32 %17)
%19 = load %struct.servent*, %struct.servent** %6
%20 = getelementptr inbounds %struct.servent, %struct.servent* %19, i32 0, i32 1
%21 = load i8*, i8** %20
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %18, i8* %21)
store i32 0, i32* %7
br label %23
23: ; preds = %45, %11
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 16
br i1 %25, label %26, label %48
26: ; preds = %23
%27 = load %struct.servent*, %struct.servent** %6
%28 = getelementptr inbounds %struct.servent, %struct.servent* %27, i32 0, i32 2
%29 = load i8**, i8*** %28
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = icmp ne i8* %33, null
br i1 %34, label %36, label %35
35: ; preds = %26
br label %48
36: ; preds = %26
%37 = load %struct.servent*, %struct.servent** %6
%38 = getelementptr inbounds %struct.servent, %struct.servent* %37, i32 0, i32 2
%39 = load i8**, i8*** %38
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %36
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %23
48: ; preds = %35, %23
br label %8
49: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
%struct.servent = type { i8*, i8*, i8**, i32 }
@.str = [26 x i8] c"name %s\09port %d\09proto %s\0A\00"
@.str.1 = [12 x i8] c" alias %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call %struct.servent* (...) @getservent()
%4 = icmp eq %struct.servent* %3, null
br i1 %4, label %114, label %5
5: ; preds = %2, %111
%6 = phi %struct.servent* [ %112, %111 ], [ %3, %2 ]
%7 = getelementptr inbounds %struct.servent, %struct.servent* %6, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = getelementptr inbounds %struct.servent, %struct.servent* %6, i64 0, i32 3
%10 = load i32, i32* %9
%11 = tail call i32 @ntohs(i32 %10)
%12 = getelementptr inbounds %struct.servent, %struct.servent* %6, i64 0, i32 1
%13 = load i8*, i8** %12
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %11, i8* %13)
%15 = getelementptr inbounds %struct.servent, %struct.servent* %6, i64 0, i32 2
%16 = load i8**, i8*** %15
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %111, label %19
19: ; preds = %5
%20 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%21 = load i8**, i8*** %15
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %111, label %25
25: ; preds = %19
%26 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%27 = load i8**, i8*** %15
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %111, label %31
31: ; preds = %25
%32 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%33 = load i8**, i8*** %15
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = icmp eq i8* %35, null
br i1 %36, label %111, label %37
37: ; preds = %31
%38 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%39 = load i8**, i8*** %15
%40 = getelementptr inbounds i8*, i8** %39, i64 4
%41 = load i8*, i8** %40
%42 = icmp eq i8* %41, null
br i1 %42, label %111, label %43
43: ; preds = %37
%44 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%45 = load i8**, i8*** %15
%46 = getelementptr inbounds i8*, i8** %45, i64 5
%47 = load i8*, i8** %46
%48 = icmp eq i8* %47, null
br i1 %48, label %111, label %49
49: ; preds = %43
%50 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %47)
%51 = load i8**, i8*** %15
%52 = getelementptr inbounds i8*, i8** %51, i64 6
%53 = load i8*, i8** %52
%54 = icmp eq i8* %53, null
br i1 %54, label %111, label %55
55: ; preds = %49
%56 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%57 = load i8**, i8*** %15
%58 = getelementptr inbounds i8*, i8** %57, i64 7
%59 = load i8*, i8** %58
%60 = icmp eq i8* %59, null
br i1 %60, label %111, label %61
61: ; preds = %55
%62 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %59)
%63 = load i8**, i8*** %15
%64 = getelementptr inbounds i8*, i8** %63, i64 8
%65 = load i8*, i8** %64
%66 = icmp eq i8* %65, null
br i1 %66, label %111, label %67
67: ; preds = %61
%68 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %65)
%69 = load i8**, i8*** %15
%70 = getelementptr inbounds i8*, i8** %69, i64 9
%71 = load i8*, i8** %70
%72 = icmp eq i8* %71, null
br i1 %72, label %111, label %73
73: ; preds = %67
%74 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %71)
%75 = load i8**, i8*** %15
%76 = getelementptr inbounds i8*, i8** %75, i64 10
%77 = load i8*, i8** %76
%78 = icmp eq i8* %77, null
br i1 %78, label %111, label %79
79: ; preds = %73
%80 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %77)
%81 = load i8**, i8*** %15
%82 = getelementptr inbounds i8*, i8** %81, i64 11
%83 = load i8*, i8** %82
%84 = icmp eq i8* %83, null
br i1 %84, label %111, label %85
85: ; preds = %79
%86 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %83)
%87 = load i8**, i8*** %15
%88 = getelementptr inbounds i8*, i8** %87, i64 12
%89 = load i8*, i8** %88
%90 = icmp eq i8* %89, null
br i1 %90, label %111, label %91
91: ; preds = %85
%92 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %89)
%93 = load i8**, i8*** %15
%94 = getelementptr inbounds i8*, i8** %93, i64 13
%95 = load i8*, i8** %94
%96 = icmp eq i8* %95, null
br i1 %96, label %111, label %97
97: ; preds = %91
%98 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %95)
%99 = load i8**, i8*** %15
%100 = getelementptr inbounds i8*, i8** %99, i64 14
%101 = load i8*, i8** %100
%102 = icmp eq i8* %101, null
br i1 %102, label %111, label %103
103: ; preds = %97
%104 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %101)
%105 = load i8**, i8*** %15
%106 = getelementptr inbounds i8*, i8** %105, i64 15
%107 = load i8*, i8** %106
%108 = icmp eq i8* %107, null
br i1 %108, label %111, label %109
109: ; preds = %103
%110 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %107)
br label %111
111: ; preds = %109, %103, %97, %91, %85, %79, %73, %67, %61, %55, %49, %43, %37, %31, %25, %19, %5
%112 = tail call %struct.servent* (...) @getservent()
%113 = icmp eq %struct.servent* %112, null
br i1 %113, label %114, label %5
114: ; preds = %111, %2
ret i32 0
}