#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*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strcat(char *, char *);
char *char_to_charhexa(unsigned char *data, int l) {
  static char resultat[3000];
  int n;
  char ch[3];
  resultat[0] = '\0';
  for (n = 0; n < l; n++) {
    sprintf(ch, "%02hx", (unsigned char)data[n]);
    strcat(resultat, ch);
  }
  return resultat;
}


x86 assembly (clang, -O0):
<char_to_charhexa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,0x2f0a(%rip)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1183 <char_to_charhexa+0x63>
lea    -0x13(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xea4(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
lea    -0x13(%rbp),%rsi
lea    0x2ed0(%rip),%rdi
call   1030 <strcat@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113d <char_to_charhexa+0x1d>
lea    0x2eb6(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_to_charhexa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0x0,0x2f0e(%rip)
test   %esi,%esi
jle    1184 <char_to_charhexa+0x64>
mov    %rdi,%r15
mov    %esi,%r13d
xor    %ebp,%ebp
lea    0xebb(%rip),%r14
lea    0x5(%rsp),%rbx
lea    0x2eef(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <sprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcat@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1160 <char_to_charhexa+0x40>
lea    0x2eb5(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@char_to_charhexa.resultat = internal global [3000 x i8] zeroinitializer
@.str = [6 x i8] c"%02hx\00"
define i8* @char_to_charhexa(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [3 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8 0, i8* getelementptr inbounds ([3000 x i8], [3000 x i8]* @char_to_charhexa.resultat, 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 [3 x i8], [3 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 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %17)
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%20 = call i32 @strcat(i8* getelementptr inbounds ([3000 x i8], [3000 x i8]* @char_to_charhexa.resultat, i64 0, i64 0), i8* %19)
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 ([3000 x i8], [3000 x i8]* @char_to_charhexa.resultat, i64 0, i64 0)
}

LLVM IR (-O2):
@char_to_charhexa.resultat = internal global [3000 x i8] zeroinitializer
@.str = [6 x i8] c"%02hx\00"
define i8* @char_to_charhexa(i8* nocapture %0, i32 %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
store i8 0, i8* getelementptr inbounds ([3000 x i8], [3000 x i8]* @char_to_charhexa.resultat, 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 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %11)
%13 = call i32 @strcat(i8* getelementptr inbounds ([3000 x i8], [3000 x i8]* @char_to_charhexa.resultat, i64 0, i64 0), i8* %4)
%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 ([3000 x i8], [3000 x i8]* @char_to_charhexa.resultat, i64 0, i64 0)
}