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

```asm
<dwt_encode_1>:
  endbr64
  mov    %rdi,%rax
  mov    %esi,%edi
  movslq %edx,%rsi
  test   %ecx,%ecx
  jne    L148
  mov    %ecx,%edx
  test   %edi,%edi
  jg     L73
  cmp    $0x1,%esi
  jg     L265
  ret
  nopl   0x0(%rax)
L148:
  test   %esi,%esi
  jne    L329
  cmp    $0x1,%edi
  jne    L329
  shll   (%rax)
  ret
  nopl   0x0(%rax)
L329:
  push   %rbx
  test   %edi,%edi
  jle    L141
  lea    -0x1(%rsi,%rsi,1),%edx
  movslq %edi,%r11
  mov    $0x1,%r9d
  movslq %edx,%rdx
  lea    (%rax,%rdx,4),%rbx
  xor    %edx,%edx
  jmp    L259
  nopl   0x0(%rax)
L338:
  mov    (%rbx),%r10d
  test   %edx,%edx
  je     L185
  cmp    %edx,%esi
  jge    L321
  mov    %r10d,%ecx
L48:
  add    %r10d,%ecx
  add    $0x2,%r9d
  sar    %ecx
  sub    %ecx,%r8d
  mov    %r8d,(%rax,%rdx,8)
  add    $0x1,%rdx
  cmp    %rdx,%r11
  je     L141
L259:
  mov    (%rax,%rdx,8),%r8d
  cmp    %edx,%esi
  jle    L338
  mov    %r9d,%ecx
  mov    (%rax,%rcx,4),%r10d
  test   %edx,%edx
  je     L185
L321:
  mov    -0x4(%rax,%rdx,8),%ecx
  jmp    L48
  nopl   0x0(%rax,%rax,1)
L265:
  test   %edi,%edi
  jle    L213
L73:
  lea    -0x2(%rsi,%rsi,1),%ecx
  lea    0x4(%rax),%r8
  movslq %ecx,%rcx
  lea    (%rax,%rcx,4),%r11
  jmp    L119
  nopl   (%rax)
L60:
  add    $0x1,%edx
  mov    (%r11),%ecx
  cmp    %esi,%edx
  jl     L44
L79:
  mov    (%r11),%r10d
L309:
  add    %r10d,%ecx
  add    $0x8,%r8
  sar    %ecx
  sub    %ecx,%r9d
  mov    %r9d,-0x8(%r8)
  cmp    %edi,%edx
  je     L213
L119:
  mov    (%r8),%r9d
  cmp    %edx,%esi
  jle    L60
  add    $0x1,%edx
  mov    -0x4(%r8),%ecx
  cmp    %esi,%edx
  jge    L79
L44:
  lea    (%rdx,%rdx,1),%r10d
  movslq %r10d,%r10
  mov    (%rax,%r10,4),%r10d
  jmp    L309
  nopl   0x0(%rax,%rax,1)
L185:
  mov    0x4(%rax),%ecx
  jmp    L48
  nopl   0x0(%rax,%rax,1)
L213:
  test   %esi,%esi
  jle    L102
  lea    -0x1(%rdi,%rdi,1),%edx
  mov    $0x1,%r8d
  movslq %edx,%rdx
  lea    (%rax,%rdx,4),%r11
  xor    %edx,%edx
  jmp    L169
  nopl   (%rax)
L157:
  cmp    %edi,%edx
  jle    L219
  mov    (%r11),%ecx
  mov    %ecx,%r10d
L32:
  lea    0x2(%rcx,%r10,1),%ecx
  add    $0x2,%r8d
  sar    $0x2,%ecx
  add    %r9d,%ecx
  mov    %ecx,(%rax,%rdx,8)
  add    $0x1,%rdx
  cmp    %rsi,%rdx
  je     L193
L169:
  mov    (%rax,%rdx,8),%r9d
  mov    %edx,%ecx
  test   %rdx,%rdx
  jne    L157
  mov    0x4(%rax),%r10d
  cmp    %edi,%ecx
  jge    L7
L35:
  mov    %r8d,%ecx
  mov    (%rax,%rcx,4),%ecx
  jmp    L32
  nopl   0x0(%rax)
L219:
  mov    -0x4(%rax,%rdx,8),%r10d
  cmp    %edi,%ecx
  jl     L35
L7:
  mov    (%r11),%ecx
  jmp    L32
  cs nopw 0x0(%rax,%rax,1)
L141:
  test   %esi,%esi
  jle    L368
  lea    -0x2(%rdi,%rdi,1),%edx
  lea    0x4(%rax),%r8
  xor    %ecx,%ecx
  movslq %edx,%rdx
  lea    (%rax,%rdx,4),%r11
  jmp    L291
  nopw   0x0(%rax,%rax,1)
L167:
  add    $0x1,%ecx
  mov    (%r11),%r10d
  cmp    %edi,%ecx
  jl     L156
L75:
  mov    (%r11),%edx
L107:
  lea    0x2(%r10,%rdx,1),%edx
  add    $0x8,%r8
  sar    $0x2,%edx
  add    %r9d,%edx
  mov    %edx,-0x8(%r8)
  cmp    %esi,%ecx
  je     L368
L291:
  mov    (%r8),%r9d
  cmp    %ecx,%edi
  jle    L167
  add    $0x1,%ecx
  mov    -0x4(%r8),%r10d
  cmp    %edi,%ecx
  jge    L75
L156:
  lea    (%rcx,%rcx,1),%edx
  movslq %edx,%rdx
  mov    (%rax,%rdx,4),%edx
  jmp    L107
  nopl   0x0(%rax)
L368:
  pop    %rbx
  ret
  nopw   0x0(%rax,%rax,1)
L193:
  ret
  nopl   0x0(%rax)
L102:
  ret
```

