#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ str_escape_display(char *, int);
int /*<<< orphan*/ str_escape_format_convert(char const *, char *, int *,
                                             char *, int);
int str_escape_get_len(char const *, char *);
int /*<<< orphan*/ str_escape_traverse_dec(char *, char *, int *);
int main(int argc, char **argv) {
  const char *cstr = "北京市:串结束\0\\x2哇哈哈:串结束\0So stupid,呵呵xxEND";
  char *buf, *dst;
  int len = 0, tmpLen = 0;
  buf = (char *)malloc(512);
  if (buf == NULL) {
    return -1;
  }
  memset(buf, 0, 512);
  dst = (char *)malloc(1024);
  if (buf == NULL) {
    return -1;
  }
  memset(dst, 0, 1024);
  printf("\n===========================================\n");
  printf("整个字节串的长度为:%u\n", (len = str_escape_get_len(cstr, "END")));
  printf("多字节编码字符输出显示(module==NULL):\n");
  tmpLen = len;
  str_escape_format_convert(cstr, buf, &tmpLen, NULL, 0);
  str_escape_display(buf, tmpLen);
  printf("\n多字节编码字符输出显示(module==\\x%%02x):\n");
  memset(buf, 0, 512);
  tmpLen = len;
  str_escape_format_convert(cstr, buf, &tmpLen, "\\x%02x", 4);
  str_escape_display(buf, tmpLen);
  printf("\n将多字节编码字符重新以正常形式输出：\n");
  memset(dst, 0, 1024);
  str_escape_traverse_dec(buf, dst, &tmpLen);
  str_escape_display(dst, tmpLen);
  putc('\n', stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d4 <main+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <main+0x1a5>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1209 <main+0x89>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <main+0x1a5>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1090 <str_escape_get_len@plt>
mov    %eax,%esi
mov    %esi,-0x2c(%rbp)
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1060 <str_escape_format_convert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   10a0 <str_escape_display@plt>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    0xe42(%rip),%rcx
mov    $0x4,%r8d
call   1060 <str_escape_format_convert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   10a0 <str_escape_display@plt>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1080 <str_escape_traverse_dec@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   10a0 <str_escape_display@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <putc@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x200,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     12d9 <main+0x149>
mov    %rax,%rbx
xor    %r14d,%r14d
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
lea    0xe0e(%rip),%r13
lea    0xe68(%rip),%rsi
mov    %r13,%rdi
call   10a0 <str_escape_get_len@plt>
mov    %eax,%ebp
lea    0xe37(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,0x4(%rsp)
lea    0x4(%rsp),%r12
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <str_escape_format_convert@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   10b0 <str_escape_display@plt>
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    %ebp,0x4(%rsp)
lea    0xe2c(%rip),%rcx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    $0x4,%r8d
call   1070 <str_escape_format_convert@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   10b0 <str_escape_display@plt>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1090 <str_escape_traverse_dec@plt>
mov    0x4(%rsp),%esi
mov    %r15,%rdi
call   10b0 <str_escape_display@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1060 <putc@plt>
jmp    12df <main+0x14f>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [65 x i8] c"\E5\8C\97\E4\BA\AC\E5\B8\82:\E4\B8\B2\E7\BB\93\E6\9D\9F\00\\x2\E5\93\87\E5\93\88\E5\93\88:\E4\B8\B2\E7\BB\93\E6\9D\9F\00So stupid,\E5\91\B5\E5\91\B5xxEND\00"
@.str.1 = [46 x i8] c"\0A===========================================\0A\00"
@.str.2 = [32 x i8] c"\E6\95\B4\E4\B8\AA\E5\AD\97\E8\8A\82\E4\B8\B2\E7\9A\84\E9\95\BF\E5\BA\A6\E4\B8\BA:%u\0A\00"
@.str.3 = [4 x i8] c"END\00"
@.str.4 = [50 x i8] c"\E5\A4\9A\E5\AD\97\E8\8A\82\E7\BC\96\E7\A0\81\E5\AD\97\E7\AC\A6\E8\BE\93\E5\87\BA\E6\98\BE\E7\A4\BA(module==NULL):\0A\00"
@.str.5 = [54 x i8] c"\0A\E5\A4\9A\E5\AD\97\E8\8A\82\E7\BC\96\E7\A0\81\E5\AD\97\E7\AC\A6\E8\BE\93\E5\87\BA\E6\98\BE\E7\A4\BA(module==\\x%%02x):\0A\00"
@.str.6 = [7 x i8] c"\\x%02x\00"
@.str.7 = [57 x i8] c"\0A\E5\B0\86\E5\A4\9A\E5\AD\97\E8\8A\82\E7\BC\96\E7\A0\81\E5\AD\97\E7\AC\A6\E9\87\8D\E6\96\B0\E4\BB\A5\E6\AD\A3\E5\B8\B8\E5\BD\A2\E5\BC\8F\E8\BE\93\E5\87\BA\EF\BC\9A\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 0, i32* %9
store i32 0, i32* %10
%11 = call i64 @malloc(i32 512)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %60
16: ; preds = %2
%17 = load i8*, i8** %7
%18 = call i32 @memset(i8* %17, i32 0, i32 512)
%19 = call i64 @malloc(i32 1024)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %8
%21 = load i8*, i8** %7
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 -1, i32* %3
br label %60
24: ; preds = %16
%25 = load i8*, i8** %8
%26 = call i32 @memset(i8* %25, i32 0, i32 1024)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%28 = load i8*, i8** %6
%29 = call i32 @str_escape_get_len(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32 %29, i32* %9
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32, i32* %9
store i32 %32, i32* %10
%33 = load i8*, i8** %6
%34 = load i8*, i8** %7
%35 = call i32 @str_escape_format_convert(i8* %33, i8* %34, i32* %10, i8* null, i32 0)
%36 = load i8*, i8** %7
%37 = load i32, i32* %10
%38 = call i32 @str_escape_display(i8* %36, i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
%40 = load i8*, i8** %7
%41 = call i32 @memset(i8* %40, i32 0, i32 512)
%42 = load i32, i32* %9
store i32 %42, i32* %10
%43 = load i8*, i8** %6
%44 = load i8*, i8** %7
%45 = call i32 @str_escape_format_convert(i8* %43, i8* %44, i32* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 4)
%46 = load i8*, i8** %7
%47 = load i32, i32* %10
%48 = call i32 @str_escape_display(i8* %46, i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.7, i64 0, i64 0))
%50 = load i8*, i8** %8
%51 = call i32 @memset(i8* %50, i32 0, i32 1024)
%52 = load i8*, i8** %7
%53 = load i8*, i8** %8
%54 = call i32 @str_escape_traverse_dec(i8* %52, i8* %53, i32* %10)
%55 = load i8*, i8** %8
%56 = load i32, i32* %10
%57 = call i32 @str_escape_display(i8* %55, i32 %56)
%58 = load i32, i32* @stdout
%59 = call i32 @putc(i8 signext 10, i32 %58)
store i32 0, i32* %3
br label %60
60: ; preds = %24, %23, %15
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [65 x i8] c"\E5\8C\97\E4\BA\AC\E5\B8\82:\E4\B8\B2\E7\BB\93\E6\9D\9F\00\\x2\E5\93\87\E5\93\88\E5\93\88:\E4\B8\B2\E7\BB\93\E6\9D\9F\00So stupid,\E5\91\B5\E5\91\B5xxEND\00"
@.str.2 = [32 x i8] c"\E6\95\B4\E4\B8\AA\E5\AD\97\E8\8A\82\E4\B8\B2\E7\9A\84\E9\95\BF\E5\BA\A6\E4\B8\BA:%u\0A\00"
@.str.3 = [4 x i8] c"END\00"
@.str.5 = [54 x i8] c"\0A\E5\A4\9A\E5\AD\97\E8\8A\82\E7\BC\96\E7\A0\81\E5\AD\97\E7\AC\A6\E8\BE\93\E5\87\BA\E6\98\BE\E7\A4\BA(module==\\x%%02x):\0A\00"
@.str.6 = [7 x i8] c"\\x%02x\00"
@stdout = global i32 0
@str = [45 x i8] c"\0A===========================================\00"
@str.8 = [49 x i8] c"\E5\A4\9A\E5\AD\97\E8\8A\82\E7\BC\96\E7\A0\81\E5\AD\97\E7\AC\A6\E8\BE\93\E5\87\BA\E6\98\BE\E7\A4\BA(module==NULL):\00"
@str.9 = [56 x i8] c"\0A\E5\B0\86\E5\A4\9A\E5\AD\97\E8\8A\82\E7\BC\96\E7\A0\81\E5\AD\97\E7\AC\A6\E9\87\8D\E6\96\B0\E4\BB\A5\E6\AD\A3\E5\B8\B8\E5\BD\A2\E5\BC\8F\E8\BE\93\E5\87\BA\EF\BC\9A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 @malloc(i32 512)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %32, label %8
8: ; preds = %2
%9 = tail call i32 @memset(i8* %6, i32 0, i32 512)
%10 = tail call i64 @malloc(i32 1024)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @memset(i8* %11, i32 0, i32 1024)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @str_escape_get_len(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.8, i64 0, i64 0))
store i32 %14, i32* %3
%17 = call i32 @str_escape_format_convert(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %6, i32* %3, i8* null, i32 0)
%18 = load i32, i32* %3
%19 = call i32 @str_escape_display(i8* %6, i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
%21 = call i32 @memset(i8* %6, i32 0, i32 512)
store i32 %14, i32* %3
%22 = call i32 @str_escape_format_convert(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %6, i32* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 4)
%23 = load i32, i32* %3
%24 = call i32 @str_escape_display(i8* %6, i32 %23)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.9, i64 0, i64 0))
%26 = call i32 @memset(i8* %11, i32 0, i32 1024)
%27 = call i32 @str_escape_traverse_dec(i8* %6, i8* %11, i32* %3)
%28 = load i32, i32* %3
%29 = call i32 @str_escape_display(i8* %11, i32 %28)
%30 = load i32, i32* @stdout
%31 = call i32 @putc(i8 signext 10, i32 %30)
br label %32
32: ; preds = %2, %8
%33 = phi i32 [ 0, %8 ], [ -1, %2 ]
ret i32 %33
}