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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *const);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *const, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *const);
uint64_t compute_hash(FILE *const handle) {
  uint64_t hash, file_size, tmp, i;
  fseek(handle, 0, SEEK_END);
  file_size = ftell(handle);
  hash = file_size;
  fseek(handle, 0, SEEK_SET);
  for (tmp = 0, i = 0;
       i < 65536 / sizeof(tmp) && fread((char *)&tmp, sizeof(tmp), 1, handle);
       hash += tmp, ++i)
    ;
  fseek(handle, (long)((0 > file_size - 65536) ? (0) : (file_size - 65536)),
        SEEK_SET);
  for (tmp = 0, i = 0;
       i < 65536 / sizeof(tmp) && fread((char *)&tmp, sizeof(tmp), 1, handle);
       hash += tmp, ++i)
    ;
  return hash;
}


x86 assembly (clang, -O0):
<compute_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1050 <fseek@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    $0x4000,%rcx
mov    %al,-0x19(%rbp)
jae    11bf <compute_hash+0x8f>
lea    -0x14(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11cf <compute_hash+0x9f>
jmp    11eb <compute_hash+0xbb>
jmp    11d4 <compute_hash+0xa4>
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1188 <compute_hash+0x58>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%ecx
sub    $0x10000,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jle    1210 <compute_hash+0xe0>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    121b <compute_hash+0xeb>
mov    -0x10(%rbp),%eax
sub    $0x10000,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%eax
movslq %eax,%rsi
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    $0x4000,%rcx
mov    %al,-0x2d(%rbp)
jae    1278 <compute_hash+0x148>
lea    -0x14(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1288 <compute_hash+0x158>
jmp    12a4 <compute_hash+0x174>
jmp    128d <compute_hash+0x15d>
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1241 <compute_hash+0x111>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_hash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
mov    0x2ea3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %r13,%rdi
call   1040 <ftell@plt>
mov    %eax,%r14d
mov    0x2e78(%rip),%r12
mov    (%r12),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
movl   $0x0,0x4(%rsp)
mov    $0x4000,%ebx
lea    0x4(%rsp),%r15
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11b3 <compute_hash+0x83>
add    0x4(%rsp),%ebp
add    $0xffffffff,%ebx
jne    1190 <compute_hash+0x60>
cmp    $0x10001,%r14d
mov    $0x10000,%esi
cmovge %r14d,%esi
add    $0xffff0000,%esi
mov    (%r12),%edx
mov    %r13,%rdi
call   1050 <fseek@plt>
movl   $0x0,0x4(%rsp)
mov    $0x4000,%ebx
lea    0x4(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1213 <compute_hash+0xe3>
add    0x4(%rsp),%ebp
add    $0xffffffff,%ebx
jne    11f0 <compute_hash+0xc0>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @compute_hash(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = load i32, i32* @SEEK_END
%9 = call i32 @fseek(i32* %7, i64 0, i32 %8)
%10 = load i32*, i32** %2
%11 = call i32 @ftell(i32* %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
store i32 %12, i32* %3
%13 = load i32*, i32** %2
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @fseek(i32* %13, i64 0, i32 %14)
store i32 0, i32* %5
store i32 0, i32* %6
br label %16
16: ; preds = %28, %1
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = icmp ult i64 %18, 16384
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = bitcast i32* %5 to i8*
%22 = load i32*, i32** %2
%23 = call i64 @fread(i8* %21, i32 4, i32 1, i32* %22)
%24 = icmp ne i64 %23, 0
br label %25
25: ; preds = %20, %16
%26 = phi i1 [ false, %16 ], [ %24, %20 ]
br i1 %26, label %27, label %34
27: ; preds = %25
br label %28
28: ; preds = %27
%29 = load i32, i32* %5
%30 = load i32, i32* %3
%31 = add nsw i32 %30, %29
store i32 %31, i32* %3
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %16
34: ; preds = %25
%35 = load i32*, i32** %2
%36 = load i32, i32* %4
%37 = sub nsw i32 %36, 65536
%38 = icmp sgt i32 0, %37
br i1 %38, label %39, label %40
39: ; preds = %34
br label %43
40: ; preds = %34
%41 = load i32, i32* %4
%42 = sub nsw i32 %41, 65536
br label %43
43: ; preds = %40, %39
%44 = phi i32 [ 0, %39 ], [ %42, %40 ]
%45 = sext i32 %44 to i64
%46 = load i32, i32* @SEEK_SET
%47 = call i32 @fseek(i32* %35, i64 %45, i32 %46)
store i32 0, i32* %5
store i32 0, i32* %6
br label %48
48: ; preds = %60, %43
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = icmp ult i64 %50, 16384
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = bitcast i32* %5 to i8*
%54 = load i32*, i32** %2
%55 = call i64 @fread(i8* %53, i32 4, i32 1, i32* %54)
%56 = icmp ne i64 %55, 0
br label %57
57: ; preds = %52, %48
%58 = phi i1 [ false, %48 ], [ %56, %52 ]
br i1 %58, label %59, label %66
59: ; preds = %57
br label %60
60: ; preds = %59
%61 = load i32, i32* %5
%62 = load i32, i32* %3
%63 = add nsw i32 %62, %61
store i32 %63, i32* %3
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %48
66: ; preds = %57
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @compute_hash(i32* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @fseek(i32* %0, i64 0, i32 %4)
%6 = tail call i32 @ftell(i32* %0)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %0, i64 0, i32 %7)
store i32 0, i32* %2
br label %9
9: ; preds = %1, %14
%10 = phi i32 [ 0, %1 ], [ %17, %14 ]
%11 = phi i32 [ %6, %1 ], [ %16, %14 ]
%12 = call i64 @fread(i8* %3, i32 4, i32 1, i32* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = load i32, i32* %2
%16 = add nsw i32 %15, %11
%17 = add nuw nsw i32 %10, 1
%18 = icmp eq i32 %17, 16384
br i1 %18, label %19, label %9
19: ; preds = %14, %9
%20 = phi i32 [ %16, %14 ], [ %11, %9 ]
%21 = icmp sgt i32 %6, 65536
%22 = select i1 %21, i32 %6, i32 65536
%23 = add nsw i32 %22, -65536
%24 = zext i32 %23 to i64
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %0, i64 %24, i32 %25)
store i32 0, i32* %2
br label %27
27: ; preds = %19, %32
%28 = phi i32 [ 0, %19 ], [ %35, %32 ]
%29 = phi i32 [ %20, %19 ], [ %34, %32 ]
%30 = call i64 @fread(i8* %3, i32 4, i32 1, i32* %0)
%31 = icmp eq i64 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = load i32, i32* %2
%34 = add nsw i32 %33, %29
%35 = add nuw nsw i32 %28, 1
%36 = icmp eq i32 %35, 16384
br i1 %36, label %37, label %27
37: ; preds = %32, %27
%38 = phi i32 [ %34, %32 ], [ %29, %27 ]
ret i32 %38
}