// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x13131
movq %rax, %rbp
movq %rax, 0x18(%rsp)
pushq $0x2
popq %rsi
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x13131
movq %rax, (%rsp)
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x132b0
movq %rax, %r12
movq (%r14), %rax
testq %r12, %r12
jns 0x1baae
movq %r12, %rcx
negq %rcx
cmpq %rcx, %rax
jae 0x1baa8
xorl %r12d, %r12d
jmp 0x1baae
addq %rax, %r12
incq %r12
decq %r12
cmpq %rax, %r12
jbe 0x1bac8
leaq 0x5ec3(%rip), %rdx      # 0x21980
pushq $0x3
popq %rsi
movq %rbx, %rdi
callq 0x12af2
leaq 0x20(%rsp), %rcx
movq %rbx, (%rcx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%rcx)
xorl %r15d, %r15d
cmpb $0x0, (%rbp)
je 0x1bc7a
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
leaq 0x18(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x1c7f7
movl %eax, %r14d
movslq 0x8(%rsp), %r13
movslq 0xc(%rsp), %rbp
movq %rbp, %rax
addq %r13, %rax
addq %r12, %r13
addq %r12, %rax
jb 0x1bb2f
movq %r13, %rax
addq %rbp, %rax
cmpq 0x10(%rsp), %rax
jbe 0x1bb41
movq %rbx, %rdi
pushq $0x2
popq %rsi
leaq 0x5e63(%rip), %rdx      # 0x2199f
callq 0x12af2
movq %rbx, %rdi
pushq $0x2
popq %rsi
leaq 0x5e67(%rip), %rdx      # 0x219b5
callq 0x12a9f
leal 0x1(%r15), %r12d
movl %r14d, %eax
leaq 0x58bb(%rip), %rcx      # 0x2141c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl %r15d, %r12d
jmp 0x1bc67
movq (%rsp), %rax
leaq (%rax,%r13), %rsi
movl 0x28(%rsp), %edx
xorl %r8d, %r8d
testl %r14d, %r14d
sete %r8b
movq %rbx, %rdi
movl %ebp, %ecx
callq 0x1cb7d
movq %rbx, %rdi
movq %rax, %rsi
callq 0x615b
jmp 0x1bc67
movq (%rsp), %rax
leaq (%rax,%r13), %r14
movl 0x28(%rsp), %edx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x1cb7d
movq %rax, %r15
addq %rax, %r13
movq %r13, %rax
addq %rbp, %rax
cmpq 0x10(%rsp), %rax
jbe 0x1bbe3
movq %rbx, %rdi
pushq $0x2
popq %rsi
leaq 0x5dc1(%rip), %rdx      # 0x2199f
callq 0x12af2
addq %rbp, %r14
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
jmp 0x1bc29
movq (%rsp), %rax
leaq (%rax,%r13), %rsi
movl 0x28(%rsp), %ecx
leaq 0x30(%rsp), %rdi
movl %ebp, %edx
callq 0x1c963
cmpl $0x8, %ebp
je 0x1bc59
cmpl $0x4, %ebp
jne 0x1bc59
cvtss2sd 0x30(%rsp), %xmm0
jmp 0x1bc5f
movq (%rsp), %rax
leaq (%rax,%r13), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x616f
jmp 0x1bc67
movq (%rsp), %rax
leaq (%rax,%r13), %r14
movq %r14, %rdi
callq 0x5140
movslq %eax, %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x616f
addq %r15, %r13
incq %r13
jmp 0x1bc67
movsd 0x30(%rsp), %xmm0
movq %rbx, %rdi
callq 0x6146
addq %rbp, %r13
movq 0x18(%rsp), %rbp
movl %r12d, %r15d
movq %r13, %r12
jmp 0x1bae1
incq %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x615b
incl %r15d
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq