// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/avilib.c
// Function: AVI_read_audio
long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes)
{
   long nr, pos, left, todo;

   if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
   if(!AVI->track[AVI->aptr].audio_index)         { AVI_errno = AVI_ERR_NO_IDX;   return -1; }

   nr = 0; /* total number of bytes read */

   while(bytes>0)
   {
      left = AVI->track[AVI->aptr].audio_index[AVI->track[AVI->aptr].audio_posc].len - AVI->track[AVI->aptr].audio_posb;
      if(left==0)
      {
         if(AVI->track[AVI->aptr].audio_posc>=AVI->track[AVI->aptr].audio_chunks-1) return nr;
         AVI->track[AVI->aptr].audio_posc++;
         AVI->track[AVI->aptr].audio_posb = 0;
         continue;
      }
      if(bytes<left)
         todo = bytes;
      else
         todo = left;
      pos = AVI->track[AVI->aptr].audio_index[AVI->track[AVI->aptr].audio_posc].pos + AVI->track[AVI->aptr].audio_posb;
      lseek(AVI->fdes, pos, SEEK_SET);
      if (avi_read(AVI->fdes,audbuf+nr,todo) != todo)
      {
         AVI_errno = AVI_ERR_READ;
         return -1;
      }
      bytes -= todo;
      nr    += todo;
      AVI->track[AVI->aptr].audio_posb += todo;
   }

   return nr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x407797
movq $0x7, 0x1211a6(%rip) # 0x528930
movq $-0x1, -0x8(%rbp)
jmp 0x407a0b
movq -0x10(%rbp), %rax
addq $0x60, %rax
movq -0x10(%rbp), %rcx
movslq 0x43c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x68(%rax)
jne 0x4077d0
movq $0xd, 0x12116d(%rip) # 0x528930
movq $-0x1, -0x8(%rbp)
jmp 0x407a0b
movq $0x0, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
jle 0x407a03
movq -0x10(%rbp), %rax
addq $0x60, %rax
movq -0x10(%rbp), %rcx
movslq 0x43c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq 0x68(%rax), %rax
movq -0x10(%rbp), %rcx
addq $0x60, %rcx
movq -0x10(%rbp), %rdx
movslq 0x43c(%rdx), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
imulq $0x18, 0x48(%rcx), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
addq $0x60, %rcx
movq -0x10(%rbp), %rdx
movslq 0x43c(%rdx), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
subq 0x50(%rcx), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x4078f3
movq -0x10(%rbp), %rax
addq $0x60, %rax
movq -0x10(%rbp), %rcx
movslq 0x43c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
addq $0x60, %rcx
movq -0x10(%rbp), %rdx
movslq 0x43c(%rdx), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
movq 0x38(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jl 0x4078a6
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x407a0b
movq -0x10(%rbp), %rax
addq $0x60, %rax
movq -0x10(%rbp), %rcx
movslq 0x43c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq 0x48(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
addq $0x60, %rax
movq -0x10(%rbp), %rcx
movslq 0x43c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x50(%rax)
jmp 0x4077d8
movq -0x20(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x407907
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x40790f
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
addq $0x60, %rax
movq -0x10(%rbp), %rcx
movslq 0x43c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq 0x68(%rax), %rax
movq -0x10(%rbp), %rcx
addq $0x60, %rcx
movq -0x10(%rbp), %rdx
movslq 0x43c(%rdx), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
imulq $0x18, 0x48(%rcx), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
addq $0x60, %rcx
movq -0x10(%rbp), %rdx
movslq 0x43c(%rdx), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
addq 0x50(%rcx), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
movq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x48fba0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
movq -0x18(%rbp), %rsi
addq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x406dc0
cmpq -0x40(%rbp), %rax
je 0x4079bd
movq $0x3, 0x120f7d(%rip) # 0x528930
movq $-0x1, -0x8(%rbp)
jmp 0x407a0b
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
addq $0x60, %rax
movq -0x10(%rbp), %rdx
movslq 0x43c(%rdx), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rax
addq 0x50(%rax), %rcx
movq %rcx, 0x50(%rax)
jmp 0x4077d8
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)