// File: /workspace/github_c_makefile_star2_O2/usgs[P]nshmp-haz-catalogs/src/agrid/adaptive/write_asum_to_file.c
// Function: write_asum_to_file
void write_asum_to_file(struct rates* seisr, char *fbasenm, struct catalog * catv, float mag)
/*--------------------------------------------------------------------------*/
{ 
  FILE *fpout;
//  int nsrc, cnt, ierr, out2=0;
  int nsrc, cnt, ierr;
//  int nsrc, cnt;
  float diffth=1e-1;
  float asum[NV];
  char fileout[200];
//  struct header headr;

// get rate array and naming based on magnitude input values
  nsrc=seisr->nv;
// Magnitudes
  if ( fabsf(mag-0.0)<diffth ) {
    sprintf(fileout,"%s_M0.out", fbasenm);
    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileout);
    for(cnt=0; cnt<nsrc; cnt++) asum[cnt]=seisr->asum[cnt];
  }
  else if ( fabsf(mag-2.5)<diffth ) {
    sprintf(fileout,"%s_M2p5.out", fbasenm);
    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileout);
    for(cnt=0; cnt<nsrc; cnt++) asum[cnt]=seisr->asum[cnt]*powf(10,-(catv->bval)*mag);
  }
  else if ( fabsf(mag-2.7)<diffth ) {
    sprintf(fileout,"%s_M2p7.out", fbasenm);
    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileout);
    for(cnt=0; cnt<nsrc; cnt++) asum[cnt]=seisr->asum[cnt]*powf(10,-(catv->bval)*mag);
  }
  else if ( fabsf(mag-3.0)<diffth ) {
    sprintf(fileout,"%s_M3.out", fbasenm);
    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileout);
    for(cnt=0; cnt<nsrc; cnt++) asum[cnt]=seisr->asum[cnt]*powf(10,-(catv->bval)*mag);
  }
  else if ( fabsf(mag-3.5)<diffth ) {
    sprintf(fileout,"%s_M3p5.out", fbasenm);
    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileout);
    for(cnt=0; cnt<nsrc; cnt++) asum[cnt]=seisr->asum[cnt]*powf(10,-(catv->bval)*mag);
  }
  else if ( fabsf(mag-4.0)<diffth ) {
    sprintf(fileout,"%s_M4.out", fbasenm);
    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileout);
    for(cnt=0; cnt<nsrc; cnt++) asum[cnt]=seisr->asum[cnt]*powf(10,-(catv->bval)*mag);
  }
  else if ( fabsf(mag-4.7)<diffth ) {
    sprintf(fileout,"%s_M4p7.out", fbasenm);
    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileout);
    for(cnt=0; cnt<nsrc; cnt++) asum[cnt]=seisr->asum[cnt]*powf(10,-(catv->bval)*mag);
  }
  else if ( fabsf(mag-4.5)<diffth ) {
    sprintf(fileout,"%s_M4p5.out", fbasenm);
    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileout);
    for(cnt=0; cnt<nsrc; cnt++) asum[cnt]=seisr->asum[cnt]*powf(10,-(catv->bval)*mag);
  }
  else if ( fabsf(mag-5.0)<diffth ) {
    sprintf(fileout,"%s_M5.out", fbasenm);
    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileout);
    for(cnt=0; cnt<nsrc; cnt++) asum[cnt]=seisr->asum[cnt]*powf(10,-(catv->bval)*mag);
  }
  else {
//    out2=1;
    sprintf(fileout,"%s_M0.out", fbasenm);
    fprintf(stderr,"No option for M%.2f printing, writing to M0 file - %s\n", mag, fileout);
    for(cnt=0; cnt<nsrc; cnt++) asum[cnt]=seisr->asum[cnt];
  }


// write results to file, fileout
  fpout=fopen(fileout,"wb+");
  ierr=fwrite(asum,4,nsrc,fpout);
  fclose(fpout);
