user: Converte this assembly snippet into its equivalent C code:

```asm
<os_alloc_assoc_set_pid>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x140,%rsp
  mov    %edi,-0x134(%rbp)
  mov    %esi,-0x138(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movl   $0x0,-0x124(%rbp)
  lea    -0x118(%rbp),%rax
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <_pqos_cap_get@plt>
  mov    -0x118(%rbp),%rax
  lea    -0x124(%rbp),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <resctrl_alloc_get_grps_num@plt>
  mov    %eax,-0x120(%rbp)
  cmpl   $0x0,-0x120(%rbp)
  je     L118
  mov    -0x120(%rbp),%eax
  jmp    L136
L118:
  mov    -0x124(%rbp),%eax
  cmp    %eax,-0x138(%rbp)
  jb     L128
  mov    -0x134(%rbp),%eax
  mov    %eax,%edx
  lea    D12(%rip),%rax
  mov    %rax,%rsi
  mov    $0x4,%edi
  call   <log_printf@plt>
  mov    $0x2,%eax
  jmp    L136
L128:
  mov    $0x0,%eax
  call   <resctrl_lock_exclusive@plt>
  mov    %eax,-0x120(%rbp)
  cmpl   $0x0,-0x120(%rbp)
  je     L70
  mov    -0x120(%rbp),%eax
  jmp    L136
L70:
  lea    -0x110(%rbp),%rcx
  mov    -0x134(%rbp),%eax
  mov    $0x100,%edx
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <resctrl_mon_assoc_get_pid@plt>
  mov    %eax,-0x11c(%rbp)
  cmpl   $0x0,-0x11c(%rbp)
  je     L47
  cmpl   $0x3,-0x11c(%rbp)
  je     L47
  mov    -0x134(%rbp),%eax
  mov    %eax,%edx
  lea    D28(%rip),%rax
  mov    %rax,%rsi
  mov    $0x2,%edi
  call   <log_printf@plt>
L47:
  mov    -0x138(%rbp),%edx
  mov    -0x134(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <resctrl_alloc_assoc_set_pid@plt>
  mov    %eax,-0x120(%rbp)
  cmpl   $0x0,-0x120(%rbp)
  jne    L12
  cmpl   $0x0,-0x11c(%rbp)
  jne    L43
  lea    -0x110(%rbp),%rdx
  mov    -0x134(%rbp),%eax
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <resctrl_mon_assoc_set_pid@plt>
  mov    %eax,-0x11c(%rbp)
  cmpl   $0x0,-0x11c(%rbp)
  je     L43
  mov    -0x134(%rbp),%eax
  mov    %eax,%edx
  lea    D14(%rip),%rax
  mov    %rax,%rsi
  mov    $0x2,%edi
  call   <log_printf@plt>
  jmp    L2
L12:
  nop
  jmp    L2
L43:
  nop
L2:
  mov    $0x0,%eax
  call   <resctrl_lock_release@plt>
  mov    -0x120(%rbp),%eax
L136:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L132
  call   <__stack_chk_fail@plt>
L132:
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: tag: D12
data_type: string
name: retrieve_data
arguments: tag: D28
data_type: string
name: retrieve_data
arguments: tag: D14
data_type: string

tool: D12: ERROR: COS out of bounds for task %d


tool: D28: WARN: Failed to obtain monitoring group assignment for task %d


tool: D14: WARN: Could not assign task %d back to monitoring group


assistant: ```c
int os_alloc_assoc_set_pid(const pid_t task, const unsigned class_id) {
  int ret;
  unsigned max_cos = 0;
  int ret_mon;
  char mon_group[256];
  const struct pqos_cap *cap;
  _pqos_cap_get(&cap, NULL);
  ret = resctrl_alloc_get_grps_num(cap, &max_cos);
  if (ret != 0)
    return ret;
  if (class_id >= max_cos) {
    log_printf((1 << 2),
               "ERROR: "
               "COS out of bounds for task %d\n",
               (int)task);
    return 2;
  }
  ret = resctrl_lock_exclusive();
  if (ret != 0)
    return ret;
  ret_mon = resctrl_mon_assoc_get_pid(task, mon_group, sizeof(mon_group));
  if (ret_mon != 0 && ret_mon != 3)
    log_printf((1 << 1),
               "WARN: "
               "Failed to obtain monitoring group assignment for "
               "task %d\n",
               task);
  ret = resctrl_alloc_assoc_set_pid(task, class_id);
  if (ret != 0)
    goto os_alloc_assoc_set_pid_exit;
  if (ret_mon == 0) {
    ret_mon = resctrl_mon_assoc_set_pid(task, mon_group);
    if (ret_mon != 0)
      log_printf((1 << 1),
                 "WARN: "
                 "Could not assign task %d back to monitoring "
                 "group\n",
                 task);
  }
os_alloc_assoc_set_pid_exit:
  resctrl_lock_release();
  return ret;
}
```