// File: /workspace/github_c_makefile_star2_O1/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 0xfa79
leaq 0x9f4a(%rip), %rdi      # 0x199ad
leaq 0x93df(%rip), %rsi      # 0x18e49
movl $0x4ed, %edx            # imm = 0x4ED
movl %r14d, %ecx
xorl %eax, %eax
callq 0xc960
testl %r14d, %r14d
js 0xfb5f
movq %rbx, %rdi
movl %r14d, %esi
callq 0xf8ab
movl %eax, %ebp
cmpl $0x0, 0x444(%rbx)
je 0xfabf
movl 0x270(%rbx), %r8d
imull %ebp, %r8d
leaq 0x9f44(%rip), %rdi      # 0x199ee
leaq 0x9398(%rip), %rsi      # 0x18e49
movl $0x4f3, %edx            # imm = 0x4F3
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc960
testl %ebp, %ebp
je 0xfb5f
movl 0x270(%rbx), %edi
imull %ebp, %edi
callq 0x22b0
movq %rax, %r15
testq %rax, %rax
je 0xfb64
leaq 0x9361(%rip), %r13      # 0x18e49
movq %r15, %rbp
cmpl $0x0, 0x444(%rbx)
je 0xfb0d
leaq 0x9f3d(%rip), %rdi      # 0x19a38
movq %r13, %rsi
movl $0x4ff, %edx            # imm = 0x4FF
movl %r14d, %ecx
xorl %eax, %eax
callq 0xc960
movq 0x248(%rbx), %rsi
testq %rsi, %rsi
je 0xfb37
movb 0x26c(%rbx), %cl
movl %r14d, %eax
shll %cl, %eax
cltq
addq %rax, %rsi
movl 0x270(%rbx), %edx
movq %rbp, %rdi
callq 0x2270
movl 0x270(%rbx), %r12d
shll $0x2, %r14d
addq 0x38(%rbx), %r14
movq %r14, %rdi
callq 0x110fb
testl %eax, %eax
js 0xfb7e
movl %eax, %r14d
addq %r12, %rbp
cmpl 0x10(%rbx), %eax
jle 0xfaeb
jmp 0xfb7e
xorl %r15d, %r15d
jmp 0xfba4
leaq 0x9eff(%rip), %rdi      # 0x19a6a
leaq 0x92d7(%rip), %rsi      # 0x18e49
movl $0x507, %edx            # imm = 0x507
xorl %eax, %eax
callq 0xc960
cmpl $0x0, 0x444(%rbx)
je 0xfba4
leaq 0x9f2a(%rip), %rdi      # 0x19ab8
leaq 0x92b4(%rip), %rsi      # 0x18e49
movl $0x50a, %edx            # imm = 0x50A
movq %r15, %rcx
xorl %eax, %eax
callq 0xc960
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq