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

/* Variables and functions */
int /*<<< orphan*/ atoi(char const *);
int /*<<< orphan*/ endprotoent();
int getopt(int, char **, char *);
struct protoent *getprotobyname(char const *);
struct protoent *getprotobynumber(int /*<<< orphan*/);
struct protoent *getprotoent();
char *optarg;
int /*<<< orphan*/ pserv(struct protoent *);
int /*<<< orphan*/ setprotoent(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  struct protoent *prp;
  const char *proto = NULL, *name = NULL;
  int c;
  while ((c = getopt(argc, argv, "p:n:")) != -1) {
    switch (c) {
    case 'n':
      name = optarg;
      break;
    case 'p':
      proto = optarg;
      break;
    default:
      usage();
    }
  }
  if (proto && name)
    usage();
  if (proto) {
    if ((prp = getprotobynumber(atoi(proto))) != NULL)
      pserv(prp);
    return 0;
  }
  if (name) {
    if ((prp = getprotobyname(name)) != NULL)
      pserv(prp);
    return 0;
  }
  setprotoent(0);
  while ((prp = getprotoent()) != NULL)
    pserv(prp);
  endprotoent();
  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)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe3c(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     122c <main+0x9c>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x6e,%eax
je     11fa <main+0x6a>
jmp    11e9 <main+0x59>
mov    -0x30(%rbp),%eax
sub    $0x70,%eax
je     120d <main+0x7d>
jmp    1220 <main+0x90>
mov    0x2df7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1227 <main+0x97>
mov    0x2de4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1227 <main+0x97>
mov    $0x0,%al
call   1090 <usage@plt>
jmp    11b6 <main+0x26>
cmpq   $0x0,-0x20(%rbp)
je     1249 <main+0xb9>
cmpq   $0x0,-0x28(%rbp)
je     1249 <main+0xb9>
mov    $0x0,%al
call   1090 <usage@plt>
cmpq   $0x0,-0x20(%rbp)
je     1287 <main+0xf7>
mov    -0x20(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1070 <getprotobynumber@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     127b <main+0xeb>
mov    -0x18(%rbp),%rdi
call   1060 <pserv@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f6 <main+0x166>
cmpq   $0x0,-0x28(%rbp)
je     12be <main+0x12e>
mov    -0x28(%rbp),%rdi
call   1080 <getprotobyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12b2 <main+0x122>
mov    -0x18(%rbp),%rdi
call   1060 <pserv@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f6 <main+0x166>
xor    %edi,%edi
call   1050 <setprotoent@plt>
mov    $0x0,%al
call   1040 <getprotoent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12e8 <main+0x158>
mov    -0x18(%rbp),%rdi
call   1060 <pserv@plt>
jmp    12c5 <main+0x135>
mov    $0x0,%al
call   1030 <endprotoent@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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    0xe59(%rip),%r12
mov    0x2e4a(%rip),%r13
xor    %r15d,%r15d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10a0 <getopt@plt>
cmp    $0xffffffff,%eax
je     11f1 <main+0x61>
cmp    $0x70,%eax
je     11e5 <main+0x55>
cmp    $0x6e,%eax
je     11eb <main+0x5b>
xor    %eax,%eax
call   1090 <usage@plt>
jmp    11c0 <main+0x30>
mov    0x0(%r13),%r15
jmp    11c0 <main+0x30>
mov    0x0(%r13),%r14
jmp    11c0 <main+0x30>
test   %r15,%r15
je     1202 <main+0x72>
test   %r14,%r14
je     1202 <main+0x72>
xor    %eax,%eax
call   1090 <usage@plt>
test   %r15,%r15
je     121d <main+0x8d>
mov    %r15,%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1070 <getprotobynumber@plt>
test   %rax,%rax
jne    122f <main+0x9f>
jmp    125d <main+0xcd>
test   %r14,%r14
je     1239 <main+0xa9>
mov    %r14,%rdi
call   1080 <getprotobyname@plt>
test   %rax,%rax
je     125d <main+0xcd>
mov    %rax,%rdi
call   1060 <pserv@plt>
jmp    125d <main+0xcd>
xor    %edi,%edi
call   1050 <setprotoent@plt>
xor    %eax,%eax
call   1040 <getprotoent@plt>
test   %rax,%rax
je     1256 <main+0xc6>
mov    %rax,%rdi
call   1060 <pserv@plt>
jmp    1240 <main+0xb0>
xor    %eax,%eax
call   1030 <endprotoent@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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