#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void Handle_TCP_Client(int client_sock) {
  char buf[512];
  ssize_t num_bytes_received;
  ssize_t num_bytes_sent;
  if ((num_bytes_received = recv(client_sock, buf, 512, 0)) < 0) {
    fprintf(stderr, "Err. recv() fallita %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  while (num_bytes_received > 0) {
    if ((num_bytes_sent = send(client_sock, buf, num_bytes_received, 0)) < 0) {
      fprintf(stderr, "Err. send() fallita %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    } else if (num_bytes_sent != num_bytes_received) {
      fprintf(stderr, "Err. send() byte invalidi %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
    if ((num_bytes_received = recv(client_sock, buf, 512, 0)) < 0) {
      fprintf(stderr, "Err. recv() fallita - %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
  }
  close(client_sock);
}


x86 assembly (clang, -O0):
<Handle_TCP_Client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x218(%rbp)
cmp    $0x0,%rax
jge    11d5 <Handle_TCP_Client+0x75>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x224(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x224(%rbp),%edi
mov    %rax,%rdx
lea    0xe3e(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11da <Handle_TCP_Client+0x7a>
cmpq   $0x0,-0x218(%rbp)
jle    1316 <Handle_TCP_Client+0x1b6>
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    -0x218(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rax,-0x220(%rbp)
cmp    $0x0,%rax
jge    1251 <Handle_TCP_Client+0xf1>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x228(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x228(%rbp),%edi
mov    %rax,%rdx
lea    0xdda(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x220(%rbp),%rax
cmp    -0x218(%rbp),%rax
je     12a5 <Handle_TCP_Client+0x145>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x22c(%rbp)
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x22c(%rbp),%edi
mov    %rax,%rdx
lea    0xd9e(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    12aa <Handle_TCP_Client+0x14a>
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x218(%rbp)
cmp    $0x0,%rax
jge    1311 <Handle_TCP_Client+0x1b1>
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x230(%rbp)
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x230(%rbp),%edi
mov    %rax,%rdx
lea    0xd50(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11da <Handle_TCP_Client+0x7a>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Handle_TCP_Client>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %edi,%ebp
mov    %rsp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     1250 <Handle_TCP_Client+0xf0>
mov    %rax,%rbx
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
test   %rbx,%rbx
je     11e7 <Handle_TCP_Client+0x87>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
test   %rax,%rax
js     11fa <Handle_TCP_Client+0x9a>
cmp    %rbx,%rax
jne    121a <Handle_TCP_Client+0xba>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    1190 <Handle_TCP_Client+0x30>
mov    0x2e12(%rip),%rax
mov    (%rax),%ebx
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe69(%rip),%rsi
jmp    1238 <Handle_TCP_Client+0xd8>
mov    %ebp,%edi
call   1050 <close@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2ddf(%rip),%rax
mov    (%rax),%ebx
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe00(%rip),%rsi
jmp    1238 <Handle_TCP_Client+0xd8>
mov    0x2dbf(%rip),%rax
mov    (%rax),%ebx
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdf8(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%ebx
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xd92(%rip),%rsi
jmp    1238 <Handle_TCP_Client+0xd8>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Err. recv() fallita %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [24 x i8] c"Err. send() fallita %s\0A\00"
@.str.2 = [30 x i8] c"Err. send() byte invalidi %s\0A\00"
@.str.3 = [26 x i8] c"Err. recv() fallita - %s\0A\00"
define void @Handle_TCP_Client(i32 %0) {
%2 = alloca i32
%3 = alloca [512 x i8]
%4 = alloca i64
%5 = alloca i64
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%8 = call i64 @recv(i32 %6, i8* %7, i32 512, i32 0)
store i64 %8, i64* %4
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
br label %18
18: ; preds = %58, %17
%19 = load i64, i64* %4
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %59
21: ; preds = %18
%22 = load i32, i32* %2
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%24 = load i64, i64* %4
%25 = call i64 @send(i32 %22, i8* %23, i64 %24, i32 0)
store i64 %25, i64* %5
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %21
%35 = load i64, i64* %5
%36 = load i64, i64* %4
%37 = icmp ne i64 %35, %36
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %34
br label %46
46: ; preds = %45
%47 = load i32, i32* %2
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%49 = call i64 @recv(i32 %47, i8* %48, i32 512, i32 0)
store i64 %49, i64* %4
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %58
51: ; preds = %46
%52 = load i32, i32* @stderr
%53 = load i32, i32* @errno
%54 = call i8* @strerror(i32 %53)
%55 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %46
br label %18
59: ; preds = %18
%60 = load i32, i32* %2
%61 = call i32 @close(i32 %60)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Err. recv() fallita %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [24 x i8] c"Err. send() fallita %s\0A\00"
@.str.2 = [30 x i8] c"Err. send() byte invalidi %s\0A\00"
@.str.3 = [26 x i8] c"Err. recv() fallita - %s\0A\00"
define void @Handle_TCP_Client(i32 %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i64 @recv(i32 %0, i8* %3, i32 512, i32 0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %1, %35
%14 = phi i64 [ %36, %35 ], [ %4, %1 ]
%15 = icmp eq i64 %14, 0
br i1 %15, label %45, label %16
16: ; preds = %13
%17 = call i64 @send(i32 %0, i8* %3, i64 %14, i32 0)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %16
%27 = icmp eq i64 %17, %14
br i1 %27, label %35, label %28
28: ; preds = %26
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %26
%36 = call i64 @recv(i32 %0, i8* %3, i32 512, i32 0)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %13
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %13
%46 = call i32 @close(i32 %0)
ret void
}