#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*/ off_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ fseeko(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ftello(int /*<<< orphan*/ *);
int fuzzy_hash_stream(int /*<<< orphan*/ *, char *);
int fuzzy_hash_file(FILE *handle, char *result) {
  off_t fpos;
  int status;
  fpos = ftello(handle);
  if (fseek(handle, 0, SEEK_SET) < 0)
    return -1;
  status = fuzzy_hash_stream(handle, result);
  if (status == 0) {
    if (fseeko(handle, fpos, SEEK_SET) < 0)
      return -1;
  }
  return status;
}


x86 assembly (clang, -O0):
<fuzzy_hash_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ftello@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
cmp    $0x0,%rax
jge    1186 <fuzzy_hash_file+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <fuzzy_hash_file+0x96>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <fuzzy_hash_stream@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11d0 <fuzzy_hash_file+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
call   1060 <fseeko@plt>
cmp    $0x0,%rax
jge    11cb <fuzzy_hash_file+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <fuzzy_hash_file+0x96>
jmp    11d0 <fuzzy_hash_file+0x90>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fuzzy_hash_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <ftello@plt>
mov    %eax,%r14d
mov    0x2e83(%rip),%r12
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     119e <fuzzy_hash_file+0x5e>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <fuzzy_hash_stream@plt>
mov    %eax,%r15d
test   %eax,%eax
jne    119b <fuzzy_hash_file+0x5b>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1060 <fseeko@plt>
test   %rax,%rax
js     119e <fuzzy_hash_file+0x5e>
mov    %r15d,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@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 i32
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = load i32*, i32** %4
%9 = call i32 @ftello(i32* %8)
store i32 %9, i32* %6
%10 = load i32*, i32** %4
%11 = load i32, i32* @SEEK_SET
%12 = call i64 @fseek(i32* %10, i32 0, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %31
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = load i8*, i8** %5
%18 = call i32 @fuzzy_hash_stream(i32* %16, i8* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %15
%22 = load i32*, i32** %4
%23 = load i32, i32* %6
%24 = load i32, i32* @SEEK_SET
%25 = call i64 @fseeko(i32* %22, i32 %23, i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 -1, i32* %3
br label %31
28: ; preds = %21
br label %29
29: ; preds = %28, %15
%30 = load i32, i32* %7
store i32 %30, i32* %3
br label %31
31: ; preds = %29, %27, %14
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @fuzzy_hash_file(i32* %0, i8* %1) {
%3 = tail call i32 @ftello(i32* %0)
%4 = load i32, i32* @SEEK_SET
%5 = tail call i64 @fseek(i32* %0, i32 0, i32 %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %2
%8 = tail call i32 @fuzzy_hash_stream(i32* %0, i8* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* @SEEK_SET
%12 = tail call i64 @fseeko(i32* %0, i32 %3, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %10, %7
br label %15
15: ; preds = %10, %2, %14
%16 = phi i32 [ %8, %14 ], [ -1, %2 ], [ -1, %10 ]
ret i32 %16
}