// File: /workspace/github_cpp_makefile_star2_O1/olegk0[P]readAVI/ReadAVI.cpp
// Function: ReadAVI::parse_movi(int)
int ReadAVI::parse_movi(int size)
{
    char chunk_id[5];
    long end_of_chunk;
    index_entry_t index_entry;
    int blk_size;

    do {
	long offset = inFile.tellg();
	/*
	 if (fileSize - offset < 8)
	 break;
	 */
	read_chars(chunk_id, 4);
	index_entry.stream_num = decodeCkid(chunk_id, &index_entry.type);

	if (index_entry.stream_num < 0) {
	    inFile.seekg(offset - 4, ios_base::beg);
	    break;
	}

	index_entry.dwChunkLength = read_int();

	if (!(avi_header.Flags & AVIF_HASINDEX)) {
	    index_entry.dwChunkOffset = offset + 8;
	    index_entries.push_back(index_entry);
	}

	MSG_DBG(3, "      AVI Movi Chunk ( id=%s(%d-%d) chunk_size=%d offset=0x%lx)\n", chunk_id, index_entry.type,
		index_entry.stream_num, index_entry.dwChunkLength, offset);
	MSG_DBG(3, "      {\n");

	end_of_chunk = index_entry.dwChunkLength + inFile.tellg();
	end_of_chunk = (end_of_chunk + 1) & ~1;
	/*    if ((end_of_chunk % 4) != 0) {
	 end_of_chunk = end_of_chunk + (4 - (end_of_chunk % 4));
	 }
	 */
//    MSG_DBG(2, "end_of_chunk:%d  %X\n", end_of_chunk, end_of_chunk);
	inFile.seekg(end_of_chunk, ios_base::beg);
	MSG_DBG(3, "      }\n");

	blk_size = end_of_chunk - offset;
	size -= blk_size;
	MSG_DBG(3, "size:%d \n", size);

    } while (size > 7);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebx
movq %rdi, %rbp
leaq 0x20(%rdi), %r15
leaq 0x8(%rdi), %rax
movq %rax, 0x30(%rsp)
leaq 0x3b9b(%rip), %r13      # 0x8230
movq %r15, %rdi
callq 0x23e0
movq %rax, %r12
movl $0x4, %edx
movq %r15, %rdi
leaq 0xf(%rsp), %rsi
callq 0x22b0
movb $0x0, 0x13(%rsp)
movsbl 0xf(%rsp), %ecx
movsbl 0x10(%rsp), %eax
movb 0x11(%rsp), %sil
movb 0x12(%rsp), %dil
xorl %r8d, %r8d
xorl %edx, %edx
cmpb %sil, (%r13,%r8,8)
jne 0x46de
cmpb %dil, 0x1(%r13,%r8,8)
je 0x46f4
cmpq $0x3, %r8
leaq 0x1(%r8), %r9
setae %dl
movq %r9, %r8
cmpq $0x4, %r9
jne 0x46d0
jmp 0x46fd
movl 0x4(%r13,%r8,8), %esi
movl %esi, 0x1c(%rsp)
leal (%rcx,%rcx,4), %ecx
leal (%rax,%rcx,2), %r14d
addl $0xfffffdf0, %r14d      # imm = 0xFFFFFDF0
testb $0x1, %dl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %eax, %r14d
movl %r14d, 0x20(%rsp)
testl %r14d, %r14d
js 0x4771
movl %ebx, 0x14(%rsp)
movl $0x4, %edx
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
callq 0x22b0
movl 0x18(%rsp), %eax
movl %eax, 0x2c(%rsp)
testb $0x10, 0x234(%rbp)
jne 0x4793
leal 0x8(%r12), %eax
movl %eax, 0x28(%rsp)
movq 0x10(%rbp), %rsi
cmpq 0x18(%rbp), %rsi
je 0x4784
movl 0x2c(%rsp), %eax
movl %eax, 0x10(%rsi)
movups 0x1c(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x14, 0x10(%rbp)
jmp 0x4793
addq $-0x4, %r12
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x22f0
jmp 0x47c7
movq 0x30(%rsp), %rdi
leaq 0x1c(%rsp), %rdx
callq 0x48d8
movq %rbp, %rbx
movslq 0x2c(%rsp), %rbp
movq %r15, %rdi
callq 0x23e0
addq %rax, %rbp
incq %rbp
andq $-0x2, %rbp
movq %r15, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x22f0
subl %ebp, %r12d
movq %rbx, %rbp
movl 0x14(%rsp), %ebx
addl %r12d, %ebx
testl %r14d, %r14d
js 0x47d5
cmpl $0x7, %ebx
jg 0x4695
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq