#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 read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void traite_connexion(int sock) {
  char buffer[256];
  int longueur;
  int i, tmp;
  while (1) {
    longueur = read(sock, buffer, 256);
    if (longueur <= 0)
      break;
    while ((longueur > 0) &&
           ((buffer[longueur - 1] == '\n') || (buffer[longueur - 1] == '\r')))
      longueur--;
    if (longueur == 0)
      break;
    buffer[longueur] = '\0';
    for (i = 0; i < longueur / 2; i++) {
      tmp = buffer[longueur - 1 - i];
      buffer[longueur - 1 - i] = buffer[i];
      buffer[i] = tmp;
    }
    buffer[longueur] = '\n';
    write(sock, buffer, longueur + 1);
  }
  close(sock);
}


x86 assembly (clang, -O0):
<traite_connexion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%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)
jg     116a <traite_connexion+0x3a>
jmp    12ea <traite_connexion+0x1ba>
jmp    116f <traite_connexion+0x3f>
xor    %eax,%eax
cmpl   $0x0,-0x114(%rbp)
mov    %al,-0x11d(%rbp)
jle    11d3 <traite_connexion+0xa3>
mov    -0x114(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x110(%rbp,%rax,1),%ecx
ff
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x11e(%rbp)
je     11c7 <traite_connexion+0x97>
mov    -0x114(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
sete   %al
mov    %al,-0x11e(%rbp)
mov    -0x11e(%rbp),%al
mov    %al,-0x11d(%rbp)
mov    -0x11d(%rbp),%al
test   $0x1,%al
jne    11e6 <traite_connexion+0xb6>
jmp    11fa <traite_connexion+0xca>
mov    -0x114(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x114(%rbp)
jmp    116f <traite_connexion+0x3f>
cmpl   $0x0,-0x114(%rbp)
jne    120c <traite_connexion+0xdc>
jmp    12ea <traite_connexion+0x1ba>
movslq -0x114(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
movl   $0x0,-0x118(%rbp)
mov    -0x118(%rbp),%eax
mov    %eax,-0x124(%rbp)
mov    -0x114(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x124(%rbp),%eax
cmp    %ecx,%eax
jge    12be <traite_connexion+0x18e>
mov    -0x114(%rbp),%eax
sub    $0x1,%eax
sub    -0x118(%rbp),%eax
cltq
movsbl -0x110(%rbp,%rax,1),%eax
ff
mov    %eax,-0x11c(%rbp)
movslq -0x118(%rbp),%rax
mov    -0x110(%rbp,%rax,1),%cl
mov    -0x114(%rbp),%eax
sub    $0x1,%eax
sub    -0x118(%rbp),%eax
cltq
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x11c(%rbp),%eax
mov    %al,%cl
movslq -0x118(%rbp),%rax
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    1225 <traite_connexion+0xf5>
movslq -0x114(%rbp),%rax
movb   $0xa,-0x110(%rbp,%rax,1)
0a
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
add    $0x1,%edx
call   1030 <write@plt>
jmp    113e <traite_connexion+0xe>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<traite_connexion>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %edi,%r12d
mov    %rsp,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1283 <traite_connexion+0x153>
movabs $0xffffffff00000000,%r13
ff ff ff
movabs $0xfffffffe00000000,%r15
ff ff ff
mov    %rsp,%r14
mov    %eax,%eax
mov    %rax,%rcx
shl    $0x20,%rcx
lea    (%rcx,%r15,1),%rsi
add    %r13,%rcx
jmp    11a3 <traite_connexion+0x73>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %r13,%rsi
add    %r13,%rcx
cmp    $0x1,%rax
mov    %rdx,%rax
jbe    1283 <traite_connexion+0x153>
lea    -0x1(%rax),%rdx
mov    %edx,%edi
movzbl (%rsp,%rdi,1),%ebx
cmp    $0xd,%bl
je     1190 <traite_connexion+0x60>
cmp    $0xa,%bl
je     1190 <traite_connexion+0x60>
movslq %eax,%rdx
movb   $0x0,(%rsp,%rdx,1)
cmp    $0x2,%edx
jl     1259 <traite_connexion+0x129>
mov    %rax,%r8
shr    %r8
mov    %r8d,%edi
and    $0x7fffffff,%edi
cmp    $0x1,%edi
jne    11df <traite_connexion+0xaf>
xor    %edi,%edi
jmp    123f <traite_connexion+0x10f>
mov    %r8d,%r9d
and    $0x7fffffff,%r9d
mov    %r8d,%edi
and    $0x1,%edi
sub    %rdi,%r9
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rcx,%rbp
sar    $0x20,%rbp
movzbl (%rsp,%rbp,1),%r10d
movzbl (%rsp,%rdi,1),%ebx
mov    %bl,(%rsp,%rbp,1)
mov    %r10b,(%rsp,%rdi,1)
mov    %rsi,%rbp
sar    $0x20,%rbp
movzbl (%rsp,%rbp,1),%r10d
movzbl 0x1(%rsp,%rdi,1),%ebx
mov    %bl,(%rsp,%rbp,1)
mov    %r10b,0x1(%rsp,%rdi,1)
add    $0x2,%rdi
add    %r15,%rsi
add    %r15,%rcx
cmp    %rdi,%r9
jne    1200 <traite_connexion+0xd0>
test   $0x1,%r8b
je     1259 <traite_connexion+0x129>
mov    %edi,%ecx
not    %ecx
add    %ecx,%eax
cltq
mov    (%rsp,%rax,1),%cl
mov    (%rsp,%rdi,1),%bl
mov    %bl,(%rsp,%rax,1)
mov    %cl,(%rsp,%rdi,1)
movb   $0xa,(%rsp,%rdx,1)
add    $0x1,%edx
mov    %r12d,%edi
mov    %r14,%rsi
call   1030 <write@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     1170 <traite_connexion+0x40>
mov    %r12d,%edi
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>

LLVM IR (-O0):
define void @traite_connexion(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
br label %7
7: ; preds = %1, %81
%8 = load i32, i32* %2
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 256)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %7
br label %90
14: ; preds = %7
br label %15
15: ; preds = %38, %14
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %36
18: ; preds = %15
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %34, label %26
26: ; preds = %18
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 13
br label %34
34: ; preds = %26, %18
%35 = phi i1 [ true, %18 ], [ %33, %26 ]
br label %36
36: ; preds = %34, %15
%37 = phi i1 [ false, %15 ], [ %35, %34 ]
br i1 %37, label %38, label %41
38: ; preds = %36
%39 = load i32, i32* %4
%40 = add nsw i32 %39, -1
store i32 %40, i32* %4
br label %15
41: ; preds = %36
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
br label %90
45: ; preds = %41
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %47
store i8 0, i8* %48
store i32 0, i32* %5
br label %49
49: ; preds = %78, %45
%50 = load i32, i32* %5
%51 = load i32, i32* %4
%52 = sdiv i32 %51, 2
%53 = icmp slt i32 %50, %52
br i1 %53, label %54, label %81
54: ; preds = %49
%55 = load i32, i32* %4
%56 = sub nsw i32 %55, 1
%57 = load i32, i32* %5
%58 = sub nsw i32 %56, %57
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
store i32 %62, i32* %6
%63 = load i32, i32* %5
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %64
%66 = load i8, i8* %65
%67 = load i32, i32* %4
%68 = sub nsw i32 %67, 1
%69 = load i32, i32* %5
%70 = sub nsw i32 %68, %69
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %71
store i8 %66, i8* %72
%73 = load i32, i32* %6
%74 = trunc i32 %73 to i8
%75 = load i32, i32* %5
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %76
store i8 %74, i8* %77
br label %78
78: ; preds = %54
%79 = load i32, i32* %5
%80 = add nsw i32 %79, 1
store i32 %80, i32* %5
br label %49
81: ; preds = %49
%82 = load i32, i32* %4
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %83
store i8 10, i8* %84
%85 = load i32, i32* %2
%86 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%87 = load i32, i32* %4
%88 = add nsw i32 %87, 1
%89 = call i32 @write(i32 %85, i8* %86, i32 %88)
br label %7
90: ; preds = %44, %13
%91 = load i32, i32* %2
%92 = call i32 @close(i32 %91)
ret void
}

LLVM IR (-O2):
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, 1
br i1 %5, label %70, label %6
6: ; preds = %1, %65
%7 = phi i32 [ %68, %65 ], [ %4, %1 ]
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %6, %15
%10 = phi i64 [ %8, %6 ], [ %11, %15 ]
%11 = add nsw i64 %10, -1
%12 = and i64 %11, 4294967295
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %12
%14 = load i8, i8* %13
switch i8 %14, label %17 [
i8 10, label %15
i8 13, label %15
]
15: ; preds = %9, %9
%16 = icmp ugt i64 %10, 1
br i1 %16, label %9, label %70
17: ; preds = %9
%18 = trunc i64 %10 to i32
%19 = shl i64 %10, 32
%20 = ashr exact i64 %19, 32
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %20
store i8 0, i8* %21
%22 = icmp sgt i32 %18, 1
br i1 %22, label %23, label %65
23: ; preds = %17
%24 = lshr i64 %10, 1
%25 = and i64 %24, 2147483647
%26 = and i64 %24, 1
%27 = icmp eq i64 %25, 1
br i1 %27, label %53, label %28
28: ; preds = %23
%29 = sub nsw i64 %25, %26
br label %30
30: ; preds = %30, %28
%31 = phi i64 [ 0, %28 ], [ %50, %30 ]
%32 = phi i64 [ 0, %28 ], [ %51, %30 ]
%33 = xor i64 %31, -1
%34 = add i64 %10, %33
%35 = shl i64 %34, 32
%36 = ashr exact i64 %35, 32
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %31
%40 = load i8, i8* %39
store i8 %40, i8* %37
store i8 %38, i8* %39
%41 = or i64 %31, 1
%42 = sub nsw i64 4294967294, %31
%43 = add i64 %10, %42
%44 = shl i64 %43, 32
%45 = ashr exact i64 %44, 32
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %41
%49 = load i8, i8* %48
store i8 %49, i8* %46
store i8 %47, i8* %48
%50 = add nuw nsw i64 %31, 2
%51 = add i64 %32, 2
%52 = icmp eq i64 %51, %29
br i1 %52, label %53, label %30
53: ; preds = %30, %23
%54 = phi i64 [ 0, %23 ], [ %50, %30 ]
%55 = icmp eq i64 %26, 0
br i1 %55, label %65, label %56
56: ; preds = %53
%57 = xor i64 %54, -1
%58 = add i64 %10, %57
%59 = shl i64 %58, 32
%60 = ashr exact i64 %59, 32
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %54
%64 = load i8, i8* %63
store i8 %64, i8* %61
store i8 %62, i8* %63
br label %65
65: ; preds = %56, %53, %17
store i8 10, i8* %21
%66 = add nsw i32 %18, 1
%67 = call i32 @write(i32 %0, i8* %3, i32 %66)
%68 = call i32 @read(i32 %0, i8* %3, i32 256)
%69 = icmp slt i32 %68, 1
br i1 %69, label %70, label %6
70: ; preds = %65, %15, %1
%71 = tail call i32 @close(i32 %0)
ret void
}