#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*/ putc(char, int /*<<< orphan*/ *);
int strlen(char const *);
void write_escaped_string(FILE *fp, const char *str) {
  const char *str_limit = str + strlen(str);
  putc('"', fp);
  while (str < str_limit) {
    unsigned char c = (unsigned char)*str++;
    if (c == '\t') {
      putc('\\', fp);
      putc('t', fp);
    } else if (c == '\n') {
      putc('\\', fp);
      putc('n', fp);
    } else if (c == '\r') {
      putc('\\', fp);
      putc('r', fp);
    } else if (c == '\f') {
      putc('\\', fp);
      putc('f', fp);
    } else if (c == '\\' || c == '"') {
      putc('\\', fp);
      putc(c, fp);
    } else
      putc(c, fp);
  }
  putc('"', fp);
}


x86 assembly (clang, -O0):
<write_escaped_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1040 <putc@plt>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    129d <write_escaped_string+0x17d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
cmp    $0x9,%eax
jne    11af <write_escaped_string+0x8f>
mov    -0x8(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <putc@plt>
mov    -0x8(%rbp),%rsi
mov    $0x74,%edi
call   1040 <putc@plt>
jmp    1298 <write_escaped_string+0x178>
movzbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    11dd <write_escaped_string+0xbd>
mov    -0x8(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <putc@plt>
mov    -0x8(%rbp),%rsi
mov    $0x6e,%edi
call   1040 <putc@plt>
jmp    1293 <write_escaped_string+0x173>
movzbl -0x19(%rbp),%eax
cmp    $0xd,%eax
jne    120b <write_escaped_string+0xeb>
mov    -0x8(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <putc@plt>
mov    -0x8(%rbp),%rsi
mov    $0x72,%edi
call   1040 <putc@plt>
jmp    128e <write_escaped_string+0x16e>
movzbl -0x19(%rbp),%eax
cmp    $0xc,%eax
jne    1239 <write_escaped_string+0x119>
mov    -0x8(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <putc@plt>
mov    -0x8(%rbp),%rsi
mov    $0x66,%edi
call   1040 <putc@plt>
jmp    1289 <write_escaped_string+0x169>
movzbl -0x19(%rbp),%eax
cmp    $0x5c,%eax
je     1253 <write_escaped_string+0x133>
movzbl -0x19(%rbp),%eax
cmp    $0x22,%eax
jne    1275 <write_escaped_string+0x155>
mov    -0x8(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <putc@plt>
mov    -0x19(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <putc@plt>
jmp    1284 <write_escaped_string+0x164>
mov    -0x19(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <putc@plt>
jmp    1289 <write_escaped_string+0x169>
jmp    128e <write_escaped_string+0x16e>
jmp    1293 <write_escaped_string+0x173>
jmp    1298 <write_escaped_string+0x178>
jmp    115f <write_escaped_string+0x3f>
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1040 <putc@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_escaped_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    $0x22,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
test   %ebx,%ebx
jle    11be <write_escaped_string+0x9e>
movslq %ebx,%r12
add    %rbp,%r12
lea    0xeaa(%rip),%r15
jmp    1181 <write_escaped_string+0x61>
nopl   0x0(%rax,%rax,1)
mov    %eax,%ebx
mov    $0x5c,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
mov    %ebx,%eax
movsbl %al,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
cmp    %r12,%rbp
jae    11be <write_escaped_string+0x9e>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
lea    -0x9(%rax),%ecx
cmp    $0x19,%cl
ja     11b0 <write_escaped_string+0x90>
mov    $0x74,%bl
movzbl %cl,%ecx
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
mov    $0x6e,%bl
jmp    1162 <write_escaped_string+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x5c,%al
je     1160 <write_escaped_string+0x40>
jmp    1171 <write_escaped_string+0x51>
mov    $0x66,%bl
jmp    1162 <write_escaped_string+0x42>
mov    $0x72,%bl
jmp    1162 <write_escaped_string+0x42>
mov    $0x22,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <putc@plt>

LLVM IR (-O0):
define void @write_escaped_string(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
store i32* %0, i32** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8* %11, i8** %5
%12 = load i32*, i32** %3
%13 = call i32 @putc(i8 signext 34, i32* %12)
br label %14
14: ; preds = %79, %2
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = icmp ult i8* %15, %16
br i1 %17, label %18, label %80
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
%21 = load i8, i8* %19
store i8 %21, i8* %6
%22 = load i8, i8* %6
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %23, 9
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i32*, i32** %3
%27 = call i32 @putc(i8 signext 92, i32* %26)
%28 = load i32*, i32** %3
%29 = call i32 @putc(i8 signext 116, i32* %28)
br label %79
30: ; preds = %18
%31 = load i8, i8* %6
%32 = zext i8 %31 to i32
%33 = icmp eq i32 %32, 10
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32*, i32** %3
%36 = call i32 @putc(i8 signext 92, i32* %35)
%37 = load i32*, i32** %3
%38 = call i32 @putc(i8 signext 110, i32* %37)
br label %78
39: ; preds = %30
%40 = load i8, i8* %6
%41 = zext i8 %40 to i32
%42 = icmp eq i32 %41, 13
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i32*, i32** %3
%45 = call i32 @putc(i8 signext 92, i32* %44)
%46 = load i32*, i32** %3
%47 = call i32 @putc(i8 signext 114, i32* %46)
br label %77
48: ; preds = %39
%49 = load i8, i8* %6
%50 = zext i8 %49 to i32
%51 = icmp eq i32 %50, 12
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = load i32*, i32** %3
%54 = call i32 @putc(i8 signext 92, i32* %53)
%55 = load i32*, i32** %3
%56 = call i32 @putc(i8 signext 102, i32* %55)
br label %76
57: ; preds = %48
%58 = load i8, i8* %6
%59 = zext i8 %58 to i32
%60 = icmp eq i32 %59, 92
br i1 %60, label %65, label %61
61: ; preds = %57
%62 = load i8, i8* %6
%63 = zext i8 %62 to i32
%64 = icmp eq i32 %63, 34
br i1 %64, label %65, label %71
65: ; preds = %61, %57
%66 = load i32*, i32** %3
%67 = call i32 @putc(i8 signext 92, i32* %66)
%68 = load i8, i8* %6
%69 = load i32*, i32** %3
%70 = call i32 @putc(i8 signext %68, i32* %69)
br label %75
71: ; preds = %61
%72 = load i8, i8* %6
%73 = load i32*, i32** %3
%74 = call i32 @putc(i8 signext %72, i32* %73)
br label %75
75: ; preds = %71, %65
br label %76
76: ; preds = %75, %52
br label %77
77: ; preds = %76, %43
br label %78
78: ; preds = %77, %34
br label %79
79: ; preds = %78, %25
br label %14
80: ; preds = %14
%81 = load i32*, i32** %3
%82 = call i32 @putc(i8 signext 34, i32* %81)
ret void
}

LLVM IR (-O2):
define void @write_escaped_string(i32* nocapture %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %1, i64 %4
%6 = tail call i32 @putc(i8 signext 34, i32* %0)
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %23
8: ; preds = %2, %19
%9 = phi i8* [ %10, %19 ], [ %1, %2 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %9
switch i8 %11, label %19 [
i8 9, label %16
i8 10, label %12
i8 13, label %13
i8 12, label %14
i8 92, label %15
i8 34, label %15
]
12: ; preds = %8
br label %16
13: ; preds = %8
br label %16
14: ; preds = %8
br label %16
15: ; preds = %8, %8
br label %16
16: ; preds = %8, %13, %15, %14, %12
%17 = phi i8 [ 114, %13 ], [ %11, %15 ], [ 102, %14 ], [ 110, %12 ], [ 116, %8 ]
%18 = tail call i32 @putc(i8 signext 92, i32* %0)
br label %19
19: ; preds = %16, %8
%20 = phi i8 [ %11, %8 ], [ %17, %16 ]
%21 = tail call i32 @putc(i8 signext %20, i32* %0)
%22 = icmp ult i8* %10, %5
br i1 %22, label %8, label %23
23: ; preds = %19, %2
%24 = tail call i32 @putc(i8 signext 34, i32* %0)
ret void
}