// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movq %rsi, %rbx
movl %edi, %r14d
leaq 0x1c91(%rip), %r15      # 0x3060
leaq 0x1c4a(%rip), %r12      # 0x3020
leaq 0x1c9e(%rip), %r13      # 0x307b
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x11b0
leal -0x67(%rax), %ecx
cmpl $0xf, %ecx
ja 0x1536
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
callq 0x133d
jmp 0x13eb
movq %r13, %rdi
xorl %eax, %eax
callq 0x10c0
jmp 0x13eb
leaq 0x1fd0(%rip), %rdi      # 0x33f8
callq 0x1080
jmp 0x13eb
movq 0x3ba2(%rip), %rax      # 0x4fd8
movq (%rax), %rdi
movq %rdi, -0x30(%rbp)
callq 0x10b0
movq %rax, %r13
movq %rax, %rdi
callq 0x1150
movq %rax, -0x48(%rbp)
leaq 0x4(%r13), %rdi
callq 0x1150
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %r13, %rdx
leaq 0x1c0b(%rip), %r13      # 0x307b
callq 0x1050
movq -0x30(%rbp), %rdi
callq 0x10b0
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %rax, %rdx
callq 0x1050
movq -0x38(%rbp), %rax
movl $0x5f786275, (%rax)     # imm = 0x5F786275
leaq 0x1c05(%rip), %rdi      # 0x30a4
movq -0x48(%rbp), %rsi
xorl %eax, %eax
callq 0x10c0
leaq 0x1c0f(%rip), %rdi      # 0x30c0
movq -0x38(%rbp), %rsi
jmp 0x14fa
movq 0x3b1a(%rip), %rax      # 0x4fd8
movq (%rax), %rdi
movq %rdi, -0x30(%rbp)
callq 0x10b0
movq %rax, %r13
movq %rax, %rdi
callq 0x1150
movq %rax, -0x40(%rbp)
movq %rax, %rdi
movq -0x30(%rbp), %rsi
movq %r13, %rdx
leaq 0x1b91(%rip), %r13      # 0x307b
callq 0x1050
leaq 0x1b75(%rip), %rdi      # 0x306b
movq -0x40(%rbp), %rsi
xorl %eax, %eax
callq 0x10c0
jmp 0x13eb
leaq 0x1ebc(%rip), %rdi      # 0x33c9
callq 0x1080
movw $0x1, %ax
movl %eax, -0x50(%rbp)
jmp 0x13eb
leaq 0x1eb5(%rip), %rdi      # 0x33da
callq 0x1080
movw $0x1, %ax
movl %eax, -0x4c(%rbp)
jmp 0x13eb
cmpl $-0x1, %eax
jne 0x1bf0
pushq $0x1
popq %r14
leaq 0x1bc1(%rip), %rsi      # 0x310b
movq -0x40(%rbp), %rdi
callq 0x11a0
movq %rax, %rbx
leaq 0x1bb1(%rip), %rsi      # 0x310e
movq -0x48(%rbp), %rdi
callq 0x11a0
movq %rax, -0x30(%rbp)
leaq 0x1ba0(%rip), %rsi      # 0x3111
movq -0x38(%rbp), %rdi
callq 0x11a0
movq %rax, -0x58(%rbp)
testq %rbx, %rbx
je 0x1bcf
leaq -0x467(%rbp), %r15
leaq -0x466(%rbp), %r13
pushq $0x1
popq %r12
leaq -0x468(%rbp), %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x1090
testq %rax, %rax
je 0x1af0
cmpb $-0x4b, -0x468(%rbp)
jne 0x1599
movq %rbx, %rdi
callq 0x1140
movq %rax, %r14
movq %r15, %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x1090
cmpb $0x62, -0x467(%rbp)
jne 0x16b9
movq %r13, %rdi
movq %r12, %rsi
pushq $0x4
popq %rdx
movq %rbx, %rcx
callq 0x1090
movb -0x466(%rbp), %cl
movb -0x465(%rbp), %al
cmpb $0x2, %al
setne %dl
cmpb $0x21, %al
setne %sil
cmpb $0x1, %cl
jne 0x161b
andb %sil, %dl
je 0x164b
movl %ecx, %edx
xorb $0x1, %dl
cmpb $0x2, %cl
setne %cl
cmpb $0x10, %al
setne %sil
orb %cl, %sil
movl %eax, %edi
xorb $0x20, %dil
orb %dl, %dil
setne %dl
andb %sil, %dl
cmpb $0x15, %al
setne %al
orb %cl, %al
andb %dl, %al
cmpb $0x1, %al
je 0x16b9
movzwl -0x464(%rbp), %eax
cmpl $0x3e9, %eax            # imm = 0x3E9
jae 0x16b9
movl %eax, %edx
leaq -0x462(%rbp), %rdi
movq %r12, %rsi
movq %rbx, %rcx
callq 0x1090
leaq -0x7a(%rbp), %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x1090
leaq -0x79(%rbp), %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x1090
subq $0x3f0, %rsp            # imm = 0x3F0
pushq $0x7e
popq %rcx
movq %rsp, %rdi
leaq -0x468(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x12ec
addq $0x3f0, %rsp            # imm = 0x3F0
testw %ax, %ax
je 0x16cb
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1180
jmp 0x1599
movb -0x466(%rbp), %dl
movb -0x465(%rbp), %al
movl %edx, %ecx
xorb $0x1, %cl
movl %eax, %esi
xorb $0x21, %sil
orb %cl, %sil
jne 0x17a7
movl -0x462(%rbp), %edx
movl -0x45e(%rbp), %ecx
movl -0x45a(%rbp), %r8d
movzwl -0x456(%rbp), %r9d
movzbl -0x454(%rbp), %eax
movq %rax, -0x38(%rbp)
movzbl -0x453(%rbp), %r11d
movzbl -0x452(%rbp), %r14d
movzbl -0x451(%rbp), %r15d
movzbl -0x450(%rbp), %r13d
movzbl -0x44f(%rbp), %r10d
movq -0x30(%rbp), %rdi
leaq 0x19d1(%rip), %rsi      # 0x3115
xorl %eax, %eax
pushq %r10
pushq %r13
pushq %r15
pushq %r14
pushq %r11
pushq -0x38(%rbp)
callq 0x1130
addq $0x30, %rsp
leaq -0x468(%rbp), %rdi
movq %r12, %rsi
pushq $0x6
popq %rdx
movq -0x58(%rbp), %r14
movq %r14, %rcx
callq 0x11e0
leaq -0x462(%rbp), %rdi
movq %r12, %rsi
pushq $0x14
popq %rdx
movq %r14, %rcx
callq 0x11e0
movsbl -0x7a(%rbp), %edi
movq %r14, %rsi
callq 0x1100
movsbl -0x79(%rbp), %edi
movq %r14, %rsi
callq 0x1100
jmp 0x1add
movl %eax, %esi
xorb $0x2, %sil
orb %cl, %sil
jne 0x1806
movl -0x462(%rbp), %edx
movl -0x45e(%rbp), %ecx
movl -0x45a(%rbp), %r8d
movl -0x456(%rbp), %r9d
movl -0x452(%rbp), %r10d
movl -0x44e(%rbp), %r11d
movl -0x44a(%rbp), %r14d
subq $0x8, %rsp
movq -0x30(%rbp), %rdi
leaq 0x1950(%rip), %rsi      # 0x3140
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x1130
addq $0x20, %rsp
jmp 0x1add
xorb $0x2, %dl
movl %eax, %esi
xorb $0x10, %sil
orb %dl, %sil
jne 0x18c9
movl -0x462(%rbp), %eax
movl %eax, -0x48(%rbp)
movzwl -0x45e(%rbp), %eax
movl %eax, -0x40(%rbp)
movzbl -0x45c(%rbp), %eax
movzbl -0x45b(%rbp), %ecx
movl %ecx, -0x60(%rbp)
movq %rax, -0x68(%rbp)
imulq $0x18, %rax, %rax
movq %rax, -0x38(%rbp)
xorl %r15d, %r15d
cmpq %r15, -0x38(%rbp)
je 0x1a0d
movsd -0x45a(%rbp,%r15), %xmm0
movsd -0x452(%rbp,%r15), %xmm1
movzbl -0x446(%rbp,%r15), %r10d
movzbl -0x445(%rbp,%r15), %r11d
movzbl -0x444(%rbp,%r15), %r13d
movzbl -0x443(%rbp,%r15), %r14d
cvtss2sd -0x44a(%rbp,%r15), %xmm2
movq -0x30(%rbp), %rdi
leaq 0x18bf(%rip), %rsi      # 0x3161
movl -0x48(%rbp), %edx
movl -0x40(%rbp), %ecx
movq -0x68(%rbp), %r8
movl -0x60(%rbp), %r9d
movb $0x3, %al
pushq %r14
pushq %r13
pushq %r11
pushq %r10
callq 0x1130
addq $0x20, %rsp
addq $0x18, %r15
jmp 0x184b
movl %eax, %esi
xorb $0x15, %sil
orb %sil, %dl
jne 0x1a39
movsd -0x462(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movzwl -0x45a(%rbp), %eax
movl %eax, -0x74(%rbp)
movsbl -0x458(%rbp), %eax
movl %eax, -0x70(%rbp)
movzbl -0x457(%rbp), %eax
movzbl -0x456(%rbp), %ecx
movl %ecx, -0x6c(%rbp)
movq %rax, -0x40(%rbp)
shll $0x5, %eax
movq %rax, -0x68(%rbp)
xorl %r13d, %r13d
cmpq %r13, -0x68(%rbp)
je 0x1a99
movsd -0x452(%rbp,%r13), %xmm1
movsd -0x44a(%rbp,%r13), %xmm2
movzbl -0x43e(%rbp,%r13), %eax
movq %rax, -0x38(%rbp)
movzbl -0x43d(%rbp,%r13), %eax
movq %rax, -0x48(%rbp)
movzbl -0x43b(%rbp,%r13), %r14d
movzwl -0x43a(%rbp,%r13), %r15d
movzbl -0x438(%rbp,%r13), %r10d
movb -0x437(%rbp,%r13), %cl
movzbl -0x436(%rbp,%r13), %edx
movb -0x435(%rbp,%r13), %al
cvtss2sd -0x442(%rbp,%r13), %xmm3
andb $0xf, %cl
pushq $0x1
popq %rdi
movl %edi, %esi
shll %cl, %esi
movzbl -0x434(%rbp,%r13), %r11d
cvtsi2sd %esi, %xmm4
divsd 0x165b(%rip), %xmm4     # 0x3008
cvtsi2sd %edx, %xmm5
andb $0xf, %al
movl %edi, %edx
movl %eax, %ecx
shll %cl, %edx
mulsd 0x164f(%rip), %xmm5     # 0x3010
cvtsi2sd %edx, %xmm6
divsd 0x164b(%rip), %xmm6     # 0x3018
movq -0x30(%rbp), %rdi
leaq 0x17b9(%rip), %rsi      # 0x3191
movsd -0x60(%rbp), %xmm0
movl -0x74(%rbp), %edx
movl -0x70(%rbp), %ecx
movq -0x40(%rbp), %r8
movl -0x6c(%rbp), %r9d
movb $0x7, %al
pushq %r11
pushq %r10
pushq %r15
pushq %r14
pushq -0x48(%rbp)
pushq -0x38(%rbp)
callq 0x1130
addq $0x30, %rsp
addq $0x20, %r13
jmp 0x1918
leaq -0x468(%rbp), %rdi
movq %r12, %rsi
pushq $0xe
popq %rdx
movq -0x58(%rbp), %r14
movq %r14, %rcx
callq 0x11e0
leaq -0x45a(%rbp), %rdi
movq %r12, %rsi
movq -0x38(%rbp), %rdx
jmp 0x1ac3
xorb $0x20, %al
orb %al, %cl
leaq -0x467(%rbp), %r15
leaq -0x466(%rbp), %r13
jne 0x1599
movl -0x462(%rbp), %edx
movl -0x45e(%rbp), %ecx
movzwl -0x45a(%rbp), %r8d
movzbl -0x458(%rbp), %r9d
movzbl -0x457(%rbp), %r10d
movl -0x456(%rbp), %r11d
movq -0x30(%rbp), %rdi
leaq 0x1756(%rip), %rsi      # 0x31dd
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x1130
popq %rcx
popq %rdx
jmp 0x1599
leaq -0x468(%rbp), %rdi
movq %r12, %rsi
pushq $0xe
popq %rdx
movq -0x58(%rbp), %r14
movq %r14, %rcx
callq 0x11e0
movq -0x40(%rbp), %rdx
shll $0x5, %edx
leaq -0x45a(%rbp), %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x11e0
leaq -0x7a(%rbp), %rdi
movq %r12, %rsi
pushq $0x2
popq %rdx
movq %r14, %rcx
callq 0x11e0
leaq -0x467(%rbp), %r15
leaq -0x466(%rbp), %r13
jmp 0x1599
cmpw $0x0, -0x4c(%rbp)
je 0x1b03
leaq 0x18ba(%rip), %rdi      # 0x33b8
callq 0x1080
cmpw $0x0, -0x50(%rbp)
je 0x1bb0
callq 0x1c18
movq %rax, %r14
leaq 0x16df(%rip), %rsi      # 0x31fc
movq %rax, %rdi
callq 0x1cd2
leaq 0x16d6(%rip), %rsi      # 0x3202
movq %r14, %rdi
callq 0x1ee6
leaq 0x16ce(%rip), %rsi      # 0x3209
movq %r14, %rdi
callq 0x1efc
leaq 0x16df(%rip), %r15      # 0x3229
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1e50
leaq 0x16d7(%rip), %rsi      # 0x3235
movq %r14, %rdi
xorl %eax, %eax
callq 0x1e50
leaq 0x16d3(%rip), %rsi      # 0x3242
movq %r14, %rdi
xorl %eax, %eax
callq 0x1e50
leaq 0x16d7(%rip), %rsi      # 0x3257
movq %r14, %rdi
xorl %eax, %eax
callq 0x1e50
leaq 0x16cd(%rip), %rsi      # 0x325e
movq %r14, %rdi
xorl %eax, %eax
callq 0x1e50
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1e50
movq %r14, %rdi
callq 0x1dd4
movq %rbx, %rdi
callq 0x10a0
movq -0x30(%rbp), %rdi
callq 0x10a0
movq -0x58(%rbp), %rdi
callq 0x10a0
xorl %r14d, %r14d
jmp 0x1bdb
leaq 0x17ad(%rip), %rdi      # 0x3383
callq 0x1080
movl %r14d, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3401(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x14da(%rip), %rsi      # 0x30de
xorl %eax, %eax
callq 0x1130
callq 0x133d
pushq $0x1
popq %rdi
callq 0x11d0