#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 */
int /*<<< orphan*/ putchar(char);
void printStr(const char *str) {
  size_t i;
  putchar('"');
  for (i = 0; str[i] != '\0'; ++i) {
    char c = str[i];
    if (c == '"' || c == '\\')
      putchar('\\');
    putchar(c);
  }
  putchar('"');
}


x86 assembly (clang, -O0):
<printStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x22,%edi
call   1030 <putchar@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     118f <printStr+0x7f>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x22,%eax
je     116b <printStr+0x5b>
movsbl -0x11(%rbp),%eax
cmp    $0x5c,%eax
jne    1175 <printStr+0x65>
mov    $0x5c,%edi
call   1030 <putchar@plt>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112e <printStr+0x1e>
mov    $0x22,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printStr>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x22,%edi
call   1030 <putchar@plt>
jmp    1146 <printStr+0x36>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x5c,%edi
call   1030 <putchar@plt>
movsbl %bl,%edi
call   1030 <putchar@plt>
add    $0x1,%r14
movzbl (%r14),%ebx
cmp    $0x22,%bl
je     1130 <printStr+0x20>
cmp    $0x5c,%bl
je     1130 <printStr+0x20>
test   %bl,%bl
jne    113a <printStr+0x2a>
mov    $0x22,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>

LLVM IR (-O0):
define void @printStr(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8
store i8* %0, i8** %2
%5 = call i32 @putchar(i8 signext 34)
store i64 0, i64* %3
br label %6
6: ; preds = %30, %1
%7 = load i8*, i8** %2
%8 = load i64, i64* %3
%9 = getelementptr inbounds i8, i8* %7, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %33
13: ; preds = %6
%14 = load i8*, i8** %2
%15 = load i64, i64* %3
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %4
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 34
br i1 %20, label %25, label %21
21: ; preds = %13
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 92
br i1 %24, label %25, label %27
25: ; preds = %21, %13
%26 = call i32 @putchar(i8 signext 92)
br label %27
27: ; preds = %25, %21
%28 = load i8, i8* %4
%29 = call i32 @putchar(i8 signext %28)
br label %30
30: ; preds = %27
%31 = load i64, i64* %3
%32 = add i64 %31, 1
store i64 %32, i64* %3
br label %6
33: ; preds = %6
%34 = call i32 @putchar(i8 signext 34)
ret void
}

LLVM IR (-O2):
define void @printStr(i8* nocapture %0) {
%2 = tail call i32 @putchar(i8 signext 34)
br label %3
3: ; preds = %9, %1
%4 = phi i64 [ 0, %1 ], [ %11, %9 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
switch i8 %6, label %9 [
i8 0, label %12
i8 92, label %7
i8 34, label %7
]
7: ; preds = %3, %3
%8 = tail call i32 @putchar(i8 signext 92)
br label %9
9: ; preds = %3, %7
%10 = tail call i32 @putchar(i8 signext %6)
%11 = add i64 %4, 1
br label %3
12: ; preds = %3
%13 = tail call i32 @putchar(i8 signext 34)
ret void
}