#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
void wfc_util_htoa(unsigned char *pHexaBuff, int szHexaBuff,
                   char *pAsciiStringBuff, int szAsciiStringBuff) {
  int i, j;
  char hex_table[] = {'0', '1', '2', '3', '4', '5', '6', '7',
                      '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
  if ((szHexaBuff * 2) > szAsciiStringBuff) {
    printf("wfc_util_htoa : not enough buffer size(%d)", szAsciiStringBuff);
    printf("\n");
    return;
  }
  memset(pAsciiStringBuff, 0, szAsciiStringBuff);
  for (i = 0, j = 0; i < szHexaBuff; i++, j += 2) {
    pAsciiStringBuff[j] = hex_table[pHexaBuff[i] >> 4];
    pAsciiStringBuff[j + 1] = hex_table[pHexaBuff[i] & 0x0F];
  }
  return;
}


x86 assembly (clang, -O0):
<wfc_util_htoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0xec3(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xec0(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jle    117f <wfc_util_htoa+0x5f>
mov    -0x1c(%rbp),%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1208 <wfc_util_htoa+0xe8>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1203 <wfc_util_htoa+0xe3>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
cltq
mov    -0x40(%rbp,%rax,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
cltq
mov    -0x40(%rbp,%rax,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    119b <wfc_util_htoa+0x7b>
jmp    1208 <wfc_util_htoa+0xe8>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wfc_util_htoa>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%r15d
lea    (%r15,%r15,1),%eax
cmp    %ecx,%eax
jle    115f <wfc_util_htoa+0x2f>
lea    0xec9(%rip),%rdi
mov    %ecx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %rdx,%rdi
xor    %esi,%esi
mov    %ecx,%edx
call   1050 <memset@plt>
test   %r15d,%r15d
jle    11b9 <wfc_util_htoa+0x89>
mov    %r15d,%edi
xor    %ecx,%ecx
lea    0xe7e(%rip),%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx,%rcx,1),%esi
shr    $0x4,%rsi
movzbl (%rsi,%rdx,1),%eax
mov    %al,(%r14,%rcx,2)
movzbl (%rbx,%rcx,1),%eax
and    $0xf,%eax
movzbl (%rax,%rdx,1),%eax
mov    %al,0x1(%r14,%rcx,2)
add    $0x1,%rcx
cmp    %rcx,%rdi
jne    1190 <wfc_util_htoa+0x60>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.wfc_util_htoa.hex_table = [16 x i8] c"0123456789ABCDEF"
@.str = [43 x i8] c"wfc_util_htoa : not enough buffer size(%d)\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @wfc_util_htoa(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [16 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%12 = bitcast [16 x i8]* %11 to i8*
%13 = load i32, i32* %6
%14 = mul nsw i32 %13, 2
%15 = load i32, i32* %8
%16 = icmp sgt i32 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load i32, i32* %8
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %65
21: ; preds = %4
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = call i32 @memset(i8* %22, i32 0, i32 %23)
store i32 0, i32* %9
store i32 0, i32* %10
br label %25
25: ; preds = %59, %21
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %64
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = ashr i32 %35, 4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = load i8*, i8** %7
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 %39, i8* %43
%44 = load i8*, i8** %5
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = and i32 %49, 15
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = load i8*, i8** %7
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %54, i64 %57
store i8 %53, i8* %58
br label %59
59: ; preds = %29
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 2
store i32 %63, i32* %10
br label %25
64: ; preds = %25
br label %65
65: ; preds = %64, %17
ret void
}

LLVM IR (-O2):
@__const.wfc_util_htoa.hex_table = [16 x i8] c"0123456789ABCDEF"
@.str = [43 x i8] c"wfc_util_htoa : not enough buffer size(%d)\00"
define void @wfc_util_htoa(i8* nocapture %0, i32 %1, i8* %2, i32 %3) {
%5 = shl nsw i32 %1, 1
%6 = icmp sgt i32 %5, %3
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %3)
%9 = tail call i32 @putchar(i32 10)
br label %35
10: ; preds = %4
%11 = tail call i32 @memset(i8* %2, i32 0, i32 %3)
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %35
13: ; preds = %10
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %32, %15 ]
%17 = phi i64 [ 0, %13 ], [ %33, %15 ]
%18 = getelementptr inbounds i8, i8* %0, i64 %16
%19 = load i8, i8* %18
%20 = lshr i8 %19, 4
%21 = zext i8 %20 to i64
%22 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.wfc_util_htoa.hex_table, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %2, i64 %17
store i8 %23, i8* %24
%25 = load i8, i8* %18
%26 = and i8 %25, 15
%27 = zext i8 %26 to i64
%28 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.wfc_util_htoa.hex_table, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = or i64 %17, 1
%31 = getelementptr inbounds i8, i8* %2, i64 %30
store i8 %29, i8* %31
%32 = add nuw nsw i64 %16, 1
%33 = add nuw nsw i64 %17, 2
%34 = icmp eq i64 %32, %14
br i1 %34, label %35, label %15
35: ; preds = %15, %10, %7
ret void
}