#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 *);
size_t strcspn(char const *, char *);
size_t strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, size_t);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
void luaO_chunkid(char *out, const char *source, size_t bufflen) {
  if (*source == '=') {
    strncpy(out, source + 1, bufflen);
    out[bufflen - 1] = '\0';
  } else {
    if (*source == '@') {
      size_t l;
      source++;
      bufflen -= sizeof(" '...' ");
      l = strlen(source);
      strcpy(out, "");
      if (l > bufflen) {
        source += (l - bufflen);
        strcat(out, "...");
      }
      strcat(out, source);
    } else {
      size_t len = strcspn(source, "\n\r");
      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    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
jne    11ae <luaO_chunkid+0x4e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12d6 <luaO_chunkid+0x176>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    1233 <luaO_chunkid+0xd3>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1221 <luaO_chunkid+0xc1>
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
jmp    12d1 <luaO_chunkid+0x171>
mov    -0x10(%rbp),%rdi
lea    0xdc6(%rip),%rsi
call   1070 <strcspn@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x11,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1269 <luaO_chunkid+0x109>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd93(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     12b4 <luaO_chunkid+0x154>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <strncat@plt>
mov    -0x8(%rbp),%rdi
lea    0xd56(%rip),%rsi
call   1080 <strcat@plt>
jmp    12c1 <luaO_chunkid+0x161>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xd45(%rip),%rsi
call   1080 <strcat@plt>
jmp    12d6 <luaO_chunkid+0x176>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<luaO_chunkid>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rsi),%al
cmp    $0x40,%al
je     119f <luaO_chunkid+0x3f>
cmp    $0x3d,%al
jne    11e0 <luaO_chunkid+0x80>
add    $0x1,%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%rbx,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
add    $0x1,%r15
add    $0xfffffffffffffff8,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
lea    0xe4d(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
sub    %rbx,%r12
jbe    11d8 <luaO_chunkid+0x78>
add    %r12,%r15
lea    0xe30(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
mov    %r14,%rdi
mov    %r15,%rsi
jmp    123f <luaO_chunkid+0xdf>
lea    0xe1d(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcspn@plt>
add    $0xffffffffffffffef,%rbx
cmp    %rbx,%rax
cmovbe %rax,%rbx
lea    0xe06(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
cmpb   $0x0,(%r15,%rbx,1)
je     122a <luaO_chunkid+0xca>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <strncat@plt>
lea    0xddb(%rip),%rsi
mov    %r14,%rdi
jmp    1230 <luaO_chunkid+0xd0>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
lea    0xdd5(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <strcat@plt>

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

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