#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
scalar_t__ ceil(double);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, unsigned long long,
                         int /*<<< orphan*/);
void *malloc(int);
int /*<<< orphan*/ sha256(unsigned char *, int, unsigned char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
char *treehash(char *fname, unsigned long long start, unsigned long long end) {
  FILE *f = NULL;
  unsigned char buffer[1048576];
  assert(start % 1048576 == 0);
  f = fopen(fname, "rb");
  assert(f != NULL);
  fseek(f, start, SEEK_SET);
  long long nr_bytes = end - start + 1;
  unsigned int nr_blocks = ((unsigned int)(ceil(((double)nr_bytes) / 1048576)));
  unsigned char *digests = malloc(nr_blocks * 32);
  size_t nr_read;
  int offset = 0;
  unsigned int bytes_to_process_here = 0;
  while (1) {
    if (nr_bytes == 0)
      break;
    if (nr_bytes >= 1048576)
      bytes_to_process_here = 1048576;
    else
      bytes_to_process_here = nr_bytes;
    nr_read = fread(buffer, 1, bytes_to_process_here, f);
    if (nr_read == 0)
      break;
    sha256(buffer, bytes_to_process_here, &digests[offset * 32]);
    offset++;
    nr_bytes -= bytes_to_process_here;
  }
  fclose(f);
  assert(nr_bytes == 0);
  int nr_blocks_left = nr_blocks;
  unsigned char *next_tmp = malloc(nr_blocks * 32);
  while (nr_blocks_left > 1) {
    int pairs_to_process = nr_blocks_left / 2;
    for (unsigned int k = 0; k < pairs_to_process; k++)
      sha256(&digests[2 * k * 32], 2 * 32, &next_tmp[k * 32]);
    for (int i = 0; i < pairs_to_process * 32; i++)
      digests[i] = next_tmp[i];
    if (nr_blocks_left % 2 == 1) {
      for (int i = 0; i < 32; i++)
        digests[pairs_to_process * 32 + i] =
            digests[(nr_blocks_left - 1) * 32 + i];
    }
    if (nr_blocks_left % 2 == 0)
      nr_blocks_left = pairs_to_process;
    else
      nr_blocks_left = pairs_to_process + 1;
  }
  char *result = malloc(2 * 32);
  assert(result != 0);
  for (int i = 0; i < 32; i++)
    sprintf(&result[2 * i], "%02x", digests[i]);
  free(digests);
  free(next_tmp);
  return (result);
}


x86 assembly (clang, -O0):
<treehash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100080,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
and    $0xfffff,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x100028(%rbp)
cvtsi2sdq -0x100028(%rbp),%xmm0
ef ff
movsd  0xdc6(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <ceil@plt>
mov    %eax,-0x10002c(%rbp)
mov    -0x10002c(%rbp),%edi
shl    $0x5,%edi
call   1090 <malloc@plt>
mov    %rax,-0x100038(%rbp)
movl   $0x0,-0x100044(%rbp)
movl   $0x0,-0x100048(%rbp)
cmpq   $0x0,-0x100028(%rbp)
jne    1285 <treehash+0xe5>
jmp    133b <treehash+0x19b>
cmpq   $0x100000,-0x100028(%rbp)
jl     12a5 <treehash+0x105>
movl   $0x100000,-0x100048(%rbp)
jmp    12b2 <treehash+0x112>
mov    -0x100028(%rbp),%rax
mov    %eax,-0x100048(%rbp)
lea    -0x100020(%rbp),%rdi
mov    -0x100048(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x100040(%rbp)
cmpq   $0x0,-0x100040(%rbp)
jne    12e7 <treehash+0x147>
jmp    133b <treehash+0x19b>
lea    -0x100020(%rbp),%rdi
mov    -0x100048(%rbp),%esi
mov    -0x100038(%rbp),%rdx
mov    -0x100044(%rbp),%eax
shl    $0x5,%eax
cltq
add    %rax,%rdx
call   1070 <sha256@plt>
mov    -0x100044(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x100044(%rbp)
mov    -0x100048(%rbp),%eax
mov    %eax,%ecx
mov    -0x100028(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x100028(%rbp)
jmp    1272 <treehash+0xd2>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
cmpq   $0x0,-0x100028(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10002c(%rbp),%eax
mov    %eax,-0x10004c(%rbp)
mov    -0x10002c(%rbp),%edi
shl    $0x5,%edi
call   1090 <malloc@plt>
mov    %rax,-0x100058(%rbp)
cmpl   $0x1,-0x10004c(%rbp)
jle    1517 <treehash+0x377>
mov    -0x10004c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10005c(%rbp)
movl   $0x0,-0x100060(%rbp)
mov    -0x100060(%rbp),%eax
cmp    -0x10005c(%rbp),%eax
jae    1402 <treehash+0x262>
mov    -0x100038(%rbp),%rdi
mov    -0x100060(%rbp),%eax
shl    $0x1,%eax
shl    $0x5,%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x100058(%rbp),%rdx
mov    -0x100060(%rbp),%eax
shl    $0x5,%eax
mov    %eax,%eax
add    %rax,%rdx
mov    $0x40,%esi
call   1070 <sha256@plt>
mov    -0x100060(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x100060(%rbp)
jmp    13a5 <treehash+0x205>
movl   $0x0,-0x100064(%rbp)
mov    -0x100064(%rbp),%eax
mov    -0x10005c(%rbp),%ecx
shl    $0x5,%ecx
cmp    %ecx,%eax
jge    1459 <treehash+0x2b9>
mov    -0x100058(%rbp),%rax
movslq -0x100064(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x100038(%rbp),%rax
movslq -0x100064(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x100064(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x100064(%rbp)
jmp    140c <treehash+0x26c>
mov    -0x10004c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    14db <treehash+0x33b>
movl   $0x0,-0x100068(%rbp)
cmpl   $0x20,-0x100068(%rbp)
jge    14d6 <treehash+0x336>
mov    -0x100038(%rbp),%rax
mov    -0x10004c(%rbp),%ecx
sub    $0x1,%ecx
shl    $0x5,%ecx
add    -0x100068(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x100038(%rbp),%rax
mov    -0x10005c(%rbp),%ecx
shl    $0x5,%ecx
add    -0x100068(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x100068(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x100068(%rbp)
jmp    147a <treehash+0x2da>
jmp    14db <treehash+0x33b>
mov    -0x10004c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1503 <treehash+0x363>
mov    -0x10005c(%rbp),%eax
mov    %eax,-0x10004c(%rbp)
jmp    1512 <treehash+0x372>
mov    -0x10005c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10004c(%rbp)
jmp    137a <treehash+0x1da>
mov    $0x40,%edi
call   1090 <malloc@plt>
mov    %rax,-0x100070(%rbp)
cmpq   $0x0,-0x100070(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
movl   $0x0,-0x100074(%rbp)
cmpl   $0x20,-0x100074(%rbp)
jge    159b <treehash+0x3fb>
mov    -0x100070(%rbp),%rdi
mov    -0x100074(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x100038(%rbp),%rax
movslq -0x100074(%rbp),%rcx
lea    0xa8d(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   10c0 <sprintf@plt>
mov    -0x100074(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x100074(%rbp)
jmp    1547 <treehash+0x3a7>
mov    -0x100038(%rbp),%rdi
call   1030 <free@plt>
mov    -0x100058(%rbp),%rdi
call   1030 <free@plt>
mov    -0x100070(%rbp),%rax
add    $0x100080,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<treehash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100028,%rsp
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r14
xor    %edi,%edi
test   $0xfffff,%ebp
sete   %dil
call   1080 <assert@plt>
lea    0xe26(%rip),%rsi
mov    %r14,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1080 <assert@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%r13
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <fseek@plt>
sub    %rbp,%r15
lea    0x1(%r15),%rax
cvtsi2sd %rax,%xmm0
mulsd  0xdda(%rip),%xmm0
call   1050 <ceil@plt>
mov    %rax,%rbx
mov    %ebx,%ebp
shl    $0x5,%ebp
mov    %ebp,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    $0x1,%r12d
inc    %r15
je     12c4 <treehash+0x114>
mov    %ebp,0x8(%rsp)
mov    %rbx,0x10(%rsp)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x100000,%r15
mov    %r15d,%r12d
mov    $0x100000,%eax
cmovge %eax,%r12d
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12b1 <treehash+0x101>
mov    %ebp,%edx
and    $0xffffffe0,%edx
add    %r14,%rdx
lea    0x20(%rsp),%rdi
mov    %r12d,%esi
call   1070 <sha256@plt>
mov    %r12d,%eax
add    $0x20,%rbp
sub    %rax,%r15
jne    1260 <treehash+0xb0>
xor    %r12d,%r12d
test   %rbx,%rbx
setne  %r12b
mov    0x10(%rsp),%rbx
mov    0x8(%rsp),%ebp
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    %r12d,%edi
call   1080 <assert@plt>
mov    %ebp,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
cmp    $0x2,%ebx
jl     1421 <treehash+0x271>
lea    0x20(%r14),%rax
mov    %rax,0x8(%rsp)
lea    0x3(%r14),%rax
mov    %rax,0x18(%rsp)
jmp    132a <treehash+0x17a>
movups (%r14,%rcx,1),%xmm0
movups %xmm0,(%r14,%rax,1)
or     $0x10,%rcx
movupd (%r14,%rcx,1),%xmm0
or     $0x10,%rax
movupd %xmm0,(%r14,%rax,1)
add    $0x1,%r12d
mov    %r12d,%ebx
cmp    $0x1,%r12d
jle    1421 <treehash+0x271>
mov    %ebx,%ebp
shr    %ebp
mov    %rbp,0x10(%rsp)
xor    %r12d,%r12d
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    %r12d,%edi
and    $0xffffffc0,%edi
add    %r14,%rdi
mov    %r13d,%edx
and    $0xffffffe0,%edx
add    %r15,%rdx
mov    $0x40,%esi
call   1070 <sha256@plt>
add    $0x20,%r13
add    $0x40,%r12
add    $0xffffffffffffffff,%rbp
jne    1340 <treehash+0x190>
mov    0x10(%rsp),%r12
mov    %r12d,%ebp
shl    $0x5,%ebp
cmp    $0x2,%ebp
mov    $0x1,%edx
cmovae %ebp,%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <memcpy@plt>
mov    %ebx,%ecx
shr    $0x1f,%ecx
add    %ebx,%ecx
and    $0xfffffffe,%ecx
mov    %ebx,%eax
sub    %ecx,%eax
je     131d <treehash+0x16d>
cmp    $0x1,%eax
jne    1319 <treehash+0x169>
shl    $0x5,%ebx
add    $0xffffffe0,%ebx
movslq %ebx,%rcx
mov    %ebp,%eax
lea    (%r14,%rax,1),%rdx
mov    0x8(%rsp),%rdi
lea    (%rdi,%rcx,1),%rsi
cmp    %rsi,%rdx
jae    12fb <treehash+0x14b>
lea    (%rdi,%rax,1),%rdx
lea    (%r14,%rcx,1),%rsi
cmp    %rdx,%rsi
jae    12fb <treehash+0x14b>
mov    0x18(%rsp),%rdx
add    %rdx,%rcx
add    %rdx,%rax
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
movzbl -0x3(%rcx,%rdx,1),%ebx
mov    %bl,-0x3(%rax,%rdx,1)
movzbl -0x2(%rcx,%rdx,1),%ebx
mov    %bl,-0x2(%rax,%rdx,1)
movzbl -0x1(%rcx,%rdx,1),%ebx
mov    %bl,-0x1(%rax,%rdx,1)
movzbl (%rcx,%rdx,1),%ebx
mov    %bl,(%rax,%rdx,1)
add    $0x4,%rdx
cmp    $0x20,%rdx
jne    13f0 <treehash+0x240>
jmp    1319 <treehash+0x169>
mov    $0x40,%edi
call   10a0 <malloc@plt>
mov    %rax,%r13
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1080 <assert@plt>
xor    %ebx,%ebx
lea    0xbc6(%rip),%r12
mov    %r13,%rbp
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%edx
mov    %rbp,%rdi
mov    %r12,%rsi
call   10d0 <sprintf@plt>
add    $0x1,%rbx
add    $0x2,%rbp
cmp    $0x20,%rbx
jne    1450 <treehash+0x2a0>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13,%rax
add    $0x100028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
@.str.1 = [5 x i8] c"%02x\00"
define i8* @treehash(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32*
%8 = alloca [1048576 x i8]
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i8*
%22 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store i32* null, i32** %7
%23 = load i64, i64* %5
%24 = urem i64 %23, 1048576
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i8*, i8** %4
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %7
%30 = load i32*, i32** %7
%31 = icmp ne i32* %30, null
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i32*, i32** %7
%35 = load i64, i64* %5
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @fseek(i32* %34, i64 %35, i32 %36)
%38 = load i64, i64* %6
%39 = load i64, i64* %5
%40 = sub i64 %38, %39
%41 = add i64 %40, 1
store i64 %41, i64* %9
%42 = load i64, i64* %9
%43 = sitofp i64 %42 to double
%44 = fdiv double %43, 0x4130000000000000
%45 = call i64 @ceil(double %44)
%46 = trunc i64 %45 to i32
store i32 %46, i32* %10
%47 = load i32, i32* %10
%48 = mul i32 %47, 32
%49 = call i8* @malloc(i32 %48)
store i8* %49, i8** %11
store i32 0, i32* %13
store i32 0, i32* %14
br label %50
50: ; preds = %3, %69
%51 = load i64, i64* %9
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %50
br label %84
54: ; preds = %50
%55 = load i64, i64* %9
%56 = icmp sge i64 %55, 1048576
br i1 %56, label %57, label %58
57: ; preds = %54
store i32 1048576, i32* %14
br label %61
58: ; preds = %54
%59 = load i64, i64* %9
%60 = trunc i64 %59 to i32
store i32 %60, i32* %14
br label %61
61: ; preds = %58, %57
%62 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %8, i64 0, i64 0
%63 = load i32, i32* %14
%64 = load i32*, i32** %7
%65 = call i64 @fread(i8* %62, i32 1, i32 %63, i32* %64)
store i64 %65, i64* %12
%66 = load i64, i64* %12
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %61
br label %84
69: ; preds = %61
%70 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %8, i64 0, i64 0
%71 = load i32, i32* %14
%72 = load i8*, i8** %11
%73 = load i32, i32* %13
%74 = mul nsw i32 %73, 32
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %72, i64 %75
%77 = call i32 @sha256(i8* %70, i32 %71, i8* %76)
%78 = load i32, i32* %13
%79 = add nsw i32 %78, 1
store i32 %79, i32* %13
%80 = load i32, i32* %14
%81 = zext i32 %80 to i64
%82 = load i64, i64* %9
%83 = sub nsw i64 %82, %81
store i64 %83, i64* %9
br label %50
84: ; preds = %68, %53
%85 = load i32*, i32** %7
%86 = call i32 @fclose(i32* %85)
%87 = load i64, i64* %9
%88 = icmp eq i64 %87, 0
%89 = zext i1 %88 to i32
%90 = call i32 @assert(i32 %89)
%91 = load i32, i32* %10
store i32 %91, i32* %15
%92 = load i32, i32* %10
%93 = mul i32 %92, 32
%94 = call i8* @malloc(i32 %93)
store i8* %94, i8** %16
br label %95
95: ; preds = %178, %84
%96 = load i32, i32* %15
%97 = icmp sgt i32 %96, 1
br i1 %97, label %98, label %179
98: ; preds = %95
%99 = load i32, i32* %15
%100 = sdiv i32 %99, 2
store i32 %100, i32* %17
store i32 0, i32* %18
br label %101
101: ; preds = %118, %98
%102 = load i32, i32* %18
%103 = load i32, i32* %17
%104 = icmp ult i32 %102, %103
br i1 %104, label %105, label %121
105: ; preds = %101
%106 = load i8*, i8** %11
%107 = load i32, i32* %18
%108 = mul i32 2, %107
%109 = mul i32 %108, 32
%110 = zext i32 %109 to i64
%111 = getelementptr inbounds i8, i8* %106, i64 %110
%112 = load i8*, i8** %16
%113 = load i32, i32* %18
%114 = mul i32 %113, 32
%115 = zext i32 %114 to i64
%116 = getelementptr inbounds i8, i8* %112, i64 %115
%117 = call i32 @sha256(i8* %111, i32 64, i8* %116)
br label %118
118: ; preds = %105
%119 = load i32, i32* %18
%120 = add i32 %119, 1
store i32 %120, i32* %18
br label %101
121: ; preds = %101
store i32 0, i32* %19
br label %122
122: ; preds = %137, %121
%123 = load i32, i32* %19
%124 = load i32, i32* %17
%125 = mul nsw i32 %124, 32
%126 = icmp slt i32 %123, %125
br i1 %126, label %127, label %140
127: ; preds = %122
%128 = load i8*, i8** %16
%129 = load i32, i32* %19
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i8, i8* %128, i64 %130
%132 = load i8, i8* %131
%133 = load i8*, i8** %11
%134 = load i32, i32* %19
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds i8, i8* %133, i64 %135
store i8 %132, i8* %136
br label %137
137: ; preds = %127
%138 = load i32, i32* %19
%139 = add nsw i32 %138, 1
store i32 %139, i32* %19
br label %122
140: ; preds = %122
%141 = load i32, i32* %15
%142 = srem i32 %141, 2
%143 = icmp eq i32 %142, 1
br i1 %143, label %144, label %169
144: ; preds = %140
store i32 0, i32* %20
br label %145
145: ; preds = %165, %144
%146 = load i32, i32* %20
%147 = icmp slt i32 %146, 32
br i1 %147, label %148, label %168
148: ; preds = %145
%149 = load i8*, i8** %11
%150 = load i32, i32* %15
%151 = sub nsw i32 %150, 1
%152 = mul nsw i32 %151, 32
%153 = load i32, i32* %20
%154 = add nsw i32 %152, %153
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds i8, i8* %149, i64 %155
%157 = load i8, i8* %156
%158 = load i8*, i8** %11
%159 = load i32, i32* %17
%160 = mul nsw i32 %159, 32
%161 = load i32, i32* %20
%162 = add nsw i32 %160, %161
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds i8, i8* %158, i64 %163
store i8 %157, i8* %164
br label %165
165: ; preds = %148
%166 = load i32, i32* %20
%167 = add nsw i32 %166, 1
store i32 %167, i32* %20
br label %145
168: ; preds = %145
br label %169
169: ; preds = %168, %140
%170 = load i32, i32* %15
%171 = srem i32 %170, 2
%172 = icmp eq i32 %171, 0
br i1 %172, label %173, label %175
173: ; preds = %169
%174 = load i32, i32* %17
store i32 %174, i32* %15
br label %178
175: ; preds = %169
%176 = load i32, i32* %17
%177 = add nsw i32 %176, 1
store i32 %177, i32* %15
br label %178
178: ; preds = %175, %173
br label %95
179: ; preds = %95
%180 = call i8* @malloc(i32 64)
store i8* %180, i8** %21
%181 = load i8*, i8** %21
%182 = icmp ne i8* %181, null
%183 = zext i1 %182 to i32
%184 = call i32 @assert(i32 %183)
store i32 0, i32* %22
br label %185
185: ; preds = %200, %179
%186 = load i32, i32* %22
%187 = icmp slt i32 %186, 32
br i1 %187, label %188, label %203
188: ; preds = %185
%189 = load i8*, i8** %21
%190 = load i32, i32* %22
%191 = mul nsw i32 2, %190
%192 = sext i32 %191 to i64
%193 = getelementptr inbounds i8, i8* %189, i64 %192
%194 = load i8*, i8** %11
%195 = load i32, i32* %22
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds i8, i8* %194, i64 %196
%198 = load i8, i8* %197
%199 = call i32 @sprintf(i8* %193, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %198)
br label %200
200: ; preds = %188
%201 = load i32, i32* %22
%202 = add nsw i32 %201, 1
store i32 %202, i32* %22
br label %185
203: ; preds = %185
%204 = load i8*, i8** %11
%205 = call i32 @free(i8* %204)
%206 = load i8*, i8** %16
%207 = call i32 @free(i8* %206)
%208 = load i8*, i8** %21
ret i8* %208
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
@.str.1 = [5 x i8] c"%02x\00"
define noalias i8* @treehash(i8* nocapture %0, i64 %1, i64 %2) {
%4 = alloca [1048576 x i8]
%5 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %4, i64 0, i64 0
%6 = and i64 %1, 1048575
%7 = icmp eq i64 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32* %10, null
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %10, i64 %1, i32 %14)
%16 = sub i64 %2, %1
%17 = add i64 %16, 1
%18 = sitofp i64 %17 to double
%19 = fmul double %18, 0x3EB0000000000000
%20 = tail call i64 @ceil(double %19)
%21 = trunc i64 %20 to i32
%22 = shl i32 %21, 5
%23 = tail call i8* @malloc(i32 %22)
%24 = icmp eq i64 %17, 0
br i1 %24, label %45, label %25
25: ; preds = %3, %33
%26 = phi i64 [ %38, %33 ], [ 0, %3 ]
%27 = phi i64 [ %40, %33 ], [ %17, %3 ]
%28 = icmp sgt i64 %27, 1048575
%29 = trunc i64 %27 to i32
%30 = select i1 %28, i32 1048576, i32 %29
%31 = call i64 @fread(i8* %5, i32 1, i32 %30, i32* %10)
%32 = icmp eq i64 %31, 0
br i1 %32, label %42, label %33
33: ; preds = %25
%34 = shl i64 %26, 5
%35 = and i64 %34, 4294967264
%36 = getelementptr inbounds i8, i8* %23, i64 %35
%37 = call i32 @sha256(i8* %5, i32 %30, i8* %36)
%38 = add nuw i64 %26, 1
%39 = zext i32 %30 to i64
%40 = sub nsw i64 %27, %39
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %25
42: ; preds = %25, %33
%43 = xor i1 %32, true
%44 = zext i1 %43 to i32
br label %45
45: ; preds = %42, %3
%46 = phi i32 [ 1, %3 ], [ %44, %42 ]
%47 = call i32 @fclose(i32* %10)
%48 = call i32 @assert(i32 %46)
%49 = call i8* @malloc(i32 %22)
%50 = icmp sgt i32 %21, 1
br i1 %50, label %51, label %141
51: ; preds = %45
%52 = getelementptr i8, i8* %23, i64 32
%53 = getelementptr i8, i8* %23, i64 32
br label %54
54: ; preds = %51, %138
%55 = phi i32 [ %139, %138 ], [ %21, %51 ]
%56 = lshr i32 %55, 1
%57 = zext i32 %56 to i64
br label %58
58: ; preds = %54, %58
%59 = phi i64 [ 0, %54 ], [ %67, %58 ]
%60 = shl i64 %59, 6
%61 = and i64 %60, 4294967232
%62 = getelementptr inbounds i8, i8* %23, i64 %61
%63 = shl i64 %59, 5
%64 = and i64 %63, 4294967264
%65 = getelementptr inbounds i8, i8* %49, i64 %64
%66 = call i32 @sha256(i8* %62, i32 64, i8* %65)
%67 = add nuw nsw i64 %59, 1
%68 = icmp eq i64 %67, %57
br i1 %68, label %69, label %58
69: ; preds = %58
%70 = shl i32 %56, 5
%71 = call i32 @llvm.umax.i32(i32 %70, i32 1)
%72 = zext i32 %71 to i64
%73 = srem i32 %55, 2
switch i32 %73, label %136 [
i32 1, label %74
i32 0, label %138
]
74: ; preds = %69
%75 = shl i32 %55, 5
%76 = add i32 %75, -32
%77 = sext i32 %76 to i64
%78 = zext i32 %70 to i64
%79 = getelementptr i8, i8* %23, i64 %78
%80 = getelementptr i8, i8* %52, i64 %78
%81 = getelementptr i8, i8* %23, i64 %77
%82 = getelementptr i8, i8* %53, i64 %77
%83 = icmp ult i8* %79, %82
%84 = icmp ult i8* %81, %80
%85 = and i1 %83, %84
br i1 %85, label %101, label %86
86: ; preds = %74
%87 = getelementptr inbounds i8, i8* %23, i64 %77
%88 = bitcast i8* %87 to <16 x i8>*
%89 = load <16 x i8>, <16 x i8>* %88
%90 = zext i32 %70 to i64
%91 = getelementptr inbounds i8, i8* %23, i64 %90
%92 = bitcast i8* %91 to <16 x i8>*
store <16 x i8> %89, <16 x i8>* %92
%93 = or i64 %77, 16
%94 = getelementptr inbounds i8, i8* %23, i64 %93
%95 = bitcast i8* %94 to <16 x i8>*
%96 = load <16 x i8>, <16 x i8>* %95
%97 = or i32 %70, 16
%98 = zext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %23, i64 %98
%100 = bitcast i8* %99 to <16 x i8>*
store <16 x i8> %96, <16 x i8>* %100
br label %136
101: ; preds = %74, %101
%102 = phi i64 [ %134, %101 ], [ 0, %74 ]
%103 = add nuw nsw i64 %102, %77
%104 = getelementptr inbounds i8, i8* %23, i64 %103
%105 = load i8, i8* %104
%106 = trunc i64 %102 to i32
%107 = add nuw nsw i32 %70, %106
%108 = zext i32 %107 to i64
%109 = getelementptr inbounds i8, i8* %23, i64 %108
store i8 %105, i8* %109
%110 = or i64 %102, 1
%111 = add nuw nsw i64 %110, %77
%112 = getelementptr inbounds i8, i8* %23, i64 %111
%113 = load i8, i8* %112
%114 = trunc i64 %110 to i32
%115 = add nuw nsw i32 %70, %114
%116 = zext i32 %115 to i64
%117 = getelementptr inbounds i8, i8* %23, i64 %116
store i8 %113, i8* %117
%118 = or i64 %102, 2
%119 = add nuw nsw i64 %118, %77
%120 = getelementptr inbounds i8, i8* %23, i64 %119
%121 = load i8, i8* %120
%122 = trunc i64 %118 to i32
%123 = add nuw nsw i32 %70, %122
%124 = zext i32 %123 to i64
%125 = getelementptr inbounds i8, i8* %23, i64 %124
store i8 %121, i8* %125
%126 = or i64 %102, 3
%127 = add nuw nsw i64 %126, %77
%128 = getelementptr inbounds i8, i8* %23, i64 %127
%129 = load i8, i8* %128
%130 = trunc i64 %126 to i32
%131 = add nuw nsw i32 %70, %130
%132 = zext i32 %131 to i64
%133 = getelementptr inbounds i8, i8* %23, i64 %132
store i8 %129, i8* %133
%134 = add nuw nsw i64 %102, 4
%135 = icmp eq i64 %134, 32
br i1 %135, label %136, label %101
136: ; preds = %101, %86, %69
%137 = add nuw nsw i32 %56, 1
br label %138
138: ; preds = %69, %136
%139 = phi i32 [ %137, %136 ], [ %56, %69 ]
%140 = icmp sgt i32 %139, 1
br i1 %140, label %54, label %141
141: ; preds = %138, %45
%142 = call dereferenceable_or_null(64) i8* @malloc(i32 64)
%143 = icmp ne i8* %142, null
%144 = zext i1 %143 to i32
%145 = call i32 @assert(i32 %144)
br label %149
146: ; preds = %149
%147 = call i32 @free(i8* %23)
%148 = call i32 @free(i8* %49)
ret i8* %142
149: ; preds = %141, %149
%150 = phi i64 [ 0, %141 ], [ %156, %149 ]
%151 = shl nuw nsw i64 %150, 1
%152 = getelementptr inbounds i8, i8* %142, i64 %151
%153 = getelementptr inbounds i8, i8* %23, i64 %150
%154 = load i8, i8* %153
%155 = call i32 @sprintf(i8* dereferenceable(1) %152, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %154)
%156 = add nuw nsw i64 %150, 1
%157 = icmp eq i64 %156, 32
br i1 %157, label %146, label %149
}