#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*/ create_client_socket(int *, char *);
int /*<<< orphan*/ create_server(int *, int);
int get_dir_fd(char *);
scalar_t__ init_stats();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ signal_init();
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  int port;
  const char *paramerr =
      " : invalid parameters\nusage : TTS-Server [-d root_dir] <listen_port>\n";
  if (argc >= 2) {
    port = atoi(argv[argc - 1]);
    if (port < 0 || port > 65535) {
      printf("%s%s", argv[0], paramerr);
      return -1;
    }
    if (argc == 4) {
      if (strcmp(argv[1], "-d")) {
        printf("%s%s", argv[0], paramerr);
        return -1;
      }
      if (get_dir_fd(argv[2]) == -1) {
        perror("TTS-Server : root directory");
        return -1;
      }
    } else if (argc == 3 || argc > 4) {
      printf("%s%s", argv[0], paramerr);
      return -1;
    }
  } else {
    printf("%s%s", argv[0], paramerr);
    return -1;
  }
  int sockets[2];
  create_server(sockets, port);
  if (sockets[0] < 0 || sockets[1] < 0) {
    printf("%s : unable to start : failed to create server socket\n", argv[0]);
    return -1;
  }
  if (init_stats() < 0)
    return -1;
  signal_init();
  while (1) {
    create_client_socket(sockets, argv[2]);
  }
  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)
