// File: /workspace/github_c_makefile_star2_O2/mvermeulen[P]wspy/topdown.c
// Function: print_topdown_fe
void print_topdown_fe(struct counter_group *cgroup,enum output_format oformat,int mask){
  unsigned long instructions=0;
  unsigned long icache_miss=0;
  unsigned long icache_access=0;
  unsigned long itlb1=0;
  unsigned long itlb2=0;
  unsigned long tlb_flush=0;
  
  struct counter_info *cinfo;

  if (oformat == PRINT_CSV_HEADER){
    fprintf(outfile,"icache,itlb1,itlb2,tlbflush,");
  }

  switch(cpu_info->vendor){
  case VENDOR_INTEL:
    return;
    break;
  case VENDOR_AMD:
    if (cinfo = find_ci_label(cgroup,"instructions")) instructions = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"ic_tag_hit_miss.instruction_cache_miss")) icache_miss = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"ic_tag_hit_miss.instruction_cache_accesses")) icache_access = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"bp_l1_tlb_miss_l2_tlb_hit")) itlb1 = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"bp_l1_tlb_miss_l2_tlb_miss.all")) itlb2 = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"ls_tlb_flush.all")) tlb_flush = cinfo->value;
    break;
  default:
    return;
  }

  if (instructions){
    switch(oformat){
    case PRINT_CSV:
      if (icache_access)
	fprintf(outfile,"%4.1f,",(double) icache_miss / icache_access*100);
      else
	fprintf(outfile,"0.0");
      fprintf(outfile,"%4.3f",(double) (itlb1 + itlb2)*1000.0 / instructions);
      fprintf(outfile,"%4.3f",(double) itlb2*1000.0 / instructions);
      fprintf(outfile,"%4.3f",(double) tlb_flush*1000.0 / instructions);
      break;
    case PRINT_NORMAL:
      fprintf(outfile,"instructions         %-14lu #\n",instructions);
      fprintf(outfile,"icache               %-14lu # %4.3f icache per 1000 inst\n",
	      icache_access,(double) icache_access * 1000 / instructions);
      fprintf(outfile,"icache miss          %-14lu # %4.1f%% icache miss rate\n",
	      icache_miss,(double) icache_miss / icache_access*100.0);
      fprintf(outfile,"l1 iTLB miss         %-14lu # %4.3f L1 iTLB per 1000 inst\n",
	      itlb1+itlb2,(double) (itlb1+itlb2)*1000/instructions);
      fprintf(outfile,"l2 iTLB miss         %-14lu # %4.3f L2 iTLB per 1000 inst\n",
	      itlb2,(double) itlb2*1000/instructions);
      fprintf(outfile,"tlb flush            %-14lu # %4.3f TLB flush per 1000 inst\n",
	      tlb_flush,(double) tlb_flush*1000/instructions);      
      break;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebp
movq %rdi, %r14
cmpl $0x2, %esi
jne 0x6da1
leaq 0xa37c(%rip), %rax      # 0x11108
movq (%rax), %rcx
leaq 0x54cb(%rip), %rdi      # 0xc261
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x32d0
leaq 0xb3c8(%rip), %rax      # 0x12170
movq (%rax), %rax
cmpl $0x1, (%rax)
jne 0x6efb
leaq 0x4219(%rip), %rsi      # 0xafd4
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x6dce
movq 0x30(%rax), %r15
jmp 0x6dd1
xorl %r15d, %r15d
leaq 0x460d(%rip), %rsi      # 0xb3e5
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x6deb
movq 0x30(%rax), %r13
jmp 0x6dee
xorl %r13d, %r13d
leaq 0x462e(%rip), %rsi      # 0xb423
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x6e08
movq 0x30(%rax), %rbx
jmp 0x6e0a
xorl %ebx, %ebx
leaq 0x4654(%rip), %rsi      # 0xb465
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x6e24
movq 0x30(%rax), %r12
jmp 0x6e27
xorl %r12d, %r12d
leaq 0x465c(%rip), %rsi      # 0xb48a
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x6e46
movq 0x30(%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x6e4f
movq $0x0, 0x8(%rsp)
leaq 0x465d(%rip), %rsi      # 0xb4b3
movq %r14, %rdi
callq 0x576f
testq %rax, %rax
je 0x6e69
movq 0x30(%rax), %rax
jmp 0x6e6b
xorl %eax, %eax
testq %r15, %r15
je 0x6efb
testl %ebp, %ebp
je 0x6f0a
cmpl $0x1, %ebp
jne 0x6efb
movq %rax, %rbp
leaq 0xa27d(%rip), %r14      # 0x11108
movq (%r14), %rcx
testq %rbx, %rbx
je 0x70c4
movq %r13, %xmm1
movq 0x3a9c(%rip), %xmm2     # 0xa940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3aa0(%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 0x39e3(%rip), %xmm0     # 0xa8c8
leaq 0x5243(%rip), %rsi      # 0xc12f
movq %rcx, %rdi
movb $0x1, %al
callq 0x31c0
jmp 0x70d6
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa1f7(%rip), %r14      # 0x11108
movq (%r14), %rdi
leaq 0x536d(%rip), %rsi      # 0xc288
movq %rax, %rbp
movq %r15, %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
movq %rbx, %xmm0
movq 0x3a08(%rip), %xmm1     # 0xa940
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movdqa %xmm1, %xmm2
movapd 0x3a08(%rip), %xmm1     # 0xa950
subpd %xmm1, %xmm0
movapd %xmm1, %xmm3
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movapd %xmm1, %xmm0
mulsd 0x39ba(%rip), %xmm0     # 0xa928
movq %r15, %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 0x530f(%rip), %rsi      # 0xc2a7
movq %rbx, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %r13, %xmm1
punpckldq 0x398e(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3996(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x20(%rsp), %xmm0
mulsd 0x38f4(%rip), %xmm0     # 0xa8c8
leaq 0x5306(%rip), %rsi      # 0xc2e1
movq %r13, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq 0x8(%rsp), %rbx
addq %rbx, %r12
movq %r12, %xmm1
punpckldq 0x3943(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x394b(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x390f(%rip), %xmm0     # 0xa928
divsd 0x10(%rsp), %xmm0
leaq 0x52f3(%rip), %rsi      # 0xc319
movq %r12, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %rbx, %xmm1
punpckldq 0x3900(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3908(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x38cc(%rip), %xmm0     # 0xa928
divsd 0x10(%rsp), %xmm0
leaq 0x52eb(%rip), %rsi      # 0xc354
movq %rbx, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %rbp, %xmm1
punpckldq 0x38bd(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x38c5(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3889(%rip), %xmm0     # 0xa928
divsd 0x10(%rsp), %xmm0
leaq 0x52e3(%rip), %rsi      # 0xc38f
movq %rbp, %rdx
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0
leaq 0x51b3(%rip), %rdi      # 0xc27e
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
callq 0x32d0
movq (%r14), %rdi
movq 0x8(%rsp), %r13
addq %r13, %r12
movq %r12, %xmm1
movq 0x3852(%rip), %xmm0     # 0xa940
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movdqa %xmm0, %xmm2
movapd 0x3852(%rip), %xmm0     # 0xa950
subpd %xmm0, %xmm1
movapd %xmm0, %xmm3
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x380e(%rip), %xmm0     # 0xa928
movq %r15, %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 0x513e(%rip), %rbx      # 0xc282
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %r13, %xmm1
punpckldq 0x37e2(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x37ea(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x37ae(%rip), %xmm0     # 0xa928
divsd 0x10(%rsp), %xmm0
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %rbp, %xmm1
punpckldq 0x37a6(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x37ae(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3772(%rip), %xmm0     # 0xa928
divsd 0x10(%rsp), %xmm0
movq %rbx, %rsi
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0