#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 */
int /*<<< orphan*/ addnchar(char *, int);
int /*<<< orphan*/ luaL_addchar(char);
char *luaL_check_lstr(int, long *);
void luaI_addquoted(int arg) {
  long l;
  char *s = luaL_check_lstr(arg, &l);
  luaL_addchar('"');
  while (l--) {
    switch (*s) {
    case '"':
    case '\\':
    case '\n':
      luaL_addchar('\\');
      luaL_addchar(*s);
      break;
    case '\0':
      addnchar("\\000", 4);
      break;
    default:
      luaL_addchar(*s);
    }
    s++;
  }
  luaL_addchar('"');
}


x86 assembly (clang, -O0):
<luaI_addquoted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <luaL_check_lstr@plt>
mov    %rax,-0x18(%rbp)
mov    $0x22,%edi
call   1040 <luaL_addchar@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     1206 <luaI_addquoted+0xd6>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     11d3 <luaI_addquoted+0xa3>
jmp    1185 <luaI_addquoted+0x55>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     11b8 <luaI_addquoted+0x88>
jmp    1196 <luaI_addquoted+0x66>
mov    -0x1c(%rbp),%eax
sub    $0x22,%eax
je     11b8 <luaI_addquoted+0x88>
jmp    11a7 <luaI_addquoted+0x77>
mov    -0x1c(%rbp),%eax
sub    $0x5c,%eax
jne    11e9 <luaI_addquoted+0xb9>
jmp    11b8 <luaI_addquoted+0x88>
mov    $0x5c,%edi
call   1040 <luaL_addchar@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <luaL_addchar@plt>
jmp    11f5 <luaI_addquoted+0xc5>
lea    0xe26(%rip),%rdi
mov    $0x4,%esi
call   1030 <addnchar@plt>
jmp    11f5 <luaI_addquoted+0xc5>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <luaL_addchar@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1155 <luaI_addquoted+0x25>
mov    $0x22,%edi
call   1040 <luaL_addchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<luaI_addquoted>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rsi
call   1050 <luaL_check_lstr@plt>
mov    %rax,%rbx
mov    $0x22,%edi
call   1040 <luaL_addchar@plt>
subq   $0x1,(%rsp)
jae    1162 <luaI_addquoted+0x32>
mov    $0x22,%edi
call   1040 <luaL_addchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe97(%rip),%r14
jmp    118d <luaI_addquoted+0x5d>
nopl   0x0(%rax,%rax,1)
mov    $0x5c,%edi
call   1040 <luaL_addchar@plt>
movsbl (%rbx),%edi
call   1040 <luaL_addchar@plt>
add    $0x1,%rbx
subq   $0x1,(%rsp)
jb     1150 <luaI_addquoted+0x20>
movsbl (%rbx),%edi
cmp    $0x21,%edi
jg     11a0 <luaI_addquoted+0x70>
test   %edi,%edi
je     11b0 <luaI_addquoted+0x80>
cmp    $0xa,%edi
je     1170 <luaI_addquoted+0x40>
jmp    117d <luaI_addquoted+0x4d>
cmp    $0x5c,%edi
je     1170 <luaI_addquoted+0x40>
cmp    $0x22,%edi
je     1170 <luaI_addquoted+0x40>
jmp    117d <luaI_addquoted+0x4d>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <addnchar@plt>
jmp    1182 <luaI_addquoted+0x52>

LLVM IR (-O0):
@.str = [5 x i8] c"\\000\00"
define void @luaI_addquoted(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i8* @luaL_check_lstr(i32 %5, i64* %3)
store i8* %6, i8** %4
%7 = call i32 @luaL_addchar(i8 signext 34)
br label %8
8: ; preds = %27, %1
%9 = load i64, i64* %3
%10 = add nsw i64 %9, -1
store i64 %10, i64* %3
%11 = icmp ne i64 %9, 0
br i1 %11, label %12, label %30
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
switch i32 %15, label %23 [
i32 34, label %16
i32 92, label %16
i32 10, label %16
i32 0, label %21
]
16: ; preds = %12, %12, %12
%17 = call i32 @luaL_addchar(i8 signext 92)
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = call i32 @luaL_addchar(i8 signext %19)
br label %27
21: ; preds = %12
%22 = call i32 @addnchar(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
br label %27
23: ; preds = %12
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = call i32 @luaL_addchar(i8 signext %25)
br label %27
27: ; preds = %23, %21, %16
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
br label %8
30: ; preds = %8
%31 = call i32 @luaL_addchar(i8 signext 34)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"\\000\00"
define void @luaI_addquoted(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = call i8* @luaL_check_lstr(i32 %0, i64* %2)
%5 = call i32 @luaL_addchar(i8 signext 34)
%6 = load i64, i64* %2
%7 = add nsw i64 %6, -1
store i64 %7, i64* %2
%8 = icmp eq i64 %6, 0
br i1 %8, label %26, label %9
9: ; preds = %1, %21
%10 = phi i8* [ %22, %21 ], [ %4, %1 ]
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %19 [
i32 34, label %13
i32 92, label %13
i32 10, label %13
i32 0, label %17
]
13: ; preds = %9, %9, %9
%14 = call i32 @luaL_addchar(i8 signext 92)
%15 = load i8, i8* %10
%16 = call i32 @luaL_addchar(i8 signext %15)
br label %21
17: ; preds = %9
%18 = call i32 @addnchar(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
br label %21
19: ; preds = %9
%20 = call i32 @luaL_addchar(i8 signext %11)
br label %21
21: ; preds = %19, %17, %13
%22 = getelementptr inbounds i8, i8* %10, i64 1
%23 = load i64, i64* %2
%24 = add nsw i64 %23, -1
store i64 %24, i64* %2
%25 = icmp eq i64 %23, 0
br i1 %25, label %26, label %9
26: ; preds = %21, %1
%27 = call i32 @luaL_addchar(i8 signext 34)
ret void
}