user: Please show me the C implementation that matches the assembly code listed below:

```asm
<format_raw_event>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x430,%rsp
  mov    %rdi,-0x428(%rbp)
  mov    %rsi,-0x430(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movl   $0x0,-0x41c(%rbp)
  mov    -0x428(%rbp),%rax
  mov    0xc(%rax),%eax
  mov    %eax,%edi
  call   <resolve_pmu@plt>
  mov    %rax,-0x418(%rbp)
  cmpq   $0x0,-0x418(%rbp)
  jne    L29
  mov    $0x0,%eax
  jmp    L51
L29:
  mov    -0x428(%rbp),%rax
  mov    0x8(%rax),%ecx
  mov    -0x418(%rbp),%rdx
  lea    -0x410(%rbp),%rax
  mov    %ecx,%r8d
  mov    %rdx,%rcx
  lea    D40(%rip),%rdx
  mov    $0x400,%esi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  mov    %eax,-0x41c(%rbp)
  mov    -0x418(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x428(%rbp),%rax
  mov    0x4(%rax),%eax
  test   %eax,%eax
  je     L9
  mov    -0x428(%rbp),%rax
  mov    0x4(%rax),%eax
  mov    -0x41c(%rbp),%edx
  movslq %edx,%rdx
  lea    -0x410(%rbp),%rcx
  add    %rdx,%rcx
  mov    %eax,%edx
  lea    D21(%rip),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <sprintf@plt>
  mov    %eax,%edx
  mov    -0x41c(%rbp),%eax
  add    %edx,%eax
  mov    %eax,-0x41c(%rbp)
L9:
  mov    -0x428(%rbp),%rax
  mov    (%rax),%eax
  test   %eax,%eax
  je     L31
  mov    -0x428(%rbp),%rax
  mov    (%rax),%eax
  mov    -0x41c(%rbp),%edx
  movslq %edx,%rdx
  lea    -0x410(%rbp),%rcx
  add    %rdx,%rcx
  mov    %eax,%edx
  lea    D48(%rip),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <sprintf@plt>
  mov    %eax,%edx
  mov    -0x41c(%rbp),%eax
  add    %edx,%eax
  mov    %eax,-0x41c(%rbp)
L31:
  cmpq   $0x0,-0x430(%rbp)
  je     L23
  mov    $0x400,%eax
  sub    -0x41c(%rbp),%eax
  mov    -0x41c(%rbp),%edx
  movslq %edx,%rdx
  lea    -0x410(%rbp),%rcx
  lea    (%rcx,%rdx,1),%rdi
  mov    -0x430(%rbp),%rdx
  mov    %rdx,%rcx
  lea    D43(%rip),%rdx
  mov    %eax,%esi
  mov    $0x0,%eax
  call   <snprintf@plt>
  add    %eax,-0x41c(%rbp)
L23:
  mov    $0x400,%eax
  sub    -0x41c(%rbp),%eax
  mov    -0x41c(%rbp),%edx
  movslq %edx,%rdx
  lea    -0x410(%rbp),%rcx
  add    %rdx,%rcx
  lea    D5(%rip),%rdx
  mov    %eax,%esi
  mov    %rcx,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  add    %eax,-0x41c(%rbp)
  lea    -0x410(%rbp),%rax
  mov    %rax,%rdi
  call   <strdup@plt>
L51:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L42
  call   <__stack_chk_fail@plt>
L42:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: data_label: D40
datatype: string
name: disassemble_data
arguments: data_label: D21
datatype: string
name: disassemble_data
arguments: data_label: D48
datatype: string
name: disassemble_data
arguments: data_label: D43
datatype: string
name: disassemble_data
arguments: data_label: D5
datatype: string

tool: D40: %s/config=%#llx

tool: D21: ,config1=%#llx

tool: D48: ,config2=%#llx

tool: D43: ,name=%s

tool: D5: /

assistant: ```c
char *format_raw_event(struct perf_event_attr *attr, char *name) {
  char buf[1024];
  int off = 0;
  char *pmu;
  pmu = resolve_pmu(attr->type);
  if (!pmu)
    return NULL;
  off = snprintf(buf, 1024, "%s/config=%#llx", pmu, attr->config);
  free(pmu);
  if (attr->config1)
    off += sprintf(buf + off, ",config1=%#llx", attr->config1);
  if (attr->config2)
    off += sprintf(buf + off, ",config2=%#llx", attr->config2);
  if (name)
    off += snprintf(buf + off, 1024 - off, ",name=%s", name);
  off += snprintf(buf + off, 1024 - off, "/");
  return strdup(buf);
}
```