// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/bmff.c
// Function: do_box_colr_jp2
static void do_box_colr_jp2(deark *c, lctx *d, struct de_boxesctx *bctx)
{
	u8 meth;
	u8 n;
	struct de_boxdata *curbox = bctx->curbox;
	i64 pos = curbox->payload_pos;
	const char *s;

	if(curbox->payload_len<3) goto done;
	meth = dbuf_getbyte_p(bctx->f, &pos);
	switch(meth) {
	case 1: s="enumerated"; break;
	case 2: s="ICC profile (restricted)"; break;
	case 3: s="ICC profile (any)"; break; // JPX only
	case 4: s="vendor"; break; // JPX only
	default: s="?";
	}
	de_dbg(c, "specification method: %d (%s)", (int)meth, s);

	n = dbuf_getbyte_p(bctx->f, &pos);
	de_dbg(c, "precedence: %u", (UI)n);
	n = dbuf_getbyte_p(bctx->f, &pos);
	de_dbg(c, "approximation code: %u", (UI)n);

	if(meth==1) {
		unsigned int enumcs;
		if(curbox->payload_len<7) goto done;
		enumcs = (unsigned int)dbuf_getu32be_p(bctx->f, &pos);
		switch(enumcs) {
			// TODO: There are lots more valid values for JPX.
		case 16: s="sRGB"; break;
		case 17: s="sRGB-like grayscale"; break;
		case 18: s="sYCC"; break;
		default: s="?";
		}
		de_dbg(c, "enumerated colourspace: %u (%s)", enumcs, s);
	}
	else if(meth==2 || meth==3) {
		dbuf_create_file_from_slice(bctx->f,
			curbox->payload_pos+3, curbox->payload_len-3,
			"icc", NULL, DE_CREATEFLAG_IS_AUX);
	}

done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x3, 0x40(%rax)
jge 0x3908c
jmp 0x3925e
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x3, %eax
ja 0x390f9
movq -0x48(%rbp), %rax
leaq 0x168098(%rip), %rcx    # 0x1a1154
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x168d6c(%rip), %rax    # 0x1a1e38
movq %rax, -0x38(%rbp)
jmp 0x39104
leaq 0x168d6a(%rip), %rax    # 0x1a1e43
movq %rax, -0x38(%rbp)
jmp 0x39104
leaq 0x168d76(%rip), %rax    # 0x1a1e5c
movq %rax, -0x38(%rbp)
jmp 0x39104
leaq 0x168d7b(%rip), %rax    # 0x1a1e6e
movq %rax, -0x38(%rbp)
jmp 0x39104
leaq 0x17eb2d(%rip), %rax    # 0x1b7c2d
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x19(%rbp), %edx
movq -0x38(%rbp), %rcx
leaq 0x168d5e(%rip), %rsi    # 0x1a1e75
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movb %al, -0x1a(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x1a(%rbp), %edx
leaq 0x168d52(%rip), %rsi    # 0x1a1e93
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movb %al, -0x1a(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x1a(%rbp), %edx
leaq 0x168d37(%rip), %rsi    # 0x1a1ea2
movb $0x0, %al
callq 0x15b0d0
movzbl -0x19(%rbp), %eax
cmpl $0x1, %eax
jne 0x39211
movq -0x28(%rbp), %rax
cmpq $0x7, 0x40(%rax)
jge 0x3918f
jmp 0x3925e
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1654b0
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x4c(%rbp)
subl $0x10, %eax
je 0x391c4
jmp 0x391b0
movl -0x4c(%rbp), %eax
subl $0x11, %eax
je 0x391d1
jmp 0x391ba
movl -0x4c(%rbp), %eax
subl $0x12, %eax
je 0x391de
jmp 0x391eb
leaq 0x168cee(%rip), %rax    # 0x1a1eb9
movq %rax, -0x38(%rbp)
jmp 0x391f6
leaq 0x168ce6(%rip), %rax    # 0x1a1ebe
movq %rax, -0x38(%rbp)
jmp 0x391f6
leaq 0x168ced(%rip), %rax    # 0x1a1ed2
movq %rax, -0x38(%rbp)
jmp 0x391f6
leaq 0x17ea3b(%rip), %rax    # 0x1b7c2d
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %edx
movq -0x38(%rbp), %rcx
leaq 0x168ccf(%rip), %rsi    # 0x1a1ed7
movb $0x0, %al
callq 0x15b0d0
jmp 0x3925c
movzbl -0x19(%rbp), %eax
cmpl $0x2, %eax
je 0x39223
movzbl -0x19(%rbp), %eax
cmpl $0x3, %eax
jne 0x3925a
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rsi
addq $0x3, %rsi
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rdx
subq $0x3, %rdx
leaq 0x16879b(%rip), %rcx    # 0x1a19e5
xorl %eax, %eax
movl %eax, %r8d
movl $0x1, %r9d
callq 0x166be0
jmp 0x3925c
jmp 0x3925e
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)