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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int getpid();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int write(int, char *, int);
int str_echo(int sockfd) {
  int nrcv, nsnd;
  char msg[1500];
  memset((char *)msg, 0, sizeof(msg));
  if ((nrcv = read(sockfd, msg, sizeof(msg) - 1)) < 0) {
    perror("servmulti : : readn error on socket");
    exit(1);
  }
  msg[nrcv] = '\0';
  printf("servmulti :message recu=%s du processus %d nrcv = %d \n", msg,
         getpid(), nrcv);
  if ((nsnd = write(sockfd, msg, nrcv)) < 0) {
    printf("servmulti : writen error on socket");
    exit(1);
  }
  printf("nsnd = %d \n", nsnd);
  return (nsnd);
}


x86 assembly (clang, -O0):
<str_echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x600,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x5f0(%rbp),%rdi
xor    %esi,%esi
mov    $0x5dc,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x5f0(%rbp),%rsi
mov    $0x5db,%edx
call   1070 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11c7 <str_echo+0x57>
lea    0xe48(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x5f0(%rbp,%rax,1)
lea    -0x5f0(%rbp),%rax
mov    %rax,-0x5f8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x5f8(%rbp),%rsi
mov    %eax,%edx
mov    -0x8(%rbp),%ecx
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x5f0(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1238 <str_echo+0xc8>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x600,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_echo>:
push   %rbp
push   %r14
push   %rbx
sub    $0x5e0,%rsp
mov    %edi,%ebx
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x5dc,%edx
call   1060 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x5db,%edx
call   1070 <read@plt>
test   %eax,%eax
js     11f9 <str_echo+0x89>
mov    %eax,%ebp
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe6c(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
mov    %eax,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
test   %eax,%eax
js     120f <str_echo+0x9f>
mov    %eax,%ebx
lea    0xe9c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x5e0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe00(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"servmulti : : readn error on socket\00"
@.str.1 = [55 x i8] c"servmulti :message recu=%s du processus %d nrcv = %d \0A\00"
@.str.2 = [35 x i8] c"servmulti : writen error on socket\00"
@.str.3 = [12 x i8] c"nsnd = %d \0A\00"
define i32 @str_echo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1500 x i8]
store i32 %0, i32* %2
%6 = getelementptr inbounds [1500 x i8], [1500 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 1500)
%8 = load i32, i32* %2
%9 = getelementptr inbounds [1500 x i8], [1500 x i8]* %5, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 1499)
store i32 %10, i32* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1500 x i8], [1500 x i8]* %5, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [1500 x i8], [1500 x i8]* %5, i64 0, i64 0
%20 = call i32 (...) @getpid()
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 %20, i32 %21)
%23 = load i32, i32* %2
%24 = getelementptr inbounds [1500 x i8], [1500 x i8]* %5, i64 0, i64 0
%25 = load i32, i32* %3
%26 = call i32 @write(i32 %23, i8* %24, i32 %25)
store i32 %26, i32* %4
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %15
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %15
%32 = load i32, i32* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [36 x i8] c"servmulti : : readn error on socket\00"
@.str.1 = [55 x i8] c"servmulti :message recu=%s du processus %d nrcv = %d \0A\00"
@.str.2 = [35 x i8] c"servmulti : writen error on socket\00"
@.str.3 = [12 x i8] c"nsnd = %d \0A\00"
define i32 @str_echo(i32 %0) {
%2 = alloca [1500 x i8]
%3 = getelementptr inbounds [1500 x i8], [1500 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 1500)
%5 = call i32 @read(i32 %0, i8* %3, i32 1499)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = zext i32 %5 to i64
%12 = getelementptr inbounds [1500 x i8], [1500 x i8]* %2, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i32 (...) @getpid()
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 %13, i32 %5)
%15 = call i32 @write(i32 %0, i8* %3, i32 %5)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %10
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %15)
ret i32 %15
}