#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 *, char const);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
void asciiToHex(const char *s, char *s_hex) {
  int i;
  char tmp[3] = "";
  strcpy(s_hex, "");
  for (i = 0; i < strlen(s); i++) {
    sprintf(tmp, "%02hX", s[i]);
    strcat(s_hex, tmp);
  }
}


x86 assembly (clang, -O0):
<asciiToHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x17(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11da <asciiToHex+0x8a>
lea    -0x17(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xe4a(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x17(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1187 <asciiToHex+0x37>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asciiToHex>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r13
movb   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
lea    0xe9f(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11bf <asciiToHex+0x7f>
xor    %ebx,%ebx
lea    0xe7d(%rip),%r15
lea    0xc(%rsp),%r12
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%r13,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
add    $0x1,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1190 <asciiToHex+0x50>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"%02hX\00"
define void @asciiToHex(i8* %0, i8* %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %2, %8
%9 = phi i64 [ %14, %8 ], [ 0, %2 ]
%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.1, i64 0, i64 0), i8 signext %11)
%13 = call i32 @strcat(i8* %1, i8* %4)
%14 = add nuw nsw i64 %9, 1
%15 = call i32 @strlen(i8* %0)
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %8, label %18
18: ; preds = %8, %2
ret void
}