user: What would the C source look like for the assembly code provided here?

```asm
<__imlib_CalcApoints>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %edi,%r13d
  mov    %esi,%ebp
  mov    %edx,%ebx
  mov    %ecx,%r14d
  mov    %r8d,%r12d
  movl   $0x0,0xc(%rsp)
  test   %esi,%esi
  js     L24
L246:
  movslq %ebp,%r15
  lea    0x0(,%rbp,4),%edi
  call   <malloc@plt>
  mov    %rax,%rcx
  lea    (%rbx,%r14,1),%eax
  cmp    %ebp,%eax
  jle    L60
  cmp    %ebx,%ebp
  jl     L151
  mov    %ebp,%r14d
  sub    %ebx,%r14d
L60:
  test   %r12d,%r12d
  jne    L33
  mov    %r12d,%r10d
  test   %ebx,%ebx
  jle    L208
  mov    %rcx,%rax
  lea    -0x1(%rbx),%edx
  lea    0x4(%rcx,%rdx,4),%rdx
L2:
  movl   $0x40004000,(%rax)
  add    $0x4,%rax
  cmp    %rdx,%rax
  jne    L2
  mov    %ebx,%r10d
L208:
  lea    (%rbx,%r14,1),%eax
  cmp    %ebp,%eax
  jge    L89
  sub    %ebx,%r13d
  sub    %r14d,%r13d
  mov    %ebp,%r11d
  sub    %ebx,%r11d
  sub    %r14d,%r11d
  mov    %r13d,%eax
  shl    $0x10,%eax
  cltd
  idiv   %r11d
  mov    %eax,%r9d
  mov    %r11d,%eax
  shl    $0xe,%eax
  cltd
  idiv   %r13d
  lea    0x1(%rax),%r8d
  test   %r11d,%r11d
  jle    L89
  mov    %r8d,%r13d
  shl    $0x10,%r13d
  movslq %r10d,%rdx
  lea    (%rcx,%rdx,4),%rsi
  lea    -0x1(%r11),%eax
  add    %rdx,%rax
  lea    0x4(%rcx,%rax,4),%rbx
  mov    $0x100,%eax
  mov    %rbx,%rdi
  mov    %r12d,%ebx
  mov    %rcx,%r12
L226:
  movzbl %bh,%ecx
  mov    %eax,%edx
  sub    %ecx,%edx
  imul   %r8d,%edx
  sar    $0x8,%edx
  or     %r13d,%edx
  mov    %edx,(%rsi)
  add    %r9d,%ebx
  add    $0x4,%rsi
  cmp    %rdi,%rsi
  jne    L226
  mov    %r12,%rcx
  add    %r11d,%r10d
L89:
  test   %r14d,%r14d
  jle    L99
  movslq %r10d,%r10
  lea    (%rcx,%r10,4),%rax
  lea    -0x1(%r14),%edx
  add    %r10,%rdx
  lea    0x4(%rcx,%rdx,4),%rdx
L142:
  movl   $0x40004000,(%rax)
  add    $0x4,%rax
  cmp    %rdx,%rax
  jne    L142
  jmp    L99
L24:
  neg    %ebp
  movl   $0x1,0xc(%rsp)
  jmp    L246
L151:
  mov    %ebp,%ebx
  mov    $0x0,%r14d
  jmp    L60
L33:
  test   %ebx,%ebx
  jle    L36
  mov    %rcx,%rax
  lea    -0x1(%rbx),%edx
  lea    0x4(%rcx,%rdx,4),%rdx
L201:
  movl   $0x0,(%rax)
  add    $0x4,%rax
  cmp    %rdx,%rax
  jne    L201
  mov    %ebx,%edi
L170:
  lea    (%rbx,%r14,1),%eax
  cmp    %ebp,%eax
  jge    L11
  mov    %ebp,%r8d
  sub    %ebx,%r8d
  sub    %r14d,%r8d
  mov    %r13d,%eax
  sub    %ebx,%eax
  sub    %r14d,%eax
  shl    $0x10,%eax
  cltd
  idiv   %r8d
  mov    %eax,%r9d
  test   %r8d,%r8d
  jle    L11
  movslq %edi,%rsi
  lea    (%rcx,%rsi,4),%rdx
  lea    -0x1(%r8),%eax
  add    %rsi,%rax
  lea    0x4(%rcx,%rax,4),%r10
  mov    $0x0,%eax
  sub    $0x1,%r13d
L206:
  movzbl %ah,%esi
  mov    %eax,%r11d
  sar    $0x10,%r11d
  add    %ebx,%r11d
  cmp    %r13d,%r11d
  mov    $0x0,%r11d
  cmovge %r11d,%esi
  mov    %esi,(%rdx)
  add    %r9d,%eax
  add    $0x4,%rdx
  cmp    %r10,%rdx
  jne    L206
  add    %r8d,%edi
L11:
  test   %r14d,%r14d
  jle    L99
  movslq %edi,%rdi
  lea    (%rcx,%rdi,4),%rax
  lea    -0x1(%r14),%edx
  add    %rdi,%rdx
  lea    0x4(%rcx,%rdx,4),%rdx
L233:
  movl   $0x0,(%rax)
  add    $0x4,%rax
  cmp    %rdx,%rax
  jne    L233
L99:
  cmpl   $0x0,0xc(%rsp)
  je     L70
  mov    %ebp,%eax
  shr    $0x1f,%eax
  add    %ebp,%eax
  sar    %eax
  sub    $0x1,%eax
  js     L70
  cltq
  sub    %rax,%r15
  lea    -0x4(%rcx,%r15,4),%rdx
L81:
  mov    (%rcx,%rax,4),%esi
  mov    (%rdx),%edi
  mov    %edi,(%rcx,%rax,4)
  mov    %esi,(%rdx)
  sub    $0x1,%rax
  add    $0x4,%rdx
  test   %eax,%eax
  jns    L81
L70:
  mov    %rcx,%rax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L36:
  mov    $0x0,%edi
  jmp    L170
```

