#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, int /*<<< orphan*/ *);
void quote(FILE *fp, char *s) {
  fprintf(fp, "\"");
  for (; *s != '\0'; s++) {
    if (*s == '\\' || *s == '\"') {
      fputc('\\', fp);
      fputc(*s, fp);
    } else if (*s < ' ') {
      fprintf(fp, "\\u%04x", *s);
    } else {
      fputc(*s, fp);
    }
  }
  fprintf(fp, "\"");
}


x86 assembly (clang, -O0):
<quote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f2 <quote+0xd2>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     1172 <quote+0x52>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1197 <quote+0x77>
mov    -0x8(%rbp),%rsi
mov    $0x5c,%edi
call   1030 <fputc@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
jmp    11dc <quote+0xbc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jge    11c5 <quote+0xa5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11d7 <quote+0xb7>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
jmp    11dc <quote+0xbc>
jmp    11e1 <quote+0xc1>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1142 <quote+0x22>
mov    -0x8(%rbp),%rdi
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quote>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x22,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
lea    0xec1(%rip),%r15
jmp    116c <quote+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x5c,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
movsbl (%rbx),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbx
movsbl (%rbx),%edx
cmp    $0x22,%edx
je     1150 <quote+0x30>
cmp    $0x5c,%dl
je     1150 <quote+0x30>
test   %dl,%dl
je     1199 <quote+0x79>
cmp    $0x1f,%dl
jg     1195 <quote+0x75>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbx
jmp    116c <quote+0x4c>
mov    %edx,%edi
jmp    1160 <quote+0x40>
mov    $0x22,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fputc@plt>

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

LLVM IR (-O2):
@.str.1 = [7 x i8] c"\\u%04x\00"
define void @quote(i32* %0, i8* nocapture %1) {
%3 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 34, i32* %0)
br label %4
4: ; preds = %18, %2
%5 = phi i8* [ %1, %2 ], [ %19, %18 ]
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i8 %6, label %12 [
i8 0, label %20
i8 92, label %8
i8 34, label %8
]
8: ; preds = %4, %4
%9 = tail call i32 @fputc(i8 signext 92, i32* %0)
%10 = load i8, i8* %5
%11 = tail call i32 @fputc(i8 signext %10, i32* %0)
br label %18
12: ; preds = %4
%13 = icmp slt i8 %6, 32
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %18
16: ; preds = %12
%17 = tail call i32 @fputc(i8 signext %6, i32* %0)
br label %18
18: ; preds = %8, %16, %14
%19 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
20: ; preds = %4
%21 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 34, i32* %0)
ret void
}