// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/riff.c
// Function: my_on_std_container_start_fn
static int my_on_std_container_start_fn(struct de_iffctx *ictx)
{
	deark *c = ictx->c;
	lctx *d = (lctx*)ictx->userdata;
	u32 chunktype = ictx->curr_container_fmt4cc.id;
	u32 formtype = ictx->curr_container_contentstype4cc.id;
	int suppress_decoding = 0;

	if(ictx->level==0 && (chunktype==CHUNK_RIFF || chunktype==CHUNK_RIFX) &&
		d->top_level_chunk_count==0)
	{
		const char *fmtname = NULL;

		switch(formtype) {
		case CODE_ACON: fmtname = "Windows animated cursor"; break;
		case CODE_AVI: fmtname = "AVI"; break;
		case CODE_CDRX: fmtname = "Corel CCX"; break;
		case CODE_CMX1:
			fmtname = "Corel CMX";
			ictx->handle_nonchunk_data_fn = my_handle_nonchunk_riff_data_fn;
			d->cmx_parse_hack = 1;
			break;
		case CODE_cmov:
			fmtname = "CorelMOVE";
			ictx->handle_nonchunk_data_fn = my_handle_nonchunk_riff_data_fn;
			d->cmv_parse_hack = 1;
			break;
		case CODE_WAVE: fmtname = "WAVE"; break;
		case CODE_WEBP: fmtname = "WebP"; break;
		}

		// Special check for CorelDraw formats.
		if(!fmtname && (formtype>>8 == 0x434452U) /* "CDR" */) {
			d->is_cdr = 1;
			fmtname = "CorelDRAW (RIFF-based)";
		}

		if(fmtname) {
			de_declare_fmt(c, fmtname);
		}
	}

	if(d->is_cdr && chunktype==CHUNK_LIST) {
		// 'cmpr' LISTs in CorelDraw files are not correctly formed.
		// Tell the parser not to process them.
		if(formtype==CODE_cmpr) {
			de_dbg(c, "[not decoding CDR cmpr list]");
			suppress_decoding = 1;
			goto done;
		}
	}

	if(chunktype==CHUNK_RIFF || chunktype==CHUNK_RIFX) {
		// TODO: INAM data is probably not scoped entirely correctly.
		if(d->INAM_data) {
			ucstring_empty(d->INAM_data);
		}
	}

	if(ictx->main_contentstype4cc.id==CODE_AVI && chunktype==CHUNK_LIST &&
		formtype==CODE_movi)
	{
		// There are often a huge number of these chunks, and we can't do
		// anything interesting with them, so skip them by default.
		if(c->debug_level<2) {
			de_dbg(c, "[not decoding movi chunks]");
			suppress_decoding = 1;
			goto done;
		}

		if(!d->in_movi) {
			// Keep track of when we are inside a 'movi' container.
			d->in_movi = 1;
			d->in_movi_level = ictx->level;
		}
	}

done:
	if(ictx->level==0) {
		d->top_level_chunk_count++;
	}
	return !suppress_decoding;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %r14
movq 0x10(%rdi), %r15
movl 0xcc(%rdi), %ebp
movl 0xfc(%rdi), %r12d
cmpl $0x0, 0x64(%rdi)
je 0xbac26
cmpl $0x0, 0x4(%r15)
setne %al
movl %ebp, %r13d
xorl $0x4c495354, %r13d      # imm = 0x4C495354
movl %r12d, %ecx
xorl $0x636d7072, %ecx       # imm = 0x636D7072
orl %r13d, %ecx
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xbabd8
leaq 0x7272d(%rip), %rsi     # 0x12d2f4
xorl %ebp, %ebp
movq %r14, %rdi
xorl %eax, %eax
callq 0xde896
jmp 0xbaca2
cmpl $0x52494658, %ebp       # imm = 0x52494658
je 0xbabe8
cmpl $0x52494646, %ebp       # imm = 0x52494646
jne 0xbabf6
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0xbabf6
callq 0xeac85
movl $0x41564920, %eax       # imm = 0x41564920
xorl 0x9c(%rbx), %eax
orl %r13d, %eax
xorl $0x6d6f7669, %r12d      # imm = 0x6D6F7669
pushq $0x1
popq %rbp
orl %eax, %r12d
jne 0xbaca2
cmpl $0x1, (%r14)
jg 0xbac9b
leaq 0x726ed(%rip), %rsi     # 0x12d311
jmp 0xbabc7
cmpl $0x52494658, %ebp       # imm = 0x52494658
je 0xbac3a
cmpl $0x52494646, %ebp       # imm = 0x52494646
jne 0xbab98
cmpl $0x0, (%r15)
jne 0xbab98
cmpl $0x41434f4e, %r12d      # imm = 0x41434F4E
je 0xbacf6
cmpl $0x636d6f76, %r12d      # imm = 0x636D6F76
je 0xbad2c
cmpl $0x43445258, %r12d      # imm = 0x43445258
je 0xbad23
cmpl $0x434d5831, %r12d      # imm = 0x434D5831
je 0xbaccb
cmpl $0x57415645, %r12d      # imm = 0x57415645
je 0xbaced
cmpl $0x57454250, %r12d      # imm = 0x57454250
je 0xbace4
cmpl $0x41564920, %r12d      # imm = 0x41564920
jne 0xbacff
leaq 0x7262a(%rip), %rsi     # 0x12d2c0
jmp 0xbad43
cmpb $0x0, 0xe(%r15)
je 0xbacbd
movl 0x64(%rbx), %eax
testl %eax, %eax
jne 0xbacac
incl (%r15)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, 0xe(%r15)
movl 0x64(%rbx), %eax
movl %eax, 0x10(%r15)
jmp 0xbaca5
leaq 0x210(%rip), %rax       # 0xbaee2
movq %rax, 0x40(%rbx)
movb $0x1, 0xc(%r15)
leaq 0x725e2(%rip), %rsi     # 0x12d2c4
jmp 0xbad43
leaq 0x725ed(%rip), %rsi     # 0x12d2d8
jmp 0xbad43
leaq 0x8259c(%rip), %rsi     # 0x13d290
jmp 0xbad43
leaq 0x725ab(%rip), %rsi     # 0x12d2a8
jmp 0xbad43
movl %r12d, %eax
andl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl $0x43445200, %eax       # imm = 0x43445200
jne 0xbab98
movl $0x1, 0x4(%r15)
leaq 0x725bc(%rip), %rsi     # 0x12d2dd
jmp 0xbad43
leaq 0x58ae8(%rip), %rsi     # 0x113812
jmp 0xbad43
leaq 0x1af(%rip), %rax       # 0xbaee2
movq %rax, 0x40(%rbx)
movb $0x1, 0xd(%r15)
leaq 0x7258b(%rip), %rsi     # 0x12d2ce
movq %r14, %rdi
callq 0xe07f7
jmp 0xbab98