// File: /workspace/github_c_makefile_star2_O0/inflex[P]ripMIME/ripOLE/ole.c
// Function: OLE_get_block
int OLE_get_block( struct OLE_object *ole, int block_index, unsigned char *block_buffer )
{
	if (block_buffer == NULL)
	{
		LOGGER_log("%s:%d:OLE_get_block:ERROR: Block buffer is NULL",FL);
		return -1;
	}

	if (ole->f != NULL)
	{
		int read_count = 0;
		int fseek_result = 0;
		size_t offset = 0;
		unsigned char *bb = NULL;

		bb = malloc(sizeof(unsigned char) *ole->header.sector_size);
		if (bb == NULL)
		{
			LOGGER_log("%s:%d:OLE_get_block:ERROR: Cannot allocate %d bytes for OLE block",FL, ole->header.sector_size);
			return -1;
		}

		DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: BlockIndex=%d, Buffer=0x%x",FL, block_index, block_buffer);

		//20051211-2343:PLD: offset = (block_index +1) << ole->header.sector_shift;
		offset = OLE_sectorpos(ole, block_index);

		DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Read offset in file = 0x%x size to read= 0x%x",FL,offset,ole->header.sector_size);

		fseek_result = fseek(ole->f, offset, SEEK_SET);
		if (fseek_result != 0)
		{
			if (bb != NULL) { free(bb); bb = NULL; }
			LOGGER_log("%s:%d:OLE_get_block:ERROR: Seek failure (block=%d:%d)",FL, block_index,offset, strerror(errno));
			return OLEER_GET_BLOCK_SEEK;
		}

		//read_count = fread(block_buffer, sizeof(unsigned char), ole->header.sector_size, ole->f);
		read_count = fread(bb, sizeof(unsigned char), ole->header.sector_size, ole->f);
		DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Read %d byte of data",FL,read_count);
		if (read_count != (int)ole->header.sector_size)
		{
			if (bb != NULL){ free(bb); bb = NULL; }
			VOLE LOGGER_log("%s:%d:Mismatch in bytes read. Requested %d, got %d\n", FL, ole->header.sector_size, read_count);
			return OLEER_GET_BLOCK_READ;
		}

		DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Copying over memory read from file",FL);

		memcpy(block_buffer, bb, ole->header.sector_size);

		DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: memory block copied to block_buffer",FL);

		/* We're now done with BB, dispose of it */
		if (bb) { free(bb); bb = NULL; }

		DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Disposed of temporary bb block",FL);

	} else {
		LOGGER_log("%s:%d:OLE_get_block:ERROR: OLE file is closed\n",FL);
		return -1;
	}

	DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Done",FL);

	return OLE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x14b20
leaq 0xb150(%rip), %rdi      # 0x1fc51
leaq 0xb143(%rip), %rsi      # 0x1fc4b
movl $0x146, %edx            # imm = 0x146
movb $0x0, %al
callq 0x117c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14e41
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x14df0
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x268(%rax), %eax
movl %eax, %edi
shlq $0x0, %rdi
callq 0x2290
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x14b9d
movq -0x10(%rbp), %rax
movl 0x268(%rax), %ecx
leaq 0xb103(%rip), %rdi      # 0x1fc81
leaq 0xb0c6(%rip), %rsi      # 0x1fc4b
movl $0x154, %edx            # imm = 0x154
movb $0x0, %al
callq 0x117c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14e41
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x14bcb
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %r8
leaq 0xb10b(%rip), %rdi      # 0x1fcc3
leaq 0xb08c(%rip), %rsi      # 0x1fc4b
movl $0x158, %edx            # imm = 0x158
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x14ab0
cltq
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x14c13
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movl 0x268(%rax), %r8d
leaq 0xb0f9(%rip), %rdi      # 0x1fcf9
leaq 0xb044(%rip), %rsi      # 0x1fc4b
movl $0x15d, %edx            # imm = 0x15D
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x22f0
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x14c91
cmpq $0x0, -0x38(%rbp)
je 0x14c47
movq -0x38(%rbp), %rdi
callq 0x2030
movq $0x0, -0x38(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x23a0
movl -0x44(%rbp), %ecx
movq -0x40(%rbp), %r8
movq %rax, %r9
leaq 0xb0d0(%rip), %rdi      # 0x1fd42
leaq 0xafd2(%rip), %rsi      # 0x1fc4b
movl $0x163, %edx            # imm = 0x163
movb $0x0, %al
callq 0x117c0
movl $0x29, -0x4(%rbp)
jmp 0x14e41
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x268(%rax), %eax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movl $0x1, %esi
callq 0x20b0
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x14ce0
movl -0x24(%rbp), %ecx
leaq 0xb0ab(%rip), %rdi      # 0x1fd78
leaq 0xaf77(%rip), %rsi      # 0x1fc4b
movl $0x169, %edx            # imm = 0x169
movb $0x0, %al
callq 0x117c0
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x268(%rcx), %eax
je 0x14d48
cmpq $0x0, -0x38(%rbp)
je 0x14d07
movq -0x38(%rbp), %rdi
callq 0x2030
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x448(%rax)
je 0x14d3c
movq -0x10(%rbp), %rax
movl 0x268(%rax), %ecx
movl -0x24(%rbp), %r8d
leaq 0xb07f(%rip), %rdi      # 0x1fda8
leaq 0xaf1b(%rip), %rsi      # 0x1fc4b
movl $0x16d, %edx            # imm = 0x16D
movb $0x0, %al
callq 0x117c0
movl $0x2a, -0x4(%rbp)
jmp 0x14e41
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x14d6f
leaq 0xb080(%rip), %rdi      # 0x1fddc
leaq 0xaee8(%rip), %rsi      # 0x1fc4b
movl $0x171, %edx            # imm = 0x171
movb $0x0, %al
callq 0x117c0
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x268(%rax), %eax
movl %eax, %edx
callq 0x2250
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x14daf
leaq 0xb07e(%rip), %rdi      # 0x1fe1a
leaq 0xaea8(%rip), %rsi      # 0x1fc4b
movl $0x175, %edx            # imm = 0x175
movb $0x0, %al
callq 0x117c0
cmpq $0x0, -0x38(%rbp)
je 0x14dc7
movq -0x38(%rbp), %rdi
callq 0x2030
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x14dee
leaq 0xb07e(%rip), %rdi      # 0x1fe59
leaq 0xae69(%rip), %rsi      # 0x1fc4b
movl $0x17a, %edx            # imm = 0x17A
movb $0x0, %al
callq 0x117c0
jmp 0x14e13
leaq 0xb09c(%rip), %rdi      # 0x1fe93
leaq 0xae4d(%rip), %rsi      # 0x1fc4b
movl $0x17d, %edx            # imm = 0x17D
movb $0x0, %al
callq 0x117c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14e41
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x14e3a
leaq 0xb09b(%rip), %rdi      # 0x1fec2
leaq 0xae1d(%rip), %rsi      # 0x1fc4b
movl $0x181, %edx            # imm = 0x181
movb $0x0, %al
callq 0x117c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)