#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 *);
int /*<<< orphan*/ putchar(char);
unsigned int string_length(char *);
void print_string(char *s) {
  unsigned int len = string_length(s);
  s += 4;
  int i = 0;
  printf("\"");
  for (i = 0; i < len; i++) {
    char c = s[i];
    if (c == '"') {
      printf("\\\"");
    } else if (c == '\\') {
      printf("\\\\");
    } else {
      putchar(c);
    }
  }
  printf("\"");
}


x86 assembly (clang, -O0):
<print_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <string_length@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11e5 <print_string+0xb5>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x22,%eax
jne    11a6 <print_string+0x76>
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
jmp    11d2 <print_string+0xa2>
movsbl -0x11(%rbp),%eax
cmp    $0x5c,%eax
jne    11c4 <print_string+0x94>
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
jmp    11cd <print_string+0x9d>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
jmp    11d2 <print_string+0xa2>
jmp    11d7 <print_string+0xa7>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116e <print_string+0x3e>
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
call   1050 <string_length@plt>
mov    %eax,%ebp
mov    $0x22,%edi
call   1030 <putchar@plt>
test   %ebp,%ebp
je     11aa <print_string+0x7a>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xea8(%rip),%r14
lea    0xe9e(%rip),%r15
jmp    1181 <print_string+0x51>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11aa <print_string+0x7a>
movzbl 0x4(%r12,%rbx,1),%eax
cmp    $0x5c,%al
je     11a0 <print_string+0x70>
cmp    $0x22,%al
jne    1170 <print_string+0x40>
mov    %r15,%rdi
call   1040 <printf@plt>
jmp    1178 <print_string+0x48>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <printf@plt>
jmp    1178 <print_string+0x48>
mov    $0x22,%edi
pop    %rbx
pop    %r12
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"\\\22\00"
@.str.2 = [3 x i8] c"\\\\\00"
define void @print_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @string_length(i8* %6)
store i32 %7, i32* %3
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 4
store i8* %9, i8** %2
store i32 0, i32* %4
%10 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %11
11: ; preds = %37, %1
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %40
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %5
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 34
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %36
26: ; preds = %15
%27 = load i8, i8* %5
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 92
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %35
32: ; preds = %26
%33 = load i8, i8* %5
%34 = call i32 @putchar(i8 signext %33)
br label %35
35: ; preds = %32, %30
br label %36
36: ; preds = %35, %24
br label %37
37: ; preds = %36
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %11
40: ; preds = %11
%41 = call i32 @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"\\\22\00"
@.str.2 = [3 x i8] c"\\\\\00"
define void @print_string(i8* %0) {
%2 = tail call i32 @string_length(i8* %0)
%3 = getelementptr inbounds i8, i8* %0, i64 4
%4 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 34)
%5 = icmp eq i32 %2, 0
br i1 %5, label %21, label %6
6: ; preds = %1
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %18
%9 = phi i64 [ 0, %6 ], [ %19, %18 ]
%10 = getelementptr inbounds i8, i8* %3, i64 %9
%11 = load i8, i8* %10
switch i8 %11, label %16 [
i8 34, label %12
i8 92, label %14
]
12: ; preds = %8
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %18
14: ; preds = %8
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %18
16: ; preds = %8
%17 = tail call i32 @putchar(i8 signext %11)
br label %18
18: ; preds = %14, %16, %12
%19 = add nuw nsw i64 %9, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %21, label %8
21: ; preds = %18, %1
%22 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 34)
ret void
}