#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__ fuzzy_digest(struct fuzzy_state *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fuzzy_free(struct fuzzy_state *);
struct fuzzy_state *fuzzy_new();
scalar_t__ fuzzy_update_stream(struct fuzzy_state *, int /*<<< orphan*/ *);
int fuzzy_hash_stream(FILE *handle, char *result) {
  struct fuzzy_state *ctx;
  int ret = -1;
  if (NULL == (ctx = fuzzy_new()))
    return -1;
  if (fuzzy_update_stream(ctx, handle) < 0)
    goto out;
  if (fuzzy_digest(ctx, result, 0) < 0)
    goto out;
  ret = 0;
out:
  fuzzy_free(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<fuzzy_hash_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    $0x0,%al
call   1050 <fuzzy_new@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    117c <fuzzy_hash_stream+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <fuzzy_hash_stream+0x8c>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fuzzy_update_stream@plt>
cmp    $0x0,%rax
jge    1198 <fuzzy_hash_stream+0x58>
jmp    11bd <fuzzy_hash_stream+0x7d>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1060 <fuzzy_digest@plt>
cmp    $0x0,%rax
jge    11b6 <fuzzy_hash_stream+0x76>
jmp    11bd <fuzzy_hash_stream+0x7d>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fuzzy_free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fuzzy_hash_stream>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <fuzzy_new@plt>
test   %rax,%rax
je     1180 <fuzzy_hash_stream+0x40>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <fuzzy_update_stream@plt>
test   %rax,%rax
js     1188 <fuzzy_hash_stream+0x48>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <fuzzy_digest@plt>
mov    %rax,%r14
sar    $0x3f,%r14
jmp    118e <fuzzy_hash_stream+0x4e>
mov    $0xffffffff,%r14d
jmp    1196 <fuzzy_hash_stream+0x56>
mov    $0xffffffff,%r14d
mov    %rbx,%rdi
call   1030 <fuzzy_free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.fuzzy_state = type { i32 }
define i32 @fuzzy_hash_stream(i32* %0, i8* %1) {
%3 = tail call %struct.fuzzy_state* (...) @fuzzy_new()
%4 = icmp eq %struct.fuzzy_state* %3, null
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = tail call i64 @fuzzy_update_stream(%struct.fuzzy_state* %3, i32* %0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call i64 @fuzzy_digest(%struct.fuzzy_state* %3, i8* %1, i32 0)
%10 = ashr i64 %9, 63
%11 = trunc i64 %10 to i32
br label %12
12: ; preds = %8, %5
%13 = phi i32 [ -1, %5 ], [ %11, %8 ]
%14 = tail call i32 @fuzzy_free(%struct.fuzzy_state* %3)
br label %15
15: ; preds = %2, %12
%16 = phi i32 [ %13, %12 ], [ -1, %2 ]
ret i32 %16
}