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

```asm
<merge>:
  endbr64
  push   %r14
  movslq %edx,%rax
  push   %r13
  push   %r12
  mov    %rax,%r12
  push   %rbp
  push   %rbx
  mov    %rsi,%rbx
  mov    %ecx,%esi
  lea    (%rbx,%rax,4),%rdx
  test   %eax,%eax
  jle    L164
  test   %ecx,%ecx
  jle    L164
  mov    %rdi,%rbp
  mov    %rbx,%rcx
  mov    %r8,%rax
  xor    %r9d,%r9d
  xor    %edi,%edi
  jmp    L85
  nopl   0x0(%rax,%rax,1)
L291:
  add    $0x1,%edi
  mov    %r13d,-0x4(%rax)
  add    $0x4,%rcx
  cmp    %r12d,%edi
  jge    L208
L36:
  cmp    %esi,%r9d
  jge    L208
L85:
  movslq (%rcx),%r13
  movslq (%rdx),%r14
  add    $0x4,%rax
  movsd  0x0(%rbp,%r14,8),%xmm0
  comisd 0x0(%rbp,%r13,8),%xmm0
  jae    L291
  mov    %r14d,-0x4(%rax)
  add    $0x4,%rdx
  add    $0x1,%r9d
  cmp    %edi,%r12d
  jg     L36
  nopl   0x0(%rax,%rax,1)
L87:
  cmp    %r9d,%esi
  jle    L23
  lea    0x4(%rdx),%rdi
  mov    %rax,%rcx
  mov    %esi,%r10d
  sub    %rdi,%rcx
  sub    %r9d,%r10d
  cmp    $0x8,%rcx
  jbe    L123
  lea    -0x1(%r10),%ecx
  cmp    $0x2,%ecx
  jbe    L123
  mov    %r10d,%edi
  xor    %ecx,%ecx
  shr    $0x2,%edi
  shl    $0x4,%rdi
  nopl   0x0(%rax)
L115:
  movdqu (%rdx,%rcx,1),%xmm2
  movups %xmm2,(%rax,%rcx,1)
  add    $0x10,%rcx
  cmp    %rcx,%rdi
  jne    L115
  mov    %r10d,%edi
  and    $0xfffffffc,%edi
  mov    %edi,%ecx
  add    %edi,%r9d
  shl    $0x2,%rcx
  add    %rcx,%rax
  add    %rcx,%rdx
  cmp    %edi,%r10d
  je     L23
  mov    (%rdx),%ecx
  mov    %ecx,(%rax)
  lea    0x1(%r9),%ecx
  cmp    %ecx,%esi
  jle    L23
  mov    0x4(%rdx),%ecx
  add    $0x2,%r9d
  mov    %ecx,0x4(%rax)
  cmp    %esi,%r9d
  jge    L23
  mov    0x8(%rdx),%edx
  mov    %edx,0x8(%rax)
L23:
  add    %r12d,%esi
  je     L3
  lea    0x4(%r8),%rdx
  mov    %rbx,%rax
  sub    %rdx,%rax
  cmp    $0x8,%rax
  jbe    L63
  lea    -0x1(%rsi),%eax
  cmp    $0x2,%eax
  jbe    L63
  mov    %esi,%edx
  xor    %eax,%eax
  shr    $0x2,%edx
  shl    $0x4,%rdx
  nopl   (%rax)
L97:
  movdqu (%r8,%rax,1),%xmm3
  movups %xmm3,(%rbx,%rax,1)
  add    $0x10,%rax
  cmp    %rdx,%rax
  jne    L97
  mov    %esi,%edx
  mov    %esi,%ecx
  and    $0xfffffffc,%edx
  and    $0x3,%ecx
  mov    %edx,%eax
  shl    $0x2,%rax
  add    %rax,%r8
  add    %rbx,%rax
  cmp    %edx,%esi
  je     L3
  mov    (%r8),%edx
  mov    %edx,(%rax)
  cmp    $0x1,%ecx
  je     L3
  mov    0x4(%r8),%edx
  mov    %edx,0x4(%rax)
  cmp    $0x2,%ecx
  je     L3
  mov    0x8(%r8),%edx
  mov    %edx,0x8(%rax)
L3:
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
  nopl   0x0(%rax,%rax,1)
L164:
  mov    %rbx,%rcx
  mov    %r8,%rax
  xor    %r9d,%r9d
  xor    %edi,%edi
  nopl   0x0(%rax,%rax,1)
L208:
  cmp    %edi,%r12d
  jle    L87
  mov    %r12d,%r13d
  lea    0x4(%rcx),%r11
  mov    %rax,%r10
  sub    %edi,%r13d
  sub    %r11,%r10
  lea    -0x1(%r13),%ebp
  cmp    $0x8,%r10
  jbe    L245
  cmp    $0x2,%ebp
  jbe    L245
  mov    %r13d,%r11d
  xor    %r10d,%r10d
  shr    $0x2,%r11d
  shl    $0x4,%r11
  xchg   %ax,%ax
L30:
  movdqu (%rcx,%r10,1),%xmm1
  movups %xmm1,(%rax,%r10,1)
  add    $0x10,%r10
  cmp    %r10,%r11
  jne    L30
  mov    %r13d,%r11d
  and    $0xfffffffc,%r11d
  mov    %r11d,%r10d
  add    %r11d,%edi
  shl    $0x2,%r10
  lea    (%rax,%r10,1),%r14
  add    %r10,%rcx
  cmp    %r11d,%r13d
  je     L100
  mov    (%rcx),%r10d
  mov    %r10d,(%r14)
  lea    0x1(%rdi),%r10d
  cmp    %r12d,%r10d
  jge    L100
  mov    0x4(%rcx),%r10d
  add    $0x2,%edi
  mov    %r10d,0x4(%r14)
  cmp    %r12d,%edi
  jge    L100
  mov    0x8(%rcx),%ecx
  mov    %ecx,0x8(%r14)
L100:
  mov    %ebp,%ebp
  lea    0x4(%rax,%rbp,4),%rax
  jmp    L87
  nopl   0x0(%rax,%rax,1)
L245:
  lea    -0x1(%r12),%r10d
  sub    %edi,%r10d
  xor    %edi,%edi
  lea    0x4(,%r10,4),%r11
  nopw   0x0(%rax,%rax,1)
L128:
  mov    (%rcx,%rdi,1),%r10d
  mov    %r10d,(%rax,%rdi,1)
  add    $0x4,%rdi
  cmp    %rdi,%r11
  jne    L128
  mov    %ebp,%ebp
  lea    0x4(%rax,%rbp,4),%rax
  jmp    L87
  nopl   (%rax)
L123:
  lea    -0x1(%rsi),%ecx
  sub    %r9d,%ecx
  lea    0x4(,%rcx,4),%r9
  xor    %ecx,%ecx
L293:
  mov    (%rdx,%rcx,1),%edi
  mov    %edi,(%rax,%rcx,1)
  add    $0x4,%rcx
  cmp    %rcx,%r9
  jne    L293
  jmp    L23
  nopl   0x0(%rax)
L63:
  mov    %esi,%esi
  xor    %eax,%eax
  nopl   0x0(%rax)
L126:
  mov    (%r8,%rax,4),%edx
  mov    %edx,(%rbx,%rax,4)
  add    $0x1,%rax
  cmp    %rax,%rsi
  jne    L126
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
```

assistant: ```c
void merge(double *vals, int *indices, int length1, int length2, int *space) {
  int n1, n2;
  int *spaceptr;
  int *index1, *index2;
  n1 = n2 = 0;
  spaceptr = space;
  index1 = indices;
  index2 = indices + length1;
  while (n1 < length1 && n2 < length2) {
    if (vals[*index1] <= vals[*index2]) {
      *spaceptr++ = *index1++;
      ++n1;
    } else {
      *spaceptr++ = *index2++;
      ++n2;
    }
  }
  while (n1 < length1) {
    *spaceptr++ = *index1++;
    ++n1;
  }
  while (n2 < length2) {
    *spaceptr++ = *index2++;
    ++n2;
  }
  spaceptr = space;
  index1 = indices;
  for (n1 = length1 + length2; n1; n1--)
    *index1++ = *spaceptr++;
}
```