// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
cmpl $0x2, -0xc(%rbp)
jne 0x8be3
leaq 0xa536(%rip), %rax      # 0x13108
movq (%rax), %rdi
leaq 0x6677(%rip), %rsi      # 0xf253
movb $0x0, %al
callq 0x31d0
leaq 0xb586(%rip), %rax      # 0x14170
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
subl $0x1, %eax
je 0x8c0c
jmp 0x8bf9
movl -0x4c(%rbp), %eax
subl $0x2, %eax
jne 0x8cf2
jmp 0x8c07
jmp 0x9165
movq -0x8(%rbp), %rdi
leaq 0x53ad(%rip), %rsi      # 0xdfc4
callq 0x6930
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x8c32
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x5798(%rip), %rsi      # 0xe3d5
callq 0x6930
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x8c58
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x57b0(%rip), %rsi      # 0xe413
callq 0x6930
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x8c7e
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x57cc(%rip), %rsi      # 0xe455
callq 0x6930
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x8ca4
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x57cb(%rip), %rsi      # 0xe47a
callq 0x6930
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x8cca
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x57ce(%rip), %rsi      # 0xe4a3
callq 0x6930
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x8cf0
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x8cf7
jmp 0x9165
cmpq $0x0, -0x18(%rbp)
je 0x9165
movl -0xc(%rbp), %eax
movl %eax, -0x50(%rbp)
testl %eax, %eax
je 0x8efe
jmp 0x8d12
movl -0x50(%rbp), %eax
subl $0x1, %eax
jne 0x9163
jmp 0x8d20
cmpq $0x0, -0x28(%rbp)
je 0x8d90
leaq 0xa3da(%rip), %rax      # 0x13108
movq (%rax), %rdi
movq -0x20(%rbp), %xmm0
movaps 0x4bf3(%rip), %xmm3     # 0xd930
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x4bf7(%rip), %xmm2     # 0xd940
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x28(%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 0x4b34(%rip), %xmm1     # 0xd8b0
mulsd %xmm1, %xmm0
leaq 0x639a(%rip), %rsi      # 0xf121
movb $0x1, %al
callq 0x31d0
jmp 0x8da8
leaq 0xa371(%rip), %rax      # 0x13108
movq (%rax), %rdi
leaq 0x64cf(%rip), %rsi      # 0xf270
movb $0x0, %al
callq 0x31d0
leaq 0xa359(%rip), %rax      # 0x13108
movq %rax, -0x58(%rbp)
movq (%rax), %rdi
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, %xmm0
movaps 0x4b63(%rip), %xmm3     # 0xd930
movaps %xmm3, -0x80(%rbp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x4b63(%rip), %xmm2     # 0xd940
movaps %xmm2, -0x70(%rbp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x4b18(%rip), %xmm1     # 0xd910
movsd %xmm1, -0x88(%rbp)
mulsd %xmm1, %xmm0
movq -0x18(%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
leaq 0x644d(%rip), %rsi      # 0xf274
movq %rsi, -0x98(%rbp)
movb $0x1, %al
movb %al, -0x89(%rbp)
callq 0x31d0
movq -0x98(%rbp), %rsi
movq -0x58(%rbp), %rcx
movsd -0x88(%rbp), %xmm1
movaps -0x80(%rbp), %xmm3
movaps -0x70(%rbp), %xmm2
movb -0x89(%rbp), %al
movq (%rcx), %rdi
movq -0x38(%rbp), %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm4
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm4, %xmm0
mulsd %xmm1, %xmm0
movq -0x18(%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
callq 0x31d0
movsd -0x88(%rbp), %xmm1
movaps -0x80(%rbp), %xmm3
movaps -0x70(%rbp), %xmm2
movq -0x58(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm4
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm4, %xmm0
mulsd %xmm1, %xmm0
movq -0x18(%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
leaq 0x6382(%rip), %rsi      # 0xf274
movb $0x1, %al
callq 0x31d0
jmp 0x9163
leaq 0xa203(%rip), %rax      # 0x13108
movq %rax, -0xa0(%rbp)
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x6360(%rip), %rsi      # 0xf27a
xorl %eax, %eax
callq 0x31d0
movq -0xa0(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
movq %rdx, %xmm0
movaps 0x49f5(%rip), %xmm3     # 0xd930
movaps %xmm3, -0xc0(%rbp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x49f2(%rip), %xmm2     # 0xd940
movaps %xmm2, -0xb0(%rbp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x49a4(%rip), %xmm1     # 0xd910
movsd %xmm1, -0xc8(%rbp)
mulsd %xmm1, %xmm0
movq -0x18(%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
leaq 0x62fe(%rip), %rsi      # 0xf299
movb $0x1, %al
movb %al, -0xc9(%rbp)
callq 0x31d0
movq -0xa0(%rbp), %rcx
movaps -0xc0(%rbp), %xmm3
movaps -0xb0(%rbp), %xmm2
movb -0xc9(%rbp), %al
movq (%rcx), %rdi
movq -0x20(%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 -0x28(%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 0x48aa(%rip), %xmm1     # 0xd8b0
mulsd %xmm1, %xmm0
leaq 0x62c2(%rip), %rsi      # 0xf2d3
callq 0x31d0
movq -0xa0(%rbp), %rcx
movsd -0xc8(%rbp), %xmm1
movaps -0xc0(%rbp), %xmm3
movaps -0xb0(%rbp), %xmm2
movb -0xc9(%rbp), %al
movq (%rcx), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
addq %rcx, %rdx
movq %rdx, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm4
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm4, %xmm0
mulsd %xmm1, %xmm0
movq -0x18(%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
leaq 0x6285(%rip), %rsi      # 0xf30b
callq 0x31d0
movq -0xa0(%rbp), %rcx
movsd -0xc8(%rbp), %xmm1
movaps -0xc0(%rbp), %xmm3
movaps -0xb0(%rbp), %xmm2
movb -0xc9(%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, %xmm4
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm4, %xmm0
mulsd %xmm1, %xmm0
movq -0x18(%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
leaq 0x6252(%rip), %rsi      # 0xf346
callq 0x31d0
movsd -0xc8(%rbp), %xmm1
movaps -0xc0(%rbp), %xmm3
movaps -0xb0(%rbp), %xmm2
movq -0xa0(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
movq %rdx, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm4
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm4, %xmm0
mulsd %xmm1, %xmm0
movq -0x18(%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
leaq 0x6225(%rip), %rsi      # 0xf381
movb $0x1, %al
callq 0x31d0
jmp 0x9165
addq $0xd0, %rsp
popq %rbp
retq
nop