// File: /workspace/github_c_makefile_star2_O2/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 0x78e2
leaq 0x9849(%rip), %rax      # 0x11108
movq (%rax), %rcx
leaq 0x4d14(%rip), %rdi      # 0xc5dd
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x32d0
movq %rdi, %r13
leaq 0x36e8(%rip), %rsi      # 0xafd4
callq 0x576f
testq %rax, %rax
je 0x78fc
movq 0x30(%rax), %rbx
jmp 0x78fe
xorl %ebx, %ebx
leaq 0xa86b(%rip), %rax      # 0x12170
movq (%rax), %rax
movl (%rax), %eax
cmpl $0x1, %eax
je 0x792e
cmpl $0x2, %eax
jne 0x794f
leaq 0x32aa(%rip), %rsi      # 0xabc5
movq %r13, %rdi
callq 0x576f
testq %rax, %rax
je 0x795e
movq 0x30(%rax), %r14
jmp 0x7961
leaq 0x3776(%rip), %rsi      # 0xb0ab
movq %r13, %rdi
callq 0x576f
testq %rax, %rax
je 0x7a85
movq 0x30(%rax), %r12
jmp 0x7a88
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
leaq 0x3291(%rip), %rsi      # 0xabf9
movq %r13, %rdi
callq 0x576f
testq %rax, %rax
je 0x797b
movq 0x30(%rax), %r15
jmp 0x797e
xorl %r15d, %r15d
leaq 0x9763(%rip), %rax      # 0x110e8
cmpl $0x0, (%rax)
leaq 0x9779(%rip), %r12      # 0x11108
movq (%r12), %rdi
je 0x79c8
movq %r15, %xmm1
movq 0x2f9e(%rip), %xmm2     # 0xa940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x2fa2(%rip), %xmm3     # 0xa950
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq %r14, %xmm1
jmp 0x7b55
movq %r14, %xmm0
movq 0x2f6b(%rip), %xmm2     # 0xa940
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x2f6f(%rip), %xmm3     # 0xa950
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 0x2f05(%rip), %xmm0     # 0xa928
leaq 0x4bbb(%rip), %rsi      # 0xc5e5
movq %r14, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r12), %rdi
movq %r15, %xmm1
punpckldq 0x2efb(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x2f03(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd 0x2e62(%rip), %xmm0     # 0xa8c8
leaq 0x4bb5(%rip), %rsi      # 0xc622
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 0x3650(%rip), %rsi      # 0xb0df
movq %r13, %rdi
callq 0x576f
testq %rax, %rax
je 0x7aa2
movq 0x30(%rax), %r14
jmp 0x7aa5
xorl %r14d, %r14d
leaq 0x3656(%rip), %rsi      # 0xb102
movq %r13, %rdi
callq 0x576f
testq %rax, %rax
je 0x7abf
movq 0x30(%rax), %rbp
jmp 0x7ac1
xorl %ebp, %ebp
leaq 0x3665(%rip), %rsi      # 0xb12d
movq %r13, %rdi
callq 0x576f
testq %rax, %rax
je 0x7adb
movq 0x30(%rax), %r15
jmp 0x7ade
xorl %r15d, %r15d
leaq 0x366f(%rip), %rsi      # 0xb154
movq %r13, %rdi
callq 0x576f
testq %rax, %rax
je 0x7af8
movq 0x30(%rax), %r13
jmp 0x7afb
xorl %r13d, %r13d
leaq (%r14,%r12), %rax
movq %r12, %rdx
movq %r15, %r12
addq %rbp, %r15
addq %r15, %rax
addq %r13, %r15
leaq 0x95d3(%rip), %rcx      # 0x110e8
cmpl $0x0, (%rcx)
movq %r14, %rcx
leaq 0x95e6(%rip), %r14      # 0x11108
movq (%r14), %rdi
je 0x7b91
movq %r15, %xmm1
movq 0x2e0c(%rip), %xmm2     # 0xa940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x2e10(%rip), %xmm3     # 0xa950
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 0x2d53(%rip), %xmm0     # 0xa8c8
leaq 0x495c(%rip), %rsi      # 0xc4d8
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0
movq %rax, %xmm0
movq 0x2da2(%rip), %xmm2     # 0xa940
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x2da6(%rip), %xmm3     # 0xa950
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 0x2d3b(%rip), %xmm0     # 0xa928
leaq 0x4a5d(%rip), %rsi      # 0xc651
movq %rcx, (%rsp)
movq %rdx, 0x18(%rsp)
movq %rbx, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movq %r15, %xmm1
punpckldq 0x2d29(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x2d31(%rip), %xmm1     # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x20(%rsp), %xmm0
mulsd 0x2c8f(%rip), %xmm0     # 0xa8c8
leaq 0x4a4e(%rip), %rsi      # 0xc68e
movq 0x18(%rsp), %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
leaq 0x4a67(%rip), %rsi      # 0xc6bd
movq %r13, %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
leaq 0x4a72(%rip), %rsi      # 0xc6dc
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
leaq 0x4a7c(%rip), %rsi      # 0xc6fb
movq %rbp, %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
leaq 0x4a87(%rip), %rsi      # 0xc71a
movq %r12, %rdx
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31c0