// File: /workspace/github_c_makefile_star2_O1/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 0x7a33
leaq 0xa6ec(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x5bc7(%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 0x4597(%rip), %rsi      # 0xbfd4
callq 0x587d
testq %rax, %rax
je 0x7a4d
movq 0x30(%rax), %rbx
jmp 0x7a4f
xorl %ebx, %ebx
leaq 0xb70a(%rip), %rax      # 0x13160
movq (%rax), %rax
movl (%rax), %eax
cmpl $0x1, %eax
je 0x7a7f
cmpl $0x2, %eax
jne 0x7aa0
leaq 0x4159(%rip), %rsi      # 0xbbc5
movq %r13, %rdi
callq 0x587d
testq %rax, %rax
je 0x7aaf
movq 0x30(%rax), %r14
jmp 0x7ab2
leaq 0x4625(%rip), %rsi      # 0xc0ab
movq %r13, %rdi
callq 0x587d
testq %rax, %rax
je 0x7bd6
movq 0x30(%rax), %r12
jmp 0x7bd9
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
leaq 0x4140(%rip), %rsi      # 0xbbf9
movq %r13, %rdi
callq 0x587d
testq %rax, %rax
je 0x7acc
movq 0x30(%rax), %r15
jmp 0x7acf
xorl %r15d, %r15d
leaq 0xa602(%rip), %rax      # 0x120d8
cmpl $0x0, (%rax)
leaq 0xa618(%rip), %r12      # 0x120f8
movq (%r12), %rdi
je 0x7b19
movq %r15, %xmm1
movq 0x3e4d(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3e51(%rip), %xmm3     # 0xb950
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq %r14, %xmm1
jmp 0x7ca6
movq %r14, %xmm0
movq 0x3e1a(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x3e1e(%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 0x3db4(%rip), %xmm0     # 0xb928
leaq 0x5a6a(%rip), %rsi      # 0xd5e5
movq %r14, %rdx
movb $0x1, %al
callq 0x31c0
movq (%r12), %rdi
movq %r15, %xmm1
punpckldq 0x3daa(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3db2(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd 0x3d11(%rip), %xmm0     # 0xb8c8
leaq 0x5a64(%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 0x44ff(%rip), %rsi      # 0xc0df
movq %r13, %rdi
callq 0x587d
testq %rax, %rax
je 0x7bf3
movq 0x30(%rax), %r14
jmp 0x7bf6
xorl %r14d, %r14d
leaq 0x4505(%rip), %rsi      # 0xc102
movq %r13, %rdi
callq 0x587d
testq %rax, %rax
je 0x7c10
movq 0x30(%rax), %rbp
jmp 0x7c12
xorl %ebp, %ebp
leaq 0x4514(%rip), %rsi      # 0xc12d
movq %r13, %rdi
callq 0x587d
testq %rax, %rax
je 0x7c2c
movq 0x30(%rax), %r15
jmp 0x7c2f
xorl %r15d, %r15d
leaq 0x451e(%rip), %rsi      # 0xc154
movq %r13, %rdi
callq 0x587d
testq %rax, %rax
je 0x7c49
movq 0x30(%rax), %r13
jmp 0x7c4c
xorl %r13d, %r13d
leaq (%r14,%r12), %rax
movq %r12, %rdx
movq %r15, %r12
addq %rbp, %r15
addq %r15, %rax
addq %r13, %r15
leaq 0xa472(%rip), %rcx      # 0x120d8
cmpl $0x0, (%rcx)
movq %r14, %rcx
leaq 0xa485(%rip), %r14      # 0x120f8
movq (%r14), %rdi
je 0x7ce2
movq %r15, %xmm1
movq 0x3cbb(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3cbf(%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 0x3c02(%rip), %xmm0     # 0xb8c8
leaq 0x580b(%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 0x3c51(%rip), %xmm2     # 0xb940
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x3c55(%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 0x3bea(%rip), %xmm0     # 0xb928
leaq 0x590c(%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 0x3bd8(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3be0(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x20(%rsp), %xmm0
mulsd 0x3b3e(%rip), %xmm0     # 0xb8c8
leaq 0x58fd(%rip), %rsi      # 0xd68e
movq 0x18(%rsp), %rdx
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
leaq 0x5916(%rip), %rsi      # 0xd6bd
movq %r13, %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
leaq 0x5921(%rip), %rsi      # 0xd6dc
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
leaq 0x592b(%rip), %rsi      # 0xd6fb
movq %rbp, %rdx
xorl %eax, %eax
callq 0x31c0
movq (%r14), %rdi
leaq 0x5936(%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