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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ wputc(char, int /*<<< orphan*/ *);
void wprint_escaped(FILE *f, const wchar_t *s, int len) {
  const wchar_t *e = &s[len];
  while (s < e) {
    wint_t x = *s++;
    if (x >= ' ') {
      if (x == '\\')
        wputc(x, f);
      wputc(x, f);
    } else if (x == '\t') {
      wputc(x, f);
    } else if (x == '\n') {
      fprintf(f, "\\n");
    } else {
      fprintf(f, "\\%03o", x);
    }
  }
}


x86 assembly (clang, -O0):
<wprint_escaped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    120f <wprint_escaped+0xef>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%eax
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x20,%eax
jl     11a5 <wprint_escaped+0x85>
movsbl -0x21(%rbp),%eax
cmp    $0x5c,%eax
jne    1191 <wprint_escaped+0x71>
mov    -0x21(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <wputc@plt>
mov    -0x21(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <wputc@plt>
jmp    120a <wprint_escaped+0xea>
movsbl -0x21(%rbp),%eax
cmp    $0x9,%eax
jne    11c6 <wprint_escaped+0xa6>
mov    -0x21(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <wputc@plt>
jmp    1205 <wprint_escaped+0xe5>
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    11ea <wprint_escaped+0xca>
mov    -0x8(%rbp),%rdi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1200 <wprint_escaped+0xe0>
mov    -0x8(%rbp),%rdi
movsbl -0x21(%rbp),%edx
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1205 <wprint_escaped+0xe5>
jmp    120a <wprint_escaped+0xea>
jmp    1146 <wprint_escaped+0x26>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wprint_escaped>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    11d6 <wprint_escaped+0xa6>
mov    %rsi,%rbx
mov    %rdi,%r14
movslq %edx,%rax
lea    (%rsi,%rax,4),%r13
lea    0xea9(%rip),%r15
lea    0xea5(%rip),%r12
jmp    116f <wprint_escaped+0x3f>
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <wputc@plt>
cmp    %r13,%rbx
jae    11d6 <wprint_escaped+0xa6>
mov    (%rbx),%eax
add    $0x4,%rbx
movsbl %al,%ebp
shl    $0x18,%eax
cmp    $0x1f000001,%eax
jl     11a0 <wprint_escaped+0x70>
cmp    $0x5c000000,%eax
jne    1160 <wprint_escaped+0x30>
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <wputc@plt>
jmp    1160 <wprint_escaped+0x30>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0xa000000,%eax
je     11bf <wprint_escaped+0x8f>
cmp    $0x9000000,%eax
je     1160 <wprint_escaped+0x30>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    116a <wprint_escaped+0x3a>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r14,%rcx
call   1050 <fwrite@plt>
jmp    116a <wprint_escaped+0x3a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\n\00"
@.str.1 = [6 x i8] c"\\%03o\00"
define void @wprint_escaped(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32*, i32** %5
%10 = load i32, i32* %6
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %9, i64 %11
store i32* %12, i32** %7
br label %13
13: ; preds = %59, %3
%14 = load i32*, i32** %5
%15 = load i32*, i32** %7
%16 = icmp ult i32* %14, %15
br i1 %16, label %17, label %60
17: ; preds = %13
%18 = load i32*, i32** %5
%19 = getelementptr inbounds i32, i32* %18, i32 1
store i32* %19, i32** %5
%20 = load i32, i32* %18
%21 = trunc i32 %20 to i8
store i8 %21, i8* %8
%22 = load i8, i8* %8
%23 = sext i8 %22 to i32
%24 = icmp sge i32 %23, 32
br i1 %24, label %25, label %37
25: ; preds = %17
%26 = load i8, i8* %8
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 92
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i8, i8* %8
%31 = load i32*, i32** %4
%32 = call i32 @wputc(i8 signext %30, i32* %31)
br label %33
33: ; preds = %29, %25
%34 = load i8, i8* %8
%35 = load i32*, i32** %4
%36 = call i32 @wputc(i8 signext %34, i32* %35)
br label %59
37: ; preds = %17
%38 = load i8, i8* %8
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 9
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i8, i8* %8
%43 = load i32*, i32** %4
%44 = call i32 @wputc(i8 signext %42, i32* %43)
br label %58
45: ; preds = %37
%46 = load i8, i8* %8
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 10
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = load i32*, i32** %4
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %57
52: ; preds = %45
%53 = load i32*, i32** %4
%54 = load i8, i8* %8
%55 = sext i8 %54 to i32
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %52, %49
br label %58
58: ; preds = %57, %41
br label %59
59: ; preds = %58, %33
br label %13
60: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\n\00"
@.str.1 = [6 x i8] c"\\%03o\00"
define void @wprint_escaped(i32* %0, i32* %1, i32 %2) {
%4 = sext i32 %2 to i64
%5 = getelementptr inbounds i32, i32* %1, i64 %4
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %30
7: ; preds = %3, %28
%8 = phi i32* [ %9, %28 ], [ %1, %3 ]
%9 = getelementptr inbounds i32, i32* %8, i64 1
%10 = load i32, i32* %8
%11 = trunc i32 %10 to i8
%12 = shl i32 %10, 24
%13 = ashr exact i32 %12, 24
%14 = icmp sgt i32 %12, 520093696
br i1 %14, label %15, label %21
15: ; preds = %7
%16 = icmp eq i32 %12, 1543503872
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 @wputc(i8 signext %11, i32* %0)
br label %19
19: ; preds = %17, %15
%20 = tail call i32 @wputc(i8 signext %11, i32* %0)
br label %28
21: ; preds = %7
switch i32 %12, label %26 [
i32 150994944, label %22
i32 167772160, label %24
]
22: ; preds = %21
%23 = tail call i32 @wputc(i8 signext %11, i32* %0)
br label %28
24: ; preds = %21
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %28
26: ; preds = %21
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %28
28: ; preds = %22, %26, %24, %19
%29 = icmp ult i32* %9, %5
br i1 %29, label %7, label %30
30: ; preds = %28, %3
ret void
}