// File: /workspace/github_c_makefile_star2_O3/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 0x76e2
leaq 0xaa3c(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x5e05(%rip), %rdi      # 0xd4cb
movl $0xc, %esi
movl $0x1, %edx
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x32c0
movq %rdi, %r15
leaq 0x48e8(%rip), %rsi      # 0xbfd4
callq 0x5860
testq %rax, %rax
je 0x771d
movsd 0x30(%rax), %xmm0
unpcklps 0x423e(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4246(%rip), %xmm0     # 0xb950
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, (%rsp)
jmp 0x7726
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
leaq 0x423e(%rip), %rsi      # 0xb96b
movq %r15, %rdi
callq 0x5860
leaq 0xba24(%rip), %rax      # 0x13160
movq (%rax), %rax
movl (%rax), %eax
cmpl $0x2, %eax
je 0x7765
cmpl $0x1, %eax
jne 0x777f
leaq 0x487b(%rip), %rsi      # 0xbfcd
movq %r15, %rdi
callq 0x5860
testq %rax, %rax
je 0x778c
movq 0x30(%rax), %rbx
jmp 0x778e
leaq 0x4398(%rip), %rsi      # 0xbb04
movq %r15, %rdi
callq 0x5860
testq %rax, %rax
je 0x77d1
movq 0x30(%rax), %rbx
jmp 0x77d3
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0x7827
xorl %ebx, %ebx
leaq 0x4857(%rip), %rsi      # 0xbfec
movq %r15, %rdi
callq 0x5860
testq %rax, %rax
je 0x77a8
movq 0x30(%rax), %r14
jmp 0x77ab
xorl %r14d, %r14d
leaq 0x4848(%rip), %rsi      # 0xbffa
movq %r15, %rdi
callq 0x5860
testq %rax, %rax
je 0x77c5
movq 0x30(%rax), %r12
jmp 0x77c8
xorl %r12d, %r12d
leaq 0x484b(%rip), %rsi      # 0xc01a
jmp 0x7814
xorl %ebx, %ebx
leaq 0x4361(%rip), %rsi      # 0xbb3b
movq %r15, %rdi
callq 0x5860
testq %rax, %rax
je 0x77ed
movq 0x30(%rax), %r14
jmp 0x77f0
xorl %r14d, %r14d
leaq 0x437b(%rip), %rsi      # 0xbb72
movq %r15, %rdi
callq 0x5860
testq %rax, %rax
je 0x780a
movq 0x30(%rax), %r12
jmp 0x780d
xorl %r12d, %r12d
leaq 0x4373(%rip), %rsi      # 0xbb87
movq %r15, %rdi
callq 0x5860
testq %rax, %rax
je 0x7827
movq 0x30(%rax), %r15
jmp 0x782a
xorl %r15d, %r15d
leaq 0xa8a7(%rip), %rax      # 0x120d8
cmpl $0x0, (%rax)
leaq 0xa8bd(%rip), %r13      # 0x120f8
movq (%r13), %rdi
je 0x78aa
movq %r14, %xmm1
movq 0x40f2(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x40f6(%rip), %xmm3     # 0xb950
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 0x4039(%rip), %xmm0     # 0xb8c8
leaq 0x5c42(%rip), %rsi      # 0xd4d8
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x31c0
movq %rbx, %xmm0
punpckldq 0x4089(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4091(%rip), %xmm0     # 0xb950
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 0x4046(%rip), %xmm0     # 0xb928
leaq 0x5bf8(%rip), %rsi      # 0xd4e1
movq %rbx, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r13), %rdi
movq %r14, %xmm1
punpckldq 0x403c(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4044(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x10(%rsp), %xmm0
mulsd 0x3fa2(%rip), %xmm0     # 0xb8c8
leaq 0x5bf0(%rip), %rsi      # 0xd51d
movq %r14, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r13), %rdi
movq %r12, %xmm1
punpckldq 0x3ff8(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4000(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd 0x3fbf(%rip), %xmm0     # 0xb928
leaq 0x5be0(%rip), %rsi      # 0xd550
movq %r12, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r13), %rdi
movq %r15, %xmm1
punpckldq 0x3fb5(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3fbd(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd 0x3f7c(%rip), %xmm0     # 0xb928
leaq 0x5be5(%rip), %rsi      # 0xd598
movq %r15, %rdx
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x31c0