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

```asm
<jp2_downsample_image_components>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x70,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %esi,-0x3c(%rbp)
  mov    %edx,-0x40(%rbp)
  mov    %ecx,-0x44(%rbp)
  mov    %r8,-0x50(%rbp)
  mov    %r9,-0x58(%rbp)
  mov    0x10(%rbp),%rax
  mov    %rax,-0x60(%rbp)
  mov    0x18(%rbp),%rax
  mov    %rax,-0x68(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x3c(%rbp),%eax
  imul   -0x40(%rbp),%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  movl   $0x0,-0x20(%rbp)
  jmp    L93
L15:
  movl   $0x0,-0x1c(%rbp)
  jmp    L36
L58:
  mov    -0x20(%rbp),%eax
  lea    0x0(,%rax,4),%edx
  mov    -0x1c(%rbp),%eax
  add    %edx,%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  mov    -0x20(%rbp),%edx
  lea    0x0(,%rdx,4),%ecx
  mov    -0x1c(%rbp),%edx
  add    %ecx,%edx
  movslq %edx,%rdx
  lea    0x0(,%rdx,4),%rcx
  mov    -0x58(%rbp),%rdx
  add    %rcx,%rdx
  mov    (%rax),%eax
  mov    %eax,(%rdx)
  addl   $0x1,-0x1c(%rbp)
L36:
  cmpl   $0x3,-0x1c(%rbp)
  jle    L58
  mov    -0x20(%rbp),%eax
  shl    $0x2,%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x10(%rbp),%rax
  mov    (%rax),%eax
  cmp    %eax,-0x3c(%rbp)
  jle    L61
  mov    -0x10(%rbp),%rax
  mov    (%rax),%eax
  test   %eax,%eax
  jns    L48
L61:
  mov    -0x10(%rbp),%rax
  movl   $0x0,(%rax)
L48:
  mov    -0x10(%rbp),%rax
  add    $0x4,%rax
  mov    (%rax),%eax
  cmp    %eax,-0x40(%rbp)
  jle    L84
  mov    -0x10(%rbp),%rax
  add    $0x4,%rax
  mov    (%rax),%eax
  test   %eax,%eax
  jns    L16
L84:
  mov    -0x10(%rbp),%rax
  add    $0x4,%rax
  movl   $0x0,(%rax)
L16:
  mov    -0x10(%rbp),%rax
  add    $0x8,%rax
  mov    (%rax),%eax
  test   %eax,%eax
  jg     L11
  mov    -0x10(%rbp),%rax
  add    $0x8,%rax
  movl   $0x1,(%rax)
L11:
  mov    -0x10(%rbp),%rax
  add    $0xc,%rax
  mov    (%rax),%eax
  test   %eax,%eax
  jg     L103
  mov    -0x10(%rbp),%rax
  add    $0xc,%rax
  movl   $0x1,(%rax)
L103:
  mov    -0x3c(%rbp),%eax
  imul   -0x40(%rbp),%eax
  mov    %eax,%edi
  mov    -0x44(%rbp),%ecx
  mov    -0x20(%rbp),%edx
  mov    -0x38(%rbp),%rsi
  mov    -0x18(%rbp),%rax
  mov    %edi,%r8d
  mov    %rax,%rdi
  call   <collect_component@plt>
  mov    -0x10(%rbp),%rax
  add    $0xc,%rax
  mov    (%rax),%edi
  mov    -0x10(%rbp),%rax
  add    $0x8,%rax
  mov    (%rax),%r9d
  mov    -0x10(%rbp),%rax
  add    $0x4,%rax
  mov    (%rax),%r10d
  mov    -0x10(%rbp),%rax
  mov    (%rax),%ecx
  mov    -0x40(%rbp),%edx
  mov    -0x3c(%rbp),%esi
  mov    -0x18(%rbp),%rax
  sub    $0x8,%rsp
  lea    -0x24(%rbp),%r8
  push   %r8
  lea    -0x28(%rbp),%r8
  push   %r8
  push   %rdi
  mov    %r10d,%r8d
  mov    %rax,%rdi
  call   <downsample_component@plt>
  add    $0x20,%rsp
  mov    -0x24(%rbp),%ecx
  mov    -0x28(%rbp),%edx
  mov    -0x3c(%rbp),%esi
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <pack_component_array@plt>
  mov    -0x28(%rbp),%edx
  mov    -0x24(%rbp),%eax
  mov    %edx,%edi
  imul   %eax,%edi
  mov    -0x44(%rbp),%ecx
  mov    -0x20(%rbp),%edx
  mov    -0x18(%rbp),%rsi
  mov    -0x38(%rbp),%rax
  mov    %edi,%r8d
  mov    %rax,%rdi
  call   <rewrite_component@plt>
  mov    -0x20(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x60(%rbp),%rax
  add    %rax,%rdx
  mov    -0x28(%rbp),%eax
  mov    %eax,(%rdx)
  mov    -0x20(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x68(%rbp),%rax
  add    %rax,%rdx
  mov    -0x24(%rbp),%eax
  mov    %eax,(%rdx)
  addl   $0x1,-0x20(%rbp)
L93:
  mov    -0x20(%rbp),%eax
  cmp    -0x44(%rbp),%eax
  jl     L15
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  nop
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L59
  call   <__stack_chk_fail@plt>
L59:
  leave
  ret
```

assistant: ```c
void jp2_downsample_image_components(unsigned char *bitmap, const int width, const int height, const int bpp, const int *csampling, int *csampling_effective, int *cwidth, int *cheight) {
  unsigned char *carray;
  int compstep;
  int out_width, out_height;
  int *csampling_base;
  int i;
  carray = malloc(width * height);
  for (compstep = 0; compstep < bpp; compstep++) {
    for (i = 0; i < 4; i++)
      csampling_effective[(compstep * 4) + i] = csampling[(compstep * 4) + i];
    csampling_base = csampling_effective + (compstep * 4);
    if ((csampling_base[0] >= width) || (csampling_base[0] < 0))
      csampling_base[0] = 0;
    if ((csampling_base[1] >= height) || (csampling_base[1] < 0))
      csampling_base[1] = 0;
    if (csampling_base[2] < 1)
      csampling_base[2] = 1;
    if (csampling_base[3] < 1)
      csampling_base[3] = 1;
    collect_component(carray, bitmap, compstep, bpp, width * height);
    downsample_component(carray, width, height, csampling_base[0], csampling_base[1], csampling_base[2], csampling_base[3], &out_width, &out_height);
    pack_component_array(carray, width, out_width, out_height);
    rewrite_component(bitmap, carray, compstep, bpp, out_width * out_height);
    cwidth[compstep] = out_width;
    cheight[compstep] = out_height;
  }
  free(carray);
}
```