// File: /workspace/github_c_makefile_star2_O2/mvermeulen[P]wspy/topdown.c
// Function: print_topdown_be
void print_topdown_be(struct counter_group *cgroup,enum output_format oformat,int mask){
  unsigned long cpu_cycles=0;
  unsigned long load_stall=0;
  unsigned long store_stall=0;  
  unsigned long l1_miss=0;
  unsigned long l2_miss=0;
  unsigned long l3_miss=0;
  
  struct counter_info *cinfo;

  if (oformat == PRINT_CSV_HEADER){
    fprintf(outfile,"l1_bound,l2_bound,l3_bound,dram_bound,store_bound");
  }

  switch(cpu_info->vendor){
  case VENDOR_INTEL:
    if (cinfo = find_ci_label(cgroup,"cpu-cycles")) cpu_cycles = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"exe_activity.bound_on_loads")) load_stall = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"exe_activity.bound_on_stores")) store_stall = cinfo->value;    
    if (cinfo = find_ci_label(cgroup,"memory_activity.stalls_l1d_miss")) l1_miss = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"memory_activity.stalls_l2_miss")) l2_miss = cinfo->value;    
    if (cinfo = find_ci_label(cgroup,"memory_activity.stalls_l3_miss")) l3_miss = cinfo->value;
    break;
  case VENDOR_AMD:
    return;
  default:
    return;
  }

  if (cpu_cycles){
    switch(oformat){
    case PRINT_CSV:
      fprintf(outfile,"%4.1f,%4.1f,%4.1f,%4.1f,%4.1f,",
	      (double) (load_stall > l1_miss)?(load_stall - l1_miss)*100.0/cpu_cycles:0,
	      (double) (l1_miss - l2_miss)*100.0/cpu_cycles,
	      (double) (l2_miss - l3_miss)*100.0/cpu_cycles,
	      (double) l3_miss*100.0/cpu_cycles,
	      (double) store_stall*100.0/cpu_cycles);
      break;
    case PRINT_NORMAL:
      fprintf(outfile,"cpu-cycles           %-14lu # %4.1f%% memory latency\n",
	      cpu_cycles,(double) (load_stall+store_stall)*100.0/cpu_cycles);
      fprintf(outfile,"load stalls          %-14lu # %4.1f%% l1 bound\n",
	      load_stall,(load_stall>l1_miss)?(load_stall - l1_miss)*100.0/cpu_cycles:0);
      fprintf(outfile,"l1 miss              %-14lu # %4.1f%% l2 bound\n",
	      l1_miss,(double) (l1_miss - l2_miss)*100.0/cpu_cycles);
      fprintf(outfile,"l2 miss              %-14lu # %4.1f%% l3 bound\n",
	      l2_miss,(double) (l2_miss - l3_miss)*100.0/cpu_cycles);      
      fprintf(outfile,"l3 miss              %-14lu # %4.1f%% dram bound\n",
	      l3_miss,(double) l3_miss*100.0/cpu_cycles);
      fprintf(outfile,"store_stalls         %-14lu # %4.1f%% store bound\n",
	      store_stall,(double) store_stall*100.0/cpu_cycles);      
      break;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebx
movq %rdi, %r14
cmpl $0x2, %esi
jne 0x692d
leaq 0xa7f0(%rip), %rax      # 0x11108
movq (%rax), %rcx
leaq 0x57c3(%rip), %rdi      # 0xc0e5
pushq $0x31
popq %rsi
pushq $0x1
popq %rdx
callq 0x32d0
leaq 0xb83c(%rip), %rax      # 0x12170
movq (%rax), %rax
cmpl $0x2, (%rax)
jne 0x6a6c
leaq 0x4024(%rip), %rsi      # 0xa96b
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x695a
movq 0x30(%rax), %r13
jmp 0x695d
xorl %r13d, %r13d
leaq 0x42ca(%rip), %rsi      # 0xac2e
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x6977
movq 0x30(%rax), %rbp
jmp 0x6979
xorl %ebp, %ebp
leaq 0x42fa(%rip), %rsi      # 0xac7a
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x6998
movq 0x30(%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x69a1
movq $0x0, 0x8(%rsp)
leaq 0x431f(%rip), %rsi      # 0xacc7
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x69bb
movq 0x30(%rax), %r12
jmp 0x69be
xorl %r12d, %r12d
leaq 0x4350(%rip), %rsi      # 0xad15
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x69d8
movq 0x30(%rax), %r15
jmp 0x69db
xorl %r15d, %r15d
leaq 0x4380(%rip), %rsi      # 0xad62
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x69f5
movq 0x30(%rax), %r14
jmp 0x69f8
xorl %r14d, %r14d
testq %r13, %r13
je 0x6a6c
testl %ebx, %ebx
je 0x6a7b
cmpl $0x1, %ebx
jne 0x6a6c
leaq 0xa6fb(%rip), %rax      # 0x11108
movq (%rax), %rdi
subq %r12, %rbp
jbe 0x6b0a
movq %rbp, %xmm1
movq 0x3f1a(%rip), %xmm2     # 0xa940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3f1e(%rip), %xmm3     # 0xa950
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3e7e(%rip), %xmm0     # 0xa8c8
movq %r13, %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm5
unpckhpd %xmm1, %xmm5            # xmm5 = xmm5[1],xmm1[1]
addsd %xmm1, %xmm5
divsd %xmm5, %xmm0
jmp 0x6b2f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa686(%rip), %rbx      # 0x11108
movq (%rbx), %rdi
movq 0x8(%rsp), %rax
addq %rbp, %rax
movq %rax, %xmm1
movq 0x3ea6(%rip), %xmm2     # 0xa940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3eaa(%rip), %xmm3     # 0xa950
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3e0a(%rip), %xmm0     # 0xa8c8
movq %r13, %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
movapd %xmm2, 0x10(%rsp)
divsd %xmm2, %xmm0
leaq 0x564e(%rip), %rsi      # 0xc136
movq %r13, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %rbp, %rax
subq %r12, %rax
ja 0x6bf9
xorpd %xmm0, %xmm0
jmp 0x6c28
movq %r13, %xmm0
punpckldq 0x3e29(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3e31(%rip), %xmm0     # 0xa950
movapd %xmm0, %xmm5
unpckhpd %xmm0, %xmm5            # xmm5 = xmm5[1],xmm0[1]
addsd %xmm0, %xmm5
xorpd %xmm0, %xmm0
subq %r15, %r12
movq %r12, %xmm2
movq 0x3e01(%rip), %xmm4     # 0xa940
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
movapd 0x3e05(%rip), %xmm6     # 0xa950
subpd %xmm6, %xmm2
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
movsd 0x3d65(%rip), %xmm7     # 0xa8c8
mulsd %xmm7, %xmm1
divsd %xmm5, %xmm1
subq %r14, %r15
movq %r15, %xmm3
punpckldq %xmm4, %xmm3    # xmm3 = xmm3[0],xmm4[0],xmm3[1],xmm4[1]
subpd %xmm6, %xmm3
movapd %xmm3, %xmm2
unpckhpd %xmm3, %xmm2            # xmm2 = xmm2[1],xmm3[1]
addsd %xmm3, %xmm2
mulsd %xmm7, %xmm2
divsd %xmm5, %xmm2
movq %r14, %xmm8
punpckldq %xmm4, %xmm8    # xmm8 = xmm8[0],xmm4[0],xmm8[1],xmm4[1]
subpd %xmm6, %xmm8
movapd %xmm8, %xmm3
unpckhpd %xmm8, %xmm3            # xmm3 = xmm3[1],xmm8[1]
addsd %xmm8, %xmm3
mulsd %xmm7, %xmm3
divsd %xmm5, %xmm3
movq 0x8(%rsp), %xmm8
punpckldq %xmm4, %xmm8    # xmm8 = xmm8[0],xmm4[0],xmm8[1],xmm4[1]
subpd %xmm6, %xmm8
movapd %xmm8, %xmm4
unpckhpd %xmm8, %xmm4            # xmm4 = xmm4[1],xmm8[1]
addsd %xmm8, %xmm4
mulsd %xmm7, %xmm4
divsd %xmm5, %xmm4
leaq 0x5533(%rip), %rsi      # 0xc117
movb $0x5, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0
movq %rax, %xmm1
punpckldq 0x3d3a(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3d42(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3ca6(%rip), %xmm0     # 0xa8c8
divsd 0x10(%rsp), %xmm0
leaq 0x553d(%rip), %rsi      # 0xc16c
movq %rbp, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %r12, %rax
subq %r15, %rax
movq %rax, %xmm1
movq 0x3cf1(%rip), %xmm0     # 0xa940
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x3cf5(%rip), %xmm0     # 0xa950
subpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x3c55(%rip), %xmm1     # 0xa8c8
mulsd %xmm1, %xmm0
divsd 0x10(%rsp), %xmm0
leaq 0x5518(%rip), %rsi      # 0xc19c
movq %r12, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %r15, %rax
subq %r14, %rax
movq %rax, %xmm1
punpckldq 0x3c9c(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3ca4(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3c08(%rip), %xmm0     # 0xa8c8
divsd 0x10(%rsp), %xmm0
leaq 0x54ff(%rip), %rsi      # 0xc1cc
movq %r15, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %r14, %xmm1
punpckldq 0x3c59(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3c61(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3bc5(%rip), %xmm0     # 0xa8c8
divsd 0x10(%rsp), %xmm0
leaq 0x54ec(%rip), %rsi      # 0xc1fc
movq %r14, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq 0x8(%rsp), %rdx
movq %rdx, %xmm1
punpckldq 0x3c11(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3c19(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3b7d(%rip), %xmm0     # 0xa8c8
divsd 0x10(%rsp), %xmm0
leaq 0x54d6(%rip), %rsi      # 0xc22e
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0