// File: /workspace/github_c_makefile_star2_O3/cogbee[P]vmir-latest/src/vmir_transform.c
// Function: liveness_update
static void
liveness_update(ir_function_t *f, int setwords, int ffv)
{
  uint32_t *new_in  = alloca(setwords * sizeof(uint32_t));
  uint32_t *new_out = alloca(setwords * sizeof(uint32_t));
  ir_bb_t *ib;
  ir_instr_t *ii, *k, *kn;
  int rounds = 0;

  SLIST_HEAD(, ir_instr) dead_instr;

  while(1) {

    int stable = 1;
    SLIST_INIT(&dead_instr);

    // Liveness analysis reach stable state a lot faster if iterating
    // backwards

    for(ib = TAILQ_LAST(&f->if_bbs, ir_bb_queue); ib != NULL;
        ib = TAILQ_PREV(ib, ir_bb_queue, ib_link)) {

      for(ii = TAILQ_LAST(&ib->ib_instrs, ir_instr_queue); ii != NULL;
          ii = TAILQ_PREV(ii, ir_instr_queue, ii_link)) {

        const uint32_t *o;

        if(ii->ii_num_succ == -1) {
          ir_instr_t *succ = TAILQ_NEXT(ii, ii_link);
          o = succ->ii_liveness + setwords * 2;
        } else {
          memset(new_out, 0, setwords * sizeof(uint32_t));

          for(int j = 0; j < ii->ii_num_succ; j++) {
            ir_bb_t *ib = ii->ii_succ[j];
            ir_instr_t *succ = TAILQ_FIRST(&ib->ib_instrs);
            assert(succ != NULL);
            const uint32_t *in = succ->ii_liveness + setwords * 2;
            bitset_or(new_out, in, setwords);
          }
          o = new_out;
        }

        memcpy(new_in, o, setwords * sizeof(uint32_t));
        if(ii->ii_ret.value < -1) {
          // Multiple return values
          for(int j = 0; j < -ii->ii_ret.value; j++) {
            bitclr(new_in, ii->ii_rets[j].value - ffv);
          }
        } else if(ii->ii_ret.value >= 0) {

          if(stable && !bitchk(o, ii->ii_ret.value - ffv) &&
             !instr_have_side_effects(ii)) {
            SLIST_INSERT_HEAD(&dead_instr, ii, ii_tmplink);
          }
          bitclr(new_in, ii->ii_ret.value - ffv);
        }

        uint32_t       *out = ii->ii_liveness;
        const uint32_t *gen = ii->ii_liveness + setwords;
        uint32_t       *in  = ii->ii_liveness + setwords * 2;

        bitset_or(new_in, gen, setwords);

        if(!memcmp(out, o,       setwords * sizeof(uint32_t)) &&
           !memcmp(in,  new_in,  setwords * sizeof(uint32_t))) {
          continue;
        }

        stable = 0;
        memcpy(out, o,       setwords * sizeof(uint32_t));
        memcpy(in,  new_in,  setwords * sizeof(uint32_t));
      }
    }
    rounds++;
    if(!stable)
      continue;

    k = SLIST_FIRST(&dead_instr);
    if(k != NULL) {
      for(; k != NULL; k = kn) {
        kn = SLIST_NEXT(k, ii_tmplink);
        instr_destroy(k);
      }
      continue;
    }
    return;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %ebx
movslq %esi, %rax
movq %rsp, %r12
movq %rax, -0x60(%rbp)
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
movq %rdi, -0x70(%rbp)
movq 0x50(%rdi), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
testq %rdx, %rdx
je 0x17c94
movq -0x60(%rbp), %rcx
leaq (,%rcx,4), %rax
movq %rax, -0x48(%rbp)
leal (%rcx,%rcx), %eax
cltq
movl %ecx, %r14d
movq $0x0, -0x38(%rbp)
movq %rax, -0x80(%rbp)
leaq (,%rax,4), %rcx
movl $0x1, -0x2c(%rbp)
movl %esi, -0x30(%rbp)
movq %rcx, -0x40(%rbp)
movl %ebx, -0x54(%rbp)
movq %rdx, -0x78(%rbp)
movq 0x18(%rdx), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x17c2c
movzwl 0x50(%rax), %r15d
cmpq $0xffff, %r15           # imm = 0xFFFF
movq %rax, -0x50(%rbp)
je 0x17ac5
movq %r13, %rdi
xorl %esi, %esi
movq -0x48(%rbp), %rdx
callq 0x3210
movq %r13, %rsi
testw %r15w, %r15w
jle 0x17acf
movq -0x50(%rbp), %rax
movq 0x40(%rax), %rax
xorl %ecx, %ecx
movl -0x30(%rbp), %r8d
movq -0x40(%rbp), %r9
movq (%rax,%rcx,8), %rdx
movq 0x10(%rdx), %rdx
testq %rdx, %rdx
je 0x17ca3
testl %r8d, %r8d
jle 0x17ab8
movq 0x38(%rdx), %rdx
addq %r9, %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
orl %edi, (%r13,%rsi,4)
incq %rsi
cmpq %rsi, %r14
jne 0x17aa8
incq %rcx
cmpq %r15, %rcx
jne 0x17a89
movq %r13, %rsi
jmp 0x17acf
movq (%rax), %rax
movq 0x38(%rax), %rsi
addq %rcx, %rsi
movq %r12, %rdi
movq %rsi, %r15
movq -0x48(%rbp), %rdx
callq 0x3360
movq -0x50(%rbp), %r9
movl 0x2c(%r9), %eax
cmpl $-0x2, %eax
jg 0x17b22
negl %eax
movq 0x18(%r9), %rdx
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
xorl %esi, %esi
movl -0x30(%rbp), %r8d
movl (%rdx,%rsi,8), %ecx
subl %ebx, %ecx
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
roll %cl, %edi
sarl $0x5, %ecx
movslq %ecx, %rcx
andl %edi, (%r12,%rcx,4)
incq %rsi
cmpq %rsi, %rax
jne 0x17b02
jmp 0x17b70
testl %eax, %eax
movl -0x30(%rbp), %r8d
js 0x17b70
subl %ebx, %eax
cmpl $0x0, -0x2c(%rbp)
movq %r15, %rsi
je 0x17b75
movl %eax, %ecx
sarl $0x5, %ecx
movslq %ecx, %r10
movl (%rsi,%r10,4), %edi
movl $0x1, %edx
movl %eax, %ecx
shll %cl, %edx
btl %eax, %edi
jb 0x17b84
movl 0x28(%r9), %eax
cmpl $0x1b, %eax
ja 0x17b84
movl $0xc3152dc, %ecx        # imm = 0xC3152DC
btl %eax, %ecx
jae 0x17b84
movq -0x38(%rbp), %rax
movq %rax, 0x48(%r9)
movq %r9, -0x38(%rbp)
jmp 0x17b84
movq %r15, %rsi
jmp 0x17b8a
movl $0x1, %edx
movl %eax, %ecx
shll %cl, %edx
sarl $0x5, %eax
movslq %eax, %r10
notl %edx
andl %edx, (%r12,%r10,4)
movq 0x38(%r9), %r15
testl %r8d, %r8d
jle 0x17bac
movq -0x60(%rbp), %rax
leaq (%r15,%rax,4), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
orl %edx, (%r12,%rcx,4)
incq %rcx
cmpq %rcx, %r14
jne 0x17b9d
movq -0x80(%rbp), %rax
leaq (%r15,%rax,4), %rax
movq %rax, -0x68(%rbp)
movq %r15, %rdi
movq -0x48(%rbp), %rbx
movq %rbx, %rdx
movq %rsi, -0x88(%rbp)
callq 0x33a0
testl %eax, %eax
jne 0x17be5
movq -0x68(%rbp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x33a0
testl %eax, %eax
je 0x17c0d
movq %r15, %rdi
movq -0x88(%rbp), %rsi
movq %rbx, %rdx
callq 0x3360
movq -0x68(%rbp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x3360
movl $0x0, -0x2c(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
testq %rax, %rax
movl -0x54(%rbp), %ebx
movq -0x40(%rbp), %rcx
jne 0x17a4e
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
testq %rdx, %rdx
jne 0x17a36
cmpl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rax
je 0x17c68
testq %rax, %rax
je 0x17c94
movq -0x38(%rbp), %rdi
movq 0x48(%rdi), %r15
callq 0xef31
movq %r15, %rdi
testq %r15, %r15
jne 0x17c57
movq -0x70(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
movl $0x0, %eax
movq %rax, -0x38(%rbp)
movl $0x1, -0x2c(%rbp)
testq %rdx, %rdx
movq -0x40(%rbp), %rcx
jne 0x17a36
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xee25(%rip), %rdi      # 0x26acf
leaq 0xe4ad(%rip), %rsi      # 0x2615e
leaq 0xee24(%rip), %rcx      # 0x26adc
movl $0x741, %edx            # imm = 0x741
callq 0x31e0