#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 *getservbyport(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(int argc, char *argv[]) {
  struct servent *se;
  if ((se = getservbyport(htons(80), "tcp"))) {
    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    $0x50,%edi
call   1030 <htons@plt>
mov    %eax,%edi
lea    0xe97(%rip),%rsi
call   1060 <getservbyport@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     120d <main+0xcd>
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    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    1208 <main+0xc8>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11dc <main+0x9c>
jmp    1208 <main+0xc8>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b6 <main+0x76>
jmp    120d <main+0xcd>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x50,%edi
call   1030 <htons@plt>
lea    0xeab(%rip),%rsi
mov    %eax,%edi
call   1060 <getservbyport@plt>
test   %rax,%rax
je     1365 <main+0x225>
mov    %rax,%r14
mov    (%rax),%rbx
mov    0x18(%rax),%edi
call   1050 <ntohs@plt>
mov    0x8(%r14),%rcx
lea    0xe86(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x8(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x10(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x18(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x20(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xe01(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x28(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xde2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x30(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xdc3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x38(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xda4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x40(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xd85(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x48(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xd66(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x50(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xd47(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x58(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xd2c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x60(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xd11(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x68(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xcf6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x70(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xcdb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%rax
mov    0x78(%rax),%rsi
test   %rsi,%rsi
je     1365 <main+0x225>
lea    0xcc0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.servent = type { i8*, i8*, i8**, i32 }
@.str = [4 x i8] c"tcp\00"
@.str.1 = [26 x i8] c"name %s\09port %d\09proto %s\0A\00"
@.str.2 = [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
%8 = call i32 @htons(i32 80)
%9 = call %struct.servent* @getservbyport(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store %struct.servent* %9, %struct.servent** %6
%10 = icmp ne %struct.servent* %9, null
br i1 %10, label %11, label %49
11: ; preds = %2
%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.1, 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.2, 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 %49
49: ; preds = %48, %2
ret i32 0
}

LLVM IR (-O2):
%struct.servent = type { i8*, i8*, i8**, i32 }
@.str = [4 x i8] c"tcp\00"
@.str.1 = [26 x i8] c"name %s\09port %d\09proto %s\0A\00"
@.str.2 = [12 x i8] c" alias %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @htons(i32 80)
%4 = tail call %struct.servent* @getservbyport(i32 %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq %struct.servent* %4, null
br i1 %5, label %111, label %6
6: ; preds = %2
%7 = getelementptr inbounds %struct.servent, %struct.servent* %4, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = getelementptr inbounds %struct.servent, %struct.servent* %4, i64 0, i32 3
%10 = load i32, i32* %9
%11 = tail call i32 @ntohs(i32 %10)
%12 = getelementptr inbounds %struct.servent, %struct.servent* %4, 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.1, i64 0, i64 0), i8* %8, i32 %11, i8* %13)
%15 = getelementptr inbounds %struct.servent, %struct.servent* %4, 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 = %6
%20 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, 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.2, 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.2, 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.2, 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.2, 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.2, 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.2, 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.2, 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.2, 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.2, 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.2, 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.2, 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.2, 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.2, 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.2, 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.2, i64 0, i64 0), i8* %107)
br label %111
111: ; preds = %6, %19, %25, %31, %37, %43, %49, %55, %61, %67, %73, %79, %85, %91, %97, %103, %109, %2
ret i32 0
}