user: Converte this assembly snippet into its equivalent C code:

```asm
<CAST_cbc_encrypt>:
  endbr64
  push   %r15
  push   %r14
  mov    %rcx,%r14
  push   %r13
  push   %r12
  push   %rbp
  mov    %rdi,%rbp
  mov    %rdx,%rdi
  push   %rbx
  mov    %r8,%rbx
  sub    $0x68,%rsp
  mov    0x4(%r8),%ecx
  mov    %rdx,0x20(%rsp)
  mov    (%r8),%edx
  mov    %rsi,0x18(%rsp)
  bswap  %ecx
  mov    %ecx,%r15d
  lea    -0x8(%rdi),%rcx
  bswap  %edx
  mov    %edx,%r13d
  mov    %fs:0x28,%rax
  mov    %rax,0x58(%rsp)
  xor    %eax,%eax
  test   %r9d,%r9d
  je     L11
  test   %rcx,%rcx
  js     L22
  shr    $0x3,%rcx
  mov    %rsi,%r8
  lea    0x40(%rsp),%r12
  mov    %r15,%rsi
  lea    0x8(,%rcx,8),%rax
  mov    %rcx,(%rsp)
  mov    %r13,%rcx
  mov    %rbp,%r13
  mov    %rax,0x8(%rsp)
  add    %rbp,%rax
  mov    %r12,%rbp
  mov    %r8,%r12
  mov    %rbx,0x10(%rsp)
  mov    %rax,%rbx
  cs nopw 0x0(%rax,%rax,1)
L129:
  mov    0x0(%r13),%eax
  mov    0x4(%r13),%r15d
  mov    %rbp,%rdi
  add    $0x8,%r12
  add    $0x8,%r13
  bswap  %eax
  bswap  %r15d
  mov    %eax,%eax
  mov    %r15d,%r15d
  xor    %rcx,%rax
  xor    %rsi,%r15
  mov    %r14,%rsi
  mov    %rax,0x40(%rsp)
  mov    %r15,0x48(%rsp)
  call   <CAST_encrypt@plt>
  mov    0x40(%rsp),%rcx
  mov    0x48(%rsp),%rsi
  mov    %rcx,%rax
  mov    %cl,-0x5(%r12)
  shr    $0x18,%rax
  mov    %al,-0x8(%r12)
  mov    %rcx,%rax
  shr    $0x10,%rax
  mov    %al,-0x7(%r12)
  movzbl %ch,%eax
  mov    %al,-0x6(%r12)
  mov    %rsi,%rax
  shr    $0x18,%rax
  mov    %al,-0x4(%r12)
  mov    %rsi,%rax
  shr    $0x10,%rax
  mov    %al,-0x3(%r12)
  mov    %rsi,%rax
  movzbl %ah,%eax
  mov    %al,-0x2(%r12)
  mov    %sil,-0x1(%r12)
  cmp    %r13,%rbx
  jne    L129
  mov    (%rsp),%rax
  mov    0x8(%rsp),%rdi
  mov    %r13,%rbp
  mov    %rsi,%r15
  add    %rdi,0x18(%rsp)
  mov    0x20(%rsp),%rdi
  mov    %rcx,%r13
  neg    %rax
  mov    0x10(%rsp),%rbx
  lea    -0x10(%rdi,%rax,8),%rcx
L22:
  cmp    $0xfffffffffffffff8,%rcx
  je     L64
  lea    0x8(%rcx),%rax
  lea    0x0(%rbp,%rax,1),%r10
  cmp    $0x7,%rax
  ja     L96
  lea    D4(%rip),%rdi
  movslq (%rdi,%rax,4),%rax
  add    %rdi,%rax
  notrack jmp *%rax
  nopl   0x0(%rax)
L11:
  test   %rcx,%rcx
  js     L207
  shr    $0x3,%rcx
  mov    0x18(%rsp),%r8
  lea    0x40(%rsp),%r12
  mov    %rbx,0x38(%rsp)
  lea    0x8(,%rcx,8),%rax
  mov    %rcx,0x28(%rsp)
  mov    %r15,%rbx
  mov    %rax,0x30(%rsp)
  add    %rbp,%rax
  mov    %rax,0x8(%rsp)
  mov    %r12,0x10(%rsp)
  mov    %r8,%r12
  nopl   0x0(%rax)
L7:
  mov    0x0(%rbp),%eax
  mov    %r13,(%rsp)
  mov    %rbx,%r15
  mov    %r14,%rsi
  mov    0x10(%rsp),%rdi
  add    $0x8,%r12
  add    $0x8,%rbp
  bswap  %eax
  mov    %eax,%r13d
  mov    -0x4(%rbp),%eax
  mov    %r13,0x40(%rsp)
  bswap  %eax
  mov    %eax,%ebx
  mov    %rbx,0x48(%rsp)
  call   <CAST_decrypt@plt>
  mov    (%rsp),%rdx
  mov    0x48(%rsp),%rax
  xor    0x40(%rsp),%rdx
  mov    %rdx,%rsi
  xor    %r15,%rax
  movzbl %dh,%ecx
  mov    %dl,-0x5(%r12)
  shr    $0x18,%rsi
  mov    %cl,-0x6(%r12)
  movzbl %ah,%ecx
  mov    %sil,-0x8(%r12)
  mov    %rdx,%rsi
  mov    %rax,%rdx
  shr    $0x18,%rdx
  mov    %cl,-0x2(%r12)
  shr    $0x10,%rsi
  mov    %dl,-0x4(%r12)
  mov    %rax,%rdx
  mov    %sil,-0x7(%r12)
  shr    $0x10,%rdx
  mov    %dl,-0x3(%r12)
  mov    %al,-0x1(%r12)
  cmp    %rbp,0x8(%rsp)
  jne    L7
  mov    0x28(%rsp),%rax
  mov    0x30(%rsp),%rdi
  mov    %rbx,%r15
  add    %rdi,0x18(%rsp)
  mov    0x20(%rsp),%rdi
  neg    %rax
  mov    0x38(%rsp),%rbx
  lea    -0x10(%rdi,%rax,8),%rcx
L207:
  cmp    $0xfffffffffffffff8,%rcx
  mov    %rcx,(%rsp)
  jne    L105
L64:
  mov    %r13,%rax
  mov    %r15,%rcx
  mov    %r13,%r8
  mov    %r13,%rdi
  movzbl %ah,%eax
  movzbl %ch,%ecx
  mov    %r15,%rsi
  shr    $0x18,%r8
  mov    %rax,%r9
  mov    %r15,%rax
  mov    %rcx,%r10
  shr    $0x10,%rdi
  shr    $0x18,%rsi
  mov    %r13d,%edx
  shr    $0x10,%rax
  mov    %r15d,%ecx
L40:
  mov    %r8b,(%rbx)
  mov    %dil,0x1(%rbx)
  mov    %r9b,0x2(%rbx)
  mov    %dl,0x3(%rbx)
  mov    %sil,0x4(%rbx)
  mov    %al,0x5(%rbx)
  mov    %r10b,0x6(%rbx)
  mov    %cl,0x7(%rbx)
  mov    0x58(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L163
  add    $0x68,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L105:
  mov    0x0(%rbp),%r12d
  mov    0x4(%rbp),%eax
  lea    0x40(%rsp),%rdi
  mov    %r14,%rsi
  bswap  %eax
  bswap  %r12d
  mov    %eax,%r8d
  mov    %r12d,%r12d
  mov    %r8,0x48(%rsp)
  mov    %r8,0x8(%rsp)
  mov    %r12,0x40(%rsp)
  call   <CAST_decrypt@plt>
  mov    0x40(%rsp),%rdx
  mov    (%rsp),%rcx
  xor    0x48(%rsp),%r15
  mov    0x8(%rsp),%r8
  xor    %r13,%rdx
  mov    0x18(%rsp),%r13
  lea    0x8(%rcx),%rbp
  add    %rbp,%r13
  cmp    $0x7,%rbp
  ja     L119
  lea    D10(%rip),%rsi
  movslq (%rsi,%rbp,4),%rax
  add    %rsi,%rax
  notrack jmp *%rax
  mov    %r15,%rax
  sub    $0x1,%r13
  movzbl %ah,%eax
  mov    %al,0x0(%r13)
  mov    %r15,%rax
  sub    $0x1,%r13
  shr    $0x10,%rax
  mov    %al,0x0(%r13)
  mov    %r15,%rcx
  lea    -0x1(%r13),%rax
  shr    $0x18,%rcx
  mov    %cl,-0x1(%r13)
L87:
  mov    %dl,-0x1(%rax)
  lea    -0x1(%rax),%r13
  movzbl %dh,%ecx
  lea    -0x1(%r13),%rax
  mov    %cl,-0x1(%r13)
L150:
  mov    %rdx,%rcx
  lea    -0x1(%rax),%r13
  shr    $0x10,%rcx
  mov    %cl,-0x1(%rax)
  shr    $0x18,%rdx
  mov    %r8,%r15
  mov    %dl,-0x1(%r13)
  mov    %r12,%r13
  jmp    L64
  nopw   0x0(%rax,%rax,1)
  xor    %eax,%eax
L92:
  movzbl -0x1(%r10),%edi
  sub    $0x1,%r10
  shl    $0x10,%rdi
  or     %rax,%rdi
L103:
  movzbl -0x1(%r10),%eax
  lea    -0x1(%r10),%r8
  shl    $0x18,%rax
  or     %rdi,%rax
  xor    %rax,%r15
L208:
  lea    -0x1(%r8),%r10
  movzbl -0x1(%r8),%r8d
L55:
  movzbl -0x1(%r10),%eax
  lea    -0x1(%r10),%rdi
  shl    $0x8,%rax
  or     %r8,%rax
L12:
  lea    -0x1(%rdi),%r10
  movzbl -0x1(%rdi),%edi
  shl    $0x10,%rdi
  or     %rax,%rdi
L202:
  movzbl -0x1(%r10),%eax
  shl    $0x18,%rax
  or     %rdi,%rax
  xor    %rax,%r13
L96:
  mov    %r14,%rsi
  lea    0x40(%rsp),%rdi
  mov    %r13,0x40(%rsp)
  mov    %r15,0x48(%rsp)
  call   <CAST_encrypt@plt>
  mov    0x40(%rsp),%rdx
  mov    0x48(%rsp),%rcx
  mov    0x18(%rsp),%r14
  mov    0x40(%rsp),%eax
  movzbl %dh,%esi
  mov    0x48(%rsp),%r11d
  mov    %rdx,%r8
  mov    %rdx,%rdi
  bswap  %eax
  mov    %rsi,%r9
  mov    %eax,(%r14)
  mov    %rcx,%rsi
  mov    %rcx,%rax
  movzbl %ch,%ebp
  bswap  %r11d
  shr    $0x18,%r8
  mov    %r11d,0x4(%r14)
  shr    $0x10,%rdi
  shr    $0x18,%rsi
  mov    %rbp,%r10
  shr    $0x10,%rax
  jmp    L40
  nopl   0x0(%rax)
  xor    %edi,%edi
  jmp    L202
  nopl   0x0(%rax)
  mov    %r10,%rdi
  xor    %eax,%eax
  jmp    L12
  nopw   0x0(%rax,%rax,1)
  xor    %r8d,%r8d
  jmp    L55
  mov    %r10,%r8
  jmp    L208
  nopl   0x0(%rax,%rax,1)
  xor    %edi,%edi
  jmp    L103
  nopw   0x0(%rax,%rax,1)
  movzbl -0x1(%r10),%eax
  sub    $0x1,%r10
  shl    $0x8,%rax
  jmp    L92
  mov    %r13,%rax
  jmp    L87
  mov    %r13,%rax
  jmp    L150
L163:
  call   <__stack_chk_fail@plt>
L119:
  mov    %r8,%r15
  mov    %r12,%r13
  jmp    L64
```