assistant: ```c
void dwt_encode_1(int *a, int dn, int sn, int cas) {
  int i;
  if (!cas) {
    if ((dn > 0) || (sn > 1)) {
      for (i = 0; i < dn; i++)
        a[(1 + (i)*2)] -= (((i) < 0 ? a[(0) * 2] : ((i) >= sn ? a[(sn - 1) * 2] : a[(i)*2])) + ((i + 1) < 0 ? a[(0) * 2] : ((i + 1) >= sn ? a[(sn - 1) * 2] : a[(i + 1) * 2]))) >> 1;
      for (i = 0; i < sn; i++)
        a[(i)*2] += (((i - 1) < 0 ? a[(1 + (0) * 2)] : ((i - 1) >= dn ? a[(1 + (dn - 1) * 2)] : a[(1 + (i - 1) * 2)])) + ((i) < 0 ? a[(1 + (0) * 2)] : ((i) >= dn ? a[(1 + (dn - 1) * 2)] : a[(1 + (i)*2)])) + 2) >> 2;
    }
  } else {
    if (!sn && dn == 1)
      a[(0) * 2] *= 2;
    else {
      for (i = 0; i < dn; i++)
        a[(i)*2] -= (((i) < 0 ? a[(1 + (0) * 2)] : ((i) >= sn ? a[(1 + (sn - 1) * 2)] : a[(1 + (i)*2)])) + ((i - 1) < 0 ? a[(1 + (0) * 2)] : ((i - 1) >= sn ? a[(1 + (sn - 1) * 2)] : a[(1 + (i - 1) * 2)]))) >> 1;
      for (i = 0; i < sn; i++)
        a[(1 + (i)*2)] += (((i) < 0 ? a[(0) * 2] : ((i) >= dn ? a[(dn - 1) * 2] : a[(i)*2])) + ((i + 1) < 0 ? a[(0) * 2] : ((i + 1) >= dn ? a[(dn - 1) * 2] : a[(i + 1) * 2])) + 2) >> 2;
    }
  }
}
```