// File: /workspace/github_cpp_makefile_star2_O2/Ziang95[P]Tomasulo_simulator/clock.cpp
// Function: clk_tick::clk_automat(int)
bool clk_tick::clk_automat(int freq)
{
    if (freq > 500)
    {
        err_log("Frequency should be no greater than 500");
        return false;
    }
    while (true)
    {
        while (!all_unit_ready_for_one())
        {
            string outp = "";
            for (auto a : clk_wait_list)
                outp += to_string(*a) + ",";
            msg_log("In waiting for vdd = 1, " + outp, 4);
            #ifdef _WIN32
            Sleep(500/freq);
            #else
            usleep(500/freq);
            #endif
        }
        pthread_mutex_lock(&boradcast_lock);
        vdd = 1;
        prog_cyc++;
        if (prog_cyc == 1)
            msg_log("Program Started\n", 0);
        pthread_cond_broadcast(&vdd_1);
        pthread_mutex_unlock(&boradcast_lock);
        while (!all_unit_ready_for_zero())
        {
            string outp = "";
            for (auto a : clk_wait_list)
                outp += to_string(*a) + ",";
            msg_log("In waiting for vdd = 0, " + outp, 4);
            #ifdef _WIN32
            Sleep(500/freq);
            #else
            usleep(500/freq);
            #endif
        }
        pthread_mutex_lock(&boradcast_lock);
        vdd = 0;
        pthread_cond_broadcast(&vdd_0);
        pthread_mutex_unlock(&boradcast_lock);
        if (instr_ended && mem_ended)
            return true;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %esi, -0x2c(%rbp)
cmpl $0x1f4, %esi            # imm = 0x1F4
jg 0x827d
leaq 0x10(%rdi), %rax
movq %rax, -0x68(%rbp)
movq %rdi, -0x38(%rbp)
leaq 0x40(%rdi), %rax
movq %rax, -0x60(%rbp)
leaq -0xe8(%rbp), %r12
leaq -0xa8(%rbp), %r14
leaq -0xc8(%rbp), %r13
callq 0x7e56
testl %eax, %eax
je 0x81d1
leaq 0xe256(%rip), %rbx      # 0x162c0
movq %rbx, %rdi
callq 0x3390
movq -0x38(%rbp), %rdx
movb $0x1, (%rdx)
movl 0x4(%rdx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%rdx)
testl %eax, %eax
jne 0x80b2
leaq -0x128(%rbp), %r15
movq %r15, %rdi
leaq 0x726d(%rip), %rsi      # 0xf304
leaq -0x58(%rbp), %rdx
callq 0x3100
movq %r15, %rdi
xorl %esi, %esi
callq 0x8343
movq %r15, %rdi
callq 0x3140
movq -0x68(%rbp), %rdi
callq 0x30e0
movq %rbx, %rdi
callq 0x3210
callq 0x7f7a
testl %eax, %eax
jne 0x8191
leaq -0x58(%rbp), %rdi
leaq 0x78bf(%rip), %rsi      # 0xf99a
movq %r12, %rdx
callq 0x3100
leaq 0xec2e(%rip), %rax      # 0x16d18
movq (%rax), %rbx
movq 0x8(%rax), %r14
cmpq %r14, %rbx
je 0x8137
movq (%rbx), %rax
movl (%rax), %esi
movq %r13, %rdi
callq 0x5ab8
movq %r12, %rdi
movq %r13, %rsi
leaq 0x71d9(%rip), %rdx      # 0xf2e9
callq 0x5bc8
leaq -0x58(%rbp), %rdi
movq %r12, %rsi
callq 0x34b0
movq %r12, %rdi
callq 0x3140
movq %r13, %rdi
callq 0x3140
addq $0x8, %rbx
jmp 0x80f1
leaq -0x108(%rbp), %r15
movq %r15, %rdi
leaq 0x71cd(%rip), %rsi      # 0xf315
leaq -0x58(%rbp), %rdx
callq 0x7331
leaq -0xa8(%rbp), %r14
leaq 0xe161(%rip), %rbx      # 0x162c0
movq %r15, %rdi
pushq $0x4
popq %rsi
callq 0x8343
movq %r15, %rdi
callq 0x3140
movl $0x1f4, %eax            # imm = 0x1F4
xorl %edx, %edx
idivl -0x2c(%rbp)
movl %eax, %edi
callq 0x3360
leaq -0x58(%rbp), %rdi
callq 0x3140
jmp 0x80c3
movq %rbx, %rdi
callq 0x3390
movq %rbx, %r15
movq -0x38(%rbp), %rbx
movb $0x0, (%rbx)
movq -0x60(%rbp), %rdi
callq 0x30e0
movq %r15, %rdi
callq 0x3210
cmpb $0x1, 0x2(%rbx)
jne 0x8056
movq -0x38(%rbp), %rax
cmpb $0x1, 0x3(%rax)
jne 0x8056
jmp 0x82ac
leaq -0x58(%rbp), %rdi
leaq 0x77be(%rip), %rsi      # 0xf99a
movq %r12, %rdx
callq 0x3100
leaq 0xeb2d(%rip), %rax      # 0x16d18
movq (%rax), %rbx
movq 0x8(%rax), %r15
cmpq %r15, %rbx
je 0x8238
movq (%rbx), %rax
movl (%rax), %esi
movq %r13, %rdi
callq 0x5ab8
movq %r12, %rdi
movq %r13, %rsi
leaq 0x70d8(%rip), %rdx      # 0xf2e9
callq 0x5bc8
leaq -0x58(%rbp), %rdi
movq %r12, %rsi
callq 0x34b0
movq %r12, %rdi
callq 0x3140
movq %r13, %rdi
callq 0x3140
addq $0x8, %rbx
jmp 0x81f2
movq %r14, %rdi
leaq 0x70a9(%rip), %rsi      # 0xf2eb
leaq -0x58(%rbp), %rdx
callq 0x7331
movq %r14, %rdi
pushq $0x4
popq %rsi
callq 0x8343
movq %r14, %rdi
callq 0x3140
movl $0x1f4, %eax            # imm = 0x1F4
xorl %edx, %edx
idivl -0x2c(%rbp)
movl %eax, %edi
callq 0x3360
leaq -0x58(%rbp), %rdi
callq 0x3140
jmp 0x8056
leaq 0x703d(%rip), %rsi      # 0xf2c1
leaq -0x88(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x3100
leaq -0x88(%rbp), %rdi
callq 0x7ee9
leaq -0x88(%rbp), %rdi
callq 0x3140
cmpl $0x1f5, -0x2c(%rbp)     # imm = 0x1F5
setl %al
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
jmp 0x8336
jmp 0x8306
jmp 0x8306
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
jmp 0x8336
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
jmp 0x832d
jmp 0x8306
jmp 0x830d
jmp 0x830d
jmp 0x8312
jmp 0x8317
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
jmp 0x832d
movq %rax, %rbx
jmp 0x833b
jmp 0x830d
movq %rax, %rbx
jmp 0x8332
movq %rax, %rbx
jmp 0x8326
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x3140
leaq -0xc8(%rbp), %rdi
callq 0x3140
leaq -0x58(%rbp), %rdi
callq 0x3140
movq %rbx, %rdi
callq 0x3440