#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) {
  putc('"', stream);
  for (; *str != '\0'; str++)
    if (*str == '\n') {
      fputs("\\n\"", stream);
      if (str[1] == '\0')
        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    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1040 <putc@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ef <print_escaped+0xcf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1199 <print_escaped+0x79>
mov    -0x8(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1184 <print_escaped+0x64>
jmp    11fd <print_escaped+0xdd>
mov    -0x8(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1030 <fputs@plt>
jmp    11d9 <print_escaped+0xb9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     11b9 <print_escaped+0x99>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11c7 <print_escaped+0xa7>
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    11de <print_escaped+0xbe>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113e <print_escaped+0x1e>
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1040 <putc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_escaped>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x22,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
lea    0xebe(%rip),%r15
lea    0xebb(%rip),%r12
jmp    116f <print_escaped+0x4f>
nopl   0x0(%rax,%rax,1)
mov    $0x5c,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
movzbl (%rbx),%eax
movsbl %al,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x21,%al
jle    1180 <print_escaped+0x60>
cmp    $0x22,%al
je     1150 <print_escaped+0x30>
cmp    $0x5c,%al
je     1150 <print_escaped+0x30>
jmp    1160 <print_escaped+0x40>
cmp    $0xa,%al
jne    11ba <print_escaped+0x9a>
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r14,%rcx
call   1040 <fwrite@plt>
cmpb   $0x0,0x1(%rbx)
je     11d6 <print_escaped+0xb6>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rdi
mov    %r14,%rcx
call   1040 <fwrite@plt>
add    $0x1,%rbx
jmp    116f <print_escaped+0x4f>
test   %al,%al
jne    1160 <print_escaped+0x40>
mov    $0x22,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
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) {
%3 = alloca i32*
%4 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
%5 = load i32*, i32** %3
%6 = call i32 @putc(i8 signext 34, i32* %5)
br label %7
7: ; preds = %48, %2
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %51
12: ; preds = %7
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 10
br i1 %16, label %17, label %29
17: ; preds = %12
%18 = load i32*, i32** %3
%19 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %18)
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %17
br label %54
26: ; preds = %17
%27 = load i32*, i32** %3
%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 = %12
%30 = load i8*, i8** %4
%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** %4
%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** %3
%41 = call i32 @putc(i8 signext 92, i32* %40)
br label %42
42: ; preds = %39, %34
%43 = load i8*, i8** %4
%44 = load i8, i8* %43
%45 = load i32*, i32** %3
%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** %4
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %4
br label %7
51: ; preds = %7
%52 = load i32*, i32** %3
%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* nocapture %1) {
%3 = tail call i32 @putc(i8 signext 34, i32* %0)
br label %4
4: ; preds = %20, %2
%5 = phi i8* [ %1, %2 ], [ %21, %20 ]
%6 = load i8, i8* %5
switch i8 %6, label %17 [
i8 0, label %22
i8 10, label %7
i8 34, label %14
i8 92, label %14
]
7: ; preds = %4
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 3, i64 1, i32* %0)
%9 = getelementptr inbounds i8, i8* %5, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %7
%13 = 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 %20
14: ; preds = %4, %4
%15 = tail call i32 @putc(i8 signext 92, i32* %0)
%16 = load i8, i8* %5
br label %17
17: ; preds = %4, %14
%18 = phi i8 [ %6, %4 ], [ %16, %14 ]
%19 = tail call i32 @putc(i8 signext %18, i32* %0)
br label %20
20: ; preds = %12, %17
%21 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
22: ; preds = %4
%23 = tail call i32 @putc(i8 signext 34, i32* %0)
br label %24
24: ; preds = %7, %22
ret void
}