// File: /workspace/github_c_makefile_star2_O1/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 $0x2088, %rsp           # imm = 0x2088
movq %rdi, %rbx
movl $0x1, %r14d
movl $0x1, %esi
xorl %edx, %edx
callq 0x14535
movq %rax, 0x48(%rsp)
movq %rbx, 0x58(%rsp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x60(%rsp)
movq %rbx, %rdi
callq 0x63bd
leaq 0x68(%rsp), %rsi
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
callq 0x149f7
movq 0x48(%rsp), %rax
cmpb $0x0, (%rax)
je 0x1d56b
movq $0x0, 0x10(%rsp)
leaq 0x68(%rsp), %r15
leaq 0x58(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x48(%rsp), %rdx
leaq 0x54(%rsp), %rcx
leaq 0x1c(%rsp), %r8
callq 0x1e526
movl %eax, %ebx
movl 0x1c(%rsp), %r12d
movl 0x54(%rsp), %ebp
testl %r12d, %r12d
jle 0x1d221
movl %r12d, %r13d
movq 0x78(%rsp), %rax
cmpq 0x70(%rsp), %rax
jb 0x1d1fe
movl $0x1, %esi
movq %r15, %rdi
callq 0x146f3
movq 0x68(%rsp), %rax
movq 0x78(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x78(%rsp)
movb $0x0, (%rax,%rcx)
decl %r13d
jg 0x1d1e5
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x1d226
leal -0x1(%r12), %eax
movslq %ebp, %r13
addl %r13d, %r12d
movslq %r12d, %rcx
addq %rcx, 0x10(%rsp)
movl %eax, 0x1c(%rsp)
leal 0x1(%r14), %r12d
movl %ebx, %eax
leaq 0x6093(%rip), %rcx      # 0x232d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x1465a
movq %rax, %rbx
cmpl $0x7, %ebp
jg 0x1d29e
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 0x1d29e
movq 0x8(%rsp), %rdi
movl %r12d, %esi
leaq 0x647c(%rip), %rdx      # 0x23715
callq 0x13ea8
movl 0x60(%rsp), %edx
movq %rbx, %r8
shrq $0x3f, %r8
movq %r15, %rdi
movq %rbx, %rsi
movl %r13d, %ecx
jmp 0x1d443
movq 0x8(%rsp), %rdi
movl %r12d, %esi
leaq 0x20(%rsp), %rdx
callq 0x14535
movq %rax, %rbx
cmpl $0x7, %r13d
jg 0x1d2fa
movq 0x20(%rsp), %rax
leal (,%rbp,8), %ecx
shrq %cl, %rax
testq %rax, %rax
je 0x1d2fa
movq 0x8(%rsp), %rdi
movl %r12d, %esi
leaq 0x6461(%rip), %rdx      # 0x23756
callq 0x13ea8
movq 0x20(%rsp), %rsi
movl 0x60(%rsp), %edx
movq %r15, %rdi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x1e5f6
movq 0x20(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1487e
movq 0x10(%rsp), %rax
addq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x1d55a
movq %r15, %rdi
movq %r13, %rsi
callq 0x146f3
movq %rax, %rbx
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x145d6
cmpq $0x8, %rbp
je 0x1d511
cmpl $0x4, %ebp
jne 0x1d511
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
jmp 0x1d517
movq 0x8(%rsp), %rdi
movl %r12d, %esi
leaq 0x20(%rsp), %rdx
callq 0x14535
movq %rax, %rbx
cmpq %r13, 0x20(%rsp)
jbe 0x1d3a1
movq 0x8(%rsp), %rdi
movl %r12d, %esi
leaq 0x639c(%rip), %rdx      # 0x23738
callq 0x13ea8
movq 0x20(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1487e
movq 0x20(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rsp)
cmpq %r13, %rax
jae 0x1d55a
movq 0x78(%rsp), %rax
cmpq 0x70(%rsp), %rax
jb 0x1d3e1
movl $0x1, %esi
movq %r15, %rdi
callq 0x146f3
movq 0x68(%rsp), %rax
movq 0x78(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x78(%rsp)
movb $0x0, (%rax,%rcx)
jmp 0x1d3b1
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x1465a
movq %rax, %rbx
cmpl $0x7, %ebp
jg 0x1d433
shll $0x3, %ebp
movq %rbx, %rax
movl %ebp, %ecx
shrq %cl, %rax
testq %rax, %rax
je 0x1d433
movq 0x8(%rsp), %rdi
movl %r12d, %esi
leaq 0x62f8(%rip), %rdx      # 0x23726
callq 0x13ea8
movl 0x60(%rsp), %edx
movq %r15, %rdi
movq %rbx, %rsi
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x1e5f6
jmp 0x1d55a
movq 0x8(%rsp), %rdi
movl %r12d, %esi
leaq 0x20(%rsp), %rdx
callq 0x14535
movq %rax, %rbx
movq %rax, %rdi
callq 0x5150
cmpq 0x20(%rsp), %rax
je 0x1d485
movq 0x8(%rsp), %rdi
movl %r12d, %esi
leaq 0x6157(%rip), %rdx      # 0x235d7
callq 0x13ea8
movq 0x20(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1487e
movq 0x78(%rsp), %rax
cmpq 0x70(%rsp), %rax
jb 0x1d4ae
movl $0x1, %esi
movq %r15, %rdi
callq 0x146f3
movq 0x68(%rsp), %rax
movq 0x78(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x78(%rsp)
movb $0x0, (%rax,%rcx)
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
addq %rax, %rcx
incq %rcx
movq %rcx, 0x10(%rsp)
jmp 0x1d55a
movq 0x78(%rsp), %rax
cmpq 0x70(%rsp), %rax
jb 0x1d4f5
movl $0x1, %esi
movq %r15, %rdi
callq 0x146f3
movq 0x68(%rsp), %rax
movq 0x78(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x78(%rsp)
movb $0x0, (%rax,%rcx)
movl %r14d, %r12d
jmp 0x1d55a
movsd %xmm0, 0x20(%rsp)
cmpl $0x1, 0x60(%rsp)
jne 0x1d538
testq %rbp, %rbp
je 0x1d555
movl %r13d, %eax
xorl %ecx, %ecx
movb 0x20(%rsp,%rcx), %dl
movb %dl, (%rbx,%rcx)
incq %rcx
cmpl %ecx, %eax
jne 0x1d528
jmp 0x1d555
testl %ebp, %ebp
je 0x1d555
leaq (%rbx,%r13), %rax
decq %rax
xorl %ecx, %ecx
movb 0x20(%rsp,%rcx), %dl
movb %dl, (%rax)
decq %rax
incq %rcx
cmpl %ecx, %ebp
jne 0x1d545
addq %r13, 0x78(%rsp)
movq 0x48(%rsp), %rax
cmpb $0x0, (%rax)
movl %r12d, %r14d
jne 0x1d1b4
leaq 0x68(%rsp), %rdi
callq 0x148ef
movl $0x1, %eax
addq $0x2088, %rsp           # imm = 0x2088
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq