// File: /workspace/github_c_makefile_star2_O1/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 0x6ede
leaq 0xb233(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x6392(%rip), %rdi      # 0xd261
movl $0x1c, %esi
movl $0x1, %edx
callq 0x32c0
leaq 0xc27b(%rip), %rax      # 0x13160
movq (%rax), %rax
cmpl $0x1, (%rax)
jne 0x7038
leaq 0x50dc(%rip), %rsi      # 0xbfd4
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6f0b
movq 0x30(%rax), %r15
jmp 0x6f0e
xorl %r15d, %r15d
leaq 0x54d0(%rip), %rsi      # 0xc3e5
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6f28
movq 0x30(%rax), %r13
jmp 0x6f2b
xorl %r13d, %r13d
leaq 0x54f1(%rip), %rsi      # 0xc423
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6f45
movq 0x30(%rax), %rbx
jmp 0x6f47
xorl %ebx, %ebx
leaq 0x5517(%rip), %rsi      # 0xc465
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6f61
movq 0x30(%rax), %r12
jmp 0x6f64
xorl %r12d, %r12d
leaq 0x551f(%rip), %rsi      # 0xc48a
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6f83
movq 0x30(%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x6f8c
movq $0x0, 0x8(%rsp)
leaq 0x5520(%rip), %rsi      # 0xc4b3
movq %r14, %rdi
callq 0x587d
testq %rax, %rax
je 0x6fa6
movq 0x30(%rax), %rax
jmp 0x6fa8
xorl %eax, %eax
testq %r15, %r15
je 0x7038
testl %ebp, %ebp
je 0x7047
cmpl $0x1, %ebp
jne 0x7038
movq %rax, %rbp
leaq 0xb130(%rip), %r14      # 0x120f8
movq (%r14), %rcx
testq %rbx, %rbx
je 0x7201
movq %r13, %xmm1
movq 0x495f(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x4963(%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 0x48a6(%rip), %xmm0     # 0xb8c8
leaq 0x6106(%rip), %rsi      # 0xd12f
movq %rcx, %rdi
movb $0x1, %al
callq 0x31c0
jmp 0x7217
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb0aa(%rip), %r14      # 0x120f8
movq (%r14), %rdi
leaq 0x6230(%rip), %rsi      # 0xd288
movq %rax, %rbp
movq %r15, %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
movq %rbx, %xmm0
movq 0x48cb(%rip), %xmm1     # 0xb940
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movdqa %xmm1, %xmm2
movapd 0x48cb(%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 0x487d(%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 0x61d2(%rip), %rsi      # 0xd2a7
movq %rbx, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %r13, %xmm1
punpckldq 0x4851(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4859(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x20(%rsp), %xmm0
mulsd 0x47b7(%rip), %xmm0     # 0xb8c8
leaq 0x61c9(%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 0x4806(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x480e(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x47d2(%rip), %xmm0     # 0xb928
divsd 0x10(%rsp), %xmm0
leaq 0x61b6(%rip), %rsi      # 0xd319
movq %r12, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %rbx, %xmm1
punpckldq 0x47c3(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x47cb(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x478f(%rip), %xmm0     # 0xb928
divsd 0x10(%rsp), %xmm0
leaq 0x61ae(%rip), %rsi      # 0xd354
movq %rbx, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %rbp, %xmm1
punpckldq 0x4780(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4788(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x474c(%rip), %xmm0     # 0xb928
divsd 0x10(%rsp), %xmm0
leaq 0x61a6(%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 0x6076(%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 0x4711(%rip), %xmm0     # 0xb940
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movdqa %xmm0, %xmm2
movapd 0x4711(%rip), %xmm0     # 0xb950
subpd %xmm0, %xmm1
movapd %xmm0, %xmm3
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x46cd(%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 0x5ffd(%rip), %rbx      # 0xd282
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %r13, %xmm1
punpckldq 0x46a1(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x46a9(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x466d(%rip), %xmm0     # 0xb928
divsd 0x10(%rsp), %xmm0
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %rbp, %xmm1
punpckldq 0x4665(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x466d(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x4631(%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