// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10070, %rsp          # imm = 0x10070
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x10028(%rbp)
movl $0x4, -0x10050(%rbp)
cmpq $0x0, 0x9450(%rip)      # 0x14210
jne 0xadff
movq -0x18(%rbp), %rax
movslq 0x3ac(%rax), %rdi
shlq $0x2, %rdi
callq 0x20b0
movq %rax, 0x9433(%rip)      # 0x14210
cmpq $0x0, %rax
jne 0xadfd
leaq 0x398c(%rip), %rdi      # 0xe776
movb $0x0, %al
callq 0x2030
movl $0x1, -0x4(%rbp)
jmp 0xb2a6
jmp 0xadff
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x3a8(%rax), %edx
leaq -0x1003c(%rbp), %rsi
callq 0xbc40
movl %eax, -0x1004c(%rbp)
cmpl $0x0, %eax
jg 0xae30
movl $0x1, -0x4(%rbp)
jmp 0xb2a6
movq -0x10(%rbp), %rax
movslq -0x1004c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x10058(%rbp)
movq -0x10058(%rbp), %rdi
callq 0x2130
cmpq $0x0, %rax
jne 0xae7b
movq 0x6192(%rip), %rax      # 0x10ff0
movq (%rax), %rdi
leaq 0x391d(%rip), %rsi      # 0xe785
movb $0x0, %al
callq 0x2220
movl $0x1, -0x4(%rbp)
jmp 0xb2a6
movq 0x938e(%rip), %rdi      # 0x14210
movq -0x18(%rbp), %rsi
movl -0x10034(%rbp), %eax
movl %eax, -0x10060(%rbp)
movq -0x1003c(%rbp), %rax
movq %rax, -0x10068(%rbp)
movsd -0x10068(%rbp), %xmm0
movss -0x10060(%rbp), %xmm1
callq 0x2670
cmpl $0x0, %eax
jge 0xaef8
movss -0x1003c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x10038(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x10034(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x38b7(%rip), %rdi      # 0xe79c
movb $0x3, %al
callq 0x2030
movl $0x1, -0x4(%rbp)
jmp 0xb2a6
xorps %xmm0, %xmm0
movss %xmm0, -0x10030(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1002c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x10028(%rbp)
movl $0x0, -0x10044(%rbp)
movl -0x10044(%rbp), %eax
movq -0x18(%rbp), %rcx
movl 0x3ac(%rcx), %ecx
subl -0x10050(%rbp), %ecx
cmpl %ecx, %eax
jge 0xb118
movq 0x92c8(%rip), %rax      # 0x14210
movl -0x10044(%rbp), %ecx
addl -0x10050(%rbp), %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movq 0x92ad(%rip), %rax      # 0x14210
movslq -0x10044(%rbp), %rcx
subss (%rax,%rcx,4), %xmm0
cvtsi2ssl -0x10050(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x10024(%rbp)
movss -0x10024(%rbp), %xmm0
ucomiss -0x10028(%rbp), %xmm0
jbe 0xafa4
movss -0x10024(%rbp), %xmm0
movss %xmm0, -0x10028(%rbp)
movq 0x9265(%rip), %rax      # 0x14210
movslq -0x10044(%rbp), %rcx
movss 0x205a(%rip), %xmm0     # 0xd014
ucomiss (%rax,%rcx,4), %xmm0
jbe 0xb053
movq 0x9245(%rip), %rax      # 0x14210
movl -0x10044(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movss 0x2030(%rip), %xmm1     # 0xd014
ucomiss %xmm1, %xmm0
jb 0xb053
cvtsi2ssl -0x10044(%rbp), %xmm1
movq 0x9218(%rip), %rax      # 0x14210
movslq -0x10044(%rbp), %rcx
movss 0x200d(%rip), %xmm0     # 0xd014
subss (%rax,%rcx,4), %xmm0
movq 0x91fd(%rip), %rax      # 0x14210
movl -0x10044(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm2
movq 0x91e5(%rip), %rax      # 0x14210
movslq -0x10044(%rbp), %rcx
subss (%rax,%rcx,4), %xmm2
divss %xmm2, %xmm0
addss %xmm0, %xmm1
movss 0x36b1(%rip), %xmm0     # 0xe6f8
mulss %xmm1, %xmm0
movss %xmm0, -0x1002c(%rbp)
movq 0x91b6(%rip), %rax      # 0x14210
movslq -0x10044(%rbp), %rcx
movss 0x3693(%rip), %xmm0     # 0xe6fc
ucomiss (%rax,%rcx,4), %xmm0
jbe 0xb102
movq 0x9196(%rip), %rax      # 0x14210
movl -0x10044(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movss 0x3669(%rip), %xmm1     # 0xe6fc
ucomiss %xmm1, %xmm0
jb 0xb102
cvtsi2ssl -0x10044(%rbp), %xmm1
movq 0x9169(%rip), %rax      # 0x14210
movslq -0x10044(%rbp), %rcx
movss 0x3646(%rip), %xmm0     # 0xe6fc
subss (%rax,%rcx,4), %xmm0
movq 0x914e(%rip), %rax      # 0x14210
movl -0x10044(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm2
movq 0x9136(%rip), %rax      # 0x14210
movslq -0x10044(%rbp), %rcx
subss (%rax,%rcx,4), %xmm2
divss %xmm2, %xmm0
addss %xmm0, %xmm1
movss 0x3602(%rip), %xmm0     # 0xe6f8
mulss %xmm1, %xmm0
movss %xmm0, -0x10030(%rbp)
jmp 0xb104
movl -0x10044(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10044(%rbp)
jmp 0xaf23
movss -0x10030(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x10030(%rbp), %xmm1
subss -0x1002c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x10028(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x3697(%rip), %rdi      # 0xe7e2
movb $0x3, %al
callq 0x2030
movl $0x1, -0x10040(%rbp)
movq -0x18(%rbp), %rax
movl 0x3ac(%rax), %eax
cltd
idivl -0x10040(%rbp)
cmpl $0x4000, %eax           # imm = 0x4000
jle 0xb185
movl -0x10040(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10040(%rbp)
jmp 0xb15c
cmpl $0x1, -0x10040(%rbp)
jle 0xb1a2
movl -0x10040(%rbp), %esi
leaq 0x366c(%rip), %rdi      # 0xe807
movb $0x0, %al
callq 0x2030
movl $0x0, -0x10044(%rbp)
cmpl $0x4000, -0x10044(%rbp) # imm = 0x4000
jge 0xb1dc
movslq -0x10044(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, -0x10020(%rbp,%rax,4)
movl -0x10044(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10044(%rbp)
jmp 0xb1ac
movl $0x0, -0x10048(%rbp)
movl -0x10048(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x3ac(%rcx), %eax
jge 0xb251
movq 0x9011(%rip), %rax      # 0x14210
movslq -0x10048(%rbp), %rcx
movss 0x34e6(%rip), %xmm0     # 0xe6f4
mulss (%rax,%rcx,4), %xmm0
cvtsi2ssl -0x10040(%rbp), %xmm1
divss %xmm1, %xmm0
movl -0x10048(%rbp), %eax
cltd
idivl -0x10040(%rbp)
cltq
addss -0x10020(%rbp,%rax,4), %xmm0
movss %xmm0, -0x10020(%rbp,%rax,4)
movl -0x10048(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10048(%rbp)
jmp 0xb1e6
leaq -0x10020(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x3ac(%rax), %eax
cltd
idivl -0x10040(%rbp)
movl %eax, %esi
movq -0x10058(%rbp), %rdx
callq 0xc0a0
movq -0x18(%rbp), %rax
movl 0x3ac(%rax), %eax
cltd
idivl -0x10040(%rbp)
movl %eax, %esi
movq -0x10058(%rbp), %rdx
leaq 0x3599(%rip), %rdi      # 0xe831
movb $0x0, %al
callq 0x2030
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10070, %rsp          # imm = 0x10070
popq %rbp
retq
nopw %cs:(%rax,%rax)