#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 *);
int /*<<< orphan*/ strcpy(char *, char *);
void bytesToString(unsigned char *bytes, int t_bytes, char *string) {
  int i;
  char tmp[3] = "";
  strcpy(string, "");
  for (i = 0; i < t_bytes; i++) {
    sprintf(tmp, "%02hx", bytes[i]);
    strcat(string, tmp);
  }
}


x86 assembly (clang, -O0):
<bytesToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x1f(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bd <bytesToString+0x7d>
lea    -0x1f(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe67(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x1f(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117a <bytesToString+0x3a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bytesToString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %esi,%ebx
mov    %rdi,%r14
movb   $0x0,0x6(%rsp)
movw   $0x0,0x4(%rsp)
lea    0xeaf(%rip),%rsi
mov    %rdx,%rdi
call   1030 <strcpy@plt>
test   %ebx,%ebx
jle    11a4 <bytesToString+0x74>
mov    %ebx,%r13d
xor    %ebp,%ebp
lea    0xe92(%rip),%r15
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <sprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <strcat@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1180 <bytesToString+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"%02hx\00"
define void @bytesToString(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [3 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = bitcast [3 x i8]* %8 to i8*
%10 = load i8*, i8** %6
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %12
12: ; preds = %27, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %5
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %22)
%24 = load i8*, i8** %6
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%26 = call i32 @strcat(i8* %24, i8* %25)
br label %27
27: ; preds = %16
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %12
30: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"%02hx\00"
define void @bytesToString(i8* nocapture %0, i32 %1, i8* %2) {
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %18
8: ; preds = %3
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %16, %10 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %13)
%15 = call i32 @strcat(i8* %2, i8* %5)
%16 = add nuw nsw i64 %11, 1
%17 = icmp eq i64 %16, %9
br i1 %17, label %18, label %10
18: ; preds = %10, %3
ret void
}