// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/jpeg.c
// Function: do_fpxr_segment
static void do_fpxr_segment(deark *c, lctx *d, i64 pos1, i64 len)
{
	i64 pos = pos1;
	size_t k;
	i64 nbytesleft;
	int saved_indent_level;
	u8 ver;
	u8 segtype;
	const char *name;

	de_dbg_indent_save(c, &saved_indent_level);
	if(len<2) goto done;
	ver = de_getbyte_p(&pos);

	de_dbg(c, "version: %u", (unsigned int)ver);
	segtype = de_getbyte_p(&pos);
	switch(segtype) {
	case 1: name = "contents list"; break;
	case 2: name = "stream data"; break;
	default: name = "?";
	}
	de_dbg(c, "segment type: %u (%s)", (unsigned int)segtype, name);

	if(segtype==1) { // contents list
		// Initialize our saved fpxr data
		destroy_fpxr_data(c, d);
		d->fpxr_data = de_malloc(c, sizeof(struct fpxr_data_struct));

		if(len<4) goto done;

		d->fpxr_data->num_entities = (size_t)de_getu16be_p(&pos);
		de_dbg(c, "interoperability count: %u", (unsigned int)d->fpxr_data->num_entities);
		d->fpxr_data->entities = de_mallocarray(c, d->fpxr_data->num_entities, sizeof(struct fpxr_entity_struct));

		for(k=0; k<d->fpxr_data->num_entities; k++) {
			i64 bytes_consumed = 0;
			struct fpxr_entity_struct *fe;
			i64 esize;
			u8 defval;
			u8 clsid_buf[16];
			char clsid_string[50];

			if(pos>=pos1+len) goto done;
			fe = &d->fpxr_data->entities[k];
			fe->index = k;
			de_dbg(c, "entity[%d] at %d", (int)k, (int)pos);
			de_dbg_indent(c, 1);

			esize = de_getu32be_p(&pos);
			if(esize==0xffffffffLL) {
				fe->is_storage = 1;
			}
			de_dbg(c, "entity type: %s", fe->is_storage?"storage":"stream");
			if(!fe->is_storage) {
				de_dbg(c, "stream size: %u", (unsigned int)esize);
				fe->stream_size = esize;
			}

			defval = de_getbyte_p(&pos);
			de_dbg(c, "default value: 0x%02x", (unsigned int)defval);

			nbytesleft = pos1+len-pos;
			if(!dbuf_get_utf16_NULterm_len(c->infile, pos, nbytesleft, &bytes_consumed)) goto done;
			fe->name_srd = dbuf_read_string(c->infile, pos, bytes_consumed-2, bytes_consumed-2,
				DE_CONVFLAG_WANT_UTF8, DE_ENCODING_UTF16LE);
			de_dbg(c, "entity name: \"%s\"", ucstring_getpsz_d(fe->name_srd->str));
			pos += bytes_consumed;

			if(fe->is_storage) { // read Entity class ID
				de_read(clsid_buf, pos, 16);
				pos += 16;
				fmtutil_guid_to_uuid(clsid_buf);
				fmtutil_render_uuid(c, clsid_buf, clsid_string, sizeof(clsid_string));
				de_dbg(c, "class id: {%s}", clsid_string);
			}
			de_dbg_indent(c, -1);
		}
	}
	else if(segtype==2) { // stream data
		size_t stream_idx;
		i64 stream_offset;

		if(len<6) goto done;

		stream_idx = (size_t)de_getu16be_p(&pos);
		de_dbg(c, "index to contents list: %d", (int)stream_idx);

		// The Exif spec (2.31) says this field is at offset 0x0C, but I'm
		// assuming that's a clerical error that should be 0x0D.
		stream_offset = de_getu32be_p(&pos);
		de_dbg(c, "offset to flashpix stream: %u", (unsigned int)stream_offset);

		nbytesleft = pos1+len-pos;
		if(nbytesleft>0) {
			de_dbg(c, "[%d bytes of flashpix stream data, at %d]", (int)nbytesleft, (int)pos);
		}
		append_fpxr_stream_data(c, d, stream_idx, pos, nbytesleft);
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x15b580
cmpq $0x2, -0x20(%rbp)
jge 0xbf15c
jmp 0xbf604
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
movq %rsi, -0xe0(%rbp)
callq 0x165170
movb %al, -0x3d(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x3d(%rbp), %edx
leaq 0x103500(%rip), %rsi    # 0x1c2686
xorl %eax, %eax
callq 0x15b0d0
movq -0xe0(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x165170
movb %al, -0x3e(%rbp)
movzbl -0x3e(%rbp), %eax
movl %eax, -0xd4(%rbp)
subl $0x1, %eax
je 0xbf1c2
jmp 0xbf1b5
movl -0xd4(%rbp), %eax
subl $0x2, %eax
je 0xbf1cf
jmp 0xbf1dc
leaq 0xf7a80(%rip), %rax     # 0x1b6c49
movq %rax, -0x48(%rbp)
jmp 0xbf1e7
leaq 0xf7a81(%rip), %rax     # 0x1b6c57
movq %rax, -0x48(%rbp)
jmp 0xbf1e7
leaq 0xf8a4a(%rip), %rax     # 0x1b7c2d
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x3e(%rbp), %edx
movq -0x48(%rbp), %rcx
leaq 0xf7a69(%rip), %rsi     # 0x1b6c63
movb $0x0, %al
callq 0x15b0d0
movzbl -0x3e(%rbp), %eax
cmpl $0x1, %eax
jne 0xbf530
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xc05e0
movq -0x8(%rbp), %rdi
movl $0x10, %esi
callq 0x15b780
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xa8(%rax)
cmpq $0x4, -0x20(%rbp)
jge 0xbf243
jmp 0xbf604
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165210
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq (%rax), %rax
movl %eax, %edx
leaq 0xf79f9(%rip), %rsi     # 0x1b6c79
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq (%rax), %rsi
movl $0x28, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rcx, 0x8(%rax)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0xa8(%rcx), %rcx
cmpq (%rcx), %rax
jae 0xbf52b
movq $0x0, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
addq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jl 0xbf2f3
jmp 0xbf604
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x8(%rax), %rax
imulq $0x28, -0x30(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x28(%rbp), %rax
movl %eax, %ecx
leaq 0xf7964(%rip), %rsi     # 0x1b6c94
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1654b0
movq %rax, -0x60(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x60(%rbp)
jne 0xbf370
movq -0x58(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl 0x20(%rax), %ecx
leaq 0xe6860(%rip), %rdx     # 0x1a5be2
leaq 0xf792c(%rip), %rax     # 0x1b6cb5
cmpl $0x0, %ecx
cmovneq %rax, %rdx
leaq 0xf790e(%rip), %rsi     # 0x1b6ca5
movb $0x0, %al
callq 0x15b0d0
movq -0x58(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jne 0xbf3cc
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl %eax, %edx
leaq 0xf7904(%rip), %rsi     # 0x1b6cbd
movb $0x0, %al
callq 0x15b0d0
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movb %al, -0x61(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x61(%rbp), %edx
leaq 0xf78de(%rip), %rsi     # 0x1b6ccd
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0x1695b0
cmpl $0x0, %eax
jne 0xbf429
jmp 0xbf604
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x50(%rbp), %rdx
subq $0x2, %rdx
movq -0x50(%rbp), %rcx
subq $0x2, %rcx
movl $0x10, %r8d
movl $0x3, %r9d
callq 0x1664c0
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0xe8(%rbp), %rdi
movq %rax, %rdx
leaq 0xf7855(%rip), %rsi     # 0x1b6ce3
movb $0x0, %al
callq 0x15b0d0
movq -0x50(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0xbf50c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x80(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl $0x10, %ecx
callq 0x164d10
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x174010
movq -0x8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
movl $0x32, %ecx
callq 0x173ee0
movq -0x8(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
leaq 0xf77f0(%rip), %rsi     # 0x1b6cf5
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xbf2bd
jmp 0xbf602
movzbl -0x3e(%rbp), %eax
cmpl $0x2, %eax
jne 0xbf600
cmpq $0x6, -0x20(%rbp)
jge 0xbf549
jmp 0xbf604
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165210
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xc8(%rbp), %rax
movl %eax, %edx
leaq 0xf778f(%rip), %rsi     # 0x1b6d04
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1654b0
movq %rax, -0xd0(%rbp)
movq -0x8(%rbp), %rdi
movq -0xd0(%rbp), %rax
movl %eax, %edx
leaq 0xf7777(%rip), %rsi     # 0x1b6d1f
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jle 0xbf5e4
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x28(%rbp), %rax
movl %eax, %ecx
leaq 0xf7760(%rip), %rsi     # 0x1b6d3d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0xc8(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %r8
callq 0xc0720
jmp 0xbf602
jmp 0xbf604
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x15b5a0
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)