// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16226
movl -0x14(%rbp), %ecx
leaq 0xa59c(%rip), %rdi      # 0x207af
leaq 0x9a31(%rip), %rsi      # 0x1fc4b
movl $0x4ed, %edx            # imm = 0x4ED
movb $0x0, %al
callq 0x117c0
cmpl $0x0, -0x14(%rbp)
jge 0x16239
movq $0x0, -0x8(%rbp)
jmp 0x163b7
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x15fe0
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16282
movl -0x18(%rbp), %ecx
movl -0x18(%rbp), %r8d
movq -0x10(%rbp), %rax
imull 0x270(%rax), %r8d
leaq 0xa581(%rip), %rdi      # 0x207f0
leaq 0x99d5(%rip), %rsi      # 0x1fc4b
movl $0x4f3, %edx            # imm = 0x4F3
movb $0x0, %al
callq 0x117c0
cmpl $0x0, -0x18(%rbp)
jne 0x16295
movq $0x0, -0x8(%rbp)
jmp 0x163b7
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
imull 0x270(%rcx), %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x0, %rdi
callq 0x2290
movq %rax, -0x28(%rbp)
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x1636a
jmp 0x162c5
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x162ef
movl -0x1c(%rbp), %ecx
leaq 0xa55e(%rip), %rdi      # 0x2083a
leaq 0x9968(%rip), %rsi      # 0x1fc4b
movl $0x4ff, %edx            # imm = 0x4FF
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x30(%rbp), %rdx
callq 0x14e50
movq -0x10(%rbp), %rax
movl 0x270(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movl -0x1c(%rbp), %eax
shll $0x2, %eax
cltq
addq %rax, %rdi
callq 0x181f0
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x1c(%rbp)
xorl %eax, %eax
cmpl $-0x2, -0x1c(%rbp)
movb %al, -0x35(%rbp)
je 0x1635d
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x35(%rbp)
jl 0x1635d
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
setle %al
movb %al, -0x35(%rbp)
movb -0x35(%rbp), %al
testb $0x1, %al
jne 0x162c5
jmp 0x16384
leaq 0xa4fb(%rip), %rdi      # 0x2086c
leaq 0x98d3(%rip), %rsi      # 0x1fc4b
movl $0x507, %edx            # imm = 0x507
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x163af
movq -0x28(%rbp), %rcx
leaq 0xa51e(%rip), %rdi      # 0x208ba
leaq 0x98a8(%rip), %rsi      # 0x1fc4b
movl $0x50a, %edx            # imm = 0x50A
movb $0x0, %al
callq 0x117c0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)