// File: olegk0[P]readAVI/ReadAVI.cpp
// Function: ReadAVI::GetFrameFromIndex(ReadAVI::frame_entry_t*)
int ReadAVI::GetFrameFromIndex(frame_entry_t *frame_entry)
{
    if (frame_entry->pointer >= index_entries.size()){
	MSG_DBG(2, "Pointer out of range\n");
	return -5;
    }
    for (unsigned i = frame_entry->pointer; i < index_entries.size(); i++) {
	if (index_entries[i].type & frame_entry->type) {
	    check_data_buf(index_entries[i].dwChunkLength);
	    try {
		inFile.seekg(index_entries[i].dwChunkOffset, ios_base::beg);
		read_chars_bin(data_buf, index_entries[i].dwChunkLength);
	    } catch (...) {
		return -1;
	    }
	    frame_entry->buf = data_buf;
	    frame_entry->pointer = i + 1;
	    frame_entry->stream_num = index_entries[i].stream_num;
	    frame_entry->type = index_entries[i].type;
	    return index_entries[i].dwChunkLength;
	}
    }
    MSG_DBG(2, "No more frames\n");
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x38(%rbp)
addq $0x8, %rdi
callq 0x2ee0
movq %rax, %rcx
movq -0x38(%rbp), %rax
cmpq %rcx, %rax
jb 0x39cc
movq 0x5601(%rip), %rax      # 0x8fb0
movq (%rax), %rdi
leaq 0x2798(%rip), %rsi      # 0x6151
movb $0x0, %al
callq 0x2360
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x3b5c
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x40(%rbp), %rdi
movl -0x1c(%rbp), %eax
movq %rax, -0x48(%rbp)
addq $0x8, %rdi
callq 0x2ee0
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jae 0x3b3d
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x5440
movl (%rax), %eax
movq -0x18(%rbp), %rcx
andl (%rcx), %eax
cmpl $0x0, %eax
je 0x3b2d
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
movq %rdi, -0x58(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x5440
movq -0x40(%rbp), %rdi
movl 0x10(%rax), %esi
callq 0x3900
movq -0x40(%rbp), %rax
movq -0x58(%rbp), %rdi
addq $0x20, %rax
movq %rax, -0x50(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x5440
movq -0x50(%rbp), %rdi
movslq 0xc(%rax), %rsi
xorl %edx, %edx
callq 0x2300
jmp 0x3a6a
movq -0x40(%rbp), %rdi
movq 0x338(%rdi), %rax
movq %rax, -0x60(%rbp)
addq $0x8, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x5440
movq -0x40(%rbp), %rdi
movq -0x60(%rbp), %rsi
movl 0x10(%rax), %edx
callq 0x3b70
jmp 0x3a99
jmp 0x3ac1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2110
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
callq 0x23d0
jmp 0x3b5c
movq -0x40(%rbp), %rdi
movq 0x338(%rdi), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
addq $0x8, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x5440
movq -0x40(%rbp), %rdi
movl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
addq $0x8, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x5440
movq -0x40(%rbp), %rdi
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
addq $0x8, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x5440
movl 0x10(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x3b5c
jmp 0x3b2f
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x39d6
movq 0x546c(%rip), %rax      # 0x8fb0
movq (%rax), %rdi
leaq 0x2619(%rip), %rsi      # 0x6167
movb $0x0, %al
callq 0x2360
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)