// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq $0x0, 0x8(%rsp)
pushq $0x1
popq %rbp
movl %ebp, %esi
xorl %edx, %edx
callq 0x13131
movq %rax, %r14
leaq 0x40(%rsp), %rax
movq %r14, (%rax)
leaq 0x48(%rsp), %rcx
movq %rbx, (%rcx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%rcx)
movq %rbx, %rdi
callq 0x6135
leaq 0x58(%rsp), %r13
movq %rbx, (%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x13589
cmpb $0x0, (%r14)
je 0x1b954
leaq 0x48(%rsp), %rdi
movq 0x8(%rsp), %rsi
leaq 0x40(%rsp), %rdx
leaq 0x14(%rsp), %rcx
leaq 0x10(%rsp), %r8
callq 0x1c7f7
movl %eax, %r14d
movslq 0x10(%rsp), %r15
movslq 0x14(%rsp), %r12
movq %r15, %rbx
addq %r12, %rbx
testl %r15d, %r15d
jle 0x1b64c
movq 0x68(%rsp), %rax
cmpq 0x60(%rsp), %rax
jb 0x1b635
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x132de
movq 0x68(%rsp), %rax
movq 0x58(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x68(%rsp)
movb $0x0, (%rcx,%rax)
decl %r15d
jmp 0x1b614
addq %rbx, 0x8(%rsp)
leal 0x1(%rbp), %r15d
movl %r14d, %eax
leaq 0x5d99(%rip), %rcx      # 0x213f8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rdi
movl %r15d, %esi
callq 0x13252
movq %rax, %rbx
cmpl $0x7, %r12d
jg 0x1b6b6
leal (,%r12,8), %ecx
decb %cl
pushq $0x1
popq %rax
shlq %cl, %rax
movq %rax, %rcx
negq %rcx
cmpq %rcx, %rbx
setge %cl
cmpq %rax, %rbx
setl %al
testb %al, %cl
jne 0x1b6b6
movq (%rsp), %rdi
movl %r15d, %esi
leaq 0x6184(%rip), %rdx      # 0x21835
callq 0x12af2
movl 0x50(%rsp), %edx
movq %rbx, %r8
shrq $0x3f, %r8
movq %r13, %rdi
movq %rbx, %rsi
movl %r12d, %ecx
jmp 0x1b85d
movq (%rsp), %rdi
movl %r15d, %esi
leaq 0x18(%rsp), %rdx
callq 0x13131
movq %rax, %rbx
movq 0x18(%rsp), %rsi
cmpl $0x7, %r12d
jg 0x1b717
movl %r12d, %ecx
shll $0x3, %ecx
movq %rsi, %rax
shrq %cl, %rax
testq %rax, %rax
je 0x1b717
movq (%rsp), %rdi
movl %r15d, %esi
leaq 0x6169(%rip), %rdx      # 0x21876
callq 0x12af2
movq 0x18(%rsp), %rsi
movl 0x50(%rsp), %edx
movq %r13, %rdi
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x1c8c9
movq 0x18(%rsp), %rdx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x13460
movq 0x8(%rsp), %rax
addq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0x1b947
movq %r13, %rdi
movq %r12, %rsi
callq 0x132de
movq %rax, %rbx
movq (%rsp), %rdi
movl %r15d, %esi
callq 0x131db
cmpl $0x8, %r12d
je 0x1b928
cmpl $0x4, %r12d
jne 0x1b928
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x18(%rsp)
jmp 0x1b92e
movq (%rsp), %rdi
movl %r15d, %esi
leaq 0x18(%rsp), %rdx
callq 0x13131
movq %rax, %rbx
movq 0x18(%rsp), %rdx
cmpq %r12, %rdx
jbe 0x1b7c0
movq (%rsp), %rdi
movl %r15d, %esi
leaq 0x60a2(%rip), %rdx      # 0x21858
callq 0x12af2
movq 0x18(%rsp), %rdx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x13460
movq 0x18(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x18(%rsp)
cmpq %r12, %rax
jae 0x1b947
movq 0x68(%rsp), %rax
cmpq 0x60(%rsp), %rax
jb 0x1b7fe
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x132de
movq 0x68(%rsp), %rax
movq 0x58(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x68(%rsp)
movb $0x0, (%rcx,%rax)
jmp 0x1b7cb
movq (%rsp), %rdi
movl %r15d, %esi
callq 0x13252
movq %rax, %rbx
cmpl $0x7, %r12d
jg 0x1b84d
leal (,%r12,8), %ecx
movq %rbx, %rax
shrq %cl, %rax
testq %rax, %rax
je 0x1b84d
movq (%rsp), %rdi
movl %r15d, %esi
leaq 0x5ffe(%rip), %rdx      # 0x21846
callq 0x12af2
movl 0x50(%rsp), %edx
movq %r13, %rdi
movq %rbx, %rsi
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x1c8c9
jmp 0x1b947
movq (%rsp), %rdi
movl %r15d, %esi
leaq 0x18(%rsp), %rdx
callq 0x13131
movq %rax, %rbx
movq %rax, %rdi
callq 0x5140
cmpq 0x18(%rsp), %rax
je 0x1b8a2
movq (%rsp), %rdi
movl %r15d, %esi
leaq 0x5e5f(%rip), %rdx      # 0x216f7
callq 0x12af2
movq 0x18(%rsp), %rax
movq %r13, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x13460
movq 0x68(%rsp), %rax
cmpq 0x60(%rsp), %rax
jb 0x1b8cc
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x132de
movq 0x68(%rsp), %rax
movq 0x58(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x68(%rsp)
movb $0x0, (%rcx,%rax)
movq 0x18(%rsp), %rax
movq 0x8(%rsp), %rcx
addq %rax, %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
jmp 0x1b947
movq 0x68(%rsp), %rax
cmpq 0x60(%rsp), %rax
jb 0x1b911
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x132de
movq 0x68(%rsp), %rax
movq 0x58(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x68(%rsp)
movb $0x0, (%rcx,%rax)
movl %ebp, %r15d
jmp 0x1b947
movsd %xmm0, 0x18(%rsp)
movl 0x50(%rsp), %ecx
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
movl %r12d, %edx
callq 0x1c963
addq %r12, 0x68(%rsp)
movq 0x40(%rsp), %r14
movl %r15d, %ebp
jmp 0x1b5d9
leaq 0x58(%rsp), %rdi
callq 0x134ba
pushq $0x1
popq %rax
addq $0x2078, %rsp           # imm = 0x2078
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq