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

```asm
<grd_bipolar_prewinder>:
  endbr64
  push   %r15
  cvtss2sd %xmm0,%xmm0
  pxor   %xmm7,%xmm7
  xor    %r15d,%r15d
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x178,%rsp
  mov    %rdi,0xd0(%rsp)
  mov    %rsi,0xd8(%rsp)
  mov    %rdx,0xe0(%rsp)
  mov    %rcx,0xc8(%rsp)
  mov    %r8,0xe8(%rsp)
  movss  %xmm1,0x4(%rsp)
  pxor   %xmm1,%xmm1
  movss  %xmm2,0x14(%rsp)
  cvtss2sd %xmm2,%xmm1
  movsd  D89(%rip),%xmm2
  movss  %xmm6,0x3c(%rsp)
  pxor   %xmm6,%xmm6
  movss  %xmm3,(%rsp)
  mulsd  %xmm2,%xmm1
  movss  %xmm4,0x2c(%rsp)
  mulsd  %xmm2,%xmm0
  movss  %xmm5,0x38(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x168(%rsp)
  xor    %eax,%eax
  lea    0x104(%rsp),%rax
  movl   $0x32,0xc4(%rsp)
  mov    %rax,0x70(%rsp)
  lea    0xf8(%rsp),%rax
  mov    %rax,0x58(%rsp)
  lea    0x120(%rsp),%rax
  cvtsd2ss %xmm1,%xmm7
  mov    %rax,0x90(%rsp)
  lea    0x118(%rsp),%rax
  cvtsd2ss %xmm0,%xmm6
  mov    %rax,0x88(%rsp)
  lea    0x110(%rsp),%rax
  mov    %rax,0x80(%rsp)
  lea    0x108(%rsp),%rax
  mov    %rax,0x78(%rsp)
  lea    0xfc(%rsp),%rax
  mov    %rax,0x60(%rsp)
  lea    0x140(%rsp),%rax
  mov    %rax,0xb0(%rsp)
  lea    0x138(%rsp),%rax
  movss  %xmm7,0x24(%rsp)
  movss  %xmm6,0x28(%rsp)
  mov    %rax,0xa8(%rsp)
  lea    0x130(%rsp),%rax
  mov    %rax,0xa0(%rsp)
  lea    0x128(%rsp),%rax
  mov    %rax,0x98(%rsp)
  lea    0x100(%rsp),%rax
  mov    %rax,0x68(%rsp)
  lea    0x160(%rsp),%rax
  mov    %rax,0x50(%rsp)
  lea    0x158(%rsp),%rax
  mov    %rax,0x48(%rsp)
  lea    0x150(%rsp),%rax
  mov    %rax,0x40(%rsp)
  lea    0x148(%rsp),%rax
  mov    %rax,0xb8(%rsp)
  nopl   0x0(%rax)
L52:
  mov    0x70(%rsp),%r14
  mov    0x58(%rsp),%r8
  mov    0x90(%rsp),%rcx
  mov    0x80(%rsp),%rsi
  mov    0x78(%rsp),%rdi
  movss  (%rsp),%xmm3
  mov    %r14,%r9
  movss  0x2c(%rsp),%xmm2
  movss  0x24(%rsp),%xmm1
  mov    0x88(%rsp),%rdx
  movss  0x28(%rsp),%xmm0
  call   <grd_trapezoid@plt>
  movslq 0xf8(%rsp),%rdx
  mov    0x120(%rsp),%rax
  mov    -0x4(%rax,%rdx,4),%ebx
  mov    D40(%rip),%rax
  movq   %rax,%xmm0
  call   <sqrt@plt>
  pxor   %xmm1,%xmm1
  movd   %ebx,%xmm0
  movss  0x3c(%rsp),%xmm2
  add    $0x1,%eax
  mov    0x60(%rsp),%r8
  mov    0xb0(%rsp),%rcx
  cvtsi2ss %eax,%xmm1
  mov    0xa8(%rsp),%rdx
  movss  (%rsp),%xmm3
  mov    0xa0(%rsp),%rsi
  mov    0x98(%rsp),%rdi
  divss  %xmm1,%xmm0
  movaps %xmm2,%xmm1
  divss  %xmm0,%xmm1
  movss  0x4(%rsp),%xmm0
  movss  %xmm1,0x8(%rsp)
  call   <grd_rampup@plt>
  movss  D72(%rip),%xmm4
  mulss  (%rsp),%xmm4
  mov    0xfc(%rsp),%esi
  mov    0x130(%rsp),%rdi
  movss  %xmm4,0xc(%rsp)
  call   <sumfloats@plt>
  pxor   %xmm0,%xmm0
  movss  0x38(%rsp),%xmm2
  mov    0x68(%rsp),%r8
  cvtsi2ss %eax,%xmm0
  mulss  0xc(%rsp),%xmm0
  mov    %r14,%r9
  mov    0x50(%rsp),%rcx
  movss  (%rsp),%xmm3
  movss  0x8(%rsp),%xmm1
  mov    0x48(%rsp),%rdx
  mov    0x40(%rsp),%rsi
  mov    0xb8(%rsp),%rdi
  subss  %xmm0,%xmm2
  movss  0x4(%rsp),%xmm0
  call   <grd_trapezoid@plt>
  mov    0x100(%rsp),%eax
  add    0xfc(%rsp),%eax
  lea    -0x1(%rax),%ebx
  mov    %eax,0xc0(%rsp)
  lea    0x0(,%rbx,4),%r13d
  movslq %ebx,%rax
  mov    %r13d,%edi
  mov    %rax,0x18(%rsp)
  call   <malloc@plt>
  mov    0x150(%rsp),%rsi
  mov    %rax,%r12
  mov    0x100(%rsp),%eax
  mov    %r12,%rdi
  lea    0x0(,%rax,4),%edx
  call   <memcpy@plt>
  mov    0xfc(%rsp),%eax
  lea    -0x4(,%rax,4),%edx
  mov    0x130(%rsp),%rax
  lea    0x4(%rax),%rsi
  movslq 0x100(%rsp),%rax
  lea    (%r12,%rax,4),%rdi
  call   <memcpy@plt>
  mov    %r13d,%edi
  call   <malloc@plt>
  mov    %r13d,%edi
  mov    %rax,%r14
  call   <malloc@plt>
  movl   $0x0,0x104(%rsp)
  mov    %rax,%rbp
  test   %ebx,%ebx
  jle    L162
  pxor   %xmm2,%xmm2
  pxor   %xmm1,%xmm1
  mov    %r14,%rdx
  xor    %eax,%eax
  cvtsi2ssl 0xf8(%rsp),%xmm2
  subss  D33(%rip),%xmm2
  cvtsi2ss %ebx,%xmm1
  subss  D33(%rip),%xmm1
  nopl   (%rax)
L21:
  pxor   %xmm0,%xmm0
  add    $0x4,%rdx
  cvtsi2ss %eax,%xmm0
  add    $0x1,%eax
  mulss  %xmm2,%xmm0
  divss  %xmm1,%xmm0
  movss  %xmm0,-0x4(%rdx)
  cmp    %ebx,%eax
  jne    L21
  mov    %ebx,0x104(%rsp)
L162:
  test   %r15,%r15
  je     L156
  mov    %r15,%rdi
  call   <free@plt>
L156:
  mov    0xf8(%rsp),%eax
  lea    0x0(,%rax,4),%edi
  call   <malloc@plt>
  mov    0xf8(%rsp),%r10d
  movl   $0x0,0x104(%rsp)
  mov    %rax,%r15
  test   %r10d,%r10d
  jle    L143
  mov    %rax,%rdx
  xor    %eax,%eax
  nopw   0x0(%rax,%rax,1)
L193:
  pxor   %xmm0,%xmm0
  add    $0x4,%rdx
  cvtsi2ss %eax,%xmm0
  add    $0x1,%eax
  movss  %xmm0,-0x4(%rdx)
  cmp    %r10d,%eax
  jne    L193
  mov    %r10d,0x104(%rsp)
L143:
  mov    %ebx,%r9d
  mov    %rbp,%r8
  mov    %r14,%rcx
  mov    %r10d,%edx
  mov    0x110(%rsp),%rsi
  mov    %r15,%rdi
  call   <interpolatefloats@plt>
  mov    0xf8(%rsp),%esi
  mov    %rbp,%rdi
  call   <sumfloats@plt>
  pxor   %xmm0,%xmm0
  pxor   %xmm7,%xmm7
  cvtsi2ss %eax,%xmm0
  mulss  0xc(%rsp),%xmm0
  ucomiss %xmm7,%xmm0
  jp     L164
  jne    L164
L151:
  mov    %r13d,%edi
  call   <malloc@plt>
  mov    %r13d,%edi
  mov    %rax,%r14
  call   <malloc@plt>
  mov    %ebx,%edx
  mov    %r14,%rsi
  mov    %rbp,%rdi
  mov    %rax,%r13
  call   <diffArray@plt>
  mov    %ebx,%edx
  mov    %r13,%rsi
  mov    %r12,%rdi
  call   <diffArray@plt>
  mov    0x18(%rsp),%rax
  mov    %ebx,%ecx
  mov    %r13,%rsi
  movss  D33(%rip),%xmm0
  divss  (%rsp),%xmm0
  mov    %r14,%rdi
  cvttss2si %xmm0,%edx
  shl    $0x2,%rax
  pxor   %xmm0,%xmm0
  movl   $0x0,-0x4(%r14,%rax,1)
  movl   $0x0,-0x4(%r13,%rax,1)
  mov    %rax,0x30(%rsp)
  call   <scalecomplex@plt>
  mov    %ebx,%edx
  mov    %r13,%rsi
  mov    %r14,%rdi
  call   <maxMagnitude@plt>
  mov    %ebx,%edx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  movss  %xmm0,0x8(%rsp)
  call   <maxMagnitude@plt>
  movss  0x8(%rsp),%xmm5
  comiss 0x14(%rsp),%xmm5
  movss  %xmm0,0x10(%rsp)
  ja     L152
L107:
  movss  0x10(%rsp),%xmm3
  comiss 0x4(%rsp),%xmm3
  ja     L74
L155:
  mov    %r14,%rdi
  call   <free@plt>
  mov    %r13,%rdi
  call   <free@plt>
  mov    0x108(%rsp),%rdi
  call   <free@plt>
  mov    0x110(%rsp),%rdi
  call   <free@plt>
  mov    0x118(%rsp),%rdi
  call   <free@plt>
  mov    0x120(%rsp),%rdi
  call   <free@plt>
  mov    0x128(%rsp),%rdi
  call   <free@plt>
  mov    0x130(%rsp),%rdi
  call   <free@plt>
  mov    0x138(%rsp),%rdi
  call   <free@plt>
  mov    0x140(%rsp),%rdi
  call   <free@plt>
  mov    0x148(%rsp),%rdi
  call   <free@plt>
  mov    0x150(%rsp),%rdi
  call   <free@plt>
  mov    0x158(%rsp),%rdi
  call   <free@plt>
  mov    0x160(%rsp),%rdi
  call   <free@plt>
  movss  D96(%rip),%xmm0
  mulss  0x14(%rsp),%xmm0
  comiss 0x8(%rsp),%xmm0
  jb     L16
  movss  D96(%rip),%xmm1
  mulss  0x4(%rsp),%xmm1
  comiss 0x10(%rsp),%xmm1
  jae    L34
L16:
  mov    %rbp,%rdi
  movss  %xmm0,0x20(%rsp)
  call   <free@plt>
  mov    %r12,%rdi
  call   <free@plt>
  subl   $0x1,0xc4(%rsp)
  movss  0x20(%rsp),%xmm0
  jne    L52
L34:
  movss  0x8(%rsp),%xmm7
  comiss %xmm0,%xmm7
  ja     L43
  movss  D96(%rip),%xmm0
  mulss  0x4(%rsp),%xmm0
  movss  0x10(%rsp),%xmm4
  comiss %xmm0,%xmm4
  ja     L43
L106:
  lea    0x0(,%rbx,8),%r13d
  mov    %r13d,%edi
  call   <malloc@plt>
  mov    0xd0(%rsp),%r14
  mov    %r13d,%edi
  mov    %rax,(%r14)
  call   <malloc@plt>
  mov    0xd8(%rsp),%r15
  mov    %r13d,%edi
  mov    %rax,(%r15)
  call   <malloc@plt>
  mov    0xe0(%rsp),%rcx
  mov    0x18(%rsp),%r13d
  mov    %rax,(%rcx)
  shl    $0x2,%r13d
  mov    %r13d,%edi
  call   <malloc@plt>
  mov    0xc8(%rsp),%rcx
  mov    %r13d,%edx
  mov    %rbp,%rsi
  mov    %rax,(%rcx)
  mov    (%r15),%rdi
  call   <memcpy@plt>
  mov    %r15,%rax
  mov    0x30(%rsp),%r15
  mov    %r13d,%edx
  mov    (%rax),%rdi
  mov    %r12,%rsi
  add    %r15,%rdi
  call   <memcpy@plt>
  mov    (%r14),%r13
  mov    %ebx,%edx
  mov    %rbp,%rdi
  add    %r13,%r15
  mov    %r13,%rsi
  call   <cumulativeSum@plt>
  mov    %ebx,%edx
  mov    %r15,%rsi
  mov    %r12,%rdi
  call   <cumulativeSum@plt>
  cvttss2si 0xc(%rsp),%edx
  mov    %ebx,%ecx
  mov    %r15,%rsi
  pxor   %xmm0,%xmm0
  mov    %r13,%rdi
  call   <scalecomplex@plt>
  movl   $0x0,0x104(%rsp)
  test   %ebx,%ebx
  jle    L194
  mov    0xc8(%rsp),%rcx
  mov    0xc0(%rsp),%eax
  mov    (%rcx),%rsi
  lea    -0x2(%rax),%ecx
  xor    %eax,%eax
  nopl   0x0(%rax)
L113:
  pxor   %xmm0,%xmm0
  mov    %rax,%rdx
  cvtsi2ss %eax,%xmm0
  mulss  (%rsp),%xmm0
  movss  %xmm0,(%rsi,%rax,4)
  add    $0x1,%rax
  cmp    %rdx,%rcx
  jne    L113
L194:
  mov    0xe8(%rsp),%rax
  mov    %ebx,(%rax)
  mov    0x168(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L157
  add    $0x178,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L43:
  lea    D50(%rip),%rdi
  call   <puts@plt>
  jmp    L106
  nopw   0x0(%rax,%rax,1)
L74:
  movss  0x4(%rsp),%xmm0
  movss  0x28(%rsp),%xmm5
  mov    $0x1,%eax
  lea    D52(%rip),%rdi
  divss  %xmm3,%xmm0
  mulss  %xmm0,%xmm5
  cvtss2sd %xmm0,%xmm0
  movss  %xmm5,0x28(%rsp)
  call   <printf@plt>
  jmp    L155
  nopl   0x0(%rax)
L164:
  movss  0x2c(%rsp),%xmm1
  divss  %xmm0,%xmm1
  movaps %xmm1,%xmm0
  call   <fabs@plt>
  mov    0xf8(%rsp),%esi
  mov    %rbp,%rdi
  mov    %eax,%edx
  call   <scalefloats@plt>
  jmp    L151
L152:
  movss  0x14(%rsp),%xmm0
  movss  0x24(%rsp),%xmm7
  mov    $0x1,%eax
  lea    D70(%rip),%rdi
  divss  %xmm5,%xmm0
  mulss  %xmm0,%xmm7
  cvtss2sd %xmm0,%xmm0
  movss  %xmm7,0x24(%rsp)
  call   <printf@plt>
  jmp    L107
L157:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: tag: D89
type_guessed: byte[8]
name: disassemble_data
arguments: tag: D40
type_guessed: f64
name: disassemble_data
arguments: tag: D72
type_guessed: byte[4]
name: disassemble_data
arguments: tag: D33
type_guessed: byte[4]
name: disassemble_data
arguments: tag: D96
type_guessed: byte[4]
name: disassemble_data
arguments: tag: D50
type_guessed: string
name: disassemble_data
arguments: tag: D52
type_guessed: string
name: disassemble_data
arguments: tag: D70
type_guessed: string

tool: {"D89": [0x5c,0x8f,0xc2,0xf5,0x28,0x5c,0xef,0x3f]}

tool: D40: 2

tool: {"D72": [0x00,0x08,0x85,0x45]}

tool: {"D33": [0x00,0x00,0x80,0x3f]}

tool: {"D96": [0x47,0x03,0x80,0x3f]}

tool: D50: bipolar_prewinder: not enough iterations

tool: D52: bipolar_prewinder: scaling Gx by %.3f


tool: D70: bipolar_prewinder: scaling Sx by %.3f


assistant: ```c
void grd_bipolar_prewinder(float gradMax, float gradMaxSys, float slewMax, float T, float kxpre, float kypre, float Gtgt, float **ktraj, float **grad, float **slew, float **time, int *N) {
  float *gxdep = NULL, *gydep = NULL;
  float *kxdep, *gxdep1, *sxdep, *txdep;
  int len_gxdep;
  float t1;
  float rSMAX_gy;
  float *kydepR, *gydepR, *sydepR, *tydepR;
  int NydepR;
  float adepR;
  float *kydepT, *gydepT, *sydepT, *tydepT;
  int NydepT;
  int len_gydep;
  float *interpvec;
  float adepx;
  float sMax;
  float gMax;
  float sscale;
  float gscale;
  float *slewx = NULL, *slewy = NULL;
  float *ktrajx = NULL, *ktrajy = NULL;
  int n;
  float *tempfloats = NULL;
  float errlevel = 0.0001f;
  int iter;
  float rSMAX_gx = .98 * slewMax;
  float rGMAX_gx = .98 * gradMax;
  for (iter = 0; iter < 50; iter++) {
    grd_trapezoid(rGMAX_gx, rSMAX_gx, kxpre, T, &kxdep, &gxdep1, &sxdep, &txdep, &len_gxdep, &n);
    t1 = txdep[len_gxdep - 1] / (1 + sqrt(2.0));
    rSMAX_gy = Gtgt / t1;
    grd_rampup(gradMaxSys, rSMAX_gy, Gtgt, T, &kydepR, &gydepR, &sydepR, &tydepR, &NydepR);
    adepR = 4257 * T * sumfloats(gydepR, NydepR);
    grd_trapezoid(gradMaxSys, rSMAX_gy, -adepR + kypre, T, &kydepT, &gydepT, &sydepT, &tydepT, &NydepT, &n);
    len_gydep = NydepR + NydepT - 1;
    gydep = (float *)malloc(len_gydep * sizeof(float));
    memcpy(gydep, gydepT, NydepT * sizeof(float));
    memcpy(&gydep[NydepT], &gydepR[1], (NydepR - 1) * sizeof(float));
    interpvec = (float *)malloc(len_gydep * sizeof(float));
    gxdep = (float *)malloc(len_gydep * sizeof(float));
    for (n = 0; n < len_gydep; n++)
      interpvec[n] = n * (len_gxdep - 1.0f) / (len_gydep - 1.0f);
    if (tempfloats != NULL)
      free(tempfloats);
    tempfloats = (float *)malloc(len_gxdep * sizeof(float));
    for (n = 0; n < len_gxdep; n++)
      tempfloats[n] = n;
    interpolatefloats(tempfloats, gxdep1, len_gxdep, interpvec, gxdep, len_gydep);
    adepx = 4257 * T * sumfloats(gxdep, len_gxdep);
    if (adepx)
      scalefloats(gxdep, len_gxdep, fabs(kxpre / adepx));
    slewx = (float *)malloc(len_gydep * sizeof(float));
    slewy = (float *)malloc(len_gydep * sizeof(float));
    diffArray(gxdep, slewx, len_gydep);
    diffArray(gydep, slewy, len_gydep);
    slewx[len_gydep - 1] = 0;
    slewy[len_gydep - 1] = 0;
    scalecomplex(slewx, slewy, 1.0f / T, 0.0f, len_gydep);
    sMax = maxMagnitude(slewx, slewy, len_gydep);
    gMax = maxMagnitude(gxdep, gydep, len_gydep);
    if (sMax > slewMax) {
      sscale = slewMax / sMax;
      rSMAX_gx = rSMAX_gx * sscale;
      if (1)
        printf("bipolar_prewinder: scaling Sx by %.3f\n", sscale);
    }
    if (gMax > gradMaxSys) {
      gscale = gradMaxSys / gMax;
      rGMAX_gx = rGMAX_gx * gscale;
      if (1)
        printf("bipolar_prewinder: scaling Gx by %.3f\n", gscale);
    }
    free(slewx);
    free(slewy);
    free(kxdep);
    free(gxdep1);
    free(sxdep);
    free(txdep);
    free(kydepR);
    free(gydepR);
    free(sydepR);
    free(tydepR);
    free(kydepT);
    free(gydepT);
    free(sydepT);
    free(tydepT);
    if (sMax <= (1 + errlevel) * slewMax && gMax <= (1 + errlevel) * gradMaxSys)
      break;
    else {
      free(gxdep);
      free(gydep);
    }
  }
  if (sMax > (1 + errlevel) * slewMax || gMax > (1 + errlevel) * gradMaxSys)
    printf("bipolar_prewinder: not enough iterations\n");
  *ktraj = (float *)malloc(2 * len_gydep * sizeof(float));
  *grad = (float *)malloc(2 * len_gydep * sizeof(float));
  *slew = (float *)malloc(2 * len_gydep * sizeof(float));
  *time = (float *)malloc(len_gydep * sizeof(float));
  memcpy(*grad, gxdep, len_gydep * sizeof(float));
  memcpy(&(*grad)[len_gydep], gydep, len_gydep * sizeof(float));
  ktrajx = *ktraj;
  ktrajy = &(*ktraj)[len_gydep];
  cumulativeSum(gxdep, ktrajx, len_gydep);
  cumulativeSum(gydep, ktrajy, len_gydep);
  scalecomplex(ktrajx, ktrajy, 4257 * T, 0.0f, len_gydep);
  for (n = 0; n < len_gydep; n++)
    (*time)[n] = n * T;
  *N = len_gydep;
  return;
}
```