// File: /workspace/github_c_makefile_star2_O2/tylerneylon[P]APIsWithLua/lua/lbaselib.c
// Function: luaB_tonumber
static int luaB_tonumber (lua_State *L) {
  if (lua_isnoneornil(L, 2)) {  /* standard conversion? */
    luaL_checkany(L, 1);
    if (lua_type(L, 1) == LUA_TNUMBER) {  /* already a number? */
      lua_settop(L, 1);  /* yes; return it */
      return 1;
    }
    else {
      size_t l;
      const char *s = lua_tolstring(L, 1, &l);
      if (s != NULL && lua_stringtonumber(L, s) == l + 1)
        return 1;  /* successful conversion to number */
      /* else not a number */
    }
  }
  else {
    size_t l;
    const char *s;
    lua_Integer n = 0;  /* to avoid warnings */
    lua_Integer base = luaL_checkinteger(L, 2);
    luaL_checktype(L, 1, LUA_TSTRING);  /* no numbers as strings */
    s = lua_tolstring(L, 1, &l);
    luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
    if (b_str2int(s, (int)base, &n) == s + l) {
      lua_pushinteger(L, n);
      return 1;
    }  /* else not a number */
  }  /* else not a number */
  lua_pushnil(L);  /* not a number */
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
pushq $0x2
popq %rsi
callq 0x5d12
testl %eax, %eax
jle 0x1701d
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x13252
movq %rax, %r15
pushq $0x1
popq %rbp
pushq $0x4
popq %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x1315e
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fca
movq %rax, %r12
movq %rax, %r13
leaq -0x2(%r15), %rax
cmpq $0x23, %rax
jb 0x16f49
leaq 0x9da9(%rip), %rdx      # 0x20ce7
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x12af2
leaq 0x9da9(%rip), %rsi      # 0x20cf9
movq %r13, %rdi
callq 0x51e0
movb (%r13,%rax), %cl
movq %rcx, 0x20(%rsp)
addl $-0x2b, %ecx
andb $-0x3, %cl
cmpb $0x1, %cl
adcq %rax, %r12
callq 0x5520
movq (%rax), %rbp
movzbl (%r12), %ebx
movzwl (%rbp,%rbx,2), %ecx
movq $0x0, (%rsp)
movl $0x0, %eax
testb $0x8, %cl
je 0x1707e
movq %r13, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movslq %r15d, %r14
movq $0x0, (%rsp)
xorl %r13d, %r13d
btl $0xb, %ecx
jb 0x16fc7
callq 0x5030
movq (%rax), %rax
movzbl %bl, %ecx
movl (%rax,%rcx,4), %eax
addl $-0x37, %eax
jmp 0x16fcd
movsbl %bl, %eax
addl $-0x30, %eax
cmpl %r15d, %eax
jge 0x17072
movq %r13, %rcx
imulq %r14, %rcx
movslq %eax, %r13
addq %rcx, %r13
movzbl 0x1(%r12), %ebx
incq %r12
movzwl (%rbp,%rbx,2), %ecx
testb $0x8, %cl
jne 0x16fae
leaq 0x9cfc(%rip), %rsi      # 0x20cf9
movq %r12, %rdi
callq 0x51e0
addq %r12, %rax
movq %r13, %rcx
negq %rcx
cmpb $0x2d, 0x20(%rsp)
cmovneq %r13, %rcx
movq %rcx, (%rsp)
jmp 0x17074
pushq $0x1
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0x131a8
movq %r14, %rdi
movl %ebp, %esi
callq 0x5d12
pushq $0x1
popq %rsi
cmpl $0x3, %eax
jne 0x17046
movq %r14, %rdi
callq 0x5b31
jmp 0x170a1
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x5fca
testq %rax, %rax
je 0x1708b
movq %r14, %rdi
movq %rax, %rsi
callq 0x5eec
movq 0x8(%rsp), %rcx
incq %rcx
cmpq %rcx, %rax
jne 0x1708b
jmp 0x170a1
xorl %eax, %eax
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rcx
addq %r13, %rcx
cmpq %rcx, %rax
je 0x17095
movq %r14, %rdi
callq 0x6135
jmp 0x170a1
movq %r14, %rdi
movq (%rsp), %rsi
callq 0x615b
pushq $0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq