// File: /workspace/github_c_makefile_star2_O3/archer1357[P]Offline-Raytracer/avilib.c
// Function: avi_parse_input_file
int avi_parse_input_file(avi_t *AVI, int getIndex)
{
  long i, rate, scale, idx_type;
  off_t n;
  unsigned char *hdrl_data;
  long header_offset=0, hdrl_len=0;
  long nvi, nai[AVI_MAX_TRACKS], ioff;
  long tot[AVI_MAX_TRACKS];
  int j;
  int lasttag = 0;
  int vids_strh_seen = 0;
  int vids_strf_seen = 0;
  int auds_strh_seen = 0;
  //  int auds_strf_seen = 0;
  int num_stream = 0;
  char data[256];

  /* Read first 12 bytes and check that this is an AVI file */

   if( avi_read(AVI->fdes,data,12) != 12 ) ERR_EXIT(AVI_ERR_READ)

   if( strncasecmp(data  ,"RIFF",4) !=0 ||
       strncasecmp(data+8,"AVI ",4) !=0 ) ERR_EXIT(AVI_ERR_NO_AVI)

   /* Go through the AVI file and extract the header list,
      the start position of the 'movi' list and an optionally
      present idx1 tag */

   hdrl_data = 0;

   while(1)
   {
      if( avi_read(AVI->fdes,data,8) != 8 ) break; /* We assume it's EOF */

      n = str2ulong((unsigned char *)data+4);
      n = PAD_EVEN(n);

      if(strncasecmp(data,"LIST",4) == 0)
      {
         if( avi_read(AVI->fdes,data,4) != 4 ) ERR_EXIT(AVI_ERR_READ)
         n -= 4;
         if(strncasecmp(data,"hdrl",4) == 0)
         {
            hdrl_len = n;
            hdrl_data = (unsigned char *) malloc(n);
            if(hdrl_data==0) ERR_EXIT(AVI_ERR_NO_MEM);

	    // offset of header

	    header_offset = lseek(AVI->fdes,0,SEEK_CUR);

            if( avi_read(AVI->fdes,(char *)hdrl_data,n) != n ) ERR_EXIT(AVI_ERR_READ)
         }
         else if(strncasecmp(data,"movi",4) == 0)
         {
            AVI->movi_start = lseek(AVI->fdes,0,SEEK_CUR);
            lseek(AVI->fdes,n,SEEK_CUR);
         }
         else
            lseek(AVI->fdes,n,SEEK_CUR);
      }
      else if(strncasecmp(data,"idx1",4) == 0)
      {
         /* n must be a multiple of 16, but the reading does not
            break if this is not the case */

         AVI->n_idx = AVI->max_idx = n/16;
         AVI->idx = (unsigned  char((*)[16]) ) malloc(n);
         if(AVI->idx==0) ERR_EXIT(AVI_ERR_NO_MEM)
         if(avi_read(AVI->fdes, (char *) AVI->idx, n) != n ) ERR_EXIT(AVI_ERR_READ)
      }
      else
         lseek(AVI->fdes,n,SEEK_CUR);
   }

   if(!hdrl_data      ) ERR_EXIT(AVI_ERR_NO_HDRL)
   if(!AVI->movi_start) ERR_EXIT(AVI_ERR_NO_MOVI)

   /* Interpret the header list */

   for(i=0;i<hdrl_len;)
   {
      /* List tags are completly ignored */

      if(strncasecmp((char *)hdrl_data+i,"LIST",4)==0) { i+= 12; continue; }

      n = str2ulong(hdrl_data+i+4);
      n = PAD_EVEN(n);

      /* Interpret the tag and its args */

      if(strncasecmp((char *)hdrl_data+i,"strh",4)==0)
      {
         i += 8;
         if(strncasecmp((char *)hdrl_data+i,"vids",4) == 0 && !vids_strh_seen)
         {
            memcpy(AVI->compressor,hdrl_data+i+4,4);
            AVI->compressor[4] = 0;

	    // ThOe
	    AVI->v_codech_off = header_offset + i+4;

            scale = str2ulong(hdrl_data+i+20);
            rate  = str2ulong(hdrl_data+i+24);
            if(scale!=0) AVI->fps = (double)rate/(double)scale;
            AVI->video_frames = str2ulong(hdrl_data+i+32);
            AVI->video_strn = num_stream;
	    AVI->max_len = 0;
            vids_strh_seen = 1;
            lasttag = 1; /* vids */
         }
         else if (strncasecmp ((char *)hdrl_data+i,"auds",4) ==0 && ! auds_strh_seen)
         {

	   //inc audio tracks
	   AVI->aptr=AVI->anum;
	   ++AVI->anum;

	   if(AVI->anum > AVI_MAX_TRACKS) {
	     fprintf(stderr, "error - only %d audio tracks supported\n", AVI_MAX_TRACKS);
	     return(-1);
	   }

	   AVI->track[AVI->aptr].audio_bytes = str2ulong(hdrl_data+i+32)*avi_sampsize(AVI, 0);
	   AVI->track[AVI->aptr].audio_strn = num_stream;
	   //	   auds_strh_seen = 1;
	   lasttag = 2; /* auds */

	   // ThOe
	   AVI->track[AVI->aptr].a_codech_off = header_offset + i;

         }
         else
            lasttag = 0;
         num_stream++;
      }
      else if(strncasecmp((char *)hdrl_data+i,"strf",4)==0)
      {
         i += 8;
         if(lasttag == 1)
         {
            BITMAPINFOHEADER_avilib bih;

            memcpy(&bih, hdrl_data + i, sizeof(BITMAPINFOHEADER_avilib));
            AVI->bitmap_info_header = (BITMAPINFOHEADER_avilib *)malloc(bih.bi_size);
            if (AVI->bitmap_info_header != NULL)
              memcpy(AVI->bitmap_info_header, hdrl_data + i, bih.bi_size);

            AVI->width  = str2ulong(hdrl_data+i+4);
            AVI->height = str2ulong(hdrl_data+i+8);
                    vids_strf_seen = 1;
	    //ThOe
	    AVI->v_codecf_off = header_offset + i+16;

	    memcpy(AVI->compressor2, hdrl_data+i+16, 4);
            AVI->compressor2[4] = 0;

         }
         else if(lasttag == 2)
         {
            WAVEFORMATEX_avilib *wfe;
	    char *nwfe;
            int wfes;

            if ((hdrl_len - i) < sizeof(WAVEFORMATEX_avilib))
              wfes = hdrl_len - i;
            else
              wfes = sizeof(WAVEFORMATEX_avilib);
            wfe = (WAVEFORMATEX_avilib *)malloc(sizeof(WAVEFORMATEX_avilib));
            if (wfe != NULL) {
              memset(wfe, 0, sizeof(WAVEFORMATEX_avilib));
	      memcpy(wfe, hdrl_data + i, wfes);
	      if (wfe->cb_size != 0) {
		nwfe = (char *)realloc(wfe, sizeof(WAVEFORMATEX_avilib) +
				       wfe->cb_size);
		if (nwfe != 0) {
		  off_t lpos = lseek(AVI->fdes, 0, SEEK_CUR);
		  lseek(AVI->fdes, header_offset + i + sizeof(WAVEFORMATEX_avilib),
			SEEK_SET);
		  wfe = (WAVEFORMATEX_avilib *)nwfe;
		  nwfe = &nwfe[sizeof(WAVEFORMATEX_avilib)];
		  avi_read(AVI->fdes, nwfe, wfe->cb_size);
		  lseek(AVI->fdes, lpos, SEEK_SET);
		}
	      }
	      AVI->wave_format_ex[AVI->aptr] = wfe;
	    }

            AVI->track[AVI->aptr].a_fmt   = str2ushort(hdrl_data+i  );

	    //ThOe
	    AVI->track[AVI->aptr].a_codecf_off = header_offset + i;

            AVI->track[AVI->aptr].a_chans = str2ushort(hdrl_data+i+2);
            AVI->track[AVI->aptr].a_rate  = str2ulong (hdrl_data+i+4);
	    //ThOe: read mp3bitrate
	    AVI->track[AVI->aptr].mp3rate = 8*str2ulong(hdrl_data+i+8)/1000;
	    //:ThOe
            AVI->track[AVI->aptr].a_bits  = str2ushort(hdrl_data+i+14);
	    //            auds_strf_seen = 1;
         }
         lasttag = 0;
      }
      else
      {
         i += 8;
         lasttag = 0;
      }

      i += n;
   }

   free(hdrl_data);

   if(!vids_strh_seen || !vids_strf_seen) ERR_EXIT(AVI_ERR_NO_VIDS)

   AVI->video_tag[0] = (char)(AVI->video_strn/10) + '0';
   AVI->video_tag[1] = (char)(AVI->video_strn%10) + '0';
   AVI->video_tag[2] = 'd';
   AVI->video_tag[3] = 'b';

   /* Audio tag is set to "99wb" if no audio present */
   if(!AVI->track[0].a_chans) AVI->track[0].audio_strn = 99;

   for(j=0; j<AVI->anum; ++j) {
     AVI->track[j].audio_tag[0] = (j+1)/10 + '0';
     AVI->track[j].audio_tag[1] = (j+1)%10 + '0';
     AVI->track[j].audio_tag[2] = 'w';
     AVI->track[j].audio_tag[3] = 'b';
   }

   lseek(AVI->fdes,AVI->movi_start,SEEK_SET);

   /* get index if wanted */

   if(!getIndex) return(0);

   /* if the file has an idx1, check if this is relative
      to the start of the file or to the start of the movi list */

   idx_type = 0;

   if(AVI->idx)
   {
      off_t pos, len;

      /* Search the first videoframe in the idx1 and look where
         it is in the file */

      for(i=0;i<AVI->n_idx;i++)
         if( strncasecmp((char *)AVI->idx[i],(char *)AVI->video_tag,3)==0 ) break;
      if(i>=AVI->n_idx) ERR_EXIT(AVI_ERR_NO_VIDS)

      pos = str2ulong(AVI->idx[i]+ 8);
      len = str2ulong(AVI->idx[i]+12);

      lseek(AVI->fdes,pos,SEEK_SET);
      if(avi_read(AVI->fdes,data,8)!=8) ERR_EXIT(AVI_ERR_READ)
      if( strncasecmp(data,(char *)AVI->idx[i],4)==0 && str2ulong((unsigned char *)data+4)==len )
      {
         idx_type = 1; /* Index from start of file */
      }
      else
      {
         lseek(AVI->fdes,pos+AVI->movi_start-4,SEEK_SET);
         if(avi_read(AVI->fdes,data,8)!=8) ERR_EXIT(AVI_ERR_READ)
         if( strncasecmp(data,(char *)AVI->idx[i],4)==0 && str2ulong((unsigned char *)data+4)==len )
         {
            idx_type = 2; /* Index from start of movi list */
         }
      }
      /* idx_type remains 0 if neither of the two tests above succeeds */
   }

   if(idx_type == 0)
   {
      /* we must search through the file to get the index */

      lseek(AVI->fdes, AVI->movi_start, SEEK_SET);

      AVI->n_idx = 0;

      while(1)
      {
         if( avi_read(AVI->fdes,data,8) != 8 ) break;
         n = str2ulong((unsigned char *)data+4);

         /* The movi list may contain sub-lists, ignore them */

         if(strncasecmp(data,"LIST",4)==0)
         {
            lseek(AVI->fdes,4,SEEK_CUR);
            continue;
         }

         /* Check if we got a tag ##db, ##dc or ##wb */

         if( ( (data[2]=='d' || data[2]=='D') &&
               (data[3]=='b' || data[3]=='B' || data[3]=='c' || data[3]=='C') )
	     || ( (data[2]=='w' || data[2]=='W') &&
		  (data[3]=='b' || data[3]=='B') ) )
	   {
	   avi_add_index_entry(AVI,(unsigned char *)data,0,lseek(AVI->fdes,0,SEEK_CUR)-8,n);
         }

         lseek(AVI->fdes,PAD_EVEN(n),SEEK_CUR);
      }
      idx_type = 1;
   }

   /* Now generate the video index and audio index arrays */

   nvi = 0;
   for(j=0; j<AVI->anum; ++j) nai[j] = 0;

   for(i=0;i<AVI->n_idx;i++) {

     if(strncasecmp((char *)AVI->idx[i],AVI->video_tag,3) == 0) nvi++;

     for(j=0; j<AVI->anum; ++j) if(strncasecmp((char *)AVI->idx[i], AVI->track[j].audio_tag,4) == 0) nai[j]++;
   }

   AVI->video_frames = nvi;
   for(j=0; j<AVI->anum; ++j) AVI->track[j].audio_chunks = nai[j];

//   fprintf(stderr, "chunks = %ld %d %s\n", AVI->track[0].audio_chunks, AVI->anum, AVI->track[0].audio_tag);

   if(AVI->video_frames==0) ERR_EXIT(AVI_ERR_NO_VIDS);
   AVI->video_index = (video_index_entry *) malloc(nvi*sizeof(video_index_entry));
   if(AVI->video_index==0) ERR_EXIT(AVI_ERR_NO_MEM);

   for(j=0; j<AVI->anum; ++j) {
       if(AVI->track[j].audio_chunks) {
	   AVI->track[j].audio_index = (audio_index_entry *) malloc((nai[j]+1)*sizeof(audio_index_entry));
	   memset(AVI->track[j].audio_index, 0, (nai[j]+1)*(sizeof(audio_index_entry)));
	   if(AVI->track[j].audio_index==0) ERR_EXIT(AVI_ERR_NO_MEM);
       }
   }

   nvi = 0;
   for(j=0; j<AVI->anum; ++j) nai[j] = tot[j] = 0;

   ioff = idx_type == 1 ? 8 : AVI->movi_start+4;

   for(i=0;i<AVI->n_idx;i++) {

     //video
     if(strncasecmp((char *)AVI->idx[i],AVI->video_tag,3) == 0) {
       AVI->video_index[nvi].key = str2ulong(AVI->idx[i]+ 4);
       AVI->video_index[nvi].pos = str2ulong(AVI->idx[i]+ 8)+ioff;
       AVI->video_index[nvi].len = str2ulong(AVI->idx[i]+12);
       nvi++;
     }

     //audio
     for(j=0; j<AVI->anum; ++j) {

       if(strncasecmp((char *)AVI->idx[i],AVI->track[j].audio_tag,4) == 0) {
	 AVI->track[j].audio_index[nai[j]].pos = str2ulong(AVI->idx[i]+ 8)+ioff;
	 AVI->track[j].audio_index[nai[j]].len = str2ulong(AVI->idx[i]+12);
	 AVI->track[j].audio_index[nai[j]].tot = tot[j];
	 tot[j] += AVI->track[j].audio_index[nai[j]].len;
	 nai[j]++;
       }
     }
   }


   for(j=0; j<AVI->anum; ++j) AVI->track[j].audio_bytes = tot[j];

   /* Reposition the file */

   lseek(AVI->fdes,AVI->movi_start,SEEK_SET);
   AVI->video_pos = 0;

   return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movl %esi, %ebp
movq %rdi, %rbx
movl (%rdi), %r14d
xorl %r15d, %r15d
leaq (%rsp,%r15), %rsi
addq $0xb0, %rsi
movl $0xc, %edx
subq %r15, %rdx
movl %r14d, %edi
callq 0x4825e0
testq %rax, %rax
jle 0x403c88
addq %rax, %r15
cmpq $0xb, %r15
jbe 0x402f67
cmpq $0xc, %r15
jne 0x403c88
leaq 0xd30c3(%rip), %rsi     # 0x4d6068
leaq 0xb0(%rsp), %rdi
movl $0x4, %edx
callq 0x401070
testl %eax, %eax
jne 0x402fd8
leaq 0xb8(%rsp), %rdi
leaq 0xd30a3(%rip), %rsi     # 0x4d606d
movl $0x4, %edx
callq 0x401070
testl %eax, %eax
je 0x402ff0
movq %rbx, %rdi
callq 0x40266b
movq $0x9, 0x118525(%rip) # 0x51b510
jmp 0x403c9b
xorl %r15d, %r15d
xorl %r13d, %r13d
movq $0x0, 0x30(%rsp)
movq %r15, %r12
movl (%rbx), %r15d
xorl %r14d, %r14d
leaq (%rsp,%r14), %rsi
addq $0xb0, %rsi
movl $0x8, %edx
subq %r14, %rdx
movl %r15d, %edi
callq 0x4825e0
testq %rax, %rax
jle 0x403246
addq %rax, %r14
cmpq $0x7, %r14
jbe 0x403008
cmpq $0x8, %r14
jne 0x403246
movslq 0xb4(%rsp), %r15
incq %r15
andq $-0x2, %r15
movl $0x4, %edx
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
leaq 0xd300d(%rip), %rsi     # 0x4d6072
callq 0x401070
testl %eax, %eax
je 0x40309e
movl $0x4, %edx
movq %r14, %rdi
leaq 0xd3051(%rip), %rsi     # 0x4d60ce
callq 0x401070
testl %eax, %eax
je 0x40314e
movl (%rbx), %edi
movq %r15, %rsi
movl $0x1, %edx
callq 0x482720
jmp 0x403002
movq %r12, 0x20(%rsp)
movl (%rbx), %r12d
xorl %r14d, %r14d
leaq (%rsp,%r14), %rsi
addq $0xb0, %rsi
movl $0x4, %edx
subq %r14, %rdx
movl %r12d, %edi
callq 0x4825e0
testq %rax, %rax
jle 0x403c88
addq %rax, %r14
cmpq $0x3, %r14
jbe 0x4030a9
cmpq $0x4, %r14
jne 0x403c88
addq $-0x4, %r15
movl $0x4, %edx
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
leaq 0xd2f7c(%rip), %rsi     # 0x4d6077
callq 0x401070
testl %eax, %eax
je 0x4031d7
movl $0x4, %edx
movq %r14, %rdi
leaq 0xd2fad(%rip), %rsi     # 0x4d60c4
callq 0x401070
movl (%rbx), %edi
testl %eax, %eax
jne 0x403137
xorl %esi, %esi
movl $0x1, %edx
callq 0x482720
movq %rax, 0x430(%rbx)
movl (%rbx), %edi
movq %r15, %rsi
movl $0x1, %edx
callq 0x482720
movq 0x20(%rsp), %r12
jmp 0x403002
movq %r12, 0x20(%rsp)
leaq 0xf(%r15), %rax
testq %r15, %r15
cmovnsq %r15, %rax
sarq $0x4, %rax
movq %rax, 0x3f0(%rbx)
movq %rax, 0x3e8(%rbx)
movq %r15, %rdi
callq 0x4458c0
movq %rax, 0x408(%rbx)
testq %rax, %rax
je 0x403bf4
movq %r13, 0x8(%rsp)
testq %r15, %r15
je 0x4031bc
movq %rax, %r12
movl (%rbx), %r13d
xorl %r14d, %r14d
leaq (%r12,%r14), %rsi
movq %r15, %rdx
subq %r14, %rdx
movl %r13d, %edi
callq 0x4825e0
testq %rax, %rax
jle 0x4031bf
addq %rax, %r14
cmpq %r15, %r14
jb 0x40319b
jmp 0x4031bf
xorl %r14d, %r14d
cmpq %r15, %r14
movq 0x8(%rsp), %r13
movq 0x20(%rsp), %r12
je 0x403002
jmp 0x403c88
movq %r15, %rdi
callq 0x4458c0
testq %rax, %rax
je 0x403bf4
movq %rax, %r14
movl (%rbx), %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x482720
movq %rax, 0x8(%rsp)
movl $0x0, %r13d
testq %r15, %r15
je 0x40322e
movl (%rbx), %r12d
xorl %r13d, %r13d
leaq (%r14,%r13), %rsi
movq %r15, %rdx
subq %r13, %rdx
movl %r12d, %edi
callq 0x4825e0
testq %rax, %rax
jle 0x40322e
addq %rax, %r13
cmpq %r15, %r13
jb 0x40320f
movq %r14, 0x30(%rsp)
cmpq %r15, %r13
movq 0x8(%rsp), %r13
je 0x402fff
jmp 0x403c88
movq 0x30(%rsp), %r14
testq %r14, %r14
je 0x4036b2
cmpq $0x0, 0x430(%rbx)
je 0x4036ca
testq %r12, %r12
jle 0x4036e2
movq %r13, 0x8(%rsp)
leaq 0x60(%rbx), %rax
movq %rax, 0x40(%rsp)
movq %r12, 0x20(%rsp)
leaq -0x8(%r12), %rax
movq %rax, 0x68(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
movl $0x0, 0x28(%rsp)
movl $0x0, 0x38(%rsp)
xorl %ecx, %ecx
movl %ecx, 0x18(%rsp)
movl %r15d, 0x10(%rsp)
movq %r12, %r13
movq 0x20(%rsp), %r12
leaq (%r14,%r13), %r15
movl $0x4, %edx
movq %r15, %rdi
leaq 0xd2dae(%rip), %rsi     # 0x4d6072
callq 0x401070
testl %eax, %eax
jne 0x4032db
addq $0xc, %r13
cmpq %r12, %r13
jl 0x4032b1
jmp 0x4036f2
movslq 0x4(%r14,%r13), %r12
movl $0x4, %edx
movq %r15, %rdi
leaq 0xd2d8d(%rip), %rsi     # 0x4d607c
callq 0x401070
testl %eax, %eax
je 0x403320
movl $0x4, %edx
movq %r15, %rdi
leaq 0xd2d7f(%rip), %rsi     # 0x4d6086
callq 0x401070
leaq 0x8(%r13), %rdx
xorl %ecx, %ecx
testl %eax, %eax
je 0x40336e
movl 0x10(%rsp), %r15d
jmp 0x40369b
leaq (%r14,%r13), %r15
addq $0x8, %r15
movl $0x4, %edx
movq %r15, %rdi
leaq 0xd2d4a(%rip), %rsi     # 0x4d6081
callq 0x401070
orl 0x38(%rsp), %eax
je 0x4034b0
movl $0x4, %edx
movq %r15, %rdi
leaq 0xd2d36(%rip), %rsi     # 0x4d608b
callq 0x401070
xorl %ecx, %ecx
testl %eax, %eax
je 0x403592
movl 0x10(%rsp), %r15d
jmp 0x403612
movl 0x18(%rsp), %eax
cmpl $0x1, %eax
movl 0x10(%rsp), %r15d
je 0x403521
cmpl $0x2, %eax
jne 0x40369b
movq %rdx, 0x48(%rsp)
movl $0x1, %edi
movl $0x14, %esi
callq 0x446d10
testq %rax, %rax
je 0x40361e
movq %rax, %rcx
movq 0x68(%rsp), %rdx
subq %r13, %rdx
cmpq $0x14, %rdx
movl $0x14, %eax
cmovaeq %rax, %rdx
leaq (%r14,%r13), %rsi
addq $0x8, %rsi
movq %rcx, 0x18(%rsp)
movq 0x18(%rsp), %rdi
callq 0x401058
movq 0x18(%rsp), %rcx
movzwl 0x10(%rcx), %esi
testq %rsi, %rsi
je 0x40349c
addq $0x14, %rsi
movq 0x18(%rsp), %rdi
callq 0x445f50
movq 0x18(%rsp), %rcx
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x40349c
movl (%rbx), %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x482720
movq %rax, 0x58(%rsp)
movl (%rbx), %edi
movq 0x8(%rsp), %rax
leaq (%rax,%r13), %rsi
addq $0x1c, %rsi
xorl %edx, %edx
callq 0x482720
movl (%rbx), %eax
movl %eax, 0x18(%rsp)
movq 0x50(%rsp), %rax
movzwl 0x10(%rax), %r15d
testq %r15, %r15
je 0x40347d
addq $0x14, %rax
movq %rax, 0x60(%rsp)
xorl %r14d, %r14d
movq 0x60(%rsp), %rax
leaq (%rax,%r14), %rsi
movq %r15, %rdx
subq %r14, %rdx
movl 0x18(%rsp), %edi
callq 0x4825e0
testq %rax, %rax
jle 0x403477
addq %rax, %r14
cmpq %r15, %r14
jb 0x403452
movl (%rbx), %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %edi
movq 0x58(%rsp), %rsi
xorl %edx, %edx
callq 0x482720
movq 0x50(%rsp), %rcx
movq 0x30(%rsp), %r14
movl 0x10(%rsp), %r15d
movslq 0x43c(%rbx), %rax
movq %rcx, 0x448(%rbx,%rax,8)
jmp 0x403625
movl 0xc(%r14,%r13), %eax
movl %eax, 0x28(%rbx)
movb $0x0, 0x2c(%rbx)
movq 0x8(%rsp), %rax
addq %r13, %rax
addq $0xc, %rax
movq %rax, 0x3f8(%rbx)
movl 0x1c(%r14,%r13), %eax
testl %eax, %eax
je 0x4034f2
xorps %xmm0, %xmm0
cvtsi2sdl 0x20(%r14,%r13), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rbx)
movslq 0x28(%r14,%r13), %rax
movq %rax, 0x40(%rbx)
movl 0x10(%rsp), %r15d
movslq %r15d, %rax
movq %rax, 0x38(%rbx)
movq $0x0, 0x58(%rbx)
movl $0x1, %ecx
movl $0x1, 0x38(%rsp)
jmp 0x403612
movq %rdx, 0x48(%rsp)
movl 0x8(%r14,%r13), %edi
movq %rdi, 0x28(%rsp)
callq 0x4458c0
movq %rax, 0x440(%rbx)
testq %rax, %rax
je 0x403556
leaq (%r14,%r13), %rsi
addq $0x8, %rsi
movq %rax, %rdi
movq 0x28(%rsp), %rdx
callq 0x401058
movslq 0xc(%r14,%r13), %rax
movq %rax, 0x10(%rbx)
movslq 0x10(%r14,%r13), %rax
movq %rax, 0x18(%rbx)
movq 0x8(%rsp), %rax
leaq 0x18(%rax,%r13), %rax
movq %rax, 0x400(%rbx)
movl 0x18(%r14,%r13), %eax
movl %eax, 0x30(%rbx)
movb $0x0, 0x34(%rbx)
movl $0x1, 0x28(%rsp)
jmp 0x403694
movslq 0x438(%rbx), %rax
leal 0x1(%rax), %ecx
movl %eax, 0x43c(%rbx)
movl %ecx, 0x438(%rbx)
cmpq $0x8, %rax
movl 0x10(%rsp), %r15d
jge 0x403dc0
movq 0x78(%rbx), %rcx
leaq 0x7(%rcx), %rdx
addq $0xe, %rcx
testq %rdx, %rdx
cmovnsq %rdx, %rcx
shrq $0x3, %rcx
imull 0x68(%rbx), %ecx
movslq 0x28(%r14,%r13), %rdx
cmpl $0x5, %ecx
movl $0x4, %esi
cmovll %esi, %ecx
imulq %rdx, %rcx
imulq $0x70, %rax, %rax
movq 0x40(%rsp), %rdx
movq %rcx, 0x30(%rdx,%rax)
movslq %r15d, %rcx
movq %rcx, 0x28(%rdx,%rax)
movq 0x8(%rsp), %rcx
addq %r13, %rcx
addq $0x8, %rcx
movq %rcx, 0x58(%rdx,%rax)
movl $0x2, %ecx
addq $0x8, %r13
incl %r15d
movq %r13, %rdx
jmp 0x40369b
movslq 0x43c(%rbx), %rax
imulq $0x70, %rax, %rcx
movq 0x8(%rsp), %rax
addq %r13, %rax
addq $0x8, %rax
movq 0x40(%rsp), %rsi
movq %rax, 0x60(%rsi,%rcx)
movd 0x8(%r14,%r13), %xmm0
pxor %xmm1, %xmm1
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movdqu %xmm0, (%rsi,%rcx)
movslq 0xc(%r14,%r13), %rax
movq %rax, 0x10(%rsi,%rcx)
movslq 0x10(%r14,%r13), %rax
movabsq $0x1fffffffffffffff, %rdx # imm = 0x1FFFFFFFFFFFFFFF
andq %rdx, %rax
movabsq $0x20c49ba5e353f7cf, %rdx # imm = 0x20C49BA5E353F7CF
mulq %rdx
shrq $0x4, %rdx
movq %rdx, 0x20(%rsi,%rcx)
movzwl 0x16(%r14,%r13), %eax
movq %rax, 0x18(%rsi,%rcx)
xorl %ecx, %ecx
movq 0x48(%rsp), %rdx
incq %r12
andq $-0x2, %r12
addq %rdx, %r12
cmpq 0x20(%rsp), %r12
jl 0x4032a0
jmp 0x4036f2
movq %rbx, %rdi
callq 0x40266b
movq $0xa, 0x117e4b(%rip) # 0x51b510
jmp 0x403c9b
movq %rbx, %rdi
callq 0x40266b
movq $0xb, 0x117e33(%rip) # 0x51b510
jmp 0x403c9b
movl $0x0, 0x38(%rsp)
movl $0x0, 0x28(%rsp)
movq %r14, %rdi
callq 0x445c00
cmpl $0x0, 0x38(%rsp)
setne %al
cmpl $0x0, 0x28(%rsp)
setne %cl
testb %cl, %al
je 0x403bdc
movq 0x38(%rbx), %rcx
movabsq $0x6666666666666667, %rdx # imm = 0x6666666666666667
movq %rcx, %rax
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x2, %rdx
addq %rax, %rdx
leal 0x30(%rdx), %eax
movb %al, 0x48(%rbx)
addl %edx, %edx
leal (%rdx,%rdx,4), %eax
subl %eax, %ecx
addb $0x30, %cl
movb %cl, 0x49(%rbx)
movw $0x6264, 0x4a(%rbx)     # imm = 0x6264
cmpq $0x0, 0x68(%rbx)
jne 0x40375f
movq $0x63, 0x88(%rbx)
movslq 0x438(%rbx), %rax
testq %rax, %rax
jle 0x4037c0
imulq $0x70, %rax, %rax
movb $0x31, %cl
movl $0x1, %edx
xorl %esi, %esi
movl $0xcccccccd, %edi       # imm = 0xCCCCCCCD
movl %edx, %r8d
imulq %rdi, %r8
shrq $0x23, %r8
leal 0x30(%r8), %r9d
addl %r8d, %r8d
leal (%r8,%r8,4), %r8d
movl %ecx, %r10d
subb %r8b, %r10b
movb %r9b, 0xa0(%rbx,%rsi)
movb %r10b, 0xa1(%rbx,%rsi)
movw $0x6277, 0xa2(%rbx,%rsi) # imm = 0x6277
addq $0x70, %rsi
incb %cl
incl %edx
cmpq %rsi, %rax
jne 0x40377d
movl (%rbx), %edi
movq 0x430(%rbx), %rsi
xorl %r15d, %r15d
xorl %edx, %edx
callq 0x482720
testl %ebp, %ebp
je 0x403c9e
leaq 0x48(%rbx), %rax
movq %rax, 0x20(%rsp)
movq 0x408(%rbx), %r12
testq %r12, %r12
je 0x403cb3
movq 0x3e8(%rbx), %r13
testq %r13, %r13
jle 0x403826
xorl %r14d, %r14d
movl $0x3, %edx
movq %r12, %rdi
movq 0x20(%rsp), %rsi
callq 0x401070
testl %eax, %eax
je 0x40383e
addq $0x10, %r12
addq $-0x10, %r14
decq %r13
jne 0x403803
movq %rbx, %rdi
callq 0x40266b
movq $0xc, 0x117cd7(%rip) # 0x51b510
jmp 0x403c9e
movslq 0x8(%r12), %r15
movl 0xc(%r12), %r12d
movl (%rbx), %edi
xorl %r13d, %r13d
movq %r15, %rsi
xorl %edx, %edx
callq 0x482720
movl (%rbx), %ebp
leaq (%rsp,%r13), %rsi
addq $0xb0, %rsi
movl $0x8, %edx
subq %r13, %rdx
movl %ebp, %edi
callq 0x4825e0
testq %rax, %rax
jle 0x403c88
addq %rax, %r13
cmpq $0x7, %r13
jbe 0x403859
cmpq $0x8, %r13
jne 0x403c88
movq 0x408(%rbx), %rsi
subq %r14, %rsi
leaq 0xb0(%rsp), %rdi
movl $0x4, %edx
callq 0x401070
testl %eax, %eax
jne 0x403c0c
movb $0x1, %cl
cmpl %r12d, 0xb4(%rsp)
jne 0x403c0c
movl %ecx, 0x10(%rsp)
movl 0x438(%rbx), %ebp
testl %ebp, %ebp
jle 0x4038e5
leaq (,%rbp,8), %rdx
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
callq 0x4010e0
movq 0x3e8(%rbx), %rax
movq %rax, 0x38(%rsp)
testq %rax, %rax
jle 0x403984
movq 0x408(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0xa0(%rbx), %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
xorl %r14d, %r14d
movq %r13, %r15
shlq $0x4, %r15
addq 0x28(%rsp), %r15
movl $0x3, %edx
movq %r15, %rdi
movq 0x20(%rsp), %rsi
callq 0x401070
cmpl $0x1, %eax
adcq $0x0, %r14
movq %r14, 0x30(%rsp)
testl %ebp, %ebp
jle 0x403973
movq 0x8(%rsp), %r12
xorl %r14d, %r14d
movl $0x4, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x401070
testl %eax, %eax
jne 0x403967
incq 0x70(%rsp,%r14,8)
incq %r14
addq $0x70, %r12
cmpq %r14, %rbp
jne 0x40394e
incq %r13
cmpq 0x38(%rsp), %r13
movq 0x30(%rsp), %r14
jne 0x403918
jmp 0x403987
xorl %r14d, %r14d
movq %r14, 0x40(%rbx)
testl %ebp, %ebp
jle 0x4039ac
leaq 0x98(%rbx), %rax
xorl %ecx, %ecx
movq 0x70(%rsp,%rcx,8), %rdx
movq %rdx, (%rax)
incq %rcx
addq $0x70, %rax
cmpq %rcx, %rbp
jne 0x403998
testq %r14, %r14
je 0x403bdc
shlq $0x3, %r14
leaq (%r14,%r14,2), %rdi
callq 0x4458c0
movq %rax, 0x410(%rbx)
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x403bf4
testl %ebp, %ebp
movl 0x10(%rsp), %ecx
jle 0x403a58
leaq 0x98(%rbx), %r14
xorl %r15d, %r15d
cmpq $0x0, (%r14)
je 0x403a1b
movq 0x70(%rsp,%r15,8), %rax
leaq (%rax,%rax,2), %rax
leaq 0x18(,%rax,8), %rsi
movl $0x1, %edi
callq 0x446d10
movl 0x10(%rsp), %ecx
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x403bf4
incq %r15
addq $0x70, %r14
cmpq %r15, %rbp
jne 0x4039e9
testl %ebp, %ebp
jle 0x403a58
leaq (,%rbp,8), %r12
leaq 0x1b0(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x4010e0
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x4010e0
movl 0x10(%rsp), %ecx
movl $0x8, %eax
movq %rax, 0x30(%rsp)
testb %cl, %cl
jne 0x403a76
movq 0x430(%rbx), %rax
addq $0x4, %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x38(%rsp)
jle 0x403b98
movq 0x408(%rbx), %r15
leaq 0xa0(%rbx), %rax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
movq $0x0, 0x10(%rsp)
movq %r15, 0x8(%rsp)
movq %r13, %r14
shlq $0x4, %r14
leaq (%r15,%r14), %r12
movl $0x3, %edx
movq %r12, %rdi
movq 0x20(%rsp), %rsi
callq 0x401070
testl %eax, %eax
movq %r13, 0x28(%rsp)
jne 0x403b04
movslq 0x4(%r12), %rax
movq 0x10(%rsp), %rsi
leaq (%rsi,%rsi,2), %rcx
movq 0x40(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
movslq 0x8(%r15,%r14), %rax
addq 0x30(%rsp), %rax
movq %rax, 0x8(%rdx,%rcx,8)
movslq 0xc(%r15,%r14), %rax
movq %rax, 0x10(%rdx,%rcx,8)
incq %rsi
movq %rsi, 0x10(%rsp)
testl %ebp, %ebp
jle 0x403b80
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %r15
addq $0xc, %r15
movq 0x18(%rsp), %r13
xorl %r14d, %r14d
movl $0x4, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x401070
testl %eax, %eax
jne 0x403b74
movslq 0x8(%r12), %rax
addq 0x30(%rsp), %rax
movq 0x28(%r13), %rcx
movq 0x70(%rsp,%r14,8), %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, (%rcx,%rsi,8)
movslq (%r15), %rax
movq %rax, 0x8(%rcx,%rsi,8)
movq 0x1b0(%rsp,%r14,8), %rdi
movq %rdi, 0x10(%rcx,%rsi,8)
addq %rax, %rdi
movq %rdi, 0x1b0(%rsp,%r14,8)
incq %rdx
movq %rdx, 0x70(%rsp,%r14,8)
incq %r14
addq $0x70, %r13
cmpq %r14, %rbp
jne 0x403b1d
movq 0x28(%rsp), %r13
incq %r13
cmpq 0x38(%rsp), %r13
movq 0x8(%rsp), %r15
jne 0x403aa6
testl %ebp, %ebp
jle 0x403bbc
leaq 0x90(%rbx), %rax
xorl %ecx, %ecx
movq 0x1b0(%rsp,%rcx,8), %rdx
movq %rdx, (%rax)
incq %rcx
addq $0x70, %rax
cmpq %rcx, %rbp
jne 0x403ba5
movl (%rbx), %edi
movq 0x430(%rbx), %rsi
xorl %r15d, %r15d
xorl %edx, %edx
callq 0x482720
movq $0x0, 0x50(%rbx)
jmp 0x403c9e
movq %rbx, %rdi
callq 0x40266b
movq $0xc, 0x117921(%rip) # 0x51b510
jmp 0x403c9b
movq %rbx, %rdi
callq 0x40266b
movq $0x8, 0x117909(%rip) # 0x51b510
jmp 0x403c9b
movl (%rbx), %edi
movq 0x430(%rbx), %rax
leaq (%r15,%rax), %rsi
addq $-0x4, %rsi
xorl %r15d, %r15d
xorl %edx, %edx
callq 0x482720
movl (%rbx), %ebp
leaq (%rsp,%r15), %rsi
addq $0xb0, %rsi
movl $0x8, %edx
subq %r15, %rdx
movl %ebp, %edi
callq 0x4825e0
testq %rax, %rax
jle 0x403c88
addq %rax, %r15
cmpq $0x7, %r15
jbe 0x403c29
cmpq $0x8, %r15
jne 0x403c88
movq 0x408(%rbx), %rsi
subq %r14, %rsi
leaq 0xb0(%rsp), %rdi
movl $0x4, %edx
callq 0x401070
testl %eax, %eax
jne 0x403cb3
cmpl %r12d, 0xb4(%rsp)
jne 0x403cb3
xorl %ecx, %ecx
jmp 0x4038c3
movq %rbx, %rdi
callq 0x40266b
movq $0x3, 0x117875(%rip) # 0x51b510
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%rbx), %edi
movq 0x430(%rbx), %rsi
xorl %edx, %edx
callq 0x482720
movq $0x0, 0x3e8(%rbx)
leaq 0xd239d(%rip), %r15     # 0x4d6072
leaq 0xb0(%rsp), %r12
movabsq $0x300000003, %r14      # imm = 0x300000003
movl (%rbx), %ebp
xorl %r13d, %r13d
leaq (%rsp,%r13), %rsi
addq $0xb0, %rsi
movl $0x8, %edx
subq %r13, %rdx
movl %ebp, %edi
callq 0x4825e0
movb $0x1, %cl
testq %rax, %rax
jle 0x4038c3
addq %rax, %r13
cmpq $0x7, %r13
jbe 0x403cec
cmpq $0x8, %r13
jne 0x4038c3
movslq 0xb4(%rsp), %r13
movl $0x4, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x401070
testl %eax, %eax
je 0x403d9b
movzbl 0xb2(%rsp), %eax
andl $-0x21, %eax
cmpl $0x57, %eax
je 0x403db1
cmpl $0x44, %eax
jne 0x403d8d
movzbl 0xb3(%rsp), %eax
addl $-0x42, %eax
cmpl $0x21, %eax
ja 0x403d8d
btq %rax, %r14
jae 0x403d8d
movl (%rbx), %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x482720
leaq -0x8(%rax), %rcx
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %r13, %r8
callq 0x4023a4
movl (%rbx), %edi
incq %r13
andq $-0x2, %r13
movq %r13, %rsi
jmp 0x403da2
movl (%rbx), %edi
movl $0x4, %esi
movl $0x1, %edx
callq 0x482720
jmp 0x403ce7
movb 0xb3(%rsp), %al
andb $-0x21, %al
cmpb $0x42, %al
je 0x403d6b
jmp 0x403d8d
callq 0x401249
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x403c9e