#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 *charset_hexstring_to_byte(char *, int /*<<< orphan*/);
char *lib_stralloc(char *);
char *charset_replace_hexcodes(char *source) {
  char *destination = lib_stralloc(source ? source : "");
  if (destination) {
    char *pread = destination;
    char *pwrite = destination;
    while (*pread != 0) {
      if (*pread == '$') {
        pread = charset_hexstring_to_byte(pread, pwrite++);
      } else {
        *pwrite++ = *pread++;
      }
    }
    *pwrite = 0;
  }
  return destination;
}


x86 assembly (clang, -O0):
<charset_replace_hexcodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1144 <charset_replace_hexcodes+0x24>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1154 <charset_replace_hexcodes+0x34>
lea    0xeb5(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1154 <charset_replace_hexcodes+0x34>
mov    -0x28(%rbp),%rdi
call   1030 <lib_stralloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ed <charset_replace_hexcodes+0xcd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e6 <charset_replace_hexcodes+0xc6>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
jne    11bf <charset_replace_hexcodes+0x9f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%esi
call   1040 <charset_hexstring_to_byte@plt>
mov    %rax,-0x18(%rbp)
jmp    11e1 <charset_replace_hexcodes+0xc1>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    117c <charset_replace_hexcodes+0x5c>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charset_replace_hexcodes>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
lea    0xed2(%rip),%rax
cmove  %rax,%rdi
call   1030 <lib_stralloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1178 <charset_replace_hexcodes+0x58>
mov    %r14d,%ebp
mov    %r14,%rax
mov    %r14,%rbx
jmp    1161 <charset_replace_hexcodes+0x41>
nopw   0x0(%rax,%rax,1)
mov    %rax,%rdi
mov    %ebp,%esi
call   1040 <charset_hexstring_to_byte@plt>
add    $0x1,%rbx
add    $0x1,%ebp
movzbl (%rax),%ecx
cmp    $0x24,%cl
je     1150 <charset_replace_hexcodes+0x30>
test   %cl,%cl
je     1175 <charset_replace_hexcodes+0x55>
add    $0x1,%rax
mov    %cl,(%rbx)
jmp    115a <charset_replace_hexcodes+0x3a>
movb   $0x0,(%rbx)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @charset_replace_hexcodes(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i8*, i8** %2
br label %11
10: ; preds = %1
br label %11
11: ; preds = %10, %8
%12 = phi i8* [ %9, %8 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %10 ]
%13 = call i8* @lib_stralloc(i8* %12)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %44
16: ; preds = %11
%17 = load i8*, i8** %3
store i8* %17, i8** %4
%18 = load i8*, i8** %3
store i8* %18, i8** %5
br label %19
19: ; preds = %41, %16
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %42
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 36
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
%33 = ptrtoint i8* %31 to i32
%34 = call i8* @charset_hexstring_to_byte(i8* %30, i32 %33)
store i8* %34, i8** %4
br label %41
35: ; preds = %24
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
%38 = load i8, i8* %36
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %5
store i8 %38, i8* %39
br label %41
41: ; preds = %35, %29
br label %19
42: ; preds = %19
%43 = load i8*, i8** %5
store i8 0, i8* %43
br label %44
44: ; preds = %42, %11
%45 = load i8*, i8** %3
ret i8* %45
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @charset_replace_hexcodes(i8* %0) {
%2 = icmp eq i8* %0, null
%3 = select i1 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%4 = tail call i8* @lib_stralloc(i8* %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %20, label %6
6: ; preds = %1, %16
%7 = phi i8* [ %17, %16 ], [ %4, %1 ]
%8 = phi i8* [ %18, %16 ], [ %4, %1 ]
%9 = load i8, i8* %7
switch i8 %9, label %14 [
i8 0, label %19
i8 36, label %10
]
10: ; preds = %6
%11 = ptrtoint i8* %8 to i64
%12 = trunc i64 %11 to i32
%13 = tail call i8* @charset_hexstring_to_byte(i8* %7, i32 %12)
br label %16
14: ; preds = %6
%15 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %9, i8* %8
br label %16
16: ; preds = %14, %10
%17 = phi i8* [ %13, %10 ], [ %15, %14 ]
%18 = getelementptr inbounds i8, i8* %8, i64 1
br label %6
19: ; preds = %6
store i8 0, i8* %8
br label %20
20: ; preds = %19, %1
ret i8* %4
}