#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(unsigned char *, char *, unsigned char);
void GetHexHash(unsigned char *hash, unsigned char **hex_hash, char **error) {
  int i, j;
  *hex_hash = (unsigned char *)malloc(65 * sizeof(unsigned char));
  if (hex_hash == NULL) {
    *error = "malloc";
    return;
  }
  for (i = 0, j = 0; i < 32; i++, j += 2)
    sprintf((*hex_hash + j), "%02X", hash[i]);
  *error = "success";
}


x86 assembly (clang, -O0):
<GetHexHash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x41,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    1166 <GetHexHash+0x46>
mov    -0x18(%rbp),%rax
lea    0xea2(%rip),%rcx
mov    %rcx,(%rax)
jmp    11c9 <GetHexHash+0xa9>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jge    11bb <GetHexHash+0x9b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe6c(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    1174 <GetHexHash+0x54>
mov    -0x18(%rbp),%rax
lea    0xe46(%rip),%rcx
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetHexHash>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
mov    $0x41,%edi
call   1030 <malloc@plt>
mov    %rax,(%r15)
movzbl 0x0(%r13),%edx
lea    0xeb5(%rip),%r12
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <sprintf@plt>
add    $0x1,%r13
mov    $0x2,%ebx
nop
mov    (%r15),%rdi
add    %rbx,%rdi
movzbl 0x0(%r13),%edx
mov    %r12,%rsi
call   1040 <sprintf@plt>
add    $0x2,%rbx
add    $0x1,%r13
cmp    $0x40,%rbx
jne    1160 <GetHexHash+0x40>
lea    0xe7d(%rip),%rax
mov    %rax,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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