void sqEscape(char *buf, int len, int index, struct Parser *p, char *cOut,
              int *eatenOut) {
  if (len < 2)
    error(p, "unterminated string", index);
  if (buf[1] == '\'') {
    *cOut = '\'';
    *eatenOut = 2;
  } else {
    *cOut = '\\';
    *eatenOut = 1;
  }
}


x86 assembly (clang, -O0):
<sqEscape>:
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    114d <sqEscape+0x3d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xeba(%rip),%rsi
mov    $0x0,%al
call   1030 <error@plt>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x27,%eax
jne    1174 <sqEscape+0x64>
mov    -0x20(%rbp),%rax
movb   $0x27,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x2,(%rax)
jmp    1185 <sqEscape+0x75>
mov    -0x20(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqEscape>:
push   %r15
push   %r14
push   %rbx
mov    %r9,%r14
mov    %r8,%r15
mov    %rdi,%rbx
cmp    $0x1,%esi
jg     1134 <sqEscape+0x24>
lea    0xed6(%rip),%rsi
mov    %rcx,%rdi
xor    %eax,%eax
call   1030 <error@plt>
xor    %eax,%eax
cmpb   $0x27,0x1(%rbx)
mov    $0x27,%ecx
mov    $0x5c,%edx
cmove  %ecx,%edx
sete   %al
add    $0x1,%eax
mov    %dl,(%r15)
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.Parser = type opaque
@.str = [20 x i8] c"unterminated string\00"
define void @sqEscape(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 i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 39
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i8*, i8** %11
store i8 39, i8* %26
%27 = load i32*, i32** %12
store i32 2, i32* %27
br label %31
28: ; preds = %19
%29 = load i8*, i8** %11
store i8 92, i8* %29
%30 = load i32*, i32** %12
store i32 1, i32* %30
br label %31
31: ; preds = %28, %25
ret void
}

LLVM IR (-O2):
%struct.Parser = type opaque
@.str = [20 x i8] c"unterminated string\00"
define void @sqEscape(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
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 39
%14 = select i1 %13, i8 39, i8 92
%15 = select i1 %13, i32 2, i32 1
store i8 %14, i8* %4
store i32 %15, i32* %5
ret void
}