#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char const, int /*<<< orphan*/ *);
void print_escaped(FILE *stream, const char *str, const char *str_end) {
  putc('"', stream);
  for (; str != str_end; str++)
    if (*str == '\n') {
      fputs("\\n\"", stream);
      if (str + 1 == str_end)
        return;
      fputs("\n\"", stream);
    } else {
      if (*str == '"' || *str == '\\')
        putc('\\', stream);
      putc(*str, stream);
    }
  putc('"', stream);
}


x86 assembly (clang, -O0):
<print_escaped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1040 <putc@plt>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11f2 <print_escaped+0xd2>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    119c <print_escaped+0x7c>
mov    -0x8(%rbp),%rsi
lea    0xe95(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
cmp    -0x18(%rbp),%rax
jne    1187 <print_escaped+0x67>
jmp    1200 <print_escaped+0xe0>
mov    -0x8(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1030 <fputs@plt>
jmp    11dc <print_escaped+0xbc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     11bc <print_escaped+0x9c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11ca <print_escaped+0xaa>
mov    -0x8(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <putc@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <putc@plt>
jmp    11e1 <print_escaped+0xc1>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1142 <print_escaped+0x22>
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1040 <putc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_escaped>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    $0x22,%edi
mov    %r15,%rsi
call   1030 <putc@plt>
cmp    %r14,%rbx
je     11c8 <print_escaped+0xa8>
lea    0xeb1(%rip),%r12
lea    0xeae(%rip),%r13
jmp    1184 <print_escaped+0x64>
nopl   0x0(%rax,%rax,1)
mov    $0x5c,%edi
mov    %r15,%rsi
call   1030 <putc@plt>
movzbl (%rbx),%eax
movsbl %al,%edi
mov    %r15,%rsi
call   1030 <putc@plt>
add    $0x1,%rbx
cmp    %r14,%rbx
je     11c8 <print_escaped+0xa8>
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     1160 <print_escaped+0x40>
cmp    $0x22,%al
je     1160 <print_escaped+0x40>
cmp    $0xa,%al
jne    1170 <print_escaped+0x50>
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r12,%rdi
mov    %r15,%rcx
call   1040 <fwrite@plt>
lea    0x1(%rbx),%rax
cmp    %r14,%rax
je     11de <print_escaped+0xbe>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r13,%rdi
mov    %r15,%rcx
call   1040 <fwrite@plt>
jmp    117b <print_escaped+0x5b>
mov    $0x22,%edi
mov    %r15,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putc@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"\\n\22\00"
@.str.1 = [3 x i8] c"\0A\22\00"
define void @print_escaped(i32* nocapture %0, i8* %1, i8* readnone %2) {
%4 = tail call i32 @putc(i8 signext 34, i32* %0)
%5 = icmp eq i8* %1, %2
br i1 %5, label %24, label %6
6: ; preds = %3, %21
%7 = phi i8* [ %22, %21 ], [ %1, %3 ]
%8 = load i8, i8* %7
switch i8 %8, label %18 [
i8 10, label %9
i8 34, label %15
i8 92, label %15
]
9: ; preds = %6
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 3, i64 1, i32* %0)
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = icmp eq i8* %11, %2
br i1 %12, label %26, label %13
13: ; preds = %9
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %21
15: ; preds = %6, %6
%16 = tail call i32 @putc(i8 signext 92, i32* %0)
%17 = load i8, i8* %7
br label %18
18: ; preds = %6, %15
%19 = phi i8 [ %8, %6 ], [ %17, %15 ]
%20 = tail call i32 @putc(i8 signext %19, i32* %0)
br label %21
21: ; preds = %13, %18
%22 = getelementptr inbounds i8, i8* %7, i64 1
%23 = icmp eq i8* %22, %2
br i1 %23, label %24, label %6
24: ; preds = %21, %3
%25 = tail call i32 @putc(i8 signext 34, i32* %0)
br label %26
26: ; preds = %9, %24
ret void
}