#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*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fputc(char const, int /*<<< orphan*/ *);
size_t strlen(char const *);
void PrintCString(FILE *theFile, const char *str) {
  unsigned i;
  size_t slen;
  fprintf(theFile, "\"");
  slen = strlen(str);
  for (i = 0; i < slen; i++) {
    if ((str[i] == '"') || (str[i] == '\\')) {
      fputc('\\', theFile);
      fputc(str[i], theFile);
    } else if (str[i] == '\n') {
      fputc('\\', theFile);
      fputc('n', theFile);
    } else {
      fputc(str[i], theFile);
    }
  }
  fprintf(theFile, "\"");
}


x86 assembly (clang, -O0):
<PrintCString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%rax
jae    1225 <PrintCString+0xf5>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
je     1199 <PrintCString+0x69>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    11c2 <PrintCString+0x92>
mov    -0x8(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    1212 <PrintCString+0xe2>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11f7 <PrintCString+0xc7>
mov    -0x8(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rsi
mov    $0x6e,%edi
call   1040 <fputc@plt>
jmp    120d <PrintCString+0xdd>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    1212 <PrintCString+0xe2>
jmp    1217 <PrintCString+0xe7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <PrintCString+0x34>
mov    -0x8(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrintCString>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x22,%edi
mov    %r12,%rsi
call   1040 <fputc@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     11a1 <PrintCString+0x81>
mov    %rax,%r15
xor    %ebx,%ebx
jmp    1175 <PrintCString+0x55>
nop
mov    $0x5c,%edi
mov    %r12,%rsi
call   1040 <fputc@plt>
movzbl (%r14,%rbx,1),%eax
movsbl %al,%edi
mov    %r12,%rsi
call   1040 <fputc@plt>
add    $0x1,%ebx
cmp    %rbx,%r15
jbe    11a1 <PrintCString+0x81>
movzbl (%r14,%rbx,1),%eax
cmp    $0xa,%al
je     1190 <PrintCString+0x70>
cmp    $0x5c,%al
je     1150 <PrintCString+0x30>
cmp    $0x22,%al
je     1150 <PrintCString+0x30>
jmp    1162 <PrintCString+0x42>
nopl   0x0(%rax,%rax,1)
mov    $0x5c,%edi
mov    %r12,%rsi
call   1040 <fputc@plt>
mov    $0x6e,%al
jmp    1162 <PrintCString+0x42>
mov    $0x22,%edi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <fputc@plt>

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

LLVM IR (-O2):
define void @PrintCString(i32* %0, i8* nocapture %1) {
%3 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 34, i32* %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %2, %15
%7 = phi i64 [ %19, %15 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i8, i8* %8
switch i8 %9, label %15 [
i8 34, label %10
i8 92, label %10
i8 10, label %13
]
10: ; preds = %6, %6
%11 = tail call i32 @fputc(i8 signext 92, i32* %0)
%12 = load i8, i8* %8
br label %15
13: ; preds = %6
%14 = tail call i32 @fputc(i8 signext 92, i32* %0)
br label %15
15: ; preds = %6, %10, %13
%16 = phi i8 [ %12, %10 ], [ 110, %13 ], [ %9, %6 ]
%17 = tail call i32 @fputc(i8 signext %16, i32* %0)
%18 = add nuw nsw i64 %7, 1
%19 = and i64 %18, 4294967295
%20 = icmp ugt i64 %4, %19
br i1 %20, label %6, label %21
21: ; preds = %15, %2
%22 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 34, i32* %0)
ret void
}