// File: /workspace/github_c_makefile_star2_O3/inflex[P]ripMIME/ripOLE/ole.c
// Function: OLE_load_minichain
unsigned char *OLE_load_minichain( struct OLE_object *ole, int miniFAT_sector_start )
{

	int chain_length = 0;
	int current_sector = miniFAT_sector_start;
	unsigned char *buffer;
	unsigned char *bp;

	DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Loading minichain starting at %d",FL, miniFAT_sector_start);

	// Added this sanity checking 2003 Aug 28
	if (miniFAT_sector_start < 0) return NULL;

	chain_length = OLE_follow_minichain( ole, miniFAT_sector_start );
	DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Found %d mini-sectors to load (%d bytes)\n",FL, chain_length, chain_length *ole->header.mini_sector_size);

	// 20040911-21H59
	// If our chain is 0 length, then there's nothing to return
	if (chain_length == 0) return NULL;

	bp = buffer = malloc( chain_length *ole->header.mini_sector_size *sizeof(unsigned char));
	if (buffer != NULL)
	{
		do {
			unsigned int next_sector;

			DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Loading sector %d",FL, current_sector);
			OLE_get_miniblock( ole, current_sector, bp );
			bp += ole->header.mini_sector_size;

			next_sector = get_uint32((char *)( ole->miniFAT +(LEN_ULONG *current_sector)));
			current_sector = next_sector;
		} while ((current_sector != OLE_SECTORID_ENDOFCHAIN)&&(current_sector >= 0)&&(current_sector <= ole->last_sector));
	} else {
		LOGGER_log("%s:%d:OLE_get_miniblock:ERROR: Failed to allocate enough memory for miniChain",FL);
	}

	DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Done. buffer=%p",FL, buffer);

	return buffer;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %r14d
movq %rdi, %rbx
cmpl $0x0, 0x444(%rdi)
je 0xf8ec
leaq 0xa0c7(%rip), %rdi      # 0x1999d
leaq 0x955c(%rip), %rsi      # 0x18e39
movl $0x4ed, %edx            # imm = 0x4ED
movl %r14d, %ecx
xorl %eax, %eax
callq 0xc84f
testl %r14d, %r14d
js 0xf9cf
movq %rbx, %rdi
movl %r14d, %esi
callq 0xf743
movl %eax, %ebp
cmpl $0x0, 0x444(%rbx)
je 0xf932
movl 0x270(%rbx), %r8d
imull %ebp, %r8d
leaq 0xa0c1(%rip), %rdi      # 0x199de
leaq 0x9515(%rip), %rsi      # 0x18e39
movl $0x4f3, %edx            # imm = 0x4F3
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc84f
testl %ebp, %ebp
je 0xf9cf
movl 0x270(%rbx), %edi
imull %ebp, %edi
callq 0x22a0
movq %rax, %r15
testq %rax, %rax
je 0xf9d4
leaq 0x94de(%rip), %r13      # 0x18e39
movq %r15, %rbp
cmpl $0x0, 0x444(%rbx)
je 0xf980
leaq 0xa0ba(%rip), %rdi      # 0x19a28
movq %r13, %rsi
movl $0x4ff, %edx            # imm = 0x4FF
movl %r14d, %ecx
xorl %eax, %eax
callq 0xc84f
movq 0x248(%rbx), %rsi
movl 0x270(%rbx), %r12d
testq %rsi, %rsi
je 0xf9ae
movb 0x26c(%rbx), %cl
movl %r14d, %eax
shll %cl, %eax
cltq
addq %rax, %rsi
movq %rbp, %rdi
movq %r12, %rdx
callq 0x2260
shll $0x2, %r14d
addq 0x38(%rbx), %r14
movq %r14, %rdi
callq 0x10eeb
testl %eax, %eax
js 0xf9ee
movl %eax, %r14d
addq %r12, %rbp
cmpl 0x10(%rbx), %eax
jle 0xf95e
jmp 0xf9ee
xorl %r15d, %r15d
jmp 0xfa14
leaq 0xa07f(%rip), %rdi      # 0x19a5a
leaq 0x9457(%rip), %rsi      # 0x18e39
movl $0x507, %edx            # imm = 0x507
xorl %eax, %eax
callq 0xc84f
cmpl $0x0, 0x444(%rbx)
je 0xfa14
leaq 0xa0aa(%rip), %rdi      # 0x19aa8
leaq 0x9434(%rip), %rsi      # 0x18e39
movl $0x50a, %edx            # imm = 0x50A
movq %r15, %rcx
xorl %eax, %eax
callq 0xc84f
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq