user: 请将以下的汇编代码转换成C语言代码:

```asm
<counting_sort>:
  endbr64
  test   %rdi,%rdi
  je     L92
  push   %r15
  push   %r14
  push   %r13
  mov    %esi,%r13d
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbx
  lea    0x0(,%r13,4),%edi
  sub    $0x18,%rsp
  call   <malloc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L130
  test   %r13d,%r13d
  jle    L132
  lea    0x4(%rbx),%rax
  mov    %rbp,%rcx
  lea    -0x1(%r13),%r15d
  sub    %rax,%rcx
  mov    %rax,0x8(%rsp)
  cmp    $0x8,%rcx
  jbe    L62
  cmp    $0x2,%r15d
  jbe    L62
  mov    %r13d,%edx
  mov    %rbx,%rcx
  pxor   %xmm2,%xmm2
  mov    %rbp,%rax
  shr    $0x2,%edx
  sub    %rbp,%rcx
  shl    $0x4,%rdx
  add    %rbp,%rdx
  nopl   0x0(%rax)
L87:
  movdqu (%rax,%rcx,1),%xmm1
  add    $0x10,%rax
  movdqa %xmm1,%xmm0
  movdqa %xmm1,%xmm3
  movups %xmm1,-0x10(%rax)
  pcmpgtd %xmm2,%xmm0
  pand   %xmm0,%xmm3
  pandn  %xmm2,%xmm0
  movdqa %xmm0,%xmm2
  por    %xmm3,%xmm2
  cmp    %rax,%rdx
  jne    L87
  movdqa %xmm2,%xmm1
  mov    %r13d,%eax
  psrldq $0x8,%xmm1
  and    $0xfffffffc,%eax
  movdqa %xmm1,%xmm0
  pcmpgtd %xmm2,%xmm0
  pand   %xmm0,%xmm1
  pandn  %xmm2,%xmm0
  por    %xmm1,%xmm0
  movdqa %xmm0,%xmm2
  psrldq $0x4,%xmm2
  movdqa %xmm2,%xmm1
  pcmpgtd %xmm0,%xmm1
  pand   %xmm1,%xmm2
  pandn  %xmm0,%xmm1
  por    %xmm2,%xmm1
  movd   %xmm1,%r12d
  test   $0x3,%r13b
  je     L175
  mov    %eax,%ecx
  mov    (%rbx,%rcx,4),%esi
  lea    0x0(,%rcx,4),%rdx
  mov    %esi,0x0(%rbp,%rcx,4)
  cmp    %esi,%r12d
  lea    0x1(%rax),%ecx
  cmovl  %esi,%r12d
  cmp    %ecx,%r13d
  jle    L175
  mov    0x4(%rbx,%rdx,1),%ecx
  cmp    %ecx,%r12d
  mov    %ecx,0x4(%rbp,%rdx,1)
  cmovl  %ecx,%r12d
  add    $0x2,%eax
  cmp    %eax,%r13d
  jle    L175
  mov    0x8(%rbx,%rdx,1),%eax
  cmp    %eax,%r12d
  mov    %eax,0x8(%rbp,%rdx,1)
  cmovl  %eax,%r12d
L175:
  lea    0x1(%r12),%r13d
  lea    0x0(,%r13,4),%edi
  call   <malloc@plt>
  mov    %rax,%rcx
  mov    %rax,%r14
  test   %rax,%rax
  je     L105
  movslq %r12d,%rax
  mov    %rcx,%rdi
  xor    %esi,%esi
  lea    0x4(,%rax,4),%rdx
  call   <memset@plt>
  mov    0x8(%rsp),%rdi
  mov    %r15d,%edx
  mov    %r14,%rcx
  mov    %rbx,%rax
  lea    (%rdi,%rdx,4),%rsi
  nop
L112:
  movslq (%rax),%rdx
  add    $0x4,%rax
  addl   $0x1,(%rcx,%rdx,4)
  cmp    %rax,%rsi
  jne    L112
  cmp    $0x1,%r13d
  je     L71
  lea    -0x1(%r12),%esi
  mov    (%rcx),%edx
  lea    0x4(%rcx),%rax
  lea    0x8(%rcx,%rsi,4),%rsi
  cs nopw 0x0(%rax,%rax,1)
L23:
  add    (%rax),%edx
  add    $0x4,%rax
  mov    %edx,-0x4(%rax)
  cmp    %rax,%rsi
  jne    L23
L71:
  mov    %r15d,%esi
  movslq %r15d,%r15
  lea    0x0(%rbp,%r15,4),%rdx
  nopl   0x0(%rax)
L137:
  movslq (%rdx),%rax
  sub    $0x1,%esi
  sub    $0x4,%rdx
  mov    %rax,%rdi
  lea    (%rcx,%rax,4),%rax
  movslq (%rax),%r8
  mov    %edi,-0x4(%rbx,%r8,4)
  subl   $0x1,(%rax)
  cmp    $0xffffffff,%esi
  jne    L137
L74:
  mov    %r14,%rdi
  call   <free@plt>
  mov    %rbp,%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)
L130:
  mov    $0x1c,%esi
  lea    D5(%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)
L105:
  mov    $0x30,%esi
  lea    D5(%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)
L62:
  mov    %rbx,%rcx
  lea    0x0(%rbp,%r13,4),%rsi
  mov    %rbp,%rax
  xor    %r12d,%r12d
  sub    %rbp,%rcx
  nopl   0x0(%rax)
L99:
  mov    (%rcx,%rax,1),%edx
  cmp    %edx,%r12d
  mov    %edx,(%rax)
  cmovl  %edx,%r12d
  add    $0x4,%rax
  cmp    %rax,%rsi
  jne    L99
  jmp    L175
  nopw   0x0(%rax,%rax,1)
L132:
  mov    $0x4,%edi
  call   <malloc@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L105
  movl   $0x0,(%r14)
  jmp    L74
L92:
  mov    $0xffffffff,%eax
  ret
```

tool_calls: name: disassemble_data
arguments: label: D5
type: 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;
}
```