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

/* Variables and functions */
int bor_read_str(int, char *, int);
int bor_write_str(int, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int contact_serv(int soc) {
  int result;
  char buffer[1024];
  printf("Entrez une suite de digits :\n");
  result = bor_read_str(0, buffer, sizeof(buffer) - 1);
  if (result <= 0) {
    perror("Erreur ou ctrl+D a l entre clavier\n");
    return result;
  }
  result = bor_write_str(soc, buffer);
  if (result <= 0) {
    perror("Erreur a l ecriture\n");
    return result;
  }
  result = bor_read_str(soc, buffer, sizeof(buffer) - 1);
  if (result <= 0) {
    perror("Erreur a la reception du message provenant du serveur\n");
    return result;
  }
  printf("Reponse du serveur : %s\n", buffer);
  return 1;
}


x86 assembly (clang, -O0):
<contact_serv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x8(%rbp)
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x410(%rbp),%rsi
xor    %edi,%edi
mov    $0x3ff,%edx
call   1050 <bor_read_str@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1193 <contact_serv+0x53>
lea    0xe9b(%rip),%rdi
call   1060 <perror@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121a <contact_serv+0xda>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
call   1030 <bor_write_str@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     11c6 <contact_serv+0x86>
lea    0xe8c(%rip),%rdi
call   1060 <perror@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121a <contact_serv+0xda>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1050 <bor_read_str@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     11fe <contact_serv+0xbe>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121a <contact_serv+0xda>
lea    -0x410(%rbp),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<contact_serv>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebp
lea    0xf27(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x3ff,%edx
call   1060 <bor_read_str@plt>
test   %eax,%eax
jle    11bd <contact_serv+0x6d>
mov    %rsp,%rsi
mov    %ebp,%edi
call   1040 <bor_write_str@plt>
test   %eax,%eax
jle    11cd <contact_serv+0x7d>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x3ff,%edx
call   1060 <bor_read_str@plt>
test   %eax,%eax
jle    11dd <contact_serv+0x8d>
lea    0xece(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret
mov    %eax,%ebx
lea    0xe3a(%rip),%rdi
call   1070 <perror@plt>
jmp    11b1 <contact_serv+0x61>
mov    %eax,%ebx
lea    0xe4e(%rip),%rdi
call   1070 <perror@plt>
jmp    11b1 <contact_serv+0x61>
mov    %eax,%ebx
lea    0xe53(%rip),%rdi
call   1070 <perror@plt>
jmp    11b1 <contact_serv+0x61>

LLVM IR (-O0):
@.str = [30 x i8] c"Entrez une suite de digits :\0A\00"
@.str.1 = [36 x i8] c"Erreur ou ctrl+D a l entre clavier\0A\00"
@.str.2 = [21 x i8] c"Erreur a l ecriture\0A\00"
@.str.3 = [55 x i8] c"Erreur a la reception du message provenant du serveur\0A\00"
@.str.4 = [25 x i8] c"Reponse du serveur : %s\0A\00"
define i32 @contact_serv(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i32 %0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = call i32 @bor_read_str(i32 0, i8* %7, i32 1023)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* %4
store i32 %13, i32* %2
br label %35
14: ; preds = %1
%15 = load i32, i32* %3
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = call i32 @bor_write_str(i32 %15, i8* %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* %4
store i32 %22, i32* %2
br label %35
23: ; preds = %14
%24 = load i32, i32* %3
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%26 = call i32 @bor_read_str(i32 %24, i8* %25, i32 1023)
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = icmp sle i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* %4
store i32 %31, i32* %2
br label %35
32: ; preds = %23
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %33)
store i32 1, i32* %2
br label %35
35: ; preds = %32, %29, %20, %11
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str.1 = [36 x i8] c"Erreur ou ctrl+D a l entre clavier\0A\00"
@.str.2 = [21 x i8] c"Erreur a l ecriture\0A\00"
@.str.3 = [55 x i8] c"Erreur a la reception du message provenant du serveur\0A\00"
@.str.4 = [25 x i8] c"Reponse du serveur : %s\0A\00"
@str = [29 x i8] c"Entrez une suite de digits :\00"
define i32 @contact_serv(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%5 = call i32 @bor_read_str(i32 0, i8* %3, i32 1023)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %21
9: ; preds = %1
%10 = call i32 @bor_write_str(i32 %0, i8* %3)
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %21
14: ; preds = %9
%15 = call i32 @bor_read_str(i32 %0, i8* %3, i32 1023)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
br label %21
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %3)
br label %21
21: ; preds = %19, %17, %12, %7
%22 = phi i32 [ %5, %7 ], [ %10, %12 ], [ %15, %17 ], [ 1, %19 ]
ret i32 %22
}