// File: /workspace/github_cpp_makefile_star2_O1/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 0x9df4
leaq -0x40(%rbp), %r14
leaq -0xc0(%rbp), %r15
leaq 0x10(%rdi), %rax
movq %rax, -0xb0(%rbp)
leaq 0x40(%rdi), %rax
movq %rax, -0xa8(%rbp)
movl $0xd1b71759, %r12d      # imm = 0xD1B71759
movq %rdi, -0xa0(%rbp)
callq 0x96a6
testl %eax, %eax
jne 0x9b4e
movq %r14, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
leaq 0xc019(%rip), %rdx      # 0x1599a
movq %rdx, %rsi
callq 0x7202
leaq 0x12380(%rip), %rax     # 0x1bd10
movq (%rax), %r15
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
cmpq %rax, %r15
je 0x9adb
movq (%r15), %rax
movl (%rax), %ebx
movl %ebx, %r13d
negl %r13d
cmovsl %ebx, %r13d
movl $0x1, %r14d
cmpl $0xa, %r13d
jb 0x9a01
movl $0x4, %r14d
movl %r13d, %eax
cmpl $0x63, %eax
jbe 0x99f8
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x99fe
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x9a01
movl %eax, %ecx
imulq %r12, %rcx
shrq $0x2d, %rcx
addl $0x4, %r14d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x99c8
addl $-0x3, %r14d
jmp 0x9a01
addl $-0x2, %r14d
jmp 0x9a01
decl %r14d
shrl $0x1f, %ebx
leal (%r14,%rbx), %esi
leaq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x98(%rbp), %r12
movq %r12, %rdi
movl $0x2d, %edx
callq 0x32b0
addq -0x98(%rbp), %rbx
movq %rbx, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x703e
movq %r12, %rdi
leaq 0xb8a0(%rip), %rsi      # 0x152e9
callq 0x34a0
leaq -0x60(%rbp), %r14
movq %r14, -0x70(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9a72
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
jmp 0x9a79
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movl $0xd1b71759, %r12d      # imm = 0xD1B71759
movq 0x8(%rax), %rdx
movq %rdx, -0x68(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x30d0
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x9ab5
callq 0x3230
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x9acd
callq 0x3230
addq $0x8, %r15
cmpq -0x78(%rbp), %r15
jne 0x99a4
leaq -0x110(%rbp), %rdi
leaq 0xb802(%rip), %rsi      # 0x152eb
leaq -0x50(%rbp), %rdx
leaq -0x40(%rbp), %r14
callq 0x8bd0
leaq -0xc0(%rbp), %r15
leaq -0x110(%rbp), %rdi
movl $0x4, %esi
callq 0x9f03
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x9b26
callq 0x3230
movl $0x1f4, %eax            # imm = 0x1F4
xorl %edx, %edx
idivl -0x2c(%rbp)
movl %eax, %edi
callq 0x3340
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x9965
callq 0x3230
jmp 0x9965
leaq 0x11763(%rip), %rdi     # 0x1b2b8
callq 0x3380
movq -0xa0(%rbp), %rdx
movb $0x1, (%rdx)
movl 0x4(%rdx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%rdx)
testl %eax, %eax
jne 0x9bb0
movq %r15, -0xd0(%rbp)
leaq -0xd0(%rbp), %rbx
movq %rbx, %rdi
leaq 0xb77b(%rip), %rsi      # 0x15304
leaq 0xb784(%rip), %rdx      # 0x15314
callq 0x7202
movq %rbx, %rdi
xorl %esi, %esi
callq 0x9f03
movq -0xd0(%rbp), %rdi
cmpq %r15, %rdi
je 0x9bb0
callq 0x3230
movq -0xb0(%rbp), %rdi
callq 0x30f0
leaq 0x116f5(%rip), %rdi     # 0x1b2b8
callq 0x31e0
callq 0x9847
testl %eax, %eax
jne 0x9db1
movq %r14, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
leaq 0xbdb6(%rip), %rdx      # 0x1599a
movq %rdx, %rsi
callq 0x7202
leaq 0x1211d(%rip), %rax     # 0x1bd10
movq (%rax), %r15
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
cmpq %rax, %r15
je 0x9d3e
movq (%r15), %rax
movl (%rax), %ebx
movl %ebx, %r13d
negl %r13d
cmovsl %ebx, %r13d
movl $0x1, %r14d
cmpl $0xa, %r13d
jb 0x9c64
movl $0x4, %r14d
movl %r13d, %eax
cmpl $0x63, %eax
jbe 0x9c5b
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x9c61
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x9c64
movl %eax, %ecx
imulq %r12, %rcx
shrq $0x2d, %rcx
addl $0x4, %r14d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x9c2b
addl $-0x3, %r14d
jmp 0x9c64
addl $-0x2, %r14d
jmp 0x9c64
decl %r14d
shrl $0x1f, %ebx
leal (%r14,%rbx), %esi
leaq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x98(%rbp), %r12
movq %r12, %rdi
movl $0x2d, %edx
callq 0x32b0
addq -0x98(%rbp), %rbx
movq %rbx, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x703e
movq %r12, %rdi
leaq 0xb63d(%rip), %rsi      # 0x152e9
callq 0x34a0
leaq -0x60(%rbp), %r14
movq %r14, -0x70(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9cd5
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
jmp 0x9cdc
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movl $0xd1b71759, %r12d      # imm = 0xD1B71759
movq 0x8(%rax), %rdx
movq %rdx, -0x68(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x30d0
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x9d18
callq 0x3230
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x9d30
callq 0x3230
addq $0x8, %r15
cmpq -0x78(%rbp), %r15
jne 0x9c07
leaq -0xf0(%rbp), %rdi
leaq 0xb5c9(%rip), %rsi      # 0x15315
leaq -0x50(%rbp), %rdx
leaq -0x40(%rbp), %r14
callq 0x8bd0
leaq -0xc0(%rbp), %r15
leaq -0xf0(%rbp), %rdi
movl $0x4, %esi
callq 0x9f03
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x9d89
callq 0x3230
movl $0x1f4, %eax            # imm = 0x1F4
xorl %edx, %edx
idivl -0x2c(%rbp)
movl %eax, %edi
callq 0x3340
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x9bc8
callq 0x3230
jmp 0x9bc8
leaq 0x11500(%rip), %r13     # 0x1b2b8
movq %r13, %rdi
callq 0x3380
movq -0xa0(%rbp), %rbx
movb $0x0, (%rbx)
movq -0xa8(%rbp), %rdi
callq 0x30f0
movq %r13, %rdi
callq 0x31e0
cmpb $0x1, 0x2(%rbx)
jne 0x9965
cmpb $0x1, 0x3(%rbx)
jne 0x9965
jmp 0x9e35
leaq -0x120(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xb4bb(%rip), %rsi      # 0x152c1
leaq 0xb4db(%rip), %rdx      # 0x152e8
leaq -0x130(%rbp), %rbx
movq %rbx, %rdi
callq 0x7202
movq %rbx, %rdi
callq 0x9777
movq -0x130(%rbp), %rdi
cmpq %r14, %rdi
je 0x9e35
callq 0x3230
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
movq -0x130(%rbp), %rdi
jmp 0x9ef1
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
cmpq %r15, %rdi
jne 0x9ef6
jmp 0x9efb
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
jmp 0x9eda
jmp 0x9ea0
movq %rax, %rbx
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
jmp 0x9eda
movq %rax, %rbx
jmp 0x9efb
jmp 0x9ea7
movq %rax, %rbx
jmp 0x9eed
jmp 0x9ee6
jmp 0x9eb2
jmp 0x9ec5
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x9ec8
callq 0x3230
jmp 0x9ec8
movq %rax, %rbx
leaq -0x40(%rbp), %r14
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x9eed
callq 0x3230
jmp 0x9eed
movq %rax, %rbx
leaq -0x40(%rbp), %r14
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x9efb
callq 0x3230
movq %rbx, %rdi
callq 0x3440