#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 hex_to_dec(char);
void hex_to_str(char *input, char *output, unsigned input_len,
                unsigned output_len) {
  for (unsigned int i = 0; i <= input_len / 2; ++i) {
    output[i] = (hex_to_dec(input[2 * i]) * 16 + hex_to_dec(input[2 * i + 1]));
  }
}


x86 assembly (clang, -O0):
<hex_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
ja     1192 <hex_to_str+0x82>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <hex_to_dec@plt>
shl    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <hex_to_dec@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <hex_to_str+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_str>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
shr    %r15d
add    $0x1,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r12,%rbx,2),%edi
call   1030 <hex_to_dec@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x1(%r12,%rbx,2),%edi
call   1030 <hex_to_dec@plt>
add    %ebp,%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <hex_to_str+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @hex_to_str(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %38, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %7
%13 = udiv i32 %12, 2
%14 = icmp ule i32 %11, %13
br i1 %14, label %15, label %41
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i32, i32* %9
%18 = mul i32 2, %17
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @hex_to_dec(i8 signext %21)
%23 = mul nsw i32 %22, 16
%24 = load i8*, i8** %5
%25 = load i32, i32* %9
%26 = mul i32 2, %25
%27 = add i32 %26, 1
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8, i8* %29
%31 = call i32 @hex_to_dec(i8 signext %30)
%32 = add nsw i32 %23, %31
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %6
%35 = load i32, i32* %9
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %15
%39 = load i32, i32* %9
%40 = add i32 %39, 1
store i32 %40, i32* %9
br label %10
41: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @hex_to_str(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = lshr i32 %2, 1
%6 = add nuw i32 %5, 1
%7 = zext i32 %6 to i64
br label %9
8: ; preds = %9
ret void
9: ; preds = %4, %9
%10 = phi i64 [ 0, %4 ], [ %23, %9 ]
%11 = shl nuw i64 %10, 1
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @hex_to_dec(i8 signext %13)
%15 = shl nsw i32 %14, 4
%16 = or i64 %11, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = tail call i32 @hex_to_dec(i8 signext %18)
%20 = add nsw i32 %19, %15
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 %21, i8* %22
%23 = add nuw nsw i64 %10, 1
%24 = icmp eq i64 %23, %7
br i1 %24, label %8, label %9
}