#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*/ putc(char const, int /*<<< orphan*/ *);
void qu_print_c_string(FILE *file, const char *str) {
  const char *c;
  putc('"', file);
  for (c = str; *c; ++c) {
    if (*c < 32) {
      switch (*c) {
      case '\r':
        fprintf(file, "\\r");
        break;
      case '\n':
        fprintf(file, "\\n");
        break;
      case '\t':
        fprintf(file, "\\t");
        break;
      default:
        fprintf(file, "\\x%02x", *c);
        break;
      }
      continue;
    } else if (*c == '\\' || *c == '"') {
      putc('\\', file);
      putc(*c, file);
    } else {
      putc(*c, file);
    }
  }
  putc('"', file);
}


x86 assembly (clang, -O0):
<qu_print_c_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1030 <putc@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1272 <qu_print_c_string+0x152>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jge    1200 <qu_print_c_string+0xe0>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x9,%eax
je     11cb <qu_print_c_string+0xab>
jmp    117b <qu_print_c_string+0x5b>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     11b4 <qu_print_c_string+0x94>
jmp    118c <qu_print_c_string+0x6c>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
jne    11e2 <qu_print_c_string+0xc2>
jmp    119d <qu_print_c_string+0x7d>
mov    -0x8(%rbp),%rdi
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11fb <qu_print_c_string+0xdb>
mov    -0x8(%rbp),%rdi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11fb <qu_print_c_string+0xdb>
mov    -0x8(%rbp),%rdi
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11fb <qu_print_c_string+0xdb>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%edx
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1261 <qu_print_c_string+0x141>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     1220 <qu_print_c_string+0x100>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1245 <qu_print_c_string+0x125>
mov    -0x8(%rbp),%rsi
mov    $0x5c,%edi
call   1030 <putc@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <putc@plt>
jmp    1257 <qu_print_c_string+0x137>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <putc@plt>
jmp    125c <qu_print_c_string+0x13c>
jmp    1261 <qu_print_c_string+0x141>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1146 <qu_print_c_string+0x26>
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1030 <putc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qu_print_c_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x22,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
mov    (%rbx),%al
test   %al,%al
je     1205 <qu_print_c_string+0xd5>
add    $0x1,%rbx
lea    0xea3(%rip),%r15
lea    0xe99(%rip),%r12
lea    0xe8f(%rip),%r13
lea    0xe91(%rip),%rbp
jmp    119a <qu_print_c_string+0x6a>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rdi
mov    %r14,%rcx
call   1050 <fwrite@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1205 <qu_print_c_string+0xd5>
movsbl %al,%edx
cmp    $0x1f,%dl
jg     11c0 <qu_print_c_string+0x90>
cmp    $0x9,%edx
je     11e7 <qu_print_c_string+0xb7>
cmp    $0xa,%edx
je     117a <qu_print_c_string+0x4a>
cmp    $0xd,%edx
jne    11f6 <qu_print_c_string+0xc6>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r13,%rdi
jmp    1187 <qu_print_c_string+0x57>
cmp    $0x5c,%al
je     11c8 <qu_print_c_string+0x98>
cmp    $0x22,%al
jne    11db <qu_print_c_string+0xab>
mov    $0x5c,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
movsbl -0x1(%rbx),%edi
jmp    11dd <qu_print_c_string+0xad>
mov    %edx,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
jmp    118f <qu_print_c_string+0x5f>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rdi
jmp    1187 <qu_print_c_string+0x57>
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    118f <qu_print_c_string+0x5f>
mov    $0x22,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putc@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"\\r\00"
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [3 x i8] c"\\t\00"
@.str.3 = [7 x i8] c"\\x%02x\00"
define void @qu_print_c_string(i32* nocapture %0, i8* nocapture %1) {
%3 = tail call i32 @putc(i8 signext 34, i32* %0)
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %31, label %6
6: ; preds = %2, %27
%7 = phi i8 [ %29, %27 ], [ %4, %2 ]
%8 = phi i8* [ %28, %27 ], [ %1, %2 ]
%9 = sext i8 %7 to i32
%10 = icmp slt i8 %7, 32
br i1 %10, label %11, label %20
11: ; preds = %6
switch i32 %9, label %18 [
i32 13, label %12
i32 10, label %14
i32 9, label %16
]
12: ; preds = %11
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %27
14: ; preds = %11
%15 = 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 %27
16: ; preds = %11
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %27
18: ; preds = %11
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %9)
br label %27
20: ; preds = %6
switch i8 %7, label %25 [
i8 92, label %21
i8 34, label %21
]
21: ; preds = %20, %20
%22 = tail call i32 @putc(i8 signext 92, i32* %0)
%23 = load i8, i8* %8
%24 = tail call i32 @putc(i8 signext %23, i32* %0)
br label %27
25: ; preds = %20
%26 = tail call i32 @putc(i8 signext %7, i32* %0)
br label %27
27: ; preds = %25, %21, %12, %14, %16, %18
%28 = getelementptr inbounds i8, i8* %8, i64 1
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %31, label %6
31: ; preds = %27, %2
%32 = tail call i32 @putc(i8 signext 34, i32* %0)
ret void
}