// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x407cb7
movl $0x0, -0x4(%rbp)
jmp 0x407e89
jmp 0x407cb9
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
leaq -0x48(%rbp), %rsi
movl $0x8, %edx
callq 0x406dc0
cmpq $0x8, %rax
je 0x407ce2
movl $0x0, -0x4(%rbp)
jmp 0x407e89
leaq -0x48(%rbp), %rdi
leaq 0xdb369(%rip), %rsi     # 0x4e3056
movl $0x4, %edx
callq 0x401070
cmpl $0x0, %eax
jne 0x407d16
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
movl $0x4, %esi
movl $0x1, %edx
callq 0x48fba0
jmp 0x407cb9
leaq -0x48(%rbp), %rdi
addq $0x4, %rdi
callq 0x403a50
addq $0x1, %rax
andq $-0x2, %rax
movq %rax, -0x40(%rbp)
leaq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x48, %rsi
movl $0x3, %edx
callq 0x401070
cmpl $0x0, %eax
jne 0x407dc6
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x50(%rax)
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jle 0x407d92
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
movq -0x40(%rbp), %rsi
movl $0x1, %edx
callq 0x48fba0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x407e89
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x406dc0
cmpq -0x40(%rbp), %rax
je 0x407dba
movl $0x0, -0x4(%rbp)
jmp 0x407e89
movl $0x1, -0x4(%rbp)
jmp 0x407e89
leaq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x60, %rsi
movq -0x10(%rbp), %rax
movslq 0x43c(%rax), %rax
imulq $0x70, %rax, %rax
addq %rax, %rsi
addq $0x40, %rsi
movl $0x4, %edx
callq 0x401070
cmpl $0x0, %eax
jne 0x407e5a
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
jle 0x407e2c
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
movq -0x40(%rbp), %rsi
movl $0x1, %edx
callq 0x48fba0
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x407e89
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x406dc0
cmpq -0x40(%rbp), %rax
je 0x407e51
movl $0x0, -0x4(%rbp)
jmp 0x407e89
movl $0x2, -0x4(%rbp)
jmp 0x407e89
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
movq -0x40(%rbp), %rsi
movl $0x1, %edx
callq 0x48fba0
cmpq $0x0, %rax
jge 0x407e80
movl $0x0, -0x4(%rbp)
jmp 0x407e89
jmp 0x407e82
jmp 0x407e84
jmp 0x407cb9
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)