// File: /workspace/github_c_makefile_star2_O1/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
movq %rdi, -0x68(%rbp)
movl %esi, -0x30(%rbp)
movslq %esi, %rcx
leaq (,%rcx,4), %rax
movq %rax, -0x48(%rbp)
movq %rsp, %r13
leaq 0xf(,%rcx,4), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
leal (%rcx,%rcx), %eax
cltq
movq %rcx, -0x78(%rbp)
movl %ecx, %r14d
movq %rax, -0x80(%rbp)
leaq (,%rax,4), %rax
movq %rax, -0x40(%rbp)
movl %edx, -0x54(%rbp)
movq -0x68(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x17cff
movl $0x1, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x40(%rbp), %rcx
movq %rax, -0x70(%rbp)
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x17cda
movzwl 0x50(%rax), %r12d
cmpq $0xffff, %r12           # imm = 0xFFFF
movq %rax, -0x50(%rbp)
je 0x17b78
movq %r15, %rdi
xorl %esi, %esi
movq -0x48(%rbp), %rdx
callq 0x3210
movq %r15, %rax
testw %r12w, %r12w
jle 0x17b82
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 0x17d35
testl %r8d, %r8d
jle 0x17b6b
movq 0x38(%rdx), %rdx
addq %r9, %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
orl %edi, (%r15,%rsi,4)
incq %rsi
cmpq %rsi, %r14
jne 0x17b5c
incq %rcx
cmpq %r12, %rcx
jne 0x17b3d
movq %r15, %rax
jmp 0x17b82
movq (%rax), %rax
movq 0x38(%rax), %rax
addq %rcx, %rax
movq %r13, %rdi
movq %rax, %r12
movq %rax, %rsi
movq -0x48(%rbp), %rdx
callq 0x3360
movq -0x50(%rbp), %r9
movl 0x2c(%r9), %eax
cmpl $-0x2, %eax
jg 0x17bd9
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, (%r13,%rcx,4)
incq %rsi
cmpq %rsi, %rax
jne 0x17bb8
jmp 0x17c34
testl %eax, %eax
movl -0x30(%rbp), %r8d
js 0x17c34
cmpl $0x0, -0x2c(%rbp)
movq %r12, %rsi
je 0x17c1d
movl %eax, %ecx
subl %ebx, %ecx
movl %ecx, %edx
sarl $0x5, %edx
movslq %edx, %rdx
movl (%rsi,%rdx,4), %edx
btl %ecx, %edx
jb 0x17c1d
movl 0x28(%r9), %ecx
cmpl $0x1b, %ecx
ja 0x17c1d
movl $0xc3152dc, %edx        # imm = 0xC3152DC
btl %ecx, %edx
jae 0x17c1d
movq -0x38(%rbp), %rcx
movq %rcx, 0x48(%r9)
movq %r9, -0x38(%rbp)
subl %ebx, %eax
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
movl %eax, %ecx
roll %cl, %edx
sarl $0x5, %eax
cltq
andl %edx, (%r13,%rax,4)
jmp 0x17c37
movq %r12, %rsi
movq 0x38(%r9), %r12
testl %r8d, %r8d
jle 0x17c5a
movq -0x78(%rbp), %rax
leaq (%r12,%rax,4), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
orl %edx, (%r13,%rcx,4)
incq %rcx
cmpq %rcx, %r14
jne 0x17c4a
movq -0x80(%rbp), %rax
leaq (%r12,%rax,4), %rax
movq %rax, -0x60(%rbp)
movq %r12, %rdi
movq %rsi, -0x88(%rbp)
movq -0x48(%rbp), %rbx
movq %rbx, %rdx
callq 0x33a0
testl %eax, %eax
jne 0x17c93
movq -0x60(%rbp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x33a0
testl %eax, %eax
je 0x17cbb
movq %r12, %rdi
movq -0x88(%rbp), %rsi
movq %rbx, %rdx
callq 0x3360
movq -0x60(%rbp), %rdi
movq %r13, %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 0x17b02
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
testq %rax, %rax
jne 0x17aea
cmpl $0x0, -0x2c(%rbp)
sete %al
movq -0x38(%rbp), %rdi
jmp 0x17d03
xorl %eax, %eax
xorl %edi, %edi
testb %al, %al
jne 0x17abf
testq %rdi, %rdi
je 0x17d26
movq 0x48(%rdi), %r12
callq 0xef89
movq %r12, %rdi
testq %r12, %r12
jne 0x17d10
jmp 0x17abf
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xed49(%rip), %rdi      # 0x26a85
leaq 0xe3d1(%rip), %rsi      # 0x26114
leaq 0xed48(%rip), %rcx      # 0x26a92
movl $0x741, %edx            # imm = 0x741
callq 0x31e0