assistant: ```c
void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, const CAST_KEY *ks, unsigned char *iv, int enc) {
  register CAST_LONG tin0, tin1;
  register CAST_LONG tout0, tout1, xor0, xor1;
  register long l = length;
  CAST_LONG tin[2];
  if (enc) {
    (tout0 = ((unsigned long)(*((iv)++))) << 24L, tout0 |= ((unsigned long)(*((iv)++))) << 16L, tout0 |= ((unsigned long)(*((iv)++))) << 8L, tout0 |= ((unsigned long)(*((iv)++))));
    (tout1 = ((unsigned long)(*((iv)++))) << 24L, tout1 |= ((unsigned long)(*((iv)++))) << 16L, tout1 |= ((unsigned long)(*((iv)++))) << 8L, tout1 |= ((unsigned long)(*((iv)++))));
    iv -= 8;
    for (l -= 8; l >= 0; l -= 8) {
      (tin0 = ((unsigned long)(*((in)++))) << 24L, tin0 |= ((unsigned long)(*((in)++))) << 16L, tin0 |= ((unsigned long)(*((in)++))) << 8L, tin0 |= ((unsigned long)(*((in)++))));
      (tin1 = ((unsigned long)(*((in)++))) << 24L, tin1 |= ((unsigned long)(*((in)++))) << 16L, tin1 |= ((unsigned long)(*((in)++))) << 8L, tin1 |= ((unsigned long)(*((in)++))));
      tin0 ^= tout0;
      tin1 ^= tout1;
      tin[0] = tin0;
      tin[1] = tin1;
      CAST_encrypt(tin, ks);
      tout0 = tin[0];
      tout1 = tin[1];
      (*((out)++) = (unsigned char)(((tout0) >> 24L) & 0xff), *((out)++) = (unsigned char)(((tout0) >> 16L) & 0xff), *((out)++) = (unsigned char)(((tout0) >> 8L) & 0xff), *((out)++) = (unsigned char)(((tout0)) & 0xff));
      (*((out)++) = (unsigned char)(((tout1) >> 24L) & 0xff), *((out)++) = (unsigned char)(((tout1) >> 16L) & 0xff), *((out)++) = (unsigned char)(((tout1) >> 8L) & 0xff), *((out)++) = (unsigned char)(((tout1)) & 0xff));
    }
    if (l != -8) {
      {
        in += l + 8;
        tin0 = tin1 = 0;
        switch (l + 8) {
        case 8:
          tin1 = ((unsigned long)(*(--(in))));
        case 7:
          tin1 |= ((unsigned long)(*(--(in)))) << 8;
        case 6:
          tin1 |= ((unsigned long)(*(--(in)))) << 16;
        case 5:
          tin1 |= ((unsigned long)(*(--(in)))) << 24;
        case 4:
          tin0 = ((unsigned long)(*(--(in))));
        case 3:
          tin0 |= ((unsigned long)(*(--(in)))) << 8;
        case 2:
          tin0 |= ((unsigned long)(*(--(in)))) << 16;
        case 1:
          tin0 |= ((unsigned long)(*(--(in)))) << 24;
        }
      };
      tin0 ^= tout0;
      tin1 ^= tout1;
      tin[0] = tin0;
      tin[1] = tin1;
      CAST_encrypt(tin, ks);
      tout0 = tin[0];
      tout1 = tin[1];
      (*((out)++) = (unsigned char)(((tout0) >> 24L) & 0xff), *((out)++) = (unsigned char)(((tout0) >> 16L) & 0xff), *((out)++) = (unsigned char)(((tout0) >> 8L) & 0xff), *((out)++) = (unsigned char)(((tout0)) & 0xff));
      (*((out)++) = (unsigned char)(((tout1) >> 24L) & 0xff), *((out)++) = (unsigned char)(((tout1) >> 16L) & 0xff), *((out)++) = (unsigned char)(((tout1) >> 8L) & 0xff), *((out)++) = (unsigned char)(((tout1)) & 0xff));
    }
    (*((iv)++) = (unsigned char)(((tout0) >> 24L) & 0xff), *((iv)++) = (unsigned char)(((tout0) >> 16L) & 0xff), *((iv)++) = (unsigned char)(((tout0) >> 8L) & 0xff), *((iv)++) = (unsigned char)(((tout0)) & 0xff));
    (*((iv)++) = (unsigned char)(((tout1) >> 24L) & 0xff), *((iv)++) = (unsigned char)(((tout1) >> 16L) & 0xff), *((iv)++) = (unsigned char)(((tout1) >> 8L) & 0xff), *((iv)++) = (unsigned char)(((tout1)) & 0xff));
  } else {
    (xor0 = ((unsigned long)(*((iv)++))) << 24L, xor0 |= ((unsigned long)(*((iv)++))) << 16L, xor0 |= ((unsigned long)(*((iv)++))) << 8L, xor0 |= ((unsigned long)(*((iv)++))));
    (xor1 = ((unsigned long)(*((iv)++))) << 24L, xor1 |= ((unsigned long)(*((iv)++))) << 16L, xor1 |= ((unsigned long)(*((iv)++))) << 8L, xor1 |= ((unsigned long)(*((iv)++))));
    iv -= 8;
    for (l -= 8; l >= 0; l -= 8) {
      (tin0 = ((unsigned long)(*((in)++))) << 24L, tin0 |= ((unsigned long)(*((in)++))) << 16L, tin0 |= ((unsigned long)(*((in)++))) << 8L, tin0 |= ((unsigned long)(*((in)++))));
      (tin1 = ((unsigned long)(*((in)++))) << 24L, tin1 |= ((unsigned long)(*((in)++))) << 16L, tin1 |= ((unsigned long)(*((in)++))) << 8L, tin1 |= ((unsigned long)(*((in)++))));
      tin[0] = tin0;
      tin[1] = tin1;
      CAST_decrypt(tin, ks);
      tout0 = tin[0] ^ xor0;
      tout1 = tin[1] ^ xor1;
      (*((out)++) = (unsigned char)(((tout0) >> 24L) & 0xff), *((out)++) = (unsigned char)(((tout0) >> 16L) & 0xff), *((out)++) = (unsigned char)(((tout0) >> 8L) & 0xff), *((out)++) = (unsigned char)(((tout0)) & 0xff));
      (*((out)++) = (unsigned char)(((tout1) >> 24L) & 0xff), *((out)++) = (unsigned char)(((tout1) >> 16L) & 0xff), *((out)++) = (unsigned char)(((tout1) >> 8L) & 0xff), *((out)++) = (unsigned char)(((tout1)) & 0xff));
      xor0 = tin0;
      xor1 = tin1;
    }
    if (l != -8) {
      (tin0 = ((unsigned long)(*((in)++))) << 24L, tin0 |= ((unsigned long)(*((in)++))) << 16L, tin0 |= ((unsigned long)(*((in)++))) << 8L, tin0 |= ((unsigned long)(*((in)++))));
      (tin1 = ((unsigned long)(*((in)++))) << 24L, tin1 |= ((unsigned long)(*((in)++))) << 16L, tin1 |= ((unsigned long)(*((in)++))) << 8L, tin1 |= ((unsigned long)(*((in)++))));
      tin[0] = tin0;
      tin[1] = tin1;
      CAST_decrypt(tin, ks);
      tout0 = tin[0] ^ xor0;
      tout1 = tin[1] ^ xor1;
      {
        out += l + 8;
        switch (l + 8) {
        case 8:
          *(--(out)) = (unsigned char)(((tout1)) & 0xff);
        case 7:
          *(--(out)) = (unsigned char)(((tout1) >> 8) & 0xff);
        case 6:
          *(--(out)) = (unsigned char)(((tout1) >> 16) & 0xff);
        case 5:
          *(--(out)) = (unsigned char)(((tout1) >> 24) & 0xff);
        case 4:
          *(--(out)) = (unsigned char)(((tout0)) & 0xff);
        case 3:
          *(--(out)) = (unsigned char)(((tout0) >> 8) & 0xff);
        case 2:
          *(--(out)) = (unsigned char)(((tout0) >> 16) & 0xff);
        case 1:
          *(--(out)) = (unsigned char)(((tout0) >> 24) & 0xff);
        }
      };
      xor0 = tin0;
      xor1 = tin1;
    }
    (*((iv)++) = (unsigned char)(((xor0) >> 24L) & 0xff), *((iv)++) = (unsigned char)(((xor0) >> 16L) & 0xff), *((iv)++) = (unsigned char)(((xor0) >> 8L) & 0xff), *((iv)++) = (unsigned char)(((xor0)) & 0xff));
    (*((iv)++) = (unsigned char)(((xor1) >> 24L) & 0xff), *((iv)++) = (unsigned char)(((xor1) >> 16L) & 0xff), *((iv)++) = (unsigned char)(((xor1) >> 8L) & 0xff), *((iv)++) = (unsigned char)(((xor1)) & 0xff));
  }
  tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
  tin[0] = tin[1] = 0;
}
```