// File: /workspace/github_c_makefile_star2_O3/bhk[P]tooltree/lua/../opensource/lua-5.2.3/src/lvm.c
// Function: luaV_settable
void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
  int loop;
  for (loop = 0; loop < MAXTAGLOOP; loop++) {
    const TValue *tm;
    if (ttistable(t)) {  /* `t' is a table? */
      Table *h = hvalue(t);
      TValue *oldval = cast(TValue *, luaH_get(h, key));
      /* if previous value is not nil, there must be a previous entry
         in the table; moreover, a metamethod has no relevance */
      if (!ttisnil(oldval) ||
         /* previous value is nil; must check the metamethod */
         ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL &&
         /* no metamethod; is there a previous entry in the table? */
         (oldval != luaO_nilobject ||
         /* no previous entry; must create one. (The next test is
            always true; we only need the assignment.) */
         (oldval = luaH_newkey(L, h, key), 1)))) {
        /* no metamethod and (now) there is an entry with given key */
        setobj2t(L, oldval, val);  /* assign new value to that entry */
        invalidateTMcache(h);
        luaC_barrierback(L, obj2gco(h), val);
        return;
      }
      /* else will try the metamethod */
    }
    else  /* not a table; check metamethod */
      if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
        luaG_typeerror(L, t, "index");
    /* there is a metamethod */
    if (ttisfunction(tm)) {
      callTM(L, tm, t, key, val, 0);
      return;
    }
    t = tm;  /* else repeat with 'tm' */
  }
  luaG_runerror(L, "loop in settable");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, (%rsp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movl 0x8(%rsi), %ecx
movl $0x64, %r14d
cmpl $0x45, %ecx
jne 0x18d86
movq (%r12), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x175ea
movq %rax, %rbp
cmpl $0x0, 0x8(%rax)
jne 0x18de1
movq 0x10(%r13), %rdi
testq %rdi, %rdi
je 0x18dc4
testb $0x2, 0xa(%rdi)
jne 0x18dc4
movq 0x18(%rbx), %rax
movq 0x128(%rax), %rdx
movl $0x1, %esi
callq 0x181f9
testq %rax, %rax
je 0x18dc4
movl 0x8(%rax), %ecx
jmp 0x18da1
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x18224
movl 0x8(%rax), %ecx
testl %ecx, %ecx
je 0x18e59
movl %ecx, %edx
andl $0xf, %edx
cmpl $0x6, %edx
je 0x18e1a
movq %rax, %r12
decl %r14d
jne 0x18d37
leaq 0x9127(%rip), %rsi      # 0x21ee1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xb027
leaq 0x8205(%rip), %rax      # 0x20fd0
cmpq %rax, %rbp
jne 0x18de1
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x1713c
movq %rax, %rbp
movq (%rsp), %rcx
movq (%rcx), %rax
movq %rax, (%rbp)
movl 0x8(%rcx), %eax
movl %eax, 0x8(%rbp)
movb $0x0, 0xa(%r13)
testb $0x40, %al
je 0x18e0b
movq (%rcx), %rax
testb $0x3, 0x9(%rax)
je 0x18e0b
testb $0x4, 0x9(%r13)
jne 0x18e40
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %rax, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq (%rsp), %r8
xorl %r9d, %r9d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x18c50
movq %rbx, %rdi
movq %r13, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xca79
leaq 0x8b18(%rip), %rdx      # 0x21978
movq %rbx, %rdi
movq %r12, %rsi
callq 0xac98