// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/jpeg.c
// Function: finalize_fpxr_stream
static void finalize_fpxr_stream(deark *c, lctx *d, struct fpxr_entity_struct *fe)
{
	de_finfo *fi = NULL;
	dbuf *outf = NULL;
	de_ucstring *name2 = NULL;

	if(!fe || !fe->stream) goto done;
	if(fe->done_flag || fe->is_storage) goto done;

	if(fe->stream->len != fe->stream_size) {
		de_warn(c, "Expected FPXR stream #%u to have %"I64_FMT" bytes, found %"I64_FMT,
			(unsigned int)fe->index, fe->stream_size, fe->stream->len);
	}

	// Process some known streams
	if(fe->name_srd) {
		if(fe->name_srd->sz_utf8 && !de_strcmp(fe->name_srd->sz_utf8, "/FUJIFILM/Preview")) {
			do_fpxr_fujifilm_preview(c, d, fe);
		}

		// The FlashPix spec says "Names in an IStorage that begin with the
		// value '\0x05' are reserved exclusively for the storage of property
		// sets."
		//
		// It probably means the last *component* of the name begins with 0x05.
		// 0x05 shouldn't appear anywhere else, I think, so I'll just search
		// the whole string for it.
		if(ucstring_contains_char(fe->name_srd->str, 0x05)) {
			do_fpxr_olepropset_stream(c, d, fe);
		}
	}

	if(c->extract_level<2) goto done;

	fi = de_finfo_create(c);

	name2 = ucstring_create(c);
	if(fe->name_srd) {
		ucstring_append_ucstring(name2, fe->name_srd->str);
	}
	if(name2->len>0) {
		ucstring_append_char(name2, '.');
	}
	ucstring_append_sz(name2, "fpxr.bin", DE_ENCODING_LATIN1);
	de_finfo_set_name_from_ucstring(c, fi, name2, 0);

	outf = dbuf_create_output_file(c, NULL, fi, DE_CREATEFLAG_IS_AUX);
	dbuf_copy(fe->stream, 0, fe->stream->len, outf);

done:
	if(fe && fe->stream) {
		dbuf_close(fe->stream);
		fe->stream = NULL;
	}
	if(fe) {
		fe->done_flag = 1;
	}
	ucstring_destroy(name2);
	dbuf_close(outf);
	de_finfo_destroy(c, fi);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xc084e
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0xc0853
jmp 0xc09ef
movq -0x18(%rbp), %rax
cmpl $0x0, 0x24(%rax)
jne 0xc0867
movq -0x18(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0xc086c
jmp 0xc09ef
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
je 0xc08b1
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %r8
leaq 0xf64bd(%rip), %rsi     # 0x1b6d67
movb $0x0, %al
callq 0x15bc10
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xc0927
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x20(%rax)
je 0xc08f9
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0xf64bf(%rip), %rsi     # 0x1b6d9d
callq 0x191a0
cmpl $0x0, %eax
jne 0xc08f9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xc0a60
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rdi
movl $0x5, %esi
callq 0xc0af0
cmpl $0x0, %eax
je 0xc0925
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xc0b60
jmp 0xc0927
movq -0x8(%rbp), %rax
cmpl $0x2, 0x90(%rax)
jge 0xc0939
jmp 0xc09ef
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xc0973
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rsi
callq 0x171460
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jle 0xc098c
movq -0x30(%rbp), %rdi
movl $0x2e, %esi
callq 0x1714c0
movq -0x30(%rbp), %rdi
leaq 0xf6418(%rip), %rsi     # 0x1b6daf
movl $0x5, %edx
callq 0x1715e0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rdx
xorl %ecx, %ecx
callq 0x15d2c0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %ecx
callq 0x166c60
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rdx
movq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
callq 0x166070
cmpq $0x0, -0x18(%rbp)
je 0xc0a1a
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0xc0a1a
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1676a0
movq -0x18(%rbp), %rax
movq $0x0, 0x10(%rax)
cmpq $0x0, -0x18(%rbp)
je 0xc0a2c
movq -0x18(%rbp), %rax
movl $0x1, 0x24(%rax)
movq -0x30(%rbp), %rdi
callq 0x171750
movq -0x28(%rbp), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15d260
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)