// File: /workspace/github_c_makefile_star2_O3/mvermeulen[P]wspy/topdown.c
// Function: print_l2cache
void print_l2cache(struct counter_group *cgroup,enum output_format oformat){
  struct counter_info *cinfo;
  unsigned long l2_access=0, l2_miss=0;
  unsigned long instructions = 0;
  unsigned long l2_from_l1_no_prefetch = 0;
  unsigned long l2_pf_hit_l2 = 0;
  unsigned long l2_pf_hit_l3 = 0;
  unsigned long l2_pf_miss_l3 = 0;
  unsigned long l1_miss_l2_miss = 0;

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

  if (cinfo = find_ci_label(cgroup,"instructions"))
    instructions = cinfo->value;

  switch(cpu_info->vendor){
  case VENDOR_INTEL:
    if (cinfo = find_ci_label(cgroup,"l2_request.all")) l2_access = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"l2_request.miss")) l2_miss = cinfo->value;
    if (csvflag){
      fprintf(outfile,"%4.2f%%,",(double) l2_miss / l2_access * 100.0);
    } else {    
      fprintf(outfile,"l2 access            %-14lu # %4.3f l2 access per 1000 inst\n",
	      l2_access,(double) l2_access / instructions*1000.0);
      fprintf(outfile,"l2 miss              %-14lu # %4.2f%% l2 miss\n",
	      l2_miss, (double) l2_miss / l2_access * 100.0);
    }
    break;
  case VENDOR_AMD:
    if (cinfo = find_ci_label(cgroup,"l2_request_g1.all_no_prefetch"))
      l2_from_l1_no_prefetch = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"l2_pf_hit_l2"))
      l2_pf_hit_l2 = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"l2_pf_miss_l2_hit_l3"))
      l2_pf_hit_l3 = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"l2_pf_miss_l2_l3"))
      l2_pf_miss_l3 = cinfo->value;
    if (cinfo = find_ci_label(cgroup,"l2_cache_req_stat.ic_dc_miss_in_l2"))
      l1_miss_l2_miss = cinfo->value;

    l2_access = l2_from_l1_no_prefetch + l2_pf_hit_l2 + l2_pf_hit_l3 + l2_pf_miss_l3;
    l2_miss = l1_miss_l2_miss + l2_pf_hit_l3 + l2_pf_miss_l3;

    if (csvflag){
      fprintf(outfile,"%4.2f%%,",(double) l2_miss / l2_access * 100.0);
    } else {
      fprintf(outfile,"instructions         %-14lu # %4.3f l2 access per 1000 inst\n",
	      instructions,(double) l2_access / instructions*1000.0);
      fprintf(outfile,"l2 hit from l1       %-14lu # %4.2f%% l2 miss\n",
	      l2_from_l1_no_prefetch, (double) l2_miss / l2_access * 100.0);
      fprintf(outfile,"l2 miss from l1      %-14lu #\n",l1_miss_l2_miss);
      fprintf(outfile,"l2 hit from l2 pf    %-14lu #\n",l2_pf_hit_l2);
      fprintf(outfile,"l3 hit from l2 pf    %-14lu #\n",l2_pf_hit_l3);
      fprintf(outfile,"l3 miss from l2 pf   %-14lu #\n",l2_pf_miss_l3);
    }
    break;
  default:
    return;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpl $0x2, %esi
