#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*/ SHA512_finish(unsigned long long *, unsigned long long *,
                                 unsigned long long);
int /*<<< orphan*/ SHA512_process(unsigned long long *, unsigned long long *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
unsigned long fread(unsigned long long *, int, int, int /*<<< orphan*/ *);
int SHA512(char *filename, unsigned long long H[]) {
  H[0] = 0x6a09e667f3bcc908ULL;
  H[1] = 0xbb67ae8584caa73bULL;
  H[2] = 0x3c6ef372fe94f82bULL;
  H[3] = 0xa54ff53a5f1d36f1ULL;
  H[4] = 0x510e527fade682d1ULL;
  H[5] = 0x9b05688c2b3e6c1fULL;
  H[6] = 0x1f83d9abfb41bd6bULL;
  H[7] = 0x5be0cd19137e2179ULL;
  unsigned long long W[80];
  FILE *fp;
  unsigned long Len;
  unsigned long long FileLen = 0;
  if (!(fp = fopen(filename, "rb")))
    return 1;
  while (1) {
    Len = fread(W, 1, 128, fp);
    FileLen += Len;
    if (Len != 128)
      break;
    SHA512_process(H, W);
  }
  SHA512_finish(H, W, FileLen);
  if (ferror(fp)) {
    fclose(fp);
    return 1;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<SHA512>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movabs $0x6a09e667f3bcc908,%rcx
e6 09 6a
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movabs $0xbb67ae8584caa73b,%rcx
ae 67 bb
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
movabs $0x3c6ef372fe94f82b,%rcx
f3 6e 3c
mov    %rcx,0x10(%rax)
mov    -0x18(%rbp),%rax
movabs $0xa54ff53a5f1d36f1,%rcx
f5 4f a5
mov    %rcx,0x18(%rax)
mov    -0x18(%rbp),%rax
movabs $0x510e527fade682d1,%rcx
52 0e 51
mov    %rcx,0x20(%rax)
mov    -0x18(%rbp),%rax
movabs $0x9b05688c2b3e6c1f,%rcx
68 05 9b
mov    %rcx,0x28(%rax)
mov    -0x18(%rbp),%rax
movabs $0x1f83d9abfb41bd6b,%rcx
d9 83 1f
mov    %rcx,0x30(%rax)
mov    -0x18(%rbp),%rax
movabs $0x5be0cd19137e2179,%rcx
cd e0 5b
mov    %rcx,0x38(%rax)
movq   $0x0,-0x2b8(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x2a8(%rbp)
cmp    $0x0,%rax
jne    123a <SHA512+0xda>
movl   $0x1,-0x4(%rbp)
jmp    12fb <SHA512+0x19b>
jmp    123f <SHA512+0xdf>
lea    -0x2a0(%rbp),%rdi
mov    -0x2a8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x80,%edx
call   1040 <fread@plt>
mov    %rax,-0x2b0(%rbp)
mov    -0x2b0(%rbp),%rax
add    -0x2b8(%rbp),%rax
mov    %rax,-0x2b8(%rbp)
cmpq   $0x80,-0x2b0(%rbp)
je     128e <SHA512+0x12e>
jmp    12a3 <SHA512+0x143>
mov    -0x18(%rbp),%rdi
lea    -0x2a0(%rbp),%rsi
call   1070 <SHA512_process@plt>
jmp    123f <SHA512+0xdf>
mov    -0x18(%rbp),%rdi
lea    -0x2a0(%rbp),%rsi
mov    -0x2b8(%rbp),%rdx
call   1060 <SHA512_finish@plt>
mov    -0x2a8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12e8 <SHA512+0x188>
mov    -0x2a8(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fb <SHA512+0x19b>
mov    -0x2a8(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SHA512>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x288,%rsp
mov    %rsi,%r15
movaps 0xe88(%rip),%xmm0
movups %xmm0,(%rsi)
movaps 0xe8e(%rip),%xmm0
movups %xmm0,0x10(%rsi)
movaps 0xe93(%rip),%xmm0
movups %xmm0,0x20(%rsi)
movaps 0xe98(%rip),%xmm0
movups %xmm0,0x30(%rsi)
lea    0xe9d(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1233 <SHA512+0xd3>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rax,%rbx
cmp    $0x80,%rax
jne    120b <SHA512+0xab>
mov    $0x80,%ebx
mov    %rsp,%r12
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <SHA512_process@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
add    %rax,%rbx
cmp    $0x80,%rax
je     11e0 <SHA512+0x80>
mov    %rsp,%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1060 <SHA512_finish@plt>
mov    %r14,%rdi
call   1030 <ferror@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    1238 <SHA512+0xd8>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x288,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @SHA512(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca [80 x i64]
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
%10 = load i64*, i64** %5
%11 = getelementptr inbounds i64, i64* %10, i64 0
store i64 7640891576956012808, i64* %11
%12 = load i64*, i64** %5
%13 = getelementptr inbounds i64, i64* %12, i64 1
store i64 -4942790177534073029, i64* %13
%14 = load i64*, i64** %5
%15 = getelementptr inbounds i64, i64* %14, i64 2
store i64 4354685564936845355, i64* %15
%16 = load i64*, i64** %5
%17 = getelementptr inbounds i64, i64* %16, i64 3
store i64 -6534734903238641935, i64* %17
%18 = load i64*, i64** %5
%19 = getelementptr inbounds i64, i64* %18, i64 4
store i64 5840696475078001361, i64* %19
%20 = load i64*, i64** %5
%21 = getelementptr inbounds i64, i64* %20, i64 5
store i64 -7276294671716946913, i64* %21
%22 = load i64*, i64** %5
%23 = getelementptr inbounds i64, i64* %22, i64 6
store i64 2270897969802886507, i64* %23
%24 = load i64*, i64** %5
%25 = getelementptr inbounds i64, i64* %24, i64 7
store i64 6620516959819538809, i64* %25
store i64 0, i64* %9
%26 = load i8*, i8** %4
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %7
%28 = icmp ne i32* %27, null
br i1 %28, label %30, label %29
29: ; preds = %2
store i32 1, i32* %3
br label %59
30: ; preds = %2
br label %31
31: ; preds = %30, %41
%32 = getelementptr inbounds [80 x i64], [80 x i64]* %6, i64 0, i64 0
%33 = load i32*, i32** %7
%34 = call i64 @fread(i64* %32, i32 1, i32 128, i32* %33)
store i64 %34, i64* %8
%35 = load i64, i64* %8
%36 = load i64, i64* %9
%37 = add i64 %36, %35
store i64 %37, i64* %9
%38 = load i64, i64* %8
%39 = icmp ne i64 %38, 128
br i1 %39, label %40, label %41
40: ; preds = %31
br label %45
41: ; preds = %31
%42 = load i64*, i64** %5
%43 = getelementptr inbounds [80 x i64], [80 x i64]* %6, i64 0, i64 0
%44 = call i32 @SHA512_process(i64* %42, i64* %43)
br label %31
45: ; preds = %40
%46 = load i64*, i64** %5
%47 = getelementptr inbounds [80 x i64], [80 x i64]* %6, i64 0, i64 0
%48 = load i64, i64* %9
%49 = call i32 @SHA512_finish(i64* %46, i64* %47, i64 %48)
%50 = load i32*, i32** %7
%51 = call i64 @ferror(i32* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %45
%54 = load i32*, i32** %7
%55 = call i32 @fclose(i32* %54)
store i32 1, i32* %3
br label %59
56: ; preds = %45
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
store i32 0, i32* %3
br label %59
59: ; preds = %56, %53, %29
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @SHA512(i8* nocapture %0, i64* %1) {
%3 = alloca [80 x i64]
%4 = bitcast i64* %1 to <2 x i64>*
store <2 x i64> <i64 7640891576956012808, i64 -4942790177534073029>, <2 x i64>* %4
%5 = getelementptr inbounds i64, i64* %1, i64 2
%6 = bitcast i64* %5 to <2 x i64>*
store <2 x i64> <i64 4354685564936845355, i64 -6534734903238641935>, <2 x i64>* %6
%7 = getelementptr inbounds i64, i64* %1, i64 4
%8 = bitcast i64* %7 to <2 x i64>*
store <2 x i64> <i64 5840696475078001361, i64 -7276294671716946913>, <2 x i64>* %8
%9 = getelementptr inbounds i64, i64* %1, i64 6
%10 = bitcast i64* %9 to <2 x i64>*
store <2 x i64> <i64 2270897969802886507, i64 6620516959819538809>, <2 x i64>* %10
%11 = bitcast [80 x i64]* %3 to i8*
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %31, label %14
14: ; preds = %2
%15 = getelementptr inbounds [80 x i64], [80 x i64]* %3, i64 0, i64 0
%16 = call i64 @fread(i64* %15, i32 1, i32 128, i32* %12)
%17 = icmp eq i64 %16, 128
br i1 %17, label %18, label %24
18: ; preds = %14, %18
%19 = phi i64 [ %22, %18 ], [ 128, %14 ]
%20 = call i32 @SHA512_process(i64* %1, i64* %15)
%21 = call i64 @fread(i64* %15, i32 1, i32 128, i32* %12)
%22 = add i64 %21, %19
%23 = icmp eq i64 %21, 128
br i1 %23, label %18, label %24
24: ; preds = %18, %14
%25 = phi i64 [ %16, %14 ], [ %22, %18 ]
%26 = call i32 @SHA512_finish(i64* %1, i64* %15, i64 %25)
%27 = call i64 @ferror(i32* %12)
%28 = icmp ne i64 %27, 0
%29 = call i32 @fclose(i32* %12)
%30 = zext i1 %28 to i32
br label %31
31: ; preds = %24, %2
%32 = phi i32 [ 1, %2 ], [ %30, %24 ]
ret i32 %32
}