#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*/ listen_loop(int);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *);
int set_up_listener(int);
int main(int argc, char *argv[]) {
  int specified_port = atoi(argv[1]);
  int primary_listener;
  int len;
  if (argc < 2) {
    printf("Invalid usage.\n");
    print_usage();
    return 0;
  }
  primary_listener = set_up_listener(specified_port);
  if (primary_listener < 0) {
    printf("Looks like we are having some problems. SailFish will now stop.\n");
    return 0;
  }
  listen_loop(primary_listener);
  return 0;
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    119f <main+0x4f>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    11db <main+0x8b>
mov    -0x14(%rbp),%edi
call   1050 <set_up_listener@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11cc <main+0x7c>
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11db <main+0x8b>
mov    -0x18(%rbp),%edi
call   1030 <listen_loop@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x1,%edi
jg     116b <main+0x1b>
lea    0xee3(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <print_usage@plt>
jmp    1194 <main+0x44>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1050 <set_up_listener@plt>
test   %eax,%eax
js     1188 <main+0x38>
mov    %eax,%edi
call   1030 <listen_loop@plt>
jmp    1194 <main+0x44>
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Invalid usage.\0A\00"
@.str.1 = [65 x i8] c"Looks like we are having some problems. SailFish will now stop.\0A\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (...) @print_usage()
store i32 0, i32* %3
br label %28
18: ; preds = %2
%19 = load i32, i32* %6
%20 = call i32 @set_up_listener(i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %28
25: ; preds = %18
%26 = load i32, i32* %7
%27 = call i32 @listen_loop(i32 %26)
store i32 0, i32* %3
br label %28
28: ; preds = %25, %23, %15
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@str = [64 x i8] c"Looks like we are having some problems. SailFish will now stop.\00"
@str.2 = [15 x i8] c"Invalid usage.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.2, i64 0, i64 0))
%6 = tail call i32 (...) @print_usage()
br label %17
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = tail call i32 @set_up_listener(i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
br label %17
15: ; preds = %7
%16 = tail call i32 @listen_loop(i32 %11)
br label %17
17: ; preds = %15, %13, %4
ret i32 0
}