// File: /workspace/github_c_makefile_star2_O0/tylerneylon[P]APIsWithLua/lua/ldebug.c
// Function: findsetreg
static int findsetreg (Proto *p, int lastpc, int reg) {
  int pc;
  int setreg = -1;  /* keep last instruction that changed 'reg' */
  int jmptarget = 0;  /* any code before this address is conditional */
  for (pc = 0; pc < lastpc; pc++) {
    Instruction i = p->code[pc];
    OpCode op = GET_OPCODE(i);
    int a = GETARG_A(i);
    switch (op) {
      case OP_LOADNIL: {
        int b = GETARG_B(i);
        if (a <= reg && reg <= a + b)  /* set registers from 'a' to 'a+b' */
          setreg = filterpc(pc, jmptarget);
        break;
      }
      case OP_TFORCALL: {
        if (reg >= a + 2)  /* affect all regs above its base */
          setreg = filterpc(pc, jmptarget);
        break;
      }
      case OP_CALL:
      case OP_TAILCALL: {
        if (reg >= a)  /* affect all registers above base */
          setreg = filterpc(pc, jmptarget);
        break;
      }
      case OP_JMP: {
        int b = GETARG_sBx(i);
        int dest = pc + 1 + b;
        /* jump is forward and do not skip 'lastpc'? */
        if (pc < dest && dest <= lastpc) {
          if (dest > jmptarget)
            jmptarget = dest;  /* update 'jmptarget' */
        }
        break;
      }
      default:
        if (testAMode(op) && reg == a)  /* any instruction that set A */
          setreg = filterpc(pc, jmptarget);
        break;
    }
  }
  return setreg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl $0xffffffff, -0x18(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xa7e2
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
shrl $0x6, %eax
movzbl %al, %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $-0x4, %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x25, %eax
ja 0xa7a2
movq -0x40(%rbp), %rax
leaq 0x29cfe(%rip), %rcx     # 0x343e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x20(%rbp), %eax
shrl $0x17, %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x10(%rbp), %eax
jg 0xa724
movl -0x10(%rbp), %eax
movl -0x28(%rbp), %ecx
addl -0x2c(%rbp), %ecx
cmpl %ecx, %eax
jg 0xa724
movl -0x14(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0xa8f0
movl %eax, -0x18(%rbp)
jmp 0xa7d2
movl -0x10(%rbp), %eax
movl -0x28(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jl 0xa744
movl -0x14(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0xa8f0
movl %eax, -0x18(%rbp)
jmp 0xa7d2
movl -0x10(%rbp), %eax
cmpl -0x28(%rbp), %eax
jl 0xa75f
movl -0x14(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0xa8f0
movl %eax, -0x18(%rbp)
jmp 0xa7d2
movl -0x20(%rbp), %eax
shrl $0xe, %eax
andl $0x3ffff, %eax          # imm = 0x3FFFF
subl $0x1ffff, %eax          # imm = 0x1FFFF
movl %eax, -0x30(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
addl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xa7a0
movl -0x34(%rbp), %eax
cmpl -0xc(%rbp), %eax
jg 0xa7a0
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jle 0xa79e
movl -0x34(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0xa7a0
jmp 0xa7d2
movl -0x24(%rbp), %eax
movl %eax, %ecx
leaq 0x2a592(%rip), %rax     # 0x34d40
movzbl (%rax,%rcx), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0xa7d0
movl -0x10(%rbp), %eax
cmpl -0x28(%rbp), %eax
jne 0xa7d0
movl -0x14(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0xa8f0
movl %eax, -0x18(%rbp)
jmp 0xa7d2
jmp 0xa7d4
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xa697
movl -0x18(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)