// File: /workspace/github_c_makefile_star2_O1/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 0xc2dc8
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 0xc2d7c
leaq 0x774f9(%rip), %rsi     # 0x13a264
xorl %ebp, %ebp
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9226
jmp 0xc2e35
cmpl $0x52494658, %ebp       # imm = 0x52494658
je 0xc2d8c
cmpl $0x52494646, %ebp       # imm = 0x52494646
jne 0xc2d9a
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0xc2d9a
callq 0xf6883
movl $0x41564920, %eax       # imm = 0x41564920
xorl 0x9c(%rbx), %eax
orl %r13d, %eax
xorl $0x6d6f7669, %r12d      # imm = 0x6D6F7669
movl $0x1, %ebp
orl %eax, %r12d
jne 0xc2e35
cmpl $0x1, (%r14)
jg 0xc2e22
leaq 0x774bb(%rip), %rsi     # 0x13a281
jmp 0xc2d6b
cmpl $0x52494658, %ebp       # imm = 0x52494658
je 0xc2ddc
cmpl $0x52494646, %ebp       # imm = 0x52494646
jne 0xc2d3c
cmpl $0x0, (%r15)
jne 0xc2d3c
movb $0x1, %al
xorl %esi, %esi
cmpl $0x434d5830, %r12d      # imm = 0x434D5830
jle 0xc2e4f
cmpl $0x5745424f, %r12d      # imm = 0x5745424F
jg 0xc2e73
cmpl $0x434d5831, %r12d      # imm = 0x434D5831
je 0xc2ea7
cmpl $0x57415645, %r12d      # imm = 0x57415645
jne 0xc2ed2
leaq 0x87393(%rip), %rsi     # 0x14a1b0
jmp 0xc2ed0
cmpb $0x0, 0xe(%r15)
jne 0xc2e35
movb $0x1, 0xe(%r15)
movl 0x64(%rbx), %eax
movl %eax, 0x10(%r15)
cmpl $0x0, 0x64(%rbx)
jne 0xc2e3e
incl (%r15)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x41434f4e, %r12d      # imm = 0x41434F4E
je 0xc2e9e
cmpl $0x41564920, %r12d      # imm = 0x41564920
je 0xc2ec9
cmpl $0x43445258, %r12d      # imm = 0x43445258
jne 0xc2ed2
leaq 0x5d969(%rip), %rsi     # 0x1207da
jmp 0xc2ed0
cmpl $0x57454250, %r12d      # imm = 0x57454250
je 0xc2ec0
cmpl $0x636d6f76, %r12d      # imm = 0x636D6F76
jne 0xc2ed2
leaq 0x7e4(%rip), %rax       # 0xc3670
movq %rax, 0x40(%rbx)
movb $0x1, 0xd(%r15)
leaq 0x773a2(%rip), %rsi     # 0x13a23e
jmp 0xc2ed0
leaq 0x77373(%rip), %rsi     # 0x13a218
jmp 0xc2ed0
leaq 0x7c2(%rip), %rax       # 0xc3670
movq %rax, 0x40(%rbx)
movb $0x1, 0xc(%r15)
leaq 0x77376(%rip), %rsi     # 0x13a234
jmp 0xc2ed0
leaq 0x77381(%rip), %rsi     # 0x13a248
jmp 0xc2ed0
leaq 0x77360(%rip), %rsi     # 0x13a230
xorl %eax, %eax
testb %al, %al
je 0xc2ef8
movl %r12d, %eax
andl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl $0x43445200, %eax       # imm = 0x43445200
jne 0xc2ef6
movl $0x1, 0x4(%r15)
leaq 0x77359(%rip), %rsi     # 0x13a24d
jmp 0xc2ef8
xorl %esi, %esi
testq %rsi, %rsi
je 0xc2d3c
movq %r14, %rdi
callq 0xeb6d6
jmp 0xc2d3c