// File: /workspace/github_c_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r12
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)
leaq 0x8(%rdx), %rax
movq %rax, 0x8(%rsp)
movq %rdx, 0x18(%rsp)
leaq 0x14(%rdx), %rax
movq %rax, 0x10(%rsp)
leaq 0x101ce7(%rip), %rbx    # 0x1838d0
leaq 0xa8a40(%rip), %r14     # 0x12a630
xorl %ebp, %ebp
movl %esi, 0x24(%rsp)
movb (%r12), %al
testb %al, %al
je 0x81c89
movl $0x4, %r15d
testb $0x2, 0x4(%rbp,%rbx)
je 0x81c96
cmpb $0x0, 0x1(%r12)
jne 0x81c22
testb $0x4, 0x4(%rbp,%rbx)
jne 0x81c96
xorl %r15d, %r15d
cmpb %sil, (%rbp,%rbx)
jne 0x81c96
movl 0x4(%rbp,%rbx), %eax
movq 0x18(%rsp), %rcx
movl %eax, 0x4(%rcx)
movq 0x18(%rbp,%rbx), %rax
movq %rax, 0x68(%rcx)
movq 0x8(%rbp,%rbx), %r13
movl $0xc, %edx
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0xe8ded
movq 0x10(%rbp,%rbx), %r8
movl $0x5, %r15d
testq %r8, %r8
je 0x81c83
movl $0x50, %esi
movq 0x10(%rsp), %rdi
leaq 0xc7171(%rip), %rdx     # 0x148dea
movq %r13, %rcx
xorl %eax, %eax
callq 0xe8d67
movl 0x24(%rsp), %esi
jmp 0x81c96
movl $0x4, %r15d
testb $0x1, 0x4(%rbp,%rbx)
jne 0x81cb5
movl %r15d, %eax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
addq $0x20, %rbp
cmpq $0x220, %rbp            # imm = 0x220
jne 0x81bf6
jmp 0x81cc2
testb %al, %al
jne 0x81c02
jmp 0x81c13
movzbl %sil, %r12d
movl %esi, %eax
andb $-0x10, %al
cmpb $-0x40, %al
je 0x81d0c
movzbl %al, %eax
cmpl $0xe0, %eax
jne 0x81d9c
addl $0xffffff20, %r12d      # imm = 0xFFFFFF20
leaq 0xa8b5b(%rip), %rdx     # 0x12a845
movl $0xc, %esi
movq 0x8(%rsp), %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe8d67
leaq 0x14c(%rip), %rax       # 0x81e51
movq 0x18(%rsp), %rcx
jmp 0x81d5c
addl $0xffffff40, %r12d      # imm = 0xFFFFFF40
leaq 0xa8b31(%rip), %rdx     # 0x12a84b
movl $0xc, %esi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe8d67
leaq 0xa8b19(%rip), %rdx     # 0x12a851
movl $0x50, %esi
movq 0x10(%rsp), %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0xe8d67
movq 0x18(%rsp), %rcx
orb $0x2, 0x5(%rcx)
leaq 0x1a98(%rip), %rax      # 0x837f4
movq %rax, 0x68(%rcx)
movq 0x18(%rsp), %rax
cmpb $0x0, 0x14(%rax)
je 0x81d7a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x50, %edx
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe8ded
movl %esi, %eax
andb $-0x8, %al
cmpb $-0x30, %al
jne 0x81df5
addl $0xffffff30, %r12d      # imm = 0xFFFFFF30
leaq 0xa8ab2(%rip), %rdx     # 0x12a864
movl $0xc, %esi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe8d67
leaq 0xa8a9a(%rip), %rdx     # 0x12a86a
movl $0x50, %esi
movq 0x10(%rsp), %rdi
movq %rbx, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0xe8d67
movq 0x18(%rsp), %rax
orb $0x1, 0x5(%rax)
jmp 0x81d60
addb $0x10, %sil
cmpb $0xd, %sil
ja 0x81e26
addl $0xffffff10, %r12d      # imm = 0xFFFFFF10
leaq 0xa8a7d(%rip), %rdx     # 0x12a88a
movl $0xc, %esi
movq 0x8(%rsp), %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe8d67
jmp 0x81d60
leaq 0xa8a63(%rip), %r15     # 0x12a890
movl $0xc, %edx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0xe8ded
movl $0x50, %edx
movq 0x10(%rsp), %rdi
movq %r15, %rsi
jmp 0x81d89