#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 */
char *escape(char *, char *, char const *);
char *quote(char *dest, char *end, const char *value) {
  if (dest >= end)
    return NULL;
  *dest++ = '"';
  dest = escape(dest, end, value);
  if (dest == NULL || dest >= end)
    return NULL;
  *dest++ = '"';
  return dest;
}


x86 assembly (clang, -O0):
<quote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     113f <quote+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <quote+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x22,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <escape@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117f <quote+0x6f>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     118c <quote+0x7c>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <quote+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x22,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quote>:
push   %rbx
cmp    %rsi,%rdi
jae    1140 <quote+0x30>
mov    %rsi,%rbx
movb   $0x22,(%rdi)
add    $0x1,%rdi
call   1030 <escape@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     113e <quote+0x2e>
cmp    %rbx,%rcx
jae    113e <quote+0x2e>
mov    %rcx,%rax
add    $0x1,%rax
movb   $0x22,(%rcx)
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @quote(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i8*, i8** %5
%9 = load i8*, i8** %6
%10 = icmp uge i8* %8, %9
br i1 %10, label %11, label %12
11: ; preds = %3
store i8* null, i8** %4
br label %30
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %5
store i8 34, i8* %13
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = load i8*, i8** %7
%18 = call i8* @escape(i8* %15, i8* %16, i8* %17)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp eq i8* %19, null
br i1 %20, label %25, label %21
21: ; preds = %12
%22 = load i8*, i8** %5
%23 = load i8*, i8** %6
%24 = icmp uge i8* %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21, %12
store i8* null, i8** %4
br label %30
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
store i8 34, i8* %27
%29 = load i8*, i8** %5
store i8* %29, i8** %4
br label %30
30: ; preds = %26, %25, %11
%31 = load i8*, i8** %4
ret i8* %31
}

LLVM IR (-O2):
define i8* @quote(i8* %0, i8* %1, i8* %2) {
%4 = icmp ult i8* %0, %1
br i1 %4, label %5, label %13
5: ; preds = %3
%6 = getelementptr inbounds i8, i8* %0, i64 1
store i8 34, i8* %0
%7 = tail call i8* @escape(i8* %6, i8* %1, i8* %2)
%8 = icmp ne i8* %7, null
%9 = icmp ult i8* %7, %1
%10 = and i1 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %7, i64 1
store i8 34, i8* %7
br label %13
13: ; preds = %5, %3, %11
%14 = phi i8* [ %12, %11 ], [ null, %3 ], [ null, %5 ]
ret i8* %14
}