#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 /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ FXClose(int);
int FXNewServerSocket(int, int);
int accept(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
scalar_t__ strcmp(char *, char *);
int FXServer(int bufferSize, int port, int maxConnections) {
  char buffer[bufferSize];
  int sock, socket;
  int exitCond = 0;
  int count;
  sock = FXNewServerSocket(port, maxConnections);
  while (!exitCond) {
    if ((socket = accept(sock, 0, 0)) != -1) {
      if ((count = read(socket, buffer, sizeof(buffer))) < 0) {
        printf("Error: unable to read recived message.\n");
        FXClose(socket);
      } else {
        buffer[count] = 0;
        if (strcmp(buffer, "exit") == 0)
          exitCond = 1;
        else
          return *buffer;
      }
      FXClose(socket);
    }
  }
  FXClose(sock);
  printf("Server: Terminato.\n");
  return 0;
}


x86 assembly (clang, -O0):
<FXServer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <FXNewServerSocket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x2c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c6 <FXServer+0x66>
jmp    126b <FXServer+0x10b>
mov    -0x24(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <accept@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
je     1266 <FXServer+0x106>
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rax
mov    -0x28(%rbp),%edi
mov    %eax,%edx
call   1050 <read@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    1215 <FXServer+0xb5>
lea    0xdfd(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%edi
call   1070 <FXClose@plt>
jmp    125e <FXServer+0xfe>
mov    -0x40(%rbp),%rdi
movslq -0x30(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
lea    0xe00(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1243 <FXServer+0xe3>
movl   $0x1,-0x2c(%rbp)
jmp    1259 <FXServer+0xf9>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    128d <FXServer+0x12d>
jmp    125e <FXServer+0xfe>
mov    -0x28(%rbp),%edi
call   1070 <FXClose@plt>
jmp    11b0 <FXServer+0x50>
mov    -0x24(%rbp),%edi
call   1070 <FXClose@plt>
lea    0xdb3(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FXServer>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
mov    %edi,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %esi,%edi
mov    %edx,%esi
call   1030 <FXNewServerSocket@plt>
mov    %eax,%r15d
jmp    11c4 <FXServer+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
mov    %r12d,%edi
call   1070 <FXClose@plt>
xor    %r13d,%r13d
mov    %r12d,%edi
call   1070 <FXClose@plt>
test   %r13d,%r13d
jne    1211 <FXServer+0xb1>
xor    %r13d,%r13d
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <accept@plt>
cmp    $0xffffffff,%eax
je     11bf <FXServer+0x5f>
mov    %eax,%r12d
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <read@plt>
test   %eax,%eax
js     11a0 <FXServer+0x40>
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
lea    0xe04(%rip),%rsi
call   1060 <strcmp@plt>
mov    $0x1,%r13d
test   %rax,%rax
je     11b7 <FXServer+0x57>
movsbl (%rbx),%eax
jmp    1227 <FXServer+0xc7>
mov    %r15d,%edi
call   1070 <FXClose@plt>
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Error: unable to read recived message.\0A\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [20 x i8] c"Server: Terminato.\0A\00"
define i32 @FXServer(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%15 = load i32, i32* %5
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
store i32 0, i32* %12
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = call i32 @FXNewServerSocket(i32 %19, i32 %20)
store i32 %21, i32* %10
br label %22
22: ; preds = %53, %3
%23 = load i32, i32* %12
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %54
26: ; preds = %22
%27 = load i32, i32* %10
%28 = call i32 @accept(i32 %27, i32 0, i32 0)
store i32 %28, i32* %11
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %53
30: ; preds = %26
%31 = load i32, i32* %11
%32 = trunc i64 %16 to i32
%33 = call i32 @read(i32 %31, i8* %18, i32 %32)
store i32 %33, i32* %13
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%37 = load i32, i32* %11
%38 = call i32 @FXClose(i32 %37)
br label %50
39: ; preds = %30
%40 = load i32, i32* %13
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %18, i64 %41
store i8 0, i8* %42
%43 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39
store i32 1, i32* %12
br label %49
46: ; preds = %39
%47 = load i8, i8* %18
%48 = sext i8 %47 to i32
store i32 %48, i32* %4
store i32 1, i32* %14
br label %58
49: ; preds = %45
br label %50
50: ; preds = %49, %35
%51 = load i32, i32* %11
%52 = call i32 @FXClose(i32 %51)
br label %53
53: ; preds = %50, %26
br label %22
54: ; preds = %22
%55 = load i32, i32* %10
%56 = call i32 @FXClose(i32 %55)
%57 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
store i32 1, i32* %14
br label %58
58: ; preds = %54, %46
%59 = load i8*, i8** %8
%60 = load i32, i32* %4
ret i32 %60
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"exit\00"
@str = [19 x i8] c"Server: Terminato.\00"
@str.3 = [39 x i8] c"Error: unable to read recived message.\00"
define i32 @FXServer(i32 %0, i32 %1, i32 %2) {
%4 = zext i32 %0 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32 @FXNewServerSocket(i32 %1, i32 %2)
br label %7
7: ; preds = %3, %27
%8 = call i32 @accept(i32 %6, i32 0, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %27, label %10
10: ; preds = %7
%11 = call i32 @read(i32 %8, i8* %5, i32 %0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.3, i64 0, i64 0))
%15 = call i32 @FXClose(i32 %8)
br label %24
16: ; preds = %10
%17 = zext i32 %11 to i64
%18 = getelementptr inbounds i8, i8* %5, i64 %17
store i8 0, i8* %18
%19 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
br label %33
24: ; preds = %16, %13
%25 = phi i32 [ 0, %13 ], [ 1, %16 ]
%26 = call i32 @FXClose(i32 %8)
br label %27
27: ; preds = %24, %7
%28 = phi i32 [ %25, %24 ], [ 0, %7 ]
%29 = icmp eq i32 %28, 0
br i1 %29, label %7, label %30
30: ; preds = %27
%31 = call i32 @FXClose(i32 %6)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %30, %21
%34 = phi i32 [ %23, %21 ], [ 0, %30 ]
ret i32 %34
}