#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(char *, int, unsigned char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
void SHA512_Convert(register char *string, register char *hashout,
                    register int len) {
  register int i;
  unsigned char result[64];
  SHA512(string, len, result);
  for (i = 0; i < 64; i++) {
    sprintf(&hashout[i * 2], "%02x", result[i]);
  }
}


x86 assembly (clang, -O0):
<SHA512_Convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x60(%rbp),%rdx
call   1030 <SHA512@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x40,-0x18(%rbp)
jge    1186 <SHA512_Convert+0x66>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x18(%rbp),%rax
lea    0xe92(%rip),%rsi
movzbl -0x60(%rbp,%rax,1),%edx
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114a <SHA512_Convert+0x2a>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SHA512_Convert>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%r15
mov    %rsp,%rax
mov    %edx,%esi
mov    %rax,%rdx
call   1030 <SHA512@plt>
xor    %ebx,%ebx
lea    0xebe(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rsp,%rbx,1),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <sprintf@plt>
add    $0x1,%rbx
add    $0x2,%r15
cmp    $0x40,%rbx
jne    1150 <SHA512_Convert+0x30>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
define void @SHA512_Convert(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [64 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = load i32, i32* %6
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%12 = call i32 @SHA512(i8* %9, i32 %10, i8* %11)
store i32 0, i32* %7
br label %13
13: ; preds = %27, %3
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 64
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = load i32, i32* %7
%19 = mul nsw i32 %18, 2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %25)
br label %27
27: ; preds = %16
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %13
30: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define void @SHA512_Convert(i8* %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%6 = call i32 @SHA512(i8* %0, i32 %2, i8* %5)
br label %7
7: ; preds = %3, %7
%8 = phi i64 [ 0, %3 ], [ %14, %7 ]
%9 = shl nuw nsw i64 %8, 1
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %8
%12 = load i8, i8* %11
%13 = call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %12)
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, 64
br i1 %15, label %16, label %7
16: ; preds = %7
ret void
}