// File: /workspace/github_c_makefile_star2_O0/usgs[P]nshmp-haz-catalogs/src/agrid/adaptive/write_asum_to_file.c
// Function: write_asum_to_csvfile
void write_asum_to_csvfile(
    struct rates *seisr,
    char *fbasenm,
    struct catalog *catv,
    struct boundaries *boundR,
    float mag)
/*--------------------------------------------------------------------------*/  
{
  FILE *fpout;
  FILE *foutAscii;
  int nsrc, cnt;
  int iy, ix;
  float diffth=1e-1;
  char fileout[200];
  char fileoutAscii[200];
                                                                                
  // compute lon/lat array
  // get rate array and naming based on magnitude input values
  nsrc=seisr->nv;
  
  // Magnitudes
  if ( fabsf(mag-0.0)<diffth ) {
    sprintf(fileout,"%s_M0.csv", fbasenm);
    sprintf(fileoutAscii,"%s_M0.asc", fbasenm);

    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileout);
    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileoutAscii);

    fpout=fopen(fileout,"w");
    foutAscii = fopen(fileoutAscii, "w");

    for(cnt=0; cnt<nsrc; cnt++) {
      iy=cnt/boundR->nsx;
      ix=cnt-iy*boundR->nsx;
      fprintf(
        fpout,
        "%9.3f, %8.3f, GR, %12.6e \n",
        boundR->minlon+ix*boundR->dlon,
        boundR->maxlat-iy*boundR->dlat,
        seisr->asum[cnt]);

      fprintf(
        foutAscii,
        "%9.3f %8.3f %12.6e \n",
        boundR->minlon+ix*boundR->dlon,
        boundR->maxlat-iy*boundR->dlat,
        seisr->asum[cnt]);
    }

    fclose(fpout);
    fclose(foutAscii);
  } else {
    fprintf(stderr, "No csvfile write option for M~=0\n");
  }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movss %xmm0, -0x24(%rbp)
movss 0x3178(%rip), %xmm0     # 0x94a0
movss %xmm0, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movl 0x298100(%rax), %eax
movl %eax, -0x3c(%rbp)
movss -0x24(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm1
movaps 0x313b(%rip), %xmm0     # 0x9490
pand %xmm0, %xmm1
movss -0x4c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x655f
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x322b(%rip), %rsi      # 0x95a4
movb $0x0, %al
callq 0x1150
leaq -0x1f0(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x321c(%rip), %rsi      # 0x95ae
movb $0x0, %al
callq 0x1150
movq 0x5c58(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movss -0x24(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq -0x120(%rbp), %rdx
leaq 0x3138(%rip), %rsi      # 0x94f2
movb $0x1, %al
callq 0x10e0
movq 0x5c30(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movss -0x24(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq -0x1f0(%rbp), %rdx
leaq 0x3110(%rip), %rsi      # 0x94f2
movb $0x1, %al
callq 0x10e0
leaq -0x120(%rbp), %rdi
leaq 0x2204(%rip), %rsi      # 0x85fb
callq 0x1130
movq %rax, -0x30(%rbp)
leaq -0x1f0(%rbp), %rdi
leaq 0x21ed(%rip), %rsi      # 0x85fb
callq 0x1130
movq %rax, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x654b
movl -0x40(%rbp), %eax
movq -0x20(%rbp), %rcx
cltd
idivl (%rcx)
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
movl -0x44(%rbp), %ecx
movq -0x20(%rbp), %rdx
imull (%rdx), %ecx
subl %ecx, %eax
movl %eax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movss 0xc(%rax), %xmm1
cvtsi2ssl -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rax
movss 0x1c(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x20(%rbp), %rax
movss 0x18(%rax), %xmm2
cvtsi2ssl -0x44(%rbp), %xmm1
movq -0x20(%rbp), %rax
movss 0x20(%rax), %xmm3
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
mulss %xmm3, %xmm1
addss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x8(%rbp), %rax
movslq -0x40(%rbp), %rcx
movss 0x14c080(%rax,%rcx,4), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x30fc(%rip), %rsi      # 0x95b8
movb $0x3, %al
callq 0x10e0
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rax
movss 0xc(%rax), %xmm1
cvtsi2ssl -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rax
movss 0x1c(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x20(%rbp), %rax
movss 0x18(%rax), %xmm2
cvtsi2ssl -0x44(%rbp), %xmm1
movq -0x20(%rbp), %rax
movss 0x20(%rax), %xmm3
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
mulss %xmm3, %xmm1
addss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x8(%rbp), %rax
movslq -0x40(%rbp), %rcx
movss 0x14c080(%rax,%rcx,4), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x309d(%rip), %rsi      # 0x95d3
movb $0x3, %al
callq 0x10e0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x641e
movq -0x30(%rbp), %rdi
callq 0x1080
movq -0x38(%rbp), %rdi
callq 0x1080
jmp 0x6577
movq 0x5a92(%rip), %rax      # 0xbff8
movq (%rax), %rdi
leaq 0x3078(%rip), %rsi      # 0x95e8
movb $0x0, %al
callq 0x10e0
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq