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

```asm
<generate_scaling>:
  endbr64
  push   %r15
  lea    -0x8(%rdi),%r10d
  mov    %edx,%r11d
  mov    %rsi,%r9
  push   %r14
  xor    %eax,%eax
  push   %r13
  mov    %rcx,%r13
  mov    %edi,%ecx
  push   %r12
  mov    $0x1,%r12d
  push   %rbp
  shl    %cl,%r12d
  mov    %r10d,%ecx
  push   %rbx
  mov    (%rsi),%edx
  shl    %cl,%edx
  mov    %r10d,%ecx
  test   %edx,%edx
  jle    L68
  cs nopw 0x0(%rax,%rax,1)
L140:
  mov    0x4(%r9),%edx
  mov    %edx,0x0(%r13,%rax,4)
  mov    (%r9),%edx
  add    $0x1,%rax
  shl    %cl,%edx
  cmp    %eax,%edx
  jg     L140
  mov    %ecx,%r10d
L68:
  lea    -0x1(%r11),%ebp
  test   %ebp,%ebp
  jle    L27
  lea    -0x2(%r11),%eax
  mov    %r9,%r8
  mov    %r10d,%ecx
  lea    0x8(%r9,%rax,8),%rbx
L125:
  mov    0x8(%r8),%r14d
  mov    (%r8),%esi
  mov    0x4(%r8),%edi
  mov    %r14d,%r10d
  sub    %esi,%r10d
  mov    %r10d,%eax
  sar    %eax
  add    $0x10000,%eax
  cltd
  idiv   %r10d
  mov    0xc(%r8),%edx
  sub    %edi,%edx
  imul   %edx,%eax
  mov    %esi,%edx
  mov    $0x8000,%esi
  test   %r10d,%r10d
  jle    L90
  nopl   0x0(%rax)
L110:
  mov    %edx,%r10d
  mov    %esi,%r15d
  add    $0x1,%edx
  add    %eax,%esi
  shl    %cl,%r10d
  sar    $0x10,%r15d
  movslq %r10d,%r10
  add    %edi,%r15d
  mov    %r15d,0x0(%r13,%r10,4)
  cmp    %edx,%r14d
  jne    L110
L90:
  add    $0x8,%r8
  cmp    %rbx,%r8
  jne    L125
  mov    %ecx,%r10d
L27:
  movslq %r11d,%rax
  mov    %r10d,%ecx
  lea    -0x8(%r9,%rax,8),%rsi
  mov    (%rsi),%eax
  shl    %cl,%eax
  mov    %eax,%ecx
  cmp    %eax,%r12d
  jle    L41
  lea    -0x1(%r12),%edx
  movslq %eax,%rdi
  sub    %ecx,%edx
  lea    0x0(%r13,%rdi,4),%rax
  add    %rdi,%rdx
  lea    0x4(%r13,%rdx,4),%rcx
  nopl   0x0(%rax,%rax,1)
L59:
  mov    0x4(%rsi),%edx
  add    $0x4,%rax
  mov    %edx,-0x4(%rax)
  cmp    %rax,%rcx
  jne    L59
L41:
  mov    $0x1,%ebx
  mov    %r10d,%ecx
  shl    %cl,%ebx
  mov    %ebx,%r15d
  sar    %r15d
  test   %ebp,%ebp
  jle    L1
  lea    -0x2(%r11),%eax
  mov    %r13,-0x8(%rsp)
  movslq %ebx,%r14
  mov    %r10d,%ecx
  lea    0x8(%r9,%rax,8),%rax
  lea    0x0(,%r14,4),%rbp
  mov    %r9,%r10
  mov    %rax,-0x20(%rsp)
  lea    -0x2(%rbx),%eax
  mov    %rax,-0x18(%rsp)
  lea    0x4(%r13),%rax
  mov    %rax,-0x10(%rsp)
  nopl   0x0(%rax)
L105:
  mov    (%r10),%eax
  mov    0x8(%r10),%r13d
  shl    %cl,%eax
  shl    %cl,%r13d
  sub    %eax,%r13d
  test   %r13d,%r13d
  jle    L39
  mov    -0x8(%rsp),%rdi
  cltq
  xor    %r12d,%r12d
  lea    (%rdi,%rax,4),%r8
  mov    -0x10(%rsp),%rdi
  add    -0x18(%rsp),%rax
  lea    (%rdi,%rax,4),%r11
  nopl   0x0(%rax,%rax,1)
L34:
  mov    (%r8),%eax
  mov    (%r8,%r14,4),%edi
  sub    %eax,%edi
  cmp    $0x1,%ebx
  jle    L10
  lea    (%r15,%rdi,1),%esi
  mov    %r8,%rdx
  mov    %eax,%r9d
  jmp    L147
  nopw   0x0(%rax,%rax,1)
L13:
  mov    (%r8),%r9d
L147:
  mov    %esi,%eax
  add    $0x4,%rdx
  add    %edi,%esi
  sar    %cl,%eax
  add    %r9d,%eax
  mov    %eax,(%rdx)
  cmp    %r11,%rdx
  jne    L13
L10:
  add    %ebx,%r12d
  add    %rbp,%r8
  add    %rbp,%r11
  cmp    %r12d,%r13d
  jg     L34
L39:
  add    $0x8,%r10
  cmp    %r10,-0x20(%rsp)
  jne    L105
L1:
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

assistant: ```c
void generate_scaling(const int bitdepth, const uint8_t points[][2], const int num, uint8_t scaling[256]) {
  const int shift_x = bitdepth - 8;
  const int scaling_size = 1 << bitdepth;
  for (int i = 0; i < points[0][0] << shift_x; i++)
    scaling[i] = points[0][1];
  for (int i = 0; i < num - 1; i++) {
    const int bx = points[i][0];
    const int by = points[i][1];
    const int ex = points[i + 1][0];
    const int ey = points[i + 1][1];
    const int dx = ex - bx;
    const int dy = ey - by;
    const int delta = dy * ((0x10000 + (dx >> 1)) / dx);
    for (int x = 0; x < dx; x++) {
      const int v = by + ((x * delta + 0x8000) >> 16);
      scaling[(bx + x) << shift_x] = v;
    }
  }
  for (int i = points[num - 1][0] << shift_x; i < scaling_size; i++)
    scaling[i] = points[num - 1][1];
  const int pad = 1 << shift_x, rnd = pad >> 1;
  for (int i = 0; i < num - 1; i++) {
    const int bx = points[i][0] << shift_x;
    const int ex = points[i + 1][0] << shift_x;
    const int dx = ex - bx;
    for (int x = 0; x < dx; x += pad) {
      const int range = scaling[bx + x + pad] - scaling[bx + x];
      for (int n = 1; n < pad; n++) {
        scaling[bx + x + n] = scaling[bx + x] + ((range * n + rnd) >> shift_x);
      }
    }
  }
}
```