// File: /workspace/github_cpp_makefile_star2_O3/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 %rcx, %r12
movl %esi, %ebp
movq %rdi, %rbx
movq %rcx, 0x8(%rsp)
movl 0x39c(%rdi), %eax
movslq 0x398(%rdi), %rcx
cmpl (%rdx,%rcx,4), %eax
jne 0x1080c4
movq %rdx, %r14
movslq %ebp, %r13
leaq (,%r13,4), %rax
addq %r13, %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 0x108128
movq %r15, %rdi
callq 0x2a7e4
movq 0x10(%r15), %rax
cmpq 0x18(%r15), %rax
je 0x10811b
movq %r12, -0x8(%rax)
addq $-0x8, %rax
movq %rax, 0x10(%r15)
jmp 0x108128
movq 0xa48(%rbx), %rcx
movslq %ebp, %rax
leaq (%rax,%rax,2), %rdx
movq (%rcx,%rdx,8), %rax
movq 0x8(%rcx,%rdx,8), %rcx
cmpq %rcx, %rax
je 0x1082de
cmpb $0x1, 0xc(%rax)
jne 0x108115
cmpl $0x1, 0x4(%rax)
jne 0x1082ed
movslq 0x8(%rax), %rdx
addq %r12, %rdx
movslq (%rax), %rsi
movq 0x450(%rbx,%rsi,8), %rdi
cmpq %rdx, %rdi
cmovgq %rdi, %rdx
movq %rdx, 0x450(%rbx,%rsi,8)
addq $0x10, %rax
jmp 0x1080db
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2a830
movq 0xa48(%rbx), %rax
leaq (,%r13,2), %rcx
addq %r13, %rcx
movq (%rax,%rcx,8), %r13
movq 0x8(%rax,%rcx,8), %r12
cmpq %r12, %r13
je 0x1082b0
leaq 0x430(%rbx), %rdi
movl $0x4401, %r8d           # imm = 0x4401
leaq 0x18(%rsp), %rdx
cmpb $0x0, 0xc(%r13)
jne 0x1082a3
movslq 0x4(%r13), %r9
decq %r9
movq 0x10(%r15), %rsi
movq 0x28(%r15), %rcx
movq %rsi, %rax
subq 0x18(%r15), %rax
sarq $0x3, %rax
addq %r9, %rax
js 0x108194
cmpq $0x3f, %rax
ja 0x10819d
leaq (%rsi,%r9,8), %rax
jmp 0x1081b6
movq %rax, %r9
sarq $0x6, %r9
jmp 0x1081a4
movq %rax, %r9
shrq $0x6, %r9
movq %r9, %rsi
shlq $0x6, %rsi
subq %rsi, %rax
shlq $0x3, %rax
addq (%rcx,%r9,8), %rax
movq (%rax), %rax
testq %rax, %rax
js 0x1082a3
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 0x1082a3
cmpl $0xe, %ecx
ja 0x1082a3
btl %ecx, %r8d
jae 0x1082a3
cmpq 0x8(%rsp), %rax
jne 0x10830c
movq %rax, 0x420(%rbx)
movq 0x428(%rbx), %rsi
movq 0x450(%rbx,%rcx,8), %rcx
cmpq %rcx, %rsi
cmovgq %rsi, %rcx
movq %rcx, 0x428(%rbx)
movq %rcx, %rsi
subq %rax, %rsi
xorps %xmm0, %xmm0
cvtsi2sd %rsi, %xmm0
addsd 0x108(%rbx), %xmm0
movsd %xmm0, 0x108(%rbx)
cmpl $0x0, 0x400(%rbx)
jle 0x1082a3
movq %rax, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movq 0x438(%rbx), %rsi
cmpq 0x440(%rbx), %rsi
je 0x108284
movupd 0x18(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x438(%rbx)
jmp 0x1082a3
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rdi
callq 0x2a8f6
leaq 0x18(%rsp), %rdx
movl $0x4401, %r8d           # imm = 0x4401
movq 0x10(%rsp), %rdi
addq $0x10, %r13
cmpq %r12, %r13
jne 0x10815e
movq 0x3b0(%rbx), %r15
movq 0x3b8(%rbx), %rbx
cmpq %r15, %rbx
je 0x1082de
movq (%r15), %rdi
movq 0x8(%rsp), %rcx
movl %ebp, %esi
movq %r14, %rdx
callq 0x108018
addq $0x8, %r15
cmpq %rbx, %r15
jne 0x1082c3
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x43933(%rip), %rdi     # 0x14bc27
leaq 0x43674(%rip), %rsi     # 0x14b96f
leaq 0x4d81d(%rip), %rcx     # 0x155b1f
movl $0x168, %edx            # imm = 0x168
callq 0xb200
leaq 0x43993(%rip), %rdi     # 0x14bca6
leaq 0x43655(%rip), %rsi     # 0x14b96f
leaq 0x4d7fe(%rip), %rcx     # 0x155b1f
movl $0x183, %edx            # imm = 0x183
callq 0xb200
nop