// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]ramulator/src/DRAM.h
// Function: ramulator::DRAM<ramulator::TLDRAM>::update_timing(ramulator::TLDRAM::Command, int const*, long)
void DRAM<T>::update_timing(typename T::Command cmd, const int* addr, long clk)
{
    // I am not a target node: I am merely one of its siblings
    if (id != addr[int(level)]) {
        for (auto& t : timing[int(cmd)]) {
            if (!t.sibling)
                continue; // not an applicable timing parameter

            assert (t.dist == 1);

            long future = clk + t.val;
            next[int(t.cmd)] = max(next[int(t.cmd)], future); // update future
        }

        return; // stop recursion: only target nodes should be recursed
    }

    // I am a target node
    if (prev[int(cmd)].size()) {
        prev[int(cmd)].pop_back();  // FIXME TIANSHI why pop back?
        prev[int(cmd)].push_front(clk); // update history
    }

    for (auto& t : timing[int(cmd)]) {
        if (t.sibling)
            continue; // not an applicable timing parameter

        long past = prev[int(cmd)][t.dist-1];
        if (past < 0)
            continue; // not enough history

        long future = past + t.val;
        next[int(t.cmd)] = max(next[int(t.cmd)], future); // update future
        // TIANSHI: for refresh statistics
        if (spec->is_refreshing(cmd) && spec->is_opening(t.cmd)) {
          assert(past == clk);
          begin_of_refreshing = clk;
          end_of_refreshing = max(end_of_refreshing, next[int(t.cmd)]);
          refresh_cycles += end_of_refreshing - clk;
          if (cur_serving_requests > 0) {
            refresh_intervals.push_back(make_pair(begin_of_refreshing, end_of_refreshing));
          }
        }
    }

    // Some commands have timings that are higher that their scope levels, thus
    // we do not stop at the cmd's scope level
    if (!children.size())
        return; // stop recursion: updated all levels

    // recursively update *all* of my children
    for (auto child : children)
        child->update_timing(cmd, addr, clk);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
movq %rcx, 0x8(%rsp)
movl 0x39c(%rdi), %eax
movslq 0x398(%rdi), %rdx
cmpl (%r14,%rdx,4), %eax
jne 0x9e0de
movslq %ebp, %r12
imulq $0x50, %r12, %rax
leaq (%rbx,%rax), %r15
addq $0x4d8, %r15            # imm = 0x4D8
movq %r15, %rdi
callq 0x18f6e
testq %rax, %rax
je 0x9dfe0
movq %r15, %rdi
callq 0x20c28
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x20c40
movq 0xa48(%rbx), %rax
imulq $0x18, %r12, %rcx
movq (%rax,%rcx), %r13
movq 0x8(%rax,%rcx), %r12
addq $0x10, %r15
leaq 0x430(%rbx), %rax
movq %rax, 0x10(%rsp)
cmpq %r12, %r13
je 0x9e12d
cmpb $0x0, 0xc(%r13)
jne 0x9e0d5
movslq 0x4(%r13), %rsi
decq %rsi
movq %r15, %rdi
callq 0x20d1e
movq (%rax), %rax
testq %rax, %rax
js 0x9e0d5
movslq 0x8(%r13), %rdx
addq %rax, %rdx
movslq (%r13), %rcx
movq 0x450(%rbx,%rcx,8), %rsi
cmpq %rdx, %rsi
cmovgq %rsi, %rdx
movq %rdx, 0x450(%rbx,%rcx,8)
cmpl $0x5, %ebp
jne 0x9e0d5
cmpl $0xe, %ecx
ja 0x9e0d5
movl $0x4401, %edx           # imm = 0x4401
btl %ecx, %edx
jae 0x9e0d5
cmpq 0x8(%rsp), %rax
jne 0x9e18b
movq %rax, 0x420(%rbx)
movq 0x428(%rbx), %rdx
movq 0x450(%rbx,%rcx,8), %rcx
cmpq %rcx, %rdx
cmovgq %rdx, %rcx
movq %rcx, 0x428(%rbx)
movq %rcx, %rdx
subq %rax, %rdx
cvtsi2sd %rdx, %xmm0
addsd 0x108(%rbx), %xmm0
movsd %xmm0, 0x108(%rbx)
cmpl $0x0, 0x400(%rbx)
jle 0x9e0d5
movq %rax, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x20d3e
addq $0x10, %r13
jmp 0x9e004
movq 0xa48(%rbx), %rdx
movslq %ebp, %rax
imulq $0x18, %rax, %rsi
movq (%rdx,%rsi), %rax
movq 0x8(%rdx,%rsi), %rdx
cmpq %rdx, %rax
je 0x9e15d
cmpb $0x1, 0xc(%rax)
jne 0x9e127
cmpl $0x1, 0x4(%rax)
jne 0x9e16c
movslq 0x8(%rax), %rsi
addq %rcx, %rsi
movslq (%rax), %rdi
movq 0x450(%rbx,%rdi,8), %r8
cmpq %rsi, %r8
cmovgq %r8, %rsi
movq %rsi, 0x450(%rbx,%rdi,8)
addq $0x10, %rax
jmp 0x9e0f5
movq 0x3b0(%rbx), %r15
movq 0x3b8(%rbx), %rbx
cmpq %r15, %rbx
jne 0x9e158
jmp 0x9e15d
movq (%r15), %rdi
movq 0x8(%rsp), %rcx
movl %ebp, %esi
movq %r14, %rdx
callq 0x9df7a
addq $0x8, %r15
cmpq %rbx, %r15
jne 0x9e142
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x34a30(%rip), %rdi     # 0xd2ba3
leaq 0x34771(%rip), %rsi     # 0xd28eb
leaq 0x3e93e(%rip), %rcx     # 0xdcabf
movl $0x168, %edx            # imm = 0x168
callq 0xb210
leaq 0x34a90(%rip), %rdi     # 0xd2c22
leaq 0x34752(%rip), %rsi     # 0xd28eb
leaq 0x3e91f(%rip), %rcx     # 0xdcabf
movl $0x183, %edx            # imm = 0x183
callq 0xb210