#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*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int strcspn(char const *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void luaO_chunkid(char *out, const char *source, int bufflen) {
  if (*source == '=') {
    strncpy(out, source + 1, bufflen);
    out[bufflen - 1] = '\0';
  } else {
    if (*source == '@') {
      int l;
      source++;
      bufflen -= sizeof(" `...' ");
      l = strlen(source);
      strcpy(out, "");
      if (l > bufflen) {
        source += (l - bufflen);
        strcat(out, "...");
      }
      strcat(out, source);
    } else {
      int len = strcspn(source, "\n");
      bufflen -= sizeof(" [string \"...\"] ");
      if (len > bufflen)
        len = bufflen;
      strcpy(out, "[string \"");
      if (source[len] != '\0') {
        strncat(out, source, len);
        strcat(out, "...");
      } else
        strcat(out, source);
      strcat(out, "\"]");
    }
  }
}


x86 assembly (clang, -O0):
<luaO_chunkid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
jne    11ad <luaO_chunkid+0x4d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12ce <luaO_chunkid+0x16e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    1232 <luaO_chunkid+0xd2>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movslq -0x14(%rbp),%rax
sub    $0x8,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1220 <luaO_chunkid+0xc0>
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
jmp    12c9 <luaO_chunkid+0x169>
mov    -0x10(%rbp),%rdi
lea    0xdc7(%rip),%rsi
call   1070 <strcspn@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x14(%rbp),%rax
sub    $0x11,%rax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1262 <luaO_chunkid+0x102>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     12ac <luaO_chunkid+0x14c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <strncat@plt>
mov    -0x8(%rbp),%rdi
lea    0xd5e(%rip),%rsi
call   1080 <strcat@plt>
jmp    12b9 <luaO_chunkid+0x159>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xd4c(%rip),%rsi
call   1080 <strcat@plt>
jmp    12ce <luaO_chunkid+0x16e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<luaO_chunkid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%al
cmp    $0x40,%al
je     119e <luaO_chunkid+0x3e>
cmp    $0x3d,%al
jne    11e1 <luaO_chunkid+0x81>
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,-0x1(%rax,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%rbx
add    $0xfffffff8,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
lea    0xe4e(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
sub    %ebp,%r15d
jle    11d9 <luaO_chunkid+0x79>
movslq %r15d,%rax
add    %rax,%rbx
lea    0xe2f(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
jmp    123e <luaO_chunkid+0xde>
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcspn@plt>
add    $0xffffffef,%ebp
cmp    %ebp,%eax
cmovle %eax,%ebp
lea    0xe07(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
movslq %ebp,%rax
cmpb   $0x0,(%rbx,%rax,1)
je     1229 <luaO_chunkid+0xc9>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <strncat@plt>
lea    0xddc(%rip),%rsi
mov    %r14,%rdi
jmp    122f <luaO_chunkid+0xcf>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
lea    0xdd5(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <strcat@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"...\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [10 x i8] c"[string \22\00"
@.str.4 = [3 x i8] c"\22]\00"
define void @luaO_chunkid(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 61
br i1 %12, label %13, label %24
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i32, i32* %6
%18 = call i32 @strncpy(i8* %14, i8* %16, i32 %17)
%19 = load i8*, i8** %4
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 0, i8* %23
br label %93
24: ; preds = %3
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 64
br i1 %28, label %29, label %56
29: ; preds = %24
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = sub i64 %33, 8
%35 = trunc i64 %34 to i32
store i32 %35, i32* %6
%36 = load i8*, i8** %5
%37 = call i32 @strlen(i8* %36)
store i32 %37, i32* %7
%38 = load i8*, i8** %4
%39 = call i32 @strcpy(i8* %38, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%40 = load i32, i32* %7
%41 = load i32, i32* %6
%42 = icmp sgt i32 %40, %41
br i1 %42, label %43, label %52
43: ; preds = %29
%44 = load i32, i32* %7
%45 = load i32, i32* %6
%46 = sub nsw i32 %44, %45
%47 = load i8*, i8** %5
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8* %49, i8** %5
%50 = load i8*, i8** %4
%51 = call i32 @strcat(i8* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %52
52: ; preds = %43, %29
%53 = load i8*, i8** %4
%54 = load i8*, i8** %5
%55 = call i32 @strcat(i8* %53, i8* %54)
br label %92
56: ; preds = %24
%57 = load i8*, i8** %5
%58 = call i32 @strcspn(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 %58, i32* %8
%59 = load i32, i32* %6
%60 = sext i32 %59 to i64
%61 = sub i64 %60, 17
%62 = trunc i64 %61 to i32
store i32 %62, i32* %6
%63 = load i32, i32* %8
%64 = load i32, i32* %6
%65 = icmp sgt i32 %63, %64
br i1 %65, label %66, label %68
66: ; preds = %56
%67 = load i32, i32* %6
store i32 %67, i32* %8
br label %68
68: ; preds = %66, %56
%69 = load i8*, i8** %4
%70 = call i32 @strcpy(i8* %69, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%71 = load i8*, i8** %5
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %85
78: ; preds = %68
%79 = load i8*, i8** %4
%80 = load i8*, i8** %5
%81 = load i32, i32* %8
%82 = call i32 @strncat(i8* %79, i8* %80, i32 %81)
%83 = load i8*, i8** %4
%84 = call i32 @strcat(i8* %83, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %89
85: ; preds = %68
%86 = load i8*, i8** %4
%87 = load i8*, i8** %5
%88 = call i32 @strcat(i8* %86, i8* %87)
br label %89
89: ; preds = %85, %78
%90 = load i8*, i8** %4
%91 = call i32 @strcat(i8* %90, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %92
92: ; preds = %89, %52
br label %93
93: ; preds = %92, %13
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"...\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [10 x i8] c"[string \22\00"
@.str.4 = [3 x i8] c"\22]\00"
define void @luaO_chunkid(i8* %0, i8* %1, i32 %2) {
%4 = load i8, i8* %1
switch i8 %4, label %25 [
i8 61, label %5
i8 64, label %11
]
5: ; preds = %3
%6 = getelementptr inbounds i8, i8* %1, i64 1
%7 = tail call i32 @strncpy(i8* %0, i8* %6, i32 %2)
%8 = add nsw i32 %2, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 0, i8* %10
br label %42
11: ; preds = %3
%12 = getelementptr inbounds i8, i8* %1, i64 1
%13 = add i32 %2, -8
%14 = tail call i32 @strlen(i8* %12)
%15 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%16 = icmp sgt i32 %14, %13
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = sub nsw i32 %14, %13
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %12, i64 %19
%21 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %17, %11
%23 = phi i8* [ %20, %17 ], [ %12, %11 ]
%24 = tail call i32 @strcat(i8* %0, i8* %23)
br label %42
25: ; preds = %3
%26 = tail call i32 @strcspn(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = add i32 %2, -17
%28 = icmp sgt i32 %26, %27
%29 = select i1 %28, i32 %27, i32 %26
%30 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %1, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %25
%36 = tail call i32 @strncat(i8* %0, i8* %1, i32 %29)
%37 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %40
38: ; preds = %25
%39 = tail call i32 @strcat(i8* %0, i8* %1)
br label %40
40: ; preds = %38, %35
%41 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %22, %40, %5
ret void
}