// File: /workspace/github_c_makefile_star2_O3/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 0x2952(%rip), %xmm1     # 0x74b0
andps %xmm0, %xmm1
movss 0x2957(%rip), %xmm2     # 0x74c0
ucomiss %xmm1, %xmm2
movsd %xmm3, 0x8(%rsp)
jbe 0x4bd7
leaq 0x2965(%rip), %rsi      # 0x74e0
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x5467(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x294f(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r12, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x5143
addq $0x14c080, %r14         # imm = 0x14C080
shlq $0x2, %r15
leaq 0xf0(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1120
jmp 0x5143
movss 0x28e5(%rip), %xmm1     # 0x74c4
addss %xmm0, %xmm1
andps 0x28c6(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
movaps %xmm0, 0x10(%rsp)
jbe 0x4c89
leaq 0x2908(%rip), %rsi      # 0x7507
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x53e3(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x28cb(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x5143
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x24a7(%rip), %xmm1     # 0x7100
mulss 0x10(%rsp), %xmm1
movss 0x2485(%rip), %xmm0     # 0x70ec
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4c3b
jmp 0x5143
movsd 0x283f(%rip), %xmm1     # 0x74d0
addsd %xmm3, %xmm1
cvtsd2ss %xmm1, %xmm1
andps 0x2810(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x4d3a
leaq 0x2863(%rip), %rsi      # 0x7513
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x5332(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x281a(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x5143
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x23f6(%rip), %xmm1     # 0x7100
mulss 0x10(%rsp), %xmm1
movss 0x23d4(%rip), %xmm0     # 0x70ec
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4cec
jmp 0x5143
movss 0x23ae(%rip), %xmm1     # 0x70f0
addss %xmm0, %xmm1
andps 0x2763(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x4de7
leaq 0x27c2(%rip), %rsi      # 0x751f
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x5285(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x276d(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x5143
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x2349(%rip), %xmm1     # 0x7100
mulss 0x10(%rsp), %xmm1
movss 0x2327(%rip), %xmm0     # 0x70ec
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4d99
jmp 0x5143
movss 0x26d9(%rip), %xmm1     # 0x74c8
addss %xmm0, %xmm1
andps 0x26b6(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x4e94
leaq 0x271f(%rip), %rsi      # 0x7529
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x51d8(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x26c0(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x5143
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x229c(%rip), %xmm1     # 0x7100
mulss 0x10(%rsp), %xmm1
movss 0x227a(%rip), %xmm0     # 0x70ec
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4e46
jmp 0x5143
movss 0x2258(%rip), %xmm1     # 0x70f4
addss %xmm0, %xmm1
andps 0x2609(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x4f41
leaq 0x267e(%rip), %rsi      # 0x7535
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x512b(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2613(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x5143
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x21ef(%rip), %xmm1     # 0x7100
mulss 0x10(%rsp), %xmm1
movss 0x21cd(%rip), %xmm0     # 0x70ec
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4ef3
jmp 0x5143
movsd 0x258f(%rip), %xmm1     # 0x74d8
addsd %xmm3, %xmm1
cvtsd2ss %xmm1, %xmm1
andps 0x2558(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x4ff2
leaq 0x25d7(%rip), %rsi      # 0x753f
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x507a(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2562(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x5143
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x213e(%rip), %xmm1     # 0x7100
mulss 0x10(%rsp), %xmm1
movss 0x211c(%rip), %xmm0     # 0x70ec
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x4fa4
jmp 0x5143
movss 0x24d2(%rip), %xmm1     # 0x74cc
addss %xmm0, %xmm1
andps 0x24ab(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x509f
leaq 0x2536(%rip), %rsi      # 0x754b
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x4fcd(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x24b5(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x5143
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x2091(%rip), %xmm1     # 0x7100
mulss 0x10(%rsp), %xmm1
movss 0x206f(%rip), %xmm0     # 0x70ec
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x5051
jmp 0x5143
movss 0x2051(%rip), %xmm1     # 0x70f8
addss %xmm0, %xmm1
andps 0x23fe(%rip), %xmm1     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x5188
leaq 0x2495(%rip), %rsi      # 0x7557
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x4f20(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2408(%rip), %rsi      # 0x74ea
movsd 0x8(%rsp), %xmm0
movq %r13, %rdx
movb $0x1, %al
callq 0x1100
testl %r15d, %r15d
jle 0x5143
xorl %r13d, %r13d
movss 0x14c080(%r14,%r13,4), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r12), %xmm1
xorps 0x1fe8(%rip), %xmm1     # 0x7100
mulss 0x10(%rsp), %xmm1
movss 0x1fc6(%rip), %xmm0     # 0x70ec
callq 0x1150
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0xf0(%rsp,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x50fa
leaq 0x244e(%rip), %rsi      # 0x7598
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 0x2351(%rip), %rsi      # 0x74e0
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x1180
movq 0x4e53(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x23b2(%rip), %rsi      # 0x7561
jmp 0x4b9b