void dqEscape(char *buf, int len, int index, struct Parser *p, char *cOut,
              int *eatenOut) {
  if (len < 2)
    error(p, "unterminated string", index);
  *eatenOut = 2;
  switch (buf[1]) {
  case '"':
    *cOut = '"';
    break;
  case 'r':
    *cOut = '\r';
    break;
  case 'n':
    *cOut = '\n';
    break;
  case 't':
    *cOut = '\t';
    break;
  case '\\':
    *cOut = '\\';
    break;
  case '`':
    *cOut = '`';
    break;
  case 'x':
    if (len < 4)
      error(p, "unterminated string", index);
    *cOut = (char)((hexc(buf[2], p, index) << 4) | hexc(buf[3], p, index));
    *eatenOut = 4;
    break;
  default:
    *cOut = '\\';
    *eatenOut = 1;
  }
}


x86 assembly (clang, -O0):
<dqEscape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    115d <dqEscape+0x3d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xeaa(%rip),%rsi
mov    $0x0,%al
call   1030 <error@plt>
mov    -0x28(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x22,%eax
je     11e6 <dqEscape+0xc6>
jmp    1180 <dqEscape+0x60>
mov    -0x2c(%rbp),%eax
sub    $0x5c,%eax
je     1216 <dqEscape+0xf6>
jmp    1191 <dqEscape+0x71>
mov    -0x2c(%rbp),%eax
sub    $0x60,%eax
je     1222 <dqEscape+0x102>
jmp    11a2 <dqEscape+0x82>
mov    -0x2c(%rbp),%eax
sub    $0x6e,%eax
je     11fe <dqEscape+0xde>
jmp    11b3 <dqEscape+0x93>
mov    -0x2c(%rbp),%eax
sub    $0x72,%eax
je     11f2 <dqEscape+0xd2>
jmp    11c4 <dqEscape+0xa4>
mov    -0x2c(%rbp),%eax
sub    $0x74,%eax
je     120a <dqEscape+0xea>
jmp    11d5 <dqEscape+0xb5>
mov    -0x2c(%rbp),%eax
sub    $0x78,%eax
je     122e <dqEscape+0x10e>
jmp    129d <dqEscape+0x17d>
mov    -0x20(%rbp),%rax
movb   $0x22,(%rax)
jmp    12ae <dqEscape+0x18e>
mov    -0x20(%rbp),%rax
movb   $0xd,(%rax)
jmp    12ae <dqEscape+0x18e>
mov    -0x20(%rbp),%rax
movb   $0xa,(%rax)
jmp    12ae <dqEscape+0x18e>
mov    -0x20(%rbp),%rax
movb   $0x9,(%rax)
jmp    12ae <dqEscape+0x18e>
mov    -0x20(%rbp),%rax
movb   $0x5c,(%rax)
jmp    12ae <dqEscape+0x18e>
mov    -0x20(%rbp),%rax
movb   $0x60,(%rax)
jmp    12ae <dqEscape+0x18e>
cmpl   $0x4,-0xc(%rbp)
jge    124d <dqEscape+0x12d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1030 <error@plt>
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    $0x0,%al
call   1040 <hexc@plt>
shl    $0x4,%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x3(%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    $0x0,%al
call   1040 <hexc@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
or     %ecx,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x4,(%rax)
jmp    12ae <dqEscape+0x18e>
mov    -0x20(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dqEscape>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r13
mov    %r8,%r14
mov    %rcx,%r15
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%rbp
cmp    $0x1,%esi
jg     1155 <dqEscape+0x35>
lea    0xf2c(%rip),%rsi
mov    %r15,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1030 <error@plt>
movl   $0x2,0x0(%r13)
movsbl 0x1(%rbp),%ecx
lea    -0x5c(%rcx),%eax
cmp    $0x1c,%eax
ja     117f <dqEscape+0x5f>
lea    0xe90(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x5c,(%r14)
jmp    11fd <dqEscape+0xdd>
cmp    $0x22,%ecx
jne    118a <dqEscape+0x6a>
movb   $0x22,(%r14)
jmp    11fd <dqEscape+0xdd>
movb   $0x5c,(%r14)
movl   $0x1,0x0(%r13)
jmp    11fd <dqEscape+0xdd>
movb   $0xa,(%r14)
jmp    11fd <dqEscape+0xdd>
cmp    $0x3,%ebx
jg     11b7 <dqEscape+0x97>
lea    0xeca(%rip),%rsi
mov    %r15,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1030 <error@plt>
movsbl 0x2(%rbp),%edi
mov    %r15,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <hexc@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
movsbl 0x3(%rbp),%edi
mov    %r15,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <hexc@plt>
or     %ebx,%eax
mov    %al,(%r14)
movl   $0x4,0x0(%r13)
jmp    11fd <dqEscape+0xdd>
movb   $0x60,(%r14)
jmp    11fd <dqEscape+0xdd>
movb   $0xd,(%r14)
jmp    11fd <dqEscape+0xdd>
movb   $0x9,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Parser = type opaque
@.str = [20 x i8] c"unterminated string\00"
define void @dqEscape(i8* %0, i32 %1, i32 %2, %struct.Parser* %3, i8* %4, i32* %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.Parser*
%11 = alloca i8*
%12 = alloca i32*
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store %struct.Parser* %3, %struct.Parser** %10
store i8* %4, i8** %11
store i32* %5, i32** %12
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %6
%16 = load %struct.Parser*, %struct.Parser** %10
%17 = load i32, i32* %9
%18 = call i32 (%struct.Parser*, i8*, i32, ...) bitcast (i32 (...)* @error to i32 (%struct.Parser*, i8*, i32, ...)*)(%struct.Parser* %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %15, %6
%20 = load i32*, i32** %12
store i32 2, i32* %20
%21 = load i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
switch i32 %24, label %64 [
i32 34, label %25
i32 114, label %27
i32 110, label %29
i32 116, label %31
i32 92, label %33
i32 96, label %35
i32 120, label %37
]
25: ; preds = %19
%26 = load i8*, i8** %11
store i8 34, i8* %26
br label %67
27: ; preds = %19
%28 = load i8*, i8** %11
store i8 13, i8* %28
br label %67
29: ; preds = %19
%30 = load i8*, i8** %11
store i8 10, i8* %30
br label %67
31: ; preds = %19
%32 = load i8*, i8** %11
store i8 9, i8* %32
br label %67
33: ; preds = %19
%34 = load i8*, i8** %11
store i8 92, i8* %34
br label %67
35: ; preds = %19
%36 = load i8*, i8** %11
store i8 96, i8* %36
br label %67
37: ; preds = %19
%38 = load i32, i32* %8
%39 = icmp slt i32 %38, 4
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load %struct.Parser*, %struct.Parser** %10
%42 = load i32, i32* %9
%43 = call i32 (%struct.Parser*, i8*, i32, ...) bitcast (i32 (...)* @error to i32 (%struct.Parser*, i8*, i32, ...)*)(%struct.Parser* %41, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %40, %37
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i64 2
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = load %struct.Parser*, %struct.Parser** %10
%50 = load i32, i32* %9
%51 = call i32 (i32, %struct.Parser*, i32, ...) bitcast (i32 (...)* @hexc to i32 (i32, %struct.Parser*, i32, ...)*)(i32 %48, %struct.Parser* %49, i32 %50)
%52 = shl i32 %51, 4
%53 = load i8*, i8** %7
%54 = getelementptr inbounds i8, i8* %53, i64 3
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = load %struct.Parser*, %struct.Parser** %10
%58 = load i32, i32* %9
%59 = call i32 (i32, %struct.Parser*, i32, ...) bitcast (i32 (...)* @hexc to i32 (i32, %struct.Parser*, i32, ...)*)(i32 %56, %struct.Parser* %57, i32 %58)
%60 = or i32 %52, %59
%61 = trunc i32 %60 to i8
%62 = load i8*, i8** %11
store i8 %61, i8* %62
%63 = load i32*, i32** %12
store i32 4, i32* %63
br label %67
64: ; preds = %19
%65 = load i8*, i8** %11
store i8 92, i8* %65
%66 = load i32*, i32** %12
store i32 1, i32* %66
br label %67
67: ; preds = %64, %44, %35, %33, %31, %29, %27, %25
ret void
}

LLVM IR (-O2):
%struct.Parser = type opaque
@.str = [20 x i8] c"unterminated string\00"
define void @dqEscape(i8* nocapture %0, i32 %1, i32 %2, %struct.Parser* %3, i8* nocapture writeonly %4, i32* nocapture writeonly %5) {
%7 = icmp slt i32 %1, 2
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 (%struct.Parser*, i8*, i32, ...) bitcast (i32 (...)* @error to i32 (%struct.Parser*, i8*, i32, ...)*)(%struct.Parser* %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %10
10: ; preds = %8, %6
store i32 2, i32* %5
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %36 [
i32 34, label %14
i32 114, label %15
i32 110, label %16
i32 116, label %17
i32 92, label %18
i32 96, label %19
i32 120, label %20
]
14: ; preds = %10
store i8 34, i8* %4
br label %37
15: ; preds = %10
store i8 13, i8* %4
br label %37
16: ; preds = %10
store i8 10, i8* %4
br label %37
17: ; preds = %10
store i8 9, i8* %4
br label %37
18: ; preds = %10
store i8 92, i8* %4
br label %37
19: ; preds = %10
store i8 96, i8* %4
br label %37
20: ; preds = %10
%21 = icmp slt i32 %1, 4
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 (%struct.Parser*, i8*, i32, ...) bitcast (i32 (...)* @error to i32 (%struct.Parser*, i8*, i32, ...)*)(%struct.Parser* %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %24
24: ; preds = %22, %20
%25 = getelementptr inbounds i8, i8* %0, i64 2
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = tail call i32 (i32, %struct.Parser*, i32, ...) bitcast (i32 (...)* @hexc to i32 (i32, %struct.Parser*, i32, ...)*)(i32 %27, %struct.Parser* %3, i32 %2)
%29 = shl i32 %28, 4
%30 = getelementptr inbounds i8, i8* %0, i64 3
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = tail call i32 (i32, %struct.Parser*, i32, ...) bitcast (i32 (...)* @hexc to i32 (i32, %struct.Parser*, i32, ...)*)(i32 %32, %struct.Parser* %3, i32 %2)
%34 = or i32 %33, %29
%35 = trunc i32 %34 to i8
store i8 %35, i8* %4
store i32 4, i32* %5
br label %37
36: ; preds = %10
store i8 92, i8* %4
store i32 1, i32* %5
br label %37
37: ; preds = %36, %24, %19, %18, %17, %16, %15, %14
ret void
}