// File: lagoproject[P]arti/analysis/primaries.cc
// Function: main
int main (int argc, char *argv[]) {
  char nfi[256]; // filename container
  char nfg[256]; // geomagnetic effects file
  char *ifiname=NULL; // input
  char line[256];

  x = y = z = h = 0.;
  // reading arguments from command line
  for (int i=1;i<argc;i++) {
    char *tmparg=argv[i];
    if (*tmparg=='-') {
      switch (*(tmparg+1)) {
        case 'm':
          ianalysis=1;
          if (atof(argv[i+1])) {
            i++;
            resolution = atof(argv[i]);
          }
          break;
        case 'n':
          inorm = 1;
          if (atof(argv[i+1]) && atof(argv[i+2])) {
            i++;
            area=atof(argv[i]);
            i++;
            fluxTime=atof(argv[i]);
          }
          else {
            fprintf(stderr, " Error: for -n option you must provide detector area and flux time\n");
            Usage(argv[0]);
            break;
          }
          break;
        case 'v':
          iverbose++;
          break;
        case 'g':
          igeo=1;
          i++;
          snprintf(nfg,256,"%s",argv[i]);
          i++;
          cGeoC = atoi(argv[i]) - 1;
          if (!(cGeoC>1 && cGeoC<5)) {
            fprintf(stderr, " Error: for -g option you must provide file name and the selected rigidity column (3 to 5)\n");
            Usage(argv[0]);
            break;
          }
          break;
        case '?':
        default:
          Usage(argv[0]);
          break;
      }
    }
    else 
      ifiname=argv[i];
  }
  if (!ifiname) {
    fprintf(stderr, "\n Error: Missing filename\n\n");
    Usage(argv[0]);
  }
  int check = 0;
  int iGeoZ = 0;
  int iGeoA = 0;
  int iGeoN = 0;

  double rGeoZ = 6.;
  double rGeoA = 25.;
  int nGeoZ = int(90. / rGeoZ) + 1;
  int nGeoA = int(360. / rGeoA) + 1; 
  double gGeoC[nGeoZ][nGeoA];
  double g[5];
  if (igeo) {
    FILE *fg; 
    // reading geo file
    if((fg=fopen(nfg,"r")) == NULL) {
      fprintf(stderr, "\nError: Can't open geomagnetic file\n\n");
      Usage(argv[0]);
    }
    while(fgets(line,250,fg)) {
      if (line[0] == '#')
        continue;
      do { // read
        check=sscanf(line, "%le %le %le %le %le\n", &g[0], &g[1], &g[2], &g[3], &g[4]); 
      } while (check != 5);
      iGeoZ = int(g[0]/rGeoZ);
      iGeoA = int(g[1]/rGeoA);
      gGeoC[iGeoZ][iGeoA] = g[cGeoC];
      iGeoN++;
    }
  }
  if (iverbose && igeo)
    fprintf(stderr,"Read %d rigidity cut-off values from column %d of file '%s'\n",iGeoN, cGeoC+1, nfg);
  //open input
  snprintf(nfi,256,"%s",ifiname);
  Open(nfi);
  //open output
  char *ifile2;
  char ifile[256];
  ifile2=ifiname;
  //remove dirs
  if (strrchr(ifile2,'/')!=NULL) {
    ifile2=strrchr(ifile2,'/')+1;
  }
  snprintf(ifile, 256,"%s",ifile2);
  if (strrchr(ifile,'.')!=NULL) {
    if (strncmp(strrchr(ifile,'.'),".bz2",4)==0) { // remove .bz2 if present
      *(strrchr(ifile,'.'))='\0';
    }
  }
  if (strrchr(ifile,'.')!=NULL) {
    if (strncmp(strrchr(ifile,'.'),".dat",4)==0) { // remove .dat if present
      *(strrchr(ifile,'.'))='\0';
    }
  }
  // open output file (.bz2) via popen
  snprintf(nfi,256,"bzip2 -9z > %s.prg.bz2",ifile);
  if ((pri = popen(nfi,"w"))==NULL) {
    fprintf(stderr,"Failed to open compressed output file. Abort.\n");
    exit(1);
  }
  if (ianalysis) {
    fprintf(stderr, "Sorry, it is not yet implemented.\n");
    ianalysis=false;
    /*
    snprintf(nfi, 256, "%s.pri.hst", ifile);
    if ((hst = fopen(nfi,"w"))==NULL) {
      fprintf(stderr,"Failed to open pri.hst (primary energy histogram) file. Abort.\n");
      exit(1);
    }
    */
  }
  fprintf(pri, "# # # prg\n");
  if (igeo)
    fprintf(pri, "# # Geomagnetic effects were included: %d values were read from column %d of file %s\n", iGeoN, cGeoC+1, nfg);
  fprintf(pri, "# # This is the Primaries file including geomagnetic effects - ARTI     %s\n", VERSION);
  fprintf(pri, "# # Include an extra column (#11) indicating geomagnetic status: \n");
  fprintf(pri, "# # 0: not-allowed // 1: allowed\n");
  fprintf(pri, "# # 11 column format is:\n");
  fprintf(pri, "# # prm_Crk_id prm_energy prm_x0 prm_theta prm_phi ph_obs_lev el_obs_lev hd_obs_lev mu_obs_lev tot_obs_lev geo_status\n");
  if (ianalysis) {
    fprintf(hst, "# # # hst\n");
    if (igeo)
      fprintf(hst, "# # Geomagnetic effects were included: %d values were read from file %s\n", iGeoN, nfg);
    fprintf(hst, "# # This is the Histogram of secondary energy file - ARTI     %s\n", VERSION);
    fprintf(hst, "# # Logaritmic energy scale. Resolution used: %d bins per energy decade\n", int(resolution));
    if (inorm)
      fprintf(hst, "# # Number of particles are divided by detector area (%.4f m^2) and flux time (%.2f s)\n", area, fluxTime);
    fprintf(hst, "# # 14 column format is:\n");
    fprintf(hst, "# # p_in_bin(GeV) N_phot N_e+ N_e- N_mu+ N_mu- N_pi0 N_pi+ N_pi- N_n N_p N_pbar N_others Total_per_bin\n");
      //1=foton, 2=e+, 3=e-, 5=mu+, 6=mu-, 7=pi0, 8=pi+, 9=pi-, 13=n, 14=p, 15=bar-p, other
  }
  if (iverbose) {
    fprintf (stderr, "Verbosity level set to: %d.\n", iverbose);
    if (iverbose > 2) 
      fprintf (stderr, "verbosity %d: Send basic information to stderr\nverbosity %d: Discarded particles due to geomagnetic effect to stderr\nverbosity %d: Allowed particles to stdout.\n", iverbose, iverbose, iverbose);
    else if (iverbose > 1) 
      fprintf (stderr, "verbosity %d: Send basic information to stderr\nverbosity %d: Discarded particles due to geomagnetic effect to stderr\n", iverbose, iverbose);
    else
      fprintf (stderr, "verbosity %d: Send basic information to stderr\n", iverbose);
  }
  // stop talking, let's work
  double d[12];
  int nbin=12, nloge=0;
  int nlogd=0;
  nloge = int(log10(GeV2keV*maxPInGeV)*resolution);
  long int histoe[nloge][nbin];
  long int nid[nbin], nle[nloge];
  nlogd = int(log10(maxDInM)*resdist);
  long int histod[nlogd][nbin];
  long int nld[nlogd];
  double histode[nlogd][nbin];
  double nlde[nlogd];
  long int maxDerr = 0, maxEerr = 0;
  int prmId, prmX, prmZ, prmA;
  double prmEn, prmTh, prmPh;
  double prmMa, prmIm;
  double secp = 0.;
  bool prmGeo = true;
  int iprmGeo = 1;
  long int geoDisShw = 0, geoDisSec = 0;
  long int totpart=0, totbin = 0;
  int minbine=10000000, maxbine=0;
  int minbind=10000000, maxbind=0;
  for (int i=0; i<nbin; i++) {
    for (int j=0; j<nloge; j++) {
      histoe[j][i] = 0;
    }
    nid[i] = 0;
  }
  for (int j=0; j<nloge; j++)
    nle[j] = 0;

  long int lines = 0, ps = 0, shower_id = 0;
  while(fgets(line,250,fi)) {
    if (!(++lines % 10000))
      fprintf (stderr, "%12ld\r", lines);
    if (line[0] == '#') {  // comments? meta-data? for now, just skipping
      continue;
    }
    do { // read
      check=sscanf(line, "%lf %le %le %lf %lf %le %le %le %le %le\n", &d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7], &d[8], &d[9]);
    } while (check != 10);
    if (d[0]<1)
      continue;

    //checking for geomagnetic effects
    if (igeo) {
      prmId=d[0];
      prmGeo=true;
      iprmGeo=1;
      if (prmId>1) { // only check for charged particles (photons=1)
        prmEn=d[1];
        prmTh=d[3];
        //CORSIKA System: -180 to +180 , 0=N, +90=E, counterclockwise
        //MAGCOS  System: 0 to 360 , 0=N, +90=E, clockwise.
        //Wonderful...
        //So... if CRK>=0, MAGCOS=CORSIKA...
        if (d[4] >= 0.)
          prmPh=d[4];
        //...else, MAGCOS=360+CORSIKA (CRK < 0)
        else
          prmPh=360.+d[4];
        // primary Z and mass
        if (prmId==14) { // protons, special case
          prmA = 1;
          prmZ = 1;
        }
        else if (prmId>100) { // nuclei
          prmA = int(prmId/100.);
          prmZ = int(prmId - prmA * 100.);
        }
        prmX = -1;
        for (int i=0; i<masaN; i++)
          if (prmId==masaI[i])
            prmX = i;
        if (prmX < 0) {
          fprintf(stderr, " Error: Can't find primary. PrmId: %04d. Please check. \nLine: %s\n", prmId, line);
          exit(1);
        }
        prmMa=masas[prmX];
        prmIm = sqrt(prmEn*prmEn - prmMa*prmMa);
        iGeoZ = int(prmTh/rGeoZ);
        iGeoA = int(prmPh/rGeoA);
        if ((prmIm/prmZ) < gGeoC[iGeoZ][iGeoA]) {
          prmGeo = false;
          iprmGeo = 0;
          geoDisShw++;
        }
      }
    }
    do {
      // fprintf(pri, "# # prm_Crk_id prm_energy prm_x0 prm_theta prm_phi ph_obs_lev el_obs_lev hd_obs_lev mu_obs_lev tot_obs_lev geo_status\n");
      check=fprintf(pri, "%04d %+.5E %+.5E %+08.3lf %+08.3lf %+.5E %+.5E %+.5E %+.5E %+.5E %d\n", prmId, prmEn, d[2], prmTh, d[4], d[5], d[6], d[7], d[8], d[9], iprmGeo);
    } while (check<=0);
    totpart++;
  }
  // say goodbye
  cerr << "From " << totpart << " primaries, in " << lines << " lines, " << geoDisShw << " primaries were discarded" << endl;
  fprintf(pri, "# # Total primaries: %ld, Discarded primaries: %ld, Allowed primaries: %ld\n", totpart, geoDisShw, (totpart-geoDisShw));
  pclose(pri);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x668, %rsp            # imm = 0x668
