#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 */
char asciiToHex(char const);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char *, int);
void setHexString(char *dest, const char *src) {
  int len = strlen(src);
  int i = 0;
  char tmp = '\0';
  for (i = 0; i < len; i++) {
    tmp = asciiToHex(*(src + i));
    strncat(dest, &tmp, 1);
  }
}


x86 assembly (clang, -O0):
<setHexString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119e <setHexString+0x6e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <asciiToHex@plt>
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1040 <strncat@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115e <setHexString+0x2e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setHexString>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
movb   $0x0,0xf(%rsp)
test   %eax,%eax
jle    1187 <setHexString+0x57>
mov    %eax,%r13d
xor    %ebx,%ebx
lea    0xf(%rsp),%r15
xchg   %ax,%ax
movsbl (%r12,%rbx,1),%edi
call   1050 <asciiToHex@plt>
mov    %al,0xf(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <strncat@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1160 <setHexString+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @setHexString(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
store i32 0, i32* %6
store i8 0, i8* %7
store i32 0, i32* %6
br label %10
10: ; preds = %23, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call signext i8 @asciiToHex(i8 signext %19)
store i8 %20, i8* %7
%21 = load i8*, i8** %3
%22 = call i32 @strncat(i8* %21, i8* %7, i32 1)
br label %23
23: ; preds = %14
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %10
26: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @setHexString(i8* %0, i8* %1) {
%3 = alloca i8
%4 = tail call i32 @strlen(i8* %1)
store i8 0, i8* %3
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %14, %8 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = call signext i8 @asciiToHex(i8 signext %11)
store i8 %12, i8* %3
%13 = call i32 @strncat(i8* %0, i8* %3, i32 1)
%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 void
}