#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 {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ atoi(char const *);
int /*<<< orphan*/ endservent();
int getopt(int, char **, char *);
struct servent *getservbyname(char const *, char const *);
struct servent *getservbyport(int /*<<< orphan*/, char const *);
struct servent *getservent();
int /*<<< orphan*/ htons(int /*<<< orphan*/);
char *optarg;
int /*<<< orphan*/ pserv(struct servent *);
int /*<<< orphan*/ setservent(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  struct servent *svp;
  const char *port = NULL, *proto = NULL, *name = NULL;
  int c;
  while ((c = getopt(argc, argv, "p:n:P:")) != -1) {
    switch (c) {
    case 'n':
      name = optarg;
      break;
    case 'p':
      port = optarg;
      break;
    case 'P':
      proto = optarg;
      break;
    default:
      usage();
    }
  }
  if (port && name)
    usage();
  if (port) {
    if ((svp = getservbyport(htons(atoi(port)), proto)) != NULL)
      pserv(svp);
    return 0;
  }
  if (name) {
    if ((svp = getservbyname(name, proto)) != NULL)
      pserv(svp);
    return 0;
  }
  setservent(0);
  while ((svp = getservent()) != NULL)
    pserv(svp);
  endservent();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe24(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     1268 <main+0xc8>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x50,%eax
je     1249 <main+0xa9>
jmp    1201 <main+0x61>
mov    -0x38(%rbp),%eax
sub    $0x6e,%eax
je     1223 <main+0x83>
jmp    1212 <main+0x72>
mov    -0x38(%rbp),%eax
sub    $0x70,%eax
je     1236 <main+0x96>
jmp    125c <main+0xbc>
mov    0x2dce(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1263 <main+0xc3>
mov    0x2dbb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1263 <main+0xc3>
mov    0x2da8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1263 <main+0xc3>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    11ce <main+0x2e>
cmpq   $0x0,-0x20(%rbp)
je     1285 <main+0xe5>
cmpq   $0x0,-0x30(%rbp)
je     1285 <main+0xe5>
mov    $0x0,%al
call   1080 <usage@plt>
cmpq   $0x0,-0x20(%rbp)
je     12ce <main+0x12e>
mov    -0x20(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,%edi
mov    -0x28(%rbp),%rsi
call   10c0 <getservbyport@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12c2 <main+0x122>
mov    -0x18(%rbp),%rdi
call   1070 <pserv@plt>
movl   $0x0,-0x4(%rbp)
jmp    1341 <main+0x1a1>
cmpq   $0x0,-0x30(%rbp)
je     1309 <main+0x169>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <getservbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12fd <main+0x15d>
mov    -0x18(%rbp),%rdi
call   1070 <pserv@plt>
movl   $0x0,-0x4(%rbp)
jmp    1341 <main+0x1a1>
xor    %edi,%edi
call   1060 <setservent@plt>
mov    $0x0,%al
call   1030 <getservent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1333 <main+0x193>
mov    -0x18(%rbp),%rdi
call   1070 <pserv@plt>
jmp    1310 <main+0x170>
mov    $0x0,%al
call   10b0 <endservent@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe49(%rip),%r13
xor    %r12d,%r12d
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    11d7 <main+0x37>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1090 <getopt@plt>
cmp    $0x6d,%eax
jg     1200 <main+0x60>
cmp    $0xffffffff,%eax
je     1222 <main+0x82>
cmp    $0x50,%eax
jne    11d0 <main+0x30>
mov    0x2dfe(%rip),%rax
mov    (%rax),%r14
jmp    11d7 <main+0x37>
nop
cmp    $0x70,%eax
je     1216 <main+0x76>
cmp    $0x6e,%eax
jne    11d0 <main+0x30>
mov    0x2de7(%rip),%rax
mov    (%rax),%r15
jmp    11d7 <main+0x37>
mov    0x2ddb(%rip),%rax
mov    (%rax),%r12
jmp    11d7 <main+0x37>
test   %r12,%r12
je     1233 <main+0x93>
test   %r15,%r15
je     1233 <main+0x93>
xor    %eax,%eax
call   1080 <usage@plt>
test   %r12,%r12
je     1258 <main+0xb8>
mov    %r12,%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   10c0 <getservbyport@plt>
test   %rax,%rax
jne    126d <main+0xcd>
jmp    129d <main+0xfd>
test   %r15,%r15
je     1277 <main+0xd7>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <getservbyname@plt>
test   %rax,%rax
je     129d <main+0xfd>
mov    %rax,%rdi
call   1070 <pserv@plt>
jmp    129d <main+0xfd>
xor    %edi,%edi
call   1060 <setservent@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <getservent@plt>
test   %rax,%rax
je     1296 <main+0xf6>
mov    %rax,%rdi
call   1070 <pserv@plt>
jmp    1280 <main+0xe0>
xor    %eax,%eax
call   10b0 <endservent@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.servent = type { i32 }
@.str = [7 x i8] c"p:n:P:\00"
@optarg = global i8* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.servent*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
br label %11
11: ; preds = %26, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %10
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %27
16: ; preds = %11
%17 = load i32, i32* %10
switch i32 %17, label %24 [
i32 110, label %18
i32 112, label %20
i32 80, label %22
]
18: ; preds = %16
%19 = load i8*, i8** @optarg
store i8* %19, i8** %9
br label %26
20: ; preds = %16
%21 = load i8*, i8** @optarg
store i8* %21, i8** %7
br label %26
22: ; preds = %16
%23 = load i8*, i8** @optarg
store i8* %23, i8** %8
br label %26
24: ; preds = %16
%25 = call i32 (...) @usage()
br label %26
26: ; preds = %24, %22, %20, %18
br label %11
27: ; preds = %11
%28 = load i8*, i8** %7
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i8*, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 (...) @usage()
br label %35
35: ; preds = %33, %30, %27
%36 = load i8*, i8** %7
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %49
38: ; preds = %35
%39 = load i8*, i8** %7
%40 = call i32 @atoi(i8* %39)
%41 = call i32 @htons(i32 %40)
%42 = load i8*, i8** %8
%43 = call %struct.servent* @getservbyport(i32 %41, i8* %42)
store %struct.servent* %43, %struct.servent** %6
%44 = icmp ne %struct.servent* %43, null
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = load %struct.servent*, %struct.servent** %6
%47 = call i32 @pserv(%struct.servent* %46)
br label %48
48: ; preds = %45, %38
store i32 0, i32* %3
br label %71
49: ; preds = %35
%50 = load i8*, i8** %9
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %61
52: ; preds = %49
%53 = load i8*, i8** %9
%54 = load i8*, i8** %8
%55 = call %struct.servent* @getservbyname(i8* %53, i8* %54)
store %struct.servent* %55, %struct.servent** %6
%56 = icmp ne %struct.servent* %55, null
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = load %struct.servent*, %struct.servent** %6
%59 = call i32 @pserv(%struct.servent* %58)
br label %60
60: ; preds = %57, %52
store i32 0, i32* %3
br label %71
61: ; preds = %49
%62 = call i32 @setservent(i32 0)
br label %63
63: ; preds = %66, %61
%64 = call %struct.servent* (...) @getservent()
store %struct.servent* %64, %struct.servent** %6
%65 = icmp ne %struct.servent* %64, null
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = load %struct.servent*, %struct.servent** %6
%68 = call i32 @pserv(%struct.servent* %67)
br label %63
69: ; preds = %63
%70 = call i32 (...) @endservent()
store i32 0, i32* %3
br label %71
71: ; preds = %69, %60, %48
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
%struct.servent = type { i32 }
@.str = [7 x i8] c"p:n:P:\00"
@optarg = global i8* null
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %16, %2
%4 = phi i8* [ %17, %16 ], [ null, %2 ]
%5 = phi i8* [ %8, %16 ], [ null, %2 ]
%6 = phi i8* [ %11, %16 ], [ null, %2 ]
br label %7
7: ; preds = %3, %18
%8 = phi i8* [ %5, %3 ], [ %19, %18 ]
%9 = phi i8* [ %6, %3 ], [ %11, %18 ]
br label %10
10: ; preds = %7, %14
%11 = phi i8* [ %9, %7 ], [ %15, %14 ]
br label %12
12: ; preds = %10, %20
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %13, label %20 [
i32 -1, label %22
i32 110, label %14
i32 112, label %16
i32 80, label %18
]
14: ; preds = %12
%15 = load i8*, i8** @optarg
br label %10
16: ; preds = %12
%17 = load i8*, i8** @optarg
br label %3
18: ; preds = %12
%19 = load i8*, i8** @optarg
br label %7
20: ; preds = %12
%21 = tail call i32 (...) @usage()
br label %12
22: ; preds = %12
%23 = icmp ne i8* %4, null
%24 = icmp ne i8* %11, null
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = tail call i32 (...) @usage()
br label %28
28: ; preds = %26, %22
br i1 %23, label %29, label %36
29: ; preds = %28
%30 = tail call i32 @atoi(i8* %4)
%31 = tail call i32 @htons(i32 %30)
%32 = tail call %struct.servent* @getservbyport(i32 %31, i8* %8)
%33 = icmp eq %struct.servent* %32, null
br i1 %33, label %53, label %34
34: ; preds = %29
%35 = tail call i32 @pserv(%struct.servent* %32)
br label %53
36: ; preds = %28
br i1 %24, label %37, label %42
37: ; preds = %36
%38 = tail call %struct.servent* @getservbyname(i8* %11, i8* %8)
%39 = icmp eq %struct.servent* %38, null
br i1 %39, label %53, label %40
40: ; preds = %37
%41 = tail call i32 @pserv(%struct.servent* %38)
br label %53
42: ; preds = %36
%43 = tail call i32 @setservent(i32 0)
%44 = tail call %struct.servent* (...) @getservent()
%45 = icmp eq %struct.servent* %44, null
br i1 %45, label %51, label %46
46: ; preds = %42, %46
%47 = phi %struct.servent* [ %49, %46 ], [ %44, %42 ]
%48 = tail call i32 @pserv(%struct.servent* %47)
%49 = tail call %struct.servent* (...) @getservent()
%50 = icmp eq %struct.servent* %49, null
br i1 %50, label %51, label %46
51: ; preds = %46, %42
%52 = tail call i32 (...) @endservent()
br label %53
53: ; preds = %37, %40, %29, %34, %51
ret i32 0
}