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

/* Variables and functions */
double CLOCKS_PER_SEC;
int EXIT_FAILURE;
int EXIT_SUCCESS;
double clock();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ self_check();
int /*<<< orphan*/ sha1_compress(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int main(void) {
  if (!self_check()) {
    printf("Self-check failed\n");
    return EXIT_FAILURE;
  }
  printf("Self-check passed\n");
  uint32_t state[5] = {0};
  uint8_t block[64] = {0};
  const long ITERS = 10000000;
  clock_t start_time = clock();
  for (long i = 0; i < ITERS; i++)
    sha1_compress(state, block);
  printf("Speed: %.1f MB/s\n",
         (double)ITERS * (sizeof(block) / sizeof(block[0])) /
             (clock() - start_time) * CLOCKS_PER_SEC / 1000000);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <self_check@plt>
cmp    $0x0,%eax
jne    1191 <main+0x41>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    126e <main+0x11e>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
movq   $0x989680,-0x128(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x130(%rbp)
ff
movq   $0x0,-0x138(%rbp)
cmpq   $0x989680,-0x138(%rbp)
jge    121f <main+0xcf>
lea    -0x20(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1070 <sha1_compress@plt>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    11e7 <main+0x97>
mov    $0x0,%al
call   1030 <clock@plt>
movaps %xmm0,%xmm1
subsd  -0x130(%rbp),%xmm1
ff
movsd  0xdcf(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    0x2da4(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xdb0(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xddb(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x130,%rsp
xor    %eax,%eax
call   1060 <self_check@plt>
test   %eax,%eax
je     1288 <main+0x138>
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
xorpd  %xmm0,%xmm0
movapd %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
movapd %xmm0,0x120(%rsp)
movapd %xmm0,0x110(%rsp)
movapd %xmm0,0x100(%rsp)
movapd %xmm0,0xf0(%rsp)
movapd %xmm0,0xe0(%rsp)
movapd %xmm0,0xd0(%rsp)
movapd %xmm0,0xc0(%rsp)
movapd %xmm0,0xb0(%rsp)
movapd %xmm0,0xa0(%rsp)
movapd %xmm0,0x90(%rsp)
movapd %xmm0,0x80(%rsp)
movapd %xmm0,0x70(%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    $0x989680,%ebx
lea    0x10(%rsp),%r14
lea    0x30(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <sha1_compress@plt>
add    $0xffffffffffffffff,%rbx
jne    1230 <main+0xe0>
xor    %eax,%eax
call   1040 <clock@plt>
subsd  0x8(%rsp),%xmm0
movsd  0xdaa(%rip),%xmm1
divsd  %xmm0,%xmm1
mov    0x2d87(%rip),%rax
mulsd  (%rax),%xmm1
divsd  0xd9b(%rip),%xmm1
lea    0xd9c(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
mov    0x2d4a(%rip),%rax
jmp    129b <main+0x14b>
lea    0xd93(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%eax
add    $0x130,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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