#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 /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ error(char *);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int read_from(int sock, char *buffer, int buf_len) {
  int bytes_read;
  int backoff = 0;
  bzero(buffer, buf_len);
  while ((bytes_read = read(sock, buffer, buf_len)) <= 0) {
    sleep(100);
    if (backoff > 3)
      return 0;
    else
      backoff++;
    ;
  }
  if (bytes_read < 0)
    error("error while reading");
  return bytes_read;
}


x86 assembly (clang, -O0):
<read_from>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <bzero@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jg     11ae <read_from+0x6e>
mov    $0x64,%edi
call   1060 <sleep@plt>
cmpl   $0x3,-0x1c(%rbp)
jle    11a0 <read_from+0x60>
movl   $0x0,-0x4(%rbp)
jmp    11ca <read_from+0x8a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1165 <read_from+0x25>
cmpl   $0x0,-0x18(%rbp)
jge    11c4 <read_from+0x84>
lea    0xe41(%rip),%rdi
call   1040 <error@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_from>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
mov    %edx,%esi
call   1040 <bzero@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <read@plt>
test   %eax,%eax
jg     11cf <read_from+0x9f>
mov    $0x64,%edi
call   1050 <sleep@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <read@plt>
test   %eax,%eax
jg     11cf <read_from+0x9f>
mov    $0x64,%edi
call   1050 <sleep@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <read@plt>
test   %eax,%eax
jg     11cf <read_from+0x9f>
mov    $0x64,%edi
call   1050 <sleep@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <read@plt>
test   %eax,%eax
jg     11cf <read_from+0x9f>
mov    $0x64,%edi
call   1050 <sleep@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <read@plt>
test   %eax,%eax
jg     11cf <read_from+0x9f>
mov    $0x64,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"error while reading\00"
define i32 @read_from(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %9
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i32 @bzero(i8* %10, i32 %11)
br label %13
13: ; preds = %27, %3
%14 = load i32, i32* %5
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = call i32 @read(i32 %14, i8* %15, i32 %16)
store i32 %17, i32* %8
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %13
%20 = call i32 @sleep(i32 100)
%21 = load i32, i32* %9
%22 = icmp sgt i32 %21, 3
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 0, i32* %4
br label %35
24: ; preds = %19
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
store i32 %26, i32* %9
br label %27
27: ; preds = %24
br label %13
28: ; preds = %13
%29 = load i32, i32* %8
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = load i32, i32* %8
store i32 %34, i32* %4
br label %35
35: ; preds = %33, %23
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @read_from(i32 %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @bzero(i8* %1, i32 %2)
%5 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %25
7: ; preds = %3
%8 = tail call i32 @sleep(i32 100)
%9 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %25
11: ; preds = %7
%12 = tail call i32 @sleep(i32 100)
%13 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = tail call i32 @sleep(i32 100)
%17 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = tail call i32 @sleep(i32 100)
%21 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = tail call i32 @sleep(i32 100)
br label %25
25: ; preds = %7, %11, %15, %19, %23, %3
%26 = phi i32 [ %5, %3 ], [ %9, %7 ], [ %13, %11 ], [ %17, %15 ], [ %21, %19 ], [ 0, %23 ]
ret i32 %26
}