// File: /workspace/github_c_makefile_star2_O1/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, %r12
movq %rsi, %rdx
movq %rdi, %r14
movl 0x298100(%rdi), %r15d
movslq %r15d, %rbx
cvtss2sd %xmm0, %xmm3
movaps 0x2976(%rip), %xmm1     # 0x74a0
andps %xmm0, %xmm1
movss 0x297b(%rip), %xmm2     # 0x74b0
ucomiss %xmm1, %xmm2
movsd %xmm3, 0x8(%rsp)
jbe 0x4ba3
leaq 0x2989(%rip), %rsi      # 0x74d0
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x549b(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2973(%rip), %rsi      # 0x74da
movsd 0x8(%rsp), %xmm0
movq %r12, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x510f
addq $0x14c080, %r14         # imm = 0x14C080
shlq $0x2, %r15
leaq 0xf0(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1120
jmp 0x510f
movss 0x2909(%rip), %xmm1     # 0x74b4
addss %xmm0, %xmm1
andps 0x28ea(%rip), %xmm1     # 0x74a0
ucomiss %xmm1, %xmm2
movaps %xmm0, 0x10(%rsp)
jbe 0x4c55
leaq 0x292c(%rip), %rsi      # 0x74f7
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x5417(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x28ef(%rip), %rsi      # 0x74da
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x510f
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x24cb(%rip), %xmm1     # 0x70f0
mulss 0x10(%rsp), %xmm1
movss 0x24a9(%rip), %xmm0     # 0x70dc
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4c07
jmp 0x510f
movsd 0x2863(%rip), %xmm1     # 0x74c0
addsd %xmm3, %xmm1
cvtsd2ss %xmm1, %xmm1
andps 0x2834(%rip), %xmm1     # 0x74a0
ucomiss %xmm1, %xmm2
jbe 0x4d06
leaq 0x2887(%rip), %rsi      # 0x7503
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x5366(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x283e(%rip), %rsi      # 0x74da
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x510f
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x241a(%rip), %xmm1     # 0x70f0
mulss 0x10(%rsp), %xmm1
movss 0x23f8(%rip), %xmm0     # 0x70dc
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4cb8
jmp 0x510f
movss 0x23d2(%rip), %xmm1     # 0x70e0
addss %xmm0, %xmm1
andps 0x2787(%rip), %xmm1     # 0x74a0
ucomiss %xmm1, %xmm2
jbe 0x4db3
leaq 0x27e6(%rip), %rsi      # 0x750f
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x52b9(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2791(%rip), %rsi      # 0x74da
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x510f
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x236d(%rip), %xmm1     # 0x70f0
mulss 0x10(%rsp), %xmm1
movss 0x234b(%rip), %xmm0     # 0x70dc
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4d65
jmp 0x510f
movss 0x26fd(%rip), %xmm1     # 0x74b8
addss %xmm0, %xmm1
andps 0x26da(%rip), %xmm1     # 0x74a0
ucomiss %xmm1, %xmm2
jbe 0x4e60
leaq 0x2743(%rip), %rsi      # 0x7519
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x520c(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x26e4(%rip), %rsi      # 0x74da
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x510f
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x22c0(%rip), %xmm1     # 0x70f0
mulss 0x10(%rsp), %xmm1
movss 0x229e(%rip), %xmm0     # 0x70dc
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4e12
jmp 0x510f
movss 0x227c(%rip), %xmm1     # 0x70e4
addss %xmm0, %xmm1
andps 0x262d(%rip), %xmm1     # 0x74a0
ucomiss %xmm1, %xmm2
jbe 0x4f0d
leaq 0x26a2(%rip), %rsi      # 0x7525
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x515f(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2637(%rip), %rsi      # 0x74da
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x510f
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x2213(%rip), %xmm1     # 0x70f0
mulss 0x10(%rsp), %xmm1
movss 0x21f1(%rip), %xmm0     # 0x70dc
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4ebf
jmp 0x510f
movsd 0x25b3(%rip), %xmm1     # 0x74c8
addsd %xmm3, %xmm1
cvtsd2ss %xmm1, %xmm1
andps 0x257c(%rip), %xmm1     # 0x74a0
ucomiss %xmm1, %xmm2
jbe 0x4fbe
leaq 0x25fb(%rip), %rsi      # 0x752f
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x50ae(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2586(%rip), %rsi      # 0x74da
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x510f
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x2162(%rip), %xmm1     # 0x70f0
mulss 0x10(%rsp), %xmm1
movss 0x2140(%rip), %xmm0     # 0x70dc
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4f70
jmp 0x510f
movss 0x24f6(%rip), %xmm1     # 0x74bc
addss %xmm0, %xmm1
andps 0x24cf(%rip), %xmm1     # 0x74a0
ucomiss %xmm1, %xmm2
jbe 0x506b
leaq 0x255a(%rip), %rsi      # 0x753b
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x5001(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x24d9(%rip), %rsi      # 0x74da
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x510f
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x20b5(%rip), %xmm1     # 0x70f0
mulss 0x10(%rsp), %xmm1
movss 0x2093(%rip), %xmm0     # 0x70dc
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x501d
jmp 0x510f
movss 0x2075(%rip), %xmm1     # 0x70e8
addss %xmm0, %xmm1
andps 0x2422(%rip), %xmm1     # 0x74a0
ucomiss %xmm1, %xmm2
jbe 0x5154
leaq 0x24b9(%rip), %rsi      # 0x7547
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x4f54(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x242c(%rip), %rsi      # 0x74da
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x510f
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x200c(%rip), %xmm1     # 0x70f0
mulss 0x10(%rsp), %xmm1
movss 0x1fea(%rip), %xmm0     # 0x70dc
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x50c6
leaq 0x2472(%rip), %rsi      # 0x7588
leaq 0x20(%rsp), %rdi
callq 0x1160
movq %rax, %r14
leaq 0xf0(%rsp), %rdi
movl $0x4, %esi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x11a0
movq %r14, %rdi
callq 0x1080
addq $0xa6130, %rsp          # imm = 0xA6130
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x2375(%rip), %rsi      # 0x74d0
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x4e87(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x23d6(%rip), %rsi      # 0x7551
jmp 0x4b67