#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 read(int, void *, int);
int ricevi_opzione(int id_connessione, char *buffer_r) {
  int count = 0;
  int byte_letti = 0;
  void *buffer = buffer_r;
  int dimensione = sizeof(char);
  while (count < dimensione) {
    if ((byte_letti = read(id_connessione, buffer, dimensione - count)) > 0) {
      count += byte_letti;
      buffer += byte_letti;
    } else
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ricevi_opzione>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1196 <ricevi_opzione+0x86>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
sub    -0x14(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    1185 <ricevi_opzione+0x75>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1191 <ricevi_opzione+0x81>
movl   $0x1,-0x4(%rbp)
jmp    119d <ricevi_opzione+0x8d>
jmp    113c <ricevi_opzione+0x2c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ricevi_opzione>:
push   %rax
mov    $0x1,%edx
call   1030 <read@plt>
xor    %ecx,%ecx
test   %eax,%eax
setle  %cl
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @ricevi_opzione(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
%10 = load i8*, i8** %5
store i8* %10, i8** %8
store i32 1, i32* %9
br label %11
11: ; preds = %32, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %9
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = load i32, i32* %4
%17 = load i8*, i8** %8
%18 = load i32, i32* %9
%19 = load i32, i32* %6
%20 = sub nsw i32 %18, %19
%21 = call i32 @read(i32 %16, i8* %17, i32 %20)
store i32 %21, i32* %7
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %15
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = add nsw i32 %25, %24
store i32 %26, i32* %6
%27 = load i32, i32* %7
%28 = load i8*, i8** %8
%29 = sext i32 %27 to i64
%30 = getelementptr i8, i8* %28, i64 %29
store i8* %30, i8** %8
br label %32
31: ; preds = %15
store i32 1, i32* %3
br label %34
32: ; preds = %23
br label %11
33: ; preds = %11
store i32 0, i32* %3
br label %34
34: ; preds = %33, %31
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @ricevi_opzione(i32 %0, i8* nocapture %1) {
%3 = tail call i32 @read(i32 %0, i8* %1, i32 1)
%4 = icmp slt i32 %3, 1
%5 = zext i1 %4 to i32
ret i32 %5
}