lea    0xe53(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     12d3 <main+0x143>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11eb <main+0x5b>
cmpl   $0xffff,-0x14(%rbp)
jle    1210 <main+0x80>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1373 <main+0x1e3>
cmpl   $0x4,-0x8(%rbp)
jne    1290 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe22(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     125d <main+0xcd>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1373 <main+0x1e3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <get_dir_fd@plt>
cmp    $0xffffffff,%eax
jne    128b <main+0xfb>
lea    0xdd4(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1373 <main+0x1e3>
jmp    12ce <main+0x13e>
cmpl   $0x3,-0x8(%rbp)
je     12a4 <main+0x114>
cmpl   $0x4,-0x8(%rbp)
jle    12c9 <main+0x139>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1373 <main+0x1e3>
jmp    12ce <main+0x13e>
jmp    12f8 <main+0x168>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1373 <main+0x1e3>
lea    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <create_server@plt>
cmpl   $0x0,-0x28(%rbp)
jl     1318 <main+0x188>
cmpl   $0x0,-0x24(%rbp)
jge    1339 <main+0x1a9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1373 <main+0x1e3>
mov    $0x0,%al
call   1060 <init_stats@plt>
cmp    $0x0,%rax
jge    1356 <main+0x1c6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1373 <main+0x1e3>
mov    $0x0,%al
call   1090 <signal_init@plt>
lea    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <create_client_socket@plt>
jmp    135d <main+0x1cd>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jl     124e <main+0xbe>
mov    %edi,%ebp
lea    -0x1(%rbp),%eax
mov    (%rbx,%rax,8),%rdi
call   10b0 <atoi@plt>
cmp    $0x10000,%eax
jae    124e <main+0xbe>
mov    %eax,%r14d
cmp    $0x4,%ebp
jne    11f6 <main+0x66>
mov    0x8(%rbx),%rdi
lea    0xe7b(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    124e <main+0xbe>
mov    0x10(%rbx),%rdi
call   1030 <get_dir_fd@plt>
cmp    $0xffffffff,%eax
jne    1200 <main+0x70>
lea    0xe5f(%rip),%rdi
call   10a0 <perror@plt>
jmp    1266 <main+0xd6>
cmp    $0x3,%ebp
je     124e <main+0xbe>
cmp    $0x5,%ebp
jae    124e <main+0xbe>
lea    0x8(%rsp),%rdi
mov    %r14d,%esi
call   1070 <create_server@plt>
cmpl   $0x0,0x8(%rsp)
js     1274 <main+0xe4>
cmpl   $0x0,0xc(%rsp)
js     1274 <main+0xe4>
xor    %eax,%eax
call   1060 <init_stats@plt>
test   %rax,%rax
js     1266 <main+0xd6>
xor    %eax,%eax
call   1090 <signal_init@plt>
lea    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rbx),%rsi
mov    %rbp,%rdi
call   1040 <create_client_socket@plt>
jmp    1240 <main+0xb0>
mov    (%rbx),%rsi
lea    0xdee(%rip),%rdi
lea    0xda1(%rip),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xdec(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1266 <main+0xd6>

LLVM IR (-O0):
@.str = [70 x i8] c" : invalid parameters\0Ausage : TTS-Server [-d root_dir] <listen_port>\0A\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [3 x i8] c"-d\00"
@.str.3 = [28 x i8] c"TTS-Server : root directory\00"
@.str.4 = [55 x i8] c"%s : unable to start : failed to create server socket\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 2
br i1 %10, label %11, label %68
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %12, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %11
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 65535
br i1 %23, label %24, label %30
24: ; preds = %21, %11
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = load i8*, i8** %7
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %28)
store i32 -1, i32* %3
br label %102
30: ; preds = %21
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 4
br i1 %32, label %33, label %54
33: ; preds = %30
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %33
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = load i8*, i8** %7
%44 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %43)
store i32 -1, i32* %3
br label %102
45: ; preds = %33
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = call i32 @get_dir_fd(i8* %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %102
53: ; preds = %45
br label %67
54: ; preds = %30
%55 = load i32, i32* %4
%56 = icmp eq i32 %55, 3
br i1 %56, label %60, label %57
57: ; preds = %54
%58 = load i32, i32* %4
%59 = icmp sgt i32 %58, 4
br i1 %59, label %60, label %66
60: ; preds = %57, %54
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 0
%63 = load i8*, i8** %62
%64 = load i8*, i8** %7
%65 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %63, i8* %64)
store i32 -1, i32* %3
br label %102
66: ; preds = %57
br label %67
67: ; preds = %66, %53
br label %74
68: ; preds = %2
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
%72 = load i8*, i8** %7
%73 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %71, i8* %72)
store i32 -1, i32* %3
br label %102
74: ; preds = %67
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%76 = load i32, i32* %6
%77 = call i32 @create_server(i32* %75, i32 %76)
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%79 = load i32, i32* %78
%80 = icmp slt i32 %79, 0
br i1 %80, label %85, label %81
81: ; preds = %74
%82 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%83 = load i32, i32* %82
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %90
85: ; preds = %81, %74
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 0
%88 = load i8*, i8** %87
%89 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* %88)
store i32 -1, i32* %3
br label %102
90: ; preds = %81
%91 = call i64 (...) @init_stats()
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %94
93: ; preds = %90
store i32 -1, i32* %3
br label %102
94: ; preds = %90
%95 = call i32 (...) @signal_init()
br label %96
96: ; preds = %94, %96
%97 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%98 = load i8**, i8*** %5
%99 = getelementptr inbounds i8*, i8** %98, i64 2
%100 = load i8*, i8** %99
%101 = call i32 @create_client_socket(i32* %97, i8* %100)
br label %96
102: ; preds = %93, %85, %68, %60, %51, %39, %24
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
@.str = [70 x i8] c" : invalid parameters\0Ausage : TTS-Server [-d root_dir] <listen_port>\0A\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [3 x i8] c"-d\00"
@.str.3 = [28 x i8] c"TTS-Server : root directory\00"
@.str.4 = [55 x i8] c"%s : unable to start : failed to create server socket\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %39
5: ; preds = %2
%6 = add nsw i32 %0, -1
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = icmp ugt i32 %10, 65535
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
br label %65
15: ; preds = %5
%16 = icmp eq i32 %0, 4
br i1 %16, label %17, label %32
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = load i8*, i8** %1
%24 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
br label %65
25: ; preds = %17
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = tail call i32 @get_dir_fd(i8* %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %42
30: ; preds = %25
%31 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %65
32: ; preds = %15
%33 = icmp eq i32 %0, 3
%34 = icmp ugt i32 %0, 4
%35 = or i1 %33, %34
br i1 %35, label %36, label %42
36: ; preds = %32
%37 = load i8*, i8** %1
%38 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
br label %65
39: ; preds = %2
%40 = load i8*, i8** %1
%41 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
br label %65
42: ; preds = %25, %32
%43 = bitcast [2 x i32]* %3 to i8*
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%45 = call i32 @create_server(i32* %44, i32 %10)
%46 = load i32, i32* %44
%47 = icmp slt i32 %46, 0
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%49 = load i32, i32* %48
%50 = icmp slt i32 %49, 0
%51 = select i1 %47, i1 true, i1 %50
br i1 %51, label %52, label %55
52: ; preds = %42
%53 = load i8*, i8** %1
%54 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* %53)
br label %64
55: ; preds = %42
%56 = call i64 (...) @init_stats()
%57 = icmp slt i64 %56, 0
br i1 %57, label %64, label %58
58: ; preds = %55
%59 = call i32 (...) @signal_init()
%60 = getelementptr inbounds i8*, i8** %1, i64 2
br label %61
61: ; preds = %61, %58
%62 = load i8*, i8** %60
%63 = call i32 @create_client_socket(i32* %44, i8* %62)
br label %61
64: ; preds = %55, %52
br label %65
65: ; preds = %64, %39, %36, %30, %22, %12
ret i32 -1
}