// File: /workspace/github_c_makefile_star2_O2/mvermeulen[P]wspy/topdown.c
// Function: print_memory
void print_memory(struct counter_group *cgroup,enum output_format oformat){
  unsigned long data_cache_local=0;
  unsigned long data_cache_remote=0;
  unsigned long prefetch_local=0;
  unsigned long prefetch_remote=0;
  struct counter_info *cinfo;
  double elapsed = finish_time.tv_sec + finish_time.tv_nsec / 1000000000.0 -
    start_time.tv_sec - start_time.tv_nsec / 1000000000.0;    

  if (oformat == PRINT_CSV_HEADER){
    fprintf(outfile,"bandwidth,");
    return;
  }  

  switch(cpu_info->vendor){
  case VENDOR_INTEL:
    break;
  case VENDOR_AMD:
    if (cinfo = find_ci_label(cgroup,"ls_data_cache_refills.local_all"))
      data_cache_local = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"ls_data_cache_refills.remote_all"))
      data_cache_remote = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"ls_hwpref_data_cache_refills.local_all"))
      prefetch_local = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"ls_hwpref_data_cache_refills.remote_all"))
      prefetch_remote = cinfo->value;        
    break;
  default:
    return;
  }

  if (csvflag){
    fprintf(outfile,"%4.1f,",(double) (data_cache_local+data_cache_remote+prefetch_local+prefetch_remote)*64.0/1024/1024/elapsed);
  } else {
    fprintf(outfile,"local bandwidth      %-14lu # %4.1f MB/s\n",
	    data_cache_local+prefetch_local,
	    (double)(data_cache_local+prefetch_local)*64.0/1024.0/1024.0/elapsed);
    fprintf(outfile,"remote bandwidth     %-14lu # %4.1f MB/s\n",
	    data_cache_remote+prefetch_remote,
	    (double)(data_cache_remote+prefetch_remote)*64.0/1024.0/1024.0/elapsed);
  }  
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
cmpl $0x2, %esi
jne 0x7ee6
leaq 0x9244(%rip), %rax      # 0x11108
movq (%rax), %rcx
leaq 0x491c(%rip), %rdi      # 0xc7ea
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x32d0
cvtsi2sdq 0xa261(%rip), %xmm3 # 0x12150
cvtsi2sdq 0xa260(%rip), %xmm2 # 0x12158
cvtsi2sdq 0xa25f(%rip), %xmm4 # 0x12160
cvtsi2sdq 0xa25e(%rip), %xmm1 # 0x12168
leaq 0xa25f(%rip), %rax      # 0x12170
movq (%rax), %rax
movl (%rax), %eax
cmpl $0x2, %eax
je 0x7f51
cmpl $0x1, %eax
jne 0x7f5e
movq %rdi, %r14
movsd %xmm4, 0x8(%rsp)
movsd %xmm3, 0x10(%rsp)
movsd %xmm1, 0x18(%rsp)
movsd %xmm2, (%rsp)
leaq 0x324b(%rip), %rsi      # 0xb18c
callq 0x576f
testq %rax, %rax
je 0x7f6c
movq 0x30(%rax), %rbx
jmp 0x7f6e
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %ebx, %ebx
jmp 0x7fdc
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorl %ebx, %ebx
leaq 0x324c(%rip), %rsi      # 0xb1c1
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x7f88
movq 0x30(%rax), %r15
jmp 0x7f8b
xorl %r15d, %r15d
leaq 0x3266(%rip), %rsi      # 0xb1f8
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x7fa5
movq 0x30(%rax), %r12
jmp 0x7fa8
xorl %r12d, %r12d
leaq 0x3285(%rip), %rsi      # 0xb234
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x7fc2
movq 0x30(%rax), %r14
jmp 0x7fc5
xorl %r14d, %r14d
movsd (%rsp), %xmm2
movsd 0x18(%rsp), %xmm1
movsd 0x10(%rsp), %xmm3
movsd 0x8(%rsp), %xmm4
movsd 0x2204(%rip), %xmm0     # 0xa1e8
divsd %xmm0, %xmm2
addsd %xmm3, %xmm2
subsd %xmm4, %xmm2
divsd %xmm0, %xmm1
subsd %xmm1, %xmm2
leaq 0x90e9(%rip), %rax      # 0x110e8
cmpl $0x0, (%rax)
leaq 0x90ff(%rip), %r13      # 0x11108
movq (%r13), %rdi
je 0x8070
addq %r15, %r14
addq %rbx, %r12
addq %r14, %r12
movq %r12, %xmm1
punpckldq 0x291b(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x2923(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x28ef(%rip), %xmm0     # 0xa930
movsd 0x28ef(%rip), %xmm1     # 0xa938
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x40d3(%rip), %rsi      # 0xc12f
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x31c0
addq %r12, %rbx
movq %rbx, %xmm1
punpckldq 0x28c0(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x28c8(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x2894(%rip), %xmm0     # 0xa930
movsd 0x2894(%rip), %xmm1     # 0xa938
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x473e(%rip), %rsi      # 0xc7f5
movq %rbx, %rdx
movb $0x1, %al
movsd %xmm2, (%rsp)
callq 0x31c0
movq (%r13), %rdi
addq %r15, %r14
movq %r14, %xmm1
punpckldq 0x2866(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x286e(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x283a(%rip), %xmm0     # 0xa930
movsd 0x283a(%rip), %xmm1     # 0xa938
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd (%rsp), %xmm0
leaq 0x470d(%rip), %rsi      # 0xc81f
movq %r14, %rdx
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x31c0