// File: /workspace/github_c_makefile_star2_O3/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
movl $0x18, %eax
leaq 0x1023fa(%rip), %rcx    # 0x183970
movl -0x14(%rax,%rcx), %r8d
testb %dl, %dl
je 0x81587
testb $0x2, %r8b
jne 0x8158d
jmp 0x815a7
testb $0x1, %r8b
je 0x815a7
cmpb $0x0, 0x1(%rdi)
jne 0x8159c
movl %r8d, %r9d
andl $0x4, %r9d
jne 0x815a7
cmpb %sil, -0x18(%rax,%rcx)
je 0x816c4
addq $0x20, %rax
cmpq $0x238, %rax            # imm = 0x238
jne 0x81576
movzbl %sil, %ebp
movl %esi, %eax
andb $-0x10, %al
cmpb $-0x40, %al
je 0x815f5
movzbl %al, %eax
cmpl $0xe0, %eax
jne 0x81670
leaq 0x8(%rbx), %rdi
addl $0xffffff20, %ebp       # imm = 0xFFFFFF20
leaq 0xa9537(%rip), %rdx     # 0x12ab15
movl $0xc, %esi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe8193
leaq 0x179(%rip), %rax       # 0x8176c
jmp 0x8163c
leaq 0x8(%rbx), %r14
addl $0xffffff40, %ebp       # imm = 0xFFFFFF40
leaq 0xa9515(%rip), %rdx     # 0x12ab1b
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe8193
leaq 0x14(%rbx), %rdi
leaq 0xa94ff(%rip), %rdx     # 0x12ab21
movl $0x50, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0xe8193
orb $0x2, 0x5(%rbx)
leaq 0x1b10(%rip), %rax      # 0x8314c
movq %rax, 0x68(%rbx)
cmpb $0x0, 0x14(%rbx)
je 0x81651
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14(%rbx), %rdi
addq $0x8, %rbx
movl $0x50, %edx
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xe8219
movl %esi, %eax
andb $-0x8, %al
cmpb $-0x30, %al
jne 0x81716
addl $0xffffff30, %ebp       # imm = 0xFFFFFF30
leaq 0x8(%rbx), %r14
leaq 0xa94a7(%rip), %rdx     # 0x12ab34
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe8193
leaq 0x14(%rbx), %rdi
leaq 0xa9491(%rip), %rdx     # 0x12ab3a
movl $0x50, %esi
movq %r14, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0xe8193
orb $0x1, 0x5(%rbx)
jmp 0x81640
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
movl $0xc, %edx
movq %r14, %rsi
callq 0xe8219
testq %r15, %r15
je 0x81640
leaq 0x14(%rbx), %rdi
leaq 0xc7c83(%rip), %rdx     # 0x149382
movl $0x50, %esi
movq %r14, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0xe8193
jmp 0x81640
addb $0x10, %sil
leaq 0x8(%rbx), %rdi
cmpb $0xd, %sil
ja 0x81744
addl $0xffffff10, %ebp       # imm = 0xFFFFFF10
leaq 0xa9429(%rip), %rdx     # 0x12ab5a
movl $0xc, %esi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe8193
jmp 0x81640
leaq 0xa9415(%rip), %r14     # 0x12ab60
movl $0xc, %edx
movq %r14, %rsi
callq 0xe8219
addq $0x14, %rbx
movl $0x50, %edx
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x81661