// File: /workspace/github_c_makefile_star2_O3/tylerneylon[P]APIsWithLua/lua/lstrlib.c
// Function: str_pack
static int str_pack (lua_State *L) {
  luaL_Buffer b;
  Header h;
  const char *fmt = luaL_checkstring(L, 1);  /* format string */
  int arg = 1;  /* current argument to pack */
  size_t totalsize = 0;  /* accumulate total size of result */
  initheader(L, &h);
  lua_pushnil(L);  /* mark to separate arguments from string buffer */
  luaL_buffinit(L, &b);
  while (*fmt != '\0') {
    int size, ntoalign;
    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);
    totalsize += ntoalign + size;
    while (ntoalign-- > 0)
     luaL_addchar(&b, LUAL_PACKPADBYTE);  /* fill alignment */
    arg++;
    switch (opt) {
      case Kint: {  /* signed integers */
        lua_Integer n = luaL_checkinteger(L, arg);
        if (size < SZINT) {  /* need overflow check? */
          lua_Integer lim = (lua_Integer)1 << ((size * NB) - 1);
          luaL_argcheck(L, -lim <= n && n < lim, arg, "integer overflow");
        }
        packint(&b, (lua_Unsigned)n, h.islittle, size, (n < 0));
        break;
      }
      case Kuint: {  /* unsigned integers */
        lua_Integer n = luaL_checkinteger(L, arg);
        if (size < SZINT)  /* need overflow check? */
          luaL_argcheck(L, (lua_Unsigned)n < ((lua_Unsigned)1 << (size * NB)),
                           arg, "unsigned overflow");
        packint(&b, (lua_Unsigned)n, h.islittle, size, 0);
        break;
      }
      case Kfloat: {  /* floating-point options */
        volatile Ftypes u;
        char *buff = luaL_prepbuffsize(&b, size);
        lua_Number n = luaL_checknumber(L, arg);  /* get argument */
        if (size == sizeof(u.f)) u.f = (float)n;  /* copy it into 'u' */
        else if (size == sizeof(u.d)) u.d = (double)n;
        else u.n = n;
        /* move 'u' to final result, correcting endianness if needed */
        copywithendian(buff, u.buff, size, h.islittle);
        luaL_addsize(&b, size);
        break;
      }
      case Kchar: {  /* fixed-size string */
        size_t len;
        const char *s = luaL_checklstring(L, arg, &len);
        luaL_argcheck(L, len <= (size_t)size, arg,
                         "string longer than given size");
        luaL_addlstring(&b, s, len);  /* add string */
        while (len++ < (size_t)size)  /* pad extra space */
          luaL_addchar(&b, LUAL_PACKPADBYTE);
        break;
      }
      case Kstring: {  /* strings with length count */
        size_t len;
        const char *s = luaL_checklstring(L, arg, &len);
        luaL_argcheck(L, size >= (int)sizeof(size_t) ||
                         len < ((size_t)1 << (size * NB)),
                         arg, "string length does not fit in given size");
        packint(&b, (lua_Unsigned)len, h.islittle, size, 0);  /* pack length */
        luaL_addlstring(&b, s, len);
        totalsize += len;
        break;
      }
      case Kzstr: {  /* zero-terminated string */
        size_t len;
        const char *s = luaL_checklstring(L, arg, &len);
        luaL_argcheck(L, strlen(s) == len, arg, "string contains zeros");
        luaL_addlstring(&b, s, len);
        luaL_addchar(&b, '\0');  /* add zero at the end */
        totalsize += len + 1;
        break;
      }
      case Kpadding: luaL_addchar(&b, LUAL_PACKPADBYTE);  /* FALLTHROUGH */
      case Kpaddalign: case Knop:
        arg--;  /* undo increment */
        break;
    }
  }
  luaL_pushresult(&b);
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2078, %rsp           # imm = 0x2078
movq %rdi, %r15
movl $0x1, %r14d
movl $0x1, %esi
xorl %edx, %edx
callq 0x14fff
movq %rax, %rbx
movq %rax, 0x50(%rsp)
movq %r15, 0x40(%rsp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x48(%rsp)
movq %r15, %rdi
callq 0x64cd
leaq 0x58(%rsp), %rsi
movq %r15, (%rsp)
movq %r15, %rdi
callq 0x154c8
cmpb $0x0, (%rbx)
je 0x1e112
movq $0x0, 0x8(%rsp)
leaq 0x58(%rsp), %r15
leaq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0x3c(%rsp), %rcx
leaq 0x38(%rsp), %r8
callq 0x1f063
movl %eax, %ebx
movl 0x38(%rsp), %r12d
movl 0x3c(%rsp), %ebp
testl %r12d, %r12d
jle 0x1ddd3
leal 0x1(%r12), %r13d
movq 0x68(%rsp), %rax
cmpq 0x60(%rsp), %rax
jb 0x1ddb8
movl $0x1, %esi
movq %r15, %rdi
callq 0x151bd
movq 0x68(%rsp), %rax
movq 0x58(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x68(%rsp)
movb $0x0, (%rcx,%rax)
decl %r13d
cmpl $0x1, %r13d
jg 0x1dd9a
movslq %ebp, %r13
addl %r13d, %r12d
movslq %r12d, %rax
addq %rax, 0x8(%rsp)
leal 0x1(%r14), %r12d
movl %ebx, %eax
leaq 0x657a(%rip), %rcx      # 0x24368
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rdi
movl %r12d, %esi
callq 0x15124
movq %rax, %rbx
cmpl $0x7, %ebp
jg 0x1de45
leal (,%rbp,8), %ecx
decb %cl
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
negq %rcx
cmpq %rcx, %rbx
setge %cl
cmpq %rax, %rbx
setl %al
testb %al, %cl
jne 0x1de45
movq (%rsp), %rdi
movl %r12d, %esi
leaq 0x698d(%rip), %rdx      # 0x247cd
callq 0x1497c
movl 0x48(%rsp), %edx
movq %rbx, %r8
shrq $0x3f, %r8
movq %r15, %rdi
movq %rbx, %rsi
movl %r13d, %ecx
jmp 0x1dfe9
movq (%rsp), %rdi
movl %r12d, %esi
leaq 0x10(%rsp), %rdx
callq 0x14fff
movq %rax, %rbx
movq 0x10(%rsp), %rsi
cmpl $0x7, %r13d
jg 0x1dea7
leal (,%rbp,8), %ecx
movq %rsi, %rax
shrq %cl, %rax
testq %rax, %rax
je 0x1dea7
movq (%rsp), %rdi
movl %r12d, %esi
leaq 0x6971(%rip), %rdx      # 0x2480e
callq 0x1497c
movq 0x10(%rsp), %rsi
movl 0x48(%rsp), %edx
movq %r15, %rdi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x1f139
movq 0x10(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1534f
movq 0x8(%rsp), %rax
addq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0x1e101
movq %r15, %rdi
movq %r13, %rsi
callq 0x151bd
movq %rax, %rbx
movq (%rsp), %rdi
movl %r12d, %esi
callq 0x150a0
cmpq $0x8, %rbp
je 0x1e0b8
cmpl $0x4, %ebp
jne 0x1e0b8
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
jmp 0x1e0be
movq (%rsp), %rdi
movl %r12d, %esi
leaq 0x10(%rsp), %rdx
callq 0x14fff
movq %rax, %rbx
movq 0x10(%rsp), %rdx
cmpq %r13, %rdx
jbe 0x1df4e
movq (%rsp), %rdi
movl %r12d, %esi
leaq 0x68ac(%rip), %rdx      # 0x247f0
callq 0x1497c
movq 0x10(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1534f
movq 0x10(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%rsp)
cmpq %r13, %rax
jae 0x1e101
movq 0x68(%rsp), %rax
cmpq 0x60(%rsp), %rax
jb 0x1df8e
movl $0x1, %esi
movq %r15, %rdi
callq 0x151bd
movq 0x68(%rsp), %rax
movq 0x58(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x68(%rsp)
movb $0x0, (%rcx,%rax)
jmp 0x1df59
movq (%rsp), %rdi
movl %r12d, %esi
callq 0x15124
movq %rax, %rbx
cmpl $0x7, %ebp
jg 0x1dfd9
shll $0x3, %ebp
movq %rbx, %rax
movl %ebp, %ecx
shrq %cl, %rax
testq %rax, %rax
je 0x1dfd9
movq (%rsp), %rdi
movl %r12d, %esi
leaq 0x680a(%rip), %rdx      # 0x247de
callq 0x1497c
movl 0x48(%rsp), %edx
movq %r15, %rdi
movq %rbx, %rsi
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x1f139
jmp 0x1e101
movq (%rsp), %rdi
movl %r12d, %esi
leaq 0x10(%rsp), %rdx
callq 0x14fff
movq %rax, %rbx
movq %rax, %rdi
callq 0x5140
cmpq 0x10(%rsp), %rax
je 0x1e02e
movq (%rsp), %rdi
movl %r12d, %esi
leaq 0x666b(%rip), %rdx      # 0x2468f
callq 0x1497c
movq 0x10(%rsp), %rax
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1534f
movq 0x68(%rsp), %rax
cmpq 0x60(%rsp), %rax
jb 0x1e05a
movl $0x1, %esi
movq %r15, %rdi
callq 0x151bd
movq 0x68(%rsp), %rax
movq 0x58(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x68(%rsp)
movb $0x0, (%rcx,%rax)
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
addq %rax, %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
jmp 0x1e101
movq 0x68(%rsp), %rax
cmpq 0x60(%rsp), %rax
jb 0x1e0a1
movl $0x1, %esi
movq %r15, %rdi
callq 0x151bd
movq 0x68(%rsp), %rax
movq 0x58(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x68(%rsp)
movb $0x0, (%rcx,%rax)
movl %r14d, %r12d
jmp 0x1e101
movsd %xmm0, 0x10(%rsp)
cmpl $0x1, 0x48(%rsp)
jne 0x1e0df
testq %rbp, %rbp
je 0x1e0fc
movl %r13d, %eax
xorl %ecx, %ecx
movb 0x10(%rsp,%rcx), %dl
movb %dl, (%rbx,%rcx)
incq %rcx
cmpl %ecx, %eax
jne 0x1e0cf
jmp 0x1e0fc
testl %ebp, %ebp
je 0x1e0fc
leaq (%rbx,%r13), %rax
decq %rax
xorl %ecx, %ecx
movb 0x10(%rsp,%rcx), %dl
movb %dl, (%rax)
decq %rax
incq %rcx
cmpl %ecx, %ebp
jne 0x1e0ec
addq %r13, 0x68(%rsp)
movq 0x50(%rsp), %rax
cmpb $0x0, (%rax)
movl %r12d, %r14d
jne 0x1dd67
leaq 0x58(%rsp), %rdi
callq 0x153c0
movl $0x1, %eax
addq $0x2078, %rsp           # imm = 0x2078
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq