#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 */
void *char_hex(char const);
void char_encode(char *dst, const char ch) {
  *dst++ = '\\';
  *dst++ = 'x';
  *dst++ = char_hex(ch >> 4 & 0xf);
  *dst++ = char_hex(ch & 0xf);
}


x86 assembly (clang, -O0):
<char_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x78,(%rax)
movsbl -0x9(%rbp),%eax
sar    $0x4,%eax
and    $0xf,%eax
movsbl %al,%edi
call   1030 <char_hex@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
movsbl -0x9(%rbp),%eax
and    $0xf,%eax
movsbl %al,%edi
call   1030 <char_hex@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_encode>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
movw   $0x785c,(%rdi)
mov    %ebx,%eax
shr    $0x4,%al
movzbl %al,%edi
call   1030 <char_hex@plt>
mov    %al,0x2(%r14)
and    $0xf,%ebx
mov    %ebx,%edi
call   1030 <char_hex@plt>
mov    %al,0x3(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @char_encode(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i32 1
store i8* %6, i8** %3
store i8 92, i8* %5
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i32 1
store i8* %8, i8** %3
store i8 120, i8* %7
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = ashr i32 %10, 4
%12 = and i32 %11, 15
%13 = trunc i32 %12 to i8
%14 = call i8* @char_hex(i8 signext %13)
%15 = ptrtoint i8* %14 to i8
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %3
store i8 %15, i8* %16
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = and i32 %19, 15
%21 = trunc i32 %20 to i8
%22 = call i8* @char_hex(i8 signext %21)
%23 = ptrtoint i8* %22 to i8
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
store i8 %23, i8* %24
ret void
}

LLVM IR (-O2):
define void @char_encode(i8* nocapture writeonly %0, i8 signext %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 1
store i8 92, i8* %0
%4 = getelementptr inbounds i8, i8* %0, i64 2
store i8 120, i8* %3
%5 = lshr i8 %1, 4
%6 = tail call i8* @char_hex(i8 signext %5)
%7 = ptrtoint i8* %6 to i64
%8 = trunc i64 %7 to i8
%9 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %8, i8* %4
%10 = and i8 %1, 15
%11 = tail call i8* @char_hex(i8 signext %10)
%12 = ptrtoint i8* %11 to i64
%13 = trunc i64 %12 to i8
store i8 %13, i8* %9
ret void
}