// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/jpeg.c
// Function: get_marker_info
static int get_marker_info(deark *c, lctx *d, u8 seg_type,
	struct marker_info *mi)
{
	i64 k;

	de_zeromem(mi, sizeof(struct marker_info));
	mi->seg_type = seg_type;

	// First, try to find the segment type in the static marker info.
	for(k=0; k<(i64)DE_ARRAYCOUNT(marker_info1_arr); k++) {
		const struct marker_info1 *mi1 = &marker_info1_arr[k];

		if(!d->is_jpegls && !(mi1->flags&FLAG_JPEG_COMPAT)) continue;
		if(d->is_jpegls && !(mi1->flags&FLAG_JPEGLS_COMPAT)) continue;
		if(!d->is_pegasus_pic2 && (mi1->flags&FLAG_PIC2_ONLY)) continue;

		if(mi1->seg_type == seg_type) {
			mi->flags = mi1->flags;
			mi->hfn = mi1->hfn;
			de_strlcpy(mi->shortname, mi1->shortname, sizeof(mi->shortname));
			if(mi1->longname) {
				de_snprintf(mi->longname, sizeof(mi->longname), "%s: %s",
					mi1->shortname, mi1->longname);
			}
			goto done;
		}
	}

	// Handle some pattern-based markers.

	if(seg_type>=0xe0 && seg_type<=0xef) {
		de_snprintf(mi->shortname, sizeof(mi->shortname), "APP%d", (int)(seg_type-0xe0));
		mi->hfn = handler_app;
		goto done;
	}

	if(seg_type>=0xc0 && seg_type<=0xcf) {
		de_snprintf(mi->shortname, sizeof(mi->shortname), "SOF%d", (int)(seg_type-0xc0));
		de_snprintf(mi->longname, sizeof(mi->longname), "%s: Start of frame", mi->shortname);
		mi->flags |= FLAG_IS_SOF;
		mi->hfn = handler_sof;
		goto done;
	}

	if(seg_type>=0xd0 && seg_type<=0xd7) {
		int rstn = (int)(seg_type-0xd0);
		de_snprintf(mi->shortname, sizeof(mi->shortname), "RST%d", rstn);
		de_snprintf(mi->longname, sizeof(mi->longname), "%s: Restart with mod 8 count %d",
			mi->shortname, rstn);
		mi->flags |= FLAG_NO_DATA;
		goto done;
	}

	if(seg_type>=0xf0 && seg_type<=0xfd) {
		de_snprintf(mi->shortname, sizeof(mi->shortname), "JPG%d", (int)(seg_type-0xf0));
		goto done;
	}

	de_strlcpy(mi->shortname, "???", sizeof(mi->shortname));
	de_strlcpy(mi->longname, "???", sizeof(mi->longname));
	return 0;

done:
	if(!mi->longname[0]) {
		// If no longname was set, use the shortname
		de_strlcpy(mi->longname, mi->shortname, sizeof(mi->longname));
	}
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdx)
movups %xmm0, 0x60(%rdx)
movups %xmm0, 0x50(%rdx)
movups %xmm0, 0x40(%rdx)
movups %xmm0, 0x30(%rdx)
movups %xmm0, 0x20(%rdx)
movups %xmm0, 0x10(%rdx)
movb %sil, (%rdx)
movb (%rdi), %dl
pushq $0x18
popq %rax
leaq 0x109ffb(%rip), %rcx    # 0x186980
cmpq $0x238, %rax            # imm = 0x238
je 0x7c9c4
movl -0x14(%rax,%rcx), %r8d
testb %dl, %dl
je 0x7c99e
testb $0x2, %r8b
jne 0x7c9a4
jmp 0x7c9be
testb $0x1, %r8b
je 0x7c9be
cmpb $0x0, 0x1(%rdi)
jne 0x7c9b3
movl %r8d, %r9d
andl $0x4, %r9d
jne 0x7c9be
cmpb %sil, -0x18(%rax,%rcx)
je 0x7cac6
addq $0x20, %rax
jmp 0x7c985
movzbl %sil, %ebp
movl %esi, %eax
andb $-0x10, %al
cmpb $-0x40, %al
je 0x7ca04
movzbl %al, %eax
cmpl $0xe0, %eax
jne 0x7ca79
leaq 0x8(%rbx), %rdi
addl $0xffffff20, %ebp       # imm = 0xFFFFFF20
leaq 0xa0eb6(%rip), %rdx     # 0x11d8a5
pushq $0xc
popq %rsi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xde40c
leaq 0x162(%rip), %rax       # 0x7cb64
jmp 0x7ca47
leaq 0x8(%rbx), %r14
addl $0xffffff40, %ebp       # imm = 0xFFFFFF40
leaq 0xa0e96(%rip), %rdx     # 0x11d8ab
pushq $0xc
popq %rsi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xde40c
leaq 0x14(%rbx), %rdi
leaq 0xa0e82(%rip), %rdx     # 0x11d8b1
pushq $0x50
popq %rsi
movq %r14, %rcx
xorl %eax, %eax
callq 0xde40c
orb $0x2, 0x5(%rbx)
leaq 0x19e3(%rip), %rax      # 0x7e42a
movq %rax, 0x68(%rbx)
cmpb $0x0, 0x14(%rbx)
je 0x7ca5c
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14(%rbx), %rdi
addq $0x8, %rbx
pushq $0x50
popq %rdx
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xde492
movl %esi, %eax
andb $-0x8, %al
cmpb $-0x30, %al
jne 0x7cb14
addl $0xffffff30, %ebp       # imm = 0xFFFFFF30
leaq 0x8(%rbx), %r14
leaq 0xa0e2e(%rip), %rdx     # 0x11d8c4
pushq $0xc
popq %rsi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xde40c
leaq 0x14(%rbx), %rdi
leaq 0xa0e1a(%rip), %rdx     # 0x11d8ca
pushq $0x50
popq %rsi
movq %r14, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0xde40c
orb $0x1, 0x5(%rbx)
jmp 0x7ca4b
movl %r8d, 0x4(%rbx)
movq (%rax,%rcx), %rdx
movq %rdx, 0x68(%rbx)
leaq 0x8(%rbx), %rdi
movq -0x10(%rax,%rcx), %r14
movq -0x8(%rax,%rcx), %r15
pushq $0xc
popq %rdx
movq %r14, %rsi
callq 0xde492
testq %r15, %r15
je 0x7ca4b
leaq 0x14(%rbx), %rdi
leaq 0xbf3b3(%rip), %rdx     # 0x13beb2
pushq $0x50
popq %rsi
movq %r14, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0xde40c
jmp 0x7ca4b
addb $0x10, %sil
leaq 0x8(%rbx), %rdi
cmpb $0xd, %sil
ja 0x7cb40
addl $0xffffff10, %ebp       # imm = 0xFFFFFF10
leaq 0xa0dbb(%rip), %rdx     # 0x11d8ea
pushq $0xc
popq %rsi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xde40c
jmp 0x7ca4b
leaq 0xa0da9(%rip), %r14     # 0x11d8f0
pushq $0xc
popq %rdx
movq %r14, %rsi
callq 0xde492
addq $0x14, %rbx
pushq $0x50
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x7ca6a