#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*/ ChiudiSocket(int);
int CreaSocket(int);
int accept(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ strcmp(char *, char *);
int main() {
  char buffer[512];
  int DescrittoreSocket, NuovoSocket;
  int exitCond = 0;
  int Quanti;
  DescrittoreSocket = CreaSocket(1745);
  printf("Server: Attendo connessioni...\n");
  while (!exitCond) {
    if ((NuovoSocket = accept(DescrittoreSocket, 0, 0)) != -1) {
      if ((Quanti = read(NuovoSocket, buffer, sizeof(buffer))) < 0) {
        printf("Impossibile leggere il messaggio.\n");
        ChiudiSocket(NuovoSocket);
      } else {
        buffer[Quanti] = 0;
        if (strcmp(buffer, "exit") == 0)
          exitCond = 1;
        else
          printf("Server: %s \n", buffer);
      }
      ChiudiSocket(NuovoSocket);
    }
  }
  ChiudiSocket(DescrittoreSocket);
  printf("Server: Terminato.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x21c(%rbp)
mov    $0x6d1,%edi
call   1050 <CreaSocket@plt>
mov    %eax,-0x214(%rbp)
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x21c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b3 <main+0x53>
jmp    127a <main+0x11a>
mov    -0x214(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <accept@plt>
mov    %eax,-0x218(%rbp)
cmp    $0xffffffff,%eax
je     1275 <main+0x115>
mov    -0x218(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1060 <read@plt>
mov    %eax,-0x220(%rbp)
cmp    $0x0,%eax
jge    1215 <main+0xb5>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x218(%rbp),%edi
call   1030 <ChiudiSocket@plt>
jmp    126a <main+0x10a>
movslq -0x220(%rbp),%rax
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1250 <main+0xf0>
movl   $0x1,-0x21c(%rbp)
jmp    1265 <main+0x105>
lea    -0x210(%rbp),%rsi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126a <main+0x10a>
mov    -0x218(%rbp),%edi
call   1030 <ChiudiSocket@plt>
jmp    119a <main+0x3a>
mov    -0x214(%rbp),%edi
call   1030 <ChiudiSocket@plt>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    $0x6d1,%edi
call   1060 <CreaSocket@plt>
mov    %eax,%ebx
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
lea    0xe5d(%rip),%r12
lea    0xe5b(%rip),%r13
jmp    11d2 <main+0x62>
nopl   0x0(%rax)
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1040 <ChiudiSocket@plt>
xor    %r15d,%r15d
mov    %ebp,%edi
call   1040 <ChiudiSocket@plt>
test   %r15d,%r15d
jne    122a <main+0xba>
xor    %r15d,%r15d
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <accept@plt>
cmp    $0xffffffff,%eax
je     11cd <main+0x5d>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1070 <read@plt>
test   %eax,%eax
js     11b0 <main+0x40>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1222 <main+0xb2>
xor    %r15d,%r15d
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c6 <main+0x56>
mov    $0x1,%r15d
jmp    11c6 <main+0x56>
mov    %ebx,%edi
call   1040 <ChiudiSocket@plt>
lea    0xdf9(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Server: Attendo connessioni...\0A\00"
@.str.1 = [35 x i8] c"Impossibile leggere il messaggio.\0A\00"
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [13 x i8] c"Server: %s \0A\00"
@.str.4 = [20 x i8] c"Server: Terminato.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [512 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%7 = call i32 @CreaSocket(i32 1745)
store i32 %7, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %41, %0
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %42
13: ; preds = %9
%14 = load i32, i32* %3
%15 = call i32 @accept(i32 %14, i32 0, i32 0)
store i32 %15, i32* %4
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %41
17: ; preds = %13
%18 = load i32, i32* %4
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 512)
store i32 %20, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* %4
%25 = call i32 @ChiudiSocket(i32 %24)
br label %38
26: ; preds = %17
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %28
store i8 0, i8* %29
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %26
store i32 1, i32* %5
br label %37
34: ; preds = %26
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %34, %33
br label %38
38: ; preds = %37, %22
%39 = load i32, i32* %4
%40 = call i32 @ChiudiSocket(i32 %39)
br label %41
41: ; preds = %38, %13
br label %9
42: ; preds = %9
%43 = load i32, i32* %3
%44 = call i32 @ChiudiSocket(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [13 x i8] c"Server: %s \0A\00"
@str = [31 x i8] c"Server: Attendo connessioni...\00"
@str.5 = [19 x i8] c"Server: Terminato.\00"
@str.6 = [34 x i8] c"Impossibile leggere il messaggio.\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @CreaSocket(i32 1745)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %5
5: ; preds = %0, %24
%6 = call i32 @accept(i32 %3, i32 0, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %24, label %8
8: ; preds = %5
%9 = call i32 @read(i32 %6, i8* %2, i32 512)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.6, i64 0, i64 0))
%13 = call i32 @ChiudiSocket(i32 %6)
br label %21
14: ; preds = %8
%15 = zext i32 %9 to i64
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 %15
store i8 0, i8* %16
%17 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %21
21: ; preds = %14, %19, %11
%22 = phi i32 [ 0, %11 ], [ 0, %19 ], [ 1, %14 ]
%23 = call i32 @ChiudiSocket(i32 %6)
br label %24
24: ; preds = %21, %5
%25 = phi i32 [ %22, %21 ], [ 0, %5 ]
%26 = icmp eq i32 %25, 0
br i1 %26, label %5, label %27
27: ; preds = %24
%28 = call i32 @ChiudiSocket(i32 %3)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}