// File: /workspace/github_c_makefile_star2_O3/inflex[P]ripMIME/ripOLE/ole.c
// Function: OLE_follow_minichain
int OLE_follow_minichain( struct OLE_object *ole, int miniFAT_sector_start )
{
	//unsigned int current_sector = miniFAT_sector_start;
	int current_sector = miniFAT_sector_start;
	int chain_length=0;
	int break_out = 0;

	DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Starting at sector %d",FL, miniFAT_sector_start);

	if (miniFAT_sector_start < 0) return 0;

	do {
		unsigned int next_sector;

		DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Requesting 4-byte value at '%d'",FL, ole->miniFAT +(LEN_ULONG *current_sector));
		if (ole->miniFAT +(LEN_ULONG *current_sector) > ole->miniFAT_limit) {
			DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Requested location is out of bounds\n",FL);
			return 0;
		}

		next_sector = get_uint32((char*) ole->miniFAT +(LEN_ULONG *current_sector));

		DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Current Msector(0x%0X:%d)->next(0x%0X:%d)\n", FL, current_sector, current_sector, next_sector, next_sector);

		/** Check for conditions that indicate we should stop traversing this chain **/

		/** 1. We cannot point to ourselves **/
		if (current_sector == next_sector) break;

		chain_length++;
		current_sector = next_sector;

		/** Test for non-positive type sector ID's **/
		switch (current_sector) {
			case OLE_SECTORID_MSAT:
			case OLE_SECTORID_SAT:
			case OLE_SECTORID_ENDOFCHAIN:
			case OLE_SECTORID_FREE:
				break_out=1;
				break;
			default:
				break_out=0;
		};

		DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: current sector = %d",FL,current_sector);
	} while ((break_out==0)&&(current_sector <= ole->last_sector ));

	DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Done.  Chainlength=%d",FL, chain_length);

	return chain_length;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %r13d
movq %rdi, %r14
cmpl $0x0, 0x444(%rdi)
je 0xf77a
leaq 0xa0bd(%rip), %rdi      # 0x19821
leaq 0x96ce(%rip), %rsi      # 0x18e39
movl $0x4a5, %edx            # imm = 0x4A5
movl %r13d, %ecx
xorl %eax, %eax
callq 0xc84f
testl %r13d, %r13d
js 0xf8a2
leaq 0x96af(%rip), %r12      # 0x18e39
leaq 0xa0c8(%rip), %r15      # 0x19859
xorl %eax, %eax
movl %eax, %ebx
cmpl $0x0, 0x444(%r14)
je 0xf7c5
leal (,%r13,4), %eax
movslq %eax, %rbp
movq 0x38(%r14), %rcx
addq %rbp, %rcx
movq %r15, %rdi
movq %r12, %rsi
movl $0x4ac, %edx            # imm = 0x4AC
xorl %eax, %eax
callq 0xc84f
jmp 0xf7d0
leal (,%r13,4), %eax
movslq %eax, %rbp
addq 0x38(%r14), %rbp
cmpq 0x40(%r14), %rbp
ja 0xf87a
movq %rbp, %rdi
callq 0x10eeb
movl %eax, %ebp
cmpl $0x0, 0x444(%r14)
je 0xf814
movl %ebp, (%rsp)
leaq 0xa0e6(%rip), %rdi      # 0x198e2
movq %r12, %rsi
movl $0x4b4, %edx            # imm = 0x4B4
movl %r13d, %ecx
movl %r13d, %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0xc84f
cmpl %ebp, %r13d
je 0xf852
cmpl $0x0, 0x444(%r14)
je 0xf83b
leaq 0xa105(%rip), %rdi      # 0x1992f
movq %r12, %rsi
movl $0x4ca, %edx            # imm = 0x4CA
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc84f
cmpl $-0x5, %ebp
ja 0xf850
leal 0x1(%rbx), %eax
movl %ebp, %r13d
cmpl 0x10(%r14), %ebp
jle 0xf793
incl %ebx
cmpl $0x0, 0x444(%r14)
je 0xf8a4
leaq 0xa102(%rip), %rdi      # 0x19965
leaq 0x95cf(%rip), %rsi      # 0x18e39
movl $0x4cd, %edx            # imm = 0x4CD
movl %ebx, %ecx
xorl %eax, %eax
callq 0xc84f
jmp 0xf8a4
cmpl $0x0, 0x444(%r14)
je 0xf8a2
leaq 0xa010(%rip), %rdi      # 0x1989b
leaq 0x95a7(%rip), %rsi      # 0x18e39
xorl %ebx, %ebx
movl $0x4ae, %edx            # imm = 0x4AE
xorl %eax, %eax
callq 0xc84f
jmp 0xf8a4
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq