#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 ssize_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int /*<<< orphan*/ stampa(char *, int);
int /*<<< orphan*/ write(int, char *, int);
int client_echo(int cfd) {
  char buffer[128];
  ssize_t rd;
  rd = read(cfd, buffer, sizeof(buffer));
  if (rd <= 0) {
    return (-1);
  }
  if (memcmp(buffer, "scus", 4) == 0) {
    memcpy(buffer, "figur\n", 6);
    rd = 6;
  } else if (memcmp(buffer, "chiudi", 6) == 0) {
    return (-1);
  }
  printf(" - letto dal client %d: ", cfd);
  stampa(buffer, rd);
  write(cfd, buffer, rd);
  return (0);
}


x86 assembly (clang, -O0):
<client_echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1060 <read@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
jg     11a1 <client_echo+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <client_echo+0xfa>
lea    -0x90(%rbp),%rdi
lea    0xe51(%rip),%rsi
mov    $0x4,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
jne    11ea <client_echo+0x8a>
lea    -0x90(%rbp),%rdi
lea    0xe34(%rip),%rsi
mov    $0x6,%edx
call   1080 <memcpy@plt>
movl   $0x6,-0x94(%rbp)
jmp    121d <client_echo+0xbd>
lea    -0x90(%rbp),%rdi
lea    0xe14(%rip),%rsi
mov    $0x6,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
jne    1218 <client_echo+0xb8>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <client_echo+0xfa>
jmp    121d <client_echo+0xbd>
mov    -0x8(%rbp),%esi
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%esi
call   1050 <stampa@plt>
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    -0x94(%rbp),%edx
call   1030 <write@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_echo>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %edi,%r14d
mov    %rsp,%rsi
mov    $0x80,%edx
call   1060 <read@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
jle    11fe <client_echo+0x9e>
mov    %eax,%ebp
lea    0xe73(%rip),%rsi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
je     11ba <client_echo+0x5a>
lea    0xe66(%rip),%rsi
mov    %rsp,%rdi
mov    $0x6,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
jne    11d3 <client_echo+0x73>
jmp    11fe <client_echo+0x9e>
lea    0xe44(%rip),%rsi
mov    %rsp,%rdi
mov    $0x6,%ebp
mov    $0x6,%edx
call   1080 <memcpy@plt>
lea    0xe39(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <stampa@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"scus\00"
@.str.1 = [7 x i8] c"figur\0A\00"
@.str.2 = [7 x i8] c"chiudi\00"
@.str.3 = [25 x i8] c" - letto dal client %d: \00"
define i32 @client_echo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 128)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %35
12: ; preds = %1
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%14 = call i64 @memcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%18 = call i32 @memcpy(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
store i32 6, i32* %5
br label %25
19: ; preds = %12
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%21 = call i64 @memcmp(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 -1, i32* %2
br label %35
24: ; preds = %19
br label %25
25: ; preds = %24, %16
%26 = load i32, i32* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%29 = load i32, i32* %5
%30 = call i32 @stampa(i8* %28, i32 %29)
%31 = load i32, i32* %3
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%33 = load i32, i32* %5
%34 = call i32 @write(i32 %31, i8* %32, i32 %33)
store i32 0, i32* %2
br label %35
35: ; preds = %25, %23, %11
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [5 x i8] c"scus\00"
@.str.1 = [7 x i8] c"figur\0A\00"
@.str.2 = [7 x i8] c"chiudi\00"
@.str.3 = [25 x i8] c" - letto dal client %d: \00"
define i32 @client_echo(i32 %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 128)
%5 = icmp slt i32 %4, 1
br i1 %5, label %19, label %6
6: ; preds = %1
%7 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @memcpy(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
br label %14
11: ; preds = %6
%12 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %11, %9
%15 = phi i32 [ 6, %9 ], [ %4, %11 ]
%16 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%17 = call i32 @stampa(i8* %3, i32 %15)
%18 = call i32 @write(i32 %0, i8* %3, i32 %15)
br label %19
19: ; preds = %11, %1, %14
%20 = phi i32 [ 0, %14 ], [ -1, %1 ], [ -1, %11 ]
ret i32 %20
}