#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*/ sha256(unsigned char *, char const *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
void sha256_hex(char out[65], const char *data) {
  unsigned char hash[32];
  int i;
  sha256(hash, data);
  for (i = 0; i < 32; i++)
    sprintf(out + (i * 2), "%02x", hash[i]);
  out[64] = '\0';
}


x86 assembly (clang, -O0):
<sha256_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <sha256@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x20,-0x34(%rbp)
jge    1180 <sha256_hex+0x60>
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x34(%rbp),%rax
lea    0xe98(%rip),%rsi
movzbl -0x30(%rbp,%rax,1),%edx
call   1040 <sprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1144 <sha256_hex+0x24>
mov    -0x8(%rbp),%rax
movb   $0x0,0x40(%rax)
add    $0x40,%rsp
pop    %rbp
ret

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

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

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