// File: /workspace/github_c_makefile_star2_O3/mvermeulen[P]wspy/topdown.c
// Function: print_l3cache
void print_l3cache(struct counter_group *cgroup,enum output_format oformat){
  struct counter_info *cinfo;
  unsigned long l3_access=0, l3_miss=0;
  unsigned long instructions = 0;

  if (oformat == PRINT_CSV_HEADER){
    fprintf(outfile,"l3miss,");
    return;
  }  

  switch(cpu_info->vendor){
  case VENDOR_INTEL:
    break;
  case VENDOR_AMD:
    if (cinfo = find_ci_label(cgroup,"instructions"))
      instructions = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"l3_lookup_state.all_coherent_accesses_to_l3"))
      l3_access = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"l3_lookup_state.l3_miss"))
      l3_miss = cinfo->value;

    if (csvflag){
      fprintf(outfile,"%4.2f%%,",(double) l3_miss / l3_access * 100.0);
    } else {
      fprintf(outfile,"instructions         %-14lu # %4.3f l3 access per 1000 inst\n",
	      instructions,(double) l3_access / instructions*1000.0);
      fprintf(outfile,"l3 access            %-14lu # %4.3f l3 access per 1000 inst\n",
	      l3_access, (double) l3_access / instructions*1000.0);
      fprintf(outfile,"l3 miss              %-14lu # %4.2f%% l3 miss\n",
	      l3_miss, (double) l3_miss / l3_access * 100.0);
    }
    break;    
  default:
    return;
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0x2, %esi
jne 0x7e0f
leaq 0xa30d(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x5944(%rip), %rdi      # 0xd739
movl $0x7, %esi
movl $0x1, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x32c0
leaq 0xb34a(%rip), %rax      # 0x13160
movq (%rax), %rax
cmpl $0x1, (%rax)
jne 0x7e38
movq %rdi, %r15
leaq 0x41ac(%rip), %rsi      # 0xbfd4
callq 0x5860
testq %rax, %rax
je 0x7e44
movq 0x30(%rax), %r14
jmp 0x7e47
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
xorl %r14d, %r14d
leaq 0x44e6(%rip), %rsi      # 0xc334
movq %r15, %rdi
callq 0x5860
testq %rax, %rax
je 0x7e61
movq 0x30(%rax), %rbx
jmp 0x7e63
xorl %ebx, %ebx
leaq 0x452d(%rip), %rsi      # 0xc397
movq %r15, %rdi
callq 0x5860
testq %rax, %rax
je 0x7e7d
movq 0x30(%rax), %r15
jmp 0x7e80
xorl %r15d, %r15d
leaq 0xa251(%rip), %rax      # 0x120d8
cmpl $0x0, (%rax)
leaq 0xa267(%rip), %r12      # 0x120f8
movq (%r12), %rdi
je 0x7efe
movq %r15, %xmm1
movq 0x3a9c(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3aa0(%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 0x39e3(%rip), %xmm0     # 0xb8c8
leaq 0x55ec(%rip), %rsi      # 0xd4d8
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x31c0
movq %rbx, %xmm0
movq 0x3a35(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x3a39(%rip), %xmm3     # 0xb950
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, %xmm4
movapd %xmm1, 0x10(%rsp)
movq %r14, %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm4, %xmm0
divsd %xmm1, %xmm0
mulsd 0x39ce(%rip), %xmm0     # 0xb928
movapd %xmm0, (%rsp)
leaq 0x57db(%rip), %rsi      # 0xd741
movq %r14, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r12), %rdi
leaq 0x5803(%rip), %rsi      # 0xd77e
movq %rbx, %rdx
movaps (%rsp), %xmm0
movb $0x1, %al
callq 0x31c0
movq (%r12), %rdi
movq %r15, %xmm1
punpckldq 0x39a6(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x39ae(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x10(%rsp), %xmm0
mulsd 0x390c(%rip), %xmm0     # 0xb8c8
leaq 0x57f8(%rip), %rsi      # 0xd7bb
movq %r15, %rdx
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x31c0