// File: /workspace/github_c_makefile_star2_O2/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 0xf261
leaq 0x9752(%rip), %rdi      # 0x1899d
leaq 0x8be7(%rip), %rsi      # 0x17e39
movl $0x4ed, %edx            # imm = 0x4ED
movl %r14d, %ecx
xorl %eax, %eax
callq 0xc2a1
testl %r14d, %r14d
js 0xf344
movq %rbx, %rdi
movl %r14d, %esi
callq 0xf0b8
movl %eax, %ebp
cmpl $0x0, 0x444(%rbx)
je 0xf2a7
movl 0x270(%rbx), %r8d
imull %ebp, %r8d
leaq 0x974c(%rip), %rdi      # 0x189de
leaq 0x8ba0(%rip), %rsi      # 0x17e39
movl $0x4f3, %edx            # imm = 0x4F3
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc2a1
testl %ebp, %ebp
je 0xf344
movl 0x270(%rbx), %edi
imull %ebp, %edi
callq 0x22a0
movq %rax, %r15
testq %rax, %rax
je 0xf349
leaq 0x8b69(%rip), %r13      # 0x17e39
movq %r15, %rbp
cmpl $0x0, 0x444(%rbx)
je 0xf2f5
leaq 0x9745(%rip), %rdi      # 0x18a28
movq %r13, %rsi
movl $0x4ff, %edx            # imm = 0x4FF
movl %r14d, %ecx
xorl %eax, %eax
callq 0xc2a1
movq 0x248(%rbx), %rsi
movl 0x270(%rbx), %r12d
testq %rsi, %rsi
je 0xf323
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 0x1082f
testl %eax, %eax
js 0xf363
movl %eax, %r14d
addq %r12, %rbp
cmpl 0x10(%rbx), %eax
jle 0xf2d3
jmp 0xf363
xorl %r15d, %r15d
jmp 0xf389
leaq 0x970a(%rip), %rdi      # 0x18a5a
leaq 0x8ae2(%rip), %rsi      # 0x17e39
movl $0x507, %edx            # imm = 0x507
xorl %eax, %eax
callq 0xc2a1
cmpl $0x0, 0x444(%rbx)
je 0xf389
leaq 0x9735(%rip), %rdi      # 0x18aa8
leaq 0x8abf(%rip), %rsi      # 0x17e39
movl $0x50a, %edx            # imm = 0x50A
movq %r15, %rcx
xorl %eax, %eax
callq 0xc2a1
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq