// File: /workspace/github_c_makefile_star2_O1/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 0x770a
leaq 0xaa14(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x5ddd(%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 0x48c0(%rip), %rsi      # 0xbfd4
callq 0x587d
testq %rax, %rax
je 0x7745
movsd 0x30(%rax), %xmm0
unpcklps 0x4216(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x421e(%rip), %xmm0     # 0xb950
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, (%rsp)
jmp 0x774e
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
leaq 0x4216(%rip), %rsi      # 0xb96b
movq %r15, %rdi
callq 0x587d
leaq 0xb9fc(%rip), %rax      # 0x13160
movq (%rax), %rax
movl (%rax), %eax
cmpl $0x2, %eax
je 0x778d
cmpl $0x1, %eax
jne 0x77a7
leaq 0x4853(%rip), %rsi      # 0xbfcd
movq %r15, %rdi
callq 0x587d
testq %rax, %rax
je 0x77b4
movq 0x30(%rax), %rbx
jmp 0x77b6
leaq 0x4370(%rip), %rsi      # 0xbb04
movq %r15, %rdi
callq 0x587d
testq %rax, %rax
je 0x77f9
movq 0x30(%rax), %rbx
jmp 0x77fb
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0x784f
xorl %ebx, %ebx
leaq 0x482f(%rip), %rsi      # 0xbfec
movq %r15, %rdi
callq 0x587d
testq %rax, %rax
je 0x77d0
movq 0x30(%rax), %r14
jmp 0x77d3
xorl %r14d, %r14d
leaq 0x4820(%rip), %rsi      # 0xbffa
movq %r15, %rdi
callq 0x587d
testq %rax, %rax
je 0x77ed
movq 0x30(%rax), %r12
jmp 0x77f0
xorl %r12d, %r12d
leaq 0x4823(%rip), %rsi      # 0xc01a
jmp 0x783c
xorl %ebx, %ebx
leaq 0x4339(%rip), %rsi      # 0xbb3b
movq %r15, %rdi
callq 0x587d
testq %rax, %rax
je 0x7815
movq 0x30(%rax), %r14
jmp 0x7818
xorl %r14d, %r14d
leaq 0x4353(%rip), %rsi      # 0xbb72
movq %r15, %rdi
callq 0x587d
testq %rax, %rax
je 0x7832
movq 0x30(%rax), %r12
jmp 0x7835
xorl %r12d, %r12d
leaq 0x434b(%rip), %rsi      # 0xbb87
movq %r15, %rdi
callq 0x587d
testq %rax, %rax
je 0x784f
movq 0x30(%rax), %r15
jmp 0x7852
xorl %r15d, %r15d
leaq 0xa87f(%rip), %rax      # 0x120d8
cmpl $0x0, (%rax)
leaq 0xa895(%rip), %r13      # 0x120f8
movq (%r13), %rdi
je 0x78d2
movq %r14, %xmm1
movq 0x40ca(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x40ce(%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 0x4011(%rip), %xmm0     # 0xb8c8
leaq 0x5c1a(%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 0x4061(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4069(%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 0x401e(%rip), %xmm0     # 0xb928
leaq 0x5bd0(%rip), %rsi      # 0xd4e1
movq %rbx, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r13), %rdi
movq %r14, %xmm1
punpckldq 0x4014(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x401c(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x10(%rsp), %xmm0
mulsd 0x3f7a(%rip), %xmm0     # 0xb8c8
leaq 0x5bc8(%rip), %rsi      # 0xd51d
movq %r14, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r13), %rdi
movq %r12, %xmm1
punpckldq 0x3fd0(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3fd8(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd 0x3f97(%rip), %xmm0     # 0xb928
leaq 0x5bb8(%rip), %rsi      # 0xd550
movq %r12, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r13), %rdi
movq %r15, %xmm1
punpckldq 0x3f8d(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3f95(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd 0x3f54(%rip), %xmm0     # 0xb928
leaq 0x5bbd(%rip), %rsi      # 0xd598
movq %r15, %rdx
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x31c0