// File: /workspace/github_c_makefile_star2_O0/mvermeulen[P]wspy/topdown.c
// Function: cache_counter_group
struct counter_group *cache_counter_group(char *name,unsigned int mask){
  int i;
  int ncounters = 0;
  int num_counters_available = (nmi_running)?5:6;
  struct counter_group *cgroup = NULL;
  
  for (i=0;i<sizeof(cache_events)/sizeof(cache_events[0]);i++){
    if (mask & cache_events[i].use) ncounters++;
  }
  if (ncounters == 0) return NULL;
  cgroup = calloc(1,sizeof(struct counter_group));
  cgroup->label = strdup("cache");
  cgroup->type_id = PERF_TYPE_HW_CACHE;  
  cgroup->ncounters = ncounters;
  cgroup->cinfo = calloc(cgroup->ncounters,sizeof(struct counter_info));
  cgroup->mask = mask;

  int count = 0;
  unsigned int group_id = -1;
  for (i=0;i<sizeof(cache_events)/sizeof(cache_events[0]);i++){
    if (mask & cache_events[i].use){
      cgroup->cinfo[count].label = cache_events[i].name;
      cgroup->cinfo[count].config = cache_events[i].config;
      if (cpu_info->vendor == VENDOR_AMD){
	if ((count % num_counters_available) == 0)
	  cgroup->cinfo[count].is_group_leader = 1;
      }
      count++;
    }
  }
  return cgroup;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x1c(%rbp)
movl 0xdb74(%rip), %edx      # 0x13130
movl $0x6, %eax
movl $0x5, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x18(%rbp)
movslq -0x18(%rbp), %rax
cmpq $0x9, %rax
jae 0x561b
movl -0x14(%rbp), %eax
movslq -0x18(%rbp), %rdx
leaq 0xd9aa(%rip), %rcx      # 0x12fa0
shlq $0x5, %rdx
addq %rdx, %rcx
andl 0x1c(%rcx), %eax
cmpl $0x0, %eax
je 0x560e
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x5610
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x55de
cmpl $0x0, -0x1c(%rbp)
jne 0x562e
movq $0x0, -0x8(%rbp)
jmp 0x578d
movl $0x1, %edi
movl $0x28, %esi
callq 0x31a0
movq %rax, -0x28(%rbp)
leaq 0x93d8(%rip), %rdi      # 0xea20
callq 0x32f0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movl $0x3, 0x8(%rax)
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x28(%rbp), %rax
movslq 0xc(%rax), %rdi
movl $0x58, %esi
callq 0x31a0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movl $0x0, -0x2c(%rbp)
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x18(%rbp)
movslq -0x18(%rbp), %rax
cmpq $0x9, %rax
jae 0x5785
movl -0x14(%rbp), %eax
movslq -0x18(%rbp), %rdx
leaq 0xd8dc(%rip), %rcx      # 0x12fa0
shlq $0x5, %rdx
addq %rdx, %rcx
andl 0x1c(%rcx), %eax
cmpl $0x0, %eax
je 0x5775
movslq -0x18(%rbp), %rcx
leaq 0xd8be(%rip), %rax      # 0x12fa0
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x2c(%rbp), %rdx
imulq $0x58, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movslq -0x18(%rbp), %rcx
leaq 0xd892(%rip), %rax      # 0x12fa0
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x2c(%rbp), %rdx
imulq $0x58, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
leaq 0xea39(%rip), %rax      # 0x14170
movq (%rax), %rax
cmpl $0x1, (%rax)
jne 0x576c
movl -0x2c(%rbp), %eax
cltd
idivl -0x20(%rbp)
cmpl $0x0, %edx
jne 0x576a
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movb 0xc(%rax), %cl
andb $-0x2, %cl
orb $0x1, %cl
movb %cl, 0xc(%rax)
jmp 0x576c
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x5777
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x56a8
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)