#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*/ uint8_t;
typedef int /*<<< orphan*/ uint64_t;
typedef double clock_t;
typedef int /*<<< orphan*/ block;

/* Variables and functions */
double CLOCKS_PER_SEC;
double clock();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ self_check();
int /*<<< orphan*/ sha512_compress(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (!self_check()) {
    printf("Self-check failed\n");
    return 1;
  }
  printf("Self-check passed\n");
  uint64_t state[8] = {};
  uint64_t block[16] = {};
  const int N = 3000000;
  clock_t start_time = clock();
  int i;
  for (i = 0; i < N; i++)
    sha512_compress(state, (uint8_t *)block);
  printf("Speed: %.1f MiB/s\n", (double)N * sizeof(block) /
                                    (clock() - start_time) * CLOCKS_PER_SEC /
                                    1048576);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <self_check@plt>
cmp    $0x0,%eax
jne    1193 <main+0x43>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0x106>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
movl   $0x2dc6c0,-0x74(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x80(%rbp)
movl   $0x0,-0x84(%rbp)
cmpl   $0x2dc6c0,-0x84(%rbp)
jge    120f <main+0xbf>
lea    -0x30(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1070 <sha512_compress@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11de <main+0x8e>
mov    $0x0,%al
call   1030 <clock@plt>
movaps %xmm0,%xmm1
subsd  -0x80(%rbp),%xmm1
movsd  0xde2(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    0x2db7(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xdc3(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xdee(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
xor    %eax,%eax
call   1060 <self_check@plt>
test   %eax,%eax
je     1212 <main+0xc2>
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
xorpd  %xmm0,%xmm0
movapd %xmm0,0x20(%rsp)
movapd %xmm0,0x10(%rsp)
movapd %xmm0,0x60(%rsp)
movapd %xmm0,0x50(%rsp)
movapd %xmm0,0x40(%rsp)
movapd %xmm0,0x30(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x2dc6c0,%ebp
lea    0x10(%rsp),%r14
lea    0x30(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <sha512_compress@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x70>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <clock@plt>
subsd  0x8(%rsp),%xmm0
movsd  0xe19(%rip),%xmm1
divsd  %xmm0,%xmm1
mov    0x2df6(%rip),%rax
mulsd  (%rax),%xmm1
mulsd  0xe0a(%rip),%xmm1
lea    0xe0b(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
jmp    1223 <main+0xd3>
lea    0xe0a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Self-check failed\0A\00"
@.str.1 = [19 x i8] c"Self-check passed\0A\00"
@.str.2 = [19 x i8] c"Speed: %.1f MiB/s\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8 x i32]
%7 = alloca [16 x i32]
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (...) @self_check()
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %39
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%17 = bitcast [8 x i32]* %6 to i8*
%18 = bitcast [16 x i32]* %7 to i8*
store i32 3000000, i32* %8
%19 = call double (...) @clock()
store double %19, double* %9
store i32 0, i32* %10
br label %20
20: ; preds = %27, %15
%21 = load i32, i32* %10
%22 = icmp slt i32 %21, 3000000
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
%25 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 0
%26 = call i32 @sha512_compress(i32* %24, i32* %25)
br label %27
27: ; preds = %23
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 1
store i32 %29, i32* %10
br label %20
30: ; preds = %20
%31 = call double (...) @clock()
%32 = load double, double* %9
%33 = fsub double %31, %32
%34 = fdiv double 1.920000e+08, %33
%35 = load double, double* @CLOCKS_PER_SEC
%36 = fmul double %34, %35
%37 = fdiv double %36, 0x4130000000000000
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), double %37)
store i32 0, i32* %3
br label %39
39: ; preds = %30, %13
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str.2 = [19 x i8] c"Speed: %.1f MiB/s\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@str = [18 x i8] c"Self-check failed\00"
@str.3 = [18 x i8] c"Self-check passed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [8 x i32]
%4 = alloca [16 x i32]
%5 = tail call i32 (...) @self_check()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %29
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
%11 = bitcast [8 x i32]* %3 to i8*
%12 = bitcast [16 x i32]* %4 to i8*
%13 = tail call double (...) @clock()
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 0
br label %16
16: ; preds = %9, %16
%17 = phi i32 [ 0, %9 ], [ %19, %16 ]
%18 = call i32 @sha512_compress(i32* %14, i32* %15)
%19 = add nuw nsw i32 %17, 1
%20 = icmp eq i32 %19, 3000000
br i1 %20, label %21, label %16
21: ; preds = %16
%22 = call double (...) @clock()
%23 = fsub double %22, %13
%24 = fdiv double 1.920000e+08, %23
%25 = load double, double* @CLOCKS_PER_SEC
%26 = fmul double %25, %24
%27 = fmul double %26, 0x3EB0000000000000
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), double %27)
br label %29
29: ; preds = %21, %7
%30 = phi i32 [ 0, %21 ], [ 1, %7 ]
ret i32 %30
}