jne 0x7a0b
leaq 0xa714(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x5bef(%rip), %rdi      # 0xd5dd
movl $0x7, %esi
movl $0x1, %edx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x32c0
movq %rdi, %r13
leaq 0x45bf(%rip), %rsi      # 0xbfd4
callq 0x5860
testq %rax, %rax
je 0x7a25
movq 0x30(%rax), %rbx
jmp 0x7a27
xorl %ebx, %ebx
leaq 0xb732(%rip), %rax      # 0x13160
movq (%rax), %rax
movl (%rax), %eax
cmpl $0x1, %eax
je 0x7a57
cmpl $0x2, %eax
jne 0x7a78
leaq 0x4181(%rip), %rsi      # 0xbbc5
movq %r13, %rdi
callq 0x5860
testq %rax, %rax
je 0x7a87
movq 0x30(%rax), %r14
jmp 0x7a8a
leaq 0x464d(%rip), %rsi      # 0xc0ab
movq %r13, %rdi
callq 0x5860
testq %rax, %rax
je 0x7bae
movq 0x30(%rax), %r12
jmp 0x7bb1
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
leaq 0x4168(%rip), %rsi      # 0xbbf9
movq %r13, %rdi
callq 0x5860
testq %rax, %rax
je 0x7aa4
movq 0x30(%rax), %r15
jmp 0x7aa7
xorl %r15d, %r15d
leaq 0xa62a(%rip), %rax      # 0x120d8
cmpl $0x0, (%rax)
leaq 0xa640(%rip), %r12      # 0x120f8
movq (%r12), %rdi
je 0x7af1
movq %r15, %xmm1
movq 0x3e75(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3e79(%rip), %xmm3     # 0xb950
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq %r14, %xmm1
jmp 0x7c7e
movq %r14, %xmm0
movq 0x3e42(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x3e46(%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, (%rsp)
movq %rbx, %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 0x3ddc(%rip), %xmm0     # 0xb928
leaq 0x5a92(%rip), %rsi      # 0xd5e5
movq %r14, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r12), %rdi
movq %r15, %xmm1
punpckldq 0x3dd2(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3dda(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd 0x3d39(%rip), %xmm0     # 0xb8c8
leaq 0x5a8c(%rip), %rsi      # 0xd622
movq %r15, %rdx
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0
xorl %r12d, %r12d
leaq 0x4527(%rip), %rsi      # 0xc0df
movq %r13, %rdi
callq 0x5860
testq %rax, %rax
je 0x7bcb
movq 0x30(%rax), %r14
jmp 0x7bce
xorl %r14d, %r14d
leaq 0x452d(%rip), %rsi      # 0xc102
movq %r13, %rdi
callq 0x5860
testq %rax, %rax
je 0x7be8
movq 0x30(%rax), %rbp
jmp 0x7bea
xorl %ebp, %ebp
leaq 0x453c(%rip), %rsi      # 0xc12d
movq %r13, %rdi
callq 0x5860
testq %rax, %rax
je 0x7c04
movq 0x30(%rax), %r15
jmp 0x7c07
xorl %r15d, %r15d
leaq 0x4546(%rip), %rsi      # 0xc154
movq %r13, %rdi
callq 0x5860
testq %rax, %rax
je 0x7c21
movq 0x30(%rax), %r13
jmp 0x7c24
xorl %r13d, %r13d
leaq (%r14,%r12), %rax
movq %r12, %rdx
movq %r15, %r12
addq %rbp, %r15
addq %r15, %rax
addq %r13, %r15
leaq 0xa49a(%rip), %rcx      # 0x120d8
cmpl $0x0, (%rcx)
movq %r14, %rcx
leaq 0xa4ad(%rip), %r14      # 0x120f8
movq (%r14), %rdi
je 0x7cba
movq %r15, %xmm1
movq 0x3ce3(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3ce7(%rip), %xmm3     # 0xb950
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq %rax, %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 0x3c2a(%rip), %xmm0     # 0xb8c8
leaq 0x5833(%rip), %rsi      # 0xd4d8
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0
movq %rax, %xmm0
movq 0x3c79(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x3c7d(%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, 0x20(%rsp)
movq %rbx, %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 0x3c12(%rip), %xmm0     # 0xb928
leaq 0x5934(%rip), %rsi      # 0xd651
movq %rcx, (%rsp)
movq %rdx, 0x18(%rsp)
movq %rbx, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %r15, %xmm1
punpckldq 0x3c00(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3c08(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x20(%rsp), %xmm0
mulsd 0x3b66(%rip), %xmm0     # 0xb8c8
leaq 0x5925(%rip), %rsi      # 0xd68e
movq 0x18(%rsp), %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
leaq 0x593e(%rip), %rsi      # 0xd6bd
movq %r13, %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
leaq 0x5949(%rip), %rsi      # 0xd6dc
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
leaq 0x5953(%rip), %rsi      # 0xd6fb
movq %rbp, %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
leaq 0x595e(%rip), %rsi      # 0xd71a
movq %r12, %rdx
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0