// File: /workspace/github_c_makefile_star2_O3/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 0x14fff
movq %rax, %r15
movq %rax, 0x18(%rsp)
leaq 0x10(%rsp), %r13
movq %rbx, %rdi
movl $0x2, %esi
movq %r13, %rdx
callq 0x14fff
movq %rax, (%rsp)
movl $0x1, %edx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x1518f
movq %rax, %r14
movq (%r13), %rax
testq %r14, %r14
jns 0x1e287
movq %r14, %rcx
negq %rcx
cmpq %rcx, %rax
jae 0x1e281
xorl %r14d, %r14d
jmp 0x1e287
addq %rax, %r14
incq %r14
leaq -0x1(%r14), %r12
cmpq %rax, %r12
jbe 0x1e2a4
leaq 0x6681(%rip), %rdx      # 0x24918
movq %rbx, %rdi
movl $0x3, %esi
callq 0x1497c
movq %rbx, 0x20(%rsp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x28(%rsp)
cmpb $0x0, (%r15)
je 0x1e49e
xorl %r13d, %r13d
movq %r12, %r15
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
leaq 0x18(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x1f063
movl %eax, %ebp
movslq 0x8(%rsp), %r12
movslq 0xc(%rsp), %r14
leaq (%r14,%r12), %rax
addq %r15, %r12
addq %r15, %rax
jb 0x1e307
leaq (%r12,%r14), %rax
cmpq 0x10(%rsp), %rax
jbe 0x1e31b
movq %rbx, %rdi
movl $0x2, %esi
leaq 0x6621(%rip), %rdx      # 0x24937
callq 0x1497c
movq %rbx, %rdi
movl $0x2, %esi
leaq 0x6623(%rip), %rdx      # 0x2494d
callq 0x14929
leal 0x1(%r13), %r15d
movl %ebp, %eax
leaq 0x6050(%rip), %rcx      # 0x2438c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
leaq (%rax,%r12), %rsi
movl 0x28(%rsp), %edx
xorl %r8d, %r8d
testl %ebp, %ebp
sete %r8b
movq %rbx, %rdi
movl %r14d, %ecx
callq 0x1f74c
movq %rbx, %rdi
movq %rax, %rsi
callq 0x64f6
jmp 0x1e47f
movq (%rsp), %rax
leaq (%rax,%r12), %r13
movl 0x28(%rsp), %edx
movq %rbx, %rdi
movq %r13, %rsi
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0x1f74c
movq %rax, %rbp
addq %rax, %r12
leaq (%r12,%r14), %rax
cmpq 0x10(%rsp), %rax
jbe 0x1e3b7
movq %rbx, %rdi
movl $0x2, %esi
leaq 0x6585(%rip), %rdx      # 0x24937
callq 0x1497c
addq %r14, %r13
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
jmp 0x1e401
movq (%rsp), %rax
addq %r12, %rax
cmpl $0x1, 0x28(%rsp)
jne 0x1e437
testl %r14d, %r14d
je 0x1e471
movl %r14d, %ecx
xorl %edx, %edx
movb (%rax,%rdx), %sil
movb %sil, 0x30(%rsp,%rdx)
incq %rdx
cmpl %edx, %ecx
jne 0x1e3e1
jmp 0x1e45a
movq (%rsp), %rax
leaq (%rax,%r12), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x650a
jmp 0x1e47f
movq (%rsp), %rax
movl %r15d, %ebp
leaq (%rax,%r12), %r15
movq %r15, %rdi
callq 0x5140
movslq %eax, %r13
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x650a
addq %r13, %r12
incq %r12
movl %ebp, %r13d
jmp 0x1e482
testl %r14d, %r14d
je 0x1e471
leaq 0x2f(%rsp), %rcx
addq %r14, %rcx
movl %r14d, %edx
xorl %esi, %esi
movb (%rax,%rsi), %dil
movb %dil, (%rcx)
decq %rcx
incq %rsi
cmpl %esi, %edx
jne 0x1e449
cmpl $0x8, %r14d
je 0x1e471
cmpl $0x4, %r14d
jne 0x1e471
xorps %xmm0, %xmm0
cvtss2sd 0x30(%rsp), %xmm0
jmp 0x1e477
movsd 0x30(%rsp), %xmm0
movq %rbx, %rdi
callq 0x64e1
movl %r15d, %r13d
addq %r14, %r12
movq 0x18(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x1e2c5
incq %r12
incl %r13d
movq %r12, %r14
jmp 0x1e4a4
movl $0x1, %r13d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x64f6
movl %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq