// File: /workspace/github_c_makefile_star2_O1/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 0x1b00(%rip), %r15      # 0x3060
leaq 0x1ab9(%rip), %r12      # 0x3020
leaq 0x1b0d(%rip), %r13      # 0x307b
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x11c0
leal -0x67(%rax), %ecx
cmpl $0xf, %ecx
ja 0x16c7
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
callq 0x14ce
jmp 0x157c
movq %r13, %rdi
xorl %eax, %eax
callq 0x10c0
jmp 0x157c
leaq 0x1e3f(%rip), %rdi      # 0x33f8
callq 0x1080
jmp 0x157c
movq 0x3a11(%rip), %rax      # 0x4fd8
movq (%rax), %rdi
movq %rdi, -0x30(%rbp)
callq 0x10b0
movq %rax, %r13
movq %rax, %rdi
callq 0x1160
movq %rax, -0x48(%rbp)
leaq 0x4(%r13), %rdi
callq 0x1160
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %r13, %rdx
leaq 0x1a7a(%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 0x1a74(%rip), %rdi      # 0x30a4
movq -0x48(%rbp), %rsi
xorl %eax, %eax
callq 0x10c0
leaq 0x1a7e(%rip), %rdi      # 0x30c0
movq -0x38(%rbp), %rsi
jmp 0x168b
movq 0x3989(%rip), %rax      # 0x4fd8
movq (%rax), %rdi
movq %rdi, -0x30(%rbp)
callq 0x10b0
movq %rax, %r13
movq %rax, %rdi
callq 0x1160
movq %rax, -0x40(%rbp)
movq %rax, %rdi
movq -0x30(%rbp), %rsi
movq %r13, %rdx
leaq 0x1a00(%rip), %r13      # 0x307b
callq 0x1050
leaq 0x19e4(%rip), %rdi      # 0x306b
movq -0x40(%rbp), %rsi
xorl %eax, %eax
callq 0x10c0
jmp 0x157c
leaq 0x1d2b(%rip), %rdi      # 0x33c9
callq 0x1080
movw $0x1, %ax
movl %eax, -0x50(%rbp)
jmp 0x157c
leaq 0x1d24(%rip), %rdi      # 0x33da
callq 0x1080
movw $0x1, %ax
movl %eax, -0x4c(%rbp)
jmp 0x157c
cmpl $-0x1, %eax
jne 0x1e6f
leaq 0x1a34(%rip), %rsi      # 0x310b
movq -0x40(%rbp), %rdi
callq 0x11b0
movq %rax, %rbx
leaq 0x1a24(%rip), %rsi      # 0x310e
movq -0x48(%rbp), %rdi
callq 0x11b0
movq %rax, %r12
leaq 0x1a14(%rip), %rsi      # 0x3111
movq -0x38(%rbp), %rdi
callq 0x11b0
testq %rbx, %rbx
je 0x1e4c
movq %rax, %r13
leaq -0x468(%rbp), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x1090
testq %rax, %rax
je 0x1d70
leaq -0x467(%rbp), %r14
leaq -0x468(%rbp), %r15
cmpb $-0x4b, -0x468(%rbp)
jne 0x1804
movq %rbx, %rdi
callq 0x1150
movq %rax, %r15
movl $0x1, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x1090
cmpb $0x62, -0x467(%rbp)
jne 0x17f0
movl $0x1, %esi
movl $0x4, %edx
leaq -0x466(%rbp), %rdi
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 0x17b2
andb %sil, %dl
je 0x17e2
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 0x17f0
movzwl -0x464(%rbp), %eax
cmpl $0x3e9, %eax            # imm = 0x3E9
jb 0x1827
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x1190
leaq -0x468(%rbp), %r15
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x1090
testq %rax, %rax
jne 0x1742
jmp 0x1d70
movl %eax, %edx
movl $0x1, %esi
leaq -0x462(%rbp), %rdi
movq %rbx, %rcx
callq 0x1090
movl $0x1, %esi
movl $0x1, %edx
leaq -0x7a(%rbp), %rdi
movq %rbx, %rcx
callq 0x1090
movl $0x1, %esi
movl $0x1, %edx
leaq -0x79(%rbp), %rdi
movq %rbx, %rcx
callq 0x1090
movzbl -0x463(%rbp), %edx
movzbl -0x464(%rbp), %edi
movb -0x466(%rbp), %cl
movb -0x465(%rbp), %al
leal (%rax,%rcx), %r9d
leal (%rdi,%r9), %r10d
leal (%rdx,%r10), %esi
movl %edx, %r8d
shll $0x8, %r8d
leal (%r9,%rcx), %edx
addb %r10b, %dl
addb %sil, %dl
orl %edi, %r8d
je 0x18be
movl %r8d, %edi
xorl %r8d, %r8d
addb -0x462(%rbp,%r8), %sil
addb %sil, %dl
incq %r8
cmpq %r8, %rdi
jne 0x18ab
cmpb -0x7a(%rbp), %sil
jne 0x17f0
cmpb -0x79(%rbp), %dl
jne 0x17f0
movl %ecx, %edx
xorb $0x1, %dl
movl %eax, %esi
xorb $0x21, %sil
orb %dl, %sil
jne 0x19ba
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), %eax
movq %rax, -0x30(%rbp)
movq %r14, %r11
movzbl -0x452(%rbp), %r14d
movzbl -0x451(%rbp), %r15d
movq %r12, %rdi
movzbl -0x450(%rbp), %r12d
movq %r13, %r10
movzbl -0x44f(%rbp), %r13d
leaq 0x17cf(%rip), %rsi      # 0x3115
xorl %eax, %eax
pushq %r13
movq %r10, %r13
pushq %r12
movq %rdi, %r12
pushq %r15
pushq %r14
movq %r11, %r14
pushq -0x30(%rbp)
pushq -0x38(%rbp)
callq 0x1140
addq $0x30, %rsp
movl $0x1, %esi
movl $0x6, %edx
leaq -0x468(%rbp), %r15
movq %r15, %rdi
movq %r13, %rcx
callq 0x11f0
movl $0x1, %esi
movl $0x14, %edx
leaq -0x462(%rbp), %rdi
movq %r13, %rcx
callq 0x11f0
movsbl -0x7a(%rbp), %edi
movq %r13, %rsi
callq 0x1110
movsbl -0x79(%rbp), %edi
movq %r13, %rsi
callq 0x1110
jmp 0x1804
movl %eax, %esi
xorb $0x2, %sil
orb %dl, %sil
jne 0x1a1e
movl -0x462(%rbp), %edx
movl -0x45e(%rbp), %ecx
movl -0x45a(%rbp), %r8d
movl -0x456(%rbp), %r9d
movl -0x452(%rbp), %r10d
movl -0x44e(%rbp), %r11d
movq %r14, %r15
movl -0x44a(%rbp), %r14d
subq $0x8, %rsp
movq %r12, %rdi
leaq 0x173b(%rip), %rsi      # 0x3140
xorl %eax, %eax
pushq %r14
movq %r15, %r14
pushq %r11
pushq %r10
callq 0x1140
addq $0x20, %rsp
jmp 0x17fd
movq %r13, -0x58(%rbp)
xorb $0x2, %cl
movl %eax, %esi
xorb $0x10, %sil
orb %cl, %sil
jne 0x1b2c
movzbl -0x45c(%rbp), %ecx
movq %rcx, -0x30(%rbp)
testl %ecx, %ecx
movq %r12, -0x38(%rbp)
leaq 0x1715(%rip), %r14      # 0x3161
je 0x1afc
movl -0x462(%rbp), %eax
movl %eax, -0x48(%rbp)
movzwl -0x45e(%rbp), %eax
movl %eax, -0x40(%rbp)
movzbl -0x45b(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x30(%rbp), %rax
leal (,%rax,8), %eax
leaq (%rax,%rax,2), %rax
movq %rax, -0x60(%rbp)
xorl %r15d, %r15d
movsd -0x45a(%rbp,%r15), %xmm0
movsd -0x452(%rbp,%r15), %xmm1
movzbl -0x446(%rbp,%r15), %r10d
movzbl -0x445(%rbp,%r15), %r11d
movzbl -0x444(%rbp,%r15), %r12d
movzbl -0x443(%rbp,%r15), %r13d
xorps %xmm2, %xmm2
cvtss2sd -0x44a(%rbp,%r15), %xmm2
movq -0x38(%rbp), %rdi
movq %r14, %rsi
movl -0x48(%rbp), %edx
movl -0x40(%rbp), %ecx
movq -0x30(%rbp), %r8
movl -0x68(%rbp), %r9d
movb $0x3, %al
pushq %r13
pushq %r12
pushq %r11
pushq %r10
callq 0x1140
addq $0x20, %rsp
addq $0x18, %r15
cmpq %r15, -0x60(%rbp)
jne 0x1a85
movl $0x1, %esi
movl $0xe, %edx
leaq -0x468(%rbp), %r15
movq %r15, %rdi
movq -0x58(%rbp), %r13
movq %r13, %rcx
callq 0x11f0
movq -0x30(%rbp), %rax
shll $0x3, %eax
leaq (%rax,%rax,2), %rdx
jmp 0x1cd8
movl %eax, %esi
xorb $0x15, %sil
orb %sil, %cl
jne 0x1d12
movzbl -0x457(%rbp), %eax
movq %rax, -0x40(%rbp)
testl %eax, %eax
movq %r12, -0x38(%rbp)
movsd 0x14b4(%rip), %xmm5     # 0x3008
movsd 0x14b4(%rip), %xmm6     # 0x3010
movsd 0x14b4(%rip), %xmm7     # 0x3018
leaq 0x1626(%rip), %r15      # 0x3191
je 0x1cb1
movsd -0x462(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movzwl -0x45a(%rbp), %eax
movl %eax, -0x60(%rbp)
movsbl -0x458(%rbp), %eax
movl %eax, -0x70(%rbp)
movzbl -0x456(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x40(%rbp), %rax
shll $0x5, %eax
movq %rax, -0x78(%rbp)
xorl %r14d, %r14d
movsd -0x452(%rbp,%r14), %xmm1
movsd -0x44a(%rbp,%r14), %xmm2
movzbl -0x43e(%rbp,%r14), %eax
movq %rax, -0x30(%rbp)
movzbl -0x43d(%rbp,%r14), %eax
movq %rax, -0x48(%rbp)
movzbl -0x43b(%rbp,%r14), %r11d
movzwl -0x43a(%rbp,%r14), %r12d
movzbl -0x438(%rbp,%r14), %r13d
movb -0x437(%rbp,%r14), %cl
movzbl -0x436(%rbp,%r14), %edx
movb -0x435(%rbp,%r14), %al
xorps %xmm3, %xmm3
cvtss2sd -0x442(%rbp,%r14), %xmm3
andb $0xf, %cl
movl $0x1, %edi
shll %cl, %edi
movzbl -0x434(%rbp,%r14), %r10d
xorps %xmm4, %xmm4
cvtsi2sd %edi, %xmm4
divsd %xmm5, %xmm4
xorps %xmm5, %xmm5
cvtsi2sd %edx, %xmm5
andb $0xf, %al
movl $0x1, %edx
movl %eax, %ecx
shll %cl, %edx
mulsd %xmm6, %xmm5
xorps %xmm6, %xmm6
cvtsi2sd %edx, %xmm6
divsd %xmm7, %xmm6
movq -0x38(%rbp), %rdi
movq %r15, %rsi
movsd -0x68(%rbp), %xmm0
movl -0x60(%rbp), %edx
movl -0x70(%rbp), %ecx
movq -0x40(%rbp), %r8
movl -0x6c(%rbp), %r9d
movb $0x7, %al
pushq %r10
pushq %r13
pushq %r12
pushq %r11
pushq -0x48(%rbp)
pushq -0x30(%rbp)
callq 0x1140
movsd 0x1389(%rip), %xmm7     # 0x3018
movsd 0x1379(%rip), %xmm6     # 0x3010
movsd 0x1369(%rip), %xmm5     # 0x3008
addq $0x30, %rsp
addq $0x20, %r14
cmpq %r14, -0x78(%rbp)
jne 0x1baa
movl $0x1, %esi
movl $0xe, %edx
leaq -0x468(%rbp), %r15
movq %r15, %rdi
movq -0x58(%rbp), %r13
movq %r13, %rcx
callq 0x11f0
movq -0x40(%rbp), %rdx
shll $0x5, %edx
movl $0x1, %esi
leaq -0x45a(%rbp), %rdi
movq %r13, %rcx
callq 0x11f0
movl $0x1, %esi
movl $0x2, %edx
leaq -0x7a(%rbp), %rdi
movq %r13, %rcx
callq 0x11f0
movq -0x38(%rbp), %r12
leaq -0x467(%rbp), %r14
jmp 0x1804
xorb $0x20, %al
orb %al, %dl
movq -0x58(%rbp), %r13
leaq -0x468(%rbp), %r15
jne 0x1804
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 %r12, %rdi
leaq 0x1481(%rip), %rsi      # 0x31dd
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x1140
addq $0x10, %rsp
jmp 0x1804
cmpw $0x0, -0x4c(%rbp)
je 0x1d83
leaq 0x163a(%rip), %rdi      # 0x33b8
callq 0x1080
cmpw $0x0, -0x50(%rbp)
je 0x1e30
callq 0x1e78
movq %rax, %r14
leaq 0x145f(%rip), %rsi      # 0x31fc
movq %rax, %rdi
callq 0x1f03
leaq 0x1456(%rip), %rsi      # 0x3202
movq %r14, %rdi
callq 0x20e7
leaq 0x144e(%rip), %rsi      # 0x3209
movq %r14, %rdi
callq 0x20fd
leaq 0x145f(%rip), %r15      # 0x3229
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2051
leaq 0x1457(%rip), %rsi      # 0x3235
movq %r14, %rdi
xorl %eax, %eax
callq 0x2051
leaq 0x1453(%rip), %rsi      # 0x3242
movq %r14, %rdi
xorl %eax, %eax
callq 0x2051
leaq 0x1457(%rip), %rsi      # 0x3257
movq %r14, %rdi
xorl %eax, %eax
callq 0x2051
leaq 0x144d(%rip), %rsi      # 0x325e
movq %r14, %rdi
xorl %eax, %eax
callq 0x2051
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2051
movq %r14, %rdi
callq 0x1fe3
movq %rbx, %rdi
callq 0x10a0
movq %r12, %rdi
callq 0x10a0
movq %r13, %rdi
callq 0x10a0
xorl %eax, %eax
jmp 0x1e5d
leaq 0x1530(%rip), %rdi      # 0x3383
callq 0x1080
movl $0x1, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x1210
nop