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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ fseeko(int /*<<< orphan*/ *, scalar_t__, int /*<<< orphan*/);
scalar_t__ ftello(int /*<<< orphan*/ *);
int fuzzy_digest(struct fuzzy_state *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fuzzy_free(struct fuzzy_state *);
struct fuzzy_state *fuzzy_new();
scalar_t__ fuzzy_set_total_input_length(struct fuzzy_state *,
                                        int /*<<< orphan*/);
scalar_t__ fuzzy_update_stream(struct fuzzy_state *, int /*<<< orphan*/ *);
int fuzzy_hash_file(FILE *handle, char *result) {
  off_t fpos, fposend;
  int status = -1;
  struct fuzzy_state *ctx;
  fpos = ftello(handle);
  if (fpos < 0)
    return -1;
  if (fseeko(handle, 0, SEEK_END) < 0)
    return -1;
  fposend = ftello(handle);
  if (fposend < 0)
    return -1;
  if (fseeko(handle, 0, SEEK_SET) < 0)
    return -1;
  if (NULL == (ctx = fuzzy_new()))
    return -1;
  if (fuzzy_set_total_input_length(ctx, (uint_least64_t)fposend) < 0)
    goto out;
  if (fuzzy_update_stream(ctx, handle) < 0)
    goto out;
  status = fuzzy_digest(ctx, result, 0);
out:
  if (status == 0) {
    if (fseeko(handle, fpos, SEEK_SET) < 0)
      return -1;
  }
  fuzzy_free(ctx);
  return status;
}


x86 assembly (clang, -O0):
<fuzzy_hash_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ftello@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11ab <fuzzy_hash_file+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e2 <fuzzy_hash_file+0x172>
mov    -0x10(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <fseeko@plt>
cmp    $0x0,%rax
jge    11d7 <fuzzy_hash_file+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e2 <fuzzy_hash_file+0x172>
mov    -0x10(%rbp),%rdi
call   1040 <ftello@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    11fb <fuzzy_hash_file+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e2 <fuzzy_hash_file+0x172>
mov    -0x10(%rbp),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <fseeko@plt>
cmp    $0x0,%rax
jge    1227 <fuzzy_hash_file+0xb7>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e2 <fuzzy_hash_file+0x172>
mov    $0x0,%al
call   1070 <fuzzy_new@plt>
mov    %rax,%rcx
mov    %rcx,-0x38(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    124c <fuzzy_hash_file+0xdc>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e2 <fuzzy_hash_file+0x172>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    %eax,%esi
call   1090 <fuzzy_set_total_input_length@plt>
cmp    $0x0,%rax
jge    126a <fuzzy_hash_file+0xfa>
jmp    1298 <fuzzy_hash_file+0x128>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fuzzy_update_stream@plt>
cmp    $0x0,%rax
jge    1286 <fuzzy_hash_file+0x116>
jmp    1298 <fuzzy_hash_file+0x128>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1080 <fuzzy_digest@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    12d3 <fuzzy_hash_file+0x163>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2d27(%rip),%rax
mov    (%rax),%edx
call   1060 <fseeko@plt>
cmp    $0x0,%rax
jge    12ce <fuzzy_hash_file+0x15e>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e2 <fuzzy_hash_file+0x172>
jmp    12d3 <fuzzy_hash_file+0x163>
mov    -0x38(%rbp),%rdi
call   1030 <fuzzy_free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fuzzy_hash_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <ftello@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     124c <fuzzy_hash_file+0xdc>
mov    %rax,%r14
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseeko@plt>
test   %rax,%rax
js     124c <fuzzy_hash_file+0xdc>
mov    %rbx,%rdi
call   1040 <ftello@plt>
test   %rax,%rax
js     124c <fuzzy_hash_file+0xdc>
mov    %rax,%r13
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseeko@plt>
test   %rax,%rax
js     124c <fuzzy_hash_file+0xdc>
xor    %eax,%eax
call   1070 <fuzzy_new@plt>
test   %rax,%rax
je     124c <fuzzy_hash_file+0xdc>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r13d,%esi
call   1090 <fuzzy_set_total_input_length@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     1244 <fuzzy_hash_file+0xd4>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <fuzzy_update_stream@plt>
test   %rax,%rax
js     1244 <fuzzy_hash_file+0xd4>
mov    %r12,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1080 <fuzzy_digest@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1244 <fuzzy_hash_file+0xd4>
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <fseeko@plt>
mov    $0x0,%ebp
test   %rax,%rax
js     125d <fuzzy_hash_file+0xed>
mov    %r12,%rdi
call   1030 <fuzzy_free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%ebp
jmp    124c <fuzzy_hash_file+0xdc>

LLVM IR (-O0):
%struct.fuzzy_state = type { i32 }
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @fuzzy_hash_file(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca %struct.fuzzy_state*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 -1, i32* %8
%10 = load i32*, i32** %4
%11 = call i64 @ftello(i32* %10)
store i64 %11, i64* %6
%12 = load i64, i64* %6
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %69
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = load i32, i32* @SEEK_END
%18 = call i64 @fseeko(i32* %16, i64 0, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 -1, i32* %3
br label %69
21: ; preds = %15
%22 = load i32*, i32** %4
%23 = call i64 @ftello(i32* %22)
store i64 %23, i64* %7
%24 = load i64, i64* %7
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -1, i32* %3
br label %69
27: ; preds = %21
%28 = load i32*, i32** %4
%29 = load i32, i32* @SEEK_SET
%30 = call i64 @fseeko(i32* %28, i64 0, i32 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 -1, i32* %3
br label %69
33: ; preds = %27
%34 = call %struct.fuzzy_state* (...) @fuzzy_new()
store %struct.fuzzy_state* %34, %struct.fuzzy_state** %9
%35 = icmp eq %struct.fuzzy_state* null, %34
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 -1, i32* %3
br label %69
37: ; preds = %33
%38 = load %struct.fuzzy_state*, %struct.fuzzy_state** %9
%39 = load i64, i64* %7
%40 = trunc i64 %39 to i32
%41 = call i64 @fuzzy_set_total_input_length(%struct.fuzzy_state* %38, i32 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %37
br label %54
44: ; preds = %37
%45 = load %struct.fuzzy_state*, %struct.fuzzy_state** %9
%46 = load i32*, i32** %4
%47 = call i64 @fuzzy_update_stream(%struct.fuzzy_state* %45, i32* %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %44
br label %54
50: ; preds = %44
%51 = load %struct.fuzzy_state*, %struct.fuzzy_state** %9
%52 = load i8*, i8** %5
%53 = call i32 @fuzzy_digest(%struct.fuzzy_state* %51, i8* %52, i32 0)
store i32 %53, i32* %8
br label %54
54: ; preds = %50, %49, %43
%55 = load i32, i32* %8
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %65
57: ; preds = %54
%58 = load i32*, i32** %4
%59 = load i64, i64* %6
%60 = load i32, i32* @SEEK_SET
%61 = call i64 @fseeko(i32* %58, i64 %59, i32 %60)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %57
store i32 -1, i32* %3
br label %69
64: ; preds = %57
br label %65
65: ; preds = %64, %54
%66 = load %struct.fuzzy_state*, %struct.fuzzy_state** %9
%67 = call i32 @fuzzy_free(%struct.fuzzy_state* %66)
%68 = load i32, i32* %8
store i32 %68, i32* %3
br label %69
69: ; preds = %65, %63, %36, %32, %26, %20, %14
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
%struct.fuzzy_state = type { i32 }
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @fuzzy_hash_file(i32* %0, i8* %1) {
%3 = tail call i64 @ftello(i32* %0)
%4 = icmp slt i64 %3, 0
br i1 %4, label %36, label %5
5: ; preds = %2
%6 = load i32, i32* @SEEK_END
%7 = tail call i64 @fseeko(i32* %0, i64 0, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %36, label %9
9: ; preds = %5
%10 = tail call i64 @ftello(i32* %0)
%11 = icmp slt i64 %10, 0
br i1 %11, label %36, label %12
12: ; preds = %9
%13 = load i32, i32* @SEEK_SET
%14 = tail call i64 @fseeko(i32* %0, i64 0, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %36, label %16
16: ; preds = %12
%17 = tail call %struct.fuzzy_state* (...) @fuzzy_new()
%18 = icmp eq %struct.fuzzy_state* %17, null
br i1 %18, label %36, label %19
19: ; preds = %16
%20 = trunc i64 %10 to i32
%21 = tail call i64 @fuzzy_set_total_input_length(%struct.fuzzy_state* %17, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %33, label %23
23: ; preds = %19
%24 = tail call i64 @fuzzy_update_stream(%struct.fuzzy_state* %17, i32* %0)
%25 = icmp slt i64 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = tail call i32 @fuzzy_digest(%struct.fuzzy_state* %17, i8* %1, i32 0)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* @SEEK_SET
%31 = tail call i64 @fseeko(i32* %0, i64 %3, i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %23, %19, %29, %26
%34 = phi i32 [ 0, %29 ], [ %27, %26 ], [ -1, %19 ], [ -1, %23 ]
%35 = tail call i32 @fuzzy_free(%struct.fuzzy_state* %17)
br label %36
36: ; preds = %29, %16, %12, %9, %5, %2, %33
%37 = phi i32 [ %34, %33 ], [ -1, %2 ], [ -1, %5 ], [ -1, %9 ], [ -1, %12 ], [ -1, %16 ], [ -1, %29 ]
ret i32 %37
}