#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 u_int32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int buf_put2c(char *, char *);
int snprintf(char *, size_t, char *, unsigned short);
int u8_escape_wchar(char *buf, size_t sz, u_int32_t ch) {
  assert(sz > 2);
  if (ch == L'\n')
    return buf_put2c(buf, "\\n");
  else if (ch == L'\t')
    return buf_put2c(buf, "\\t");
  else if (ch == L'\r')
    return buf_put2c(buf, "\\r");
  else if (ch == L'\e')
    return buf_put2c(buf, "\\e");
  else if (ch == L'\b')
    return buf_put2c(buf, "\\b");
  else if (ch == L'\f')
    return buf_put2c(buf, "\\f");
  else if (ch == L'\v')
    return buf_put2c(buf, "\\v");
  else if (ch == L'\a')
    return buf_put2c(buf, "\\a");
  else if (ch == L'\\')
    return buf_put2c(buf, "\\\\");
  else if (ch < 32 || ch == 0x7f)
    return snprintf(buf, sz, "\\x%.2hhx", (unsigned char)ch);
  else if (ch > 0xFFFF)
    return snprintf(buf, sz, "\\U%.8x", (u_int32_t)ch);
  else if (ch >= 0x80)
    return snprintf(buf, sz, "\\u%.4hx", (unsigned short)ch);
  buf[0] = (char)ch;
  buf[1] = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<u8_escape_wchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x2,-0x18(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0xa,-0x1c(%rbp)
jne    1177 <u8_escape_wchar+0x47>
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1050 <buf_put2c@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
cmpl   $0x9,-0x1c(%rbp)
jne    1199 <u8_escape_wchar+0x69>
mov    -0x10(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1050 <buf_put2c@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
cmpl   $0xd,-0x1c(%rbp)
jne    11bb <u8_escape_wchar+0x8b>
mov    -0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1050 <buf_put2c@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
cmpl   $0x1b,-0x1c(%rbp)
jne    11dd <u8_escape_wchar+0xad>
mov    -0x10(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1050 <buf_put2c@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
cmpl   $0x8,-0x1c(%rbp)
jne    11ff <u8_escape_wchar+0xcf>
mov    -0x10(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1050 <buf_put2c@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
cmpl   $0xc,-0x1c(%rbp)
jne    1221 <u8_escape_wchar+0xf1>
mov    -0x10(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1050 <buf_put2c@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
cmpl   $0xb,-0x1c(%rbp)
jne    1243 <u8_escape_wchar+0x113>
mov    -0x10(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1050 <buf_put2c@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
cmpl   $0x7,-0x1c(%rbp)
jne    1265 <u8_escape_wchar+0x135>
mov    -0x10(%rbp),%rdi
lea    0xdbd(%rip),%rsi
call   1050 <buf_put2c@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
cmpl   $0x5c,-0x1c(%rbp)
jne    1287 <u8_escape_wchar+0x157>
mov    -0x10(%rbp),%rdi
lea    0xd9e(%rip),%rsi
call   1050 <buf_put2c@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
cmpl   $0x20,-0x1c(%rbp)
jl     129b <u8_escape_wchar+0x16b>
cmpl   $0x7f,-0x1c(%rbp)
jne    12c0 <u8_escape_wchar+0x190>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
movzbl %al,%eax
lea    0xd6b(%rip),%rdx
movzwl %ax,%ecx
call   1030 <snprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
cmpl   $0xffff,-0x1c(%rbp)
jle    12ef <u8_escape_wchar+0x1bf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
lea    0xd45(%rip),%rdx
movzwl %ax,%ecx
call   1030 <snprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
cmpl   $0x80,-0x1c(%rbp)
jl     131e <u8_escape_wchar+0x1ee>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
lea    0xd1d(%rip),%rdx
movzwl %ax,%ecx
call   1030 <snprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <u8_escape_wchar+0x23f>
jmp    1323 <u8_escape_wchar+0x1f3>
jmp    1328 <u8_escape_wchar+0x1f8>
jmp    132d <u8_escape_wchar+0x1fd>
jmp    1332 <u8_escape_wchar+0x202>
jmp    1337 <u8_escape_wchar+0x207>
jmp    133c <u8_escape_wchar+0x20c>
jmp    1341 <u8_escape_wchar+0x211>
jmp    1346 <u8_escape_wchar+0x216>
jmp    134b <u8_escape_wchar+0x21b>
jmp    1350 <u8_escape_wchar+0x220>
jmp    1355 <u8_escape_wchar+0x225>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u8_escape_wchar>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %edi,%edi
cmp    $0x3,%rsi
setae  %dil
call   1040 <assert@plt>
lea    -0x7(%rbx),%eax
cmp    $0x55,%eax
ja     11a3 <u8_escape_wchar+0x73>
lea    0xea5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0x1002(%rip),%rsi
jmp    11d1 <u8_escape_wchar+0xa1>
lea    0xff0(%rip),%rsi
jmp    11d1 <u8_escape_wchar+0xa1>
lea    0xfde(%rip),%rsi
jmp    11d1 <u8_escape_wchar+0xa1>
lea    0xfd2(%rip),%rsi
jmp    11d1 <u8_escape_wchar+0xa1>
lea    0xfdb(%rip),%rsi
jmp    11d1 <u8_escape_wchar+0xa1>
lea    0xfcf(%rip),%rsi
jmp    11d1 <u8_escape_wchar+0xa1>
lea    0xfbd(%rip),%rsi
jmp    11d1 <u8_escape_wchar+0xa1>
cmp    $0x20,%ebx
jl     11de <u8_escape_wchar+0xae>
cmp    $0x7f,%ebx
je     11de <u8_escape_wchar+0xae>
cmp    $0x10000,%ebx
jb     11ea <u8_escape_wchar+0xba>
movzwl %bx,%ecx
lea    0xfbd(%rip),%rdx
jmp    11fc <u8_escape_wchar+0xcc>
lea    0xf99(%rip),%rsi
jmp    11d1 <u8_escape_wchar+0xa1>
lea    0xf9f(%rip),%rsi
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <buf_put2c@plt>
movzbl %bl,%ecx
lea    0xf8b(%rip),%rdx
jmp    11fc <u8_escape_wchar+0xcc>
cmp    $0x80,%ebx
jb     120c <u8_escape_wchar+0xdc>
movzwl %bx,%ecx
lea    0xf87(%rip),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <snprintf@plt>
mov    %bl,(%r14)
movb   $0x0,0x1(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\n\00"
@.str.1 = [3 x i8] c"\\t\00"
@.str.2 = [3 x i8] c"\\r\00"
@.str.3 = [3 x i8] c"\\e\00"
@.str.4 = [3 x i8] c"\\b\00"
@.str.5 = [3 x i8] c"\\f\00"
@.str.6 = [3 x i8] c"\\v\00"
@.str.7 = [3 x i8] c"\\a\00"
@.str.8 = [3 x i8] c"\\\\\00"
@.str.9 = [9 x i8] c"\\x%.2hhx\00"
@.str.10 = [7 x i8] c"\\U%.8x\00"
@.str.11 = [8 x i8] c"\\u%.4hx\00"
define i32 @u8_escape_wchar(i8* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%8 = load i64, i64* %6
%9 = icmp ugt i64 %8, 2
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, 10
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i32 @buf_put2c(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %4
br label %114
17: ; preds = %3
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 9
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i8*, i8** %5
%22 = call i32 @buf_put2c(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %22, i32* %4
br label %114
23: ; preds = %17
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, 13
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i8*, i8** %5
%28 = call i32 @buf_put2c(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 %28, i32* %4
br label %114
29: ; preds = %23
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 27
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i8*, i8** %5
%34 = call i32 @buf_put2c(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 %34, i32* %4
br label %114
35: ; preds = %29
%36 = load i32, i32* %7
%37 = icmp eq i32 %36, 8
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i8*, i8** %5
%40 = call i32 @buf_put2c(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 %40, i32* %4
br label %114
41: ; preds = %35
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, 12
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i8*, i8** %5
%46 = call i32 @buf_put2c(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32 %46, i32* %4
br label %114
47: ; preds = %41
%48 = load i32, i32* %7
%49 = icmp eq i32 %48, 11
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i8*, i8** %5
%52 = call i32 @buf_put2c(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32 %52, i32* %4
br label %114
53: ; preds = %47
%54 = load i32, i32* %7
%55 = icmp eq i32 %54, 7
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i8*, i8** %5
%58 = call i32 @buf_put2c(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32 %58, i32* %4
br label %114
59: ; preds = %53
%60 = load i32, i32* %7
%61 = icmp eq i32 %60, 92
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i8*, i8** %5
%64 = call i32 @buf_put2c(i8* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32 %64, i32* %4
br label %114
65: ; preds = %59
%66 = load i32, i32* %7
%67 = icmp slt i32 %66, 32
br i1 %67, label %71, label %68
68: ; preds = %65
%69 = load i32, i32* %7
%70 = icmp eq i32 %69, 127
br i1 %70, label %71, label %78
71: ; preds = %68, %65
%72 = load i8*, i8** %5
%73 = load i64, i64* %6
%74 = load i32, i32* %7
%75 = trunc i32 %74 to i8
%76 = zext i8 %75 to i16
%77 = call i32 @snprintf(i8* %72, i64 %73, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i16 zeroext %76)
store i32 %77, i32* %4
br label %114
78: ; preds = %68
%79 = load i32, i32* %7
%80 = icmp sgt i32 %79, 65535
br i1 %80, label %81, label %87
81: ; preds = %78
%82 = load i8*, i8** %5
%83 = load i64, i64* %6
%84 = load i32, i32* %7
%85 = trunc i32 %84 to i16
%86 = call i32 @snprintf(i8* %82, i64 %83, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i16 zeroext %85)
store i32 %86, i32* %4
br label %114
87: ; preds = %78
%88 = load i32, i32* %7
%89 = icmp sge i32 %88, 128
br i1 %89, label %90, label %96
90: ; preds = %87
%91 = load i8*, i8** %5
%92 = load i64, i64* %6
%93 = load i32, i32* %7
%94 = trunc i32 %93 to i16
%95 = call i32 @snprintf(i8* %91, i64 %92, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i16 zeroext %94)
store i32 %95, i32* %4
br label %114
96: ; preds = %87
br label %97
97: ; preds = %96
br label %98
98: ; preds = %97
br label %99
99: ; preds = %98
br label %100
100: ; preds = %99
br label %101
101: ; preds = %100
br label %102
102: ; preds = %101
br label %103
103: ; preds = %102
br label %104
104: ; preds = %103
br label %105
105: ; preds = %104
br label %106
106: ; preds = %105
br label %107
107: ; preds = %106
%108 = load i32, i32* %7
%109 = trunc i32 %108 to i8
%110 = load i8*, i8** %5
%111 = getelementptr inbounds i8, i8* %110, i64 0
store i8 %109, i8* %111
%112 = load i8*, i8** %5
%113 = getelementptr inbounds i8, i8* %112, i64 1
store i8 0, i8* %113
store i32 1, i32* %4
br label %114
114: ; preds = %107, %90, %81, %71, %62, %56, %50, %44, %38, %32, %26, %20, %14
%115 = load i32, i32* %4
ret i32 %115
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\n\00"
@.str.1 = [3 x i8] c"\\t\00"
@.str.2 = [3 x i8] c"\\r\00"
@.str.3 = [3 x i8] c"\\e\00"
@.str.4 = [3 x i8] c"\\b\00"
@.str.5 = [3 x i8] c"\\f\00"
@.str.6 = [3 x i8] c"\\v\00"
@.str.7 = [3 x i8] c"\\a\00"
@.str.8 = [3 x i8] c"\\\\\00"
@.str.9 = [9 x i8] c"\\x%.2hhx\00"
@.str.10 = [7 x i8] c"\\U%.8x\00"
@.str.11 = [8 x i8] c"\\u%.4hx\00"
define i32 @u8_escape_wchar(i8* %0, i64 %1, i32 %2) {
%4 = icmp ugt i64 %1, 2
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
switch i32 %2, label %25 [
i32 10, label %7
i32 9, label %9
i32 13, label %11
i32 27, label %13
i32 8, label %15
i32 12, label %17
i32 11, label %19
i32 7, label %21
i32 92, label %23
]
7: ; preds = %3
%8 = tail call i32 @buf_put2c(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %46
9: ; preds = %3
%10 = tail call i32 @buf_put2c(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %46
11: ; preds = %3
%12 = tail call i32 @buf_put2c(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %46
13: ; preds = %3
%14 = tail call i32 @buf_put2c(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %46
15: ; preds = %3
%16 = tail call i32 @buf_put2c(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %46
17: ; preds = %3
%18 = tail call i32 @buf_put2c(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %46
19: ; preds = %3
%20 = tail call i32 @buf_put2c(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %46
21: ; preds = %3
%22 = tail call i32 @buf_put2c(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %46
23: ; preds = %3
%24 = tail call i32 @buf_put2c(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
br label %46
25: ; preds = %3
%26 = icmp slt i32 %2, 32
%27 = icmp eq i32 %2, 127
%28 = or i1 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = trunc i32 %2 to i16
%31 = and i16 %30, 255
%32 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i16 zeroext %31)
br label %46
33: ; preds = %25
%34 = icmp ugt i32 %2, 65535
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = trunc i32 %2 to i16
%37 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i16 zeroext %36)
br label %46
38: ; preds = %33
%39 = icmp ugt i32 %2, 127
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = trunc i32 %2 to i16
%42 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i16 zeroext %41)
br label %46
43: ; preds = %38
%44 = trunc i32 %2 to i8
store i8 %44, i8* %0
%45 = getelementptr inbounds i8, i8* %0, i64 1
store i8 0, i8* %45
br label %46
46: ; preds = %43, %40, %35, %29, %23, %21, %19, %17, %15, %13, %11, %9, %7
%47 = phi i32 [ %8, %7 ], [ %10, %9 ], [ %12, %11 ], [ %14, %13 ], [ %16, %15 ], [ %18, %17 ], [ %20, %19 ], [ %22, %21 ], [ %24, %23 ], [ %32, %29 ], [ %37, %35 ], [ %42, %40 ], [ 1, %43 ]
ret i32 %47
}