// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0xcc(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl 0xfc(%rax), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x64(%rax)
jne 0x11f5d6
cmpl $0x52494646, -0x1c(%rbp) # imm = 0x52494646
je 0x11f498
cmpl $0x52494658, -0x1c(%rbp) # imm = 0x52494658
jne 0x11f5d6
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x11f5d6
movq $0x0, -0x30(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x34(%rbp)
subl $0x41434f4e, %eax       # imm = 0x41434F4E
je 0x11f50f
jmp 0x11f4bc
movl -0x34(%rbp), %eax
subl $0x41564920, %eax       # imm = 0x41564920
je 0x11f51c
jmp 0x11f4c8
movl -0x34(%rbp), %eax
subl $0x43445258, %eax       # imm = 0x43445258
je 0x11f529
jmp 0x11f4d4
movl -0x34(%rbp), %eax
subl $0x434d5831, %eax       # imm = 0x434D5831
je 0x11f536
jmp 0x11f4e0
movl -0x34(%rbp), %eax
subl $0x57415645, %eax       # imm = 0x57415645
je 0x11f57e
jmp 0x11f4f0
movl -0x34(%rbp), %eax
subl $0x57454250, %eax       # imm = 0x57454250
je 0x11f58b
jmp 0x11f500
movl -0x34(%rbp), %eax
subl $0x636d6f76, %eax       # imm = 0x636D6F76
je 0x11f55a
jmp 0x11f596
leaq 0xa6929(%rip), %rax     # 0x1c5e3f
movq %rax, -0x30(%rbp)
jmp 0x11f596
leaq 0xa6934(%rip), %rax     # 0x1c5e57
movq %rax, -0x30(%rbp)
jmp 0x11f596
leaq 0x8cebb(%rip), %rax     # 0x1ac3eb
movq %rax, -0x30(%rbp)
jmp 0x11f596
leaq 0xa691e(%rip), %rax     # 0x1c5e5b
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
leaq 0x1074(%rip), %rcx      # 0x1205c0
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0xc(%rax)
jmp 0x11f596
leaq 0xa6904(%rip), %rax     # 0x1c5e65
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
leaq 0x1050(%rip), %rcx      # 0x1205c0
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0xd(%rax)
jmp 0x11f596
leaq 0xb6c8b(%rip), %rax     # 0x1d6210
movq %rax, -0x30(%rbp)
jmp 0x11f596
leaq 0xa68dd(%rip), %rax     # 0x1c5e6f
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x11f5c0
movl -0x20(%rbp), %eax
shrl $0x8, %eax
cmpl $0x434452, %eax         # imm = 0x434452
jne 0x11f5c0
movq -0x18(%rbp), %rax
movl $0x1, 0x4(%rax)
leaq 0xa68b8(%rip), %rax     # 0x1c5e74
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x11f5d4
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15e380
jmp 0x11f5d6
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x11f612
cmpl $0x4c495354, -0x1c(%rbp) # imm = 0x4C495354
jne 0x11f612
cmpl $0x636d7072, -0x20(%rbp) # imm = 0x636D7072
jne 0x11f610
movq -0x10(%rbp), %rdi
leaq 0xa688e(%rip), %rsi     # 0x1c5e8b
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x24(%rbp)
jmp 0x11f6a8
jmp 0x11f612
cmpl $0x52494646, -0x1c(%rbp) # imm = 0x52494646
je 0x11f624
cmpl $0x52494658, -0x1c(%rbp) # imm = 0x52494658
jne 0x11f63e
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x11f63c
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x171210
jmp 0x11f63e
movq -0x8(%rbp), %rax
cmpl $0x41564920, 0x9c(%rax) # imm = 0x41564920
jne 0x11f6a6
cmpl $0x4c495354, -0x1c(%rbp) # imm = 0x4C495354
jne 0x11f6a6
cmpl $0x6d6f7669, -0x20(%rbp) # imm = 0x6D6F7669
jne 0x11f6a6
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jge 0x11f684
movq -0x10(%rbp), %rdi
leaq 0xa6834(%rip), %rsi     # 0x1c5ea8
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x24(%rbp)
jmp 0x11f6a8
movq -0x18(%rbp), %rax
cmpb $0x0, 0xe(%rax)
jne 0x11f6a4
movq -0x18(%rbp), %rax
movb $0x1, 0xe(%rax)
movq -0x8(%rbp), %rax
movl 0x64(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x11f6a6
jmp 0x11f6a8
movq -0x8(%rbp), %rax
cmpl $0x0, 0x64(%rax)
jne 0x11f6bd
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
cmpl $0x0, -0x24(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)