#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*/ fwrite(char const *, int, int, int /*<<< orphan*/ *);
size_t strlen(char const *);
void hs_output_lua_string(FILE *fh, const char *s) {
  size_t len = strlen(s);
  for (unsigned i = 0; i < len; ++i) {
    switch (s[i]) {
    case '\n':
      fwrite("\\n", 2, 1, fh);
      break;
    case '\r':
      fwrite("\\r", 2, 1, fh);
      break;
    case '"':
      fwrite("\\\"", 2, 1, fh);
      break;
    case '\\':
      fwrite("\\\\", 2, 1, fh);
      break;
    default:
      fwrite(s + i, 1, 1, fh);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<hs_output_lua_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    1249 <hs_output_lua_string+0x129>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
sub    $0xa,%eax
je     11a0 <hs_output_lua_string+0x80>
jmp    116d <hs_output_lua_string+0x4d>
mov    -0x20(%rbp),%eax
sub    $0xd,%eax
je     11bf <hs_output_lua_string+0x9f>
jmp    117e <hs_output_lua_string+0x5e>
mov    -0x20(%rbp),%eax
sub    $0x22,%eax
je     11de <hs_output_lua_string+0xbe>
jmp    118f <hs_output_lua_string+0x6f>
mov    -0x20(%rbp),%eax
sub    $0x5c,%eax
je     11fd <hs_output_lua_string+0xdd>
jmp    121c <hs_output_lua_string+0xfc>
mov    -0x8(%rbp),%rcx
lea    0xe55(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
jmp    1236 <hs_output_lua_string+0x116>
mov    -0x8(%rbp),%rcx
lea    0xe39(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
jmp    1236 <hs_output_lua_string+0x116>
mov    -0x8(%rbp),%rcx
lea    0xe1d(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
jmp    1236 <hs_output_lua_string+0x116>
mov    -0x8(%rbp),%rcx
lea    0xe01(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
jmp    1236 <hs_output_lua_string+0x116>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fwrite@plt>
jmp    123b <hs_output_lua_string+0x11b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1144 <hs_output_lua_string+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hs_output_lua_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     11da <hs_output_lua_string+0xaa>
mov    %rax,%rbx
xor    %r13d,%r13d
lea    0xea7(%rip),%rbp
lea    0xea3(%rip),%r12
jmp    1192 <hs_output_lua_string+0x62>
nopl   0x0(%rax,%rax,1)
lea    0xe89(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
add    $0x1,%r13d
cmp    %r13,%rbx
jbe    11da <hs_output_lua_string+0xaa>
movsbl (%r15,%r13,1),%edi
cmp    $0x21,%edi
jg     11b0 <hs_output_lua_string+0x80>
cmp    $0xa,%edi
je     1170 <hs_output_lua_string+0x40>
cmp    $0xd,%edi
jne    11d0 <hs_output_lua_string+0xa0>
lea    0xe56(%rip),%rdi
jmp    1177 <hs_output_lua_string+0x47>
nop
cmp    $0x22,%edi
je     11c0 <hs_output_lua_string+0x90>
cmp    $0x5c,%edi
jne    11d0 <hs_output_lua_string+0xa0>
mov    %r12,%rdi
jmp    1177 <hs_output_lua_string+0x47>
nop
mov    %rbp,%rdi
jmp    1177 <hs_output_lua_string+0x47>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rsi
call   1040 <fputc@plt>
jmp    1189 <hs_output_lua_string+0x59>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\n\00"
@.str.1 = [3 x i8] c"\\r\00"
@.str.2 = [3 x i8] c"\\\22\00"
@.str.3 = [3 x i8] c"\\\\\00"
define void @hs_output_lua_string(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %5
store i32 0, i32* %6
br label %9
9: ; preds = %41, %2
%10 = load i32, i32* %6
%11 = zext i32 %10 to i64
%12 = load i64, i64* %5
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %44
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = load i32, i32* %6
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
switch i32 %20, label %33 [
i32 10, label %21
i32 13, label %24
i32 34, label %27
i32 92, label %30
]
21: ; preds = %14
%22 = load i32*, i32** %3
%23 = call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2, i32 1, i32* %22)
br label %40
24: ; preds = %14
%25 = load i32*, i32** %3
%26 = call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 1, i32* %25)
br label %40
27: ; preds = %14
%28 = load i32*, i32** %3
%29 = call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 1, i32* %28)
br label %40
30: ; preds = %14
%31 = load i32*, i32** %3
%32 = call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2, i32 1, i32* %31)
br label %40
33: ; preds = %14
%34 = load i8*, i8** %4
%35 = load i32, i32* %6
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i32*, i32** %3
%39 = call i32 @fwrite(i8* %37, i32 1, i32 1, i32* %38)
br label %40
40: ; preds = %33, %30, %27, %24, %21
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add i32 %42, 1
store i32 %43, i32* %6
br label %9
44: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\n\00"
@.str.1 = [3 x i8] c"\\r\00"
@.str.2 = [3 x i8] c"\\\22\00"
@.str.3 = [3 x i8] c"\\\\\00"
define void @hs_output_lua_string(i32* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %21, %2
ret void
6: ; preds = %2, %21
%7 = phi i64 [ %23, %21 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
switch i32 %10, label %19 [
i32 10, label %11
i32 13, label %13
i32 34, label %15
i32 92, label %17
]
11: ; preds = %6
%12 = tail call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2, i32 1, i32* %0)
br label %21
13: ; preds = %6
%14 = tail call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 1, i32* %0)
br label %21
15: ; preds = %6
%16 = tail call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 1, i32* %0)
br label %21
17: ; preds = %6
%18 = tail call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2, i32 1, i32* %0)
br label %21
19: ; preds = %6
%20 = tail call i32 @fputc(i32 %10, i32* %0)
br label %21
21: ; preds = %11, %13, %15, %17, %19
%22 = add nuw nsw i64 %7, 1
%23 = and i64 %22, 4294967295
%24 = icmp ugt i64 %3, %23
br i1 %24, label %6, label %5
}