#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*/ gzFile;
typedef int /*<<< orphan*/ SHA_CTX;

/* Variables and functions */
int /*<<< orphan*/ SHA1_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Update(int /*<<< orphan*/ *, char *, size_t);
int /*<<< orphan*/ error(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ gzclose(int /*<<< orphan*/);
int /*<<< orphan*/ gzeof(int /*<<< orphan*/);
int /*<<< orphan*/ gzopen(char const *, char *);
size_t gzread(int /*<<< orphan*/, char *, int);
void shagetdb(const char *fn, unsigned char *sha) {
  gzFile fd;
  SHA_CTX c;
  if (!(fd = gzopen(fn, "rb"))) {
    error(0, "file open failed for '%s'", fn);
    return;
  }
  SHA1_Init(&c);
  while (!gzeof(fd)) {
    char buf[8192];
    size_t r = gzread(fd, buf, 8192);
    SHA1_Update(&c, buf, r);
  }
  SHA1_Final(sha, &c);
  gzclose(fd);
}


x86 assembly (clang, -O0):
<shagetdb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1090 <gzopen@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11c6 <shagetdb+0x46>
mov    -0x8(%rbp),%rdx
xor    %edi,%edi
lea    0xe47(%rip),%rsi
call   1080 <error@plt>
jmp    1238 <shagetdb+0xb8>
lea    -0x18(%rbp),%rdi
call   1070 <SHA1_Init@plt>
mov    -0x14(%rbp),%edi
call   1040 <gzeof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ec <shagetdb+0x6c>
jmp    1223 <shagetdb+0xa3>
mov    -0x14(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x2000,%edx
call   1050 <gzread@plt>
mov    %rax,-0x2028(%rbp)
lea    -0x2020(%rbp),%rsi
mov    -0x2028(%rbp),%rdx
lea    -0x18(%rbp),%rdi
call   1060 <SHA1_Update@plt>
jmp    11cf <shagetdb+0x4f>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <SHA1_Final@plt>
mov    -0x14(%rbp),%edi
call   1030 <gzclose@plt>
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shagetdb>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2018,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe66(%rip),%rsi
call   1090 <gzopen@plt>
test   %eax,%eax
je     121a <shagetdb+0x9a>
mov    %eax,%ebp
lea    0xc(%rsp),%rdi
call   1070 <SHA1_Init@plt>
mov    %ebp,%edi
call   1040 <gzeof@plt>
test   %eax,%eax
jne    11f8 <shagetdb+0x78>
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2000,%edx
call   1050 <gzread@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1060 <SHA1_Update@plt>
mov    %ebp,%edi
call   1040 <gzeof@plt>
test   %eax,%eax
je     11d0 <shagetdb+0x50>
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   10a0 <SHA1_Final@plt>
mov    %ebp,%edi
call   1030 <gzclose@plt>
add    $0x2018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde2(%rip),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
add    $0x2018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <error@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [26 x i8] c"file open failed for '%s'\00"
define void @shagetdb(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [8192 x i8]
%8 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 @gzopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @error(i32 0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %34
15: ; preds = %2
%16 = call i32 @SHA1_Init(i32* %6)
br label %17
17: ; preds = %22, %15
%18 = load i32, i32* %5
%19 = call i32 @gzeof(i32 %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i32, i32* %5
%24 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%25 = call i64 @gzread(i32 %23, i8* %24, i32 8192)
store i64 %25, i64* %8
%26 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%27 = load i64, i64* %8
%28 = call i32 @SHA1_Update(i32* %6, i8* %26, i64 %27)
br label %17
29: ; preds = %17
%30 = load i8*, i8** %4
%31 = call i32 @SHA1_Final(i8* %30, i32* %6)
%32 = load i32, i32* %5
%33 = call i32 @gzclose(i32 %32)
br label %34
34: ; preds = %29, %12
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [26 x i8] c"file open failed for '%s'\00"
define void @shagetdb(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [8192 x i8]
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @gzopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @error(i32 0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %24
10: ; preds = %2
%11 = call i32 @SHA1_Init(i32* %3)
%12 = call i32 @gzeof(i32 %6)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
br label %16
16: ; preds = %14, %16
%17 = call i64 @gzread(i32 %6, i8* %15, i32 8192)
%18 = call i32 @SHA1_Update(i32* %3, i8* %15, i64 %17)
%19 = call i32 @gzeof(i32 %6)
%20 = icmp eq i32 %19, 0
br i1 %20, label %16, label %21
21: ; preds = %16, %10
%22 = call i32 @SHA1_Final(i8* %1, i32* %3)
%23 = call i32 @gzclose(i32 %6)
br label %24
24: ; preds = %21, %8
ret void
}