#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*/ uint32_t;
typedef scalar_t__ clock_t;

/* Variables and functions */
scalar_t__ clock();
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ p(unsigned char *, int);
int /*<<< orphan*/ printf(char *, float);
int /*<<< orphan*/ sha256(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ sha256_init(int /*<<< orphan*/ *);
int main() {
  clock_t t1, t2;
  t1 = clock();
  unsigned char src[32];
  unsigned char dst[32];
  sha256_init((uint32_t *)src);
  unsigned int i = 0;
  for (i = 0; i < 0x5fffff; i++) {
    sha256(dst, src, 32);
    memcpy(src, dst, 32);
  }
  t2 = clock();
  float diff = (((float)t2 - (float)t1) / 1000000.0F) * 1000;
  printf("Time diff: %f\n", diff);
  p(src, 8);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
call   1060 <sha256_init@plt>
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x5fffff,-0x64(%rbp)
jae    11d0 <main+0x70>
lea    -0x60(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1070 <sha256@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x20,%edx
call   1080 <memcpy@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1191 <main+0x31>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x18(%rbp)
cvtsi2ssq -0x18(%rbp),%xmm0
cvtsi2ssq -0x10(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  0xe11(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xe01(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x68(%rbp)
movss  -0x68(%rbp),%xmm0
lea    0xdf4(%rip),%rdi
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x8,%esi
call   1030 <p@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
mov    %rsp,%r15
mov    %r15,%rdi
call   1060 <sha256_init@plt>
mov    $0x5fffff,%ebp
lea    0x20(%rsp),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x20,%edx
call   1070 <sha256@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1080 <memcpy@plt>
add    $0xffffffff,%ebp
jne    1190 <main+0x30>
xor    %eax,%eax
call   1040 <clock@plt>
cvtsi2ss %rax,%xmm0
cvtsi2ss %r14,%xmm1
subss  %xmm1,%xmm0
divss  0xe2e(%rip),%xmm0
mulss  0xe2a(%rip),%xmm0
lea    0xe27(%rip),%rdi
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    $0x8,%esi
call   1030 <p@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Time diff: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
%6 = alloca i32
%7 = alloca float
store i32 0, i32* %1
%8 = call i64 (...) @clock()
store i64 %8, i64* %2
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%10 = bitcast i8* %9 to i32*
%11 = call i32 @sha256_init(i32* %10)
store i32 0, i32* %6
store i32 0, i32* %6
br label %12
12: ; preds = %22, %0
%13 = load i32, i32* %6
%14 = icmp ult i32 %13, 6291455
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%18 = call i32 @sha256(i8* %16, i8* %17, i32 32)
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%21 = call i32 @memcpy(i8* %19, i8* %20, i32 32)
br label %22
22: ; preds = %15
%23 = load i32, i32* %6
%24 = add i32 %23, 1
store i32 %24, i32* %6
br label %12
25: ; preds = %12
%26 = call i64 (...) @clock()
store i64 %26, i64* %3
%27 = load i64, i64* %3
%28 = sitofp i64 %27 to float
%29 = load i64, i64* %2
%30 = sitofp i64 %29 to float
%31 = fsub float %28, %30
%32 = fdiv float %31, 1.000000e+06
%33 = fmul float %32, 1.000000e+03
store float %33, float* %7
%34 = load float, float* %7
%35 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), float %34)
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%37 = call i32 @p(i8* %36, i32 8)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Time diff: %f\0A\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = alloca [32 x i8]
%3 = tail call i64 (...) @clock()
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = bitcast [32 x i8]* %1 to i32*
%7 = call i32 @sha256_init(i32* %6)
br label %8
8: ; preds = %0, %8
%9 = phi i32 [ 0, %0 ], [ %12, %8 ]
%10 = call i32 @sha256(i8* %5, i8* %4, i32 32)
%11 = call i32 @memcpy(i8* %4, i8* %5, i32 32)
%12 = add nuw nsw i32 %9, 1
%13 = icmp eq i32 %12, 6291455
br i1 %13, label %14, label %8
14: ; preds = %8
%15 = call i64 (...) @clock()
%16 = sitofp i64 %15 to float
%17 = sitofp i64 %3 to float
%18 = fsub float %16, %17
%19 = fdiv float %18, 1.000000e+06
%20 = fmul float %19, 1.000000e+03
%21 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), float %20)
%22 = call i32 @p(i8* %4, i32 8)
ret i32 0
}