#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 /*<<< orphan*/ sprintf(char *, char *, unsigned char);
char *quote_char(char *buf, char ch) {
  buf[0] = '\\';
  if (ch < ' ')
    sprintf(buf + 1, "%2.2X", (unsigned char)ch);
  else {
    buf[1] = buf[2] = '\0';
    switch (ch) {
    case '\'':
    case '\\':
    case '<':
    case '>':
      buf[1] = ch;
      break;
    default:
      buf[0] = ch;
    }
  }
  return buf;
}


x86 assembly (clang, -O0):
<quote_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x5c,(%rax)
movsbl -0x9(%rbp),%eax
cmp    $0x20,%eax
jge    1153 <quote_char+0x43>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xebb(%rip),%rsi
movzbl -0x9(%rbp),%edx
call   1030 <sprintf@plt>
jmp    11c8 <quote_char+0xb8>
mov    -0x8(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
movsbl -0x9(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x27,%eax
je     11ab <quote_char+0x9b>
jmp    1178 <quote_char+0x68>
mov    -0x10(%rbp),%eax
sub    $0x3c,%eax
je     11ab <quote_char+0x9b>
jmp    1189 <quote_char+0x79>
mov    -0x10(%rbp),%eax
sub    $0x3e,%eax
je     11ab <quote_char+0x9b>
jmp    119a <quote_char+0x8a>
mov    -0x10(%rbp),%eax
sub    $0x5c,%eax
jne    11ba <quote_char+0xaa>
jmp    11ab <quote_char+0x9b>
mov    -0x9(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
jmp    11c3 <quote_char+0xb3>
mov    -0x9(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
jmp    11c8 <quote_char+0xb8>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quote_char>:
push   %rbx
mov    %rdi,%rbx
movb   $0x5c,(%rdi)
cmp    $0x1f,%sil
jg     1133 <quote_char+0x23>
lea    0x1(%rbx),%rdi
movzbl %sil,%edx
lea    0xed4(%rip),%rsi
call   1030 <sprintf@plt>
jmp    115c <quote_char+0x4c>
movw   $0x0,0x1(%rbx)
lea    -0x27(%rsi),%eax
cmp    $0x35,%al
ja     1159 <quote_char+0x49>
movzbl %al,%eax
movabs $0x20000000a00001,%rcx
bt     %rax,%rcx
jae    1159 <quote_char+0x49>
mov    %sil,0x1(%rbx)
jmp    115c <quote_char+0x4c>
mov    %sil,(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%2.2X\00"
define i8* @quote_char(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, i64 0
store i8 92, i8* %6
%7 = load i8, i8* %4
%8 = sext i8 %7 to i32
%9 = icmp slt i32 %8, 32
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %4
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %13)
br label %31
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 2
store i8 0, i8* %17
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8 0, i8* %19
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
switch i32 %21, label %26 [
i32 39, label %22
i32 92, label %22
i32 60, label %22
i32 62, label %22
]
22: ; preds = %15, %15, %15, %15
%23 = load i8, i8* %4
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 %23, i8* %25
br label %30
26: ; preds = %15
%27 = load i8, i8* %4
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 0
store i8 %27, i8* %29
br label %30
30: ; preds = %26, %22
br label %31
31: ; preds = %30, %10
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
@.str = [6 x i8] c"%2.2X\00"
define i8* @quote_char(i8* returned writeonly %0, i8 signext %1) {
store i8 92, i8* %0
%3 = icmp slt i8 %1, 32
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = tail call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %1)
br label %12
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %0, i64 2
store i8 0, i8* %8
%9 = getelementptr inbounds i8, i8* %0, i64 1
store i8 0, i8* %9
switch i8 %1, label %11 [
i8 39, label %10
i8 92, label %10
i8 60, label %10
i8 62, label %10
]
10: ; preds = %7, %7, %7, %7
store i8 %1, i8* %9
br label %12
11: ; preds = %7
store i8 %1, i8* %0
br label %12
12: ; preds = %10, %11, %4
ret i8* %0
}