// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2120, %rsp           # imm = 0x2120
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x20390
movq %rax, -0x2040(%rbp)
movl $0x1, -0x2044(%rbp)
movq $0x0, -0x2050(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x2038(%rbp), %rsi
callq 0x2fdf0
movq -0x8(%rbp), %rdi
callq 0x6b60
movq -0x8(%rbp), %rdi
leaq -0x2028(%rbp), %rsi
callq 0x20aa0
movq -0x2040(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x2d9b2
movq -0x2050(%rbp), %rsi
leaq -0x2038(%rbp), %rdi
leaq -0x2040(%rbp), %rdx
leaq -0x2054(%rbp), %rcx
leaq -0x2058(%rbp), %r8
callq 0x2fe30
movl %eax, -0x205c(%rbp)
movl -0x2058(%rbp), %eax
addl -0x2054(%rbp), %eax
cltq
addq -0x2050(%rbp), %rax
movq %rax, -0x2050(%rbp)
movl -0x2058(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x2058(%rbp)
cmpl $0x0, %eax
jle 0x2d407
movq -0x2018(%rbp), %rcx
movb $0x1, %al
cmpq -0x2020(%rbp), %rcx
movb %al, -0x20e1(%rbp)
jb 0x2d3df
leaq -0x2028(%rbp), %rdi
movl $0x1, %esi
callq 0x20630
cmpq $0x0, %rax
setne %al
movb %al, -0x20e1(%rbp)
movb -0x20e1(%rbp), %al
movq -0x2028(%rbp), %rax
movq -0x2018(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x2018(%rbp)
movb $0x0, (%rax,%rcx)
jmp 0x2d393
movl -0x2044(%rbp), %eax
incl %eax
movl %eax, -0x2044(%rbp)
movl -0x205c(%rbp), %eax
movq %rax, -0x20f0(%rbp)
subq $0x8, %rax
ja 0x2d9ad
movq -0x20f0(%rbp), %rax
leaq 0x973e(%rip), %rcx      # 0x36b78
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movl -0x2044(%rbp), %esi
callq 0x20550
movq %rax, -0x2068(%rbp)
cmpl $0x8, -0x2054(%rbp)
jge 0x2d4d3
movl -0x2054(%rbp), %eax
shll $0x3, %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x2070(%rbp)
xorl %eax, %eax
subq -0x2070(%rbp), %rax
cmpq -0x2068(%rbp), %rax
jg 0x2d4ab
movq -0x2068(%rbp), %rcx
movb $0x1, %al
cmpq -0x2070(%rbp), %rcx
movb %al, -0x20f1(%rbp)
jl 0x2d4cd
movq -0x8(%rbp), %rdi
movl -0x2044(%rbp), %esi
leaq 0x9c19(%rip), %rdx      # 0x370d5
callq 0x1fab0
cmpl $0x0, %eax
setne %al
movb %al, -0x20f1(%rbp)
movb -0x20f1(%rbp), %al
movq -0x2068(%rbp), %rsi
movl -0x2030(%rbp), %edx
movl -0x2054(%rbp), %ecx
cmpq $0x0, -0x2068(%rbp)
setl %al
andb $0x1, %al
movzbl %al, %r8d
leaq -0x2028(%rbp), %rdi
callq 0x2ff40
jmp 0x2d9ad
movq -0x8(%rbp), %rdi
movl -0x2044(%rbp), %esi
callq 0x20550
movq %rax, -0x2078(%rbp)
cmpl $0x8, -0x2054(%rbp)
jge 0x2d586
movq -0x2078(%rbp), %rax
movq %rax, -0x2100(%rbp)
movl -0x2054(%rbp), %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq -0x2100(%rbp), %rcx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, -0x20f2(%rbp)
jb 0x2d580
movq -0x8(%rbp), %rdi
movl -0x2044(%rbp), %esi
leaq 0x9b77(%rip), %rdx      # 0x370e6
callq 0x1fab0
cmpl $0x0, %eax
setne %al
movb %al, -0x20f2(%rbp)
movb -0x20f2(%rbp), %al
movq -0x2078(%rbp), %rsi
movl -0x2030(%rbp), %edx
movl -0x2054(%rbp), %ecx
leaq -0x2028(%rbp), %rdi
xorl %r8d, %r8d
callq 0x2ff40
jmp 0x2d9ad
movslq -0x2054(%rbp), %rsi
leaq -0x2028(%rbp), %rdi
callq 0x20630
movq %rax, -0x20a8(%rbp)
movq -0x8(%rbp), %rdi
movl -0x2044(%rbp), %esi
callq 0x204b0
movsd %xmm0, -0x20b0(%rbp)
movslq -0x2054(%rbp), %rax
cmpq $0x4, %rax
jne 0x2d601
movsd -0x20b0(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x20a0(%rbp)
jmp 0x2d632
movslq -0x2054(%rbp), %rax
cmpq $0x8, %rax
jne 0x2d620
movsd -0x20b0(%rbp), %xmm0
movsd %xmm0, -0x20a0(%rbp)
jmp 0x2d630
movsd -0x20b0(%rbp), %xmm0
movsd %xmm0, -0x20a0(%rbp)
jmp 0x2d632
movq -0x20a8(%rbp), %rdi
leaq -0x20a0(%rbp), %rsi
movl -0x2054(%rbp), %edx
movl -0x2030(%rbp), %ecx
callq 0x30080
movslq -0x2054(%rbp), %rax
addq -0x2018(%rbp), %rax
movq %rax, -0x2018(%rbp)
jmp 0x2d9ad
movq -0x8(%rbp), %rdi
movl -0x2044(%rbp), %esi
leaq -0x20b8(%rbp), %rdx
callq 0x20390
movq %rax, -0x20c0(%rbp)
movq -0x20b8(%rbp), %rcx
movslq -0x2054(%rbp), %rdx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, -0x2101(%rbp)
jbe 0x2d6c5
movq -0x8(%rbp), %rdi
movl -0x2044(%rbp), %esi
leaq 0x9a44(%rip), %rdx      # 0x370f8
callq 0x1fab0
cmpl $0x0, %eax
setne %al
movb %al, -0x2101(%rbp)
movb -0x2101(%rbp), %al
movq -0x20c0(%rbp), %rsi
movq -0x20b8(%rbp), %rdx
leaq -0x2028(%rbp), %rdi
callq 0x208a0
movq -0x20b8(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20b8(%rbp)
movslq -0x2054(%rbp), %rcx
cmpq %rcx, %rax
jae 0x2d764
movq -0x2018(%rbp), %rcx
movb $0x1, %al
cmpq -0x2020(%rbp), %rcx
movb %al, -0x2102(%rbp)
jb 0x2d73c
leaq -0x2028(%rbp), %rdi
movl $0x1, %esi
callq 0x20630
cmpq $0x0, %rax
setne %al
movb %al, -0x2102(%rbp)
movb -0x2102(%rbp), %al
movq -0x2028(%rbp), %rax
movq -0x2018(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x2018(%rbp)
movb $0x0, (%rax,%rcx)
jmp 0x2d6e5
jmp 0x2d9ad
movq -0x8(%rbp), %rdi
movl -0x2044(%rbp), %esi
leaq -0x20c8(%rbp), %rdx
callq 0x20390
movq %rax, -0x20d0(%rbp)
movb $0x1, %al
cmpl $0x8, -0x2054(%rbp)
movb %al, -0x2103(%rbp)
jge 0x2d7f0
movq -0x20c8(%rbp), %rax
movq %rax, -0x2110(%rbp)
movl -0x2054(%rbp), %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq -0x2110(%rbp), %rcx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, -0x2103(%rbp)
jb 0x2d7f0
movq -0x8(%rbp), %rdi
movl -0x2044(%rbp), %esi
leaq 0x9937(%rip), %rdx      # 0x37116
callq 0x1fab0
cmpl $0x0, %eax
setne %al
movb %al, -0x2103(%rbp)
movb -0x2103(%rbp), %al
movq -0x20c8(%rbp), %rsi
movl -0x2030(%rbp), %edx
movl -0x2054(%rbp), %ecx
leaq -0x2028(%rbp), %rdi
xorl %r8d, %r8d
callq 0x2ff40
movq -0x20d0(%rbp), %rsi
movq -0x20c8(%rbp), %rdx
leaq -0x2028(%rbp), %rdi
callq 0x208a0
movq -0x20c8(%rbp), %rax
addq -0x2050(%rbp), %rax
movq %rax, -0x2050(%rbp)
jmp 0x2d9ad
movq -0x8(%rbp), %rdi
movl -0x2044(%rbp), %esi
leaq -0x20d8(%rbp), %rdx
callq 0x20390
movq %rax, -0x20e0(%rbp)
movq -0x20e0(%rbp), %rdi
callq 0x5150
movq %rax, %rcx
movb $0x1, %al
cmpq -0x20d8(%rbp), %rcx
movb %al, -0x2111(%rbp)
je 0x2d8ab
movq -0x8(%rbp), %rdi
movl -0x2044(%rbp), %esi
leaq 0x96fd(%rip), %rdx      # 0x36f97
callq 0x1fab0
cmpl $0x0, %eax
setne %al
movb %al, -0x2111(%rbp)
movb -0x2111(%rbp), %al
movq -0x20e0(%rbp), %rsi
movq -0x20d8(%rbp), %rdx
leaq -0x2028(%rbp), %rdi
callq 0x208a0
movq -0x2018(%rbp), %rcx
movb $0x1, %al
cmpq -0x2020(%rbp), %rcx
movb %al, -0x2112(%rbp)
jb 0x2d901
leaq -0x2028(%rbp), %rdi
movl $0x1, %esi
callq 0x20630
cmpq $0x0, %rax
setne %al
movb %al, -0x2112(%rbp)
movb -0x2112(%rbp), %al
movq -0x2028(%rbp), %rax
movq -0x2018(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x2018(%rbp)
movb $0x0, (%rax,%rcx)
movq -0x20d8(%rbp), %rax
addq $0x1, %rax
addq -0x2050(%rbp), %rax
movq %rax, -0x2050(%rbp)
jmp 0x2d9ad
movq -0x2018(%rbp), %rcx
movb $0x1, %al
cmpq -0x2020(%rbp), %rcx
movb %al, -0x2113(%rbp)
jb 0x2d978
leaq -0x2028(%rbp), %rdi
movl $0x1, %esi
callq 0x20630
cmpq $0x0, %rax
setne %al
movb %al, -0x2113(%rbp)
movb -0x2113(%rbp), %al
movq -0x2028(%rbp), %rax
movq -0x2018(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x2018(%rbp)
movb $0x0, (%rax,%rcx)
movl -0x2044(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2044(%rbp)
jmp 0x2d336
leaq -0x2028(%rbp), %rdi
callq 0x20940
movl $0x1, %eax
addq $0x2120, %rsp           # imm = 0x2120
popq %rbp
retq
nopl (%rax)