// File: /workspace/github_c_makefile_star2_O3/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 0x6eb6
leaq 0xb25b(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x63ba(%rip), %rdi      # 0xd261
movl $0x1c, %esi
movl $0x1, %edx
callq 0x32c0
leaq 0xc2a3(%rip), %rax      # 0x13160
movq (%rax), %rax
cmpl $0x1, (%rax)
jne 0x7010
leaq 0x5104(%rip), %rsi      # 0xbfd4
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6ee3
movq 0x30(%rax), %r15
jmp 0x6ee6
xorl %r15d, %r15d
leaq 0x54f8(%rip), %rsi      # 0xc3e5
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6f00
movq 0x30(%rax), %r13
jmp 0x6f03
xorl %r13d, %r13d
leaq 0x5519(%rip), %rsi      # 0xc423
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6f1d
movq 0x30(%rax), %rbx
jmp 0x6f1f
xorl %ebx, %ebx
leaq 0x553f(%rip), %rsi      # 0xc465
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6f39
movq 0x30(%rax), %r12
jmp 0x6f3c
xorl %r12d, %r12d
leaq 0x5547(%rip), %rsi      # 0xc48a
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6f5b
movq 0x30(%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x6f64
movq $0x0, 0x8(%rsp)
leaq 0x5548(%rip), %rsi      # 0xc4b3
movq %r14, %rdi
callq 0x5860
testq %rax, %rax
je 0x6f7e
movq 0x30(%rax), %rax
jmp 0x6f80
xorl %eax, %eax
testq %r15, %r15
je 0x7010
testl %ebp, %ebp
je 0x701f
cmpl $0x1, %ebp
jne 0x7010
movq %rax, %rbp
leaq 0xb158(%rip), %r14      # 0x120f8
movq (%r14), %rcx
testq %rbx, %rbx
je 0x71d9
movq %r13, %xmm1
movq 0x4987(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x498b(%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 0x48ce(%rip), %xmm0     # 0xb8c8
leaq 0x612e(%rip), %rsi      # 0xd12f
movq %rcx, %rdi
movb $0x1, %al
callq 0x31c0
jmp 0x71ef
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb0d2(%rip), %r14      # 0x120f8
movq (%r14), %rdi
leaq 0x6258(%rip), %rsi      # 0xd288
movq %rax, %rbp
movq %r15, %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
movq %rbx, %xmm0
movq 0x48f3(%rip), %xmm1     # 0xb940
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movdqa %xmm1, %xmm2
movapd 0x48f3(%rip), %xmm1     # 0xb950
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 0x48a5(%rip), %xmm0     # 0xb928
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 0x61fa(%rip), %rsi      # 0xd2a7
movq %rbx, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %r13, %xmm1
punpckldq 0x4879(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4881(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x20(%rsp), %xmm0
mulsd 0x47df(%rip), %xmm0     # 0xb8c8
leaq 0x61f1(%rip), %rsi      # 0xd2e1
movq %r13, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq 0x8(%rsp), %rbx
addq %rbx, %r12
movq %r12, %xmm1
punpckldq 0x482e(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4836(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x47fa(%rip), %xmm0     # 0xb928
divsd 0x10(%rsp), %xmm0
leaq 0x61de(%rip), %rsi      # 0xd319
movq %r12, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %rbx, %xmm1
punpckldq 0x47eb(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x47f3(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x47b7(%rip), %xmm0     # 0xb928
divsd 0x10(%rsp), %xmm0
leaq 0x61d6(%rip), %rsi      # 0xd354
movq %rbx, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %rbp, %xmm1
punpckldq 0x47a8(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x47b0(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4774(%rip), %xmm0     # 0xb928
divsd 0x10(%rsp), %xmm0
leaq 0x61ce(%rip), %rsi      # 0xd38f
movq %rbp, %rdx
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0
leaq 0x609e(%rip), %rdi      # 0xd27e
movl $0x3, %esi
movl $0x1, %edx
callq 0x32c0
movq (%r14), %rdi
movq 0x8(%rsp), %r13
addq %r13, %r12
movq %r12, %xmm1
movq 0x4739(%rip), %xmm0     # 0xb940
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movdqa %xmm0, %xmm2
movapd 0x4739(%rip), %xmm0     # 0xb950
subpd %xmm0, %xmm1
movapd %xmm0, %xmm3
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x46f5(%rip), %xmm0     # 0xb928
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 0x6025(%rip), %rbx      # 0xd282
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %r13, %xmm1
punpckldq 0x46c9(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x46d1(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4695(%rip), %xmm0     # 0xb928
divsd 0x10(%rsp), %xmm0
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %rbp, %xmm1
punpckldq 0x468d(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4695(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4659(%rip), %xmm0     # 0xb928
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