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

```asm
<RGB32toBGR32>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %rdi,%r15
  mov    %edx,0x10(%rsp)
  mov    %ecx,%r13d
  mov    %r8d,0x8(%rsp)
  mov    %r9d,%ebx
  mov    0xa0(%rsp),%rbp
  mov    0xb8(%rsp),%r12d
  mov    0xd0(%rsp),%r14d
  mov    %fs:0x28,%rax
  mov    %rax,0x48(%rsp)
  xor    %eax,%eax
  lea    0x44(%rsp),%rax
  push   %rax
  lea    0x48(%rsp),%rax
  push   %rax
  mov    0xe8(%rsp),%eax
  push   %rax
  push   %r14
  mov    0xe8(%rsp),%eax
  push   %rax
  mov    0xe8(%rsp),%eax
  push   %rax
  push   %r12
  mov    0xe8(%rsp),%eax
  push   %rax
  mov    0xe8(%rsp),%eax
  push   %rax
  push   %rbp
  mov    0xe8(%rsp),%eax
  push   %rax
  mov    0xe8(%rsp),%eax
  push   %rax
  call   <chk_args@plt>
  add    $0x60,%rsp
  test   %eax,%eax
  je     L45
  test   %r12d,%r12d
  js     L150
L147:
  test   %r13d,%r13d
  js     L75
L272:
  mov    0x40(%rsp),%eax
  cmp    $0x1,%eax
  je     L3
  cmp    $0x2,%eax
  jne    L102
  cmpl   $0x2,0x44(%rsp)
  jne    L35
  mov    0xc0(%rsp),%eax
  shl    $0x2,%eax
  cltq
  mov    %r12d,%edx
  imul   0xc8(%rsp),%edx
  movslq %edx,%rdx
  add    %rdx,%rax
  add    %rax,%rbp
  mov    0x8(%rsp),%eax
  shl    $0x2,%eax
  cltq
  imul   %r13d,%ebx
  movslq %ebx,%rdx
  lea    (%rax,%rdx,1),%rbx
  add    %r15,%rbx
  cmpl   $0x0,0xd8(%rsp)
  jle    L4
  lea    0x0(,%r14,8),%r15d
  movslq %r15d,%rax
  neg    %rax
  mov    %rax,0x8(%rsp)
  movslq %r12d,%r12
  lea    0x0(,%r14,4),%eax
  cltq
  sub    %rax,%r12
  mov    %r12,0x18(%rsp)
  lea    0x0(%r13,%r13,1),%eax
  cltq
  mov    %rax,0x10(%rsp)
  lea    -0x1(%r14),%eax
  mov    %eax,0x24(%rsp)
  mov    %eax,%eax
  add    $0x1,%rax
  lea    0x0(,%rax,8),%rsi
  mov    %rsi,0x30(%rsp)
  shl    $0x2,%rax
  mov    %rax,0x38(%rsp)
  mov    $0x0,%r12d
  movslq %r13d,%r13
  mov    %r13,0x28(%rsp)
  mov    0xd8(%rsp),%r13d
  jmp    L275
L150:
  mov    0xb0(%rsp),%eax
  sub    $0x1,%eax
  imul   %r12d,%eax
  cltq
  sub    %rax,%rbp
  jmp    L147
L75:
  mov    0x10(%rsp),%eax
  sub    $0x1,%eax
  imul   %r13d,%eax
  cltq
  sub    %rax,%r15
  jmp    L272
L3:
  mov    $0xffffffff,%eax
  cmpl   $0x1,0x44(%rsp)
  jne    L15
  mov    0xc0(%rsp),%eax
  lea    0x0(,%rax,4),%esi
  movslq %esi,%rsi
  mov    %r12d,%eax
  imul   0xc8(%rsp),%eax
  cltq
  add    %rax,%rsi
  add    %rbp,%rsi
  mov    0x8(%rsp),%edi
  shl    $0x2,%edi
  movslq %edi,%rdi
  mov    %ebx,%eax
  imul   %r13d,%eax
  cltq
  add    %rax,%rdi
  add    %r15,%rdi
  cmpl   $0x0,0x98(%rsp)
  jle    L224
  mov    0x90(%rsp),%eax
  shl    $0x2,%eax
  mov    %r12d,%r11d
  sub    %eax,%r11d
  movslq %r11d,%r11
  sub    %eax,%r13d
  movslq %r13d,%rbx
  mov    0x90(%rsp),%eax
  lea    -0x1(%rax),%r8d
  mov    %r8d,%eax
  lea    0x4(,%rax,4),%r10
  mov    $0x0,%r9d
  mov    %r8d,%r8d
  mov    0x90(%rsp),%ebp
  mov    0x98(%rsp),%r12d
  jmp    L13
L65:
  mov    (%rsi,%rcx,4),%edx
  mov    %edx,%eax
  shl    $0x10,%eax
  and    $0xff0000,%eax
  mov    %edx,%r13d
  shr    $0x10,%r13d
  movzbl %r13b,%r13d
  or     %r13d,%eax
  and    $0xff00,%edx
  or     %edx,%eax
  mov    %eax,(%rdi,%rcx,4)
  mov    %rcx,%rax
  add    $0x1,%rcx
  cmp    %r8,%rax
  jne    L65
  add    %r10,%rsi
  add    %r10,%rdi
L77:
  add    %r11,%rsi
  add    %rbx,%rdi
  add    $0x1,%r9d
  cmp    %r9d,%r12d
  je     L67
L13:
  mov    $0x0,%ecx
  test   %ebp,%ebp
  jne    L65
  jmp    L77
L131:
  mov    0x0(%rbp,%rdx,4),%ecx
  mov    %ecx,%eax
  shl    $0x10,%eax
  and    $0xff0000,%eax
  mov    %ecx,%edi
  shr    $0x10,%edi
  movzbl %dil,%edi
  or     %edi,%eax
  and    $0xff00,%ecx
  or     %ecx,%eax
  mov    %eax,(%rbx,%rdx,8)
  mov    %eax,0x4(%rbx,%rdx,8)
  mov    %rdx,%rax
  add    $0x1,%rdx
  cmp    %rsi,%rax
  jne    L131
  add    0x30(%rsp),%rbx
  add    0x38(%rsp),%rbp
L271:
  add    0x8(%rsp),%rbx
  mov    0x28(%rsp),%rax
  lea    (%rbx,%rax,1),%rdi
  mov    %r15d,%edx
  mov    %rbx,%rsi
  call   <memcpy@plt>
  add    0x18(%rsp),%rbp
  add    0x10(%rsp),%rbx
  add    $0x1,%r12d
  cmp    %r12d,%r13d
  je     L135
L275:
  mov    0x24(%rsp),%esi
  mov    $0x0,%edx
  test   %r14d,%r14d
  jne    L131
  jmp    L271
L45:
  mov    $0xffffffff,%eax
  jmp    L15
L224:
  mov    $0x0,%eax
  jmp    L15
L67:
  mov    $0x0,%eax
  jmp    L15
L102:
  mov    $0xffffffff,%eax
  jmp    L15
L35:
  mov    $0xffffffff,%eax
  jmp    L15
L4:
  mov    $0x0,%eax
  jmp    L15
L135:
  mov    $0x0,%eax
L15:
  mov    0x48(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L81
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L81:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int RGB32toBGR32(unsigned char *dest_ptr, int dest_width, int dest_height, int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy, unsigned char *src_ptr, int src_width, int src_height, int src_pitch, int src_x, int src_y, int src_dx, int src_dy) {
  int scale_x, scale_y;
  if (!chk_args(dest_ptr, dest_width, dest_height, dest_pitch, dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height, src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
    return -1;
  if (src_pitch < 0)
    src_ptr -= (src_height - 1) * src_pitch;
  if (dest_pitch < 0)
    dest_ptr -= (dest_height - 1) * dest_pitch;
  if (scale_x == 1 && scale_y == 1) {
    unsigned char *s, *d;
    register int i;
    s = src_ptr + src_x * 4 + src_y * src_pitch;
    d = dest_ptr + dest_x * 4 + dest_y * dest_pitch;
    for (i = 0; i < dest_dy; i++) {
      register int ddx = dest_dx;
      while (ddx) {
        register unsigned int a;
        a = *(unsigned int *)s;
        *(unsigned int *)d = ((a & 0x000000ff) << 16) | ((a & 0x0000ff00) << 0) | ((a & 0x00ff0000) >> 16);
        s += 4;
        d += 4;
        ddx--;
      }
      s += src_pitch - dest_dx * 4;
      d += dest_pitch - dest_dx * 4;
    }
    return 0;
  }
  if (scale_x == 2 && scale_y == 2) {
    unsigned char *s, *d;
    register int i;
    s = src_ptr + src_x * 4 + src_y * src_pitch;
    d = dest_ptr + dest_x * 4 + dest_y * dest_pitch;
    for (i = 0; i < src_dy; i++) {
      register int sdx = src_dx;
      while (sdx) {
        register unsigned int a, c;
        a = *(unsigned int *)s;
        c = ((a & 0x000000ff) << 16) | ((a & 0x0000ff00) << 0) | ((a & 0x00ff0000) >> 16);
        *(unsigned int *)d = c;
        *(unsigned int *)(d + 4) = c;
        d += 2 * 4;
        s += 4;
        sdx--;
      }
      s -= src_dx * 4;
      d -= src_dx * 2 * 4;
      memcpy(d + dest_pitch, d, src_dx * 2 * 4);
      s += src_pitch;
      d += dest_pitch * 2;
    }
    return 0;
  }
  return -1;
}
```