#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 */
struct str_sorter_server {
  int dummy;
};

/* Variables and functions */
int atoi(char *);
struct str_sorter_server *createServer(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ removeServer(struct str_sorter_server *);
int runServer(struct str_sorter_server *);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("Use: tcp_string_sorter [ip adress] port\n");
    return -1;
  }
  int port = 0;
  char *address = NULL;
  if (argc == 2)
    port = atoi(argv[1]);
  else {
    address = argv[1];
    port = atoi(argv[2]);
  }
  struct str_sorter_server *sss = createServer(address, port);
  if (NULL == sss)
    return -1;
  int res = runServer(sss);
  removeServer(sss);
  return res;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <main+0xc5>
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11b6 <main+0x66>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    11d2 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <createServer@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    11fa <main+0xaa>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <main+0xc5>
mov    -0x28(%rbp),%rdi
call   1070 <runServer@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <removeServer@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1166 <main+0x16>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
jmp    11a7 <main+0x57>
mov    0x8(%rsi),%rbx
cmp    $0x2,%edi
jne    1176 <main+0x26>
mov    %rbx,%rdi
xor    %ebx,%ebx
jmp    117a <main+0x2a>
mov    0x10(%rsi),%rdi
call   1060 <atoi@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <createServer@plt>
test   %rax,%rax
je     11a7 <main+0x57>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <runServer@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <removeServer@plt>
mov    %ebp,%eax
jmp    11ac <main+0x5c>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.str_sorter_server = type { i32 }
@.str = [41 x i8] c"Use: tcp_string_sorter [ip adress] port\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 %struct.str_sorter_server*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %43
14: ; preds = %2
store i32 0, i32* %6
store i8* null, i8** %7
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %6
br label %30
22: ; preds = %14
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
store i8* %25, i8** %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %6
br label %30
30: ; preds = %22, %17
%31 = load i8*, i8** %7
%32 = load i32, i32* %6
%33 = call %struct.str_sorter_server* @createServer(i8* %31, i32 %32)
store %struct.str_sorter_server* %33, %struct.str_sorter_server** %8
%34 = load %struct.str_sorter_server*, %struct.str_sorter_server** %8
%35 = icmp eq %struct.str_sorter_server* null, %34
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 -1, i32* %3
br label %43
37: ; preds = %30
%38 = load %struct.str_sorter_server*, %struct.str_sorter_server** %8
%39 = call i32 @runServer(%struct.str_sorter_server* %38)
store i32 %39, i32* %9
%40 = load %struct.str_sorter_server*, %struct.str_sorter_server** %8
%41 = call i32 @removeServer(%struct.str_sorter_server* %40)
%42 = load i32, i32* %9
store i32 %42, i32* %3
br label %43
43: ; preds = %37, %36, %12
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.str_sorter_server = type { i32 }
@str = [40 x i8] c"Use: tcp_string_sorter [ip adress] port\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %22
6: ; preds = %2
%7 = icmp eq i32 %0, 2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
br i1 %7, label %13, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
br label %13
13: ; preds = %6, %10
%14 = phi i8* [ %12, %10 ], [ %9, %6 ]
%15 = phi i8* [ %9, %10 ], [ null, %6 ]
%16 = tail call i32 @atoi(i8* %14)
%17 = tail call %struct.str_sorter_server* @createServer(i8* %15, i32 %16)
%18 = icmp eq %struct.str_sorter_server* %17, null
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = tail call i32 @runServer(%struct.str_sorter_server* %17)
%21 = tail call i32 @removeServer(%struct.str_sorter_server* %17)
br label %22
22: ; preds = %19, %13, %4
%23 = phi i32 [ -1, %4 ], [ %20, %19 ], [ -1, %13 ]
ret i32 %23
}