// File: /workspace/github_c_makefile_star2_O2/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, -0x54(%rbp)
movl %esi, -0x3c(%rbp)
movslq %esi, %rcx
leaq (,%rcx,4), %rax
movq %rax, -0x50(%rbp)
movq %rsp, %r12
leaq 0xf(,%rcx,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
addq $0x50, %rdi
movq %rcx, -0x80(%rbp)
leal (%rcx,%rcx), %eax
cltq
pushq $0x1
popq %rcx
movq %rax, -0x78(%rbp)
leaq (,%rax,4), %rbx
movl %ecx, -0x2c(%rbp)
xorl %eax, %eax
movq %rdi, -0x60(%rbp)
movq %rdi, %rdx
movq %r12, -0x38(%rbp)
movq %rax, %rdi
movq (%rdx), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x14f66
movq %rdi, -0x48(%rbp)
movq %rax, -0x70(%rbp)
leaq 0x18(%rax), %r13
movq (%r13), %rax
movq 0x8(%rax), %rax
movq (%rax), %r13
testq %r13, %r13
je 0x14f55
movzwl 0x50(%r13), %r14d
cmpw $-0x1, %r14w
je 0x14e1f
movq %r15, %rdi
xorl %esi, %esi
movq -0x50(%rbp), %rdx
callq 0x3210
testw %r14w, %r14w
movl $0x0, %eax
cmovlel %eax, %r14d
movzwl %r14w, %r12d
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x14e16
movq 0x40(%r13), %rax
movq (%rax,%r14,8), %rax
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x14fb7
movq 0x38(%rax), %rsi
addq %rbx, %rsi
movq %r15, %rdi
movl -0x3c(%rbp), %edx
callq 0x1501f
incq %r14
jmp 0x14de5
movq %r15, %r14
movq -0x38(%rbp), %r12
jmp 0x14e2a
movq (%r13), %rax
movq 0x38(%rax), %r14
addq %rbx, %r14
movq %r12, %rdi
movq %r14, %rsi
movq -0x50(%rbp), %rdx
callq 0x3360
movl 0x2c(%r13), %eax
cmpl $-0x2, %eax
movl -0x54(%rbp), %r8d
pushq $-0x2
popq %r9
jg 0x14e71
negl %eax
movq 0x18(%r13), %rdx
xorl %esi, %esi
cmpq %rsi, %rax
je 0x14eca
movl (%rdx,%rsi,8), %ecx
subl %r8d, %ecx
movl %r9d, %edi
roll %cl, %edi
sarl $0x5, %ecx
movslq %ecx, %rcx
andl %edi, (%r12,%rcx,4)
incq %rsi
jmp 0x14e52
testl %eax, %eax
js 0x14eca
subl %r8d, %eax
cmpl $0x0, -0x2c(%rbp)
je 0x14eb7
movl %eax, %ecx
sarl $0x5, %ecx
movslq %ecx, %rsi
movl (%r14,%rsi,4), %edi
pushq $0x1
popq %rdx
movl %eax, %ecx
shll %cl, %edx
btl %eax, %edi
jb 0x14ec4
movl 0x28(%r13), %eax
cmpl $0x1b, %eax
ja 0x14ec4
movl $0xc3152dc, %ecx        # imm = 0xC3152DC
btl %eax, %ecx
jae 0x14ec4
movq -0x48(%rbp), %rax
movq %rax, 0x48(%r13)
movq %r13, -0x48(%rbp)
jmp 0x14ec4
pushq $0x1
popq %rdx
movl %eax, %ecx
shll %cl, %edx
sarl $0x5, %eax
movslq %eax, %rsi
notl %edx
andl %edx, (%r12,%rsi,4)
movq 0x38(%r13), %r12
movq -0x80(%rbp), %rax
leaq (%r12,%rax,4), %rsi
movq -0x78(%rbp), %rax
leaq (%r12,%rax,4), %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %edx
callq 0x1501f
movq %r12, %rdi
movq %r14, -0x88(%rbp)
movq %r14, %rsi
movq -0x50(%rbp), %r14
movq %r14, %rdx
callq 0x33a0
testl %eax, %eax
jne 0x14f1f
movq -0x68(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r14, %rdx
callq 0x33a0
testl %eax, %eax
je 0x14f48
movq %r12, %rdi
movq -0x88(%rbp), %rsi
movq %r14, %rdx
callq 0x3360
movq -0x68(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r14, %rdx
callq 0x3360
movl $0x0, -0x2c(%rbp)
addq $0x8, %r13
movq -0x38(%rbp), %r12
jmp 0x14da3
movq -0x70(%rbp), %rdx
addq $0x8, %rdx
movq -0x48(%rbp), %rax
jmp 0x14d81
movl $0x0, %eax
movq -0x60(%rbp), %rdx
cmpl $0x0, -0x2c(%rbp)
pushq $0x1
popq %rcx
movl %ecx, -0x2c(%rbp)
je 0x14d81
testq %rdi, %rdi
je 0x14fa8
testq %rdi, %rdi
je 0x14f97
movq 0x48(%rdi), %r14
callq 0xe058
movq %r14, %rdi
jmp 0x14f84
pushq $0x1
popq %rax
movl %eax, -0x2c(%rbp)
xorl %eax, %eax
movq -0x60(%rbp), %rdx
jmp 0x14d81
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xcc7c(%rip), %rdi      # 0x21c3a
leaq 0xc304(%rip), %rsi      # 0x212c9
leaq 0xcc7b(%rip), %rcx      # 0x21c47
movl $0x741, %edx            # imm = 0x741
callq 0x31e0