// File: /workspace/github_c_makefile_star2_O1/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 0x6a73
leaq 0xb69e(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x6681(%rip), %rdi      # 0xd0e5
movl $0x31, %esi
movl $0x1, %edx
callq 0x32c0
leaq 0xc6e6(%rip), %rax      # 0x13160
movq (%rax), %rax
cmpl $0x2, (%rax)
jne 0x6c9b
leaq 0x4ede(%rip), %rsi      # 0xb96b
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6aa0
movq 0x30(%rax), %rbp
jmp 0x6aa2
xorl %ebp, %ebp
leaq 0x5185(%rip), %rsi      # 0xbc2e
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6abc
movq 0x30(%rax), %r13
jmp 0x6abf
xorl %r13d, %r13d
leaq 0x51b4(%rip), %rsi      # 0xbc7a
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6ade
movq 0x30(%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x6ae7
movq $0x0, 0x8(%rsp)
leaq 0x51d9(%rip), %rsi      # 0xbcc7
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6b01
movq 0x30(%rax), %r12
jmp 0x6b04
xorl %r12d, %r12d
leaq 0x520a(%rip), %rsi      # 0xbd15
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6b1e
movq 0x30(%rax), %r15
jmp 0x6b21
xorl %r15d, %r15d
leaq 0x523a(%rip), %rsi      # 0xbd62
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6b3b
movq 0x30(%rax), %r14
jmp 0x6b3e
xorl %r14d, %r14d
testq %rbp, %rbp
je 0x6c9b
testl %ebx, %ebx
je 0x6caa
cmpl $0x1, %ebx
jne 0x6c9b
leaq 0xb599(%rip), %rax      # 0x120f8
movq (%rax), %rdi
xorpd %xmm0, %xmm0
movq %rbp, %xmm2
subq %r12, %r13
jbe 0x6bbd
movq %r13, %xmm1
movq 0x4dc3(%rip), %xmm3     # 0xb940
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x4dc7(%rip), %xmm4     # 0xb950
subpd %xmm4, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4d27(%rip), %xmm0     # 0xb8c8
movdqa %xmm2, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm4, %xmm1
movapd %xmm1, %xmm3
unpckhpd %xmm1, %xmm3            # xmm3 = xmm3[1],xmm1[1]
addsd %xmm1, %xmm3
divsd %xmm3, %xmm0
subq %r15, %r12
movq %r12, %xmm3
movq 0x4d73(%rip), %xmm4     # 0xb940
punpckldq %xmm4, %xmm3    # xmm3 = xmm3[0],xmm4[0],xmm3[1],xmm4[1]
movapd 0x4d77(%rip), %xmm5     # 0xb950
subpd %xmm5, %xmm3
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
addsd %xmm3, %xmm1
movsd 0x4cd7(%rip), %xmm6     # 0xb8c8
mulsd %xmm6, %xmm1
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
subpd %xmm5, %xmm2
movapd %xmm2, %xmm7
unpckhpd %xmm2, %xmm7            # xmm7 = xmm7[1],xmm2[1]
addsd %xmm2, %xmm7
divsd %xmm7, %xmm1
subq %r14, %r15
movq %r15, %xmm3
punpckldq %xmm4, %xmm3    # xmm3 = xmm3[0],xmm4[0],xmm3[1],xmm4[1]
subpd %xmm5, %xmm3
movapd %xmm3, %xmm2
unpckhpd %xmm3, %xmm2            # xmm2 = xmm2[1],xmm3[1]
addsd %xmm3, %xmm2
mulsd %xmm6, %xmm2
divsd %xmm7, %xmm2
movq %r14, %xmm8
punpckldq %xmm4, %xmm8    # xmm8 = xmm8[0],xmm4[0],xmm8[1],xmm4[1]
subpd %xmm5, %xmm8
movapd %xmm8, %xmm3
unpckhpd %xmm8, %xmm3            # xmm3 = xmm3[1],xmm8[1]
addsd %xmm8, %xmm3
mulsd %xmm6, %xmm3
divsd %xmm7, %xmm3
movq 0x8(%rsp), %xmm8
punpckldq %xmm4, %xmm8    # xmm8 = xmm8[0],xmm4[0],xmm8[1],xmm4[1]
subpd %xmm5, %xmm8
movapd %xmm8, %xmm4
unpckhpd %xmm8, %xmm4            # xmm4 = xmm4[1],xmm8[1]
addsd %xmm8, %xmm4
mulsd %xmm6, %xmm4
divsd %xmm7, %xmm4
leaq 0x6491(%rip), %rsi      # 0xd117
movb $0x5, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb447(%rip), %rbx      # 0x120f8
movq (%rbx), %rdi
movq 0x8(%rsp), %rax
addq %r13, %rax
movq %rax, %xmm1
movq 0x4c77(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x4c7b(%rip), %xmm3     # 0xb950
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4bdb(%rip), %xmm0     # 0xb8c8
movq %rbp, %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 0x641f(%rip), %rsi      # 0xd136
movq %rbp, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %r13, %rax
subq %r12, %rax
ja 0x6d32
xorpd %xmm0, %xmm0
jmp 0x6d61
movq %rax, %xmm1
punpckldq 0x4c01(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4c09(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4b6d(%rip), %xmm0     # 0xb8c8
divsd 0x10(%rsp), %xmm0
leaq 0x6404(%rip), %rsi      # 0xd16c
movq %r13, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %r12, %rax
subq %r15, %rax
movq %rax, %xmm1
movq 0x4bb8(%rip), %xmm0     # 0xb940
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x4bbc(%rip), %xmm0     # 0xb950
subpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x4b1c(%rip), %xmm1     # 0xb8c8
mulsd %xmm1, %xmm0
divsd 0x10(%rsp), %xmm0
leaq 0x63df(%rip), %rsi      # 0xd19c
movq %r12, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %r15, %rax
subq %r14, %rax
movq %rax, %xmm1
punpckldq 0x4b63(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4b6b(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4acf(%rip), %xmm0     # 0xb8c8
divsd 0x10(%rsp), %xmm0
leaq 0x63c6(%rip), %rsi      # 0xd1cc
movq %r15, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq %r14, %xmm1
punpckldq 0x4b20(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4b28(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4a8c(%rip), %xmm0     # 0xb8c8
divsd 0x10(%rsp), %xmm0
leaq 0x63b3(%rip), %rsi      # 0xd1fc
movq %r14, %rdx
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq 0x8(%rsp), %rdx
movq %rdx, %xmm1
punpckldq 0x4ad8(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4ae0(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4a44(%rip), %xmm0     # 0xb8c8
divsd 0x10(%rsp), %xmm0
leaq 0x639d(%rip), %rsi      # 0xd22e
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0