// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/os2bmp.c
// Function: do_BA_segment
static void do_BA_segment(deark *c, i64 pos, i64 *pnextoffset)
{
	u8 b0, b1;
	enum fmtcode fmt;
	const char *fmtname;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c,"BA segment at %d", (int)pos);
	de_dbg_indent(c, 1);

	*pnextoffset = 0;

	b0 = de_getbyte(pos+0);
	b1 = de_getbyte(pos+1);
	if(b0!='B' || b1!='A') {
		de_err(c, "Not a BA segment");
		goto done;
	}

	*pnextoffset = de_getu32le(pos+6);
	de_dbg(c, "offset of next segment: %d", (int)*pnextoffset);

	// Peek at the next two bytes
	b0 = de_getbyte(pos+14+0);
	b1 = de_getbyte(pos+14+1);
	fmt = bytes_to_fmtcode(b0, b1);
	fmtname = get_fmt_shortname_from_code(fmt);

	switch(fmt) {
	case DE_OS2FMT_CI:
	case DE_OS2FMT_CP:
		do_extract_CI_or_CP(c, fmt, fmtname, pos+14);
		break;
	case DE_OS2FMT_BM:
		do_extract_one_image(c, pos+14, fmt, fmtname, "bmp");
		break;
	case DE_OS2FMT_IC:
		do_extract_one_image(c, pos+14, fmt, fmtname, "os2.ico");
		break;
	case DE_OS2FMT_PT:
		do_extract_one_image(c, pos+14, fmt, fmtname, "ptr");
		break;
	default:
		de_err(c, "Not BM/IC/PT/CI/CP format. Not supported.");
		goto done;
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl %eax, %edx
leaq 0xd64d6(%rip), %rsi     # 0x1bd398
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x0, %rsi
callq 0x165060
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x1, %rsi
callq 0x165060
movb %al, -0x1a(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x42, %eax
jne 0xe6f24
movzbl -0x1a(%rbp), %eax
cmpl $0x41, %eax
je 0xe6f3b
movq -0x8(%rbp), %rdi
leaq 0xd647a(%rip), %rsi     # 0x1bd3a9
movb $0x0, %al
callq 0x15bfb0
jmp 0xe707a
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x6, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %edx
leaq 0xd644f(%rip), %rsi     # 0x1bd3ba
xorl %eax, %eax
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0xe, %rsi
callq 0x165060
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0xf, %rsi
callq 0x165060
movb %al, -0x1a(%rbp)
movzbl -0x19(%rbp), %edi
movzbl -0x1a(%rbp), %esi
callq 0xe6360
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %edi
callq 0xe6430
movq %rax, -0x28(%rbp)
movl -0x20(%rbp), %eax
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x8, %eax
ja 0xe7064
movq -0x38(%rbp), %rax
leaq 0xd620a(%rip), %rcx     # 0x1bd1e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
movq -0x28(%rbp), %rdx
movq -0x10(%rbp), %rcx
addq $0xe, %rcx
callq 0xe7090
jmp 0xe7078
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0xe, %rsi
movl -0x20(%rbp), %edx
movq -0x28(%rbp), %rcx
leaq 0xc5cec(%rip), %r8      # 0x1acd07
callq 0xe7390
jmp 0xe7078
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0xe, %rsi
movl -0x20(%rbp), %edx
movq -0x28(%rbp), %rcx
leaq 0xc2295(%rip), %r8      # 0x1a92d1
callq 0xe7390
jmp 0xe7078
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0xe, %rsi
movl -0x20(%rbp), %edx
movq -0x28(%rbp), %rcx
leaq 0xc227f(%rip), %r8      # 0x1a92dc
callq 0xe7390
jmp 0xe7078
movq -0x8(%rbp), %rdi
leaq 0xd6366(%rip), %rsi     # 0x1bd3d5
movb $0x0, %al
callq 0x15bfb0
jmp 0xe707a
jmp 0xe707a
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x15b5a0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)