// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/cfb.c
// Function: do_process_stream
static void do_process_stream(deark *c, lctx *d, struct dir_entry_info *dei)
{
	int saved_indent_level;
	de_finfo *fi_raw = NULL; // Use this if we extract the raw stream
	de_finfo *fi_tmp = NULL; // Can be used by format-specific code
	de_ucstring *fn_raw = NULL; // Use this if we extract the raw stream
	de_ucstring *fn_tmp = NULL; // Can be used by format-specific code
	dbuf *firstpart = NULL;
	int is_thumbsdb_stream = 0;
	int is_OfficeArtStream = 0;
	int is_summaryinfo = 0;
	int is_propset = 0;
	int is_namedThumbnail = 0;
	int is_namedImages = 0;
	int is_root = (dei->parent_id==0);

	de_dbg_indent_save(c, &saved_indent_level);

	// By default, use the "stream name" as the filename.
	fn_raw = ucstring_create(c);

	if(dei->parent_id>0 && d->dir_entry[dei->parent_id].path) {
		ucstring_append_ucstring(fn_raw, d->dir_entry[dei->parent_id].path);
		ucstring_append_sz(fn_raw, "/", DE_ENCODING_LATIN1);
	}

	ucstring_append_ucstring(fn_raw, dei->fname_srd->str);
	fn_tmp = ucstring_clone(fn_raw);

	fi_raw = de_finfo_create(c);
	fi_tmp = de_finfo_create(c);

	// By default, use the mod time from the directory entry.
	if(dei->mod_time.is_valid) {
		fi_raw->timestamp[DE_TIMESTAMPIDX_MODIFY] = dei->mod_time; // struct copy
		fi_tmp->timestamp[DE_TIMESTAMPIDX_MODIFY] = dei->mod_time; // struct copy
	}

	if(d->extract_raw_streams) {
		dbuf *outf = NULL;

		de_finfo_set_name_from_ucstring(c, fi_raw, fn_raw, DE_SNFLAG_FULLPATH);
		fi_raw->original_filename_flag = 1;

		outf = dbuf_create_output_file(c, NULL, fi_raw, 0);
		copy_any_stream_to_dbuf(c, d, dei, 0, dei->stream_size, outf);
		dbuf_close(outf);
	}

	if(!d->decode_streams) goto done;

	// Read the first part of the stream, to use for format detection.
	firstpart = dbuf_create_membuf(c, 256, 0x1);
	copy_any_stream_to_dbuf(c, d, dei, 0,
		(dei->stream_size>256)?256:dei->stream_size, firstpart);

	// Stream type detection

	// FIXME? The stream detection happens even if d->subformat_req==SUBFMT_RAW.
	// We probably should have different detection logic in that case.

	if(!de_strcasecmp(dei->fname_srd->sz_utf8, "\x05" "SummaryInformation")) {
		is_propset = 1;
		is_summaryinfo = 1;
	}
	else if(!de_strncmp(dei->fname_srd->sz_utf8, "\x05", 1)) {
		// TODO: Is there a good way to tell whether a stream is a property set?
		is_propset = 1;
	}
	else if(d->subformat_final==SUBFMT_TIFF37680 &&
		!de_strcasecmp(dei->fname_srd->sz_utf8, "CONTENTS"))
	{
		// TODO: This is not the only place to find a "CONTENTS" stream.
		is_propset = 1;
	}
	else if(d->subformat_final==SUBFMT_THUMBSDB) {
		is_thumbsdb_stream = 1;
	}
	else if(!de_strcasecmp(dei->fname_srd->sz_utf8, "Pictures")) {
		// This stream often appears in PPT documents.
		is_OfficeArtStream = 1;
	}
	else if(!de_strcasecmp(dei->fname_srd->sz_utf8, "EscherStm")) {
		is_OfficeArtStream = 1;
	}
	else if(!de_strcasecmp(dei->fname_srd->sz_utf8, "EscherDelayStm")) {
		// Found in MS Publisher, and probably other formats.
		is_OfficeArtStream = 1;
	}
	else if(!de_strcasecmp(dei->fname_srd->sz_utf8, "Thumbnail")) {
		is_namedThumbnail = 1;
	}
	else if(!de_strcasecmp(dei->fname_srd->sz_utf8, "Images")) {
		is_namedImages = 1;
	}

	if(is_OfficeArtStream) {
		unsigned int rectype;
		rectype = (unsigned int)dbuf_getu16le(firstpart, 2);
		if((rectype&0xf000)!=0xf000) {
			is_OfficeArtStream = 0;
		}
	}

	// End of stream type detection

	if(is_propset) {
		do_cfb_olepropertyset(c, d, dei, is_summaryinfo, is_root);
	}
	else if(is_thumbsdb_stream) {
		do_extract_stream_to_file_thumbsdb(c, d, dei, fi_tmp, fn_tmp, firstpart);
	}
	else if(is_OfficeArtStream) {
		do_OfficeArtStream(c, d, dei);
	}
	else if(is_namedThumbnail) {
		do_StreamNamedThumbnail(c, d, dei);
	}
	else if(is_namedImages) {
		do_StreamNamedImages(c, d, dei);
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
	dbuf_close(firstpart);
	ucstring_destroy(fn_raw);
	ucstring_destroy(fn_tmp);
	de_finfo_destroy(c, fi_raw);
	de_finfo_destroy(c, fi_tmp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x70(%rax)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x70(%rax)
jle 0x53e83
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x70(%rcx), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x78(%rax)
je 0x53e83
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x70(%rcx), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movq 0x78(%rax), %rsi
callq 0x171460
movq -0x38(%rbp), %rdi
leaq 0x14a2c5(%rip), %rsi    # 0x19e13e
movl $0x5, %edx
callq 0x1715e0
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x18(%rax), %rsi
callq 0x171460
movq -0x38(%rbp), %rdi
callq 0x171700
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x40(%rax)
je 0x53ef9
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x40(%rcx), %rdx
movq %rdx, 0x18(%rax)
movq 0x48(%rcx), %rcx
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x40(%rcx), %rdx
movq %rdx, 0x18(%rax)
movq 0x48(%rcx), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, 0xc(%rax)
je 0x53f6a
movq $0x0, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl $0x1, %ecx
callq 0x15d2c0
movq -0x28(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
xorl %ecx, %ecx
callq 0x166c60
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %r8
movq -0x70(%rbp), %r9
xorl %eax, %eax
movl %eax, %ecx
callq 0x543d0
movq -0x70(%rbp), %rdi
callq 0x1676a0
movq -0x10(%rbp), %rax
cmpb $0x0, 0xd(%rax)
jne 0x53f79
jmp 0x5423c
movq -0x8(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x1, %edx
callq 0x168020
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x100, 0x10(%rax)      # imm = 0x100
jle 0x53fca
movl $0x100, %eax            # imm = 0x100
movq %rax, -0x98(%rbp)
jmp 0x53fd9
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x80(%rbp), %rdx
movq -0x88(%rbp), %rsi
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %r8
movq -0x48(%rbp), %r9
xorl %eax, %eax
movl %eax, %ecx
callq 0x543d0
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x151b33(%rip), %rsi    # 0x1a5b45
callq 0x15aaa0
cmpl $0x0, %eax
jne 0x5402f
movl $0x1, -0x58(%rbp)
movl $0x1, -0x54(%rbp)
jmp 0x54175
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x151b17(%rip), %rsi    # 0x1a5b59
movl $0x1, %edx
callq 0x19050
cmpl $0x0, %eax
jne 0x5405d
movl $0x1, -0x58(%rbp)
jmp 0x54173
movq -0x10(%rbp), %rax
cmpl $0x3, 0x4(%rax)
jne 0x54090
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x151ae1(%rip), %rsi    # 0x1a5b5b
callq 0x15aaa0
cmpl $0x0, %eax
jne 0x54090
movl $0x1, -0x58(%rbp)
jmp 0x54171
movq -0x10(%rbp), %rax
cmpl $0x2, 0x4(%rax)
jne 0x540a6
movl $0x1, -0x4c(%rbp)
jmp 0x5416f
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x151aab(%rip), %rsi    # 0x1a5b64
callq 0x15aaa0
cmpl $0x0, %eax
jne 0x540cf
movl $0x1, -0x50(%rbp)
jmp 0x5416d
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x151a8b(%rip), %rsi    # 0x1a5b6d
callq 0x15aaa0
cmpl $0x0, %eax
jne 0x540f5
movl $0x1, -0x50(%rbp)
jmp 0x5416b
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x151a6f(%rip), %rsi    # 0x1a5b77
callq 0x15aaa0
cmpl $0x0, %eax
jne 0x5411b
movl $0x1, -0x50(%rbp)
jmp 0x54169
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x151a58(%rip), %rsi    # 0x1a5b86
callq 0x15aaa0
cmpl $0x0, %eax
jne 0x54141
movl $0x1, -0x5c(%rbp)
jmp 0x54167
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x17576d(%rip), %rsi    # 0x1c98c1
callq 0x15aaa0
cmpl $0x0, %eax
jne 0x54165
movl $0x1, -0x60(%rbp)
jmp 0x54167
jmp 0x54169
jmp 0x5416b
jmp 0x5416d
jmp 0x5416f
jmp 0x54171
jmp 0x54173
jmp 0x54175
cmpl $0x0, -0x50(%rbp)
je 0x541a4
movq -0x48(%rbp), %rdi
movl $0x2, %esi
callq 0x165280
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0xf000, %eax           # imm = 0xF000
je 0x541a2
movl $0x0, -0x50(%rbp)
jmp 0x541a4
cmpl $0x0, -0x58(%rbp)
je 0x541c4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x54(%rbp), %ecx
movl -0x64(%rbp), %r8d
callq 0x54610
jmp 0x5423a
cmpl $0x0, -0x4c(%rbp)
je 0x541e9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x48(%rbp), %r9
callq 0x54730
jmp 0x54238
cmpl $0x0, -0x50(%rbp)
je 0x54202
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x54ba0
jmp 0x54236
cmpl $0x0, -0x5c(%rbp)
je 0x5421b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x54c90
jmp 0x54234
cmpl $0x0, -0x60(%rbp)
je 0x54232
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x54da0
jmp 0x54234
jmp 0x54236
jmp 0x54238
jmp 0x5423a
jmp 0x5423c
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x15b5a0
movq -0x48(%rbp), %rdi
callq 0x1676a0
movq -0x38(%rbp), %rdi
callq 0x171750
movq -0x40(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15d260
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)