// File: /workspace/github_c_makefile_star2_O2/tylerneylon[P]APIsWithLua/lua/ldblib.c
// Function: db_sethook
static int db_sethook (lua_State *L) {
  int arg, mask, count;
  lua_Hook func;
  lua_State *L1 = getthread(L, &arg);
  if (lua_isnoneornil(L, arg+1)) {  /* no hook? */
    lua_settop(L, arg+1);
    func = NULL; mask = 0; count = 0;  /* turn off hooks */
  }
  else {
    const char *smask = luaL_checkstring(L, arg+2);
    luaL_checktype(L, arg+1, LUA_TFUNCTION);
    count = (int)luaL_optinteger(L, arg + 3, 0);
    func = hookf; mask = makemask(smask, count);
  }
  if (lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY) == LUA_TNIL) {
    lua_createtable(L, 0, 2);  /* create a hook table */
    lua_pushvalue(L, -1);
    lua_rawsetp(L, LUA_REGISTRYINDEX, &HOOKKEY);  /* set it in position */
    lua_pushstring(L, "k");
    lua_setfield(L, -2, "__mode");  /** hooktable.__mode = "k" */
    lua_pushvalue(L, -1);
    lua_setmetatable(L, -2);  /* setmetatable(hooktable) = hooktable */
  }
  checkstack(L, L1, 1);
  lua_pushthread(L1); lua_xmove(L1, L, 1);  /* key (thread) */
  lua_pushvalue(L, arg + 1);  /* value (hook function) */
  lua_rawset(L, -3);  /* hooktable[L1] = new Lua hook */
  lua_sethook(L1, func, mask, count);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x14(%rsp), %r15
movq %r15, %rsi
callq 0x181a6
movq %rax, %r14
movl (%r15), %r15d
leal 0x1(%r15), %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5d12
testl %eax, %eax
movl %ebp, 0x4(%rsp)
jle 0x17ed3
leal 0x2(%r15), %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x13131
movq %rax, %r12
pushq $0x6
popq %rdx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1315e
addl $0x3, %r15d
movq %rbx, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x132b0
movq %rax, %rbp
pushq $0x63
popq %rsi
movq %r12, %rdi
callq 0x5160
xorl %r15d, %r15d
testq %rax, %rax
setne %r15b
pushq $0x72
popq %rsi
movq %r12, %rdi
callq 0x5160
leal 0x2(%r15), %r13d
testq %rax, %rax
cmovel %r15d, %r13d
pushq $0x6c
popq %rsi
movq %r12, %rdi
callq 0x5160
leal 0x4(%r13), %ecx
testq %rax, %rax
cmovel %r13d, %ecx
leal 0x8(%rcx), %r12d
movq %rbp, 0x8(%rsp)
testl %ebp, %ebp
cmovlel %ecx, %r12d
leaq 0x314(%rip), %r13       # 0x181e5
jmp 0x17eec
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5b31
xorl %r13d, %r13d
movq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0x903d(%rip), %rdx      # 0x20f30
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x660d
testl %eax, %eax
jne 0x17f6c
pushq $0x2
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x665a
pushq $-0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5cee
leaq 0x900b(%rip), %rdx      # 0x20f30
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x6a5b
leaq 0x7c0e(%rip), %rsi      # 0x1fb47
movq %rbx, %rdi
callq 0x61d0
leaq 0x7e39(%rip), %rdx      # 0x1fd81
pushq $-0x2
popq %r15
movq %rbx, %rdi
movl %r15d, %esi
callq 0x68b9
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5cee
movq %rbx, %rdi
movl %r15d, %esi
callq 0x6ad0
pushq $0x1
popq %r15
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x1826a
movq %r14, %rdi
callq 0x63b4
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %edx
callq 0x5a91
movq %rbx, %rdi
movl 0x4(%rsp), %esi
callq 0x5cee
pushq $-0x3
popq %rsi
movq %rbx, %rdi
callq 0x698e
movq %r14, %rdi
movq %r13, %rsi
movl %r12d, %edx
movq 0x8(%rsp), %rcx
callq 0x72e0
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq