// File: /workspace/github_c_makefile_star2_O2/archer1357[P]Offline-Raytracer/avilib.c
// Function: AVI_read_data
int AVI_read_data(avi_t *AVI, char *vidbuf, long max_vidbuf,
                              char *audbuf, long max_audbuf,
                              long *len)
{

/*
 * Return codes:
 *
 *    1 = video data read
 *    2 = audio data read
 *    0 = reached EOF
 *   -1 = video buffer too small
 *   -2 = audio buffer too small
 */

   off_t n;
   char data[8];

   if(AVI->mode==AVI_MODE_WRITE) return 0;

   while(1)
   {
      /* Read tag and length */

      if( avi_read(AVI->fdes,data,8) != 8 ) return 0;

      /* if we got a list tag, ignore it */

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

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

      if(strncasecmp(data,AVI->video_tag,3) == 0)
      {
         *len = n;
         AVI->video_pos++;
         if(n>max_vidbuf)
         {
            lseek(AVI->fdes,n,SEEK_CUR);
            return -1;
         }
         if(avi_read(AVI->fdes,vidbuf,n) != n ) return 0;
         return 1;
      }
      else if(strncasecmp(data,AVI->track[AVI->aptr].audio_tag,4) == 0)
      {
         *len = n;
         if(n>max_audbuf)
         {
            lseek(AVI->fdes,n,SEEK_CUR);
            return -2;
         }
         if(avi_read(AVI->fdes,audbuf,n) != n ) return 0;
         return 2;
         break;
      }
      else
         if(lseek(AVI->fdes,n,SEEK_CUR)<0)  return 0;
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r13
xorl %edi, %edi
cmpq $0x0, 0x8(%r13)
je 0x4043af
movq %rdx, 0x28(%rsp)
movq %r9, 0x8(%rsp)
movq %r8, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
leaq 0x48(%r13), %r15
leaq 0x60(%r13), %r14
leaq 0x30(%rsp), %r12
pushq $0x4
popq %rbx
movl (%r13), %edi
movq %r12, %rsi
pushq $0x8
popq %rdx
callq 0x403c91
cmpq $0x8, %rax
jne 0x404332
movq %r12, %rdi
leaq 0xcddba(%rip), %rsi     # 0x4d2072
movq %rbx, %rdx
callq 0x401078
testl %eax, %eax
je 0x40431e
movslq 0x34(%rsp), %rbp
incq %rbp
andq $-0x2, %rbp
movq %r12, %rdi
movq %r15, %rsi
pushq $0x3
popq %rdx
callq 0x401078
testl %eax, %eax
je 0x404336
movslq 0x43c(%r13), %rax
imulq $0x70, %rax, %rax
leaq (%r14,%rax), %rsi
addq $0x40, %rsi
movq %r12, %rdi
movq %rbx, %rdx
callq 0x401078
testl %eax, %eax
je 0x40435c
movl (%r13), %edi
movq %rbp, %rsi
pushq $0x1
popq %rdx
callq 0x47efe0
testq %rax, %rax
jns 0x404295
jmp 0x404332
movl (%r13), %edi
movq %rbx, %rsi
pushq $0x1
popq %rdx
callq 0x47efe0
jmp 0x404295
xorl %edi, %edi
jmp 0x4043af
movq 0x8(%rsp), %rax
movq %rbp, (%rax)
incq 0x50(%r13)
movl (%r13), %edi
cmpq 0x28(%rsp), %rbp
jle 0x40437f
pushq $0x1
popq %rdx
movq %rbp, %rsi
callq 0x47efe0
pushq $-0x1
jmp 0x40437c
movq 0x8(%rsp), %rax
movq %rbp, (%rax)
movl (%r13), %edi
cmpq 0x20(%rsp), %rbp
jle 0x404397
pushq $0x1
popq %rdx
movq %rbp, %rsi
callq 0x47efe0
pushq $-0x2
popq %rdi
jmp 0x4043af
movq 0x18(%rsp), %rsi
movq %rbp, %rdx
callq 0x403c91
xorl %edi, %edi
cmpq %rbp, %rax
sete %dil
jmp 0x4043af
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
callq 0x403c91
xorl %edi, %edi
cmpq %rbp, %rax
sete %dil
addl %edi, %edi
movl %edi, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq