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

```asm
<downsample_component>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0xb8,%rsp
  mov    %rdi,-0xe0(%rbp)
  mov    %esi,-0x44(%rbp)
  mov    %edx,%r14d
  mov    %ecx,-0x6c(%rbp)
  mov    %r8d,-0x70(%rbp)
  mov    %r9d,-0x48(%rbp)
  mov    0x18(%rbp),%rax
  mov    %rax,-0x68(%rbp)
  mov    0x20(%rbp),%rbx
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  lea    (%r9,%r9,1),%ecx
  lea    -0x1(%rcx),%eax
  mov    %eax,-0x74(%rbp)
  cltq
  shl    $0x2,%rax
  lea    0xf(%rax),%rdx
  mov    %rdx,%rdi
  and    $0xfffffffffffffff0,%rdi
  and    $0xfffffffffffff000,%rdx
  mov    %rsp,%rsi
  sub    %rdx,%rsi
L39:
  cmp    %rsi,%rsp
  je     L47
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L39
L47:
  mov    %rdi,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  je     L213
  orq    $0x0,-0x8(%rsp,%rdx,1)
L213:
  mov    %rsp,-0xa8(%rbp)
  add    $0xf,%rax
  mov    %rax,%rsi
  and    $0xfffffffffffffff0,%rsi
  and    $0xfffffffffffff000,%rax
  mov    %rsp,%rdx
  sub    %rax,%rdx
L347:
  cmp    %rdx,%rsp
  je     L332
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L347
L332:
  mov    %rsi,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L64
  orq    $0x0,-0x8(%rsp,%rax,1)
L64:
  mov    %rsp,-0xb0(%rbp)
  movslq -0x44(%rbp),%r15
  lea    0xf(%r15),%rax
  mov    %rax,%rdx
  and    $0xfffffffffffffff0,%rdx
  and    $0xfffffffffffff000,%rax
  mov    %rsp,%rsi
  sub    %rax,%rsi
L230:
  cmp    %rsi,%rsp
  je     L61
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L230
L61:
  mov    %rdx,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L149
  orq    $0x0,-0x8(%rsp,%rax,1)
L149:
  mov    %rsp,-0x58(%rbp)
  mov    -0x48(%rbp),%eax
  sub    $0x1,%eax
  mov    %eax,-0xd8(%rbp)
  mov    -0x44(%rbp),%eax
  lea    -0x2(%rcx,%rax,1),%eax
  cltq
  add    $0xf,%rax
  mov    %rax,%rdx
  and    $0xfffffffffffffff0,%rdx
  and    $0xfffffffffffff000,%rax
  mov    %rsp,%rcx
  sub    %rax,%rcx
L351:
  cmp    %rcx,%rsp
  je     L363
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L351
L363:
  mov    %rdx,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L247
  orq    $0x0,-0x8(%rsp,%rax,1)
L247:
  mov    %rsp,-0x80(%rbp)
  mov    0x10(%rbp),%eax
  lea    (%rax,%rax,1),%ecx
  lea    -0x1(%rcx),%eax
  mov    %eax,-0x78(%rbp)
  cltq
  shl    $0x2,%rax
  lea    0xf(%rax),%rsi
  mov    %rsi,%rdx
  and    $0xfffffffffffffff0,%rdx
  and    $0xfffffffffffff000,%rsi
  mov    %rsp,%rdi
  sub    %rsi,%rdi
L137:
  cmp    %rdi,%rsp
  je     L331
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L137
L331:
  mov    %rdx,%rsi
  and    $0xfff,%esi
  sub    %rsi,%rsp
  test   %rsi,%rsi
  je     L317
  orq    $0x0,-0x8(%rsp,%rsi,1)
L317:
  mov    %rsp,-0xb8(%rbp)
  add    $0xf,%rax
  mov    %rax,%rdx
  and    $0xfffffffffffffff0,%rdx
  and    $0xfffffffffffff000,%rax
  mov    %rsp,%rsi
  sub    %rax,%rsi
L56:
  cmp    %rsi,%rsp
  je     L40
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L56
L40:
  mov    %rdx,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L252
  orq    $0x0,-0x8(%rsp,%rax,1)
L252:
  mov    %rsp,-0xc0(%rbp)
  movslq %r14d,%rax
  mov    %rax,-0x98(%rbp)
  lea    0xf(%rax),%rdx
  mov    %rdx,%rax
  and    $0xfffffffffffffff0,%rax
  and    $0xfffffffffffff000,%rdx
  mov    %rsp,%rsi
  sub    %rdx,%rsi
L299:
  cmp    %rsi,%rsp
  je     L205
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L299
L205:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  je     L323
  orq    $0x0,-0x8(%rsp,%rdx,1)
L323:
  mov    %rsp,%r12
  mov    0x10(%rbp),%eax
  sub    $0x1,%eax
  mov    %eax,-0x50(%rbp)
  lea    -0x2(%rcx,%r14,1),%eax
  cltq
  add    $0xf,%rax
  mov    %rax,%rdx
  and    $0xfffffffffffffff0,%rdx
  and    $0xfffffffffffff000,%rax
  mov    %rsp,%rcx
  sub    %rax,%rcx
L214:
  cmp    %rcx,%rsp
  je     L306
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L214
L306:
  mov    %rdx,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L63
  orq    $0x0,-0x8(%rsp,%rax,1)
L63:
  mov    %rsp,-0x60(%rbp)
  mov    -0x68(%rbp),%rax
  mov    -0x44(%rbp),%edi
  mov    %edi,(%rax)
  mov    %r14d,(%rbx)
  mov    -0x48(%rbp),%edx
  mov    -0xb0(%rbp),%rsi
  mov    -0xa8(%rbp),%rdi
  call   <build_downsample_pixelprop_table@plt>
  mov    0x10(%rbp),%edx
  mov    -0xc0(%rbp),%rsi
  mov    -0xb8(%rbp),%rdi
  call   <build_downsample_pixelprop_table@plt>
  mov    0x10(%rbp),%edx
  mov    -0x70(%rbp),%r13d
  mov    %r13d,%esi
  mov    %r14d,%edi
  call   <return_downscaled_array_len@plt>
  mov    %eax,(%rbx)
  cmpl   $0x1,0x10(%rbp)
  jne    L177
  test   %r13d,%r13d
  je     L135
L177:
  mov    -0x44(%rbp),%edi
  test   %edi,%edi
  jle    L135
  lea    -0x1(%r14),%eax
  imul   %edi,%eax
  cltq
  mov    %rax,-0x88(%rbp)
  mov    -0xe0(%rbp),%rsi
  mov    %rsi,%r13
  lea    -0x1(%rdi),%eax
  lea    0x1(%rsi,%rax,1),%rax
  mov    %rax,-0x90(%rbp)
  movslq 0x10(%rbp),%rdi
  mov    %rdi,-0xc8(%rbp)
  mov    -0x98(%rbp),%rax
  lea    -0x1(%rax,%rdi,1),%rax
  mov    -0x60(%rbp),%rsi
  add    %rsi,%rax
  mov    %rax,-0x98(%rbp)
  lea    -0x1(%rdi),%rax
  mov    %rax,-0xd0(%rbp)
  lea    -0x1(%r14),%edi
  mov    %edi,-0xd4(%rbp)
  add    %rax,%rsi
  mov    %rsi,-0xa0(%rbp)
L305:
  movzbl 0x0(%r13),%esi
  mov    -0x50(%rbp),%edx
  mov    -0x60(%rbp),%rdi
  call   <memset@plt>
  mov    -0x88(%rbp),%rax
  movzbl 0x0(%r13,%rax,1),%esi
  mov    -0x50(%rbp),%edx
  mov    -0x98(%rbp),%rdi
  call   <memset@plt>
  test   %r14d,%r14d
  jle    L70
  mov    -0x60(%rbp),%rdi
  mov    %rdi,%rax
  add    -0xd0(%rbp),%rax
  mov    -0xd4(%rbp),%esi
  add    -0xc8(%rbp),%rsi
  add    %rdi,%rsi
  mov    %r13,%rdx
L217:
  movzbl (%rdx),%ecx
  mov    %cl,(%rax)
  add    %r15,%rdx
  add    $0x1,%rax
  cmp    %rsi,%rax
  jne    L217
L70:
  push   -0xc0(%rbp)
  push   -0xb8(%rbp)
  mov    -0x78(%rbp),%r9d
  mov    0x10(%rbp),%r8d
  mov    -0x70(%rbp),%ecx
  mov    %r14d,%edx
  mov    %r12,%rsi
  mov    -0xa0(%rbp),%rdi
  call   <downsample_component_line@plt>
  add    $0x10,%rsp
  cmpl   $0x0,(%rbx)
  jle    L73
  mov    %r13,%rdx
  mov    $0x0,%eax
L183:
  movzbl (%r12,%rax,1),%ecx
  mov    %cl,(%rdx)
  add    $0x1,%rax
  add    %r15,%rdx
  cmp    %eax,(%rbx)
  jg     L183
L73:
  add    $0x1,%r13
  cmp    -0x90(%rbp),%r13
  jne    L305
L135:
  mov    -0x48(%rbp),%r14d
  mov    %r14d,%edx
  mov    -0x6c(%rbp),%r13d
  mov    %r13d,%esi
  mov    -0x44(%rbp),%edi
  call   <return_downscaled_array_len@plt>
  mov    -0x68(%rbp),%rdi
  mov    %eax,(%rdi)
  cmp    $0x1,%r14d
  jne    L242
  test   %r13d,%r13d
  jne    L242
L270:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L91
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L242:
  cmpl   $0x0,(%rbx)
  jle    L270
  mov    -0xe0(%rbp),%r12
  mov    $0x0,%r13d
  movslq -0x48(%rbp),%rax
  lea    -0x1(%r15,%rax,1),%rdx
  mov    -0x80(%rbp),%rdi
  add    %rdi,%rdx
  mov    %rdx,-0x50(%rbp)
  lea    -0x1(%rdi,%rax,1),%r14
  mov    %rbx,-0x60(%rbp)
  mov    -0xd8(%rbp),%ebx
L92:
  movzbl (%r12),%esi
  mov    %ebx,%edx
  mov    -0x80(%rbp),%rdi
  call   <memset@plt>
  movzbl -0x1(%r12,%r15,1),%esi
  mov    %ebx,%edx
  mov    -0x50(%rbp),%rdi
  call   <memset@plt>
  mov    -0x44(%rbp),%edx
  mov    %r12,%rsi
  mov    %r14,%rdi
  call   <memcpy@plt>
  push   -0xb0(%rbp)
  push   -0xa8(%rbp)
  mov    -0x74(%rbp),%r9d
  mov    -0x48(%rbp),%r8d
  mov    -0x6c(%rbp),%ecx
  mov    -0x44(%rbp),%edx
  mov    -0x58(%rbp),%rsi
  mov    %r14,%rdi
  call   <downsample_component_line@plt>
  mov    -0x68(%rbp),%rax
  mov    (%rax),%edx
  mov    -0x58(%rbp),%rsi
  mov    %r12,%rdi
  call   <memcpy@plt>
  add    $0x1,%r13d
  add    %r15,%r12
  add    $0x10,%rsp
  mov    -0x60(%rbp),%rax
  cmp    %r13d,(%rax)
  jg     L92
  jmp    L270
L91:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void downsample_component(unsigned char *carray, int width, int height, const int xpos, const int ypos, const int xstep, const int ystep, int *out_width, int *out_height) {
  int x_pixel_len = (xstep * 2) - 1;
  int x_pixel_coord[x_pixel_len];
  float x_pixel_percent[x_pixel_len];
  unsigned char x_out_buff[width];
  unsigned char x_in_buff[width + (xstep - 1) * 2];
  int y_pixel_len = (ystep * 2) - 1;
  int y_pixel_coord[y_pixel_len];
  float y_pixel_percent[y_pixel_len];
  unsigned char y_out_buff[height];
  unsigned char y_in_buff[height + (ystep - 1) * 2];
  int linecount;
  unsigned char *datastart;
  int i;
  *out_width = width;
  *out_height = height;
  build_downsample_pixelprop_table(x_pixel_coord, x_pixel_percent, xstep);
  build_downsample_pixelprop_table(y_pixel_coord, y_pixel_percent, ystep);
  *out_height = return_downscaled_array_len(height, ypos, ystep);
  if ((ystep != 1) || (ypos != 0)) {
    for (linecount = 0; linecount < width; linecount++) {
      datastart = carray + linecount;
      memset(y_in_buff, *datastart, ystep - 1);
      memset((y_in_buff + ystep - 1 + height), *(datastart + ((height - 1) * width)), ystep - 1);
      for (i = 0; i < height; i++)
        *(y_in_buff + (ystep - 1) + i) = *(datastart + (width * i));
      downsample_component_line(y_in_buff + (ystep - 1), y_out_buff, height, ypos, ystep, y_pixel_len, y_pixel_coord, y_pixel_percent);
      for (i = 0; i < *out_height; i++)
        *(datastart + (width * i)) = *(y_out_buff + i);
    }
  }
  *out_width = return_downscaled_array_len(width, xpos, xstep);
  if ((xstep != 1) || (xpos != 0)) {
    for (linecount = 0; linecount < *out_height; linecount++) {
      datastart = carray + (linecount * width);
      memset(x_in_buff, *datastart, xstep - 1);
      memset((x_in_buff + xstep - 1 + width), *(datastart + (width - 1)), xstep - 1);
      memcpy(x_in_buff + (xstep - 1), datastart, width);
      downsample_component_line(x_in_buff + (xstep - 1), x_out_buff, width, xpos, xstep, x_pixel_len, x_pixel_coord, x_pixel_percent);
      memcpy(datastart, x_out_buff, *out_width);
    }
  }
}
```