#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*/ printf(char *, ...);
void dump_string(const char *str) {
  printf("\"");
  for (const char *p = str; *p != '\0'; p++) {
    switch (*p) {
    case '\n':
      printf("\\n");
      break;
    case '\r':
      printf("\\r");
      break;
    case '\t':
      printf("\\t");
      break;
    case '\\':
      printf("\\\\");
      break;
    case '"':
      printf("\\\"");
      break;
    default:
      if (*p < 32)
        printf("\\x%02x", (unsigned char)*p);
      else
        printf("%c", *p);
      break;
    }
  }
  printf("\"");
}


x86 assembly (clang, -O0):
<dump_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1257 <dump_string+0x147>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x9,%eax
je     11c4 <dump_string+0xb4>
jmp    115a <dump_string+0x4a>
mov    -0x14(%rbp),%eax
sub    $0xa,%eax
je     119e <dump_string+0x8e>
jmp    116b <dump_string+0x5b>
mov    -0x14(%rbp),%eax
sub    $0xd,%eax
je     11b1 <dump_string+0xa1>
jmp    117c <dump_string+0x6c>
mov    -0x14(%rbp),%eax
sub    $0x22,%eax
je     11ea <dump_string+0xda>
jmp    118d <dump_string+0x7d>
mov    -0x14(%rbp),%eax
sub    $0x5c,%eax
je     11d7 <dump_string+0xc7>
jmp    11fd <dump_string+0xed>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1241 <dump_string+0x131>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1241 <dump_string+0x131>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1241 <dump_string+0x131>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1241 <dump_string+0x131>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1241 <dump_string+0x131>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jge    1227 <dump_string+0x117>
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123c <dump_string+0x12c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1241 <dump_string+0x131>
jmp    1246 <dump_string+0x136>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1132 <dump_string+0x22>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x22,%edi
call   1030 <putchar@plt>
mov    (%rbx),%al
test   %al,%al
je     11d6 <dump_string+0xb6>
add    $0x1,%rbx
lea    0xeb3(%rip),%r14
lea    0xf1a(%rip),%r12
lea    0xf0d(%rip),%r13
lea    0xf09(%rip),%rbp
lea    0xf0b(%rip),%r15
jmp    1180 <dump_string+0x60>
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11d6 <dump_string+0xb6>
movsbl %al,%edi
lea    -0x9(%rdi),%ecx
cmp    $0x19,%ecx
ja     11a0 <dump_string+0x80>
movslq (%r14,%rcx,4),%rcx
add    %r14,%rcx
jmp    *%rcx
mov    %r12,%rdi
jmp    116e <dump_string+0x4e>
nopl   0x0(%rax)
cmp    $0x5c,%edi
jne    11ae <dump_string+0x8e>
lea    0xec5(%rip),%rdi
jmp    116e <dump_string+0x4e>
cmp    $0x1f,%al
jg     11cf <dump_string+0xaf>
movzbl %al,%esi
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1175 <dump_string+0x55>
mov    %rbp,%rdi
jmp    116e <dump_string+0x4e>
mov    %r15,%rdi
jmp    116e <dump_string+0x4e>
call   1030 <putchar@plt>
jmp    1175 <dump_string+0x55>
mov    $0x22,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\22\00"
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [3 x i8] c"\\r\00"
@.str.3 = [3 x i8] c"\\t\00"
@.str.4 = [3 x i8] c"\\\\\00"
@.str.5 = [3 x i8] c"\\\22\00"
@.str.6 = [7 x i8] c"\\x%02x\00"
@.str.7 = [3 x i8] c"%c\00"
define void @dump_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = load i8*, i8** %2
store i8* %5, i8** %3
br label %6
6: ; preds = %42, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %45
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %25 [
i32 10, label %15
i32 13, label %17
i32 9, label %19
i32 92, label %21
i32 34, label %23
]
15: ; preds = %11
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %41
17: ; preds = %11
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %41
19: ; preds = %11
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %41
21: ; preds = %11
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %41
23: ; preds = %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %41
25: ; preds = %11
%26 = load i8*, i8** %3
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp slt i32 %28, 32
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %33)
br label %40
35: ; preds = %25
%36 = load i8*, i8** %3
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %35, %30
br label %41
41: ; preds = %40, %23, %21, %19, %17, %15
br label %42
42: ; preds = %41
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %3
br label %6
45: ; preds = %6
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret void
}

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