#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 */
struct bytebuffer {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ bytebuffer_put(struct bytebuffer *, void *, int);
int fread(void *, int, int, int /*<<< orphan*/ *);
void bytebuffer_read(struct bytebuffer *b, FILE *in) {
  char t[1024];
  int i = fread((void *)t, 1, 1024, in);
  while (i > 0 && bytebuffer_put(b, (void *)t, i) == 0) {
    i = fread((void *)t, 1, 1024, in);
  }
}


x86 assembly (clang, -O0):
<bytebuffer_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x414(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x414(%rbp)
mov    %al,-0x415(%rbp)
jle    118b <bytebuffer_read+0x6b>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   1040 <bytebuffer_put@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x415(%rbp)
mov    -0x415(%rbp),%al
test   $0x1,%al
jne    119e <bytebuffer_read+0x7e>
jmp    11c3 <bytebuffer_read+0xa3>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x414(%rbp)
jmp    1153 <bytebuffer_read+0x33>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bytebuffer_read>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    117b <bytebuffer_read+0x5b>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <bytebuffer_put@plt>
test   %rax,%rax
jne    117b <bytebuffer_read+0x5b>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jg     1150 <bytebuffer_read+0x30>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.bytebuffer = type { i32 }
define void @bytebuffer_read(%struct.bytebuffer* %0, i32* %1) {
%3 = alloca %struct.bytebuffer*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i32
store %struct.bytebuffer* %0, %struct.bytebuffer** %3
store i32* %1, i32** %4
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = load i32*, i32** %4
%9 = call i32 @fread(i8* %7, i32 1, i32 1024, i32* %8)
store i32 %9, i32* %6
br label %10
10: ; preds = %21, %2
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load %struct.bytebuffer*, %struct.bytebuffer** %3
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = load i32, i32* %6
%17 = call i64 @bytebuffer_put(%struct.bytebuffer* %14, i8* %15, i32 %16)
%18 = icmp eq i64 %17, 0
br label %19
19: ; preds = %13, %10
%20 = phi i1 [ false, %10 ], [ %18, %13 ]
br i1 %20, label %21, label %25
21: ; preds = %19
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = load i32*, i32** %4
%24 = call i32 @fread(i8* %22, i32 1, i32 1024, i32* %23)
store i32 %24, i32* %6
br label %10
25: ; preds = %19
ret void
}

LLVM IR (-O2):
%struct.bytebuffer = type { i32 }
define void @bytebuffer_read(%struct.bytebuffer* %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @fread(i8* %4, i32 1, i32 1024, i32* %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %2, %11
%8 = phi i32 [ %12, %11 ], [ %5, %2 ]
%9 = call i64 @bytebuffer_put(%struct.bytebuffer* %0, i8* %4, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = call i32 @fread(i8* %4, i32 1, i32 1024, i32* %1)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %7, label %14
14: ; preds = %7, %11, %2
ret void
}