#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 */

/* Variables and functions */
int /*<<< orphan*/ SHA512(unsigned char *, int /*<<< orphan*/, unsigned char *);
int SHA512_DIGEST_LENGTH;
int /*<<< orphan*/ SHA512iv(unsigned char *, int /*<<< orphan*/,
                            unsigned char *, unsigned long long *);
unsigned long long U64(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ put_hex_string(unsigned char *);
int /*<<< orphan*/ strlen(unsigned char *);
int main() {
  unsigned char ibuf[] = "test input string";
  unsigned char ibufhash[] =
      "\x36\xee\x5f\x7d\x28\xa8\xf3"
      "\x56\x92\xd7\x1c\x0c\x1c\x78\xee\xc1\xc9\xe4\xb9\x5f\xa4\x08\x02\x60\x68"
      "\xd5\x5a"
      "\x70\x41\x70\x00\x8d\xa2\x19\x8f\x16\xd9\x7c\x90\x13\xea\x56\x42\x45\x4f"
      "\x08\xc6"
      "\x2f\xcb\x2e\xf2\xa8\x3c\x21\xbe\x61\x7f\x80\x10\x35\x08\xd8\x10\xaf";
  unsigned char obuf[SHA512_DIGEST_LENGTH];
  unsigned long long h[8];
  printf("SHA512_DIGEST_LENGTH: %d\n", SHA512_DIGEST_LENGTH);
  h[0] = U64(0x6a09e667f3bcc908);
  h[1] = U64(0xbb67ae8584caa73b);
  h[2] = U64(0x3c6ef372fe94f82b);
  h[3] = U64(0xa54ff53a5f1d36f1);
  h[4] = U64(0x510e527fade682d1);
  h[5] = U64(0x9b05688c2b3e6c1f);
  h[6] = U64(0x1f83d9abfb41bd6b);
  h[7] = U64(0x5be0cd19137e2179);
  printf("New implemenatation sha512iv() with old IV supplied as argument\n");
  SHA512iv(ibuf, strlen(ibuf), obuf, h);
  put_hex_string(obuf);
  printf("OpenSSL Implemntation sha512() with build in IV\n");
  SHA512(ibuf, strlen(ibuf), obuf);
  put_hex_string(obuf);
  printf("SHA512 of \"test input string\" generated from independent source");
  put_hex_string(ibufhash);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
movaps 0xe87(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
movw   $0x67,-0x10(%rbp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movaps 0xeab(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0xe75(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
movb   $0x0,-0x30(%rbp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xc8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x80(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xf3bcc908,%edi
call   1060 <U64@plt>
mov    %rax,-0xc0(%rbp)
mov    $0x84caa73b,%edi
call   1060 <U64@plt>
mov    %rax,-0xb8(%rbp)
mov    $0xfe94f82b,%edi
call   1060 <U64@plt>
mov    %rax,-0xb0(%rbp)
mov    $0x5f1d36f1,%edi
call   1060 <U64@plt>
mov    %rax,-0xa8(%rbp)
mov    $0xade682d1,%edi
call   1060 <U64@plt>
mov    %rax,-0xa0(%rbp)
mov    $0x2b3e6c1f,%edi
call   1060 <U64@plt>
mov    %rax,-0x98(%rbp)
mov    $0xfb41bd6b,%edi
call   1060 <U64@plt>
mov    %rax,-0x90(%rbp)
mov    $0x137e2179,%edi
call   1060 <U64@plt>
mov    %rax,-0x88(%rbp)
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xd8(%rbp),%rdi
mov    -0xc8(%rbp),%rdx
mov    %eax,%esi
lea    -0xc0(%rbp),%rcx
call   1030 <SHA512iv@plt>
mov    -0xc8(%rbp),%rdi
call   1080 <put_hex_string@plt>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0xd0(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xd0(%rbp),%rdi
mov    -0xc8(%rbp),%rdx
mov    %eax,%esi
call   1070 <SHA512@plt>
mov    -0xc8(%rbp),%rdi
call   1080 <put_hex_string@plt>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1080 <put_hex_string@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
mov    %rsp,%r15
movaps 0xe76(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movw   $0x67,-0x20(%rbp)
movaps 0xeb5(%rip),%xmm0
movaps %xmm0,-0x90(%rbp)
movaps 0xe97(%rip),%xmm0
movaps %xmm0,-0xa0(%rbp)
movaps 0xe79(%rip),%xmm0
movaps %xmm0,-0xb0(%rbp)
movaps 0xe5b(%rip),%xmm0
movaps %xmm0,-0xc0(%rbp)
movb   $0x0,-0x80(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    (%rax),%esi
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xf3bcc908,%edi
call   1070 <U64@plt>
mov    %rax,-0x70(%rbp)
mov    $0x84caa73b,%edi
call   1070 <U64@plt>
mov    %rax,-0x68(%rbp)
mov    $0xfe94f82b,%edi
call   1070 <U64@plt>
mov    %rax,-0x60(%rbp)
mov    $0x5f1d36f1,%edi
call   1070 <U64@plt>
mov    %rax,-0x58(%rbp)
mov    $0xade682d1,%edi
call   1070 <U64@plt>
mov    %rax,-0x50(%rbp)
mov    $0x2b3e6c1f,%edi
call   1070 <U64@plt>
mov    %rax,-0x48(%rbp)
mov    $0xfb41bd6b,%edi
call   1070 <U64@plt>
mov    %rax,-0x40(%rbp)
mov    $0x137e2179,%edi
call   1070 <U64@plt>
mov    %rax,-0x38(%rbp)
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
lea    -0x30(%rbp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    -0x70(%rbp),%rcx
mov    %r14,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1040 <SHA512iv@plt>
mov    %rbx,%rdi
call   1090 <put_hex_string@plt>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1080 <SHA512@plt>
mov    %rbx,%rdi
call   1090 <put_hex_string@plt>
lea    0xdb0(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    -0xc0(%rbp),%rdi
call   1090 <put_hex_string@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.ibuf = [18 x i8] c"test input string\00"
@__const.main.ibufhash = [65 x i8] c"6\EE_}(\A8\F3V\92\D7\1C\0C\1Cx\EE\C1\C9\E4\B9_\A4\08\02`h\D5ZpAp\00\8D\A2\19\8F\16\D9|\90\13\EAVBEO\08\C6/\CB.\F2\A8<!\BEa\7F\80\105\08\D8\10\AF\00"
@SHA512_DIGEST_LENGTH = global i32 0
@.str = [26 x i8] c"SHA512_DIGEST_LENGTH: %d\0A\00"
@.str.1 = [65 x i8] c"New implemenatation sha512iv() with old IV supplied as argument\0A\00"
@.str.2 = [49 x i8] c"OpenSSL Implemntation sha512() with build in IV\0A\00"
@.str.3 = [64 x i8] c"SHA512 of \22test input string\22 generated from independent source\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [18 x i8]
%3 = alloca [65 x i8]
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [8 x i64]
store i32 0, i32* %1
%7 = bitcast [18 x i8]* %2 to i8*
%8 = bitcast [65 x i8]* %3 to i8*
%9 = load i32, i32* @SHA512_DIGEST_LENGTH
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
%13 = load i32, i32* @SHA512_DIGEST_LENGTH
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i64 @U64(i32 -205731576)
%16 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 0
store i64 %15, i64* %16
%17 = call i64 @U64(i32 -2067093701)
%18 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 1
store i64 %17, i64* %18
%19 = call i64 @U64(i32 -23791573)
%20 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 2
store i64 %19, i64* %20
%21 = call i64 @U64(i32 1595750129)
%22 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 3
store i64 %21, i64* %22
%23 = call i64 @U64(i32 -1377402159)
%24 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 4
store i64 %23, i64* %24
%25 = call i64 @U64(i32 725511199)
%26 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 5
store i64 %25, i64* %26
%27 = call i64 @U64(i32 -79577749)
%28 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 6
store i64 %27, i64* %28
%29 = call i64 @U64(i32 327033209)
%30 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 7
store i64 %29, i64* %30
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
%32 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%33 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 0
%36 = call i32 @SHA512iv(i8* %32, i32 %34, i8* %12, i64* %35)
%37 = call i32 @put_hex_string(i8* %12)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%39 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%40 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = call i32 @SHA512(i8* %39, i32 %41, i8* %12)
%43 = call i32 @put_hex_string(i8* %12)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
%45 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 0
%46 = call i32 @put_hex_string(i8* %45)
store i32 0, i32* %1
%47 = load i8*, i8** %4
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@__const.main.ibuf = [18 x i8] c"test input string\00"
@__const.main.ibufhash = [65 x i8] c"6\EE_}(\A8\F3V\92\D7\1C\0C\1Cx\EE\C1\C9\E4\B9_\A4\08\02`h\D5ZpAp\00\8D\A2\19\8F\16\D9|\90\13\EAVBEO\08\C6/\CB.\F2\A8<!\BEa\7F\80\105\08\D8\10\AF\00"
@SHA512_DIGEST_LENGTH = global i32 0
@.str = [26 x i8] c"SHA512_DIGEST_LENGTH: %d\0A\00"
@.str.3 = [64 x i8] c"SHA512 of \22test input string\22 generated from independent source\00"
@str = [64 x i8] c"New implemenatation sha512iv() with old IV supplied as argument\00"
@str.4 = [48 x i8] c"OpenSSL Implemntation sha512() with build in IV\00"
define i32 @main() {
%1 = alloca [18 x i8]
%2 = alloca [65 x i8]
%3 = alloca [8 x i64]
%4 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [65 x i8], [65 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @SHA512_DIGEST_LENGTH
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = bitcast [8 x i64]* %3 to i8*
%11 = load i32, i32* @SHA512_DIGEST_LENGTH
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i64 @U64(i32 -205731576)
%14 = getelementptr inbounds [8 x i64], [8 x i64]* %3, i64 0, i64 0
store i64 %13, i64* %14
%15 = tail call i64 @U64(i32 -2067093701)
%16 = getelementptr inbounds [8 x i64], [8 x i64]* %3, i64 0, i64 1
store i64 %15, i64* %16
%17 = tail call i64 @U64(i32 -23791573)
%18 = getelementptr inbounds [8 x i64], [8 x i64]* %3, i64 0, i64 2
store i64 %17, i64* %18
%19 = tail call i64 @U64(i32 1595750129)
%20 = getelementptr inbounds [8 x i64], [8 x i64]* %3, i64 0, i64 3
store i64 %19, i64* %20
%21 = tail call i64 @U64(i32 -1377402159)
%22 = getelementptr inbounds [8 x i64], [8 x i64]* %3, i64 0, i64 4
store i64 %21, i64* %22
%23 = tail call i64 @U64(i32 725511199)
%24 = getelementptr inbounds [8 x i64], [8 x i64]* %3, i64 0, i64 5
store i64 %23, i64* %24
%25 = tail call i64 @U64(i32 -79577749)
%26 = getelementptr inbounds [8 x i64], [8 x i64]* %3, i64 0, i64 6
store i64 %25, i64* %26
%27 = tail call i64 @U64(i32 327033209)
%28 = getelementptr inbounds [8 x i64], [8 x i64]* %3, i64 0, i64 7
store i64 %27, i64* %28
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
%30 = call i32 @strlen(i8* %4)
%31 = call i32 @SHA512iv(i8* %4, i32 %30, i8* %9, i64* %14)
%32 = call i32 @put_hex_string(i8* %9)
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.4, i64 0, i64 0))
%34 = call i32 @strlen(i8* %4)
%35 = call i32 @SHA512(i8* %4, i32 %34, i8* %9)
%36 = call i32 @put_hex_string(i8* %9)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @put_hex_string(i8* %5)
ret i32 0
}