#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 htoa(char, char);
int /*<<< orphan*/ memset(char *, char, unsigned long);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
unsigned long strlen(char *);
char *hex2ascii(char *hstr) {
  register unsigned long int i, l;
  char c = 0;
  char a[20480], t[4];
  l = strlen(hstr);
  memset(a, '\0', l + 1);
  for (i = 0; i < l; i++) {
    if (i % 2 != 0) {
      sprintf(t, "%c", htoa(c, hstr[i]));
      strcat(a, t);
    } else
      c = hstr[i];
  }
  return a;
}


x86 assembly (clang, -O0):
<hex2ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5030,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x5020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1224 <hex2ascii+0xd4>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1200 <hex2ascii+0xb0>
lea    -0x5024(%rbp),%rax
mov    %rax,-0x5030(%rbp)
mov    -0x19(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl %dl,%edi
movsbl (%rax,%rcx,1),%esi
call   1050 <htoa@plt>
mov    -0x5030(%rbp),%rdi
mov    %eax,%edx
lea    0xe1d(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x5020(%rbp),%rdi
lea    -0x5024(%rbp),%rsi
call   1060 <strcat@plt>
jmp    120e <hex2ascii+0xbe>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
jmp    1213 <hex2ascii+0xc3>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    118e <hex2ascii+0x3e>
lea    -0x5020(%rbp),%rax
add    $0x5030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2ascii>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5018,%rsp
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%r13
lea    0x1(%rax),%rdx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <memset@plt>
test   %r13,%r13
je     11c7 <hex2ascii+0x87>
xor    %ebx,%ebx
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
xor    %ebp,%ebp
jmp    11b8 <hex2ascii+0x78>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %bl,%edi
movsbl %al,%esi
call   1050 <htoa@plt>
mov    %al,0xc(%rsp)
movb   $0x0,0xd(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <strcat@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     11c7 <hex2ascii+0x87>
movzbl (%r14,%rbp,1),%eax
test   $0x1,%bpl
jne    1190 <hex2ascii+0x50>
mov    %eax,%ebx
jmp    11af <hex2ascii+0x6f>
lea    0x10(%rsp),%rax
add    $0x5018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define i8* @hex2ascii(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8
%6 = alloca [20480 x i8]
%7 = alloca [4 x i8]
store i8* %0, i8** %2
store i8 0, i8* %5
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %4
%10 = getelementptr inbounds [20480 x i8], [20480 x i8]* %6, i64 0, i64 0
%11 = load i64, i64* %4
%12 = add i64 %11, 1
%13 = call i32 @memset(i8* %10, i8 signext 0, i64 %12)
store i64 0, i64* %3
br label %14
14: ; preds = %40, %1
%15 = load i64, i64* %3
%16 = load i64, i64* %4
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %43
18: ; preds = %14
%19 = load i64, i64* %3
%20 = urem i64 %19, 2
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%24 = load i8, i8* %5
%25 = load i8*, i8** %2
%26 = load i64, i64* %3
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @htoa(i8 signext %24, i8 signext %28)
%30 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [20480 x i8], [20480 x i8]* %6, i64 0, i64 0
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%33 = call i32 @strcat(i8* %31, i8* %32)
br label %39
34: ; preds = %18
%35 = load i8*, i8** %2
%36 = load i64, i64* %3
%37 = getelementptr inbounds i8, i8* %35, i64 %36
%38 = load i8, i8* %37
store i8 %38, i8* %5
br label %39
39: ; preds = %34, %22
br label %40
40: ; preds = %39
%41 = load i64, i64* %3
%42 = add i64 %41, 1
store i64 %42, i64* %3
br label %14
43: ; preds = %14
%44 = getelementptr inbounds [20480 x i8], [20480 x i8]* %6, i64 0, i64 0
ret i8* %44
}

LLVM IR (-O2):
define i8* @hex2ascii(i8* nocapture %0) {
%2 = alloca [20480 x i8]
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [20480 x i8], [20480 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add i64 %6, 1
%8 = call i32 @memset(i8* %4, i8 signext 0, i64 %7)
%9 = icmp eq i64 %6, 0
br i1 %9, label %27, label %10
10: ; preds = %1
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
br label %12
12: ; preds = %10, %23
%13 = phi i8 [ 0, %10 ], [ %24, %23 ]
%14 = phi i64 [ 0, %10 ], [ %25, %23 ]
%15 = and i64 %14, 1
%16 = icmp eq i64 %15, 0
%17 = getelementptr inbounds i8, i8* %0, i64 %14
%18 = load i8, i8* %17
br i1 %16, label %23, label %19
19: ; preds = %12
%20 = call i32 @htoa(i8 signext %13, i8 signext %18)
%21 = trunc i32 %20 to i8
store i8 %21, i8* %5
store i8 0, i8* %11
%22 = call i32 @strcat(i8* %4, i8* %5)
br label %23
23: ; preds = %12, %19
%24 = phi i8 [ %13, %19 ], [ %18, %12 ]
%25 = add nuw i64 %14, 1
%26 = icmp eq i64 %25, %6
br i1 %26, label %27, label %12
27: ; preds = %23, %1
ret i8* %4
}