// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movq %rdi, %rbx
leaq 0x4(%rsp), %r15
movq %r15, %rsi
callq 0x19a2b
movq %rax, %r14
movl (%r15), %r15d
leal 0x1(%r15), %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5f7f
testl %eax, %eax
movl %ebp, (%rsp)
jle 0x1974c
leal 0x2(%r15), %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x14535
movq %rax, %r12
movq %rbx, %rdi
movl %ebp, %esi
movl $0x6, %edx
callq 0x1456f
addl $0x3, %r15d
movq %rbx, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x146c5
movq %rax, %rbp
movq %r12, %rdi
movl $0x63, %esi
callq 0x5170
xorl %r13d, %r13d
testq %rax, %rax
setne %r13b
movq %r12, %rdi
movl $0x72, %esi
callq 0x5170
leal 0x2(%r13), %r15d
testq %rax, %rax
cmovel %r13d, %r15d
movq %r12, %rdi
movl $0x6c, %esi
callq 0x5170
leal 0x4(%r15), %ecx
testq %rax, %rax
cmovel %r15d, %ecx
leal 0x8(%rcx), %r12d
testl %ebp, %ebp
cmovlel %ecx, %r12d
leaq 0x327(%rip), %r13       # 0x19a71
jmp 0x1975e
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5d51
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r12d, %r12d
leaq 0x96ab(%rip), %rdx      # 0x22e10
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x6889
testl %eax, %eax
jne 0x197e3
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x68d6
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5f5b
leaq 0x9677(%rip), %rdx      # 0x22e10
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x6cd9
leaq 0x8303(%rip), %rsi      # 0x21ab0
movq %rbx, %rdi
callq 0x645b
leaq 0x852d(%rip), %rdx      # 0x21ce9
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6b3f
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5f5b
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6d47
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x19afa
movq %r14, %rdi
callq 0x663c
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x5cb2
movq %rbx, %rdi
movl (%rsp), %esi
callq 0x5f5b
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x6c1a
movq %r14, %rdi
movq %r13, %rsi
movl %r12d, %edx
movl %ebp, %ecx
callq 0x7564
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq