// File: /workspace/github_c_makefile_star2_O3/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), %r12d
movl 0xfc(%rdi), %ebp
cmpl $0x0, 0x64(%rdi)
je 0xc218f
cmpl $0x0, 0x4(%r15)
setne %al
cmpl $0x4c495354, %r12d      # imm = 0x4C495354
sete %r13b
cmpl $0x636d7072, %ebp       # imm = 0x636D7072
sete %cl
andb %r13b, %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xc2285
leaq 0x7845e(%rip), %rsi     # 0x13a5e8
jmp 0xc22d7
cmpl $0x52494658, %r12d      # imm = 0x52494658
je 0xc21a1
cmpl $0x52494646, %r12d      # imm = 0x52494646
jne 0xc2159
cmpl $0x0, (%r15)
jne 0xc2282
cmpl $0x434d5830, %ebp       # imm = 0x434D5830
jle 0xc21db
cmpl $0x5745424f, %ebp       # imm = 0x5745424F
jg 0xc2200
cmpl $0x434d5831, %ebp       # imm = 0x434D5831
je 0xc2251
cmpl $0x57415645, %ebp       # imm = 0x57415645
jne 0xc2232
leaq 0x8858a(%rip), %rsi     # 0x14a760
jmp 0xc227a
cmpl $0x41434f4e, %ebp       # imm = 0x41434F4E
je 0xc2229
cmpl $0x41564920, %ebp       # imm = 0x41564920
je 0xc2273
cmpl $0x43445258, %ebp       # imm = 0x43445258
jne 0xc2232
leaq 0x5e704(%rip), %rsi     # 0x120902
jmp 0xc227a
cmpl $0x57454250, %ebp       # imm = 0x57454250
je 0xc226a
cmpl $0x636d6f76, %ebp       # imm = 0x636D6F76
jne 0xc2232
leaq 0x868(%rip), %rax       # 0xc2a7f
movq %rax, 0x40(%rbx)
movb $0x1, 0xd(%r15)
leaq 0x7839b(%rip), %rsi     # 0x13a5c2
jmp 0xc227a
leaq 0x7836c(%rip), %rsi     # 0x13a59c
jmp 0xc227a
movl %ebp, %eax
andl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl $0x43445200, %eax       # imm = 0x43445200
jne 0xc2282
movl $0x1, 0x4(%r15)
leaq 0x78382(%rip), %rsi     # 0x13a5d1
jmp 0xc227a
leaq 0x827(%rip), %rax       # 0xc2a7f
movq %rax, 0x40(%rbx)
movb $0x1, 0xc(%r15)
leaq 0x78350(%rip), %rsi     # 0x13a5b8
jmp 0xc227a
leaq 0x7835b(%rip), %rsi     # 0x13a5cc
jmp 0xc227a
leaq 0x7833a(%rip), %rsi     # 0x13a5b4
movq %r14, %rdi
callq 0xeb125
xorl %r13d, %r13d
cmpl $0x52494658, %r12d      # imm = 0x52494658
je 0xc2297
cmpl $0x52494646, %r12d      # imm = 0x52494646
jne 0xc22a5
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0xc22a5
callq 0xf6423
cmpl $0x41564920, 0x9c(%rbx) # imm = 0x41564920
sete %al
andb %r13b, %al
cmpl $0x6d6f7669, %ebp       # imm = 0x6D6F7669
sete %cl
andb %al, %cl
movl $0x1, %ebp
cmpb $0x1, %cl
jne 0xc22e3
cmpl $0x1, (%r14)
jg 0xc22fe
leaq 0x7832e(%rip), %rsi     # 0x13a605
xorl %ebp, %ebp
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8617
movl 0x64(%rbx), %eax
testl %eax, %eax
jne 0xc22ed
incl (%r15)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0xe(%r15)
jne 0xc22e3
movb $0x1, 0xe(%r15)
movl 0x64(%rbx), %eax
movl %eax, 0x10(%r15)
jmp 0xc22e6