#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__ isprint(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *emit_char(char *p, int i) {
  if (i == '\\') {
    *p++ = '\\';
    *p++ = '\\';
  } else if (isprint(i) && (i != '-')) {
    *p++ = i;
  } else if (i == '\n') {
    *p++ = '\\';
    *p++ = 'n';
  } else if (i == '\r') {
    *p++ = '\\';
    *p++ = 'r';
  } else if (i == '\f') {
    *p++ = '\\';
    *p++ = 'f';
  } else if (i == '\t') {
    *p++ = '\\';
    *p++ = 't';
  } else {
    p += sprintf(p, "\\%03o", i);
  }
  return p;
}


x86 assembly (clang, -O0):
<emit_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x5c,-0xc(%rbp)
jne    1162 <emit_char+0x42>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
jmp    12a1 <emit_char+0x181>
mov    -0xc(%rbp),%edi
call   1030 <isprint@plt>
cmp    $0x0,%rax
je     1199 <emit_char+0x79>
cmpl   $0x2d,-0xc(%rbp)
je     1199 <emit_char+0x79>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    129c <emit_char+0x17c>
cmpl   $0xa,-0xc(%rbp)
jne    11cc <emit_char+0xac>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x6e,(%rax)
jmp    1297 <emit_char+0x177>
cmpl   $0xd,-0xc(%rbp)
jne    11ff <emit_char+0xdf>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x72,(%rax)
jmp    1292 <emit_char+0x172>
cmpl   $0xc,-0xc(%rbp)
jne    1232 <emit_char+0x112>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x66,(%rax)
jmp    128d <emit_char+0x16d>
cmpl   $0x9,-0xc(%rbp)
jne    1265 <emit_char+0x145>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x74,(%rax)
jmp    1288 <emit_char+0x168>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xd8d(%rip),%rsi
call   1040 <sprintf@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    128d <emit_char+0x16d>
jmp    1292 <emit_char+0x172>
jmp    1297 <emit_char+0x177>
jmp    129c <emit_char+0x17c>
jmp    12a1 <emit_char+0x181>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emit_char>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmp    $0x5c,%esi
jne    1138 <emit_char+0x18>
movw   $0x5c5c,(%r14)
add    $0x2,%r14
jmp    1152 <emit_char+0x32>
mov    %esi,%ebx
mov    %esi,%edi
call   1030 <isprint@plt>
cmp    $0x2d,%ebx
je     115d <emit_char+0x3d>
test   %rax,%rax
je     115d <emit_char+0x3d>
mov    %bl,(%r14)
add    $0x1,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    -0x9(%rbx),%eax
cmp    $0x4,%eax
ja     1185 <emit_char+0x65>
lea    0xe94(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movw   $0x745c,(%r14)
jmp    1132 <emit_char+0x12>
movw   $0x6e5c,(%r14)
jmp    1132 <emit_char+0x12>
lea    0xe88(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1040 <sprintf@plt>
cltq
add    %r14,%rax
jmp    1155 <emit_char+0x35>
movw   $0x665c,(%r14)
jmp    1132 <emit_char+0x12>
movw   $0x725c,(%r14)
jmp    1132 <emit_char+0x12>

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

LLVM IR (-O2):
@.str = [6 x i8] c"\\%03o\00"
define i8* @emit_char(i8* writeonly %0, i32 %1) {
%3 = icmp eq i32 %1, 92
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %0, i64 1
store i8 92, i8* %0
%6 = getelementptr inbounds i8, i8* %0, i64 2
store i8 92, i8* %5
br label %32
7: ; preds = %2
%8 = tail call i64 @isprint(i32 %1)
%9 = icmp ne i64 %8, 0
%10 = icmp ne i32 %1, 45
%11 = and i1 %10, %9
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = trunc i32 %1 to i8
%14 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %13, i8* %0
br label %32
15: ; preds = %7
switch i32 %1, label %28 [
i32 10, label %16
i32 13, label %19
i32 12, label %22
i32 9, label %25
]
16: ; preds = %15
%17 = getelementptr inbounds i8, i8* %0, i64 1
store i8 92, i8* %0
%18 = getelementptr inbounds i8, i8* %0, i64 2
store i8 110, i8* %17
br label %32
19: ; preds = %15
%20 = getelementptr inbounds i8, i8* %0, i64 1
store i8 92, i8* %0
%21 = getelementptr inbounds i8, i8* %0, i64 2
store i8 114, i8* %20
br label %32
22: ; preds = %15
%23 = getelementptr inbounds i8, i8* %0, i64 1
store i8 92, i8* %0
%24 = getelementptr inbounds i8, i8* %0, i64 2
store i8 102, i8* %23
br label %32
25: ; preds = %15
%26 = getelementptr inbounds i8, i8* %0, i64 1
store i8 92, i8* %0
%27 = getelementptr inbounds i8, i8* %0, i64 2
store i8 116, i8* %26
br label %32
28: ; preds = %15
%29 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %1)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
br label %32
32: ; preds = %12, %19, %25, %28, %22, %16, %4
%33 = phi i8* [ %6, %4 ], [ %14, %12 ], [ %18, %16 ], [ %21, %19 ], [ %24, %22 ], [ %27, %25 ], [ %31, %28 ]
ret i8* %33
}