user: What is the c source code of the assembly code below:

```asm
<grd_bipolar_prewinder>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x140,%rsp
  movss  %xmm0,-0xf4(%rbp)
  movss  %xmm1,-0xf8(%rbp)
  movss  %xmm2,-0xfc(%rbp)
  movss  %xmm3,-0x100(%rbp)
  movss  %xmm4,-0x104(%rbp)
  movss  %xmm5,-0x108(%rbp)
  movss  %xmm6,-0x10c(%rbp)
  mov    %rdi,-0x118(%rbp)
  mov    %rsi,-0x120(%rbp)
  mov    %rdx,-0x128(%rbp)
  mov    %rcx,-0x130(%rbp)
  mov    %r8,-0x138(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movq   $0x0,-0x48(%rbp)
  movq   $0x0,-0x40(%rbp)
  movq   $0x0,-0x30(%rbp)
  movq   $0x0,-0x28(%rbp)
  movq   $0x0,-0x20(%rbp)
  movq   $0x0,-0x18(%rbp)
  movq   $0x0,-0x38(%rbp)
  movss  D62(%rip),%xmm0
  movss  %xmm0,-0xc4(%rbp)
  pxor   %xmm1,%xmm1
  cvtss2sd -0xfc(%rbp),%xmm1
  movsd  D98(%rip),%xmm0
  mulsd  %xmm1,%xmm0
  cvtsd2ss %xmm0,%xmm0
  movss  %xmm0,-0xcc(%rbp)
  pxor   %xmm1,%xmm1
  cvtss2sd -0xf4(%rbp),%xmm1
  movsd  D98(%rip),%xmm0
  mulsd  %xmm1,%xmm0
  cvtsd2ss %xmm0,%xmm0
  movss  %xmm0,-0xc8(%rbp)
  movl   $0x0,-0xd0(%rbp)
  jmp    L146
L47:
  lea    -0xe0(%rbp),%r9
  lea    -0xec(%rbp),%r8
  lea    -0x90(%rbp),%rcx
  lea    -0x98(%rbp),%rdx
  lea    -0xa0(%rbp),%rsi
  lea    -0xa8(%rbp),%rdi
  movss  -0x100(%rbp),%xmm2
  movss  -0x104(%rbp),%xmm1
  movss  -0xcc(%rbp),%xmm0
  mov    -0xc8(%rbp),%eax
  movaps %xmm2,%xmm3
  movaps %xmm1,%xmm2
  movaps %xmm0,%xmm1
  movd   %eax,%xmm0
  call   <grd_trapezoid@plt>
  mov    -0x90(%rbp),%rdx
  mov    -0xec(%rbp),%eax
  cltq
  shl    $0x2,%rax
  sub    $0x4,%rax
  add    %rdx,%rax
  movss  (%rax),%xmm7
  movss  %xmm7,-0x13c(%rbp)
  mov    D127(%rip),%rax
  movq   %rax,%xmm0
  call   <sqrt@plt>
  add    $0x1,%eax
  pxor   %xmm1,%xmm1
  cvtsi2ss %eax,%xmm1
  movss  -0x13c(%rbp),%xmm0
  divss  %xmm1,%xmm0
  movss  %xmm0,-0xc0(%rbp)
  movss  -0x10c(%rbp),%xmm0
  divss  -0xc0(%rbp),%xmm0
  movss  %xmm0,-0xbc(%rbp)
  lea    -0xe8(%rbp),%r8
  lea    -0x70(%rbp),%rcx
  lea    -0x78(%rbp),%rdx
  lea    -0x80(%rbp),%rsi
  lea    -0x88(%rbp),%rdi
  movss  -0x100(%rbp),%xmm2
  movss  -0x10c(%rbp),%xmm1
  movss  -0xbc(%rbp),%xmm0
  mov    -0xf8(%rbp),%eax
  movaps %xmm2,%xmm3
  movaps %xmm1,%xmm2
  movaps %xmm0,%xmm1
  movd   %eax,%xmm0
  call   <grd_rampup@plt>
  movss  -0x100(%rbp),%xmm1
  movss  D73(%rip),%xmm0
  mulss  %xmm0,%xmm1
  movss  %xmm1,-0x13c(%rbp)
  mov    -0xe8(%rbp),%edx
  mov    -0x80(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <sumfloats@plt>
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mulss  -0x13c(%rbp),%xmm0
  movss  %xmm0,-0xb8(%rbp)
  movss  -0x108(%rbp),%xmm0
  movaps %xmm0,%xmm1
  subss  -0xb8(%rbp),%xmm1
  lea    -0xe0(%rbp),%r9
  lea    -0xe4(%rbp),%r8
  lea    -0x50(%rbp),%rcx
  lea    -0x58(%rbp),%rdx
  lea    -0x60(%rbp),%rsi
  lea    -0x68(%rbp),%rdi
  movss  -0x100(%rbp),%xmm2
  movss  -0xbc(%rbp),%xmm0
  mov    -0xf8(%rbp),%eax
  movaps %xmm2,%xmm3
  movaps %xmm1,%xmm2
  movaps %xmm0,%xmm1
  movd   %eax,%xmm0
  call   <grd_trapezoid@plt>
  mov    -0xe8(%rbp),%edx
  mov    -0xe4(%rbp),%eax
  add    %edx,%eax
  sub    $0x1,%eax
  mov    %eax,-0xdc(%rbp)
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x40(%rbp)
  mov    -0xe4(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edx
  mov    -0x60(%rbp),%rcx
  mov    -0x40(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0xe8(%rbp),%eax
  sub    $0x1,%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edx
  mov    -0x80(%rbp),%rax
  lea    0x4(%rax),%rcx
  mov    -0xe4(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rsi
  mov    -0x40(%rbp),%rax
  add    %rsi,%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x10(%rbp)
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x48(%rbp)
  movl   $0x0,-0xe0(%rbp)
  jmp    L91
L85:
  mov    -0xe0(%rbp),%eax
  pxor   %xmm1,%xmm1
  cvtsi2ss %eax,%xmm1
  mov    -0xec(%rbp),%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  movss  D99(%rip),%xmm2
  subss  %xmm2,%xmm0
  mulss  %xmm1,%xmm0
  pxor   %xmm1,%xmm1
  cvtsi2ssl -0xdc(%rbp),%xmm1
  movss  D99(%rip),%xmm2
  subss  %xmm2,%xmm1
  mov    -0xe0(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  divss  %xmm1,%xmm0
  movss  %xmm0,(%rax)
  mov    -0xe0(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,-0xe0(%rbp)
L91:
  mov    -0xe0(%rbp),%eax
  cmp    %eax,-0xdc(%rbp)
  jg     L85
  cmpq   $0x0,-0x38(%rbp)
  je     L73
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
L73:
  mov    -0xec(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x38(%rbp)
  movl   $0x0,-0xe0(%rbp)
  jmp    L148
L97:
  mov    -0xe0(%rbp),%edx
  mov    -0xe0(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rcx
  mov    -0x38(%rbp),%rax
  add    %rcx,%rax
  pxor   %xmm0,%xmm0
  cvtsi2ss %edx,%xmm0
  movss  %xmm0,(%rax)
  mov    -0xe0(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,-0xe0(%rbp)
L148:
  mov    -0xe0(%rbp),%edx
  mov    -0xec(%rbp),%eax
  cmp    %eax,%edx
  jl     L97
  mov    -0xec(%rbp),%edx
  mov    -0xa0(%rbp),%rsi
  mov    -0xdc(%rbp),%r8d
  mov    -0x48(%rbp),%rdi
  mov    -0x10(%rbp),%rcx
  mov    -0x38(%rbp),%rax
  mov    %r8d,%r9d
  mov    %rdi,%r8
  mov    %rax,%rdi
  call   <interpolatefloats@plt>
  movss  -0x100(%rbp),%xmm1
  movss  D73(%rip),%xmm0
  mulss  %xmm0,%xmm1
  movss  %xmm1,-0x13c(%rbp)
  mov    -0xec(%rbp),%edx
  mov    -0x48(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <sumfloats@plt>
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mulss  -0x13c(%rbp),%xmm0
  movss  %xmm0,-0xb4(%rbp)
  pxor   %xmm0,%xmm0
  ucomiss -0xb4(%rbp),%xmm0
  jp     L21
  pxor   %xmm0,%xmm0
  ucomiss -0xb4(%rbp),%xmm0
  je     L131
L21:
  movss  -0x104(%rbp),%xmm0
  divss  -0xb4(%rbp),%xmm0
  movd   %xmm0,%eax
  movd   %eax,%xmm0
  call   <fabs@plt>
  mov    %eax,%edx
  mov    -0xec(%rbp),%ecx
  mov    -0x48(%rbp),%rax
  mov    %ecx,%esi
  mov    %rax,%rdi
  call   <scalefloats@plt>
L131:
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x30(%rbp)
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x28(%rbp)
  mov    -0xdc(%rbp),%edx
  mov    -0x30(%rbp),%rcx
  mov    -0x48(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <diffArray@plt>
  mov    -0xdc(%rbp),%edx
  mov    -0x28(%rbp),%rcx
  mov    -0x40(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <diffArray@plt>
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%rax
  lea    -0x4(%rax),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  pxor   %xmm0,%xmm0
  movss  %xmm0,(%rax)
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%rax
  lea    -0x4(%rax),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  pxor   %xmm0,%xmm0
  movss  %xmm0,(%rax)
  movss  D99(%rip),%xmm0
  divss  -0x100(%rbp),%xmm0
  cvttss2si %xmm0,%edx
  mov    -0xdc(%rbp),%ecx
  mov    -0x28(%rbp),%rsi
  mov    -0x30(%rbp),%rax
  mov    D74(%rip),%edi
  movd   %edi,%xmm0
  mov    %rax,%rdi
  call   <scalecomplex@plt>
  mov    -0xdc(%rbp),%edx
  mov    -0x28(%rbp),%rcx
  mov    -0x30(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <maxMagnitude@plt>
  movd   %xmm0,%eax
  mov    %eax,-0xd8(%rbp)
  mov    -0xdc(%rbp),%edx
  mov    -0x40(%rbp),%rcx
  mov    -0x48(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <maxMagnitude@plt>
  movd   %xmm0,%eax
  mov    %eax,-0xd4(%rbp)
  movss  -0xd8(%rbp),%xmm0
  comiss -0xfc(%rbp),%xmm0
  jbe    L55
  movss  -0xfc(%rbp),%xmm0
  divss  -0xd8(%rbp),%xmm0
  movss  %xmm0,-0xb0(%rbp)
  movss  -0xcc(%rbp),%xmm0
  mulss  -0xb0(%rbp),%xmm0
  movss  %xmm0,-0xcc(%rbp)
  pxor   %xmm4,%xmm4
  cvtss2sd -0xb0(%rbp),%xmm4
  movq   %xmm4,%rax
  movq   %rax,%xmm0
  lea    D124(%rip),%rax
  mov    %rax,%rdi
  mov    $0x1,%eax
  call   <printf@plt>
L55:
  movss  -0xd4(%rbp),%xmm0
  comiss -0xf8(%rbp),%xmm0
  jbe    L105
  movss  -0xf8(%rbp),%xmm0
  divss  -0xd4(%rbp),%xmm0
  movss  %xmm0,-0xac(%rbp)
  movss  -0xc8(%rbp),%xmm0
  mulss  -0xac(%rbp),%xmm0
  movss  %xmm0,-0xc8(%rbp)
  pxor   %xmm5,%xmm5
  cvtss2sd -0xac(%rbp),%xmm5
  movq   %xmm5,%rax
  movq   %rax,%xmm0
  lea    D172(%rip),%rax
  mov    %rax,%rdi
  mov    $0x1,%eax
  call   <printf@plt>
L105:
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0xa8(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0xa0(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x98(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x90(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x88(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x80(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x78(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x70(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x68(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x60(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  movss  -0xc4(%rbp),%xmm1
  movss  D99(%rip),%xmm0
  addss  %xmm1,%xmm0
  mulss  -0xfc(%rbp),%xmm0
  comiss -0xd8(%rbp),%xmm0
  jb     L119
  movss  -0xc4(%rbp),%xmm1
  movss  D99(%rip),%xmm0
  addss  %xmm1,%xmm0
  mulss  -0xf8(%rbp),%xmm0
  comiss -0xd4(%rbp),%xmm0
  jae    L133
L119:
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  addl   $0x1,-0xd0(%rbp)
L146:
  cmpl   $0x31,-0xd0(%rbp)
  jle    L47
L133:
  movss  -0xc4(%rbp),%xmm1
  movss  D99(%rip),%xmm0
  addss  %xmm1,%xmm0
  movaps %xmm0,%xmm1
  mulss  -0xfc(%rbp),%xmm1
  movss  -0xd8(%rbp),%xmm0
  comiss %xmm1,%xmm0
  ja     L165
  movss  -0xc4(%rbp),%xmm1
  movss  D99(%rip),%xmm0
  addss  %xmm1,%xmm0
  movaps %xmm0,%xmm1
  mulss  -0xf8(%rbp),%xmm1
  movss  -0xd4(%rbp),%xmm0
  comiss %xmm1,%xmm0
  jbe    L32
L165:
  lea    D58(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
L32:
  mov    -0xdc(%rbp),%eax
  add    %eax,%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,%rdx
  mov    -0x118(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0xdc(%rbp),%eax
  add    %eax,%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,%rdx
  mov    -0x120(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0xdc(%rbp),%eax
  add    %eax,%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,%rdx
  mov    -0x128(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,%rdx
  mov    -0x130(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edx
  mov    -0x120(%rbp),%rax
  mov    (%rax),%rax
  mov    -0x48(%rbp),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edx
  mov    -0x120(%rbp),%rax
  mov    (%rax),%rcx
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rax,%rcx
  mov    -0x40(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    -0x118(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x118(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0xdc(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rdx,%rax
  mov    %rax,-0x18(%rbp)
  mov    -0xdc(%rbp),%edx
  mov    -0x20(%rbp),%rcx
  mov    -0x48(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <cumulativeSum@plt>
  mov    -0xdc(%rbp),%edx
  mov    -0x18(%rbp),%rcx
  mov    -0x40(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <cumulativeSum@plt>
  movss  -0x100(%rbp),%xmm1
  movss  D73(%rip),%xmm0
  mulss  %xmm1,%xmm0
  cvttss2si %xmm0,%edx
  mov    -0xdc(%rbp),%ecx
  mov    -0x18(%rbp),%rsi
  mov    -0x20(%rbp),%rax
  mov    D74(%rip),%edi
  movd   %edi,%xmm0
  mov    %rax,%rdi
  call   <scalecomplex@plt>
  movl   $0x0,-0xe0(%rbp)
  jmp    L102
L69:
  mov    -0xe0(%rbp),%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mov    -0x130(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0xe0(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rdx,%rax
  mulss  -0x100(%rbp),%xmm0
  movss  %xmm0,(%rax)
  mov    -0xe0(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,-0xe0(%rbp)
L102:
  mov    -0xe0(%rbp),%eax
  cmp    %eax,-0xdc(%rbp)
  jg     L69
  mov    -0x138(%rbp),%rax
  mov    -0xdc(%rbp),%edx
  mov    %edx,(%rax)
  nop
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L139
  call   <__stack_chk_fail@plt>
L139:
  leave
  ret
```

tool_calls: name: read_data
arguments: data_label: D62
type: byte[4]
name: read_data
arguments: data_label: D98
type: byte[8]
name: read_data
arguments: data_label: D127
type: f64
name: read_data
arguments: data_label: D73
type: byte[4]
name: read_data
arguments: data_label: D99
type: byte[4]
name: read_data
arguments: data_label: D74
type: byte[4]
name: read_data
arguments: data_label: D124
type: string
name: read_data
arguments: data_label: D172
type: string
name: read_data
arguments: data_label: D58
type: string

tool: {"D62": [0x17,0xb7,0xd1,0x38]}

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

tool: D127: 2

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

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

tool: {"D74": [0x00,0x00,0x00,0x00]}

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


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


tool: D58: bipolar_prewinder: not enough iterations

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;
}
```