// File: /workspace/github_c_makefile_star2_O0/mohamedamjad[P]UBLOXlib/src/main.c
// Function: main
int main(int argc, char *argv[]){
  int opt;
  short unsigned int generate_report = 0;
  short unsigned int generate_charts = 0;
  char *input_file_name, *output_file_name, *output_ubx_purified_file_name;

  while ((opt = getopt(argc, argv, "grvm:hi:o:")) != -1) {
    switch (opt) {
      case 'i':
        input_file_name = (char*)malloc(strlen(optarg));
        strncpy( input_file_name, optarg, strlen(optarg));
        printf("Input file: %s\n", input_file_name);
        break;
      case 'm':
        printf("Looking for a specific µbx message: YES");
        break;
      case 'o':
        output_file_name = (char*) malloc(strlen(optarg));
        output_ubx_purified_file_name = (char*) malloc(strlen(optarg)+4);
        strncpy( output_file_name, optarg, strlen(optarg));
        strncpy( output_ubx_purified_file_name, optarg, strlen(optarg));
        strncpy( output_ubx_purified_file_name, "ubx_", 4);
        printf("Output plain text file: %s\n", output_file_name);
        printf("Output purified UBX file: %s\n", output_ubx_purified_file_name);
        break;
      case 'h':
        displayHelp();
        break;
      case 'v':
        printf("µBlox Lib version 0.0.1\n");
        break;
      case 'r':
        printf("Generate detailed report: YES\n");
        generate_report = 1;
        break;
      case 'g':
        printf("Plot charts: YES\n");
        generate_charts = 1;
        break;
      default:
        fprintf(stderr, "Usage: %s -i input_file -o output_file [-h]\n",
                argv[0]);
        displayHelp();
        exit(EXIT_FAILURE);
    }
  }


  FILE *ubx_file;
  FILE *output_file;
  FILE *output_ubx_purified_file;
  int length=0;
  ubx_message ubx_msg;
  //double e_square, N, x, y, z;
  int longitude, latitude, height, hMSL, hAcc, vAcc, iToW_01_02,
      iToW_01_21, year, month, day, hour, min, sec, valid_01_21, tAcc, nano,
      iToW_02_10, week_number, numSV, reserved1, sv, mesQI, cno, lli,
      iToW_01_20, fToW, leap_seconds, validity_flag, freqID, gnssID, locktime,
      prStdev, cpStdev, doStdev, recStat;
  unsigned char trkStat;
  double cpMes, prMes, rcvTow;
  float doMes;
  long file_pos;

  ubx_file = fopen(input_file_name, "rb");
  output_file = fopen( output_file_name, "wa");
  output_ubx_purified_file = fopen( output_ubx_purified_file_name, "wba");
  
  if(!ubx_file){
    printf("Probleme occured when I tried to open the UBLOX file\n");
    return 1;
  }
  while(fread(&ubx_msg.header[0],sizeof(unsigned char),1,ubx_file)){
    //fread(&ubx_msg.header[0],sizeof(unsigned char),1,ubx_file);
    if (ubx_msg.header[0]!=0xb5) continue;
    file_pos = ftell(ubx_file);
    fread(&ubx_msg.header[1],sizeof(unsigned char),1,ubx_file);
    if (ubx_msg.header[1]!=0x62){
        fseek(ubx_file, file_pos, SEEK_SET);
   	continue;
    }
    
    fread(&ubx_msg.message_class,sizeof(unsigned char),4,ubx_file);
    if( (ubx_msg.message_class != 0x01 || ubx_msg.message_id != 0x02) && (ubx_msg.message_class != 0x01 || ubx_msg.message_id != 0x21) && (ubx_msg.message_class != 0x02 || ubx_msg.message_id != 0x10) && (ubx_msg.message_class != 0x01 || ubx_msg.message_id != 0x20) && (ubx_msg.message_class != 0x02 || ubx_msg.message_id != 0x15)){
        fseek(ubx_file, file_pos, SEEK_SET);
    	continue;
    }

    length = (ubx_msg.message_length[1]<<8)|ubx_msg.message_length[0];
    if(length > MAX_PAYLOAD_SIZE){
        fseek(ubx_file, file_pos, SEEK_SET);
        continue;
    }
    fread(&ubx_msg.payload,sizeof(unsigned char),length,ubx_file);
    fread(&ubx_msg.checksum_A,sizeof(unsigned char),1,ubx_file);
    fread(&ubx_msg.checksum_B,sizeof(unsigned char),1,ubx_file);

    if(getCompleteChecksum(ubx_msg) == 1){
	fseek(ubx_file, file_pos, SEEK_SET);
	continue;
    }

    /////////////////////////////////////////////////////////////////////////
    //iToW_01_21 = (signed long)
    if((ubx_msg.message_class == 0x01 && ubx_msg.message_id == 0x21)){
        //printf("message de type 0x01 0x21\n");
        iToW_01_21 = (signed long)((ubx_msg.payload[3]<<24)|(ubx_msg.payload[2]<<16)|(ubx_msg.payload[1]<<8)|ubx_msg.payload[0]);
        tAcc = (signed long)((ubx_msg.payload[7]<<24)|(ubx_msg.payload[6]<<16)|(ubx_msg.payload[5]<<8)|ubx_msg.payload[4]);
        nano = (signed long)((ubx_msg.payload[11]<<24)|(ubx_msg.payload[10]<<16)|(ubx_msg.payload[9]<<8)|ubx_msg.payload[8]);
        year = ((ubx_msg.payload[13]<<8)|ubx_msg.payload[12]);
        month = ubx_msg.payload[14];
        day = ubx_msg.payload[15];
        hour = ubx_msg.payload[16];
        min = ubx_msg.payload[17];
        sec = ubx_msg.payload[18];
        valid_01_21 = ubx_msg.payload[19];
        fprintf(output_file, "NAV_TIMEUTC,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", iToW_01_21, tAcc, nano, year, month, day, hour, min, sec, valid_01_21);
        fwrite( &ubx_msg, sizeof(unsigned char), 6, output_ubx_purified_file);
        fwrite( ubx_msg.payload, sizeof(unsigned char), 20, output_ubx_purified_file);
        fwrite( &(ubx_msg.checksum_A), sizeof(unsigned char), 1, output_ubx_purified_file);
        fwrite( &(ubx_msg.checksum_B), sizeof(unsigned char), 1, output_ubx_purified_file);

        
    }
    /////////////////////////////////////////////////////////////////////////

    else if(ubx_msg.message_class == 0x01 && ubx_msg.message_id == 0x02){
	/////////////////////////////////////////////////////////////////////////
	// Sortir la valeur du GPS millisecondtime of week
	iToW_01_02 = (signed long)((ubx_msg.payload[3]<<24)|(ubx_msg.payload[2]<<16)|(ubx_msg.payload[1]<<8)|ubx_msg.payload[0]);
	longitude = (signed long)((ubx_msg.payload[7]<<24)|(ubx_msg.payload[6]<<16)|(ubx_msg.payload[5]<<8)|ubx_msg.payload[4]);
	latitude = (signed long)((ubx_msg.payload[11]<<24)|(ubx_msg.payload[10]<<16)|(ubx_msg.payload[9]<<8)|ubx_msg.payload[8]);
	height = (signed long)((ubx_msg.payload[15]<<24)|(ubx_msg.payload[14]<<16)|(ubx_msg.payload[13]<<8)|ubx_msg.payload[12]);
	hMSL = (signed long)((ubx_msg.payload[19]<<24)|(ubx_msg.payload[18]<<16)|(ubx_msg.payload[17]<<8)|ubx_msg.payload[16]);
	hAcc = (signed long)((ubx_msg.payload[23]<<24)|(ubx_msg.payload[22]<<16)|(ubx_msg.payload[21]<<8)|ubx_msg.payload[20]);
	vAcc = (signed long)((ubx_msg.payload[27]<<24)|(ubx_msg.payload[26]<<16)|(ubx_msg.payload[25]<<8)|ubx_msg.payload[24]);

	// Convertir en coordonnées cartésiennes:
	//e_square = (double)(2.0*f_WGS84-f_WGS84*f_WGS84);
	//printf("\ne2 = %f\n", e_square);
	//printf("\nlatitude double = %f\n", (double)latitude);
	//N = (double)(a_WGS84/sqrt(1.0 - e_square * sin(PI*(double)latitude*1e-7/180.0)*sin(PI*(double)latitude*1e-7/180.0)));

	//x = (N + (double)h*1e-3)*cos(PI*(double)longitude*1e-7/180.0)*cos(PI*(double)latitude*1e-7/180.0);
	//y = (N + (double)h*1e-3)*sin(PI*(double)longitude*1e-7/180.0)*cos(PI*(double)latitude*1e-7/180.0);
	//z = (N * (double)(1.0-e_square) + (double)h*1e-3)*sin(PI*(double)latitude*1e-7/180.0);
	//printf("%de-7 %de-7 %d\n",longitude,latitude,h);
	//printf("%f %f %f %d %d\n",x,y,z,hAcc,vAcc);
	fprintf(output_file, "NAV_POSLLH,%d,%d,%d,%d,%d,%d,%d\n",iToW_01_02,longitude,latitude,height,hMSL,hAcc,vAcc);
	//////////////////////////////////////////////////////////////////////////
    }
    else if (ubx_msg.message_class == 0x02 && ubx_msg.message_id == 0x10){
        iToW_02_10 = (signed long)((ubx_msg.payload[3]<<24)|(ubx_msg.payload[2]<<16)|(ubx_msg.payload[1]<<8)|ubx_msg.payload[0]);
        week_number = ((ubx_msg.payload[5]<<8)|ubx_msg.payload[4]);
        numSV = ubx_msg.payload[6];
        reserved1 = ubx_msg.payload[7];
        //fprintf(output_file, "RXM_RAW %d %d %d %d\n", iToW_02_10, week_number, numSV, reserved1);
        for(int j = 0; j<numSV; j++){
            //cpMes = ((ubx_msg.payload[15+j*24]<<56)|(ubx_msg.payload[14+j*24]<<48)|(ubx_msg.payload[13+j*24]<<40)|(ubx_msg.payload[12+j*24]<<32)|(ubx_msg.payload[11+j*24]<<24)|(ubx_msg.payload[10+j*24]<<16)|(ubx_msg.payload[9+j*24]<<8)|ubx_msg.payload[8+j*24]);
            memcpy( &cpMes, ubx_msg.payload+8+j*24, sizeof(double));
            memcpy( &prMes, ubx_msg.payload+16+j*24, sizeof(double));
            memcpy(&doMes, ubx_msg.payload+24+j*24, sizeof(float));
            sv = ubx_msg.payload[28+j*24];
            mesQI = ubx_msg.payload[29+j*24];
            cno = ubx_msg.payload[30+j*24];
            lli = ubx_msg.payload[31+j*24];
            fprintf(output_file,"RXM_RAW,%d,%d,%d,%d,%.3f,%.3f,%.3f,%d,%d,%d,%d\n", iToW_02_10, week_number, numSV, reserved1, cpMes, prMes, doMes, sv, mesQI, cno, lli);
        }
        fwrite( &ubx_msg, sizeof(unsigned char), 6 + 8, output_ubx_purified_file);
        fwrite (ubx_msg.payload + 8 , sizeof(unsigned char), 24*numSV, output_ubx_purified_file);
        fwrite( &(ubx_msg.checksum_A) , sizeof(unsigned char), 2, output_ubx_purified_file);


    }

    /////////////////////////////////////////////////////////////////////////////
    else if (ubx_msg.message_class == 0x02 && ubx_msg.message_id == 0x15){
        memcpy( &rcvTow, ubx_msg.payload, sizeof(double));
        week_number = ((ubx_msg.payload[9]<<8)|ubx_msg.payload[8]);
        leap_seconds = *((char*) ubx_msg.payload+10);
        numSV = ubx_msg.payload[11];
        recStat = ubx_msg.payload[12];
        //fprintf(output_file, "RXM_RAW %d %d %d %d\n", iToW_02_10, week_number, numSV, reserved1);
        for(int j = 0; j<numSV; j++){
            //cpMes = ((ubx_msg.payload[15+j*24]<<56)|(ubx_msg.payload[14+j*24]<<48)|(ubx_msg.payload[13+j*24]<<40)|(ubx_msg.payload[12+j*24]<<32)|(ubx_msg.payload[11+j*24]<<24)|(ubx_msg.payload[10+j*24]<<16)|(ubx_msg.payload[9+j*24]<<8)|ubx_msg.payload[8+j*24]);
            memcpy( &prMes, ubx_msg.payload+16+j*32, sizeof(double));
            memcpy( &cpMes, ubx_msg.payload+24+j*32, sizeof(double));
            memcpy(&doMes, ubx_msg.payload+32+j*32, sizeof(float));
            gnssID = ubx_msg.payload[36+j*32];
            sv = ubx_msg.payload[37+j*32];
            freqID = ubx_msg.payload[39+j*32];
            locktime = ((ubx_msg.payload[41+j*32]<<8)|ubx_msg.payload[40+j*32]);
            cno = ubx_msg.payload[42+j*32];
            prStdev = ubx_msg.payload[43+j*32];
            cpStdev = ubx_msg.payload[44+j*32];
            doStdev = ubx_msg.payload[45+j*32];
            trkStat = ubx_msg.payload[46+j*32];
            fprintf(output_file,"RXM_RAWX,%.9f,%d,%d,%d,%d,%.3f,%.3f,%.3f,%d,%d,%d,%d,%d,%.2f,%.3f,%.3f,%2X\n", rcvTow, week_number, leap_seconds, numSV, recStat, prMes, cpMes, doMes, gnssID, sv, freqID, locktime, cno, (1<<(prStdev & 0x0f))/100.0, 0.004*cpStdev, (1<<(doStdev & 0x0f))/500.0, trkStat);
        }
        fwrite( &ubx_msg, sizeof(unsigned char), 6 + 8, output_ubx_purified_file);
        fwrite (ubx_msg.payload + 8 , sizeof(unsigned char), 32*numSV, output_ubx_purified_file);
        fwrite( &(ubx_msg.checksum_A) , sizeof(unsigned char), 2, output_ubx_purified_file);

    }

    /////////////////////////////////////////////////////////////////////////////
    else if (ubx_msg.message_class == 0x01 && ubx_msg.message_id == 0x20){
        iToW_01_20    = (signed long)((ubx_msg.payload[3]<<24)|(ubx_msg.payload[2]<<16)|(ubx_msg.payload[1]<<8)|ubx_msg.payload[0]);
        fToW          = (signed long)((ubx_msg.payload[7]<<24)|(ubx_msg.payload[6]<<16)|(ubx_msg.payload[5]<<8)|ubx_msg.payload[4]);
        week_number   = ((ubx_msg.payload[9]<<8)|ubx_msg.payload[8]);
        leap_seconds  = ubx_msg.payload[10];
        validity_flag = ubx_msg.payload[11];
        tAcc          = (signed long)((ubx_msg.payload[15]<<24)|(ubx_msg.payload[14]<<16)|(ubx_msg.payload[13]<<8)|ubx_msg.payload[12]);
        fprintf(output_file, "NAV_TIMEGPS %d %d %d %d %d %d\n", iToW_01_20, fToW, week_number, leap_seconds, validity_flag, tAcc);
    }
  }
  if(generate_report == 1){
    printf("ANALYSIS REPORT:\n");
  }
  if(generate_charts == 1){
    gnuplot_ctrl * ptr_plot;
    ptr_plot = gnuplot_init();
    
    gnuplot_setstyle(ptr_plot, "lines");
    gnuplot_set_xlabel(ptr_plot, "epochs");
    gnuplot_set_ylabel(ptr_plot, "clock accuracy estimation in ns");
        gnuplot_cmd(ptr_plot, "plot sin(x)");

    gnuplot_cmd(ptr_plot, "set term png");
    gnuplot_cmd(ptr_plot, "set output \"out.png\"");
    gnuplot_cmd(ptr_plot, "replot");
    gnuplot_cmd(ptr_plot, "set term x11");
    gnuplot_cmd(ptr_plot, "plot sin(x)");
    
    gnuplot_close(ptr_plot);
  }
  fclose(ubx_file);
  fclose(output_file);
  fclose(output_ubx_purified_file);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x948, %rsp            # imm = 0x948
movl $0x0, -0x1c(%rbp)
movl %edi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movw $0x0, -0x2e(%rbp)
movw $0x0, -0x30(%rbp)
movl -0x20(%rbp), %edi
movq -0x28(%rbp), %rsi
leaq 0x2cd9(%rip), %rdx      # 0x4181
callq 0x1190
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
je 0x16db
movl -0x2c(%rbp), %eax
addl $-0x67, %eax
movl %eax, %ecx
movq %rcx, -0x530(%rbp)
subl $0xf, %eax
ja 0x16a8
movq -0x530(%rbp), %rax
leaq 0x2b41(%rip), %rcx      # 0x4020
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x4ae9(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
callq 0x10a0
movq %rax, %rdi
callq 0x1130
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x540(%rbp)
movq 0x4ac3(%rip), %rax      # 0x5fd8
movq (%rax), %rax
movq %rax, -0x538(%rbp)
movq 0x4ab2(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
callq 0x10a0
movq -0x540(%rbp), %rdi
movq -0x538(%rbp), %rsi
movq %rax, %rdx
callq 0x1050
movq -0x38(%rbp), %rsi
leaq 0x2c3d(%rip), %rdi      # 0x418c
movb $0x0, %al
callq 0x10b0
jmp 0x16d6
leaq 0x2c3a(%rip), %rdi      # 0x419c
movb $0x0, %al
callq 0x10b0
jmp 0x16d6
movq 0x4a63(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
callq 0x10a0
movq %rax, %rdi
callq 0x1130
movq %rax, -0x40(%rbp)
movq 0x4a48(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
callq 0x10a0
movq %rax, %rdi
addq $0x4, %rdi
callq 0x1130
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x560(%rbp)
movq 0x4a1e(%rip), %rax      # 0x5fd8
movq (%rax), %rax
movq %rax, -0x558(%rbp)
movq 0x4a0d(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
callq 0x10a0
movq -0x560(%rbp), %rdi
movq -0x558(%rbp), %rsi
movq %rax, %rdx
callq 0x1050
movq -0x48(%rbp), %rax
movq %rax, -0x550(%rbp)
movq 0x49dd(%rip), %rax      # 0x5fd8
movq (%rax), %rax
movq %rax, -0x548(%rbp)
movq 0x49cc(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
callq 0x10a0
movq -0x550(%rbp), %rdi
movq -0x548(%rbp), %rsi
movq %rax, %rdx
callq 0x1050
movq -0x48(%rbp), %rdi
leaq 0x2b90(%rip), %rsi      # 0x41c5
movl $0x4, %edx
callq 0x1050
movq -0x40(%rbp), %rsi
leaq 0x2b80(%rip), %rdi      # 0x41ca
movb $0x0, %al
callq 0x10b0
movq -0x48(%rbp), %rsi
leaq 0x2b8a(%rip), %rdi      # 0x41e6
movb $0x0, %al
callq 0x10b0
jmp 0x16d6
callq 0x13e0
jmp 0x16d6
leaq 0x2b91(%rip), %rdi      # 0x4204
movb $0x0, %al
callq 0x10b0
jmp 0x16d6
leaq 0x2b9b(%rip), %rdi      # 0x421e
movb $0x0, %al
callq 0x10b0
movw $0x1, -0x2e(%rbp)
jmp 0x16d6
leaq 0x2ba4(%rip), %rdi      # 0x423d
movb $0x0, %al
callq 0x10b0
movw $0x1, -0x30(%rbp)
jmp 0x16d6
movq 0x4949(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
leaq 0x2b8f(%rip), %rsi      # 0x424f
movb $0x0, %al
callq 0x1110
callq 0x13e0
movl $0x1, %edi
callq 0x11b0
jmp 0x149a
movl $0x0, -0x64(%rbp)
movq -0x38(%rbp), %rdi
leaq 0x2b8f(%rip), %rsi      # 0x427c
callq 0x1180
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rdi
leaq 0x2b7e(%rip), %rsi      # 0x427f
callq 0x1180
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
leaq 0x2b6d(%rip), %rsi      # 0x4282
callq 0x1180
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x173f
leaq 0x2b5a(%rip), %rdi      # 0x4286
movb $0x0, %al
callq 0x10b0
movl $0x1, -0x1c(%rbp)
jmp 0x24fd
jmp 0x1741
leaq -0x458(%rbp), %rdi
movq -0x50(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x1080
cmpq $0x0, %rax
je 0x23e8
movzbl -0x458(%rbp), %eax
cmpl $0xb5, %eax
je 0x1773
jmp 0x1741
movq -0x50(%rbp), %rdi
callq 0x1120
movq %rax, -0x518(%rbp)
leaq -0x458(%rbp), %rdi
addq $0x1, %rdi
movq -0x50(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x1080
movzbl -0x457(%rbp), %eax
cmpl $0x62, %eax
je 0x17bf
movq -0x50(%rbp), %rdi
movq -0x518(%rbp), %rsi
xorl %edx, %edx
callq 0x1160
jmp 0x1741
leaq -0x458(%rbp), %rdi
addq $0x2, %rdi
movq -0x50(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x1080
movzbl -0x456(%rbp), %eax
cmpl $0x1, %eax
jne 0x17f5
movzbl -0x455(%rbp), %eax
cmpl $0x2, %eax
je 0x186c
movzbl -0x456(%rbp), %eax
cmpl $0x1, %eax
jne 0x180d
movzbl -0x455(%rbp), %eax
cmpl $0x21, %eax
je 0x186c
movzbl -0x456(%rbp), %eax
cmpl $0x2, %eax
jne 0x1825
movzbl -0x455(%rbp), %eax
cmpl $0x10, %eax
je 0x186c
movzbl -0x456(%rbp), %eax
cmpl $0x1, %eax
jne 0x183d
movzbl -0x455(%rbp), %eax
cmpl $0x20, %eax
je 0x186c
movzbl -0x456(%rbp), %eax
cmpl $0x2, %eax
jne 0x1855
movzbl -0x455(%rbp), %eax
cmpl $0x15, %eax
je 0x186c
movq -0x50(%rbp), %rdi
movq -0x518(%rbp), %rsi
xorl %edx, %edx
callq 0x1160
jmp 0x1741
movzbl -0x453(%rbp), %eax
shll $0x8, %eax
movzbl -0x454(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x64(%rbp)
cmpl $0x3e8, -0x64(%rbp)     # imm = 0x3E8
jle 0x18a2
movq -0x50(%rbp), %rdi
movq -0x518(%rbp), %rsi
xorl %edx, %edx
callq 0x1160
jmp 0x1741
leaq -0x458(%rbp), %rdi
addq $0x6, %rdi
movslq -0x64(%rbp), %rdx
movq -0x50(%rbp), %rcx
movl $0x1, %esi
callq 0x1080
leaq -0x458(%rbp), %rdi
addq $0x3ee, %rdi            # imm = 0x3EE
movq -0x50(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x1080
leaq -0x458(%rbp), %rdi
addq $0x3ef, %rdi            # imm = 0x3EF
movq -0x50(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x1080
movq %rsp, %rdi
movl $0x7e, %ecx
leaq -0x458(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x12d0
cwtl
cmpl $0x1, %eax
jne 0x1931
movq -0x50(%rbp), %rdi
movq -0x518(%rbp), %rsi
xorl %edx, %edx
callq 0x1160
jmp 0x1741
movzbl -0x456(%rbp), %eax
cmpl $0x1, %eax
jne 0x1b3b
movzbl -0x455(%rbp), %eax
cmpl $0x21, %eax
jne 0x1b3b
movzbl -0x44f(%rbp), %eax
shll $0x18, %eax
movzbl -0x450(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x451(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x452(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x478(%rbp)
movzbl -0x44b(%rbp), %eax
shll $0x18, %eax
movzbl -0x44c(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x44d(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x44e(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x498(%rbp)
movzbl -0x447(%rbp), %eax
shll $0x18, %eax
movzbl -0x448(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x449(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x44a(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x49c(%rbp)
movzbl -0x445(%rbp), %eax
shll $0x8, %eax
movzbl -0x446(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x47c(%rbp)
movzbl -0x444(%rbp), %eax
movl %eax, -0x480(%rbp)
movzbl -0x443(%rbp), %eax
movl %eax, -0x484(%rbp)
movzbl -0x442(%rbp), %eax
movl %eax, -0x488(%rbp)
movzbl -0x441(%rbp), %eax
movl %eax, -0x48c(%rbp)
movzbl -0x440(%rbp), %eax
movl %eax, -0x490(%rbp)
movzbl -0x43f(%rbp), %eax
movl %eax, -0x494(%rbp)
movq -0x58(%rbp), %rdi
movl -0x478(%rbp), %edx
movl -0x498(%rbp), %ecx
movl -0x49c(%rbp), %r8d
movl -0x47c(%rbp), %r9d
movl -0x480(%rbp), %r15d
movl -0x484(%rbp), %r14d
movl -0x488(%rbp), %ebx
movl -0x48c(%rbp), %r11d
movl -0x490(%rbp), %r10d
movl -0x494(%rbp), %eax
leaq 0x281e(%rip), %rsi      # 0x42bc
movl %r15d, (%rsp)
movl %r14d, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movb $0x0, %al
callq 0x1110
movq -0x60(%rbp), %rcx
leaq -0x458(%rbp), %rdi
movl $0x1, %esi
movl $0x6, %edx
callq 0x11c0
leaq -0x458(%rbp), %rdi
addq $0x6, %rdi
movq -0x60(%rbp), %rcx
movl $0x1, %esi
movl $0x14, %edx
callq 0x11c0
leaq -0x458(%rbp), %rdi
addq $0x3ee, %rdi            # imm = 0x3EE
movq -0x60(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x11c0
leaq -0x458(%rbp), %rdi
addq $0x3ef, %rdi            # imm = 0x3EF
movq -0x60(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x11c0
jmp 0x23e3
movzbl -0x456(%rbp), %eax
cmpl $0x1, %eax
jne 0x1d12
movzbl -0x455(%rbp), %eax
cmpl $0x2, %eax
jne 0x1d12
movzbl -0x44f(%rbp), %eax
shll $0x18, %eax
movzbl -0x450(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x451(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x452(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x474(%rbp)
movzbl -0x44b(%rbp), %eax
shll $0x18, %eax
movzbl -0x44c(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x44d(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x44e(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x45c(%rbp)
movzbl -0x447(%rbp), %eax
shll $0x18, %eax
movzbl -0x448(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x449(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x44a(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x460(%rbp)
movzbl -0x443(%rbp), %eax
shll $0x18, %eax
movzbl -0x444(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x445(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x446(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x464(%rbp)
movzbl -0x43f(%rbp), %eax
shll $0x18, %eax
movzbl -0x440(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x441(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x442(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x468(%rbp)
movzbl -0x43b(%rbp), %eax
shll $0x18, %eax
movzbl -0x43c(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x43d(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x43e(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x46c(%rbp)
movzbl -0x437(%rbp), %eax
shll $0x18, %eax
movzbl -0x438(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x439(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x43a(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x470(%rbp)
movq -0x58(%rbp), %rdi
movl -0x474(%rbp), %edx
movl -0x45c(%rbp), %ecx
movl -0x460(%rbp), %r8d
movl -0x464(%rbp), %r9d
movl -0x468(%rbp), %r11d
movl -0x46c(%rbp), %r10d
movl -0x470(%rbp), %eax
leaq 0x25ee(%rip), %rsi      # 0x42e7
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x1110
jmp 0x23e1
movzbl -0x456(%rbp), %eax
cmpl $0x2, %eax
jne 0x1f50
movzbl -0x455(%rbp), %eax
cmpl $0x10, %eax
jne 0x1f50
movzbl -0x44f(%rbp), %eax
shll $0x18, %eax
movzbl -0x450(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x451(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x452(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x4a0(%rbp)
movzbl -0x44d(%rbp), %eax
shll $0x8, %eax
movzbl -0x44e(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x4a4(%rbp)
movzbl -0x44c(%rbp), %eax
movl %eax, -0x4a8(%rbp)
movzbl -0x44b(%rbp), %eax
movl %eax, -0x4ac(%rbp)
movl $0x0, -0x51c(%rbp)
movl -0x51c(%rbp), %eax
cmpl -0x4a8(%rbp), %eax
jge 0x1ee9
imull $0x18, -0x51c(%rbp), %eax
cltq
movq -0x44a(%rbp,%rax), %rax
movq %rax, -0x4f8(%rbp)
imull $0x18, -0x51c(%rbp), %eax
cltq
movq -0x442(%rbp,%rax), %rax
movq %rax, -0x500(%rbp)
imull $0x18, -0x51c(%rbp), %eax
cltq
movl -0x43a(%rbp,%rax), %eax
movl %eax, -0x50c(%rbp)
imull $0x18, -0x51c(%rbp), %eax
addl $0x1c, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
movl %eax, -0x4b0(%rbp)
imull $0x18, -0x51c(%rbp), %eax
addl $0x1d, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
movl %eax, -0x4b4(%rbp)
imull $0x18, -0x51c(%rbp), %eax
addl $0x1e, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
movl %eax, -0x4b8(%rbp)
imull $0x18, -0x51c(%rbp), %eax
addl $0x1f, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
movl %eax, -0x4bc(%rbp)
movq -0x58(%rbp), %rdi
movl -0x4a0(%rbp), %edx
movl -0x4a4(%rbp), %ecx
movl -0x4a8(%rbp), %r8d
movl -0x4ac(%rbp), %r9d
movsd -0x4f8(%rbp), %xmm0
movsd -0x500(%rbp), %xmm1
movss -0x50c(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
movl -0x4b0(%rbp), %ebx
movl -0x4b4(%rbp), %r11d
movl -0x4b8(%rbp), %r10d
movl -0x4bc(%rbp), %eax
leaq 0x244b(%rip), %rsi      # 0x4308
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x3, %al
callq 0x1110
movl -0x51c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x51c(%rbp)
jmp 0x1da2
movq -0x60(%rbp), %rcx
leaq -0x458(%rbp), %rdi
movl $0x1, %esi
movl $0xe, %edx
callq 0x11c0
leaq -0x458(%rbp), %rdi
addq $0x6, %rdi
addq $0x8, %rdi
imull $0x18, -0x4a8(%rbp), %eax
movslq %eax, %rdx
movq -0x60(%rbp), %rcx
movl $0x1, %esi
callq 0x11c0
leaq -0x458(%rbp), %rdi
addq $0x3ee, %rdi            # imm = 0x3EE
movq -0x60(%rbp), %rcx
movl $0x1, %esi
movl $0x2, %edx
callq 0x11c0
jmp 0x23df
movzbl -0x456(%rbp), %eax
cmpl $0x2, %eax
jne 0x22ae
movzbl -0x455(%rbp), %eax
cmpl $0x15, %eax
jne 0x22ae
movq -0x452(%rbp), %rax
movq %rax, -0x508(%rbp)
movzbl -0x449(%rbp), %eax
shll $0x8, %eax
movzbl -0x44a(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x4a4(%rbp)
movsbl -0x448(%rbp), %eax
movl %eax, -0x4c8(%rbp)
movzbl -0x447(%rbp), %eax
movl %eax, -0x4a8(%rbp)
movzbl -0x446(%rbp), %eax
movl %eax, -0x4e8(%rbp)
movl $0x0, -0x520(%rbp)
movl -0x520(%rbp), %eax
cmpl -0x4a8(%rbp), %eax
jge 0x2245
movl -0x520(%rbp), %eax
shll $0x5, %eax
cltq
movq -0x442(%rbp,%rax), %rax
movq %rax, -0x500(%rbp)
movl -0x520(%rbp), %eax
shll $0x5, %eax
cltq
movq -0x43a(%rbp,%rax), %rax
movq %rax, -0x4f8(%rbp)
movl -0x520(%rbp), %eax
shll $0x5, %eax
cltq
movl -0x432(%rbp,%rax), %eax
movl %eax, -0x50c(%rbp)
movl -0x520(%rbp), %eax
shll $0x5, %eax
addl $0x24, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
movl %eax, -0x4d4(%rbp)
movl -0x520(%rbp), %eax
shll $0x5, %eax
addl $0x25, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
movl %eax, -0x4b0(%rbp)
movl -0x520(%rbp), %eax
shll $0x5, %eax
addl $0x27, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
movl %eax, -0x4d0(%rbp)
movl -0x520(%rbp), %eax
shll $0x5, %eax
addl $0x29, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
shll $0x8, %eax
movl -0x520(%rbp), %ecx
shll $0x5, %ecx
addl $0x28, %ecx
movslq %ecx, %rcx
movzbl -0x452(%rbp,%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x4d8(%rbp)
movl -0x520(%rbp), %eax
shll $0x5, %eax
addl $0x2a, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
movl %eax, -0x4b8(%rbp)
movl -0x520(%rbp), %eax
shll $0x5, %eax
addl $0x2b, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
movl %eax, -0x4dc(%rbp)
movl -0x520(%rbp), %eax
shll $0x5, %eax
addl $0x2c, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
movl %eax, -0x4e0(%rbp)
movl -0x520(%rbp), %eax
shll $0x5, %eax
addl $0x2d, %eax
cltq
movzbl -0x452(%rbp,%rax), %eax
movl %eax, -0x4e4(%rbp)
movl -0x520(%rbp), %eax
shll $0x5, %eax
addl $0x2e, %eax
cltq
movb -0x452(%rbp,%rax), %al
movb %al, -0x4e9(%rbp)
movq -0x58(%rbp), %rdi
movsd -0x508(%rbp), %xmm0
movl -0x4a4(%rbp), %edx
movl -0x4c8(%rbp), %eax
movl %eax, -0x564(%rbp)
movl -0x4a8(%rbp), %r8d
movl -0x4e8(%rbp), %r9d
movsd -0x500(%rbp), %xmm1
movsd -0x4f8(%rbp), %xmm2
movss -0x50c(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
movl -0x4d4(%rbp), %r15d
movl -0x4b0(%rbp), %r14d
movl -0x4d0(%rbp), %ebx
movl -0x4d8(%rbp), %r11d
movl -0x4b8(%rbp), %r10d
movl -0x4dc(%rbp), %ecx
andl $0xf, %ecx
movl $0x1, %eax
shll %cl, %eax
cvtsi2sd %eax, %xmm4
movsd 0x1e55(%rip), %xmm5     # 0x4018
divsd %xmm5, %xmm4
cvtsi2sdl -0x4e0(%rbp), %xmm6
movsd 0x1e39(%rip), %xmm5     # 0x4010
mulsd %xmm6, %xmm5
movl -0x4e4(%rbp), %ecx
andl $0xf, %ecx
movl $0x1, %eax
shll %cl, %eax
movl -0x564(%rbp), %ecx
cvtsi2sd %eax, %xmm6
movsd 0x1e0b(%rip), %xmm7     # 0x4008
divsd %xmm7, %xmm6
movzbl -0x4e9(%rbp), %eax
leaq 0x2129(%rip), %rsi      # 0x4338
movl %r15d, (%rsp)
movl %r14d, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movb $0x7, %al
callq 0x1110
movl -0x520(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x520(%rbp)
jmp 0x1fc8
movq -0x60(%rbp), %rcx
leaq -0x458(%rbp), %rdi
movl $0x1, %esi
movl $0xe, %edx
callq 0x11c0
leaq -0x458(%rbp), %rdi
addq $0x6, %rdi
addq $0x8, %rdi
movl -0x4a8(%rbp), %eax
shll $0x5, %eax
movslq %eax, %rdx
movq -0x60(%rbp), %rcx
movl $0x1, %esi
callq 0x11c0
leaq -0x458(%rbp), %rdi
addq $0x3ee, %rdi            # imm = 0x3EE
movq -0x60(%rbp), %rcx
movl $0x1, %esi
movl $0x2, %edx
callq 0x11c0
jmp 0x23dd
movzbl -0x456(%rbp), %eax
cmpl $0x1, %eax
jne 0x23db
movzbl -0x455(%rbp), %eax
cmpl $0x20, %eax
jne 0x23db
movzbl -0x44f(%rbp), %eax
shll $0x18, %eax
movzbl -0x450(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x451(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x452(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x4c0(%rbp)
movzbl -0x44b(%rbp), %eax
shll $0x18, %eax
movzbl -0x44c(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x44d(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x44e(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x4c4(%rbp)
movzbl -0x449(%rbp), %eax
shll $0x8, %eax
movzbl -0x44a(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x4a4(%rbp)
movzbl -0x448(%rbp), %eax
movl %eax, -0x4c8(%rbp)
movzbl -0x447(%rbp), %eax
movl %eax, -0x4cc(%rbp)
movzbl -0x443(%rbp), %eax
shll $0x18, %eax
movzbl -0x444(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x445(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x446(%rbp), %ecx
orl %ecx, %eax
cltq
movl %eax, -0x498(%rbp)
movq -0x58(%rbp), %rdi
movl -0x4c0(%rbp), %edx
movl -0x4c4(%rbp), %ecx
movl -0x4a4(%rbp), %r8d
movl -0x4c8(%rbp), %r9d
movl -0x4cc(%rbp), %r10d
movl -0x498(%rbp), %eax
leaq 0x1fb8(%rip), %rsi      # 0x4384
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x1110
jmp 0x23dd
jmp 0x23df
jmp 0x23e1
jmp 0x23e3
jmp 0x1741
movzwl -0x2e(%rbp), %eax
cmpl $0x1, %eax
jne 0x23ff
leaq 0x1fab(%rip), %rdi      # 0x43a3
movb $0x0, %al
callq 0x10b0
movzwl -0x30(%rbp), %eax
cmpl $0x1, %eax
jne 0x24db
callq 0x2510
movq %rax, -0x528(%rbp)
movq -0x528(%rbp), %rdi
leaq 0x1f8f(%rip), %rsi      # 0x43b5
callq 0x2610
movq -0x528(%rbp), %rdi
leaq 0x1f82(%rip), %rsi      # 0x43bb
callq 0x28b0
movq -0x528(%rbp), %rdi
leaq 0x1f76(%rip), %rsi      # 0x43c2
callq 0x28e0
movq -0x528(%rbp), %rdi
leaq 0x1f83(%rip), %rsi      # 0x43e2
movb $0x0, %al
callq 0x27f0
movq -0x528(%rbp), %rdi
leaq 0x1f7a(%rip), %rsi      # 0x43ee
movb $0x0, %al
callq 0x27f0
movq -0x528(%rbp), %rdi
leaq 0x1f72(%rip), %rsi      # 0x43fb
movb $0x0, %al
callq 0x27f0
movq -0x528(%rbp), %rdi
leaq 0x1f72(%rip), %rsi      # 0x4410
movb $0x0, %al
callq 0x27f0
movq -0x528(%rbp), %rdi
leaq 0x1f64(%rip), %rsi      # 0x4417
movb $0x0, %al
callq 0x27f0
movq -0x528(%rbp), %rdi
leaq 0x1f1a(%rip), %rsi      # 0x43e2
movb $0x0, %al
callq 0x27f0
movq -0x528(%rbp), %rdi
callq 0x2740
movq -0x50(%rbp), %rdi
callq 0x1090
movq -0x58(%rbp), %rdi
callq 0x1090
movq -0x60(%rbp), %rdi
callq 0x1090
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
addq $0x948, %rsp            # imm = 0x948
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop