// File: /workspace/github_cpp_makefile_star2_O3/CMU-SAFARI[P]SMLA/src/Controller.h
// Function: ramulator::Controller<ramulator::WideIO>::tick()
void tick()
    {
        clk++;

				if (channel->spec->standard_name.substr(0,8) == "SMLA_CIO"
							&& channel->id % 4 != clk % 4)  {
					return;
				}

        req_queue_length_sum += readq.size() + writeq.size() + pending.size();
        read_req_queue_length_sum += readq.size() + pending.size();
        write_req_queue_length_sum += writeq.size();

        /*** 1. Serve completed reads ***/
        if (pending.size()) {
            Request& req = pending[0];
            if (req.depart <= clk) {
                if (req.depart - req.arrive > 1) { // this request really accessed a row
                  read_latency_sum += req.depart - req.arrive;
                  channel->update_serving_requests(
                      req.addr_vec.data(), -1, clk);
                }
                req.callback(req);
                pending.pop_front();
            }
        }

        /*** 2. Refresh scheduler ***/
        refresh->tick_ref();

        /*** 3. Should we schedule writes? ***/
        if (!write_mode) {
            // yes -- write queue is almost full or read queue is empty
            if (writeq.size() >= int(0.8 * writeq.max) || readq.size() == 0)
                write_mode = true;
        }
        else {
            // no -- write queue is almost empty and read queue is not empty
            if (writeq.size() <= int(0.2 * writeq.max) && readq.size() != 0)
                write_mode = false;
        }

        /*** 4. Find the best command to schedule, if any ***/
        Queue* queue = !write_mode ? &readq : &writeq;
        if (otherq.size())
            queue = &otherq;  // "other" requests are rare, so we give them precedence over reads/writes

        auto req = scheduler->get_head(queue->q);
        if (req == queue->q.end() || !is_ready(req)) {
            // we couldn't find a command to schedule -- let's try to be speculative
            auto cmd = T::Command::PRE;
            vector<int> victim = rowpolicy->get_victim(cmd);
            if (!victim.empty()){
                issue_cmd(cmd, victim);
            }
            return;  // nothing more to be done this cycle
        }

        if (req->is_first_command) {
            req->is_first_command = false;
            int coreid = req->coreid;
            if (req->type == Request::Type::READ || req->type == Request::Type::WRITE) {
              channel->update_serving_requests(req->addr_vec.data(), 1, clk);
            }
            int tx = (channel->spec->prefetch_size * channel->spec->channel_width / 8);
            if (req->type == Request::Type::READ) {
                if (is_row_hit(req)) {
                    ++read_row_hits[coreid];
                    ++row_hits;
                } else if (is_row_open(req)) {
                    ++read_row_conflicts[coreid];
                    ++row_conflicts;
                } else {
                    ++read_row_misses[coreid];
                    ++row_misses;
                }
              read_transaction_bytes += tx;
            } else if (req->type == Request::Type::WRITE) {
              if (is_row_hit(req)) {
                  ++write_row_hits[coreid];
                  ++row_hits;
              } else if (is_row_open(req)) {
                  ++write_row_conflicts[coreid];
                  ++row_conflicts;
              } else {
                  ++write_row_misses[coreid];
                  ++row_misses;
              }
              write_transaction_bytes += tx;
            }
        }

        // issue command on behalf of request
        auto cmd = get_first_cmd(req);
        issue_cmd(cmd, get_addr_vec(cmd, req));

        // check whether this is the last command (which finishes the request)
        if (cmd != channel->spec->translate[int(req->type)])
            return;

        // set a future completion time for read requests
        if (req->type == Request::Type::READ) {
            req->depart = clk + channel->spec->read_latency_smla[channel->id % 4];
            pending.push_back(*req);
        }

        if (req->type == Request::Type::WRITE) {
            channel->update_serving_requests(req->addr_vec.data(), -1, clk);
        }

        // remove request from queue
        queue->q.erase(req);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
incq 0xff8(%rdi)
leaq 0x4ecc5(%rip), %rsi     # 0x665f8
leaq 0x8(%rsp), %r14
movl $0x8, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x52f0
leaq 0x368cf(%rip), %rsi     # 0x4e21d
movq %r14, %rdi
callq 0x50f0
testl %eax, %eax
je 0x17977
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x179d1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x52d0
jmp 0x179d1
movq 0xff8(%rbx), %r14
movq 0x1000(%rbx), %rax
movl 0x39c(%rax), %eax
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
movslq %eax, %r15
leaq 0x3(%r14), %rax
testq %r14, %r14
cmovnsq %r14, %rax
andq $-0x4, %rax
subq %rax, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x179c8
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x52d0
cmpq %r15, %r14
jne 0x17f49
movq 0x1038(%rbx), %rsi
movl 0x1058(%rbx), %eax
leal (%rax,%rsi), %r8d
movq 0x10d0(%rbx), %rdx
movq 0x10b0(%rbx), %rcx
movq %rdx, %rdi
subq %rcx, %rdi
sarq $0x3, %rdi
cmpq $0x1, %rdx
adcq $-0x1, %rdi
leaq (%rdi,%rdi,4), %rdi
movq 0x10b8(%rbx), %r9
subq 0x10c0(%rbx), %r9
sarq $0x5, %r9
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %r9
addq %rdi, %r9
movq 0x10a8(%rbx), %rdi
movq 0x1098(%rbx), %r15
subq %r15, %rdi
sarq $0x5, %rdi
imulq %rdx, %rdi
addq %r9, %rdi
addq %rdi, %r8
movq %r8, %xmm0
movq 0x3661b(%rip), %xmm1    # 0x4e070
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3661f(%rip), %xmm2    # 0x4e080
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
addsd 0x950(%rbx), %xmm3
movsd %xmm3, 0x950(%rbx)
movl %esi, %esi
addq %rdi, %rsi
movq %rsi, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
addsd 0xa80(%rbx), %xmm1
leaq 0x1088(%rbx), %r14
movsd %xmm1, 0xa80(%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0xbb0(%rbx), %xmm0
movsd %xmm0, 0xbb0(%rbx)
testq %rdi, %rdi
je 0x17b95
movq %r15, %rsi
subq 0x10a0(%rbx), %rsi
movq %rsi, %rax
sarq $0x5, %rax
imulq %rdx, %rax
cmpq $-0x5f, %rsi
jl 0x17b0b
cmpq $0x5, %rax
jb 0x17b30
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rdx
shrq $0x2, %rdx
jmp 0x17b22
notq %rax
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rdx
shrq $0x2, %rdx
notq %rdx
imulq $-0x1e0, %rdx, %r15     # imm = 0xFE20
addq (%rcx,%rdx,8), %r15
addq %rsi, %r15
movq 0x38(%r15), %rax
movq 0xff8(%rbx), %rcx
cmpq %rcx, %rax
jg 0x17b95
subq 0x30(%r15), %rax
cmpq $0x2, %rax
jl 0x17b77
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd 0x820(%rbx), %xmm0
movsd %xmm0, 0x820(%rbx)
movq 0x1000(%rbx), %rdi
movq 0x10(%r15), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x17f82
cmpq $0x0, 0x50(%r15)
je 0x17f58
leaq 0x40(%r15), %rdi
movq %r15, %rsi
callq *0x58(%r15)
movq %r14, %rdi
callq 0x181ce
movq 0x1020(%rbx), %rdi
callq 0x181fc
movb 0x10d8(%rbx), %al
movl 0x1038(%rbx), %edx
movl 0x1058(%rbx), %ecx
movl 0x1060(%rbx), %esi
xorps %xmm0, %xmm0
cvtsi2sd %rsi, %xmm0
testb %al, %al
je 0x17be4
testq %rdx, %rdx
sete %dl
mulsd 0x364e5(%rip), %xmm0    # 0x4e0b8
cvttsd2si %xmm0, %esi
cmpl %esi, %ecx
seta %cl
orb %dl, %cl
jne 0x17c09
xorl %ecx, %ecx
jmp 0x17c01
testq %rdx, %rdx
sete %dl
mulsd 0x364be(%rip), %xmm0    # 0x4e0b0
cvttsd2si %xmm0, %esi
cmpl %esi, %ecx
setae %cl
orb %dl, %cl
movb $0x1, %cl
je 0x17c09
movb %cl, 0x10d8(%rbx)
movl %ecx, %eax
movzbl %al, %eax
shll $0x5, %eax
addq $0x1028, %rax           # imm = 0x1028
cmpl $0x0, 0x1078(%rbx)
movl $0x1068, %r15d          # imm = 0x1068
cmoveq %rax, %r15
addq %rbx, %r15
movq 0x1008(%rbx), %rdi
movq %r15, %rsi
callq 0x18234
cmpq %r15, %rax
je 0x17d06
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1474a
testb %al, %al
je 0x17d06
cmpb $0x1, 0x10(%r12)
movq %r14, 0x30(%rsp)
jne 0x17e5e
movb $0x0, 0x10(%r12)
movl 0x38(%r12), %ebp
movl 0x3c(%r12), %eax
cmpl $0x1, %eax
ja 0x17c9f
movq 0xff8(%rbx), %rcx
movq 0x1000(%rbx), %rdi
movq 0x20(%r12), %rsi
movl $0x1, %edx
callq 0x17f82
movl 0x3c(%r12), %eax
movq 0x1000(%rbx), %rdi
movq 0x390(%rdi), %rcx
movl 0x2610(%rcx), %edx
imull 0x260c(%rcx), %edx
leal 0x7(%rdx), %r14d
testl %edx, %edx
cmovnsl %edx, %r14d
cmpl $0x1, %eax
je 0x17d7c
testl %eax, %eax
jne 0x17e5e
movl %ebp, 0x4(%rsp)
movl 0x1c4(%rcx), %esi
movq 0x20(%r12), %rdx
callq 0x15138
movl $0x70, %r13d
testb %al, %al
je 0x17da6
movl $0x1a0, %ebp            # imm = 0x1A0
movl $0x2f8, %edi            # imm = 0x2F8
jmp 0x17e1a
movq 0x1010(%rbx), %rax
movslq 0x8(%rax), %rcx
shlq $0x5, %rcx
movl $0x1, 0x2c(%rsp)
cmpq $0x0, 0x20(%rax,%rcx)
je 0x17f58
leaq (%rax,%rcx), %rsi
addq $0x10, %rsi
leaq 0x8(%rsp), %r14
leaq 0x2c(%rsp), %rdx
movq %r14, %rdi
callq *0x18(%rsi)
movq (%r14), %rdi
cmpq 0x8(%r14), %rdi
je 0x17d61
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x18610
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x17f49
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x52d0
jmp 0x17f49
movl %ebp, 0x4(%rsp)
movl 0x1c8(%rcx), %esi
movq 0x20(%r12), %rdx
callq 0x15138
movl $0x108, %r13d           # imm = 0x108
testb %al, %al
je 0x17dd8
movl $0x1a0, %ebp            # imm = 0x1A0
movl $0x508, %edi            # imm = 0x508
jmp 0x17e1a
movq 0x1000(%rbx), %rdi
movq 0x390(%rdi), %rax
movslq 0x3c(%r12), %rcx
movl 0x1c4(%rax,%rcx,4), %esi
movq 0x20(%r12), %rdx
callq 0x19d7c
testb %al, %al
movl $0x458, %eax            # imm = 0x458
movl $0x3a8, %edi            # imm = 0x3A8
jmp 0x17e08
movq 0x1000(%rbx), %rdi
movq 0x390(%rdi), %rax
movslq 0x3c(%r12), %rcx
movl 0x1c4(%rax,%rcx,4), %esi
movq 0x20(%r12), %rdx
callq 0x19d7c
testb %al, %al
movl $0x668, %eax            # imm = 0x668
movl $0x5b8, %edi            # imm = 0x5B8
cmovneq %rax, %rdi
movl $0x2d0, %eax            # imm = 0x2D0
movl $0x238, %ebp            # imm = 0x238
cmovneq %rax, %rbp
sarl $0x3, %r14d
addq %rbx, %rdi
movl 0x4(%rsp), %esi
callq 0x19d3a
movsd 0x36266(%rip), %xmm0    # 0x4e098
movsd 0x70(%rax), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x70(%rax)
addsd (%rbx,%rbp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd %xmm0, (%rbx,%rbp)
addsd (%rbx,%r13), %xmm1
movsd %xmm1, (%rbx,%r13)
movq 0x1000(%rbx), %rdi
movq 0x390(%rdi), %rax
movslq 0x3c(%r12), %rcx
movl 0x1c4(%rax,%rcx,4), %esi
leaq 0x20(%r12), %r13
movq 0x20(%r12), %rdx
callq 0x1480c
movl %eax, %ebp
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x14f2e
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0x18610
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x17ebd
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x52d0
movq 0x1000(%rbx), %rcx
movq 0x390(%rcx), %rax
movslq 0x3c(%r12), %rdx
cmpl 0x1c4(%rax,%rdx,4), %ebp
jne 0x17f49
testl %edx, %edx
jne 0x17f1d
movq %r12, %rsi
addq $0x10, %rsi
movl 0x39c(%rcx), %ecx
leal 0x3(%rcx), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
andl $-0x4, %edx
subl %edx, %ecx
movslq %ecx, %rcx
movslq 0x276c(%rax,%rcx,4), %rax
addq 0xff8(%rbx), %rax
movq %rax, 0x48(%r12)
movq 0x30(%rsp), %rdi
callq 0x1886a
movl 0x3c(%r12), %edx
cmpl $0x1, %edx
jne 0x17f3e
movq 0xff8(%rbx), %rcx
movq 0x1000(%rbx), %rdi
movq (%r13), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x17f82
movq %r15, %rdi
movq %r12, %rsi
callq 0x190f0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5150
jmp 0x17f5f
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x17f79
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x52d0
movq %rbx, %rdi
callq 0x54c0
nop