#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*/ free(unsigned char *);
unsigned char *get_sha256_hash(char const *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strcat(char *, char *);
char *get_sha256_hash_hex_str(const char *unhashed) {
  unsigned char *hashed = get_sha256_hash(unhashed);
  char *hashed_hex = (char *)malloc(65);
  char next_hex[3];
  int index = 0;
  hashed_hex[0] = '\0';
  for (index = 0; index < 32; index++) {
    sprintf(next_hex, "%02X", hashed[index]);
    strcat(hashed_hex, next_hex);
  }
  free(hashed);
  return hashed_hex;
}


x86 assembly (clang, -O0):
<get_sha256_hash_hex_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <get_sha256_hash@plt>
mov    %rax,-0x10(%rbp)
mov    $0x41,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x20(%rbp)
cmpl   $0x20,-0x20(%rbp)
jge    11cd <get_sha256_hash_hex_str+0x7d>
lea    -0x1b(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
lea    0xe57(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118c <get_sha256_hash_hex_str+0x3c>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sha256_hash_hex_str>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
call   1040 <get_sha256_hash@plt>
mov    %rax,%r14
mov    $0x41,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
movb   $0x0,(%rax)
xor    %ebx,%ebx
lea    0xe82(%rip),%r15
lea    0xd(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbx,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1070 <sprintf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <strcat@plt>
add    $0x1,%rbx
cmp    $0x20,%rbx
jne    1190 <get_sha256_hash_hex_str+0x40>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define i8* @get_sha256_hash_hex_str(i8* %0) {
%2 = alloca [3 x i8]
%3 = tail call i8* @get_sha256_hash(i8* %0)
%4 = tail call i64 @malloc(i32 65)
%5 = inttoptr i64 %4 to i8*
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
store i8 0, i8* %5
br label %7
7: ; preds = %1, %7
%8 = phi i64 [ 0, %1 ], [ %13, %7 ]
%9 = getelementptr inbounds i8, i8* %3, i64 %8
%10 = load i8, i8* %9
%11 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %10)
%12 = call i32 @strcat(i8* %5, i8* %6)
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, 32
br i1 %14, label %15, label %7
15: ; preds = %7
%16 = call i32 @free(i8* %3)
ret i8* %5
}