#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(unsigned char, int /*<<< orphan*/ *);
void print_qstr(const char *buf, FILE *fp) {
  unsigned char *bp;
  if (!buf) {
    fprintf(fp, "<null>");
    return;
  }
  for (bp = (unsigned char *)buf; *bp; ++bp)
    if (*bp == '(' || *bp == ')' || *bp == '"' || *bp == '\'') {
      putc('\\', fp);
      putc(*bp, fp);
    } else if (*bp == ' ') {
      putc('\\', fp);
      putc(' ', fp);
    } else if (*bp == '\t') {
      putc('\\', fp);
      putc('t', fp);
    } else if (*bp == '\n') {
      putc('\\', fp);
      putc('n', fp);
    } else if (*bp == '\r') {
      putc('\\', fp);
      putc('r', fp);
    } else if (*bp > ' ' && *bp <= '~')
      putc(*bp, fp);
    else
      fprintf(fp, "\\%03o", *bp);
}


x86 assembly (clang, -O0):
<print_qstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1152 <print_qstr+0x32>
mov    -0x10(%rbp),%rdi
lea    0xeba(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    130f <print_qstr+0x1ef>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     130f <print_qstr+0x1ef>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x28,%eax
je     11a7 <print_qstr+0x87>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x29,%eax
je     11a7 <print_qstr+0x87>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x22,%eax
je     11a7 <print_qstr+0x87>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x27,%eax
jne    11cc <print_qstr+0xac>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1030 <putc@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
jmp    12f9 <print_qstr+0x1d9>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jne    11fd <print_qstr+0xdd>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1030 <putc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x20,%edi
call   1030 <putc@plt>
jmp    12f4 <print_qstr+0x1d4>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x9,%eax
jne    122e <print_qstr+0x10e>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1030 <putc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x74,%edi
call   1030 <putc@plt>
jmp    12ef <print_qstr+0x1cf>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xa,%eax
jne    125f <print_qstr+0x13f>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1030 <putc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x6e,%edi
call   1030 <putc@plt>
jmp    12ea <print_qstr+0x1ca>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xd,%eax
jne    1290 <print_qstr+0x170>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1030 <putc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x72,%edi
call   1030 <putc@plt>
jmp    12e5 <print_qstr+0x1c5>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jle    12c7 <print_qstr+0x1a7>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7e,%eax
jg     12c7 <print_qstr+0x1a7>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
jmp    12e0 <print_qstr+0x1c0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movzbl (%rax),%edx
lea    0xd2e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12e5 <print_qstr+0x1c5>
jmp    12ea <print_qstr+0x1ca>
jmp    12ef <print_qstr+0x1cf>
jmp    12f4 <print_qstr+0x1d4>
jmp    12f9 <print_qstr+0x1d9>
jmp    12fe <print_qstr+0x1de>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115a <print_qstr+0x3a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_qstr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     1206 <print_qstr+0xd6>
mov    %rdi,%rbx
lea    0xf61(%rip),%r15
lea    0xeab(%rip),%r12
jmp    117c <print_qstr+0x4c>
mov    $0x5c,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
mov    $0x72,%edi
nopl   0x0(%rax)
mov    %r14,%rsi
call   1030 <putc@plt>
add    $0x1,%rbx
movzbl (%rbx),%edx
cmp    $0x29,%rdx
ja     11a0 <print_qstr+0x70>
movslq (%r12,%rdx,4),%rax
add    %r12,%rax
jmp    *%rax
mov    $0x5c,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
movzbl (%rbx),%edi
jmp    1170 <print_qstr+0x40>
lea    -0x21(%rdx),%eax
cmp    $0x5d,%al
ja     11e7 <print_qstr+0xb7>
mov    %edx,%edi
jmp    1170 <print_qstr+0x40>
mov    $0x5c,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
mov    $0x74,%edi
jmp    1170 <print_qstr+0x40>
mov    $0x5c,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
mov    $0x6e,%edi
jmp    1170 <print_qstr+0x40>
mov    $0x5c,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
mov    $0x20,%edi
jmp    1170 <print_qstr+0x40>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbx
jmp    117c <print_qstr+0x4c>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe9b(%rip),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <fwrite@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"<null>\00"
@.str.1 = [6 x i8] c"\\%03o\00"
define void @print_qstr(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32*, i32** %4
%10 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %114
11: ; preds = %2
%12 = load i8*, i8** %3
store i8* %12, i8** %5
br label %13
13: ; preds = %111, %11
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %114
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = icmp eq i32 %20, 40
br i1 %21, label %37, label %22
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 41
br i1 %26, label %37, label %27
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 34
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = icmp eq i32 %35, 39
br i1 %36, label %37, label %44
37: ; preds = %32, %27, %22, %17
%38 = load i32*, i32** %4
%39 = call i32 @putc(i8 zeroext 92, i32* %38)
%40 = load i8*, i8** %5
%41 = load i8, i8* %40
%42 = load i32*, i32** %4
%43 = call i32 @putc(i8 zeroext %41, i32* %42)
br label %110
44: ; preds = %32
%45 = load i8*, i8** %5
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = icmp eq i32 %47, 32
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i32*, i32** %4
%51 = call i32 @putc(i8 zeroext 92, i32* %50)
%52 = load i32*, i32** %4
%53 = call i32 @putc(i8 zeroext 32, i32* %52)
br label %109
54: ; preds = %44
%55 = load i8*, i8** %5
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = icmp eq i32 %57, 9
br i1 %58, label %59, label %64
59: ; preds = %54
%60 = load i32*, i32** %4
%61 = call i32 @putc(i8 zeroext 92, i32* %60)
%62 = load i32*, i32** %4
%63 = call i32 @putc(i8 zeroext 116, i32* %62)
br label %108
64: ; preds = %54
%65 = load i8*, i8** %5
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = icmp eq i32 %67, 10
br i1 %68, label %69, label %74
69: ; preds = %64
%70 = load i32*, i32** %4
%71 = call i32 @putc(i8 zeroext 92, i32* %70)
%72 = load i32*, i32** %4
%73 = call i32 @putc(i8 zeroext 110, i32* %72)
br label %107
74: ; preds = %64
%75 = load i8*, i8** %5
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
%78 = icmp eq i32 %77, 13
br i1 %78, label %79, label %84
79: ; preds = %74
%80 = load i32*, i32** %4
%81 = call i32 @putc(i8 zeroext 92, i32* %80)
%82 = load i32*, i32** %4
%83 = call i32 @putc(i8 zeroext 114, i32* %82)
br label %106
84: ; preds = %74
%85 = load i8*, i8** %5
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = icmp sgt i32 %87, 32
br i1 %88, label %89, label %99
89: ; preds = %84
%90 = load i8*, i8** %5
%91 = load i8, i8* %90
%92 = zext i8 %91 to i32
%93 = icmp sle i32 %92, 126
br i1 %93, label %94, label %99
94: ; preds = %89
%95 = load i8*, i8** %5
%96 = load i8, i8* %95
%97 = load i32*, i32** %4
%98 = call i32 @putc(i8 zeroext %96, i32* %97)
br label %105
99: ; preds = %89, %84
%100 = load i32*, i32** %4
%101 = load i8*, i8** %5
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = call i32 (i32*, i8*, ...) @fprintf(i32* %100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %103)
br label %105
105: ; preds = %99, %94
br label %106
106: ; preds = %105, %79
br label %107
107: ; preds = %106, %69
br label %108
108: ; preds = %107, %59
br label %109
109: ; preds = %108, %49
br label %110
110: ; preds = %109, %37
br label %111
111: ; preds = %110
%112 = load i8*, i8** %5
%113 = getelementptr inbounds i8, i8* %112, i32 1
store i8* %113, i8** %5
br label %13
114: ; preds = %8, %13
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"<null>\00"
@.str.1 = [6 x i8] c"\\%03o\00"
define void @print_qstr(i8* %0, i32* nocapture %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 6, i64 1, i32* %1)
br label %35
6: ; preds = %2, %33
%7 = phi i8* [ %34, %33 ], [ %0, %2 ]
%8 = load i8, i8* %7
switch i8 %8, label %25 [
i8 0, label %35
i8 40, label %9
i8 41, label %9
i8 34, label %9
i8 39, label %9
i8 32, label %13
i8 9, label %16
i8 10, label %19
i8 13, label %22
]
9: ; preds = %6, %6, %6, %6
%10 = tail call i32 @putc(i8 zeroext 92, i32* %1)
%11 = load i8, i8* %7
%12 = tail call i32 @putc(i8 zeroext %11, i32* %1)
br label %33
13: ; preds = %6
%14 = tail call i32 @putc(i8 zeroext 92, i32* %1)
%15 = tail call i32 @putc(i8 zeroext 32, i32* %1)
br label %33
16: ; preds = %6
%17 = tail call i32 @putc(i8 zeroext 92, i32* %1)
%18 = tail call i32 @putc(i8 zeroext 116, i32* %1)
br label %33
19: ; preds = %6
%20 = tail call i32 @putc(i8 zeroext 92, i32* %1)
%21 = tail call i32 @putc(i8 zeroext 110, i32* %1)
br label %33
22: ; preds = %6
%23 = tail call i32 @putc(i8 zeroext 92, i32* %1)
%24 = tail call i32 @putc(i8 zeroext 114, i32* %1)
br label %33
25: ; preds = %6
%26 = add i8 %8, -33
%27 = icmp ult i8 %26, 94
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 @putc(i8 zeroext %8, i32* %1)
br label %33
30: ; preds = %25
%31 = zext i8 %8 to i32
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %9, %16, %22, %30, %28, %19, %13
%34 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
35: ; preds = %6, %4
ret void
}