#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ strfry(char *);
int /*<<< orphan*/ write(int, char *, int);
void traite_connexion(int sock) {
  char buffer[256];
  int longueur;
  while (1) {
    longueur = read(sock, buffer, 256);
    if (longueur < 0) {
      perror("read");
      exit(0);
    }
    if (longueur == 0)
      break;
    buffer[longueur] = '\0';
    strfry(buffer);
    write(sock, buffer, longueur);
  }
  close(sock);
}


x86 assembly (clang, -O0):
<traite_connexion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    11a8 <traite_connexion+0x48>
lea    0xe64(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x114(%rbp)
jne    11ba <traite_connexion+0x5a>
jmp    11ef <traite_connexion+0x8f>
movslq -0x114(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
call   1070 <strfry@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
call   1030 <write@plt>
jmp    116e <traite_connexion+0xe>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<traite_connexion>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
js     11c3 <traite_connexion+0x63>
mov    %eax,%ebp
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %ebp,%ebp
je     11d6 <traite_connexion+0x76>
mov    %ebp,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
call   1070 <strfry@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1190 <traite_connexion+0x30>
lea    0xe36(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    %ebx,%edi
call   1040 <close@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
define void @traite_connexion(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i32
store i32 %0, i32* %2
br label %5
5: ; preds = %1, %18
%6 = load i32, i32* %2
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 256)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %5
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
br label %28
18: ; preds = %14
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %21
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%23 = call i32 @strfry(i8* %22)
%24 = load i32, i32* %2
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%26 = load i32, i32* %4
%27 = call i32 @write(i32 %24, i8* %25, i32 %26)
br label %5
28: ; preds = %17
%29 = load i32, i32* %2
%30 = call i32 @close(i32 %29)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
define void @traite_connexion(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 256)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %12, %1
%7 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 0)
unreachable
9: ; preds = %1, %12
%10 = phi i32 [ %17, %12 ], [ %4, %1 ]
%11 = icmp eq i32 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %9
%13 = zext i32 %10 to i64
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i32 @strfry(i8* %3)
%16 = call i32 @write(i32 %0, i8* %3, i32 %10)
%17 = call i32 @read(i32 %0, i8* %3, i32 256)
%18 = icmp slt i32 %17, 0
br i1 %18, label %6, label %9
19: ; preds = %9
%20 = call i32 @close(i32 %0)
ret void
}