#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ putc(unsigned int, int /*<<< orphan*/ *);
void putc_escaped(unsigned ch, FILE *file) {
  if (ch == '\\' || ch == '-' || ch == ']')
    putc('\\', file);
  if (ch == '\0')
    fprintf(file, "\\0");
  else if (ch < ' ')
    fprintf(file, "\\x%02x", ch);
  else if (ch < 0x7f)
    putc(ch & 0x7f, file);
  else if (ch < 0x10000)
    fprintf(file, "\\u%04x", ch);
  else
    fprintf(file, "\\u+%06x", ch);
}


x86 assembly (clang, -O0):
<putc_escaped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5c,-0x4(%rbp)
je     114d <putc_escaped+0x2d>
cmpl   $0x2d,-0x4(%rbp)
je     114d <putc_escaped+0x2d>
cmpl   $0x5d,-0x4(%rbp)
jne    115b <putc_escaped+0x3b>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1030 <putc@plt>
cmpl   $0x0,-0x4(%rbp)
jne    117c <putc_escaped+0x5c>
mov    -0x10(%rbp),%rdi
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1209 <putc_escaped+0xe9>
cmpl   $0x20,-0x4(%rbp)
jae    11a0 <putc_escaped+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1204 <putc_escaped+0xe4>
cmpl   $0x7f,-0x4(%rbp)
jae    11be <putc_escaped+0x9e>
mov    -0x4(%rbp),%edi
and    $0x7f,%edi
mov    -0x10(%rbp),%rsi
call   1030 <putc@plt>
jmp    11ff <putc_escaped+0xdf>
cmpl   $0x10000,-0x4(%rbp)
jae    11e5 <putc_escaped+0xc5>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11fa <putc_escaped+0xda>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11ff <putc_escaped+0xdf>
jmp    1204 <putc_escaped+0xe4>
jmp    1209 <putc_escaped+0xe9>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putc_escaped>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    -0x2d(%rbx),%eax
cmp    $0x30,%eax
ja     116f <putc_escaped+0x3f>
movabs $0x1800000000001,%rcx
bt     %rax,%rcx
jae    116f <putc_escaped+0x3f>
mov    $0x5c,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
mov    %ebx,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putc@plt>
test   %ebx,%ebx
jne    1193 <putc_escaped+0x63>
lea    0xe86(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <fwrite@plt>
cmp    $0x1f,%ebx
ja     11a1 <putc_escaped+0x71>
lea    0xe64(%rip),%rsi
jmp    11be <putc_escaped+0x8e>
cmp    $0x7e,%ebx
jbe    115e <putc_escaped+0x2e>
cmp    $0xffff,%ebx
ja     11b7 <putc_escaped+0x87>
lea    0xe55(%rip),%rsi
jmp    11be <putc_escaped+0x8e>
lea    0xe53(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"\\0\00"
@.str.1 = [7 x i8] c"\\x%02x\00"
@.str.2 = [7 x i8] c"\\u%04x\00"
@.str.3 = [8 x i8] c"\\u+%06x\00"
define void @putc_escaped(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
store i32 %0, i32* %3
store i32* %1, i32** %4
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 92
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 45
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 93
br i1 %12, label %13, label %16
13: ; preds = %10, %7, %2
%14 = load i32*, i32** %4
%15 = call i32 @putc(i32 92, i32* %14)
br label %16
16: ; preds = %13, %10
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32*, i32** %4
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %51
22: ; preds = %16
%23 = load i32, i32* %3
%24 = icmp ult i32 %23, 32
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32*, i32** %4
%27 = load i32, i32* %3
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %50
29: ; preds = %22
%30 = load i32, i32* %3
%31 = icmp ult i32 %30, 127
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i32, i32* %3
%34 = and i32 %33, 127
%35 = load i32*, i32** %4
%36 = call i32 @putc(i32 %34, i32* %35)
br label %49
37: ; preds = %29
%38 = load i32, i32* %3
%39 = icmp ult i32 %38, 65536
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load i32*, i32** %4
%42 = load i32, i32* %3
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %48
44: ; preds = %37
%45 = load i32*, i32** %4
%46 = load i32, i32* %3
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %44, %40
br label %49
49: ; preds = %48, %32
br label %50
50: ; preds = %49, %25
br label %51
51: ; preds = %50, %19
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\0\00"
@.str.1 = [7 x i8] c"\\x%02x\00"
@.str.2 = [7 x i8] c"\\u%04x\00"
@.str.3 = [8 x i8] c"\\u+%06x\00"
define void @putc_escaped(i32 %0, i32* nocapture %1) {
switch i32 %0, label %7 [
i32 93, label %3
i32 92, label %3
i32 45, label %3
i32 0, label %5
]
3: ; preds = %2, %2, %2
%4 = tail call i32 @putc(i32 92, i32* %1)
br label %13
5: ; preds = %2
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %21
7: ; preds = %2
%8 = icmp ult i32 %0, 32
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %21
11: ; preds = %7
%12 = icmp ult i32 %0, 127
br i1 %12, label %13, label %15
13: ; preds = %3, %11
%14 = tail call i32 @putc(i32 %0, i32* %1)
br label %21
15: ; preds = %11
%16 = icmp ult i32 %0, 65536
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %21
19: ; preds = %15
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %21
21: ; preds = %9, %17, %19, %13, %5
ret void
}