// File: Ziang95[P]Tomasulo_simulator/branch.cpp
// Function: branchCtrl::branch_automat()
void branchCtrl::branch_automat()
{
    next_vdd = 0;
    while (true)
    {
        at_rising_edge(next_vdd);
        at_falling_edge(next_vdd);
        if (ROB_i>-1)
        {
            pthread_mutex_lock(&squash_mutex);
            while (!instr_Q->squash)
                pthread_cond_wait(&squash_cond, &squash_mutex);
            pthread_mutex_unlock(&squash_mutex);
            ROBEntry *R = CPU_ROB->get_entry(ROB_i);
            RAT = R->bkupRAT;
            at_falling_edge(next_vdd);
            for (auto fu : iAdder)
                fu->squash(ROB_i);
            for (auto fu : fAdder)
                fu->squash(ROB_i);
            for (auto fu : fMtplr)
                fu->squash(ROB_i);
            for (auto fu : lsUnit)
                fu->squash(ROB_i);
            nopBub->squash(ROB_i);
            main_mem.squash(ROB_i);
            fCDB.squash(ROB_i);
            R->finished = true;
            CPU_ROB->squash(ROB_i);
            at_rising_edge(next_vdd);
            instr_Q->move_ptr(target);
            msg_log("squash finished", 3);
            at_falling_edge(next_vdd);
            at_rising_edge(next_vdd);
            instr_Q->squash = false;
            ROB_i = -1;
            at_falling_edge(next_vdd);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl $0x0, 0x10(%rax)
movq -0xd0(%rbp), %rdi
addq $0x10, %rdi
callq 0x12130
movq -0xd0(%rbp), %rdi
addq $0x10, %rdi
callq 0x121a0
movq -0xd0(%rbp), %rax
cmpl $-0x1, (%rax)
jle 0x10a01
leaq 0x1edc0(%rip), %rdi     # 0x2f418
callq 0x4510
leaq 0x1edf4(%rip), %rax     # 0x2f458
movq (%rax), %rax
movb 0x4(%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x10672
jmp 0x10687
leaq 0x1ed6f(%rip), %rdi     # 0x2f3e8
leaq 0x1ed98(%rip), %rsi     # 0x2f418
callq 0x4530
jmp 0x1065d
leaq 0x1ed8a(%rip), %rdi     # 0x2f418
callq 0x42c0
movq -0xd0(%rbp), %rax
leaq 0x1edbf(%rip), %rcx     # 0x2f460
movq (%rcx), %rdi
movl (%rax), %esi
callq 0xe4d0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rsi
addq $0x68, %rsi
leaq 0x1f69a(%rip), %rdi     # 0x2fd58
callq 0x10af0
movq -0xd0(%rbp), %rdi
addq $0x10, %rdi
callq 0x121a0
leaq 0x1edd6(%rip), %rax     # 0x2f4b0
movq %rax, -0x18(%rbp)
leaq 0x1edcb(%rip), %rdi     # 0x2f4b0
callq 0x88d0
movq %rax, -0x20(%rbp)
leaq 0x1edbb(%rip), %rdi     # 0x2f4b0
callq 0x8900
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8930
testb $0x1, %al
jne 0x10711
jmp 0x10741
leaq -0x20(%rbp), %rdi
callq 0x8970
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movl (%rax), %esi
callq 0x5800
leaq -0x20(%rbp), %rdi
callq 0x8990
jmp 0x106fe
leaq 0x1ed80(%rip), %rax     # 0x2f4c8
movq %rax, -0x38(%rbp)
leaq 0x1ed75(%rip), %rdi     # 0x2f4c8
callq 0x89d0
movq %rax, -0x40(%rbp)
leaq 0x1ed65(%rip), %rdi     # 0x2f4c8
callq 0x8a00
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x8a30
testb $0x1, %al
jne 0x1077f
jmp 0x107af
leaq -0x40(%rbp), %rdi
callq 0x8a70
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movl (%rax), %esi
callq 0x5800
leaq -0x40(%rbp), %rdi
callq 0x8a90
jmp 0x1076c
leaq 0x1ed2a(%rip), %rax     # 0x2f4e0
movq %rax, -0x58(%rbp)
leaq 0x1ed1f(%rip), %rdi     # 0x2f4e0
callq 0x8ad0
movq %rax, -0x60(%rbp)
leaq 0x1ed0f(%rip), %rdi     # 0x2f4e0
callq 0x8b00
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x8b30
testb $0x1, %al
jne 0x107ed
jmp 0x1081d
leaq -0x60(%rbp), %rdi
callq 0x8b70
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movl (%rax), %esi
callq 0x5800
leaq -0x60(%rbp), %rdi
callq 0x8b90
jmp 0x107da
leaq 0x1ecd4(%rip), %rax     # 0x2f4f8
movq %rax, -0x78(%rbp)
leaq 0x1ecc9(%rip), %rdi     # 0x2f4f8
callq 0x8bd0
movq %rax, -0x80(%rbp)
leaq 0x1ecb9(%rip), %rdi     # 0x2f4f8
callq 0x8c00
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x8c30
testb $0x1, %al
jne 0x10861
jmp 0x10897
leaq -0x80(%rbp), %rdi
callq 0x8c70
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, -0x90(%rbp)
movq -0x90(%rbp), %rdi
movl (%rax), %esi
callq 0x5800
leaq -0x80(%rbp), %rdi
callq 0x8c90
jmp 0x1084b
movq -0xd0(%rbp), %rax
leaq 0x1ec03(%rip), %rcx     # 0x2f4a8
movq (%rcx), %rdi
movl (%rax), %esi
callq 0x78e0
movq -0xd0(%rbp), %rax
movl (%rax), %esi
leaq 0x1f561(%rip), %rdi     # 0x2fe20
callq 0x1b310
movq -0xd0(%rbp), %rax
movl (%rax), %esi
leaq 0x1ec3c(%rip), %rdi     # 0x2f510
callq 0x5080
movq -0xd0(%rbp), %rax
movq -0x10(%rbp), %rcx
movb $0x1, (%rcx)
leaq 0x1eb72(%rip), %rcx     # 0x2f460
movq (%rcx), %rdi
movl (%rax), %esi
callq 0xe720
movq -0xd0(%rbp), %rdi
addq $0x10, %rdi
callq 0x12130
movq -0xd0(%rbp), %rax
leaq 0x1eb42(%rip), %rcx     # 0x2f458
movq (%rcx), %rdi
movl 0x4(%rax), %esi
callq 0x17820
leaq -0xb1(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x4600
movq -0xd8(%rbp), %rdx
leaq 0x11950(%rip), %rsi     # 0x22292
leaq -0xb0(%rbp), %rdi
callq 0x44c0
jmp 0x10950
leaq -0xb0(%rbp), %rdi
movl $0x3, %esi
callq 0x12060
jmp 0x10963
leaq -0xb0(%rbp), %rdi
callq 0x4240
leaq -0xb1(%rbp), %rdi
callq 0x43d0
movq -0xd0(%rbp), %rdi
addq $0x10, %rdi
callq 0x121a0
movq -0xd0(%rbp), %rdi
addq $0x10, %rdi
callq 0x12130
movq -0xd0(%rbp), %rdi
leaq 0x1eaaf(%rip), %rax     # 0x2f458
movq (%rax), %rax
movb $0x0, 0x4(%rax)
movl $0xffffffff, (%rdi)     # imm = 0xFFFFFFFF
addq $0x10, %rdi
callq 0x121a0
jmp 0x10a01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x109f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4240
leaq -0xb1(%rbp), %rdi
callq 0x43d0
jmp 0x10a06
jmp 0x10621
movq -0xc0(%rbp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)