// File: /workspace/github_c_makefile_star2_O3/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 0x8017
leaq 0xa107(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x57ef(%rip), %rdi      # 0xd7ea
movl $0xa, %esi
movl $0x1, %edx
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x32c0
cvtsi2sdq 0xb120(%rip), %xmm3 # 0x13140
cvtsi2sdq 0xb11f(%rip), %xmm2 # 0x13148
cvtsi2sdq 0xb11e(%rip), %xmm4 # 0x13150
cvtsi2sdq 0xb11d(%rip), %xmm1 # 0x13158
leaq 0xb11e(%rip), %rax      # 0x13160
movq (%rax), %rax
movl (%rax), %eax
cmpl $0x2, %eax
je 0x8082
cmpl $0x1, %eax
jne 0x808f
movq %rdi, %r14
movsd %xmm4, 0x8(%rsp)
movsd %xmm3, 0x10(%rsp)
movsd %xmm1, 0x18(%rsp)
movsd %xmm2, (%rsp)
leaq 0x411a(%rip), %rsi      # 0xc18c
callq 0x5860
testq %rax, %rax
je 0x809d
movq 0x30(%rax), %rbx
jmp 0x809f
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %ebx, %ebx
jmp 0x810d
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorl %ebx, %ebx
leaq 0x411b(%rip), %rsi      # 0xc1c1
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x80b9
movq 0x30(%rax), %r15
jmp 0x80bc
xorl %r15d, %r15d
leaq 0x4135(%rip), %rsi      # 0xc1f8
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x80d6
movq 0x30(%rax), %r12
jmp 0x80d9
xorl %r12d, %r12d
leaq 0x4154(%rip), %rsi      # 0xc234
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x80f3
movq 0x30(%rax), %r14
jmp 0x80f6
xorl %r14d, %r14d
movsd (%rsp), %xmm2
movsd 0x18(%rsp), %xmm1
movsd 0x10(%rsp), %xmm3
movsd 0x8(%rsp), %xmm4
movsd 0x30d3(%rip), %xmm0     # 0xb1e8
divsd %xmm0, %xmm2
addsd %xmm3, %xmm2
subsd %xmm4, %xmm2
divsd %xmm0, %xmm1
subsd %xmm1, %xmm2
leaq 0x9fa8(%rip), %rax      # 0x120d8
cmpl $0x0, (%rax)
leaq 0x9fbe(%rip), %r13      # 0x120f8
movq (%r13), %rdi
je 0x81a1
addq %r15, %r14
addq %rbx, %r12
addq %r14, %r12
movq %r12, %xmm1
punpckldq 0x37ea(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x37f2(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x37be(%rip), %xmm0     # 0xb930
movsd 0x37be(%rip), %xmm1     # 0xb938
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x4fa2(%rip), %rsi      # 0xd12f
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 0x378f(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3797(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3763(%rip), %xmm0     # 0xb930
movsd 0x3763(%rip), %xmm1     # 0xb938
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x560d(%rip), %rsi      # 0xd7f5
movq %rbx, %rdx
movb $0x1, %al
movsd %xmm2, (%rsp)
callq 0x31c0
movq (%r13), %rdi
addq %r15, %r14
movq %r14, %xmm1
punpckldq 0x3735(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x373d(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3709(%rip), %xmm0     # 0xb930
movsd 0x3709(%rip), %xmm1     # 0xb938
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd (%rsp), %xmm0
leaq 0x55dc(%rip), %rsi      # 0xd81f
movq %r14, %rdx
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x31c0