// File: /workspace/github_c_makefile_star2_O0/mvermeulen[P]wspy/topdown.c
// Function: parse_amd_event
unsigned long parse_amd_event(char *description){
  char *desc = strdup(description);
  char *name,*val;
  unsigned long value;
  union amd_raw_cpu_format result;
  struct stat statbuf;
  result.config = 0;
  
  for (name = strtok(desc,",\n");name;name = strtok(NULL,",\n")){
    if (val = strchr(name,'=')){ // expected format "desc=value"
      *val = 0; // null terminator for name
      val++;
      value = strtol(val,NULL,16);
      
      if (!strcmp(name,"event")){
	result.event = value;
	result.event2 = value>>8;
      } else if (!strcmp(name,"umask")){
	result.umask = value;
      } else if (!strcmp(name,"cmask")){
	result.cmask = value;
      } else if (!strcmp(name,"requires")){
	// the value encodes the name of the type field...
	debug("checking for %s\n",val);
	if (stat(val,&statbuf) ==-1){
	  fatal("%s not found, is the perf module for this device loaded in the kernel?\n");
	}
      } else {
	fatal("unimplemented %s in parse_amd_event\n",name);
      }
    }
  }
  debug2("parse_event(\"%s\") = %lx\n",description,result.config);
  
  return result.config;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x32f0
movq %rax, -0x10(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xa239(%rip), %rsi      # 0xe528
callq 0x3290
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x449f
movq -0x18(%rbp), %rdi
movl $0x3d, %esi
callq 0x30e0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x4484
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x10, %edx
callq 0x3200
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq 0xa1d8(%rip), %rsi      # 0xe52b
callq 0x31b0
cmpl $0x0, %eax
jne 0x43a6
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
andq $0xff, %rcx
andq $-0x100, %rax
orq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rcx
shrq $0x8, %rcx
movq -0x30(%rbp), %rax
andq $0xf, %rcx
shlq $0x20, %rcx
movabsq $-0xf00000001, %rdx     # imm = 0xFFFFFFF0FFFFFFFF
andq %rdx, %rax
orq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x4482
movq -0x18(%rbp), %rdi
leaq 0xa180(%rip), %rsi      # 0xe531
callq 0x31b0
cmpl $0x0, %eax
jne 0x43e0
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
andq $0xff, %rcx
shlq $0x8, %rcx
andq $-0xff01, %rax          # imm = 0xFFFF00FF
orq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x4480
movq -0x18(%rbp), %rdi
leaq 0xa14c(%rip), %rsi      # 0xe537
callq 0x31b0
cmpl $0x0, %eax
jne 0x441e
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
andq $0xff, %rcx
shlq $0x18, %rcx
movabsq $-0xff000001, %rdx      # imm = 0xFFFFFFFF00FFFFFF
andq %rdx, %rax
orq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x447e
movq -0x18(%rbp), %rdi
leaq 0xa15b(%rip), %rsi      # 0xe584
callq 0x31b0
cmpl $0x0, %eax
jne 0x446a
movq -0x20(%rbp), %rsi
leaq 0xa14f(%rip), %rdi      # 0xe58d
movb $0x0, %al
callq 0xbfe0
movq -0x20(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x31f0
cmpl $-0x1, %eax
jne 0x4468
leaq 0xa13d(%rip), %rdi      # 0xe59e
movb $0x0, %al
callq 0xbaf0
jmp 0x447c
movq -0x18(%rbp), %rsi
leaq 0xa171(%rip), %rdi      # 0xe5e6
movb $0x0, %al
callq 0xbaf0
jmp 0x447e
jmp 0x4480
jmp 0x4482
jmp 0x4484
jmp 0x4486
xorl %eax, %eax
movl %eax, %edi
leaq 0xa097(%rip), %rsi      # 0xe528
callq 0x3290
movq %rax, -0x18(%rbp)
jmp 0x42f8
movq -0x8(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq 0xa0bd(%rip), %rdi      # 0xe56b
movb $0x0, %al
callq 0xc0f0
movq -0x30(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)