// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/jpeg.c
// Function: do_jps_segment
static void do_jps_segment(deark *c, lctx *d, i64 pos1, i64 len)
{
	i64 pos = pos1;
	i64 blk_len;
	u32 st_descr;
	de_ucstring *flags_str = NULL;
	de_ucstring *comment = NULL;
	unsigned int mtype;

	// Descriptor block
	if(len<8) goto done;
	blk_len = de_getu16be_p(&pos);
	if(blk_len<4) goto done;
	st_descr = (u32)de_getu32be(pos);

	flags_str = ucstring_create(c);
	mtype = (unsigned int)(st_descr&0x000000ff);
	switch(mtype) {
	case 0: ucstring_append_flags_item(flags_str, "MONOSCOPIC_IMAGE"); break;
	case 1: ucstring_append_flags_item(flags_str, "STEREOSCOPIC_IMAGE"); break;
	}
	if(mtype==0) {
		switch((st_descr&0x0000ff00)>>8) {
		case 0: ucstring_append_flags_item(flags_str, "EYE_BOTH"); break;
		case 1: ucstring_append_flags_item(flags_str, "EYE_LEFT"); break;
		case 2: ucstring_append_flags_item(flags_str, "EYE_RIGHT"); break;
		}
	}
	else if(mtype==1) {
		switch((st_descr&0x0000ff00)>>8) {
		case 1: ucstring_append_flags_item(flags_str, "LAYOUT_INTERLEAVED"); break;
		case 2: ucstring_append_flags_item(flags_str, "LAYOUT_SIDEBYSIDE"); break;
		case 3: ucstring_append_flags_item(flags_str, "LAYOUT_OVERUNDER"); break;
		case 4: ucstring_append_flags_item(flags_str, "LAYOUT_ANAGLYPH"); break;
		}
	}
	ucstring_append_flags_item(flags_str, (st_descr&0x00010000)?"half-height":"full-height");
	ucstring_append_flags_item(flags_str, (st_descr&0x00020000)?"half-width":"full-width");
	// TODO: FIELD ORDER BIT
	// TODO: SEPARATION

	de_dbg(c, "stereoscopic descriptor: 0x%08x (%s)", (unsigned int)st_descr,
		ucstring_getpsz(flags_str));
	pos += blk_len;

	// Comment block
	if(pos1+len-pos<2) goto done;
	blk_len = de_getu16be_p(&pos);
	if(pos+blk_len > pos1+len) goto done;
	comment = ucstring_create(c);
	dbuf_read_to_ucstring_n(c->infile, pos, blk_len, DE_DBG_MAX_STRLEN, comment,
				0, DE_ENCODING_ASCII);
	de_dbg(c, "comment: \"%s\"", ucstring_getpsz(comment));

done:
	ucstring_destroy(flags_str);
	ucstring_destroy(comment);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %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 $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
cmpq $0x8, -0x20(%rbp)
jge 0xbff9f
jmp 0xc021c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165210
movq %rax, -0x30(%rbp)
cmpq $0x4, -0x30(%rbp)
jge 0xbffc0
jmp 0xc021c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165470
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x40(%rbp)
movzbl -0x34(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
testl %eax, %eax
je 0xbfffe
jmp 0xbfff4
movl -0x50(%rbp), %eax
subl $0x1, %eax
je 0xc0010
jmp 0xc0020
movq -0x40(%rbp), %rdi
leaq 0xf7067(%rip), %rsi     # 0x1b7070
callq 0x172680
jmp 0xc0020
movq -0x40(%rbp), %rdi
leaq 0xf7066(%rip), %rsi     # 0x1b7081
callq 0x172680
cmpl $0x0, -0x4c(%rbp)
jne 0xc0080
movzwl -0x34(%rbp), %eax
shrl $0x8, %eax
movl %eax, -0x54(%rbp)
testl %eax, %eax
je 0xc004a
jmp 0xc0036
movl -0x54(%rbp), %eax
subl $0x1, %eax
je 0xc005c
jmp 0xc0040
movl -0x54(%rbp), %eax
subl $0x2, %eax
je 0xc006e
jmp 0xc007e
movq -0x40(%rbp), %rdi
leaq 0xf703f(%rip), %rsi     # 0x1b7094
callq 0x172680
jmp 0xc007e
movq -0x40(%rbp), %rdi
leaq 0xf7036(%rip), %rsi     # 0x1b709d
callq 0x172680
jmp 0xc007e
movq -0x40(%rbp), %rdi
leaq 0xf702d(%rip), %rsi     # 0x1b70a6
callq 0x172680
jmp 0xc00f5
cmpl $0x1, -0x4c(%rbp)
jne 0xc00f3
movzbl -0x33(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0x3, %eax
ja 0xc00f1
movq -0x60(%rbp), %rax
leaq 0xf6296(%rip), %rcx     # 0x1b6338
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x40(%rbp), %rdi
leaq 0xf6ffa(%rip), %rsi     # 0x1b70b0
callq 0x172680
jmp 0xc00f1
movq -0x40(%rbp), %rdi
leaq 0xf6ffb(%rip), %rsi     # 0x1b70c3
callq 0x172680
jmp 0xc00f1
movq -0x40(%rbp), %rdi
leaq 0xf6ffb(%rip), %rsi     # 0x1b70d5
callq 0x172680
jmp 0xc00f1
movq -0x40(%rbp), %rdi
leaq 0xf6ffa(%rip), %rsi     # 0x1b70e6
callq 0x172680
jmp 0xc00f3
jmp 0xc00f5
movq -0x40(%rbp), %rdi
movl -0x34(%rbp), %ecx
andl $0x10000, %ecx          # imm = 0x10000
leaq 0xf6ff9(%rip), %rsi     # 0x1b7102
leaq 0xf6fe6(%rip), %rax     # 0x1b70f6
cmpl $0x0, %ecx
cmovneq %rax, %rsi
callq 0x172680
movq -0x40(%rbp), %rdi
movl -0x34(%rbp), %ecx
andl $0x20000, %ecx          # imm = 0x20000
leaq 0xf6fe9(%rip), %rsi     # 0x1b7119
leaq 0xf6fd7(%rip), %rax     # 0x1b710e
cmpl $0x0, %ecx
cmovneq %rax, %rsi
callq 0x172680
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x40(%rbp), %rdi
callq 0x172500
movq -0x70(%rbp), %rdi
movl -0x64(%rbp), %edx
movq %rax, %rcx
leaq 0xf6fb9(%rip), %rsi     # 0x1b7124
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
subq -0x28(%rbp), %rax
cmpq $0x2, %rax
jge 0xc0195
jmp 0xc021c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165210
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
addq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jle 0xc01c1
jmp 0xc021c
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %r8
movl $0x1f4, %ecx            # imm = 0x1F4
xorl %r9d, %r9d
movl $0x1, (%rsp)
callq 0x166a40
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x48(%rbp), %rdi
callq 0x172500
movq -0x78(%rbp), %rdi
movq %rax, %rdx
leaq 0xe0437(%rip), %rsi     # 0x1a064c
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rdi
callq 0x171750
movq -0x48(%rbp), %rdi
callq 0x171750
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)