// File: /workspace/github_c_makefile_star2_O1/radforddc[P]icpc_siggen/signal_tester.c
// Function: save_signal
static int save_signal(char *cmd, MJD_Siggen_Setup *setup){
  float spec[MAX_SPE_CHS], d, a_over_e=0, t10, t90;
  struct point cart;
  int   comp_f;
  int   i, j, k, a_over_e_dt=4;
  char  *cp;
  static float *s;

  if (s == NULL){//first call
    if ((s = (float *) malloc(setup->ntsteps_out*sizeof(*s))) == NULL){
      printf("Malloc failed\n");
      return 1;
    }
  }

  if ((k = get_cart(cmd, &cart, setup->coord_type)) <= 0) return 1;
  cp = cmd + k;
  if (strlen(cp) == 0){
    fprintf(stderr, "must supply file name\n");
    return 1;
  }

  if (get_signal(cart, s, setup) < 0) {
    printf("point not in crystal or has no field: (x = %.1f, y = %.1f, z = %.1f)\n",
	   cart.x, cart.y, cart.z);
    return 1;
  }

  /* calculate t10, t90, and A/E */
  a_over_e = t10 = t90 = 0;
  for (i = 0; i < setup->ntsteps_out - a_over_e_dt; i++) {
    d = (s[i+a_over_e_dt] - s[i]) / (float) a_over_e_dt;
    if (d > a_over_e) a_over_e = d;
    if (s[i] < 0.1f && s[i+1] >= 0.1f)
      t10 = 10.0f*((float) i + (0.1f - s[i]) / (s[i+1] - s[i]));
    if (s[i] < 0.9f && s[i+1] >= 0.9f)
      t90 = 10.0f*((float) i + (0.9f - s[i]) / (s[i+1] - s[i]));
  }
  printf("t_90, t_10-90, A/E = %4.0f %4.0f %f\n", t90, t90-t10, a_over_e);

  comp_f = 1;
  while (setup->ntsteps_out/comp_f > MAX_SPE_CHS) comp_f++;
  if (comp_f > 1) printf("spectrum will be compressed by factor %d\n", comp_f);
  for (i = 0; i < (int) (sizeof(spec)/sizeof(spec[0])); i++) spec[i] = 0.0;

  /*copy signal data to spectrum array*/
  for (j = 0; j < setup->ntsteps_out; j++) spec[j/comp_f] += s[j]*1000/comp_f;
  write_spectrum(spec, setup->ntsteps_out/comp_f, cp);
  printf("%d channels of data saved in spectrum %s\n",
	 setup->ntsteps_out/comp_f, cp);

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10048, %rsp          # imm = 0x10048
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, 0x7e98(%rip)      # 0xf230
jne 0x73ba
movslq 0x3ac(%r14), %rdi
shlq $0x2, %rdi
callq 0x20d0
movq %rax, 0x7e7f(%rip)      # 0xf230
testq %rax, %rax
je 0x7722
movl 0x3a8(%r14), %edx
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x7dec
movl $0x1, %ebp
testl %eax, %eax
jle 0x7733
movl %eax, %r15d
cmpb $0x0, (%rbx,%r15)
je 0x7747
movq 0x7e40(%rip), %rdi      # 0xf230
movsd 0x10(%rsp), %xmm0
movss 0x18(%rsp), %xmm1
movss %xmm1, 0xc(%rsp)
movq %r14, %rsi
callq 0x263a
testl %eax, %eax
js 0x74f6
movl 0x3ac(%r14), %eax
cmpl $0x5, %eax
jl 0x7521
addl $-0x4, %eax
movq 0x7e04(%rip), %rcx      # 0xf230
xorps %xmm0, %xmm0
xorl %edx, %edx
movss 0x22bb(%rip), %xmm2     # 0x96f4
movss 0xbd3(%rip), %xmm4      # 0x8014
movss 0x22af(%rip), %xmm5     # 0x96f8
movss 0x22ab(%rip), %xmm6     # 0x96fc
xorps %xmm3, %xmm3
xorps %xmm1, %xmm1
movaps %xmm0, %xmm7
movss (%rcx,%rdx,4), %xmm8
movss 0x10(%rcx,%rdx,4), %xmm0
subss %xmm8, %xmm0
mulss %xmm2, %xmm0
ucomiss %xmm8, %xmm4
jbe 0x74a6
movss 0x4(%rcx,%rdx,4), %xmm9
ucomiss %xmm4, %xmm9
jb 0x74a6
xorps %xmm10, %xmm10
cvtsi2ss %edx, %xmm10
movaps %xmm4, %xmm3
subss %xmm8, %xmm3
subss %xmm8, %xmm9
divss %xmm9, %xmm3
addss %xmm10, %xmm3
mulss %xmm5, %xmm3
ucomiss %xmm8, %xmm6
jbe 0x74dd
movss 0x4(%rcx,%rdx,4), %xmm9
ucomiss %xmm6, %xmm9
jb 0x74dd
xorps %xmm10, %xmm10
cvtsi2ss %edx, %xmm10
movaps %xmm6, %xmm1
subss %xmm8, %xmm1
subss %xmm8, %xmm9
divss %xmm9, %xmm1
addss %xmm10, %xmm1
mulss %xmm5, %xmm1
maxss %xmm7, %xmm0
incq %rdx
cmpq %rdx, %rax
jne 0x7457
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
jmp 0x752a
xorps %xmm0, %xmm0
cvtss2sd 0x10(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x14(%rsp), %xmm1
cvtss2sd 0xc(%rsp), %xmm2
leaq 0x223e(%rip), %rdi      # 0x9753
movb $0x3, %al
callq 0x2030
jmp 0x7733
xorps %xmm2, %xmm2
xorps %xmm1, %xmm1
xorps %xmm3, %xmm3
addq %r15, %rbx
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
subss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x2256(%rip), %rdi      # 0x9799
movb $0x3, %al
callq 0x2030
movl 0x3ac(%r14), %ecx
xorl %ebp, %ebp
incl %ebp
movl %ecx, %eax
cltd
idivl %ebp
cmpl $0x4000, %eax           # imm = 0x4000
jg 0x7553
cmpl $0x2, %ebp
jb 0x7576
leaq 0x2251(%rip), %rdi      # 0x97be
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
leaq 0x40(%rsp), %rdi
movl $0x10000, %edx          # imm = 0x10000
xorl %esi, %esi
callq 0x2050
movslq 0x3ac(%r14), %rcx
testq %rcx, %rcx
jle 0x75d2
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
movq 0x7c8f(%rip), %rdi      # 0xf230
xorl %esi, %esi
movss 0x2155(%rip), %xmm1     # 0x9700
movss (%rdi,%rsi,4), %xmm2
mulss %xmm1, %xmm2
divss %xmm0, %xmm2
movl %esi, %eax
xorl %edx, %edx
divl %ebp
addss 0x40(%rsp,%rax,4), %xmm2
movss %xmm2, 0x40(%rsp,%rax,4)
incq %rsi
cmpq %rsi, %rcx
jne 0x75ab
movl %ecx, %eax
cltd
idivl %ebp
movl %eax, %r12d
movq $0x18, 0x1c(%rsp)
movl $0x0, 0x24(%rsp)
movabsq $0x1800000001, %rax     # imm = 0x1800000001
movq %rax, 0x34(%rsp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x2c(%rsp)
leaq 0x222b(%rip), %rsi      # 0x983b
movq %rbx, %rdi
callq 0x20e0
testq %rax, %rax
je 0x774e
movq %rax, %r15
movl %r12d, 0x28(%rsp)
leaq 0x2236(%rip), %rsi      # 0x9866
movq %rbx, %rdi
callq 0x21a0
movq %rax, %r13
testq %rax, %rax
jne 0x764e
movq %rbx, %rdi
callq 0x2160
movq %rax, %r13
addq %rbx, %r13
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x2110
leaq 0x1(%rax), %rsi
testq %rax, %rax
cmoveq %rbx, %rsi
movq %r13, %rdx
subq %rsi, %rdx
cmpq $0x7, %rdx
jg 0x768b
leaq 0x20(%rsp), %rdi
movabsq $0x20202020202020, %rax # imm = 0x20202020202020
movq %rax, (%rdi)
callq 0x2290
jmp 0x7694
movq -0x8(%r13), %rax
movq %rax, 0x20(%rsp)
leaq 0x1c(%rsp), %rdi
movl 0xc(%rdi), %eax
shll $0x2, %eax
leaq 0x3c(%rsp), %r13
movl %eax, (%r13)
movl $0x20, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2230
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rcx
callq 0x2230
movslq %r12d, %rdx
leaq 0x40(%rsp), %rdi
movl $0x4, %esi
movq %r15, %rcx
callq 0x2230
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rcx
callq 0x2230
movq %r15, %rdi
callq 0x2210
movl 0x3ac(%r14), %eax
cltd
idivl %ebp
leaq 0x20d6(%rip), %rdi      # 0x97e8
xorl %ebp, %ebp
movl %eax, %esi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2030
jmp 0x7733
leaq 0x2341(%rip), %rdi      # 0x9a6a
callq 0x2090
movl $0x1, %ebp
movl %ebp, %eax
addq $0x10048, %rsp          # imm = 0x10048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2378
jmp 0x7733
movq 0x489b(%rip), %rax      # 0xbff0
movq (%rax), %rdi
leaq 0x20de(%rip), %rsi      # 0x983d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2250
jmp 0x7701