// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]ramulator/src/Controller.h
// Function: ramulator::Controller<ramulator::DDR3>::cmd_issue_autoprecharge(ramulator::DDR3::Command&, std::vector<int, std::allocator<int>> const&)
void cmd_issue_autoprecharge(typename T::Command& cmd,
                                            const vector<int>& addr_vec) {

        // currently, autoprecharge is only used with closed row policy
        if(channel->spec->is_accessing(cmd) && rowpolicy->type == RowPolicy<T>::Type::ClosedAP) {
            // check if it is the last request to the opened row
            Queue* queue = write_mode ? &writeq : &readq;

            auto begin = addr_vec.begin();
            vector<int> rowgroup(begin, begin + int(T::Level::Row) + 1);

			int num_row_hits = 0;

            for (auto itr = queue->q.begin(); itr != queue->q.end(); ++itr) {
                if (is_row_hit(itr)) { 
                    auto begin2 = itr->addr_vec.begin();
                    vector<int> rowgroup2(begin2, begin2 + int(T::Level::Row) + 1);
                    if(rowgroup == rowgroup2)
                        num_row_hits++;
                }
            }

            if(num_row_hits == 0) {
                Queue* queue = &actq;
                for (auto itr = queue->q.begin(); itr != queue->q.end(); ++itr) {
                    if (is_row_hit(itr)) {
                        auto begin2 = itr->addr_vec.begin();
                        vector<int> rowgroup2(begin2, begin2 + int(T::Level::Row) + 1);
                        if(rowgroup == rowgroup2)
                            num_row_hits++;
                    }
                }
            }

            assert(num_row_hits > 0); // The current request should be a hit, 
                                      // so there should be at least one request 
                                      // that hits in the current open row
            if(num_row_hits == 1) {
                if(cmd == T::Command::RD)
                    cmd = T::Command::RDA;
                else if (cmd == T::Command::WR)
                    cmd = T::Command::WRA;
                else
                    assert(false && "Unimplemented command type.");
            }
        }

    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl (%rsi), %eax
addl $-0x3, %eax
cmpl $0x3, %eax
ja 0x206c3
movq %rdi, %r14
movq 0x10a8(%rdi), %rax
cmpl $0x1, 0x8(%rax)
jne 0x206c3
movq %rsi, %rbx
movzbl 0x1190(%r14), %eax
shll $0x5, %eax
leaq (%r14,%rax), %r15
addq $0x10c0, %r15           # imm = 0x10C0
movq (%rdx), %rsi
leaq 0x10(%rsi), %rdx
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %r12
movq %r12, %rcx
callq 0x1b74e
xorl %r13d, %r13d
movq %r15, %rbp
movq (%rbp), %rbp
cmpq %r15, %rbp
je 0x20630
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1ba2a
testb %al, %al
je 0x205e6
movq 0x20(%rbp), %rsi
leaq 0x10(%rsi), %rdx
movq %r12, %rdi
leaq 0x7(%rsp), %rcx
callq 0x201f6
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x20254
movzbl %al, %eax
addl %eax, %r13d
movq %r12, %rdi
callq 0x1b7dc
jmp 0x205e6
testl %r13d, %r13d
je 0x20658
testl %r13d, %r13d
jle 0x206d2
cmpl $0x1, %r13d
jne 0x206b9
movl (%rbx), %eax
cmpl $0x3, %eax
je 0x206b4
cmpl $0x4, %eax
jne 0x206f1
pushq $0x6
jmp 0x206b6
leaq 0x1100(%r14), %r12
xorl %r13d, %r13d
leaq 0x20(%rsp), %r15
movq %r12, %rbp
movq (%rbp), %rbp
cmpq %r12, %rbp
je 0x20635
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1ba2a
testb %al, %al
je 0x2066a
movq 0x20(%rbp), %rsi
leaq 0x10(%rsi), %rdx
movq %r15, %rdi
leaq 0x7(%rsp), %rcx
callq 0x201f6
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x20254
movzbl %al, %eax
addl %eax, %r13d
movq %r15, %rdi
callq 0x1b7dc
jmp 0x2066a
pushq $0x5
popq %rax
movl %eax, (%rbx)
leaq 0x8(%rsp), %rdi
callq 0x1b7dc
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb240b(%rip), %rdi     # 0xd2ae4
leaq 0xb2367(%rip), %rsi     # 0xd2a47
leaq 0xb240e(%rip), %rcx     # 0xd2af5
movl $0x247, %edx            # imm = 0x247
callq 0xb210
leaq 0xb2484(%rip), %rdi     # 0xd2b7c
leaq 0xb2348(%rip), %rsi     # 0xd2a47
leaq 0xb23ef(%rip), %rcx     # 0xd2af5
movl $0x250, %edx            # imm = 0x250
callq 0xb210
jmp 0x20714
jmp 0x20727
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x1b7dc
jmp 0x2072a
jmp 0x20727
jmp 0x20727
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x1b7dc
movq %rbx, %rdi
callq 0xb4d0