// File: /workspace/github_cpp_makefile_star2_O3/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 0x9e00
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 0x9702
testl %eax, %eax
jne 0x9b5a
movq %r14, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
leaq 0xc00d(%rip), %rdx      # 0x1599a
movq %rdx, %rsi
callq 0x721e
leaq 0x12374(%rip), %rax     # 0x1bd10
movq (%rax), %r15
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
cmpq %rax, %r15
je 0x9ae7
movq (%r15), %rax
movl (%rax), %ebx
movl %ebx, %r13d
negl %r13d
cmovsl %ebx, %r13d
movl $0x1, %r14d
cmpl $0xa, %r13d
jb 0x9a0d
movl $0x4, %r14d
movl %r13d, %eax
cmpl $0x63, %eax
jbe 0x9a04
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x9a0a
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x9a0d
movl %eax, %ecx
imulq %r12, %rcx
shrq $0x2d, %rcx
addl $0x4, %r14d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x99d4
addl $-0x3, %r14d
jmp 0x9a0d
addl $-0x2, %r14d
jmp 0x9a0d
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 0x7056
movq %r12, %rdi
leaq 0xb894(%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 0x9a7e
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
jmp 0x9a85
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 0x9ac1
callq 0x3230
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x9ad9
callq 0x3230
addq $0x8, %r15
cmpq -0x78(%rbp), %r15
jne 0x99b0
leaq -0x110(%rbp), %rdi
leaq 0xb7f6(%rip), %rsi      # 0x152eb
leaq -0x50(%rbp), %rdx
leaq -0x40(%rbp), %r14
callq 0x8c2e
leaq -0xc0(%rbp), %r15
leaq -0x110(%rbp), %rdi
movl $0x4, %esi
callq 0x9f0f
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x9b32
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 0x9971
callq 0x3230
jmp 0x9971
leaq 0x11757(%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 0x9bbc
movq %r15, -0xd0(%rbp)
leaq -0xd0(%rbp), %rbx
movq %rbx, %rdi
leaq 0xb76f(%rip), %rsi      # 0x15304
leaq 0xb778(%rip), %rdx      # 0x15314
callq 0x721e
movq %rbx, %rdi
xorl %esi, %esi
callq 0x9f0f
movq -0xd0(%rbp), %rdi
cmpq %r15, %rdi
je 0x9bbc
callq 0x3230
movq -0xb0(%rbp), %rdi
callq 0x30f0
leaq 0x116e9(%rip), %rdi     # 0x1b2b8
callq 0x31e0
callq 0x987b
testl %eax, %eax
jne 0x9dbd
movq %r14, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
leaq 0xbdaa(%rip), %rdx      # 0x1599a
movq %rdx, %rsi
callq 0x721e
leaq 0x12111(%rip), %rax     # 0x1bd10
movq (%rax), %r15
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
cmpq %rax, %r15
je 0x9d4a
movq (%r15), %rax
movl (%rax), %ebx
movl %ebx, %r13d
negl %r13d
cmovsl %ebx, %r13d
movl $0x1, %r14d
cmpl $0xa, %r13d
jb 0x9c70
movl $0x4, %r14d
movl %r13d, %eax
cmpl $0x63, %eax
jbe 0x9c67
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x9c6d
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x9c70
movl %eax, %ecx
imulq %r12, %rcx
shrq $0x2d, %rcx
addl $0x4, %r14d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x9c37
addl $-0x3, %r14d
jmp 0x9c70
addl $-0x2, %r14d
jmp 0x9c70
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 0x7056
movq %r12, %rdi
leaq 0xb631(%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 0x9ce1
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
jmp 0x9ce8
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 0x9d24
callq 0x3230
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x9d3c
callq 0x3230
addq $0x8, %r15
cmpq -0x78(%rbp), %r15
jne 0x9c13
leaq -0xf0(%rbp), %rdi
leaq 0xb5bd(%rip), %rsi      # 0x15315
leaq -0x50(%rbp), %rdx
leaq -0x40(%rbp), %r14
callq 0x8c2e
leaq -0xc0(%rbp), %r15
leaq -0xf0(%rbp), %rdi
movl $0x4, %esi
callq 0x9f0f
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x9d95
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 0x9bd4
callq 0x3230
jmp 0x9bd4
leaq 0x114f4(%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 0x9971
cmpb $0x1, 0x3(%rbx)
jne 0x9971
jmp 0x9e41
leaq -0x120(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xb4af(%rip), %rsi      # 0x152c1
leaq 0xb4cf(%rip), %rdx      # 0x152e8
leaq -0x130(%rbp), %rbx
movq %rbx, %rdi
callq 0x721e
movq %rbx, %rdi
callq 0x97ab
movq -0x130(%rbp), %rdi
cmpq %r14, %rdi
je 0x9e41
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 0x9efd
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
cmpq %r15, %rdi
jne 0x9f02
jmp 0x9f07
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
jmp 0x9ee6
jmp 0x9eac
movq %rax, %rbx
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
jmp 0x9ee6
movq %rax, %rbx
jmp 0x9f07
jmp 0x9eb3
movq %rax, %rbx
jmp 0x9ef9
jmp 0x9ef2
jmp 0x9ebe
jmp 0x9ed1
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x9ed4
callq 0x3230
jmp 0x9ed4
movq %rax, %rbx
leaq -0x40(%rbp), %r14
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x9ef9
callq 0x3230
jmp 0x9ef9
movq %rax, %rbx
leaq -0x40(%rbp), %r14
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x9f07
callq 0x3230
movq %rbx, %rdi
callq 0x3440