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


x86 assembly (clang, -O0):
<GetHexHash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x41,%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1164 <GetHexHash+0x44>
mov    -0x18(%rbp),%rax
lea    0xeac(%rip),%rcx
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11cc <GetHexHash+0xac>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jge    11b6 <GetHexHash+0x96>
mov    -0x28(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe78(%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    1172 <GetHexHash+0x52>
mov    -0x18(%rbp),%rax
lea    0xe52(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetHexHash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r13
mov    $0x41,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     1185 <GetHexHash+0x65>
mov    %rax,%r15
mov    %rbx,(%rsp)
xor    %r14d,%r14d
lea    0xebd(%rip),%r12
lea    0xebb(%rip),%rbp
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%r13,%r14,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <sprintf@plt>
add    $0x1,%r14
add    $0x2,%rbx
cmp    $0x20,%r14
jne    1160 <GetHexHash+0x40>
mov    (%rsp),%rbx
jmp    118f <GetHexHash+0x6f>
lea    0xe74(%rip),%rbp
xor    %r15d,%r15d
mov    %rbp,(%rbx)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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