// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
cmpl $0x2, -0xc(%rbp)
jne 0x9695
leaq 0x9a89(%rip), %rax      # 0x13108
movq (%rax), %rdi
leaq 0x5e34(%rip), %rsi      # 0xf4bd
movb $0x0, %al
callq 0x31d0
jmp 0x9a67
movq -0x8(%rbp), %rdi
leaq 0x4924(%rip), %rsi      # 0xdfc4
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x96bb
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x4295(%rip), %rsi      # 0xd95b
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x96e1
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x28(%rbp)
leaq 0xaa88(%rip), %rax      # 0x14170
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
subl $0x1, %eax
je 0x9708
jmp 0x96f7
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0x97a5
jmp 0x983f
movq -0x8(%rbp), %rdi
leaq 0x48aa(%rip), %rsi      # 0xdfbd
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x972e
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x48a3(%rip), %rsi      # 0xdfdc
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x9754
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x488b(%rip), %rsi      # 0xdfea
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x977a
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x4885(%rip), %rsi      # 0xe00a
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x97a0
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x983f
movq -0x8(%rbp), %rdi
leaq 0x4344(%rip), %rsi      # 0xdaf4
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x97cb
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x4355(%rip), %rsi      # 0xdb2b
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x97f1
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x4366(%rip), %rsi      # 0xdb62
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x9817
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x4355(%rip), %rsi      # 0xdb77
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x983d
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x983f
leaq 0x98a2(%rip), %rax      # 0x130e8
cmpl $0x0, (%rax)
je 0x98b7
leaq 0x98b6(%rip), %rax      # 0x13108
movq (%rax), %rdi
movq -0x38(%rbp), %xmm0
movaps 0x40cf(%rip), %xmm3     # 0xd930
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x40d3(%rip), %xmm2     # 0xd940
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x30(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd 0x4010(%rip), %xmm1     # 0xd8b0
mulsd %xmm1, %xmm0
leaq 0x5c1f(%rip), %rsi      # 0xf4ca
movb $0x1, %al
callq 0x31d0
jmp 0x9a67
leaq 0x984a(%rip), %rax      # 0x13108
movq %rax, -0x58(%rbp)
movq (%rax), %rdi
movq -0x30(%rbp), %rdx
movq %rdx, %xmm0
movaps 0x405b(%rip), %xmm3     # 0xd930
movaps %xmm3, -0x80(%rbp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x405b(%rip), %xmm2     # 0xd940
movaps %xmm2, -0x70(%rbp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x20(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd 0x3ff4(%rip), %xmm1     # 0xd910
movsd %xmm1, -0x90(%rbp)
mulsd %xmm1, %xmm0
leaq 0x5ba4(%rip), %rsi      # 0xf4d3
movb $0x1, %al
movb %al, -0x81(%rbp)
callq 0x31d0
movq -0x58(%rbp), %rcx
movaps -0x80(%rbp), %xmm3
movaps -0x70(%rbp), %xmm2
movb -0x81(%rbp), %al
movq (%rcx), %rdi
movq -0x38(%rbp), %rdx
movq %rdx, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x30(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd 0x3f1f(%rip), %xmm1     # 0xd8b0
mulsd %xmm1, %xmm0
leaq 0x5b73(%rip), %rsi      # 0xf50f
callq 0x31d0
movsd -0x90(%rbp), %xmm1
movq -0x58(%rbp), %rcx
movaps -0x80(%rbp), %xmm4
movaps -0x70(%rbp), %xmm3
movb -0x81(%rbp), %al
movq (%rcx), %rdi
movq -0x40(%rbp), %rdx
movq %rdx, %xmm0
punpckldq %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
subpd %xmm3, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
movq -0x20(%rbp), %xmm2
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
subpd %xmm3, %xmm2
movaps %xmm2, %xmm3
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm3, %xmm2
divsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
leaq 0x5b41(%rip), %rsi      # 0xf542
callq 0x31d0
movaps -0x80(%rbp), %xmm3
movaps -0x70(%rbp), %xmm2
movq -0x58(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rdx
movq %rdx, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x20(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd 0x3ebb(%rip), %xmm1     # 0xd910
mulsd %xmm1, %xmm0
leaq 0x5b2a(%rip), %rsi      # 0xf58a
movb $0x1, %al
callq 0x31d0
addq $0x90, %rsp
popq %rbp
retq