user: Please show me the C implementation that matches the assembly code listed below:

```asm
<mergeSortAndCountInversion>:
  endbr64
  push   %r15
  xor    %r15d,%r15d
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  cmp    $0x1,%esi
  jle    L154
  mov    %esi,%r12d
  mov    %esi,%ebx
  mov    %rdi,%rbp
  sar    %r12d
  lea    0x0(,%r12,4),%edi
  sub    %r12d,%ebx
  call   <malloc@plt>
  lea    0x0(,%rbx,4),%edi
  mov    %rax,%r13
  call   <malloc@plt>
  lea    0x4(%rbp),%rdx
  mov    %rax,%r14
  mov    %r13,%rax
  sub    %rdx,%rax
  cmp    $0x8,%rax
  jbe    L10
  lea    -0x1(%r12),%eax
  cmp    $0x2,%eax
  jbe    L10
  mov    %r12d,%edx
  mov    %rbp,%rcx
  mov    %r13,%rax
  shr    $0x2,%edx
  sub    %r13,%rcx
  shl    $0x4,%rdx
  add    %r13,%rdx
  nopl   0x0(%rax,%rax,1)
L177:
  movdqu (%rax,%rcx,1),%xmm0
  add    $0x10,%rax
  movups %xmm0,-0x10(%rax)
  cmp    %rdx,%rax
  jne    L177
  mov    %r12d,%eax
  and    $0xfffffffc,%eax
  test   $0x3,%r12b
  je     L54
  mov    %eax,%ecx
  mov    0x0(%rbp,%rcx,4),%esi
  lea    0x0(,%rcx,4),%rdx
  mov    %esi,0x0(%r13,%rcx,4)
  lea    0x1(%rax),%ecx
  cmp    %ecx,%r12d
  jle    L54
  mov    0x4(%rbp,%rdx,1),%ecx
  add    $0x2,%eax
  mov    %ecx,0x4(%r13,%rdx,1)
  cmp    %eax,%r12d
  jle    L54
  mov    0x8(%rbp,%rdx,1),%eax
  mov    %eax,0x8(%r13,%rdx,1)
L54:
  test   %ebx,%ebx
  jle    L145
  lea    0x1(%r12),%ecx
  mov    %r14,%rax
  lea    -0x1(%rbx),%edx
  movslq %ecx,%rcx
  shl    $0x2,%rcx
  lea    0x0(%rbp,%rcx,1),%rsi
  sub    %rsi,%rax
  cmp    $0x8,%rax
  jbe    L55
  cmp    $0x2,%edx
  jbe    L55
  mov    %ebx,%edx
  mov    %rbp,%rsi
  mov    %r14,%rax
  shr    $0x2,%edx
  sub    %r14,%rsi
  shl    $0x4,%rdx
  lea    -0x4(%rsi,%rcx,1),%rcx
  add    %r14,%rdx
  nopw   0x0(%rax,%rax,1)
L59:
  movdqu (%rax,%rcx,1),%xmm1
  add    $0x10,%rax
  movups %xmm1,-0x10(%rax)
  cmp    %rdx,%rax
  jne    L59
  mov    %ebx,%eax
  and    $0xfffffffc,%eax
  test   $0x3,%bl
  je     L145
  lea    (%r12,%rax,1),%edx
  movslq %eax,%rsi
  movslq %edx,%rdx
  lea    0x0(,%rsi,4),%rcx
  mov    0x0(%rbp,%rdx,4),%edx
  mov    %edx,(%r14,%rsi,4)
  lea    0x1(%rax),%edx
  cmp    %edx,%ebx
  jle    L145
  add    %r12d,%edx
  add    $0x2,%eax
  movslq %edx,%rdx
  mov    0x0(%rbp,%rdx,4),%edx
  mov    %edx,0x4(%r14,%rcx,1)
  cmp    %eax,%ebx
  jle    L145
  add    %r12d,%eax
  cltq
  mov    0x0(%rbp,%rax,4),%eax
  mov    %eax,0x8(%r14,%rcx,1)
L145:
  mov    %r12d,%esi
  mov    %r13,%rdi
  call   <mergeSortAndCountInversion>
  mov    %ebx,%esi
  mov    %r14,%rdi
  mov    %eax,%r15d
  call   <mergeSortAndCountInversion>
  mov    %ebx,%r8d
  mov    %r14,%rcx
  mov    %r12d,%edx
  mov    %r13,%rsi
  mov    %rbp,%rdi
  add    %eax,%r15d
  call   <mergeAndCountInversion@plt>
  mov    %r13,%rdi
  add    %eax,%r15d
  call   <free@plt>
  mov    %r14,%rdi
  call   <free@plt>
L154:
  add    $0x8,%rsp
  mov    %r15d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L10:
  mov    %r12d,%eax
  mov    %rbp,%rcx
  lea    0x0(%r13,%rax,4),%rsi
  sub    %r13,%rcx
  mov    %r13,%rax
  nopl   0x0(%rax)
L70:
  mov    (%rcx,%rax,1),%edx
  add    $0x4,%rax
  mov    %edx,-0x4(%rax)
  cmp    %rsi,%rax
  jne    L70
  jmp    L54
  nopl   0x0(%rax)
L55:
  lea    0x4(%r14,%rdx,4),%rsi
  mov    %rbp,%rdx
  mov    %r14,%rax
  sub    %r14,%rdx
  lea    -0x4(%rdx,%rcx,1),%rcx
  nopl   0x0(%rax,%rax,1)
L117:
  mov    (%rcx,%rax,1),%edx
  add    $0x4,%rax
  mov    %edx,-0x4(%rax)
  cmp    %rax,%rsi
  jne    L117
  jmp    L145
```

assistant: ```c
int mergeSortAndCountInversion(int A[], int length) {
  if (length < 2) {
    return 0;
  }
  int inversionCount = 0;
  int middle = length / 2;
  int *L = (int *)malloc(middle * sizeof(int));
  int *R = (int *)malloc((length - middle) * sizeof(int));
  int i;
  for (i = 0; i < middle; i++) {
    L[i] = A[i];
  }
  for (i = 0; i < length - middle; i++) {
    R[i] = A[middle + i];
  }
  inversionCount += mergeSortAndCountInversion(L, middle);
  inversionCount += mergeSortAndCountInversion(R, length - middle);
  inversionCount += mergeAndCountInversion(A, L, middle, R, length - middle);
  free(L);
  free(R);
  return inversionCount;
}
```