assistant: ```c
int *__imlib_CalcApoints(int s, int d, int b1, int b2, int up) {
  int *p, i, j = 0, rv = 0;
  if (d < 0) {
    rv = 1;
    d = -d;
  }
  p = malloc(d * sizeof(int));
  if (d < (b1 + b2)) {
    if (d < b1) {
      b1 = d;
      b2 = 0;
    } else
      b2 = d - b1;
  }
  if (up) {
    int val, inc;
    for (i = 0; i < b1; i++)
      p[j++] = 0;
    if (d > (b1 + b2)) {
      int ss, dd;
      ss = s - b1 - b2;
      dd = d - b1 - b2;
      val = 0;
      inc = (ss << 16) / dd;
      for (i = 0; i < dd; i++) {
        p[j++] = (val >> 8) - ((val >> 8) & 0xffffff00);
        if (((val >> 16) + b1) >= (s - 1))
          p[j - 1] = 0;
        val += inc;
      }
    }
    for (i = 0; i < b2; i++)
      p[j++] = 0;
  } else {
    int val, inc;
    for (i = 0; i < b1; i++)
      p[j++] = (1 << (16 + 14)) + (1 << 14);
    if (d > (b1 + b2)) {
      int ss, dd, ap, Cp;
      ss = s - b1 - b2;
      dd = d - b1 - b2;
      val = 0;
      inc = (ss << 16) / dd;
      Cp = ((dd << 14) / ss) + 1;
      for (i = 0; i < dd; i++) {
        ap = ((0x100 - ((val >> 8) & 0xff)) * Cp) >> 8;
        p[j] = ap | (Cp << 16);
        j++;
        val += inc;
      }
    }
    for (i = 0; i < b2; i++)
      p[j++] = (1 << (16 + 14)) + (1 << 14);
  }
  if (rv) {
    for (i = d / 2; --i >= 0;) {
      int tmp = p[i];
      p[i] = p[d - i - 1];
      p[d - i - 1] = tmp;
    }
  }
  return p;
}
```