#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 */

/* Variables and functions */
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int option_char;
  int portno = 8888;
  int maxnpending = 5;
  while ((option_char = getopt(argc, argv, "p:n:h")) != -1) {
    switch (option_char) {
    case 'p':
      portno = atoi(optarg);
      break;
    case 'n':
      maxnpending = atoi(optarg);
      break;
    case 'h':
      fprintf(stdout, "%s",
              "usage:\n"
              "  echoserver [options]\n"
              "options:\n"
              "  -p                  Port (Default: 8888)\n"
              "  -n                  Maximum pending connections\n"
              "  -h                  Show this help message\n");
      exit(0);
      break;
    default:
      fprintf(stderr, "%s",
              "usage:\n"
              "  echoserver [options]\n"
              "options:\n"
              "  -p                  Port (Default: 8888)\n"
              "  -n                  Maximum pending connections\n"
              "  -h                  Show this help message\n");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x22b8,-0x18(%rbp)
movl   $0x5,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1233 <main+0xf3>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x68,%eax
je     11e5 <main+0xa5>
jmp    1197 <main+0x57>
mov    -0x20(%rbp),%eax
sub    $0x6e,%eax
je     11cf <main+0x8f>
jmp    11a8 <main+0x68>
mov    -0x20(%rbp),%eax
sub    $0x70,%eax
jne    1208 <main+0xc8>
jmp    11b9 <main+0x79>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    122e <main+0xee>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    122e <main+0xee>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
lea    0xe0d(%rip),%rdx
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
lea    0xdea(%rip),%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1164 <main+0x24>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xead(%rip),%r14
mov    0x2e9e(%rip),%r15
jmp    116d <main+0x2d>
nopl   0x0(%rax)
cmp    $0x70,%eax
jne    11be <main+0x7e>
mov    (%r15),%edi
call   1050 <atoi@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <getopt@plt>
cmp    $0x6f,%eax
jg     1160 <main+0x20>
cmp    $0x6e,%eax
je     1165 <main+0x25>
cmp    $0xffffffff,%eax
jne    1196 <main+0x56>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x68,%eax
jne    11be <main+0x7e>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
lea    0xe57(%rip),%rdx
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
lea    0xe34(%rip),%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"p:n:h\00"
@optarg = global i32 0
@stdout = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [178 x i8] c"usage:\0A echoserver [options]\0Aoptions:\0A -p Port (Default: 8888)\0A -n Maximum pending connections\0A -h Show this help message\0A\00"
@stderr = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 8888, i32* %7
store i32 5, i32* %8
br label %9
9: ; preds = %30, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %6
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %31
14: ; preds = %9
%15 = load i32, i32* %6
switch i32 %15, label %26 [
i32 112, label %16
i32 110, label %19
i32 104, label %22
]
16: ; preds = %14
%17 = load i32, i32* @optarg
%18 = call i32 @atoi(i32 %17)
store i32 %18, i32* %7
br label %30
19: ; preds = %14
%20 = load i32, i32* @optarg
%21 = call i32 @atoi(i32 %20)
store i32 %21, i32* %8
br label %30
22: ; preds = %14
%23 = load i32, i32* @stdout
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([178 x i8], [178 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %14
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([178 x i8], [178 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %19, %16
br label %9
31: ; preds = %9
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [6 x i8] c"p:n:h\00"
@optarg = global i32 0
@stdout = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [178 x i8] c"usage:\0A echoserver [options]\0Aoptions:\0A -p Port (Default: 8888)\0A -n Maximum pending connections\0A -h Show this help message\0A\00"
@stderr = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %13, %2
%4 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %4, label %9 [
i32 -1, label %16
i32 112, label %13
i32 110, label %13
i32 104, label %5
]
5: ; preds = %3
%6 = load i32, i32* @stdout
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([178 x i8], [178 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([178 x i8], [178 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %3, %3
%14 = load i32, i32* @optarg
%15 = tail call i32 @atoi(i32 %14)
br label %3
16: ; preds = %3
ret i32 0
}