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

```asm
<kernel_dgetr_3_lib4>:
  endbr64
  xor    %eax,%eax
  cmp    $0x1,%edi
  push   %r12
  mov    %edx,%r10d
  sete   %al
  push   %rbp
  lea    (%rsi,%rax,1),%r11d
  push   %rbx
  xor    %ebx,%ebx
  cmp    %edx,%r11d
  jl     L109
  test   %edx,%edx
  jle    L33
  movslq %edx,%rsi
  mov    %r8,%rdx
  mov    %rsi,%rax
  shl    $0x5,%rax
  add    %rcx,%rax
  nopw   0x0(%rax,%rax,1)
L30:
  movsd  (%rcx),%xmm0
  add    $0x20,%rcx
  add    $0x8,%rdx
  movsd  %xmm0,-0x8(%rdx)
  movsd  -0x18(%rcx),%xmm0
  movsd  %xmm0,0x18(%rdx)
  movsd  -0x10(%rcx),%xmm0
  movsd  %xmm0,0x38(%rdx)
  cmp    %rax,%rcx
  jne    L30
  lea    -0x4(,%r9,4),%edx
  mov    %r10d,%ebx
  movslq %edx,%rdx
  add    %rsi,%rdx
  lea    (%r8,%rdx,8),%r8
L53:
  lea    -0x3(%r11),%edx
  cmp    %edx,%ebx
  jge    L52
  lea    -0x4(%r11),%ebp
  lea    0x0(,%r9,4),%esi
  mov    %r8,%rdx
  sub    %ebx,%ebp
  movslq %esi,%rsi
  shr    $0x2,%ebp
  shl    $0x3,%rsi
  lea    0x1(%rbp),%r12d
  mov    %r12,%rcx
  shl    $0x7,%rcx
  add    %rax,%rcx
  nopl   0x0(%rax)
L26:
  movsd  (%rax),%xmm0
  sub    $0xffffffffffffff80,%rax
  movsd  %xmm0,(%rdx)
  movsd  -0x78(%rax),%xmm0
  movsd  %xmm0,0x20(%rdx)
  movsd  -0x70(%rax),%xmm0
  movsd  %xmm0,0x40(%rdx)
  movsd  -0x60(%rax),%xmm0
  movsd  %xmm0,0x8(%rdx)
  movsd  -0x58(%rax),%xmm0
  movsd  %xmm0,0x28(%rdx)
  movsd  -0x50(%rax),%xmm0
  movsd  %xmm0,0x48(%rdx)
  movsd  -0x40(%rax),%xmm0
  movsd  %xmm0,0x10(%rdx)
  movsd  -0x38(%rax),%xmm0
  movsd  %xmm0,0x30(%rdx)
  movsd  -0x30(%rax),%xmm0
  movsd  %xmm0,0x50(%rdx)
  movsd  -0x20(%rax),%xmm0
  movsd  %xmm0,0x18(%rdx)
  movsd  -0x18(%rax),%xmm0
  movsd  %xmm0,0x38(%rdx)
  movsd  -0x10(%rax),%xmm0
  movsd  %xmm0,0x58(%rdx)
  add    %rsi,%rdx
  cmp    %rcx,%rax
  jne    L26
  imul   %r12,%rsi
  lea    0x4(%rbx,%rbp,4),%ebx
  add    %rsi,%r8
L109:
  mov    %r8,%rdx
  cmp    %ebx,%r11d
  jle    L70
  lea    -0x1(%r11),%esi
  mov    %rcx,%rax
  sub    %ebx,%esi
  add    $0x1,%rsi
  lea    (%r8,%rsi,8),%rdx
  nopw   0x0(%rax,%rax,1)
L1:
  movsd  (%rax),%xmm0
  add    $0x8,%r8
  add    $0x20,%rax
  movsd  %xmm0,-0x8(%r8)
  movsd  -0x18(%rax),%xmm0
  movsd  %xmm0,0x18(%r8)
  movsd  -0x10(%rax),%xmm0
  movsd  %xmm0,0x38(%r8)
  cmp    %rdx,%r8
  jne    L1
  shl    $0x5,%rsi
  add    %rsi,%rcx
L70:
  cmp    $0x1,%edi
  je     L48
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
  cs nopw 0x0(%rax,%rax,1)
L33:
  mov    %rcx,%rax
  xor    %ebx,%ebx
  jmp    L53
  nopw   0x0(%rax,%rax,1)
L48:
  movsd  0x8(%rcx),%xmm0
  sub    %r11d,%r10d
  and    $0x3,%r10d
  movsd  %xmm0,0x20(%rdx)
  movsd  0x10(%rcx),%xmm0
  movsd  %xmm0,0x40(%rdx)
  movsd  0x30(%rcx),%xmm0
  cmp    $0x1,%r10d
  je     L46
  movsd  %xmm0,0x48(%rdx)
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L46:
  lea    0x5(,%r9,4),%eax
  cltq
  movsd  %xmm0,(%rdx,%rax,8)
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L52:
  mov    %rax,%rcx
  jmp    L109
```

assistant: ```c
void kernel_dgetr_3_lib4(int tri, int kmax, int kna, double *A, double *C, int sdc) {
  if (tri == 1) {
    kmax += 1;
  }
  const int bs = 4;
  int k;
  k = 0;
  if (kmax < kna)
    goto cleanup_loop;
  if (kna > 0) {
    for (; k < kna; k++) {
      C[0 + bs * 0] = A[0 + bs * 0];
      C[0 + bs * 1] = A[1 + bs * 0];
      C[0 + bs * 2] = A[2 + bs * 0];
      C += 1;
      A += bs;
    }
    C += bs * (sdc - 1);
  }
  for (; k < kmax - 3; k += 4) {
    C[0 + bs * 0] = A[0 + bs * 0];
    C[0 + bs * 1] = A[1 + bs * 0];
    C[0 + bs * 2] = A[2 + bs * 0];
    C[1 + bs * 0] = A[0 + bs * 1];
    C[1 + bs * 1] = A[1 + bs * 1];
    C[1 + bs * 2] = A[2 + bs * 1];
    C[2 + bs * 0] = A[0 + bs * 2];
    C[2 + bs * 1] = A[1 + bs * 2];
    C[2 + bs * 2] = A[2 + bs * 2];
    C[3 + bs * 0] = A[0 + bs * 3];
    C[3 + bs * 1] = A[1 + bs * 3];
    C[3 + bs * 2] = A[2 + bs * 3];
    C += bs * sdc;
    A += bs * bs;
  }
cleanup_loop:
  for (; k < kmax; k++) {
    C[0 + bs * 0] = A[0 + bs * 0];
    C[0 + bs * 1] = A[1 + bs * 0];
    C[0 + bs * 2] = A[2 + bs * 0];
    C += 1;
    A += bs;
  }
  if (tri == 1) {
    kna = (bs - (bs - kna + kmax) % bs) % bs;
    if (kna == 1) {
      C[0 + bs * 1] = A[1 + bs * 0];
      C[0 + bs * 2] = A[2 + bs * 0];
      C[1 + bs * (sdc + 1)] = A[2 + bs * 1];
    } else {
      C[0 + bs * 1] = A[1 + bs * 0];
      C[0 + bs * 2] = A[2 + bs * 0];
      C[1 + bs * 2] = A[2 + bs * 1];
    }
  }
}
```