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

```asm
<counting_sort>:
  endbr64
  test   %rdi,%rdi
  je     L122
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  mov    %rdi,%r12
  mov    %esi,%ebp
  lea    0x0(,%rsi,4),%edi
  call   <malloc@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L26
  test   %ebp,%ebp
  jle    L12
  mov    %ebp,%eax
  lea    0x0(%r13,%rax,4),%rsi
  mov    %r13,%rax
  mov    $0x0,%ebx
  mov    %r12,%rcx
  sub    %r13,%rcx
L17:
  mov    (%rcx,%rax,1),%edx
  cmp    %edx,%ebx
  cmovl  %edx,%ebx
  mov    %edx,(%rax)
  add    $0x4,%rax
  cmp    %rsi,%rax
  jne    L17
  add    $0x1,%ebx
  lea    0x0(,%rbx,4),%edi
  call   <malloc@plt>
  mov    %rax,%rdi
  test   %rax,%rax
  je     L110
  mov    $0x0,%eax
  test   %ebx,%ebx
  jle    L42
L85:
  movl   $0x0,(%rdi,%rax,4)
  add    $0x1,%rax
  cmp    %eax,%ebx
  jg     L85
L19:
  test   %ebp,%ebp
  jle    L125
L42:
  mov    %r12,%rax
  lea    -0x1(%rbp),%edx
  lea    0x4(%r12,%rdx,4),%rcx
L75:
  movslq (%rax),%rdx
  addl   $0x1,(%rdi,%rdx,4)
  add    $0x4,%rax
  cmp    %rcx,%rax
  jne    L75
  cmp    $0x1,%ebx
  jle    L119
L199:
  mov    $0x1,%eax
L142:
  mov    -0x4(%rdi,%rax,4),%edx
  add    %edx,(%rdi,%rax,4)
  add    $0x1,%rax
  cmp    %eax,%ebx
  jg     L142
  sub    $0x1,%ebp
  js     L80
L167:
  movslq %ebp,%rax
  lea    0x0(%r13,%rax,4),%rdx
L97:
  mov    (%rdx),%ecx
  movslq %ecx,%rax
  lea    (%rdi,%rax,4),%rax
  movslq (%rax),%rsi
  mov    %ecx,-0x4(%r12,%rsi,4)
  subl   $0x1,(%rax)
  sub    $0x4,%rdx
  sub    $0x1,%ebp
  jns    L97
L80:
  call   <free@plt>
  mov    %r13,%rdi
  call   <free@plt>
  mov    $0x0,%eax
L131:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L26:
  mov    $0x1c,%esi
  lea    D6(%rip),%rdi
  call   <printf@plt>
  mov    $0x0,%eax
  jmp    L131
L110:
  mov    $0x30,%esi
  lea    D6(%rip),%rdi
  call   <printf@plt>
  mov    $0x0,%eax
  jmp    L131
L125:
  cmp    $0x1,%ebx
  jg     L199
  jmp    L80
L122:
  mov    $0xffffffff,%eax
  ret
L119:
  sub    $0x1,%ebp
  jmp    L167
L12:
  mov    $0x4,%edi
  call   <malloc@plt>
  mov    %rax,%rdi
  test   %rax,%rax
  je     L110
  movl   $0x0,(%rax)
  mov    $0x1,%ebx
  jmp    L19
```

tool_calls: name: read_data
arguments: data_tag: D6
type_guessed: string

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