// File: /workspace/github_cpp_makefile_star2_O3/CMU-SAFARI[P]ramulator/src/DRAM.h
// Function: ramulator::DRAM<ramulator::DDR3>::update_serving_requests(int const*, int, long)
void DRAM<T>::update_serving_requests(const int* addr, int delta, long clk) {
  assert(id == addr[int(level)]);
  assert(delta == 1 || delta == -1);
  // update total serving requests
  if (begin_of_cur_reqcnt != -1 && cur_serving_requests > 0) {
    serving_requests += (clk - begin_of_cur_reqcnt) * cur_serving_requests;
    active_cycles += clk - begin_of_cur_reqcnt;
  }
  // update begin of current request number
  begin_of_cur_reqcnt = clk;
  cur_serving_requests += delta;
  assert(cur_serving_requests >= 0);

  if (delta == 1 && cur_serving_requests == 1) {
    // transform from inactive to active
    begin_of_serving = clk;
    if (end_of_refreshing > begin_of_serving) {
      active_refresh_overlap_cycles += end_of_refreshing - begin_of_serving;
    }
  } else if (cur_serving_requests == 0) {
    // transform from active to inactive
    assert(begin_of_serving != -1);
    assert(delta == -1);
    active_cycles += clk - begin_of_cur_reqcnt;
    end_of_serving = clk;

    for (const auto& ref: refresh_intervals) {
      active_refresh_overlap_cycles += min(end_of_serving, ref.second) - ref.first;
    }
    refresh_intervals.clear();
  }

  int child_id = addr[int(level) + 1];
  // We only count the level bank or the level higher than bank
  if (child_id < 0 || !children.size() || (int(level) > int(T::Level::Bank)) ) {
    return;
  }
  children[child_id]->update_serving_requests(addr, delta, clk);
}

// Assembly:
pushq %rbx
movl 0x398(%rdi), %eax
movl 0x39c(%rdi), %r9d
movslq %eax, %r8
cmpl (%rsi,%r8,4), %r9d
jne 0x28d51
cmpl $0x1, %edx
je 0x28bc9
cmpl $-0x1, %edx
jne 0x28dcd
movq 0x418(%rdi), %r10
cmpq $-0x1, %r10
setne %r11b
movl 0x400(%rdi), %ebx
movl %ebx, %r9d
testl %ebx, %ebx
setg %bl
testb %bl, %r11b
je 0x28c1f
movq %rcx, %r11
subq %r10, %r11
xorps %xmm0, %xmm0
cvtsi2sd %r11, %xmm0
imulq %r9, %r11
xorps %xmm1, %xmm1
cvtsi2sd %r11, %xmm1
addsd 0x2d0(%rdi), %xmm1
movsd %xmm1, 0x2d0(%rdi)
addsd 0x70(%rdi), %xmm0
movsd %xmm0, 0x70(%rdi)
movq %rcx, 0x418(%rdi)
addl %edx, %r9d
movl %r9d, 0x400(%rdi)
js 0x28d70
cmpl $0x1, %edx
jne 0x28c6e
cmpl $0x1, %r9d
jne 0x28c6e
movq %rcx, 0x408(%rdi)
movq 0x428(%rdi), %r9
subq %rcx, %r9
jle 0x28c73
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
addsd 0x238(%rdi), %xmm0
movsd %xmm0, 0x238(%rdi)
jmp 0x28c73
testl %r9d, %r9d
je 0x28cc1
movslq 0x4(%rsi,%r8,4), %r8
testq %r8, %r8
js 0x28d4f
cmpl $0x2, %eax
jg 0x28d4f
movq 0x3b0(%rdi), %rax
cmpq %rax, 0x3b8(%rdi)
je 0x28d4f
movq (%rax,%r8,8), %rdi
movl 0x398(%rdi), %eax
movl 0x39c(%rdi), %r9d
movslq %eax, %r8
cmpl (%rsi,%r8,4), %r9d
je 0x28bc9
jmp 0x28d51
cmpq $-0x1, 0x408(%rdi)
je 0x28dae
cmpl $-0x1, %edx
jne 0x28d8f
xorpd %xmm0, %xmm0
addsd 0x70(%rdi), %xmm0
movsd %xmm0, 0x70(%rdi)
movq %rcx, 0x410(%rdi)
movq 0x430(%rdi), %r9
movq 0x438(%rdi), %r10
cmpq %r10, %r9
je 0x28c73
movsd 0x238(%rdi), %xmm0
movq %r9, %r11
movq 0x8(%r11), %rbx
cmpq %rcx, %rbx
cmovgeq %rcx, %rbx
subq (%r11), %rbx
xorps %xmm1, %xmm1
cvtsi2sd %rbx, %xmm1
addsd %xmm1, %xmm0
addq $0x10, %r11
cmpq %r10, %r11
jne 0x28d0f
movsd %xmm0, 0x238(%rdi)
cmpq %r10, %r9
je 0x28c73
movq %r9, 0x438(%rdi)
jmp 0x28c73
popq %rbx
retq
leaq 0x122c00(%rip), %rdi    # 0x14b958
leaq 0x122c10(%rip), %rsi    # 0x14b96f
leaq 0x122c14(%rip), %rcx    # 0x14b97a
movl $0x19a, %edx            # imm = 0x19A
callq 0xb200
leaq 0x122c8a(%rip), %rdi    # 0x14ba01
leaq 0x122bf1(%rip), %rsi    # 0x14b96f
leaq 0x122bf5(%rip), %rcx    # 0x14b97a
movl $0x1a4, %edx            # imm = 0x1A4
callq 0xb200
leaq 0x122c5f(%rip), %rdi    # 0x14b9f5
leaq 0x122bd2(%rip), %rsi    # 0x14b96f
leaq 0x122bd6(%rip), %rcx    # 0x14b97a
movl $0x1af, %edx            # imm = 0x1AF
callq 0xb200
leaq 0x122c66(%rip), %rdi    # 0x14ba1b
leaq 0x122bb3(%rip), %rsi    # 0x14b96f
leaq 0x122bb7(%rip), %rcx    # 0x14b97a
movl $0x1ae, %edx            # imm = 0x1AE
callq 0xb200
leaq 0x122c13(%rip), %rdi    # 0x14b9e7
leaq 0x122b94(%rip), %rsi    # 0x14b96f
leaq 0x122b98(%rip), %rcx    # 0x14b97a
movl $0x19b, %edx            # imm = 0x19B
callq 0xb200