// File: /workspace/github_c_makefile_star2_O2/mvermeulen[P]wspy/topdown.c
// Function: print_branch
void print_branch(struct counter_group *cgroup,enum output_format oformat){
  struct counter_info *cinfo;
  unsigned long instructions = 0;
  unsigned long cpu_cycles = 0;
  unsigned long branches = 0;
  unsigned long branch_miss = 0;
  unsigned long cond_branches = 0;
  unsigned long ind_branches = 0;

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

  if (cinfo = find_ci_label(cgroup,"instructions"))
    instructions = cinfo->value;
  if (cinfo = find_ci_label(cgroup,"cpu-cycles"))
    cpu_cycles = cinfo->value;
  switch (cpu_info->vendor){
  case VENDOR_AMD:
    if (cinfo = find_ci_label(cgroup,"branch-instructions"))
      branches = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"branch-misses"))
      branch_miss = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"conditional-branches"))
      cond_branches = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"indirect-branches"))
      ind_branches = cinfo->value;
    break;
  case VENDOR_INTEL:
    if (cinfo = find_ci_label(cgroup,"br_inst_retired.all_branches"))
      branches = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"br_misp_retired.all_branches"))
      branch_miss = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"br_inst_retired.cond"))
      cond_branches = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"br_inst_retired.indirect"))
      ind_branches = cinfo->value;
    break;
    break;
  }
  

  if (csvflag){
      fprintf(outfile,"%4.2f%%,",(double) branch_miss / branches * 100.0);
  } else {
      fprintf(outfile,"branches             %-14lu # %4.3f branches per 1000 inst\n",
	      branches,(double) branches / instructions * 1000.0);
      fprintf(outfile,"branch misses        %-14lu # %4.2f%% branch miss\n",
	      branch_miss, (double) branch_miss / branches * 100.0);
      fprintf(outfile,"conditional          %-14lu # %4.3f conditional branches per 1000 inst\n",
	      cond_branches,(double) cond_branches / instructions * 1000.0);
      fprintf(outfile,"indirect             %-14lu # %4.3f indirect branches per 1000 inst\n",
	      ind_branches,(double) ind_branches / instructions * 1000.0);      
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
cmpl $0x2, %esi
jne 0x75bd
leaq 0x9b6d(%rip), %rax      # 0x11108
movq (%rax), %rcx
leaq 0x4f26(%rip), %rdi      # 0xc4cb
pushq $0xc
popq %rsi
pushq $0x1
popq %rdx
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x32d0
movq %rdi, %r15
leaq 0x3a0d(%rip), %rsi      # 0xafd4
callq 0x576f
testq %rax, %rax
je 0x75f8
movsd 0x30(%rax), %xmm0
unpcklps 0x3363(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x336b(%rip), %xmm0     # 0xa950
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, (%rsp)
jmp 0x7601
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
leaq 0x3363(%rip), %rsi      # 0xa96b
movq %r15, %rdi
callq 0x576f
leaq 0xab59(%rip), %rax      # 0x12170
movq (%rax), %rax
movl (%rax), %eax
cmpl $0x2, %eax
je 0x7640
cmpl $0x1, %eax
jne 0x765a
leaq 0x39a0(%rip), %rsi      # 0xafcd
movq %r15, %rdi
callq 0x576f
testq %rax, %rax
je 0x7667
movq 0x30(%rax), %rbx
jmp 0x7669
leaq 0x34bd(%rip), %rsi      # 0xab04
movq %r15, %rdi
callq 0x576f
testq %rax, %rax
je 0x76ac
movq 0x30(%rax), %rbx
jmp 0x76ae
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0x7702
xorl %ebx, %ebx
leaq 0x397c(%rip), %rsi      # 0xafec
movq %r15, %rdi
callq 0x576f
testq %rax, %rax
je 0x7683
movq 0x30(%rax), %r14
jmp 0x7686
xorl %r14d, %r14d
leaq 0x396d(%rip), %rsi      # 0xaffa
movq %r15, %rdi
callq 0x576f
testq %rax, %rax
je 0x76a0
movq 0x30(%rax), %r12
jmp 0x76a3
xorl %r12d, %r12d
leaq 0x3970(%rip), %rsi      # 0xb01a
jmp 0x76ef
xorl %ebx, %ebx
leaq 0x3486(%rip), %rsi      # 0xab3b
movq %r15, %rdi
callq 0x576f
testq %rax, %rax
je 0x76c8
movq 0x30(%rax), %r14
jmp 0x76cb
xorl %r14d, %r14d
leaq 0x34a0(%rip), %rsi      # 0xab72
movq %r15, %rdi
callq 0x576f
testq %rax, %rax
je 0x76e5
movq 0x30(%rax), %r12
jmp 0x76e8
xorl %r12d, %r12d
leaq 0x3498(%rip), %rsi      # 0xab87
movq %r15, %rdi
callq 0x576f
testq %rax, %rax
je 0x7702
movq 0x30(%rax), %r15
jmp 0x7705
xorl %r15d, %r15d
leaq 0x99dc(%rip), %rax      # 0x110e8
cmpl $0x0, (%rax)
leaq 0x99f2(%rip), %r13      # 0x11108
movq (%r13), %rdi
je 0x7785
movq %r14, %xmm1
movq 0x3217(%rip), %xmm2     # 0xa940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x321b(%rip), %xmm3     # 0xa950
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq %rbx, %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
divsd %xmm2, %xmm0
mulsd 0x315e(%rip), %xmm0     # 0xa8c8
leaq 0x4d67(%rip), %rsi      # 0xc4d8
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x31c0
movq %rbx, %xmm0
punpckldq 0x31ae(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x31b6(%rip), %xmm0     # 0xa950
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd 0x316b(%rip), %xmm0     # 0xa928
leaq 0x4d1d(%rip), %rsi      # 0xc4e1
movq %rbx, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r13), %rdi
movq %r14, %xmm1
punpckldq 0x3161(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3169(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x10(%rsp), %xmm0
mulsd 0x30c7(%rip), %xmm0     # 0xa8c8
leaq 0x4d15(%rip), %rsi      # 0xc51d
movq %r14, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r13), %rdi
movq %r12, %xmm1
punpckldq 0x311d(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3125(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd 0x30e4(%rip), %xmm0     # 0xa928
leaq 0x4d05(%rip), %rsi      # 0xc550
movq %r12, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r13), %rdi
movq %r15, %xmm1
punpckldq 0x30da(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x30e2(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd 0x30a1(%rip), %xmm0     # 0xa928
leaq 0x4d0a(%rip), %rsi      # 0xc598
movq %r15, %rdx
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x31c0