#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 sscanf(char const *, char *, unsigned int *);
void hexstring_to_asciistring(unsigned char *dest, const unsigned char *text) {
  unsigned int ch;
  for (; sscanf((const char *)text, "%2x", &ch) == 1; text += 2) {
    if (ch == 0)
      ch = 48;
    *dest++ = ch;
  }
  *dest = 0;
}


x86 assembly (clang, -O0):
<hexstring_to_asciistring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed5(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    1175 <hexstring_to_asciistring+0x65>
cmpl   $0x0,-0x14(%rbp)
jne    114e <hexstring_to_asciistring+0x3e>
movl   $0x30,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    1120 <hexstring_to_asciistring+0x10>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexstring_to_asciistring>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xedb(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    1185 <hexstring_to_asciistring+0x75>
add    $0x2,%rbx
lea    0xebe(%rip),%r15
lea    0x4(%rsp),%r12
jmp    116e <hexstring_to_asciistring+0x5e>
nopl   0x0(%rax)
mov    %al,(%r14)
add    $0x1,%r14
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <sscanf@plt>
add    $0x2,%rbx
cmp    $0x1,%eax
jne    1185 <hexstring_to_asciistring+0x75>
mov    0x4(%rsp),%eax
test   %eax,%eax
jne    1150 <hexstring_to_asciistring+0x40>
movl   $0x30,0x4(%rsp)
mov    $0x30,%eax
jmp    1150 <hexstring_to_asciistring+0x40>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%2x\00"
define void @hexstring_to_asciistring(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %6
6: ; preds = %19, %2
%7 = load i8*, i8** %4
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %5)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %22
10: ; preds = %6
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 48, i32* %5
br label %14
14: ; preds = %13, %10
%15 = load i32, i32* %5
%16 = trunc i32 %15 to i8
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
store i8 %16, i8* %17
br label %19
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 2
store i8* %21, i8** %4
br label %6
22: ; preds = %6
%23 = load i8*, i8** %3
store i8 0, i8* %23
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%2x\00"
define void @hexstring_to_asciistring(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %20
7: ; preds = %2, %13
%8 = phi i8* [ %17, %13 ], [ %1, %2 ]
%9 = phi i8* [ %16, %13 ], [ %0, %2 ]
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %7
store i32 48, i32* %3
br label %13
13: ; preds = %12, %7
%14 = phi i32 [ 48, %12 ], [ %10, %7 ]
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %15, i8* %9
%17 = getelementptr inbounds i8, i8* %8, i64 2
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%19 = icmp eq i32 %18, 1
br i1 %19, label %7, label %20
20: ; preds = %13, %2
%21 = phi i8* [ %0, %2 ], [ %16, %13 ]
store i8 0, i8* %21
ret void
}