#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 /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ s_run(unsigned long);
unsigned long strtoul(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  int ch;
  unsigned long int port = 9000;
  while ((ch = getopt(argc, argv, "p:")) != -1) {
    switch (ch) {
    case 'p':
      port = strtoul(optarg, NULL, 10);
      if (port <= 1024 || port > 65536) {
        printf("Invalid Port\n");
        exit(1);
      }
      break;
    case '?':
    default:
      printf("Not enough arguments\n");
    }
  }
  printf("Operating on port %lu\n", port);
  s_run(port);
  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   $0x2328,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe84(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     121e <main+0xce>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x3f,%eax
je     1206 <main+0xb6>
jmp    11a1 <main+0x51>
mov    -0x24(%rbp),%eax
sub    $0x70,%eax
jne    120b <main+0xbb>
jmp    11b2 <main+0x62>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x400,-0x20(%rbp)
jbe    11e9 <main+0x99>
cmpq   $0x10000,-0x20(%rbp)
jbe    1201 <main+0xb1>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1219 <main+0xc9>
jmp    120b <main+0xbb>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    116e <main+0x1e>
mov    -0x20(%rbp),%rsi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <s_run@plt>
xor    %eax,%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
mov    $0x2328,%r14d
lea    0xe83(%rip),%r15
mov    0x2e74(%rip),%r13
lea    0xe8f(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <getopt@plt>
cmp    $0xffffffff,%eax
je     11e8 <main+0x88>
cmp    $0x70,%eax
je     11b1 <main+0x51>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    1190 <main+0x30>
mov    0x0(%r13),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtoul@plt>
mov    %rax,%r14
add    $0xfffffffffffeffff,%rax
cmp    $0xffffffffffff03ff,%rax
ja     1190 <main+0x30>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe14(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1050 <s_run@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"p:\00"
@optarg = global i32 0
@.str.1 = [14 x i8] c"Invalid Port\0A\00"
@.str.2 = [22 x i8] c"Not enough arguments\0A\00"
@.str.3 = [23 x i8] c"Operating on port %lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 9000, i64* %7
br label %8
8: ; preds = %30, %2
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %6
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %31
13: ; preds = %8
%14 = load i32, i32* %6
switch i32 %14, label %28 [
i32 112, label %15
i32 63, label %27
]
15: ; preds = %13
%16 = load i32, i32* @optarg
%17 = call i64 @strtoul(i32 %16, i32* null, i32 10)
store i64 %17, i64* %7
%18 = load i64, i64* %7
%19 = icmp ule i64 %18, 1024
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i64, i64* %7
%22 = icmp ugt i64 %21, 65536
br i1 %22, label %23, label %26
23: ; preds = %20, %15
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %20
br label %30
27: ; preds = %13
br label %28
28: ; preds = %13, %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %26
br label %8
31: ; preds = %8
%32 = load i64, i64* %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i64 %32)
%34 = load i64, i64* %7
%35 = call i32 @s_run(i64 %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"p:\00"
@optarg = global i32 0
@.str.3 = [23 x i8] c"Operating on port %lu\0A\00"
@str = [21 x i8] c"Not enough arguments\00"
@str.4 = [13 x i8] c"Invalid Port\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %7, %2
%4 = phi i64 [ %9, %7 ], [ 9000, %2 ]
br label %5
5: ; preds = %3, %15
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %15 [
i32 -1, label %17
i32 112, label %7
]
7: ; preds = %5
%8 = load i32, i32* @optarg
%9 = tail call i64 @strtoul(i32 %8, i32* null, i32 10)
%10 = add i64 %9, -65537
%11 = icmp ult i64 %10, -64512
br i1 %11, label %12, label %3
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %5
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %5
17: ; preds = %5
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i64 %4)
%19 = tail call i32 @s_run(i64 %4)
ret i32 0
}