// File: /workspace/github_cpp_makefile_star2_O2/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 %rax
xorpd %xmm0, %xmm0
movl 0x39c(%rdi), %r8d
movslq 0x398(%rdi), %rax
cmpl (%rsi,%rax,4), %r8d
jne 0x1f559
cmpl $-0x1, %edx
je 0x1f3ed
cmpl $0x1, %edx
jne 0x1f578
movq 0x418(%rdi), %r9
cmpq $-0x1, %r9
setne %r10b
movl 0x400(%rdi), %r11d
movl %r11d, %r8d
testl %r11d, %r11d
setg %r11b
andb %r10b, %r11b
cmpb $0x1, %r11b
jne 0x1f444
movq %rcx, %r10
subq %r9, %r10
cvtsi2sd %r10, %xmm1
imulq %r8, %r10
cvtsi2sd %r10, %xmm2
addsd 0x2d0(%rdi), %xmm2
movsd %xmm2, 0x2d0(%rdi)
addsd 0x70(%rdi), %xmm1
movsd %xmm1, 0x70(%rdi)
movq %rcx, 0x418(%rdi)
addl %edx, %r8d
movl %r8d, 0x400(%rdi)
js 0x1f53a
cmpl $0x1, %edx
jne 0x1f494
cmpl $0x1, %r8d
jne 0x1f494
movq %rcx, 0x408(%rdi)
movq 0x428(%rdi), %r8
subq %rcx, %r8
jle 0x1f510
cvtsi2sd %r8, %xmm1
addsd 0x238(%rdi), %xmm1
movsd %xmm1, 0x238(%rdi)
jmp 0x1f510
testl %r8d, %r8d
jne 0x1f510
cmpq $-0x1, 0x408(%rdi)
je 0x1f5b6
cmpl $-0x1, %edx
jne 0x1f597
movsd 0x70(%rdi), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x70(%rdi)
movq %rcx, 0x410(%rdi)
movq 0x430(%rdi), %r8
movq 0x438(%rdi), %r9
movq %r8, %r10
cmpq %r9, %r10
je 0x1f504
movq 0x8(%r10), %r11
cmpq %rcx, %r11
cmovgeq %rcx, %r11
subq (%r10), %r11
cvtsi2sd %r11, %xmm1
addsd 0x238(%rdi), %xmm1
movsd %xmm1, 0x238(%rdi)
addq $0x10, %r10
jmp 0x1f4d6
cmpq %r8, %r9
je 0x1f510
movq %r8, 0x438(%rdi)
movslq 0x4(%rsi,%rax,4), %r8
testq %r8, %r8
js 0x1f538
cmpl $0x2, %eax
jg 0x1f538
movq 0x3b0(%rdi), %rax
cmpq %rax, 0x3b8(%rdi)
je 0x1f538
movq (%rax,%r8,8), %rdi
jmp 0x1f3c7
popq %rax
retq
leaq 0xb343c(%rip), %rdi     # 0xd297d
leaq 0xb33a3(%rip), %rsi     # 0xd28eb
leaq 0xb33a7(%rip), %rcx     # 0xd28f6
movl $0x1a4, %edx            # imm = 0x1A4
callq 0xb210
leaq 0xb3374(%rip), %rdi     # 0xd28d4
leaq 0xb3384(%rip), %rsi     # 0xd28eb
leaq 0xb3388(%rip), %rcx     # 0xd28f6
movl $0x19a, %edx            # imm = 0x19A
callq 0xb210
leaq 0xb33e4(%rip), %rdi     # 0xd2963
leaq 0xb3365(%rip), %rsi     # 0xd28eb
leaq 0xb3369(%rip), %rcx     # 0xd28f6
movl $0x19b, %edx            # imm = 0x19B
callq 0xb210
leaq 0xb33d3(%rip), %rdi     # 0xd2971
leaq 0xb3346(%rip), %rsi     # 0xd28eb
leaq 0xb334a(%rip), %rcx     # 0xd28f6
movl $0x1af, %edx            # imm = 0x1AF
callq 0xb210
leaq 0xb33da(%rip), %rdi     # 0xd2997
leaq 0xb3327(%rip), %rsi     # 0xd28eb
leaq 0xb332b(%rip), %rcx     # 0xd28f6
movl $0x1ae, %edx            # imm = 0x1AE
callq 0xb210
nop