movl $0x0, -0x1c(%rbp)
movl %edi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq $0x0, -0x238(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x4b64(%rip)     # 0x62c8
xorps %xmm0, %xmm0
movsd %xmm0, 0x4b51(%rip)     # 0x62c0
xorps %xmm0, %xmm0
movsd %xmm0, 0x4b3e(%rip)     # 0x62b8
xorps %xmm0, %xmm0
movsd %xmm0, 0x4b2b(%rip)     # 0x62b0
movl $0x1, -0x344(%rbp)
movl -0x344(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x1a5c
movq -0x28(%rbp), %rax
movslq -0x344(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x350(%rbp)
movq -0x350(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x1a30
movq -0x350(%rbp), %rax
movsbl 0x1(%rax), %eax
movl %eax, -0x648(%rbp)
subl $0x3f, %eax
je 0x1a1e
jmp 0x17e3
movl -0x648(%rbp), %eax
subl $0x67, %eax
je 0x1974
jmp 0x17f4
movl -0x648(%rbp), %eax
subl $0x6d, %eax
je 0x1822
jmp 0x1801
movl -0x648(%rbp), %eax
subl $0x6e, %eax
je 0x1882
jmp 0x180e
movl -0x648(%rbp), %eax
subl $0x76, %eax
je 0x1960
jmp 0x1a20
movl $0x1, 0x4a5c(%rip)      # 0x6288
movq -0x28(%rbp), %rax
movl -0x344(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10f0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1852
jp 0x1852
jmp 0x187d
movl -0x344(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x344(%rbp)
movq -0x28(%rbp), %rax
movslq -0x344(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10f0
movsd %xmm0, 0x489b(%rip)     # 0x6118
jmp 0x1a2e
movl $0x1, 0x4a00(%rip)      # 0x628c
movq -0x28(%rbp), %rax
movl -0x344(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10f0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x18b2
jp 0x18b2
jmp 0x1930
movq -0x28(%rbp), %rax
movl -0x344(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10f0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x18d8
jp 0x18d8
jmp 0x1930
movl -0x344(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x344(%rbp)
movq -0x28(%rbp), %rax
movslq -0x344(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10f0
movsd %xmm0, 0x49dd(%rip)     # 0x62e0
movl -0x344(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x344(%rbp)
movq -0x28(%rbp), %rax
movslq -0x344(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10f0
movsd %xmm0, 0x49ba(%rip)     # 0x62e8
jmp 0x195b
movq 0x4699(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
leaq 0x1ae9(%rip), %rsi      # 0x342a
movb $0x0, %al
callq 0x1110
movq -0x28(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x1510
jmp 0x1a2e
jmp 0x1a2e
movl 0x490e(%rip), %eax      # 0x6274
addl $0x1, %eax
movl %eax, 0x4905(%rip)      # 0x6274
jmp 0x1a2e
movl $0x1, 0x4912(%rip)      # 0x6290
movl -0x344(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x344(%rbp)
leaq -0x230(%rbp), %rdi
movq -0x28(%rbp), %rax
movslq -0x344(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movl $0x100, %esi            # imm = 0x100
leaq 0x1750(%rip), %rdx      # 0x30ff
movb $0x0, %al
callq 0x1150
movl -0x344(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x344(%rbp)
movq -0x28(%rbp), %rax
movslq -0x344(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1130
subl $0x1, %eax
movl %eax, 0x48f6(%rip)      # 0x62d8
cmpl $0x1, 0x48ef(%rip)      # 0x62d8
jle 0x19f4
cmpl $0x5, 0x48e6(%rip)      # 0x62d8
jl 0x1a1c
movq 0x45d5(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
leaq 0x1a69(%rip), %rsi      # 0x346e
movb $0x0, %al
callq 0x1110
movq -0x28(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x1510
jmp 0x1a2e
jmp 0x1a2e
jmp 0x1a20
movq -0x28(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x1510
jmp 0x1a46
movq -0x28(%rbp), %rax
movslq -0x344(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x238(%rbp)
jmp 0x1a48
movl -0x344(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x344(%rbp)
jmp 0x178f
cmpq $0x0, -0x238(%rbp)
jne 0x1a8c
movq 0x4563(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
leaq 0x1a53(%rip), %rsi      # 0x34ca
movb $0x0, %al
callq 0x1110
movq -0x28(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x1510
movl $0x0, -0x354(%rbp)
movl $0x0, -0x358(%rbp)
movl $0x0, -0x35c(%rbp)
movl $0x0, -0x360(%rbp)
movabsq $0x4018000000000000, %rax # imm = 0x4018000000000000
movq %rax, -0x368(%rbp)
movabsq $0x4039000000000000, %rax # imm = 0x4039000000000000
movq %rax, -0x370(%rbp)
movsd -0x368(%rbp), %xmm1
movsd 0x155a(%rip), %xmm0     # 0x3040
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
incl %eax
movl %eax, -0x374(%rbp)
movsd -0x370(%rbp), %xmm1
movsd 0x1542(%rip), %xmm0     # 0x3048
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
incl %eax
movl %eax, -0x378(%rbp)
movl -0x374(%rbp), %eax
movl %eax, %ecx
movl -0x378(%rbp), %eax
movq %rax, -0x658(%rbp)
movq %rsp, %rdx
movq %rdx, -0x380(%rbp)
movq %rcx, %rdx
imulq %rax, %rdx
leaq 0xf(,%rdx,8), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x650(%rbp)
movq %rdx, %rsp
movq %rcx, -0x388(%rbp)
movq %rax, -0x390(%rbp)
cmpl $0x0, 0x4723(%rip)      # 0x6290
je 0x1cd6
leaq -0x230(%rbp), %rdi
leaq 0x1581(%rip), %rsi      # 0x3102
callq 0x10d0
movq %rax, -0x3c8(%rbp)
cmpq $0x0, %rax
jne 0x1bb9
movq 0x4436(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
leaq 0x1942(%rip), %rsi      # 0x34e6
movb $0x0, %al
callq 0x1110
movq -0x28(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x1510
jmp 0x1bbb
leaq -0x340(%rbp), %rdi
movq -0x3c8(%rbp), %rdx
movl $0xfa, %esi
callq 0x1140
cmpq $0x0, %rax
je 0x1cd4
movsbl -0x340(%rbp), %eax
cmpl $0x23, %eax
jne 0x1beb
jmp 0x1bbb
jmp 0x1bed
leaq -0x340(%rbp), %rdi
leaq -0x3c0(%rbp), %rdx
leaq -0x3c0(%rbp), %rcx
addq $0x8, %rcx
leaq -0x3c0(%rbp), %r8
addq $0x10, %r8
leaq -0x3c0(%rbp), %r9
addq $0x18, %r9
leaq -0x3c0(%rbp), %rax
addq $0x20, %rax
leaq 0x1e66(%rip), %rsi      # 0x3a94
subq $0x10, %rsp
movq %rax, (%rsp)
movb $0x0, %al
callq 0x1090
addq $0x10, %rsp
movl %eax, -0x354(%rbp)
cmpl $0x5, -0x354(%rbp)
jne 0x1bed
movq -0x650(%rbp), %rax
movq -0x658(%rbp), %rdx
movsd -0x3c0(%rbp), %xmm0
divsd -0x368(%rbp), %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0x358(%rbp)
movsd -0x3b8(%rbp), %xmm0
divsd -0x370(%rbp), %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0x35c(%rbp)
movslq 0x463f(%rip), %rcx      # 0x62d8
movsd -0x3c0(%rbp,%rcx,8), %xmm0
movslq -0x358(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x35c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x360(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x360(%rbp)
jmp 0x1bbb
jmp 0x1cd6
cmpl $0x0, 0x4597(%rip)      # 0x6274
je 0x1d16
cmpl $0x0, 0x45aa(%rip)      # 0x6290
je 0x1d16
movq 0x42e1(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
movl -0x360(%rbp), %edx
movl 0x45da(%rip), %ecx      # 0x62d8
addl $0x1, %ecx
leaq -0x230(%rbp), %r8
leaq 0x17fd(%rip), %rsi      # 0x350c
movb $0x0, %al
callq 0x1110
leaq -0x130(%rbp), %rdi
movq -0x238(%rbp), %rcx
movl $0x100, %esi            # imm = 0x100
leaq 0x13cf(%rip), %rdx      # 0x30ff
movb $0x0, %al
callq 0x1150
leaq -0x130(%rbp), %rdi
callq 0x1400
movq -0x238(%rbp), %rax
movq %rax, -0x3d0(%rbp)
movq -0x3d0(%rbp), %rdi
movl $0x2f, %esi
callq 0x10c0
cmpq $0x0, %rax
je 0x1d84
movq -0x3d0(%rbp), %rdi
movl $0x2f, %esi
callq 0x10c0
addq $0x1, %rax
movq %rax, -0x3d0(%rbp)
leaq -0x4d0(%rbp), %rdi
movq -0x3d0(%rbp), %rcx
movl $0x100, %esi            # imm = 0x100
leaq 0x1361(%rip), %rdx      # 0x30ff
movb $0x0, %al
callq 0x1150
leaq -0x4d0(%rbp), %rdi
movl $0x2e, %esi
callq 0x10c0
cmpq $0x0, %rax
je 0x1dfc
leaq -0x4d0(%rbp), %rdi
movl $0x2e, %esi
callq 0x10c0
movq %rax, %rdi
leaq 0x1789(%rip), %rsi      # 0x3560
movl $0x4, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0x1dfa
leaq -0x4d0(%rbp), %rdi
movl $0x2e, %esi
callq 0x10c0
movb $0x0, (%rax)
jmp 0x1dfc
leaq -0x4d0(%rbp), %rdi
movl $0x2e, %esi
callq 0x10c0
cmpq $0x0, %rax
je 0x1e53
leaq -0x4d0(%rbp), %rdi
movl $0x2e, %esi
callq 0x10c0
movq %rax, %rdi
leaq 0x171b(%rip), %rsi      # 0x3549
movl $0x4, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0x1e51
leaq -0x4d0(%rbp), %rdi
movl $0x2e, %esi
callq 0x10c0
movb $0x0, (%rax)
jmp 0x1e53
leaq -0x130(%rbp), %rdi
leaq -0x4d0(%rbp), %rcx
movl $0x100, %esi            # imm = 0x100
leaq 0x16e1(%rip), %rdx      # 0x354e
movb $0x0, %al
callq 0x1150
leaq -0x130(%rbp), %rdi
leaq 0x16e3(%rip), %rsi      # 0x3565
callq 0x1030
movq %rax, 0x4412(%rip)      # 0x62a0
cmpq $0x0, %rax
jne 0x1eb6
movq 0x4135(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
leaq 0x16c2(%rip), %rsi      # 0x3567
movb $0x0, %al
callq 0x1110
movl $0x1, %edi
callq 0x10e0
cmpl $0x0, 0x43cb(%rip)      # 0x6288
je 0x1ee1
movq 0x410a(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
leaq 0x16c6(%rip), %rsi      # 0x3596
movb $0x0, %al
callq 0x1110
movl $0x0, 0x43a7(%rip)      # 0x6288
movq 0x43b8(%rip), %rdi      # 0x62a0
leaq 0x16ca(%rip), %rsi      # 0x35b9
movb $0x0, %al
callq 0x1110
cmpl $0x0, 0x4393(%rip)      # 0x6290
je 0x1f2a
movq 0x439a(%rip), %rdi      # 0x62a0
movl -0x360(%rbp), %edx
movl 0x43c6(%rip), %ecx      # 0x62d8
addl $0x1, %ecx
leaq -0x230(%rbp), %r8
leaq 0x16a1(%rip), %rsi      # 0x35c4
movb $0x0, %al
callq 0x1110
movq 0x436f(%rip), %rdi      # 0x62a0
leaq 0x16e2(%rip), %rsi      # 0x361a
leaq 0x1215(%rip), %rdx      # 0x3154
movb $0x0, %al
callq 0x1110
movq 0x4353(%rip), %rdi      # 0x62a0
leaq 0x1712(%rip), %rsi      # 0x3666
movb $0x0, %al
callq 0x1110
movq 0x433e(%rip), %rdi      # 0x62a0
leaq 0x1740(%rip), %rsi      # 0x36a9
movb $0x0, %al
callq 0x1110
movq 0x4329(%rip), %rdi      # 0x62a0
leaq 0x174d(%rip), %rsi      # 0x36cb
movb $0x0, %al
callq 0x1110
movq 0x4314(%rip), %rdi      # 0x62a0
leaq 0x1752(%rip), %rsi      # 0x36e5
movb $0x0, %al
callq 0x1110
cmpl $0x0, 0x42e7(%rip)      # 0x6288
je 0x2078
movq 0x42fa(%rip), %rdi      # 0x62a8
leaq 0x17a7(%rip), %rsi      # 0x375c
movb $0x0, %al
callq 0x1110
cmpl $0x0, 0x42cd(%rip)      # 0x6290
je 0x1fe7
movq 0x42dc(%rip), %rdi      # 0x62a8
movl -0x360(%rbp), %edx
leaq -0x230(%rbp), %rcx
leaq 0x1787(%rip), %rsi      # 0x3767
movb $0x0, %al
callq 0x1110
movq 0x42ba(%rip), %rdi      # 0x62a8
leaq 0x17bb(%rip), %rsi      # 0x37b0
leaq 0x1158(%rip), %rdx      # 0x3154
movb $0x0, %al
callq 0x1110
movq 0x429e(%rip), %rdi      # 0x62a8
cvttsd2si 0x4106(%rip), %edx # 0x6118
leaq 0x17d9(%rip), %rsi      # 0x37f2
movb $0x0, %al
callq 0x1110
cmpl $0x0, 0x4265(%rip)      # 0x628c
je 0x204e
movq 0x4278(%rip), %rdi      # 0x62a8
movsd 0x42a8(%rip), %xmm0     # 0x62e0
movsd 0x42a8(%rip), %xmm1     # 0x62e8
leaq 0x17f4(%rip), %rsi      # 0x383b
movb $0x2, %al
callq 0x1110
movq 0x4253(%rip), %rdi      # 0x62a8
leaq 0x1837(%rip), %rsi      # 0x3893
movb $0x0, %al
callq 0x1110
movq 0x423e(%rip), %rdi      # 0x62a8
leaq 0x183c(%rip), %rsi      # 0x38ad
movb $0x0, %al
callq 0x1110
cmpl $0x0, 0x41f5(%rip)      # 0x6274
je 0x212a
movq 0x3f44(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
movl 0x41df(%rip), %edx      # 0x6274
leaq 0x1879(%rip), %rsi      # 0x3915
movb $0x0, %al
callq 0x1110
cmpl $0x2, 0x41ca(%rip)      # 0x6274
jle 0x20d9
movq 0x3f1d(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
movl 0x41b8(%rip), %edx      # 0x6274
movl 0x41b2(%rip), %ecx      # 0x6274
movl 0x41ab(%rip), %r8d      # 0x6274
leaq 0x1862(%rip), %rsi      # 0x3932
movb $0x0, %al
callq 0x1110
jmp 0x2128
cmpl $0x1, 0x4194(%rip)      # 0x6274
jle 0x2108
movq 0x3ee7(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
movl 0x4182(%rip), %edx      # 0x6274
movl 0x417c(%rip), %ecx      # 0x6274
leaq 0x18d4(%rip), %rsi      # 0x39d3
movb $0x0, %al
callq 0x1110
jmp 0x2126
movq 0x3ec1(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
movl 0x415c(%rip), %edx      # 0x6274
leaq 0x192a(%rip), %rsi      # 0x3a49
movb $0x0, %al
callq 0x1110
jmp 0x2128
jmp 0x212a
movl $0xc, -0x534(%rbp)
movl $0x0, -0x538(%rbp)
movl $0x0, -0x53c(%rbp)
movsd 0x3f90(%rip), %xmm0     # 0x60e0
movsd 0x3f98(%rip), %xmm1     # 0x60f0
mulsd %xmm1, %xmm0
callq 0x2970
movsd 0x3faf(%rip), %xmm1     # 0x6118
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x538(%rbp)
movl -0x538(%rbp), %eax
movl %eax, %ecx
movl -0x534(%rbp), %eax
movq %rax, -0x678(%rbp)
movq %rcx, %rdx
imulq %rax, %rdx
leaq 0xf(,%rdx,8), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x670(%rbp)
movq %rdx, %rsp
movq %rcx, -0x548(%rbp)
movq %rax, -0x550(%rbp)
movl -0x534(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x668(%rbp)
movq %rcx, %rsp
movq %rax, -0x558(%rbp)
movl -0x538(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x660(%rbp)
movq %rcx, %rsp
movq %rax, -0x560(%rbp)
movsd 0x3ee9(%rip), %xmm0     # 0x6100
callq 0x2970
mulsd 0x3eec(%rip), %xmm0     # 0x6110
cvttsd2si %xmm0, %eax
movl %eax, -0x53c(%rbp)
movl -0x53c(%rbp), %eax
movl %eax, %ecx
movl -0x534(%rbp), %eax
movq %rcx, -0x568(%rbp)
movq %rax, -0x570(%rbp)
movl -0x53c(%rbp), %eax
movq %rax, -0x578(%rbp)
movl -0x53c(%rbp), %eax
movl %eax, %ecx
movl -0x534(%rbp), %eax
movq %rcx, -0x580(%rbp)
movq %rax, -0x588(%rbp)
movl -0x53c(%rbp), %eax
movq %rax, -0x590(%rbp)
movq $0x0, -0x598(%rbp)
movq $0x0, -0x5a0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x5e0(%rbp)
movb $0x1, -0x5e1(%rbp)
movl $0x1, -0x5e8(%rbp)
movq $0x0, -0x5f0(%rbp)
movq $0x0, -0x5f8(%rbp)
movq $0x0, -0x600(%rbp)
movq $0x0, -0x608(%rbp)
movl $0x989680, -0x60c(%rbp) # imm = 0x989680
movl $0x0, -0x610(%rbp)
movl $0x989680, -0x614(%rbp) # imm = 0x989680
movl $0x0, -0x618(%rbp)
movl $0x0, -0x61c(%rbp)
movl -0x61c(%rbp), %eax
cmpl -0x534(%rbp), %eax
jge 0x23a4
movl $0x0, -0x620(%rbp)
movl -0x620(%rbp), %eax
cmpl -0x538(%rbp), %eax
jge 0x237a
movq -0x670(%rbp), %rax
movq -0x678(%rbp), %rdx
movslq -0x620(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x61c(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x620(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x620(%rbp)
jmp 0x232c
movq -0x668(%rbp), %rax
movslq -0x61c(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x61c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x61c(%rbp)
jmp 0x2310
movl $0x0, -0x624(%rbp)
movl -0x624(%rbp), %eax
cmpl -0x538(%rbp), %eax
jge 0x23e3
movq -0x660(%rbp), %rax
movslq -0x624(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x624(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x624(%rbp)
jmp 0x23ae
movq $0x0, -0x630(%rbp)
movq $0x0, -0x638(%rbp)
movq $0x0, -0x640(%rbp)
leaq -0x340(%rbp), %rdi
movq 0x3e86(%rip), %rdx      # 0x6298
movl $0xfa, %esi
callq 0x1140
cmpq $0x0, %rax
je 0x289b
movq -0x630(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x630(%rbp)
movl $0x2710, %ecx           # imm = 0x2710
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x2467
movq 0x3b81(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
movq -0x630(%rbp), %rdx
leaq 0x1619(%rip), %rsi      # 0x3a79
movb $0x0, %al
callq 0x1110
movsbl -0x340(%rbp), %eax
cmpl $0x23, %eax
jne 0x2475
jmp 0x2404
jmp 0x2477
leaq -0x340(%rbp), %rdi
leaq -0x530(%rbp), %rdx
leaq -0x530(%rbp), %rcx
addq $0x8, %rcx
leaq -0x530(%rbp), %r8
addq $0x10, %r8
leaq -0x530(%rbp), %r9
addq $0x18, %r9
leaq -0x530(%rbp), %r15
addq $0x20, %r15
leaq -0x530(%rbp), %r14
addq $0x28, %r14
leaq -0x530(%rbp), %rbx
addq $0x30, %rbx
leaq -0x530(%rbp), %r11
addq $0x38, %r11
leaq -0x530(%rbp), %r10
addq $0x40, %r10
leaq -0x530(%rbp), %rax
addq $0x48, %rax
leaq 0x1591(%rip), %rsi      # 0x3a80
subq $0x30, %rsp
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movb $0x0, %al
callq 0x1090
addq $0x30, %rsp
movl %eax, -0x354(%rbp)
cmpl $0xa, -0x354(%rbp)
jne 0x2477
movsd 0xb02(%rip), %xmm0      # 0x3038
ucomisd -0x530(%rbp), %xmm0
jbe 0x2545
jmp 0x2404
cmpl $0x0, 0x3d44(%rip)      # 0x6290
je 0x27f7
cvttsd2si -0x530(%rbp), %eax
movl %eax, -0x5a4(%rbp)
movb $0x1, -0x5e1(%rbp)
movl $0x1, -0x5e8(%rbp)
cmpl $0x1, -0x5a4(%rbp)
jle 0x27f5
movsd -0x528(%rbp), %xmm0
movsd %xmm0, -0x5b8(%rbp)
movsd -0x518(%rbp), %xmm0
movsd %xmm0, -0x5c0(%rbp)
movsd -0x510(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x25c1
movsd -0x510(%rbp), %xmm0
movsd %xmm0, -0x5c8(%rbp)
jmp 0x25d9
movsd 0xa7f(%rip), %xmm0      # 0x3048
addsd -0x510(%rbp), %xmm0
movsd %xmm0, -0x5c8(%rbp)
cmpl $0xe, -0x5a4(%rbp)
jne 0x25f8
movl $0x1, -0x5b0(%rbp)
movl $0x1, -0x5ac(%rbp)
jmp 0x2662
cmpl $0x64, -0x5a4(%rbp)
jle 0x2660
cvtsi2sdl -0x5a4(%rbp), %xmm0
movsd 0xa3f(%rip), %xmm1      # 0x3050
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x5b0(%rbp)
cvtsi2sdl -0x5a4(%rbp), %xmm1
cvtsi2sdl -0x5b0(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0xa02(%rip), %xmm2      # 0x3050
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x5ac(%rbp)
jmp 0x2662
movl $0xffffffff, -0x5a8(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x644(%rbp)
cmpl $0x1b, -0x644(%rbp)
jge 0x26b7
movl -0x5a4(%rbp), %eax
movslq -0x644(%rbp), %rdx
leaq 0x3a8d(%rip), %rcx      # 0x6120
cmpl (%rcx,%rdx,4), %eax
jne 0x26a4
movl -0x644(%rbp), %eax
movl %eax, -0x5a8(%rbp)
jmp 0x26a6
movl -0x644(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x644(%rbp)
jmp 0x2676
cmpl $0x0, -0x5a8(%rbp)
jge 0x26ef
movq 0x3909(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
movl -0x5a4(%rbp), %edx
leaq -0x340(%rbp), %rcx
leaq 0x13cb(%rip), %rsi      # 0x3aa9
movb $0x0, %al
callq 0x1110
movl $0x1, %edi
callq 0x10e0
movslq -0x5a8(%rbp), %rcx
leaq 0x3a93(%rip), %rax      # 0x6190
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x5d0(%rbp)
movsd -0x5b8(%rbp), %xmm0
movsd -0x5b8(%rbp), %xmm2
movsd -0x5d0(%rbp), %xmm1
mulsd -0x5d0(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x1060
movq -0x658(%rbp), %rdx
movq -0x650(%rbp), %rax
movsd %xmm0, -0x5d8(%rbp)
movsd -0x5c0(%rbp), %xmm0
divsd -0x368(%rbp), %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0x358(%rbp)
movsd -0x5c8(%rbp), %xmm0
divsd -0x370(%rbp), %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0x35c(%rbp)
movsd -0x5d8(%rbp), %xmm1
cvtsi2sdl -0x5ac(%rbp), %xmm0
divsd %xmm0, %xmm1
movslq -0x358(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x35c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x27f3
movb $0x0, -0x5e1(%rbp)
movl $0x0, -0x5e8(%rbp)
movq -0x5f0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x5f0(%rbp)
jmp 0x27f5
jmp 0x27f7
jmp 0x27f9
movq 0x3aa0(%rip), %rdi      # 0x62a0
movl -0x5a4(%rbp), %edx
movsd -0x5b8(%rbp), %xmm0
movsd -0x520(%rbp), %xmm1
movsd -0x5c0(%rbp), %xmm2
movsd -0x510(%rbp), %xmm3
movsd -0x508(%rbp), %xmm4
movsd -0x500(%rbp), %xmm5
movsd -0x4f8(%rbp), %xmm6
movsd -0x4f0(%rbp), %xmm7
movsd -0x4e8(%rbp), %xmm8
movl -0x5e8(%rbp), %ecx
leaq 0x128f(%rip), %rsi      # 0x3aeb
subq $0x10, %rsp
movsd %xmm8, (%rsp)
movb $0x8, %al
callq 0x1110
addq $0x10, %rsp
movl %eax, -0x354(%rbp)
cmpl $0x0, -0x354(%rbp)
jle 0x27f9
movq -0x600(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x600(%rbp)
jmp 0x2404
movq 0x374e(%rip), %rdi      # 0x5ff0
leaq 0x1287(%rip), %rsi      # 0x3b30
callq 0x10a0
movq %rax, %rdi
movq -0x600(%rbp), %rsi
callq 0x1170
movq %rax, %rdi
leaq 0x126f(%rip), %rsi      # 0x3b36
callq 0x10a0
movq %rax, %rdi
movq -0x630(%rbp), %rsi
callq 0x1170
movq %rax, %rdi
leaq 0x1261(%rip), %rsi      # 0x3b46
callq 0x10a0
movq %rax, %rdi
movq -0x5f0(%rbp), %rsi
callq 0x1170
movq %rax, %rdi
leaq 0x124c(%rip), %rsi      # 0x3b4f
callq 0x10a0
movq %rax, %rdi
movq 0x369e(%rip), %rsi      # 0x5fb0
callq 0x10b0
movq 0x3982(%rip), %rdi      # 0x62a0
movq -0x600(%rbp), %rdx
movq -0x5f0(%rbp), %rcx
movq -0x600(%rbp), %r8
subq -0x5f0(%rbp), %r8
leaq 0x1228(%rip), %rsi      # 0x3b69
movb $0x0, %al
callq 0x1110
movq 0x3951(%rip), %rdi      # 0x62a0
callq 0x1100
movq -0x380(%rbp), %rax
movq %rax, %rsp
movl -0x1c(%rbp), %eax
leaq -0x18(%rbp), %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)