#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 SHA256_DIGEST_LENGTH;
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
char *sha2string(unsigned char sha[SHA256_DIGEST_LENGTH]) {
  static char string[65];
  int i = 0;
  for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
    sprintf(string + (i * 2), "%02x", sha[i]);
  }
  string[64] = '\0';
  return string;
}


x86 assembly (clang, -O0):
<sha2string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2eac(%rip),%rcx
cmp    (%rcx),%eax
jge    1174 <sha2string+0x64>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
cltq
lea    0x2f05(%rip),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
lea    0xea3(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1030 <sprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <sha2string+0x1a>
movb   $0x0,0x2f15(%rip)
lea    0x2ece(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha2string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    0x2ec0(%rip),%r12
cmpl   $0x0,(%r12)
jle    1161 <sha2string+0x51>
mov    %rdi,%r14
lea    0x2f1f(%rip),%r13
xor    %ebx,%ebx
lea    0xec6(%rip),%r15
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
add    $0x1,%rbx
movslq (%r12),%rax
add    $0x2,%r13
cmp    %rax,%rbx
jl     1140 <sha2string+0x30>
movb   $0x0,0x2f28(%rip)
lea    0x2ee1(%rip),%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
@sha2string.string = internal global [65 x i8] zeroinitializer
@.str = [5 x i8] c"%02x\00"
define i8* @sha2string(i8* nocapture %0) {
%2 = load i32, i32* @SHA256_DIGEST_LENGTH
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %15
4: ; preds = %1, %4
%5 = phi i64 [ %11, %4 ], [ 0, %1 ]
%6 = shl nuw nsw i64 %5, 1
%7 = getelementptr inbounds [65 x i8], [65 x i8]* @sha2string.string, i64 0, i64 %6
%8 = getelementptr inbounds i8, i8* %0, i64 %5
%9 = load i8, i8* %8
%10 = tail call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %9)
%11 = add nuw nsw i64 %5, 1
%12 = load i32, i32* @SHA256_DIGEST_LENGTH
%13 = sext i32 %12 to i64
%14 = icmp slt i64 %11, %13
br i1 %14, label %4, label %15
15: ; preds = %4, %1
store i8 0, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @sha2string.string, i64 0, i64 64)
ret i8* getelementptr inbounds ([65 x i8], [65 x i8]* @sha2string.string, i64 0, i64 0)
}