// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
cmpl $0x2, -0xc(%rbp)
jne 0x9ae5
leaq 0x9639(%rip), %rax      # 0x13108
movq (%rax), %rdi
leaq 0x5af6(%rip), %rsi      # 0xf5cf
movb $0x0, %al
callq 0x31d0
jmp 0x9f92
movq -0x8(%rbp), %rdi
leaq 0x44d4(%rip), %rsi      # 0xdfc4
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x9b0b
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x30(%rbp)
leaq 0xa65e(%rip), %rax      # 0x14170
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
subl $0x1, %eax
je 0x9cda
jmp 0x9b25
movl -0x5c(%rbp), %eax
subl $0x2, %eax
jne 0x9f90
jmp 0x9b33
movq -0x8(%rbp), %rdi
leaq 0x4077(%rip), %rsi      # 0xdbb5
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x9b59
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x4085(%rip), %rsi      # 0xdbe9
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x9b7f
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x28(%rbp)
leaq 0x9562(%rip), %rax      # 0x130e8
cmpl $0x0, (%rax)
je 0x9bf7
leaq 0x9576(%rip), %rax      # 0x13108
movq (%rax), %rdi
movq -0x28(%rbp), %xmm0
movaps 0x3d8f(%rip), %xmm3     # 0xd930
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x3d93(%rip), %xmm2     # 0xd940
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x20(%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 0x3cd0(%rip), %xmm1     # 0xd8b0
mulsd %xmm1, %xmm0
leaq 0x58df(%rip), %rsi      # 0xf4ca
movb $0x1, %al
callq 0x31d0
jmp 0x9cd5
leaq 0x950a(%rip), %rax      # 0x13108
movq %rax, -0x68(%rbp)
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
movq %rdx, %xmm0
movaps 0x3d1b(%rip), %xmm3     # 0xd930
movaps %xmm3, -0x90(%rbp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x3d18(%rip), %xmm2     # 0xd940
movaps %xmm2, -0x80(%rbp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x30(%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 0x3cb1(%rip), %xmm1     # 0xd910
mulsd %xmm1, %xmm0
leaq 0x596d(%rip), %rsi      # 0xf5d7
movb $0x1, %al
callq 0x31d0
movaps -0x90(%rbp), %xmm3
movaps -0x80(%rbp), %xmm2
movq -0x68(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%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 -0x20(%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 0x3bed(%rip), %xmm1     # 0xd8b0
mulsd %xmm1, %xmm0
leaq 0x5946(%rip), %rsi      # 0xf614
movb $0x1, %al
callq 0x31d0
jmp 0x9f92
movq -0x8(%rbp), %rdi
leaq 0x43b6(%rip), %rsi      # 0xe09b
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x9d00
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x43c4(%rip), %rsi      # 0xe0cf
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x9d26
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x43c1(%rip), %rsi      # 0xe0f2
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x9d4c
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x43c6(%rip), %rsi      # 0xe11d
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x9d72
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x43c7(%rip), %rsi      # 0xe144
callq 0x6930
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x9d98
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
addq -0x48(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x58(%rbp), %rax
addq -0x48(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq 0x9325(%rip), %rax      # 0x130e8
cmpl $0x0, (%rax)
je 0x9e34
leaq 0x9339(%rip), %rax      # 0x13108
movq (%rax), %rdi
movq -0x28(%rbp), %xmm0
movaps 0x3b52(%rip), %xmm3     # 0xd930
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x3b56(%rip), %xmm2     # 0xd940
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x20(%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 0x3a93(%rip), %xmm1     # 0xd8b0
mulsd %xmm1, %xmm0
leaq 0x56a2(%rip), %rsi      # 0xf4ca
movb $0x1, %al
callq 0x31d0
jmp 0x9f8e
leaq 0x92cd(%rip), %rax      # 0x13108
movq %rax, -0x98(%rbp)
movq (%rax), %rdi
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %xmm0
movaps 0x3adb(%rip), %xmm3     # 0xd930
movaps %xmm3, -0xc0(%rbp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x3ad8(%rip), %xmm2     # 0xd940
movaps %xmm2, -0xb0(%rbp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq %rdx, %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 0x3a6e(%rip), %xmm1     # 0xd910
mulsd %xmm1, %xmm0
leaq 0x5796(%rip), %rsi      # 0xf643
movb $0x1, %al
callq 0x31d0
movaps -0xc0(%rbp), %xmm3
movaps -0xb0(%rbp), %xmm2
movq -0x98(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %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 -0x20(%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 0x39a4(%rip), %xmm1     # 0xd8b0
mulsd %xmm1, %xmm0
leaq 0x5769(%rip), %rsi      # 0xf680
movb $0x1, %al
callq 0x31d0
leaq 0x91e3(%rip), %rax      # 0x13108
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
leaq 0x577c(%rip), %rsi      # 0xf6af
movb $0x0, %al
callq 0x31d0
leaq 0x91c7(%rip), %rax      # 0x13108
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
leaq 0x577f(%rip), %rsi      # 0xf6ce
movb $0x0, %al
callq 0x31d0
leaq 0x91ab(%rip), %rax      # 0x13108
movq (%rax), %rdi
movq -0x48(%rbp), %rdx
leaq 0x5782(%rip), %rsi      # 0xf6ed
movb $0x0, %al
callq 0x31d0
leaq 0x918f(%rip), %rax      # 0x13108
movq (%rax), %rdi
movq -0x50(%rbp), %rdx
leaq 0x5785(%rip), %rsi      # 0xf70c
movb $0x0, %al
callq 0x31d0
jmp 0x9f92
jmp 0x9f92
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)