user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<counting_sort>:
  endbr64
  test   %rdi,%rdi
  je     L3
  push   %r15
  push   %r14
  mov    %rdi,%r14
  lea    0x0(,%rsi,4),%edi
  push   %r13
  push   %r12
  push   %rbp
  mov    %esi,%ebp
  push   %rbx
  sub    $0x18,%rsp
  call   <malloc@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L8
  test   %ebp,%ebp
  jle    L42
  lea    -0x1(%rbp),%r12d
  mov    %r14,%rcx
  xor    %ebx,%ebx
  mov    %r12,%rbp
  shl    $0x2,%r12
  sub    %rax,%rcx
  lea    0x4(%rax,%r12,1),%rsi
  nopl   0x0(%rax,%rax,1)
L71:
  mov    (%rcx,%rax,1),%edx
  cmp    %edx,%ebx
  mov    %edx,(%rax)
  cmovl  %edx,%ebx
  add    $0x4,%rax
  cmp    %rax,%rsi
  jne    L71
  lea    0x1(%rbx),%r13d
  lea    0x0(,%r13,4),%edi
  call   <malloc@plt>
  mov    %rax,%rcx
  test   %rax,%rax
  je     L14
  mov    %rax,0x8(%rsp)
  movslq %ebx,%rax
  xor    %esi,%esi
  mov    %rcx,%rdi
  lea    0x4(,%rax,4),%rdx
  call   <memset@plt>
  mov    0x8(%rsp),%r8
  lea    0x4(%r14,%r12,1),%rsi
  mov    %rax,%rcx
  mov    %r14,%rax
  nopw   0x0(%rax,%rax,1)
L58:
  movslq (%rax),%rdx
  add    $0x4,%rax
  addl   $0x1,(%rcx,%rdx,4)
  cmp    %rax,%rsi
  jne    L58
  cmp    $0x1,%r13d
  je     L1
  lea    -0x1(%rbx),%edx
  lea    0x4(%rcx),%rax
  lea    0x8(%rcx,%rdx,4),%rsi
  nopw   0x0(%rax,%rax,1)
L74:
  mov    -0x4(%rax),%edx
  add    %edx,(%rax)
  add    $0x4,%rax
  cmp    %rsi,%rax
  jne    L74
L1:
  mov    %ebp,%esi
  movslq %ebp,%rbp
  lea    (%r15,%rbp,4),%rdx
  nop
L82:
  movslq (%rdx),%rax
  sub    $0x1,%esi
  sub    $0x4,%rdx
  mov    %rax,%rdi
  lea    (%rcx,%rax,4),%rax
  movslq (%rax),%r9
  mov    %edi,-0x4(%r14,%r9,4)
  subl   $0x1,(%rax)
  cmp    $0xffffffff,%esi
  jne    L82
L60:
  mov    %r8,%rdi
  call   <free@plt>
  mov    %r15,%rdi
  call   <free@plt>
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L8:
  mov    $0x1c,%esi
  lea    D18(%rip),%rdi
  call   <printf@plt>
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L14:
  mov    $0x30,%esi
  lea    D18(%rip),%rdi
  call   <printf@plt>
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L42:
  mov    $0x4,%edi
  call   <malloc@plt>
  mov    %rax,%r8
  test   %rax,%rax
  je     L14
  movl   $0x0,(%r8)
  jmp    L60
L3:
  mov    $0xffffffff,%eax
  ret
```

tool_calls: name: retrieve_data
arguments: data_label: D18
data_type: string

tool: D18: 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;
}
```