#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(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ serve(int);
int /*<<< orphan*/ stderr;
main(int argc, char **argv) {
  extern char *optarg;
  extern int optind;
  int c, err = 0;
  int port = 21234;
  static char usage[] = "usage: %s [-d] [-p port]\n";
  while ((c = getopt(argc, argv, "dp:")) != -1)
    switch (c) {
    case 'p':
      port = atoi(optarg);
      if (port < 1024 || port > 65535) {
        fprintf(stderr, "invalid port number: %s\n", optarg);
        err = 1;
      }
      break;
    case '?':
      err = 1;
      break;
    }
  if (err || (optind < argc)) {
    fprintf(stderr, usage, argv[0]);
    exit(1);
  }
  serve(port);
}


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   $0x0,-0x18(%rbp)
movl   $0x52f2,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     121b <main+0xcb>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x3f,%eax
je     120f <main+0xbf>
jmp    11a7 <main+0x57>
mov    -0x20(%rbp),%eax
sub    $0x70,%eax
jne    1216 <main+0xc6>
jmp    11b8 <main+0x68>
mov    0x2e21(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x400,-0x1c(%rbp)
jl     11e4 <main+0x94>
cmpl   $0xffff,-0x1c(%rbp)
jle    120a <main+0xba>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%rdx
lea    0xe06(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x18(%rbp)
jmp    1216 <main+0xc6>
movl   $0x1,-0x18(%rbp)
jmp    1174 <main+0x24>
cmpl   $0x0,-0x18(%rbp)
jne    1237 <main+0xe7>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    125d <main+0x10d>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x2e02(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1030 <serve@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%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
mov    $0x52f2,%r14d
xor    %r12d,%r12d
lea    0xe90(%rip),%r15
jmp    1190 <main+0x40>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %r13,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%r12b
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <getopt@plt>
cmp    $0xffffffff,%eax
je     11cf <main+0x7f>
cmp    $0x3f,%eax
je     118a <main+0x3a>
cmp    $0x70,%eax
jne    1190 <main+0x40>
mov    0x2e2d(%rip),%rax
mov    (%rax),%r13
mov    %r13,%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
add    $0xffff0000,%eax
cmp    $0xffff03ff,%eax
ja     1190 <main+0x40>
jmp    1172 <main+0x22>
mov    0x2dfa(%rip),%rax
cmp    %ebp,(%rax)
setl   %al
or     %al,%r12b
test   $0x1,%r12b
jne    11fd <main+0xad>
mov    %r14d,%edi
call   1030 <serve@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0x2e40(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@main.usage = internal global [26 x i8] c"usage: %s [-d] [-p port]\0A\00"
@.str = [4 x i8] c"dp:\00"
@optarg = external global i8*
@stderr = global i32 0
@.str.1 = [25 x i8] c"invalid port number: %s\0A\00"
@optind = external global i32
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 0, i32* %7
store i32 21234, 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 ([4 x i8], [4 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 %30 [
i32 112, label %16
i32 63, label %29
]
16: ; preds = %14
%17 = load i8*, i8** @optarg
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 1024
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, 65535
br i1 %23, label %24, label %28
24: ; preds = %21, %16
%25 = load i32, i32* @stderr
%26 = load i8*, i8** @optarg
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 1, i32* %7
br label %28
28: ; preds = %24, %21
br label %30
29: ; preds = %14
store i32 1, i32* %7
br label %30
30: ; preds = %14, %29, %28
br label %9
31: ; preds = %9
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = load i32, i32* @optind
%36 = load i32, i32* %4
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %45
38: ; preds = %34, %31
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @main.usage, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %34
%46 = load i32, i32* %8
%47 = call i32 @serve(i32 %46)
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@main.usage = internal global [26 x i8] c"usage: %s [-d] [-p port]\0A\00"
@.str = [4 x i8] c"dp:\00"
@optarg = external global i8*
@stderr = global i32 0
@.str.1 = [25 x i8] c"invalid port number: %s\0A\00"
@optind = external global i32
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %18, %2
%4 = phi i1 [ true, %18 ], [ false, %2 ]
%5 = phi i32 [ %19, %18 ], [ 21234, %2 ]
br label %6
6: ; preds = %3, %10
%7 = phi i32 [ %5, %3 ], [ %12, %10 ]
br label %8
8: ; preds = %6, %8
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %9, label %8 [
i32 -1, label %20
i32 112, label %10
i32 63, label %18
]
10: ; preds = %8
%11 = load i8*, i8** @optarg
%12 = tail call i32 @atoi(i8* %11)
%13 = add i32 %12, -65536
%14 = icmp ult i32 %13, -64512
br i1 %14, label %15, label %6
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %18
18: ; preds = %8, %15
%19 = phi i32 [ %12, %15 ], [ %7, %8 ]
br label %3
20: ; preds = %8
%21 = load i32, i32* @optind
%22 = icmp slt i32 %21, %0
%23 = select i1 %4, i1 true, i1 %22
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @main.usage, i64 0, i64 0), i8* %26)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %20
%30 = tail call i32 @serve(i32 %7)
ret i32 0
}