#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ kotya_init(int);
int /*<<< orphan*/ kotya_main_loop();
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int flag_n = 0, opt;
  int port = 8080;
  ;
  pid_t pid;
  while ((opt = getopt(argc, argv, "p:n")) != -1) {
    switch (opt) {
    case 'p':
      port = atoi(optarg);
      break;
    case 'n':
      flag_n = 1;
      break;
    default:
      fprintf(stderr, "Usage: %s [-p port]\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  }
  if (flag_n == 0) {
    pid = fork();
    if (pid == -1)
      do {
        perror("fork");
        exit(EXIT_FAILURE);
      } while (0);
    else if (pid > 0)
      exit(0);
  }
  kotya_init(port);
  kotya_main_loop();
  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)
movl   $0x0,-0x14(%rbp)
movl   $0x1f90,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe4e(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1239 <main+0xb9>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x6e,%eax
je     11fe <main+0x7e>
jmp    11d7 <main+0x57>
mov    -0x24(%rbp),%eax
sub    $0x70,%eax
jne    120a <main+0x8a>
jmp    11e8 <main+0x68>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1234 <main+0xb4>
movl   $0x1,-0x14(%rbp)
jmp    1234 <main+0xb4>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde3(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11a4 <main+0x24>
cmpl   $0x0,-0x14(%rbp)
jne    1291 <main+0x111>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1276 <main+0xf6>
jmp    125c <main+0xdc>
lea    0xdb6(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
jle    1287 <main+0x107>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    128c <main+0x10c>
jmp    1291 <main+0x111>
mov    -0x1c(%rbp),%edi
call   1070 <kotya_init@plt>
mov    $0x0,%al
call   1040 <kotya_main_loop@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,%r12
mov    %edi,%ebp
xor    %ebx,%ebx
mov    $0x1f90,%r14d
lea    0xe61(%rip),%r15
mov    0x2e52(%rip),%r13
mov    %ebx,%ecx
nopl   0x0(%rax,%rax,1)
mov    %ecx,%ebx
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1060 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x6e,%eax
je     11b0 <main+0x30>
cmp    $0xffffffff,%eax
je     11e1 <main+0x61>
cmp    $0x70,%eax
jne    1215 <main+0x95>
mov    0x0(%r13),%edi
call   1080 <atoi@plt>
mov    %eax,%r14d
jmp    11a6 <main+0x26>
test   %ebx,%ebx
jne    11f5 <main+0x75>
xor    %eax,%eax
call   10a0 <fork@plt>
cmp    $0xffffffff,%eax
je     123c <main+0xbc>
test   %eax,%eax
jg     124a <main+0xca>
mov    %r14d,%edi
call   1070 <kotya_init@plt>
xor    %eax,%eax
call   1040 <kotya_main_loop@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xddb(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xdd6(%rip),%rdi
call   1050 <perror@plt>
jmp    122e <main+0xae>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"p:n\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Usage: %s [-p port]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"fork\00"
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
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 8080, i32* %8
br label %10
10: ; preds = %29, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %7
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %30
15: ; preds = %10
%16 = load i32, i32* %7
switch i32 %16, label %21 [
i32 112, label %17
i32 110, label %20
]
17: ; preds = %15
%18 = load i32, i32* @optarg
%19 = call i32 @atoi(i32 %18)
store i32 %19, i32* %8
br label %29
20: ; preds = %15
store i32 1, i32* %6
br label %29
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %20, %17
br label %10
30: ; preds = %10
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %50
33: ; preds = %30
%34 = call i32 (...) @fork()
store i32 %34, i32* %9
%35 = load i32, i32* %9
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %43
37: ; preds = %33
br label %38
38: ; preds = %37
%39 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; No predecessors!
br label %49
43: ; preds = %33
%44 = load i32, i32* %9
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @exit(i32 0)
unreachable
48: ; preds = %43
br label %49
49: ; preds = %48, %42
br label %50
50: ; preds = %49, %30
%51 = load i32, i32* %8
%52 = call i32 @kotya_init(i32 %51)
%53 = call i32 (...) @kotya_main_loop()
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"p:n\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Usage: %s [-p port]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"fork\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %9, %2
%4 = phi i32 [ %11, %9 ], [ 8080, %2 ]
%5 = phi i32 [ %7, %9 ], [ 0, %2 ]
br label %6
6: ; preds = %3, %6
%7 = phi i32 [ 1, %6 ], [ %5, %3 ]
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %12 [
i32 -1, label %18
i32 112, label %9
i32 110, label %6
]
9: ; preds = %6
%10 = load i32, i32* @optarg
%11 = tail call i32 @atoi(i32 %10)
br label %3
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %6
%19 = icmp eq i32 %7, 0
br i1 %19, label %20, label %31
20: ; preds = %18
%21 = tail call i32 (...) @fork()
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %20
%28 = icmp sgt i32 %21, 0
br i1 %28, label %29, label %31
29: ; preds = %27
%30 = tail call i32 @exit(i32 0)
unreachable
31: ; preds = %27, %18
%32 = tail call i32 @kotya_init(i32 %4)
%33 = tail call i32 (...) @kotya_main_loop()
ret i32 0
}