// File: /workspace/github_c_makefile_star2_O3/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 0x6a3e
leaq 0xb6d3(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x66b6(%rip), %rdi      # 0xd0e5
movl $0x31, %esi
movl $0x1, %edx
callq 0x32c0
leaq 0xc71b(%rip), %rax      # 0x13160
movq (%rax), %rax
cmpl $0x2, (%rax)
jne 0x6b7d
leaq 0x4f13(%rip), %rsi      # 0xb96b
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6a6b
movq 0x30(%rax), %r13
jmp 0x6a6e
xorl %r13d, %r13d
leaq 0x51b9(%rip), %rsi      # 0xbc2e
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6a88
movq 0x30(%rax), %rbp
jmp 0x6a8a
xorl %ebp, %ebp
leaq 0x51e9(%rip), %rsi      # 0xbc7a
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6aa9
movq 0x30(%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x6ab2
movq $0x0, 0x8(%rsp)
leaq 0x520e(%rip), %rsi      # 0xbcc7
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6acc
movq 0x30(%rax), %r12
jmp 0x6acf
xorl %r12d, %r12d
leaq 0x523f(%rip), %rsi      # 0xbd15
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6ae9
movq 0x30(%rax), %r15
jmp 0x6aec
xorl %r15d, %r15d
leaq 0x526f(%rip), %rsi      # 0xbd62
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6b06
movq 0x30(%rax), %r14
jmp 0x6b09
xorl %r14d, %r14d
testq %r13, %r13
je 0x6b7d
testl %ebx, %ebx
je 0x6b8c
cmpl $0x1, %ebx
jne 0x6b7d
leaq 0xb5da(%rip), %rax      # 0x120f8
movq (%rax), %rdi
subq %r12, %rbp
jbe 0x6c1b
movq %rbp, %xmm1
movq 0x4e09(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x4e0d(%rip), %xmm3     # 0xb950
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4d6d(%rip), %xmm0     # 0xb8c8
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 0x6c40
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb565(%rip), %rbx      # 0x120f8
movq (%rbx), %rdi
movq 0x8(%rsp), %rax
addq %rbp, %rax
movq %rax, %xmm1
movq 0x4d95(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x4d99(%rip), %xmm3     # 0xb950
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4cf9(%rip), %xmm0     # 0xb8c8
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 0x653d(%rip), %rsi      # 0xd136
movq %r13, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %rbp, %rax
subq %r12, %rax
ja 0x6d0a
xorpd %xmm0, %xmm0
jmp 0x6d39
movq %r13, %xmm0
punpckldq 0x4d18(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4d20(%rip), %xmm0     # 0xb950
movapd %xmm0, %xmm5
unpckhpd %xmm0, %xmm5            # xmm5 = xmm5[1],xmm0[1]
addsd %xmm0, %xmm5
xorpd %xmm0, %xmm0
subq %r15, %r12
movq %r12, %xmm2
movq 0x4cf0(%rip), %xmm4     # 0xb940
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
movapd 0x4cf4(%rip), %xmm6     # 0xb950
subpd %xmm6, %xmm2
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
movsd 0x4c54(%rip), %xmm7     # 0xb8c8
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 0x6422(%rip), %rsi      # 0xd117
movb $0x5, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0
movq %rax, %xmm1
punpckldq 0x4c29(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4c31(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4b95(%rip), %xmm0     # 0xb8c8
divsd 0x10(%rsp), %xmm0
leaq 0x642c(%rip), %rsi      # 0xd16c
movq %rbp, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %r12, %rax
subq %r15, %rax
movq %rax, %xmm1
movq 0x4be0(%rip), %xmm0     # 0xb940
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x4be4(%rip), %xmm0     # 0xb950
subpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x4b44(%rip), %xmm1     # 0xb8c8
mulsd %xmm1, %xmm0
divsd 0x10(%rsp), %xmm0
leaq 0x6407(%rip), %rsi      # 0xd19c
movq %r12, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %r15, %rax
subq %r14, %rax
movq %rax, %xmm1
punpckldq 0x4b8b(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4b93(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4af7(%rip), %xmm0     # 0xb8c8
divsd 0x10(%rsp), %xmm0
leaq 0x63ee(%rip), %rsi      # 0xd1cc
movq %r15, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %r14, %xmm1
punpckldq 0x4b48(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4b50(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4ab4(%rip), %xmm0     # 0xb8c8
divsd 0x10(%rsp), %xmm0
leaq 0x63db(%rip), %rsi      # 0xd1fc
movq %r14, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq 0x8(%rsp), %rdx
movq %rdx, %xmm1
punpckldq 0x4b00(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4b08(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4a6c(%rip), %xmm0     # 0xb8c8
divsd 0x10(%rsp), %xmm0
leaq 0x63c5(%rip), %rsi      # 0xd22e
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0