// File: /workspace/github_c_makefile_star2_O1/tylerneylon[P]APIsWithLua/lua/lstrlib.c
// Function: str_unpack
static int str_unpack (lua_State *L) {
  Header h;
  const char *fmt = luaL_checkstring(L, 1);
  size_t ld;
  const char *data = luaL_checklstring(L, 2, &ld);
  size_t pos = (size_t)posrelat(luaL_optinteger(L, 3, 1), ld) - 1;
  int n = 0;  /* number of results */
  luaL_argcheck(L, pos <= ld, 3, "initial position out of string");
  initheader(L, &h);
  while (*fmt != '\0') {
    int size, ntoalign;
    KOption opt = getdetails(&h, pos, &fmt, &size, &ntoalign);
    if ((size_t)ntoalign + size > ~pos || pos + ntoalign + size > ld)
      luaL_argerror(L, 2, "data string too short");
    pos += ntoalign;  /* skip alignment */
    /* stack space for item + next position */
    luaL_checkstack(L, 2, "too many results");
    n++;
    switch (opt) {
      case Kint:
      case Kuint: {
        lua_Integer res = unpackint(L, data + pos, h.islittle, size,
                                       (opt == Kint));
        lua_pushinteger(L, res);
        break;
      }
      case Kfloat: {
        volatile Ftypes u;
        lua_Number num;
        copywithendian(u.buff, data + pos, size, h.islittle);
        if (size == sizeof(u.f)) num = (lua_Number)u.f;
        else if (size == sizeof(u.d)) num = (lua_Number)u.d;
        else num = u.n;
        lua_pushnumber(L, num);
        break;
      }
      case Kchar: {
        lua_pushlstring(L, data + pos, size);
        break;
      }
      case Kstring: {
        size_t len = (size_t)unpackint(L, data + pos, h.islittle, size, 0);
        luaL_argcheck(L, pos + len + size <= ld, 2, "data string too short");
        lua_pushlstring(L, data + pos + size, len);
        pos += len;  /* skip string */
        break;
      }
      case Kzstr: {
        size_t len = (int)strlen(data + pos);
        lua_pushlstring(L, data + pos, len);
        pos += len + 1;  /* skip string plus final '\0' */
        break;
      }
      case Kpaddalign: case Kpadding: case Knop:
        n--;  /* undo increment */
        break;
    }
    pos += size;
  }
  lua_pushinteger(L, pos + 1);  /* next position */
  return n + 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movl $0x1, %esi
xorl %edx, %edx
callq 0x14535
movq %rax, 0x8(%rsp)
leaq 0x18(%rsp), %r15
movq %rbx, %rdi
movl $0x2, %esi
movq %r15, %rdx
callq 0x14535
movq %rax, (%rsp)
movl $0x1, %edx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x146c5
movq %rax, %r13
movq (%r15), %rax
testq %r13, %r13
jns 0x1d6e1
movq %r13, %rcx
negq %rcx
cmpq %rcx, %rax
jae 0x1d6db
xorl %r13d, %r13d
jmp 0x1d6e1
addq %rax, %r13
incq %r13
leaq -0x1(%r13), %r15
cmpq %rax, %r15
jbe 0x1d6fe
leaq 0x616f(%rip), %rdx      # 0x23860
movq %rbx, %rdi
movl $0x3, %esi
callq 0x13ea8
movq %rbx, 0x20(%rsp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x28(%rsp)
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x1d8f2
xorl %r12d, %r12d
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
leaq 0x14(%rsp), %rcx
leaq 0x10(%rsp), %r8
callq 0x1e526
movl %eax, %r13d
movslq 0x10(%rsp), %r14
movslq 0x14(%rsp), %rbp
leaq (%r14,%rbp), %rax
addq %r15, %rax
jb 0x1d763
leaq (%r15,%r14), %rax
addq %rbp, %rax
cmpq 0x18(%rsp), %rax
jbe 0x1d777
movq %rbx, %rdi
movl $0x2, %esi
leaq 0x610d(%rip), %rdx      # 0x2387f
callq 0x13ea8
addq %r14, %r15
movq %rbx, %rdi
movl $0x2, %esi
leaq 0x610c(%rip), %rdx      # 0x23895
callq 0x13e55
leal 0x1(%r12), %r14d
movl %r13d, %eax
leaq 0x5b5f(%rip), %rcx      # 0x232fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
leaq (%rax,%r15), %rsi
movl 0x28(%rsp), %edx
xorl %r8d, %r8d
testl %r13d, %r13d
sete %r8b
movq %rbx, %rdi
movl %ebp, %ecx
callq 0x1e8be
movq %rbx, %rdi
movq %rax, %rsi
callq 0x63e6
jmp 0x1d8d3
movq (%rsp), %rax
leaq (%rax,%r15), %r12
movl 0x28(%rsp), %edx
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x1e8be
movq %rax, %r13
addq %rax, %r15
leaq (%r15,%rbp), %rax
cmpq 0x18(%rsp), %rax
jbe 0x1d817
movq %rbx, %rdi
movl $0x2, %esi
leaq 0x606d(%rip), %rdx      # 0x2387f
callq 0x13ea8
addq %rbp, %r12
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
jmp 0x1d85f
movq (%rsp), %rax
addq %r15, %rax
cmpl $0x1, 0x28(%rsp)
jne 0x1d88f
testl %ebp, %ebp
je 0x1d8c5
movl %ebp, %ecx
xorl %edx, %edx
movb (%rax,%rdx), %sil
movb %sil, 0x30(%rsp,%rdx)
incq %rdx
cmpl %edx, %ecx
jne 0x1d83f
jmp 0x1d8b0
movq (%rsp), %rax
leaq (%rax,%r15), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x63fa
jmp 0x1d8d3
movq (%rsp), %rax
leaq (%rax,%r15), %r12
movq %r12, %rdi
callq 0x5150
movslq %eax, %r13
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x63fa
addq %r13, %r15
incq %r15
jmp 0x1d8d3
testl %ebp, %ebp
je 0x1d8c5
leaq 0x2f(%rsp), %rcx
addq %rbp, %rcx
movl %ebp, %edx
xorl %esi, %esi
movb (%rax,%rsi), %dil
movb %dil, (%rcx)
decq %rcx
incq %rsi
cmpl %esi, %edx
jne 0x1d89f
cmpl $0x8, %ebp
je 0x1d8c5
cmpl $0x4, %ebp
jne 0x1d8c5
xorps %xmm0, %xmm0
cvtss2sd 0x30(%rsp), %xmm0
jmp 0x1d8cb
movsd 0x30(%rsp), %xmm0
movq %rbx, %rdi
callq 0x63d1
movl %r14d, %r12d
addq %rbp, %r15
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x1d723
incq %r15
incl %r12d
movq %r15, %r13
jmp 0x1d8f8
movl $0x1, %r12d
movq %rbx, %rdi
movq %r13, %rsi
callq 0x63e6
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq