// File: /workspace/github_c_makefile_star2_O2/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 $0x1e8, %rsp            # imm = 0x1E8
movl %esi, %ebp
movq %rdi, %rbx
movl (%rdi), %edi
leaq 0xa0(%rsp), %rsi
pushq $0xc
popq %rdx
callq 0x403c91
cmpq $0xc, %rax
jne 0x4031ed
leaq 0xcf068(%rip), %rsi     # 0x4d2068
leaq 0xa0(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x401078
testl %eax, %eax
jne 0x40302f
leaq 0xa8(%rsp), %rdi
leaq 0xcf04a(%rip), %rsi     # 0x4d206d
pushq $0x4
popq %rdx
callq 0x401078
testl %eax, %eax
je 0x403047
movq %rbx, %rdi
callq 0x40263d
movq $0x9, 0x1154ee(%rip) # 0x518530
jmp 0x403200
movl %ebp, 0x30(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0xa0(%rsp), %r13
pushq $0x8
popq %rax
movq %rax, 0x48(%rsp)
leaq 0xcf007(%rip), %r15     # 0x4d2072
pushq $0x4
popq %r12
leaq 0xcf001(%rip), %r14     # 0x4d2077
movq $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
movl (%rbx), %edi
movq %r13, %rsi
pushq $0x8
popq %rdx
callq 0x403c91
cmpq $0x8, %rax
jne 0x403216
movslq 0xa4(%rsp), %rbp
incq %rbp
andq $-0x2, %rbp
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x401078
testl %eax, %eax
je 0x4030d9
movq %r13, %rdi
leaq 0xcf005(%rip), %rsi     # 0x4d20ce
movq %r12, %rdx
callq 0x401078
testl %eax, %eax
je 0x403132
movl (%rbx), %edi
jmp 0x403122
movl (%rbx), %edi
movq %r13, %rsi
movq %r12, %rdx
callq 0x403c91
cmpq $0x4, %rax
jne 0x4031ed
addq $-0x4, %rbp
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x401078
testl %eax, %eax
je 0x4031a9
movq %r13, %rdi
leaq 0xcefb0(%rip), %rsi     # 0x4d20c4
movq %r12, %rdx
callq 0x401078
movl (%rbx), %edi
testl %eax, %eax
je 0x40317b
movq %rbp, %rsi
pushq $0x1
popq %rdx
callq 0x47efe0
jmp 0x403087
movq %rbp, %rax
cqto
pushq $0x10
popq %rcx
idivq %rcx
movq %rax, 0x3f0(%rbx)
movq %rax, 0x3e8(%rbx)
movq %rbp, %rdi
callq 0x442160
movq %rax, 0x408(%rbx)
testq %rax, %rax
je 0x403a59
movl (%rbx), %edi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x403c91
cmpq %rbp, %rax
je 0x403087
jmp 0x4031ed
xorl %esi, %esi
pushq $0x1
popq %r14
movl %r14d, %edx
callq 0x47efe0
movq %rax, 0x430(%rbx)
movl (%rbx), %edi
movq %rbp, %rsi
movl %r14d, %edx
leaq 0xceed8(%rip), %r14     # 0x4d2077
callq 0x47efe0
jmp 0x403087
movq %rbp, %rdi
callq 0x442160
testq %rax, %rax
je 0x403a59
movl (%rbx), %edi
xorl %esi, %esi
pushq $0x1
popq %rdx
movq %rax, %r14
callq 0x47efe0
movq %rax, 0x8(%rsp)
movl (%rbx), %edi
movq %r14, (%rsp)
movq %r14, %rsi
leaq 0xcee99(%rip), %r14     # 0x4d2077
movq %rbp, %rdx
callq 0x403c91
movq %rbp, 0x20(%rsp)
jmp 0x403170
movq %rbx, %rdi
callq 0x40263d
movq $0x3, 0x115330(%rip) # 0x518530
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %r8
testq %r8, %r8
je 0x4036c8
cmpq $0x0, 0x430(%rbx)
je 0x4036e0
leaq 0x60(%rbx), %rax
movq %rax, 0x50(%rsp)
movq 0x20(%rsp), %rax
addq $-0x8, %rax
movq %rax, 0x58(%rsp)
movq $0x0, 0x10(%rsp)
leaq 0xcee1a(%rip), %rbp     # 0x4d2072
pushq $0x4
popq %r13
movl $0x0, 0x28(%rsp)
movl $0x0, 0x18(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
cmpq 0x20(%rsp), %r15
jge 0x40360e
leaq (%r8,%r15), %r14
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x401078
testl %eax, %eax
jne 0x40329d
addq $0xc, %r15
movq (%rsp), %r8
jmp 0x403272
movq (%rsp), %rbp
movslq 0x4(%rbp,%r15), %rax
movq %rax, 0x40(%rsp)
movq %r14, %rdi
leaq 0xcedc7(%rip), %rsi     # 0x4d207c
movq %r13, %rdx
callq 0x401078
testl %eax, %eax
je 0x4032ee
movq %r14, %rdi
leaq 0xcedbb(%rip), %rsi     # 0x4d2086
movq %r13, %rdx
callq 0x401078
leaq 0x8(%r15), %rcx
xorl %r14d, %r14d
testl %eax, %eax
je 0x403344
movq (%rsp), %r8
leaq 0xced89(%rip), %rbp     # 0x4d2072
jmp 0x4035f7
leaq (%r15,%rbp), %r14
addq $0x8, %r14
movq %r14, %rdi
leaq 0xced81(%rip), %rsi     # 0x4d2081
movq %r13, %rdx
callq 0x401078
orl 0x18(%rsp), %eax
movslq 0x10(%rsp), %r12
je 0x403425
movq %r14, %rdi
leaq 0xced6a(%rip), %rsi     # 0x4d208b
movq %r13, %rdx
callq 0x401078
xorl %r14d, %r14d
testl %eax, %eax
leaq 0xced3d(%rip), %rbp     # 0x4d2072
je 0x4034fe
movq (%rsp), %r8
jmp 0x403570
movq (%rsp), %r8
leaq (%r8,%r15), %rax
addq $0x8, %rax
cmpl $0x1, %r12d
leaq 0xced17(%rip), %rbp     # 0x4d2072
je 0x40348c
cmpl $0x2, %r12d
jne 0x4035f7
movq %rax, %r12
movq %rcx, 0x38(%rsp)
pushq $0x1
popq %rdi
pushq $0x14
popq %r14
movq %r14, %rsi
callq 0x4435b0
testq %rax, %rax
je 0x403585
movq 0x58(%rsp), %rdx
subq %r15, %rdx
cmpq $0x14, %rdx
cmovaeq %r14, %rdx
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
callq 0x401060
movzwl 0x10(%r14), %esi
testq %rsi, %rsi
je 0x40340e
addq $0x14, %rsi
movq %r14, %rdi
callq 0x4427f0
movq %r14, %rcx
testq %rax, %rax
je 0x403411
movq %rax, %r14
movl (%rbx), %edi
xorl %esi, %esi
pushq $0x1
popq %rdx
callq 0x47efe0
movq %rax, %r12
movl (%rbx), %edi
movq 0x8(%rsp), %rax
leaq (%rax,%r15), %rsi
addq $0x1c, %rsi
xorl %edx, %edx
callq 0x47efe0
movq %r14, %rsi
addq $0x14, %rsi
movl (%rbx), %edi
movzwl 0x10(%r14), %edx
callq 0x403c91
movl (%rbx), %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x47efe0
movq %r14, %rcx
movslq 0x43c(%rbx), %rax
movq %rcx, 0x448(%rbx,%rax,8)
jmp 0x40358c
movl 0xc(%rbp,%r15), %eax
movl %eax, 0x28(%rbx)
movb $0x0, 0x2c(%rbx)
movq 0x8(%rsp), %rax
addq %r15, %rax
addq $0xc, %rax
movq %rax, 0x3f8(%rbx)
movl 0x1c(%rbp,%r15), %eax
testl %eax, %eax
movq %rbp, %r8
je 0x403464
cvtsi2sdl 0x20(%r8,%r15), %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rbx)
movslq 0x28(%r8,%r15), %rax
movq %rax, 0x40(%rbx)
movq %r12, 0x38(%rbx)
andq $0x0, 0x58(%rbx)
pushq $0x1
popq %rax
movl %eax, %r14d
movl %eax, 0x18(%rsp)
leaq 0xcebeb(%rip), %rbp     # 0x4d2072
jmp 0x403570
movq %rax, 0x28(%rsp)
movq %rcx, 0x38(%rsp)
movl 0x8(%r8,%r15), %edi
movq %rdi, %r12
callq 0x442160
movq %rax, 0x440(%rbx)
testq %rax, %rax
je 0x4034bf
movq %rax, %rdi
movq 0x28(%rsp), %rsi
movq %r12, %rdx
callq 0x401060
movq (%rsp), %r8
movslq 0xc(%r8,%r15), %rax
movq %rax, 0x10(%rbx)
movslq 0x10(%r8,%r15), %rax
movq %rax, 0x18(%rbx)
movq 0x8(%rsp), %rax
leaq 0x18(%rax,%r15), %rax
movq %rax, 0x400(%rbx)
movl 0x18(%r8,%r15), %eax
movl %eax, 0x30(%rbx)
movb $0x0, 0x34(%rbx)
pushq $0x1
popq %rax
movl %eax, 0x28(%rsp)
jmp 0x4035f2
movslq 0x438(%rbx), %rcx
leal 0x1(%rcx), %eax
movl %ecx, 0x43c(%rbx)
movl %eax, 0x438(%rbx)
cmpq $0x8, %rcx
movq (%rsp), %r8
jge 0x403c1c
movslq 0x28(%r8,%r15), %rsi
movq 0x78(%rbx), %rax
addq $0x7, %rax
cqto
pushq $0x8
popq %rdi
idivq %rdi
imull 0x68(%rbx), %eax
cmpl $0x5, %eax
pushq $0x4
popq %rdx
cmovll %edx, %eax
imulq %rsi, %rax
imulq $0x70, %rcx, %rcx
movq 0x50(%rsp), %rdx
movq %rax, 0x30(%rdx,%rcx)
movq %r12, 0x28(%rdx,%rcx)
movq 0x8(%rsp), %rax
leaq 0x8(%rax,%r15), %rax
movq %rax, 0x58(%rdx,%rcx)
pushq $0x2
popq %rax
movl %eax, %r14d
addq $0x8, %r15
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
movq %r15, %rcx
jmp 0x4035f7
movslq 0x43c(%rbx), %rax
imulq $0x70, %rax, %rcx
movq 0x8(%rsp), %rax
addq %r15, %rax
addq $0x8, %rax
movq 0x50(%rsp), %rsi
movq %rax, 0x60(%rsi,%rcx)
movq (%rsp), %r8
movd 0x8(%r8,%r15), %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(%r8,%r15), %rax
movq %rax, 0x10(%rsi,%rcx)
movslq 0x10(%r8,%r15), %rax
shlq $0x3, %rax
xorl %r14d, %r14d
xorl %edx, %edx
movl $0x3e8, %edi            # imm = 0x3E8
divq %rdi
movq %rax, 0x20(%rsi,%rcx)
movzwl 0x16(%r8,%r15), %eax
movq %rax, 0x18(%rsi,%rcx)
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %r15
incq %r15
andq $-0x2, %r15
addq %rcx, %r15
movl %r14d, %r12d
jmp 0x403272
movq %r8, %rdi
callq 0x4424a0
cmpl $0x0, 0x18(%rsp)
setne %al
cmpl $0x0, 0x28(%rsp)
setne %cl
testb %cl, %al
je 0x403a71
movq 0x38(%rbx), %rax
pushq $0xa
popq %rcx
cqto
idivq %rcx
addb $0x30, %al
movb %al, 0x48(%rbx)
addb $0x30, %dl
movb %dl, 0x49(%rbx)
movw $0x6264, 0x4a(%rbx)     # imm = 0x6264
cmpq $0x0, 0x68(%rbx)
jne 0x40365d
movq $0x63, 0x88(%rbx)
leaq 0x48(%rbx), %rax
movq %rax, 0x18(%rsp)
movl 0x438(%rbx), %eax
xorl %esi, %esi
testl %eax, %eax
cmovlel %esi, %eax
imulq $0x70, %rax, %rdi
movb $0x31, %r8b
pushq $0x1
popq %rcx
pushq $0xa
popq %r9
movl 0x30(%rsp), %r14d
movl %ecx, %eax
xorl %edx, %edx
divl %r9d
cmpq %rsi, %rdi
je 0x4036f8
imull $0xa, %eax, %eax
movl %r8d, %r10d
subb %al, %r10b
movl %ecx, %eax
xorl %edx, %edx
divl %r9d
addb $0x30, %al
movb %al, 0xa0(%rbx,%rsi)
movb %r10b, 0xa1(%rbx,%rsi)
movw $0x6277, 0xa2(%rbx,%rsi) # imm = 0x6277
addq $0x70, %rsi
incb %r8b
incl %ecx
jmp 0x403686
movq %rbx, %rdi
callq 0x40263d
movq $0xa, 0x114e55(%rip) # 0x518530
jmp 0x403200
movq %rbx, %rdi
callq 0x40263d
movq $0xb, 0x114e3d(%rip) # 0x518530
jmp 0x403200
movl (%rbx), %edi
movq 0x430(%rbx), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x47efe0
testl %r14d, %r14d
je 0x403202
movq 0x408(%rbx), %r15
testq %r15, %r15
je 0x403825
movq 0x3e8(%rbx), %r13
xorl %r12d, %r12d
testq %r13, %r13
cmovleq %r12, %r13
pushq $0x3
popq %r14
subq $0x1, %r13
jb 0x403a71
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
callq 0x401078
testl %eax, %eax
je 0x403760
addq $0x10, %r15
addq $-0x10, %r12
jmp 0x403738
movslq 0x8(%r15), %r14
movl 0xc(%r15), %r15d
movl (%rbx), %edi
xorl %ebp, %ebp
movq %r14, %rsi
xorl %edx, %edx
callq 0x47efe0
movl (%rbx), %edi
leaq 0xa0(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x403c91
cmpq $0x8, %rax
jne 0x403a89
movq 0x408(%rbx), %rsi
subq %r12, %rsi
leaq 0xa0(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x401078
testl %eax, %eax
jne 0x4037c0
movb $0x1, %al
cmpl %r15d, 0xa4(%rsp)
je 0x40390b
movl (%rbx), %edi
movq 0x430(%rbx), %rax
leaq (%r14,%rax), %rsi
addq $-0x4, %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x47efe0
movl (%rbx), %edi
leaq 0xa0(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x403c91
cmpq $0x8, %rax
jne 0x403a89
movq 0x408(%rbx), %rsi
subq %r12, %rsi
leaq 0xa0(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x401078
testl %eax, %eax
jne 0x403825
cmpl %r15d, 0xa4(%rsp)
jne 0x403825
xorl %eax, %eax
jmp 0x40390b
movl (%rbx), %edi
movq 0x430(%rbx), %rsi
xorl %edx, %edx
callq 0x47efe0
andq $0x0, 0x3e8(%rbx)
leaq 0xa0(%rsp), %r14
pushq $0x8
popq %r12
pushq $0x4
popq %rbp
pushq $0x1
popq %r15
movl (%rbx), %edi
movq %r14, %rsi
movq %r12, %rdx
callq 0x403c91
cmpq $0x8, %rax
jne 0x403909
movslq 0xa4(%rsp), %r13
movq %r14, %rdi
leaq 0xce7f9(%rip), %rsi     # 0x4d2072
movq %rbp, %rdx
callq 0x401078
testl %eax, %eax
je 0x4038e8
movzbl 0xa2(%rsp), %eax
andl $-0x21, %eax
cmpl $0x57, %eax
je 0x4038fa
cmpl $0x44, %eax
jne 0x4038da
movzbl 0xa3(%rsp), %eax
addl $-0x42, %eax
cmpl $0x21, %eax
ja 0x4038da
movabsq $0x300000003, %rcx      # imm = 0x300000003
btq %rax, %rcx
jae 0x4038da
movl (%rbx), %edi
xorl %esi, %esi
movl %r15d, %edx
callq 0x47efe0
leaq -0x8(%rax), %rcx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %r13, %r8
callq 0x4023ba
movl (%rbx), %edi
incq %r13
andq $-0x2, %r13
movq %r13, %rsi
jmp 0x4038ed
movl (%rbx), %edi
movq %rbp, %rsi
movl %r15d, %edx
callq 0x47efe0
jmp 0x403850
movb 0xa3(%rsp), %al
andb $-0x21, %al
cmpb $0x42, %al
je 0x4038ba
jmp 0x4038da
movb $0x1, %al
movl %eax, 0x40(%rsp)
movl 0x438(%rbx), %r14d
xorl %eax, %eax
testl %r14d, %r14d
cmovlel %eax, %r14d
cmpq %rax, %r14
je 0x40392f
andq $0x0, 0x60(%rsp,%rax,8)
incq %rax
jmp 0x40391f
movq 0x3e8(%rbx), %rax
xorl %esi, %esi
testq %rax, %rax
cmovleq %rsi, %rax
movq %rax, 0x30(%rsp)
leaq 0xa0(%rbx), %rax
movq %rax, 0x10(%rsp)
pushq $0x4
popq %r15
xorl %r12d, %r12d
cmpq 0x30(%rsp), %r12
je 0x4039cd
movq %rsi, (%rsp)
movq %r12, 0x20(%rsp)
shlq $0x4, %r12
addq 0x408(%rbx), %r12
movq %r12, %rdi
movq 0x18(%rsp), %rsi
pushq $0x3
popq %rdx
callq 0x401078
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
movq %rcx, 0x8(%rsp)
movq 0x10(%rsp), %r13
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x4039ba
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x401078
testl %eax, %eax
jne 0x4039b1
incq 0x60(%rsp,%rbp,8)
incq %rbp
addq $0x70, %r13
jmp 0x403995
movq (%rsp), %rsi
addq 0x8(%rsp), %rsi
movq 0x20(%rsp), %r12
incq %r12
jmp 0x403957
movq %rsi, 0x40(%rbx)
imulq $0xe, %r14, %rbp
leaq 0x60(%rsp), %rax
xorl %ecx, %ecx
cmpq %rcx, %rbp
je 0x4039f6
movq (%rax), %rdx
movq %rdx, 0x98(%rbx,%rcx,8)
addq $0xe, %rcx
addq $0x8, %rax
jmp 0x4039dc
testq %rsi, %rsi
je 0x403a71
imulq $0x18, %rsi, %rdi
callq 0x442160
movq %rax, 0x410(%rbx)
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x403a59
leaq 0x60(%rsp), %r12
xorl %r13d, %r13d
pushq $0x1
popq %r15
cmpq %r13, %rbp
je 0x403aa1
cmpq $0x0, 0x98(%rbx,%r13,8)
je 0x403a4f
imulq $0x18, (%r12), %rsi
addq $0x18, %rsi
movq %r15, %rdi
callq 0x4435b0
movq %rax, 0xc8(%rbx,%r13,8)
testq %rax, %rax
je 0x403a59
addq $0xe, %r13
addq $0x8, %r12
jmp 0x403a21
movq %rbx, %rdi
callq 0x40263d
movq $0x8, 0x114ac4(%rip) # 0x518530
jmp 0x403200
movq %rbx, %rdi
callq 0x40263d
movq $0xc, 0x114aac(%rip) # 0x518530
jmp 0x403200
movq %rbx, %rdi
callq 0x40263d
movq $0x3, 0x114a94(%rip) # 0x518530
jmp 0x403202
xorl %eax, %eax
cmpq %rax, %r14
je 0x403abc
andq $0x0, 0x1a0(%rsp,%rax,8)
andq $0x0, 0x60(%rsp,%rax,8)
incq %rax
jmp 0x403aa3
cmpb $0x0, 0x40(%rsp)
jne 0x403ad3
movq 0x430(%rbx), %rax
addq $0x4, %rax
movq %rax, 0x48(%rsp)
leaq 0xa0(%rbx), %rax
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r12d, %r12d
movq %rbp, 0x20(%rsp)
cmpq 0x30(%rsp), %r12
je 0x403bdc
movq 0x408(%rbx), %r15
movq %r12, (%rsp)
shlq $0x4, %r12
leaq (%r15,%r12), %r13
movq %r13, %rdi
movq 0x18(%rsp), %rsi
pushq $0x3
popq %rdx
callq 0x401078
testl %eax, %eax
jne 0x403b59
movslq 0x4(%r13), %rax
movq 0x10(%rsp), %rsi
imulq $0x18, %rsi, %rcx
movq 0x28(%rsp), %rdx
movq %rax, (%rdx,%rcx)
movslq 0x8(%r15,%r12), %rax
addq 0x48(%rsp), %rax
movq %rax, 0x8(%rdx,%rcx)
movslq 0xc(%r15,%r12), %rax
movq %rax, 0x10(%rdx,%rcx)
incq %rsi
movq %rsi, 0x10(%rsp)
addq %r15, %r12
addq $0xc, %r12
movq 0x8(%rsp), %rbp
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x403bcb
movq %r13, %rdi
movq %rbp, %rsi
pushq $0x4
popq %rdx
callq 0x401078
testl %eax, %eax
jne 0x403bc2
movslq 0x8(%r13), %rax
addq 0x48(%rsp), %rax
movq 0x28(%rbp), %rcx
movq 0x60(%rsp,%r15,8), %rdx
imulq $0x18, %rdx, %rsi
movq %rax, (%rcx,%rsi)
movslq (%r12), %rax
movq %rax, 0x8(%rcx,%rsi)
movq 0x1a0(%rsp,%r15,8), %rdi
movq %rdi, 0x10(%rcx,%rsi)
addq %rax, %rdi
movq %rdi, 0x1a0(%rsp,%r15,8)
incq %rdx
movq %rdx, 0x60(%rsp,%r15,8)
incq %r15
addq $0x70, %rbp
jmp 0x403b68
movq (%rsp), %r12
incq %r12
movq 0x20(%rsp), %rbp
jmp 0x403af0
leaq 0x1a0(%rsp), %rax
xorl %ecx, %ecx
cmpq %rcx, %rbp
je 0x403c00
movq (%rax), %rdx
movq %rdx, 0x90(%rbx,%rcx,8)
addq $0xe, %rcx
addq $0x8, %rax
jmp 0x403be6
movl (%rbx), %edi
movq 0x430(%rbx), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x47efe0
andq $0x0, 0x50(%rbx)
jmp 0x403202
movq $0x516868, %rax         # imm = 0x516868
movq (%rax), %rdi
leaq 0xce413(%rip), %rsi     # 0x4d2040
pushq $0x8
popq %rdx
xorl %eax, %eax
callq 0x424b10
pushq $-0x1
popq %rbp
jmp 0x403202