// File: /workspace/github_c_makefile_star2_O0/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
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movslq -0xc(%rbp), %rax
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0x18(%rbp)
movslq -0xc(%rbp), %rax
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0x20(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x1, -0x54(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x29b94
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x29b7a
movq -0x30(%rbp), %rax
movswl 0x50(%rax), %eax
cmpl $-0x1, %eax
jne 0x29909
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x38(%rax), %rax
movl -0xc(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
jmp 0x299c5
movq -0x20(%rbp), %rdi
movslq -0xc(%rbp), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x31f0
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x30(%rbp), %rcx
movswl 0x50(%rcx), %ecx
cmpl %ecx, %eax
jge 0x299bd
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
je 0x2995f
jmp 0x2997e
leaq 0x163f8(%rip), %rdi     # 0x3fd5e
leaq 0x15a80(%rip), %rsi     # 0x3f3ed
movl $0x741, %edx            # imm = 0x741
leaq 0x163f2(%rip), %rcx     # 0x3fd6b
callq 0x31c0
movq -0x80(%rbp), %rax
movq 0x38(%rax), %rax
movl -0xc(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
movq -0x88(%rbp), %rsi
movl -0xc(%rbp), %edx
callq 0x2a400
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x29923
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
movslq -0xc(%rbp), %rdx
shlq $0x2, %rdx
callq 0x3330
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x2c(%rax)
jge 0x29a32
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movq -0x30(%rbp), %rdx
xorl %ecx, %ecx
subl 0x2c(%rdx), %ecx
cmpl %ecx, %eax
jge 0x29a30
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x8c(%rbp), %rcx
movl (%rax,%rcx,8), %esi
subl -0x10(%rbp), %esi
callq 0x2a450
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x299ee
jmp 0x29a95
movq -0x30(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jl 0x29a93
cmpl $0x0, -0x54(%rbp)
je 0x29a80
movq -0x60(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x2c(%rax), %esi
subl -0x10(%rbp), %esi
callq 0x2a480
cmpl $0x0, %eax
jne 0x29a80
movq -0x30(%rbp), %rdi
callq 0x2a4d0
cmpl $0x0, %eax
jne 0x29a80
jmp 0x29a6a
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x29a80
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x2c(%rax), %esi
subl -0x10(%rbp), %esi
callq 0x2a450
jmp 0x29a95
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movl -0xc(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movl -0xc(%rbp), %edx
callq 0x2a400
movq -0x98(%rbp), %rdi
movq -0x60(%rbp), %rsi
movslq -0xc(%rbp), %rdx
shlq $0x2, %rdx
callq 0x3290
cmpl $0x0, %eax
jne 0x29b2b
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0xc(%rbp), %rdx
shlq $0x2, %rdx
callq 0x3290
cmpl $0x0, %eax
jne 0x29b2b
jmp 0x29b62
movl $0x0, -0x54(%rbp)
movq -0x98(%rbp), %rdi
movq -0x60(%rbp), %rsi
movslq -0xc(%rbp), %rdx
shlq $0x2, %rdx
callq 0x3330
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0xc(%rbp), %rdx
shlq $0x2, %rdx
callq 0x3330
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x298c6
jmp 0x29b7c
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x298a8
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x54(%rbp)
jne 0x29ba8
jmp 0x29886
movq -0x50(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x29be4
jmp 0x29bb9
cmpq $0x0, -0x38(%rbp)
je 0x29bdf
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0x1cad0
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x29bb9
jmp 0x29886
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)