#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 launch_server(int, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int port, portRedirection;
  char *redirection;
  int resultServ;
  char *msg;
  if (argc != (3 + 1)) {
    msg = "Bad number of arguments\n";
    write(1, msg, strlen(msg));
    return 1;
  }
  port = atoi(argv[1]);
  redirection = argv[2];
  portRedirection = atoi(argv[3]);
  if ((port == 0) || (portRedirection == 0)) {
    msg = "Incorrect arguments\n";
    write(1, msg, strlen(msg));
    return 2;
  }
  resultServ = launch_server(port, redirection, portRedirection);
  if (resultServ != 0) {
    msg = "Server stopped with errors\n";
    write(1, msg, strlen(msg));
    return resultServ;
  }
  msg = "Serveur stopped without error\n";
  printf("%s", msg);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11a8 <main+0x58>
lea    0xe89(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
jmp    1295 <main+0x145>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11e8 <main+0x98>
cmpl   $0x0,-0x18(%rbp)
jne    1220 <main+0xd0>
lea    0xe2a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
movl   $0x2,-0x4(%rbp)
jmp    1295 <main+0x145>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1070 <launch_server@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1273 <main+0x123>
lea    0xdeb(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1295 <main+0x145>
lea    0xdd0(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xde0(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    119b <main+0x4b>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
call   1060 <atoi@plt>
test   %ebp,%ebp
je     11c0 <main+0x70>
test   %eax,%eax
je     11c0 <main+0x70>
mov    0x10(%rbx),%rsi
mov    %ebp,%edi
mov    %eax,%edx
call   1070 <launch_server@plt>
test   %eax,%eax
je     11e5 <main+0x95>
mov    %eax,%ebx
lea    0xe9d(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
jmp    11af <main+0x5f>
lea    0xe5e(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    $0x1,%ebx
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    11fa <main+0xaa>
lea    0xe52(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    $0x2,%ebx
jmp    11fa <main+0xaa>
lea    0xe7d(%rip),%rdi
lea    0xe57(%rip),%rsi
call   1050 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Bad number of arguments\0A\00"
@.str.1 = [21 x i8] c"Incorrect arguments\0A\00"
@.str.2 = [28 x i8] c"Server stopped with errors\0A\00"
@.str.3 = [31 x i8] c"Serveur stopped without error\0A\00"
@.str.4 = [3 x i8] c"%s\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 i8*
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %18
13: ; preds = %2
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %10
%14 = load i8*, i8** %10
%15 = load i8*, i8** %10
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @write(i32 1, i8* %14, i32 %16)
store i32 1, i32* %3
br label %56
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
store i8* %25, i8** %8
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %7
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %18
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32, %18
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8** %10
%36 = load i8*, i8** %10
%37 = load i8*, i8** %10
%38 = call i32 @strlen(i8* %37)
%39 = call i32 @write(i32 1, i8* %36, i32 %38)
store i32 2, i32* %3
br label %56
40: ; preds = %32
%41 = load i32, i32* %6
%42 = load i8*, i8** %8
%43 = load i32, i32* %7
%44 = call i32 @launch_server(i32 %41, i8* %42, i32 %43)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %40
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8** %10
%48 = load i8*, i8** %10
%49 = load i8*, i8** %10
%50 = call i32 @strlen(i8* %49)
%51 = call i32 @write(i32 1, i8* %48, i32 %50)
%52 = load i32, i32* %9
store i32 %52, i32* %3
br label %56
53: ; preds = %40
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8** %10
%54 = load i8*, i8** %10
%55 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %54)
store i32 0, i32* %3
br label %56
56: ; preds = %53, %47, %35, %13
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [25 x i8] c"Bad number of arguments\0A\00"
@.str.1 = [21 x i8] c"Incorrect arguments\0A\00"
@.str.2 = [28 x i8] c"Server stopped with errors\0A\00"
@.str.3 = [31 x i8] c"Serveur stopped without error\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %30
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = icmp eq i32 %10, 0
%15 = icmp eq i32 %13, 0
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %17, label %20
17: ; preds = %7
%18 = tail call i32 @strlen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %30
20: ; preds = %7
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @launch_server(i32 %10, i8* %22, i32 %13)
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = tail call i32 @strlen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %30
28: ; preds = %20
%29 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %25, %17, %4
%31 = phi i32 [ 1, %4 ], [ 2, %17 ], [ %23, %25 ], [ 0, %28 ]
ret i32 %31
}