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

```asm
<counting_sort>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %esi,-0x2c(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  jne    L77
  mov    $0xffffffff,%eax
  jmp    L54
L77:
  mov    -0x2c(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x10(%rbp)
  cmpq   $0x0,-0x10(%rbp)
  jne    L149
  mov    $0x1c,%esi
  lea    D5(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  mov    $0x0,%eax
  jmp    L54
L149:
  movl   $0x0,-0x1c(%rbp)
  movl   $0x0,-0x18(%rbp)
  movl   $0x0,-0x1c(%rbp)
  jmp    L151
L113:
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  mov    -0x18(%rbp),%edx
  cmp    %eax,%edx
  cmovge %edx,%eax
  mov    %eax,-0x18(%rbp)
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  mov    -0x1c(%rbp),%edx
  movslq %edx,%rdx
  lea    0x0(,%rdx,4),%rcx
  mov    -0x10(%rbp),%rdx
  add    %rcx,%rdx
  mov    (%rax),%eax
  mov    %eax,(%rdx)
  addl   $0x1,-0x1c(%rbp)
L151:
  mov    -0x1c(%rbp),%eax
  cmp    -0x2c(%rbp),%eax
  jl     L113
  mov    -0x18(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,-0x14(%rbp)
  mov    -0x14(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x8(%rbp)
  cmpq   $0x0,-0x8(%rbp)
  jne    L62
  mov    $0x30,%esi
  lea    D5(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  mov    $0x0,%eax
  jmp    L54
L62:
  movl   $0x0,-0x1c(%rbp)
  jmp    L126
L93:
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x8(%rbp),%rax
  add    %rdx,%rax
  movl   $0x0,(%rax)
  addl   $0x1,-0x1c(%rbp)
L126:
  mov    -0x1c(%rbp),%eax
  cmp    -0x14(%rbp),%eax
  jl     L93
  movl   $0x0,-0x1c(%rbp)
  jmp    L100
L85:
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x8(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%edx
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rcx
  mov    -0x28(%rbp),%rax
  add    %rcx,%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,4),%rcx
  mov    -0x8(%rbp),%rax
  add    %rcx,%rax
  add    $0x1,%edx
  mov    %edx,(%rax)
  addl   $0x1,-0x1c(%rbp)
L100:
  mov    -0x1c(%rbp),%eax
  cmp    -0x2c(%rbp),%eax
  jl     L85
  movl   $0x1,-0x1c(%rbp)
  jmp    L70
L49:
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x8(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%ecx
  mov    -0x1c(%rbp),%eax
  cltq
  shl    $0x2,%rax
  lea    -0x4(%rax),%rdx
  mov    -0x8(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%edx
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rsi
  mov    -0x8(%rbp),%rax
  add    %rsi,%rax
  add    %ecx,%edx
  mov    %edx,(%rax)
  addl   $0x1,-0x1c(%rbp)
L70:
  mov    -0x1c(%rbp),%eax
  cmp    -0x14(%rbp),%eax
  jl     L49
  mov    -0x2c(%rbp),%eax
  sub    $0x1,%eax
  mov    %eax,-0x1c(%rbp)
  jmp    L25
L69:
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  mov    -0x1c(%rbp),%edx
  movslq %edx,%rdx
  lea    0x0(,%rdx,4),%rcx
  mov    -0x10(%rbp),%rdx
  add    %rcx,%rdx
  mov    (%rdx),%edx
  movslq %edx,%rdx
  lea    0x0(,%rdx,4),%rcx
  mov    -0x8(%rbp),%rdx
  add    %rcx,%rdx
  mov    (%rdx),%edx
  movslq %edx,%rdx
  shl    $0x2,%rdx
  lea    -0x4(%rdx),%rcx
  mov    -0x28(%rbp),%rdx
  add    %rcx,%rdx
  mov    (%rax),%eax
  mov    %eax,(%rdx)
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x8(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%edx
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rcx
  mov    -0x10(%rbp),%rax
  add    %rcx,%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,4),%rcx
  mov    -0x8(%rbp),%rax
  add    %rcx,%rax
  sub    $0x1,%edx
  mov    %edx,(%rax)
  subl   $0x1,-0x1c(%rbp)
L25:
  cmpl   $0x0,-0x1c(%rbp)
  jns    L69
  mov    -0x8(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    $0x0,%eax
L54:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: data_tag: D5
type_guessed: string

tool: D5: malloc failed %d


assistant: ```c
int counting_sort(int *num, int array_size) {
  if (!num) {
    return -1;
  }
  int *p_tmp = (int *)malloc(sizeof(int) * array_size);
  if (!p_tmp) {
    printf("malloc failed %d\n", 28);
    return 0;
  }
  int i = 0;
  int max_value = 0;
  for (i = 0; i < array_size; i++) {
    max_value = max_value > num[i] ? max_value : num[i];
    p_tmp[i] = num[i];
  }
  int counter_size = max_value + 1;
  int *p_counter = (int *)malloc(sizeof(int) * counter_size);
  if (!p_counter) {
    printf("malloc failed %d\n", 48);
    return 0;
  }
  for (i = 0; i < counter_size; i++) {
    p_counter[i] = 0;
  }
  for (i = 0; i < array_size; i++) {
    p_counter[num[i]] += 1;
  }
  for (i = 1; i < counter_size; i++) {
    p_counter[i] += p_counter[i - 1];
  }
  for (i = array_size - 1; i >= 0; i--) {
    num[p_counter[p_tmp[i]] - 1] = p_tmp[i];
    p_counter[p_tmp[i]] -= 1;
  }
  free(p_counter);
  free(p_tmp);
  return 0;
}
```