//  fprintf(stderr,"Wrote M%.2f results to file, %s.\n", mag, fileout);
  

}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa6130, %rsp          # imm = 0xA6130
movq %rdx, %r15
movq %rsi, %rdx
movq %rdi, %r14
movslq 0x298100(%rdi), %rbx
cvtss2sd %xmm0, %xmm3
movaps 0x2fb1(%rip), %xmm1     # 0x74b0
andps %xmm0, %xmm1
movss 0x2fb6(%rip), %xmm2     # 0x74c0
ucomiss %xmm1, %xmm2
movsd %xmm3, 0x8(%rsp)
jbe 0x457b
leaq 0x2fc4(%rip), %rsi      # 0x74e0
xorl %r12d, %r12d
leaq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x1170
movq 0x5ac3(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2fab(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r15, %rdx
movb $0x1, %al
callq 0x10f0
testl %ebx, %ebx
movl $0x0, %eax
cmovgl %ebx, %eax
cmpq %r12, %rax
je 0x4b82
movss 0x14c080(%r14,%r12,4), %xmm0
movss %xmm0, 0xf0(%rsp,%r12,4)
incq %r12
jmp 0x4559
movss 0x2f41(%rip), %xmm1     # 0x74c4
addss %xmm0, %xmm1
andps 0x2f22(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
movaps %xmm0, 0x10(%rsp)
jbe 0x4633
leaq 0x2f64(%rip), %rsi      # 0x7507
xorl %r13d, %r13d
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1170
movq 0x5a3c(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2f24(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r12, %rdx
movb $0x1, %al
callq 0x10f0
testl %ebx, %ebx
movl $0x0, %r12d
cmovgl %ebx, %r12d
cmpq %r13, %r12
movaps 0x10(%rsp), %xmm0
je 0x4b82
movss 0x14c080(%r14,%r13,4), %xmm1
movss %xmm1, 0x8(%rsp)
movss 0xc(%r15), %xmm1
xorps 0x2af3(%rip), %xmm1     # 0x7100
mulss %xmm0, %xmm1
movss 0x2ad3(%rip), %xmm0     # 0x70ec
callq 0x1140
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
jmp 0x45e2
movsd 0x2e95(%rip), %xmm1     # 0x74d0
addsd %xmm3, %xmm1
cvtsd2ss %xmm1, %xmm1
andps 0x2e66(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x46ea
leaq 0x2eb9(%rip), %rsi      # 0x7513
xorl %r13d, %r13d
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1170
movq 0x5985(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2e6d(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r12, %rdx
movb $0x1, %al
callq 0x10f0
testl %ebx, %ebx
movl $0x0, %r12d
cmovgl %ebx, %r12d
cmpq %r13, %r12
movaps 0x10(%rsp), %xmm0
je 0x4b82
movss 0x14c080(%r14,%r13,4), %xmm1
movss %xmm1, 0x8(%rsp)
movss 0xc(%r15), %xmm1
xorps 0x2a3c(%rip), %xmm1     # 0x7100
mulss %xmm0, %xmm1
movss 0x2a1c(%rip), %xmm0     # 0x70ec
callq 0x1140
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
jmp 0x4699
movss 0x29fe(%rip), %xmm1     # 0x70f0
addss %xmm0, %xmm1
andps 0x2db3(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x479d
leaq 0x2e12(%rip), %rsi      # 0x751f
xorl %r13d, %r13d
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1170
movq 0x58d2(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2dba(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r12, %rdx
movb $0x1, %al
callq 0x10f0
testl %ebx, %ebx
movl $0x0, %r12d
cmovgl %ebx, %r12d
cmpq %r13, %r12
movaps 0x10(%rsp), %xmm0
je 0x4b82
movss 0x14c080(%r14,%r13,4), %xmm1
movss %xmm1, 0x8(%rsp)
movss 0xc(%r15), %xmm1
xorps 0x2989(%rip), %xmm1     # 0x7100
mulss %xmm0, %xmm1
movss 0x2969(%rip), %xmm0     # 0x70ec
callq 0x1140
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
jmp 0x474c
movss 0x2d23(%rip), %xmm1     # 0x74c8
addss %xmm0, %xmm1
andps 0x2d00(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x4850
leaq 0x2d69(%rip), %rsi      # 0x7529
xorl %r13d, %r13d
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1170
movq 0x581f(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2d07(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r12, %rdx
movb $0x1, %al
callq 0x10f0
testl %ebx, %ebx
movl $0x0, %r12d
cmovgl %ebx, %r12d
cmpq %r13, %r12
movaps 0x10(%rsp), %xmm0
je 0x4b82
movss 0x14c080(%r14,%r13,4), %xmm1
movss %xmm1, 0x8(%rsp)
movss 0xc(%r15), %xmm1
xorps 0x28d6(%rip), %xmm1     # 0x7100
mulss %xmm0, %xmm1
movss 0x28b6(%rip), %xmm0     # 0x70ec
callq 0x1140
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
jmp 0x47ff
movss 0x289c(%rip), %xmm1     # 0x70f4
addss %xmm0, %xmm1
andps 0x2c4d(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x4903
leaq 0x2cc2(%rip), %rsi      # 0x7535
xorl %r13d, %r13d
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1170
movq 0x576c(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2c54(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r12, %rdx
movb $0x1, %al
callq 0x10f0
testl %ebx, %ebx
movl $0x0, %r12d
cmovgl %ebx, %r12d
cmpq %r13, %r12
movaps 0x10(%rsp), %xmm0
je 0x4b82
movss 0x14c080(%r14,%r13,4), %xmm1
movss %xmm1, 0x8(%rsp)
movss 0xc(%r15), %xmm1
xorps 0x2823(%rip), %xmm1     # 0x7100
mulss %xmm0, %xmm1
movss 0x2803(%rip), %xmm0     # 0x70ec
callq 0x1140
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
jmp 0x48b2
movsd 0x2bcd(%rip), %xmm1     # 0x74d8
addsd %xmm3, %xmm1
cvtsd2ss %xmm1, %xmm1
andps 0x2b96(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x49ba
leaq 0x2c15(%rip), %rsi      # 0x753f
xorl %r13d, %r13d
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1170
movq 0x56b5(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2b9d(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r12, %rdx
movb $0x1, %al
callq 0x10f0
testl %ebx, %ebx
movl $0x0, %r12d
cmovgl %ebx, %r12d
cmpq %r13, %r12
movaps 0x10(%rsp), %xmm0
je 0x4b82
movss 0x14c080(%r14,%r13,4), %xmm1
movss %xmm1, 0x8(%rsp)
movss 0xc(%r15), %xmm1
xorps 0x276c(%rip), %xmm1     # 0x7100
mulss %xmm0, %xmm1
movss 0x274c(%rip), %xmm0     # 0x70ec
callq 0x1140
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
jmp 0x4969
movss 0x2b0a(%rip), %xmm1     # 0x74cc
addss %xmm0, %xmm1
andps 0x2ae3(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x4a6d
leaq 0x2b6e(%rip), %rsi      # 0x754b
xorl %r13d, %r13d
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1170
movq 0x5602(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2aea(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r12, %rdx
movb $0x1, %al
callq 0x10f0
testl %ebx, %ebx
movl $0x0, %r12d
cmovgl %ebx, %r12d
cmpq %r13, %r12
movaps 0x10(%rsp), %xmm0
je 0x4b82
movss 0x14c080(%r14,%r13,4), %xmm1
movss %xmm1, 0x8(%rsp)
movss 0xc(%r15), %xmm1
xorps 0x26b9(%rip), %xmm1     # 0x7100
mulss %xmm0, %xmm1
movss 0x2699(%rip), %xmm0     # 0x70ec
callq 0x1140
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
jmp 0x4a1c
movss 0x2683(%rip), %xmm1     # 0x70f8
addss %xmm0, %xmm1
andps 0x2a30(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x4b20
leaq 0x2ac7(%rip), %rsi      # 0x7557
xorl %r13d, %r13d
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1170
movq 0x554f(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2a37(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r12, %rdx
movb $0x1, %al
callq 0x10f0
testl %ebx, %ebx
movl $0x0, %r12d
cmovgl %ebx, %r12d
cmpq %r13, %r12
movaps 0x10(%rsp), %xmm0
je 0x4b82
movss 0x14c080(%r14,%r13,4), %xmm1
movss %xmm1, 0x8(%rsp)
movss 0xc(%r15), %xmm1
xorps 0x2606(%rip), %xmm1     # 0x7100
mulss %xmm0, %xmm1
movss 0x25e6(%rip), %xmm0     # 0x70ec
callq 0x1140
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
jmp 0x4acf
leaq 0x29b9(%rip), %rsi      # 0x74e0
xorl %r12d, %r12d
leaq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x1170
movq 0x54b8(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2a17(%rip), %rsi      # 0x7561
movsd 0x8(%rsp), %xmm0
movq %r15, %rdx
movb $0x1, %al
callq 0x10f0
testl %ebx, %ebx
movl $0x0, %eax
cmovgl %ebx, %eax
cmpq %r12, %rax
je 0x4b82
movss 0x14c080(%r14,%r12,4), %xmm0
movss %xmm0, 0xf0(%rsp,%r12,4)
incq %r12
jmp 0x4b64
leaq 0x2a0f(%rip), %rsi      # 0x7598
leaq 0x20(%rsp), %rdi
callq 0x1150
movq %rax, %r14
leaq 0xf0(%rsp), %rdi
pushq $0x4
popq %rsi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x1190
movq %r14, %rdi
callq 0x1080
addq $0xa6130, %rsp          # imm = 0xA6130
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq