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

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int u8_escape_wchar(char *, int, int);
int /*<<< orphan*/ wprintf(char *, char, char);
int main() {
  setlocale(LC_ALL, "");
  wchar_t wc = L'知';
  char buffer[100] = {};
  wprintf(L"%c==\\u%4x\n", wc, u8_escape_wchar(buffer, 100, wc));
  wprintf(L"%c==\\u%4x\n", wc, wc);
  wprintf(L"%c==\\u%4x\n", 'a', 'a');
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
call   1060 <setlocale@plt>
movl   $0x77e5,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %al,-0x71(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    $0x64,%esi
call   1030 <u8_escape_wchar@plt>
mov    -0x71(%rbp),%cl
lea    0xe6c(%rip),%rdi
movsbl %cl,%esi
movsbl %al,%edx
call   1050 <wprintf@plt>
mov    -0x4(%rbp),%eax
mov    %al,%cl
mov    -0x4(%rbp),%eax
lea    0xe52(%rip),%rdi
movsbl %cl,%esi
movsbl %al,%edx
call   1050 <wprintf@plt>
lea    0xe40(%rip),%rdi
mov    $0x61,%edx
mov    %edx,%esi
call   1050 <wprintf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
lea    0xebb(%rip),%rsi
call   1050 <setlocale@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    %rsp,%rdi
mov    $0x64,%esi
mov    $0x77e5,%edx
call   1030 <u8_escape_wchar@plt>
movsbl %al,%edx
lea    0xe76(%rip),%rbx
mov    %rbx,%rdi
mov    $0xffffffe5,%esi
call   1040 <wprintf@plt>
mov    %rbx,%rdi
mov    $0xffffffe5,%esi
mov    $0xffffffe5,%edx
call   1040 <wprintf@plt>
mov    %rbx,%rdi
mov    $0x61,%esi
mov    $0x61,%edx
call   1040 <wprintf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [11 x i32] [i32 37, i32 99, i32 61, i32 61, i32 92, i32 117, i32 37, i32 52, i32 120, i32 10, i32 0]
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = load i32, i32* @LC_ALL
%4 = call i32 @setlocale(i32 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 30693, i32* %1
%5 = bitcast [100 x i8]* %2 to i8*
%6 = load i32, i32* %1
%7 = trunc i32 %6 to i8
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%9 = load i32, i32* %1
%10 = call i32 @u8_escape_wchar(i8* %8, i32 100, i32 %9)
%11 = trunc i32 %10 to i8
%12 = call i32 @wprintf(i8* bitcast ([11 x i32]* @.str.1 to i8*), i8 signext %7, i8 signext %11)
%13 = load i32, i32* %1
%14 = trunc i32 %13 to i8
%15 = load i32, i32* %1
%16 = trunc i32 %15 to i8
%17 = call i32 @wprintf(i8* bitcast ([11 x i32]* @.str.1 to i8*), i8 signext %14, i8 signext %16)
%18 = call i32 @wprintf(i8* bitcast ([11 x i32]* @.str.1 to i8*), i8 signext 97, i8 signext 97)
ret i32 0
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [11 x i32] [i32 37, i32 99, i32 61, i32 61, i32 92, i32 117, i32 37, i32 52, i32 120, i32 10, i32 0]
define i32 @main() {
%1 = alloca [100 x i8]
%2 = load i32, i32* @LC_ALL
%3 = tail call i32 @setlocale(i32 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = call i32 @u8_escape_wchar(i8* %4, i32 100, i32 30693)
%6 = trunc i32 %5 to i8
%7 = call i32 @wprintf(i8* bitcast ([11 x i32]* @.str.1 to i8*), i8 signext -27, i8 signext %6)
%8 = call i32 @wprintf(i8* bitcast ([11 x i32]* @.str.1 to i8*), i8 signext -27, i8 signext -27)
%9 = call i32 @wprintf(i8* bitcast ([11 x i32]* @.str.1 to i8*), i8 signext 97, i8 signext 97)
ret i32 0
}