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

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int STDIN_FILENO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
void prise(int lesock) {
  int n;
  char recvbuf[1024];
  fd_set rset;
  while (1) {
    FD_ZERO(&rset);
    FD_SET(lesock, &rset);
    FD_SET(STDIN_FILENO, &rset);
    select(lesock + 1, &rset, NULL, NULL, NULL);
    if (FD_ISSET(lesock, &rset)) {
      n = read(lesock, recvbuf, 1024);
      if (n <= 0) {
        printf("Connection ferm�e\n");
        exit(0);
      }
      recvbuf[n] = 0;
      printf("%s", recvbuf);
    }
    if (FD_ISSET(STDIN_FILENO, &rset)) {
      n = read(STDIN_FILENO, recvbuf, 1024);
      if (n > 0) {
        recvbuf[n] = 0;
        write(lesock, recvbuf, n);
      }
    }
  }
}


x86 assembly (clang, -O0):
<prise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x414(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x414(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    -0x414(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x414(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1080 <select@plt>
mov    -0x4(%rbp),%edi
lea    -0x414(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     124b <prise+0xcb>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     122a <prise+0xaa>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    -0x414(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12b4 <prise+0x134>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    12af <prise+0x12f>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <write@plt>
jmp    12b4 <prise+0x134>
jmp    118e <prise+0xe>

x86 assembly (clang, -O2):
<prise>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %edi,%ebx
lea    0x1(%rbx),%r14d
lea    0xc(%rsp),%rbp
mov    0x2e2d(%rip),%r13
lea    0x10(%rsp),%r15
lea    0xe41(%rip),%r12
nop
mov    %rbp,%rdi
call   1080 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10b0 <FD_SET@plt>
mov    0x0(%r13),%edi
mov    %rbp,%rsi
call   10b0 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <select@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1226 <prise+0x96>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1268 <prise+0xd8>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13),%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     11c0 <prise+0x30>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    11c0 <prise+0x30>
mov    %eax,%ecx
movb   $0x0,0x10(%rsp,%rcx,1)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    11c0 <prise+0x30>
lea    0xd94(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [21 x i8] c"Connection ferm\EF\BF\BDe\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define void @prise(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
store i32 %0, i32* %2
br label %6
6: ; preds = %1, %52
%7 = call i32 @FD_ZERO(i32* %5)
%8 = load i32, i32* %2
%9 = call i32 @FD_SET(i32 %8, i32* %5)
%10 = load i32, i32* @STDIN_FILENO
%11 = call i32 @FD_SET(i32 %10, i32* %5)
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
%14 = call i32 @select(i32 %13, i32* %5, i32* null, i32* null, i32* null)
%15 = load i32, i32* %2
%16 = call i64 @FD_ISSET(i32 %15, i32* %5)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %6
%19 = load i32, i32* %2
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 1024)
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = icmp sle i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %18
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %27, %6
%34 = load i32, i32* @STDIN_FILENO
%35 = call i64 @FD_ISSET(i32 %34, i32* %5)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %52
37: ; preds = %33
%38 = load i32, i32* @STDIN_FILENO
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%40 = call i32 @read(i32 %38, i8* %39, i32 1024)
store i32 %40, i32* %3
%41 = load i32, i32* %3
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %51
43: ; preds = %37
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %45
store i8 0, i8* %46
%47 = load i32, i32* %2
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%49 = load i32, i32* %3
%50 = call i32 @write(i32 %47, i8* %48, i32 %49)
br label %51
51: ; preds = %43, %37
br label %52
52: ; preds = %51, %33
br label %6
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@str = [20 x i8] c"Connection ferm\EF\BF\BDe\00"
define void @prise(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = add nsw i32 %0, 1
br label %7
7: ; preds = %33, %1
%8 = call i32 @FD_ZERO(i32* %3)
%9 = call i32 @FD_SET(i32 %0, i32* %3)
%10 = load i32, i32* @STDIN_FILENO
%11 = call i32 @FD_SET(i32 %10, i32* %3)
%12 = call i32 @select(i32 %6, i32* %3, i32* null, i32* null, i32* null)
%13 = call i64 @FD_ISSET(i32 %0, i32* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %25, label %15
15: ; preds = %7
%16 = call i32 @read(i32 %0, i8* %4, i32 1024)
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %15
%22 = zext i32 %16 to i64
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %22
store i8 0, i8* %23
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %25
25: ; preds = %21, %7
%26 = load i32, i32* @STDIN_FILENO
%27 = call i64 @FD_ISSET(i32 %26, i32* %3)
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i32, i32* @STDIN_FILENO
%31 = call i32 @read(i32 %30, i8* %4, i32 1024)
%32 = icmp sgt i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %29, %34, %25
br label %7
34: ; preds = %29
%35 = zext i32 %31 to i64
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %35
store i8 0, i8* %36
%37 = call i32 @write(i32 %0, i8* %4, i32 %31)
br label %33
}