// File: /workspace/github_cpp_makefile_star2_O1/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 0x10abc8
movslq %ebp, %r12
leaq (%r12,%r12,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %r15
addq $0x4d8, %r15            # imm = 0x4D8
movq 0x48(%r15), %rax
movq %rax, %rcx
subq 0x28(%r15), %rcx
shrq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
shlq $0x6, %rcx
movq 0x20(%r15), %rax
movq 0x30(%r15), %rdx
subq 0x38(%r15), %rdx
sarq $0x3, %rdx
addq %rcx, %rdx
subq 0x10(%r15), %rax
sarq $0x3, %rax
addq %rdx, %rax
je 0x10ac2c
movq %r15, %rdi
callq 0x2a50c
movq 0x10(%r15), %rax
cmpq 0x18(%r15), %rax
je 0x10ac1f
movq 0x8(%rsp), %rcx
movq %rcx, -0x8(%rax)
addq $-0x8, %rax
movq %rax, 0x10(%r15)
jmp 0x10ac2c
movq 0xa48(%rbx), %rdx
movslq %ebp, %rax
leaq (%rax,%rax,2), %rsi
movq (%rdx,%rsi,8), %rax
movq 0x8(%rdx,%rsi,8), %rdx
cmpq %rdx, %rax
je 0x10adf5
cmpb $0x1, 0xc(%rax)
jne 0x10ac19
cmpl $0x1, 0x4(%rax)
jne 0x10ae04
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 0x10abdf
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2a558
movq 0xa48(%rbx), %rax
leaq (%r12,%r12,2), %rcx
movq (%rax,%rcx,8), %r13
movq 0x8(%rax,%rcx,8), %r12
cmpq %r12, %r13
je 0x10adc7
leaq 0x430(%rbx), %rdi
movl $0x4401, %r8d           # imm = 0x4401
leaq 0x18(%rsp), %rdx
movabsq $-0x400000000000000, %r10 # imm = 0xFC00000000000000
cmpb $0x0, 0xc(%r13)
jne 0x10adba
movq 0x10(%r15), %rcx
movq %rcx, %rax
subq 0x18(%r15), %rax
movslq 0x4(%r13), %rsi
sarq $0x3, %rax
addq %rsi, %rax
decq %rax
cmpq $0x3f, %rax
ja 0x10ac98
decq %rsi
leaq (%rcx,%rsi,8), %rax
jmp 0x10acc0
movq 0x28(%r15), %rcx
movq %rax, %r9
shrq $0x6, %r9
leaq (%r9,%r10), %rsi
testq %rax, %rax
cmovgq %r9, %rsi
movq %rsi, %r9
shlq $0x6, %r9
subq %r9, %rax
shlq $0x3, %rax
addq (%rcx,%rsi,8), %rax
movq (%rax), %rax
testq %rax, %rax
js 0x10adba
movslq 0x8(%r13), %r9
addq %rax, %r9
movslq (%r13), %rcx
movq 0x450(%rbx,%rcx,8), %rsi
cmpq %r9, %rsi
cmovgq %rsi, %r9
movq %r9, 0x450(%rbx,%rcx,8)
cmpl $0x5, %ebp
jne 0x10adba
cmpl $0xe, %ecx
ja 0x10adba
btl %ecx, %r8d
jae 0x10adba
movq 0x8(%rsp), %r9
cmpq %r9, %rax
jne 0x10ae23
movq %r9, 0x420(%rbx)
movq 0x428(%rbx), %rsi
movq 0x450(%rbx,%rcx,8), %rax
cmpq %rax, %rsi
cmovgq %rsi, %rax
movq %rax, 0x428(%rbx)
movq %rax, %rcx
subq %r9, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
addsd 0x108(%rbx), %xmm0
movsd %xmm0, 0x108(%rbx)
cmpl $0x0, 0x400(%rbx)
jle 0x10adba
movq %r9, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq 0x438(%rbx), %rsi
cmpq 0x440(%rbx), %rsi
je 0x10ad91
movupd 0x18(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x438(%rbx)
jmp 0x10adba
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rdi
callq 0x2a61e
movabsq $-0x400000000000000, %r10 # imm = 0xFC00000000000000
leaq 0x18(%rsp), %rdx
movl $0x4401, %r8d           # imm = 0x4401
movq 0x10(%rsp), %rdi
addq $0x10, %r13
cmpq %r12, %r13
jne 0x10ac65
movq 0x3b0(%rbx), %r15
movq 0x3b8(%rbx), %rbx
cmpq %r15, %rbx
je 0x10adf5
movq (%r15), %rdi
movq 0x8(%rsp), %rcx
movl %ebp, %esi
movq %r14, %rdx
callq 0x10ab20
addq $0x8, %r15
cmpq %rbx, %r15
jne 0x10adda
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x43ddc(%rip), %rdi     # 0x14ebe7
leaq 0x43b1d(%rip), %rsi     # 0x14e92f
leaq 0x4dcc6(%rip), %rcx     # 0x158adf
movl $0x168, %edx            # imm = 0x168
callq 0xb200
leaq 0x43e3c(%rip), %rdi     # 0x14ec66
leaq 0x43afe(%rip), %rsi     # 0x14e92f
leaq 0x4dca7(%rip), %rcx     # 0x158adf
movl $0x183, %edx            # imm = 0x183
callq 0xb200