user: 请从给定的汇编指令推导出C源代码：

```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  D65(%rip),%xmm2
  movss  %xmm3,(%rsp)
  movss  %xmm4,0x38(%rsp)
  mulsd  %xmm2,%xmm1
  movss  %xmm5,0x3c(%rsp)
  mulsd  %xmm2,%xmm0
  movss  %xmm6,0xc0(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x168(%rsp)
  xor    %eax,%eax
  lea    0x104(%rsp),%rax
  movl   $0x32,0xc4(%rsp)
  mov    %rax,0x98(%rsp)
  lea    0xf8(%rsp),%rax
  mov    %rax,0x80(%rsp)
  lea    0x120(%rsp),%rax
  cvtsd2ss %xmm1,%xmm7
  mov    %rax,0xb8(%rsp)
  lea    0x118(%rsp),%rax
  mov    %rax,0xb0(%rsp)
  lea    0x110(%rsp),%rax
  mov    %rax,0xa8(%rsp)
  lea    0x108(%rsp),%rax
  mov    %rax,0xa0(%rsp)
  lea    0xfc(%rsp),%rax
  mov    %rax,0x88(%rsp)
  lea    0x140(%rsp),%rax
  mov    %rax,0x58(%rsp)
  lea    0x138(%rsp),%rax
  movss  %xmm7,0x28(%rsp)
  pxor   %xmm7,%xmm7
  cvtsd2ss %xmm0,%xmm7
  movss  %xmm7,0x2c(%rsp)
  mov    %rax,0x50(%rsp)
  lea    0x130(%rsp),%rax
  mov    %rax,0x48(%rsp)
  lea    0x128(%rsp),%rax
  mov    %rax,0x40(%rsp)
  lea    0x100(%rsp),%rax
  mov    %rax,0x90(%rsp)
  lea    0x160(%rsp),%rax
  mov    %rax,0x78(%rsp)
  lea    0x158(%rsp),%rax
  mov    %rax,0x70(%rsp)
  lea    0x150(%rsp),%rax
  mov    %rax,0x68(%rsp)
  lea    0x148(%rsp),%rax
  mov    %rax,0x60(%rsp)
  nopl   0x0(%rax)
L125:
  mov    0x98(%rsp),%r14
  mov    0x80(%rsp),%r8
  mov    0xb8(%rsp),%rcx
  mov    0xa8(%rsp),%rsi
  mov    0xa0(%rsp),%rdi
  movss  (%rsp),%xmm3
  mov    %r14,%r9
  movss  0x38(%rsp),%xmm2
  movss  0x28(%rsp),%xmm1
  mov    0xb0(%rsp),%rdx
  movss  0x2c(%rsp),%xmm0
  call   <grd_trapezoid@plt>
  movslq 0xf8(%rsp),%rdx
  mov    0x120(%rsp),%rax
  mov    -0x4(%rax,%rdx,4),%ebx
  mov    D62(%rip),%rax
  movq   %rax,%xmm0
  call   <sqrt@plt>
  pxor   %xmm1,%xmm1
  movd   %ebx,%xmm0
  movss  0xc0(%rsp),%xmm2
  add    $0x1,%eax
  mov    0x58(%rsp),%rcx
  mov    0x50(%rsp),%rdx
  cvtsi2ss %eax,%xmm1
  movss  (%rsp),%xmm3
  mov    0x48(%rsp),%rsi
  mov    0x88(%rsp),%r8
  mov    0x40(%rsp),%rdi
  divss  %xmm1,%xmm0
  movaps %xmm2,%xmm1
  divss  %xmm0,%xmm1
  movss  0x4(%rsp),%xmm0
  movss  %xmm1,0x8(%rsp)
  call   <grd_rampup@plt>
  movss  D125(%rip),%xmm6
  mulss  (%rsp),%xmm6
  mov    0xfc(%rsp),%esi
  mov    0x130(%rsp),%rdi
  movss  %xmm6,0xc(%rsp)
  call   <sumfloats@plt>
  pxor   %xmm0,%xmm0
  movss  0x3c(%rsp),%xmm2
  mov    0x90(%rsp),%r8
  cvtsi2ss %eax,%xmm0
  mulss  0xc(%rsp),%xmm0
  movss  (%rsp),%xmm3
  mov    %r14,%r9
  movss  0x8(%rsp),%xmm1
  mov    0x70(%rsp),%rdx
  mov    0x68(%rsp),%rsi
  mov    0x78(%rsp),%rcx
  mov    0x60(%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,0x20(%rsp)
  lea    0x0(,%rbx,4),%r13d
  movslq %ebx,%rcx
  mov    %r13d,%edi
  mov    %rcx,0x18(%rsp)
  call   <malloc@plt>
  mov    0x100(%rsp),%ecx
  mov    0x150(%rsp),%rsi
  mov    %rax,%rdi
  mov    %rax,%r12
  lea    0x0(,%rcx,4),%edx
  call   <memcpy@plt>
  mov    0xfc(%rsp),%eax
  mov    0x130(%rsp),%rcx
  lea    -0x4(,%rax,4),%edx
  movslq 0x100(%rsp),%rax
  lea    0x4(%rcx),%rsi
  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    L153
  mov    0x20(%rsp),%eax
  pxor   %xmm5,%xmm5
  pxor   %xmm4,%xmm4
  cvtsi2ssl 0xf8(%rsp),%xmm5
  subss  D0(%rip),%xmm5
  sub    $0x2,%eax
  cvtsi2ss %ebx,%xmm4
  subss  D0(%rip),%xmm4
  cmp    $0x2,%eax
  jbe    L220
  mov    %ebx,%edx
  movdqa D137(%rip),%xmm1
  movaps %xmm5,%xmm3
  movaps %xmm4,%xmm2
  shr    $0x2,%edx
  mov    %r14,%rax
  shufps $0x0,%xmm3,%xmm3
  shufps $0x0,%xmm2,%xmm2
  shl    $0x4,%rdx
  add    %r14,%rdx
  nopl   0x0(%rax)
L225:
  movdqa %xmm1,%xmm0
  add    $0x10,%rax
  paddd  D37(%rip),%xmm1
  cvtdq2ps %xmm0,%xmm0
  mulps  %xmm3,%xmm0
  divps  %xmm2,%xmm0
  movups %xmm0,-0x10(%rax)
  cmp    %rdx,%rax
  jne    L225
  mov    %ebx,%eax
  and    $0xfffffffc,%eax
  test   $0x3,%bl
  je     L206
L163:
  pxor   %xmm0,%xmm0
  movslq %eax,%rcx
  cvtsi2ss %eax,%xmm0
  lea    0x0(,%rcx,4),%rdx
  mulss  %xmm5,%xmm0
  divss  %xmm4,%xmm0
  movss  %xmm0,(%r14,%rcx,4)
  lea    0x1(%rax),%ecx
  cmp    %ecx,%ebx
  jle    L206
  pxor   %xmm0,%xmm0
  add    $0x2,%eax
  cvtsi2ss %ecx,%xmm0
  mulss  %xmm5,%xmm0
  divss  %xmm4,%xmm0
  movss  %xmm0,0x4(%r14,%rdx,1)
  cmp    %eax,%ebx
  jle    L206
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mulss  %xmm5,%xmm0
  divss  %xmm4,%xmm0
  movss  %xmm0,0x8(%r14,%rdx,1)
L206:
  mov    %ebx,0x104(%rsp)
L153:
  test   %r15,%r15
  je     L83
  mov    %r15,%rdi
  call   <free@plt>
L83:
  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    L136
  lea    -0x1(%r10),%eax
  cmp    $0x2,%eax
  jbe    L229
  mov    %r10d,%edx
  movdqa D137(%rip),%xmm1
  mov    %r15,%rax
  shr    $0x2,%edx
  shl    $0x4,%rdx
  add    %r15,%rdx
  nopl   0x0(%rax)
L178:
  movdqa %xmm1,%xmm0
  add    $0x10,%rax
  paddd  D37(%rip),%xmm1
  cvtdq2ps %xmm0,%xmm0
  movups %xmm0,-0x10(%rax)
  cmp    %rax,%rdx
  jne    L178
  mov    %r10d,%eax
  and    $0xfffffffc,%eax
  test   $0x3,%r10b
  je     L95
L21:
  pxor   %xmm0,%xmm0
  movslq %eax,%rdx
  cvtsi2ss %eax,%xmm0
  lea    0x0(,%rdx,4),%rcx
  movss  %xmm0,(%r15,%rdx,4)
  lea    0x1(%rax),%edx
  cmp    %edx,%r10d
  jle    L95
  pxor   %xmm0,%xmm0
  add    $0x2,%eax
  cvtsi2ss %edx,%xmm0
  movss  %xmm0,0x4(%r15,%rcx,1)
  cmp    %eax,%r10d
  jle    L95
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  movss  %xmm0,0x8(%r15,%rcx,1)
L95:
  mov    %r10d,0x104(%rsp)
L136:
  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   %xmm6,%xmm6
  cvtsi2ss %eax,%xmm0
  mulss  0xc(%rsp),%xmm0
  ucomiss %xmm6,%xmm0
  jp     L302
  jne    L302
L187:
  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  D0(%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),%xmm7
  comiss 0x14(%rsp),%xmm7
  movss  %xmm0,0x10(%rsp)
  ja     L344
L296:
  movss  0x10(%rsp),%xmm7
  comiss 0x4(%rsp),%xmm7
  ja     L140
L17:
  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  D52(%rip),%xmm0
  mulss  0x14(%rsp),%xmm0
  comiss 0x8(%rsp),%xmm0
  jb     L76
  movss  D52(%rip),%xmm1
  mulss  0x4(%rsp),%xmm1
  comiss 0x10(%rsp),%xmm1
  jae    L241
L76:
  mov    %rbp,%rdi
  movss  %xmm0,0x24(%rsp)
  call   <free@plt>
  mov    %r12,%rdi
  call   <free@plt>
  subl   $0x1,0xc4(%rsp)
  movss  0x24(%rsp),%xmm0
  jne    L125
L241:
  movss  0x8(%rsp),%xmm6
  comiss %xmm0,%xmm6
  ja     L239
  movss  D52(%rip),%xmm0
  mulss  0x4(%rsp),%xmm0
  movss  0x10(%rsp),%xmm6
  comiss %xmm0,%xmm6
  ja     L239
L24:
  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),%rsi
  mov    0x18(%rsp),%r13d
  mov    %rax,(%rsi)
  shl    $0x2,%r13d
  mov    %r13d,%edi
  call   <malloc@plt>
  mov    0xc8(%rsp),%rsi
  mov    %r13d,%edx
  mov    %rax,(%rsi)
  mov    (%r15),%rdi
  mov    %rbp,%rsi
  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    L271
  mov    0x20(%rsp),%eax
  mov    0xc8(%rsp),%rsi
  sub    $0x2,%eax
  mov    (%rsi),%rcx
  cmp    $0x2,%eax
  jbe    L210
  mov    %ebx,%edx
  movss  (%rsp),%xmm3
  mov    %rcx,%rax
  movdqa D137(%rip),%xmm1
  shr    $0x2,%edx
  movdqa D37(%rip),%xmm2
  sub    $0x1,%edx
  shufps $0x0,%xmm3,%xmm3
  shl    $0x4,%rdx
  lea    0x10(%rcx,%rdx,1),%rdx
  nop
L31:
  movdqa %xmm1,%xmm0
  add    $0x10,%rax
  paddd  %xmm2,%xmm1
  cvtdq2ps %xmm0,%xmm0
  mulps  %xmm3,%xmm0
  movups %xmm0,-0x10(%rax)
  cmp    %rdx,%rax
  jne    L31
  mov    %ebx,%eax
  and    $0xfffffffc,%eax
  test   $0x3,%bl
  je     L271
L332:
  pxor   %xmm0,%xmm0
  movss  (%rsp),%xmm4
  movslq %eax,%rdx
  cvtsi2ss %eax,%xmm0
  lea    0x0(,%rdx,4),%rsi
  mulss  %xmm4,%xmm0
  movss  %xmm0,(%rcx,%rdx,4)
  lea    0x1(%rax),%edx
  cmp    %ebx,%edx
  jge    L271
  pxor   %xmm0,%xmm0
  add    $0x2,%eax
  cvtsi2ss %edx,%xmm0
  mulss  %xmm4,%xmm0
  movss  %xmm0,0x4(%rcx,%rsi,1)
  cmp    %eax,%ebx
  jle    L271
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mulss  %xmm4,%xmm0
  movss  %xmm0,0x8(%rcx,%rsi,1)
L271:
  mov    0xe8(%rsp),%rax
  mov    %ebx,(%rax)
  mov    0x168(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L345
  add    $0x178,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L239:
  lea    D113(%rip),%rdi
  call   <puts@plt>
  jmp    L24
  nopl   0x0(%rax)
L302:
  movss  0x38(%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    L187
  nopl   0x0(%rax,%rax,1)
L140:
  movss  0x4(%rsp),%xmm0
  movss  0x2c(%rsp),%xmm6
  mov    $0x1,%eax
  lea    D8(%rip),%rdi
  divss  %xmm7,%xmm0
  mulss  %xmm0,%xmm6
  cvtss2sd %xmm0,%xmm0
  movss  %xmm6,0x2c(%rsp)
  call   <printf@plt>
  jmp    L17
  nopl   0x0(%rax)
L344:
  movss  0x14(%rsp),%xmm0
  movss  0x28(%rsp),%xmm5
  mov    $0x1,%eax
  lea    D169(%rip),%rdi
  divss  %xmm7,%xmm0
  mulss  %xmm0,%xmm5
  cvtss2sd %xmm0,%xmm0
  movss  %xmm5,0x28(%rsp)
  call   <printf@plt>
  jmp    L296
L229:
  xor    %eax,%eax
  jmp    L21
L220:
  xor    %eax,%eax
  jmp    L163
L210:
  xor    %eax,%eax
  jmp    L332
L345:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: tag: D65
type: byte[8]
name: extract_symbolic_data
arguments: tag: D62
type: f64
name: extract_symbolic_data
arguments: tag: D125
type: byte[4]
name: extract_symbolic_data
arguments: tag: D0
type: byte[4]
name: extract_symbolic_data
arguments: tag: D137
type: byte[16]
name: extract_symbolic_data
arguments: tag: D37
type: byte[16]
name: extract_symbolic_data
arguments: tag: D52
type: byte[4]
name: extract_symbolic_data
arguments: tag: D113
type: string
name: extract_symbolic_data
arguments: tag: D8
type: string
name: extract_symbolic_data
arguments: tag: D169
type: string

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

tool: D62: 2

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

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

tool: {"D137": [0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00]}

tool: {"D37": [0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00]}

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

tool: D113: bipolar_prewinder: not enough iterations

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


tool: D169: 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;
}
```