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

/* Variables and functions */
scalar_t__ ferror(int /*<<< orphan*/ *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fuzzy_update(struct fuzzy_state *, unsigned char *, size_t);
int fuzzy_update_stream(struct fuzzy_state *state, FILE *handle) {
  unsigned char buffer[4096];
  size_t n;
  for (;;) {
    n = fread(buffer, 1, 4096, handle);
    if (0 == n)
      break;
    if (fuzzy_update(state, buffer, n) < 0)
      return -1;
  }
  if (ferror(handle) != 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<fuzzy_update_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1050 <fread@plt>
mov    %rax,-0x1028(%rbp)
xor    %eax,%eax
cmp    -0x1028(%rbp),%rax
jne    1178 <fuzzy_update_stream+0x48>
jmp    11aa <fuzzy_update_stream+0x7a>
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x1028(%rbp),%rdx
call   1030 <fuzzy_update@plt>
cmp    $0x0,%rax
jge    11a5 <fuzzy_update_stream+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <fuzzy_update_stream+0xa0>
jmp    1143 <fuzzy_update_stream+0x13>
mov    -0x18(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     11c9 <fuzzy_update_stream+0x99>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <fuzzy_update_stream+0xa0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fuzzy_update_stream>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     1184 <fuzzy_update_stream+0x54>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <fuzzy_update@plt>
test   %rax,%rax
jns    1150 <fuzzy_update_stream+0x20>
mov    $0xffffffff,%eax
jmp    1191 <fuzzy_update_stream+0x61>
mov    %r15,%rdi
call   1040 <ferror@plt>
neg    %rax
sbb    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.fuzzy_state = type { i32 }
define i32 @fuzzy_update_stream(%struct.fuzzy_state* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.fuzzy_state*
%5 = alloca i32*
%6 = alloca [4096 x i8]
%7 = alloca i64
store %struct.fuzzy_state* %0, %struct.fuzzy_state** %4
store i32* %1, i32** %5
br label %8
8: ; preds = %22, %2
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%10 = load i32*, i32** %5
%11 = call i64 @fread(i8* %9, i32 1, i32 4096, i32* %10)
store i64 %11, i64* %7
%12 = load i64, i64* %7
%13 = icmp eq i64 0, %12
br i1 %13, label %14, label %15
14: ; preds = %8
br label %23
15: ; preds = %8
%16 = load %struct.fuzzy_state*, %struct.fuzzy_state** %4
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%18 = load i64, i64* %7
%19 = call i64 @fuzzy_update(%struct.fuzzy_state* %16, i8* %17, i64 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 -1, i32* %3
br label %29
22: ; preds = %15
br label %8
23: ; preds = %14
%24 = load i32*, i32** %5
%25 = call i64 @ferror(i32* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -1, i32* %3
br label %29
28: ; preds = %23
store i32 0, i32* %3
br label %29
29: ; preds = %28, %27, %21
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.fuzzy_state = type { i32 }
define i32 @fuzzy_update_stream(%struct.fuzzy_state* %0, i32* nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %8, %2
%6 = call i64 @fread(i8* %4, i32 1, i32 4096, i32* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = call i64 @fuzzy_update(%struct.fuzzy_state* %0, i8* %4, i64 %6)
%10 = icmp slt i64 %9, 0
br i1 %10, label %15, label %5
11: ; preds = %5
%12 = call i64 @ferror(i32* %1)
%13 = icmp ne i64 %12, 0
%14 = sext i1 %13 to i32
br label %15
15: ; preds = %8, %11
%16 = phi i32 [ %14, %11 ], [ -1, %8 ]
ret i32 %16
}