#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*/ snprintf(char *, int, char *, unsigned char);
int /*<<< orphan*/ strncat(char *, char *, int);
char *hex2ascii(unsigned char *p, int l) {
  int i;
  static char out[1024];
  char temp[1024];
  out[0] = '\0';
  for (i = 0; i < l; i++) {
    snprintf(temp, 1024, "%02x", p[i]);
    strncat(out, temp, 1024);
  }
  return out;
}


x86 assembly (clang, -O0):
<hex2ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,0x2f07(%rip)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1196 <hex2ascii+0x76>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    $0x400,%esi
lea    0xe99(%rip),%rdx
movzbl (%rax,%rcx,1),%ecx
call   1030 <snprintf@plt>
lea    -0x410(%rbp),%rsi
lea    0x2ec2(%rip),%rdi
mov    $0x400,%edx
call   1040 <strncat@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1140 <hex2ascii+0x20>
lea    0x2ea3(%rip),%rax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2ascii>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
movb   $0x0,0x2f08(%rip)
test   %esi,%esi
jle    118e <hex2ascii+0x6e>
mov    %rdi,%r15
mov    %esi,%r13d
xor    %ebp,%ebp
lea    0xeb5(%rip),%r14
mov    %rsp,%rbx
lea    0x2eeb(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15,%rbp,1),%ecx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1030 <snprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <strncat@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1160 <hex2ascii+0x40>
lea    0x2eab(%rip),%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@hex2ascii.out = internal global [1024 x i8] zeroinitializer
@.str = [5 x i8] c"%02x\00"
define i8* @hex2ascii(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8 0, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @hex2ascii.out, i64 0, i64 0)
store i32 0, i32* %5
br label %7
7: ; preds = %21, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %24
11: ; preds = %7
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = call i32 @snprintf(i8* %12, i32 1024, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %17)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = call i32 @strncat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @hex2ascii.out, i64 0, i64 0), i8* %19, i32 1024)
br label %21
21: ; preds = %11
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %7
24: ; preds = %7
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @hex2ascii.out, i64 0, i64 0)
}

LLVM IR (-O2):
@hex2ascii.out = internal global [1024 x i8] zeroinitializer
@.str = [5 x i8] c"%02x\00"
define i8* @hex2ascii(i8* nocapture %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
store i8 0, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @hex2ascii.out, i64 0, i64 0)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %14, %8 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = call i32 @snprintf(i8* %4, i32 1024, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %11)
%13 = call i32 @strncat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @hex2ascii.out, i64 0, i64 0), i8* %4, i32 1024)
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %7
br i1 %15, label %16, label %8
16: ; preds = %8, %2
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @hex2ascii.out, i64 0, i64 0)
}