// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/fmtutil-iff.c
// Function: do_iff_chunk_sequence
static int do_iff_chunk_sequence(deark *c, struct de_iffctx *ictx,
	struct de_iffchunkctx *parent, i64 pos1, i64 len, int level)
{
	i64 pos;
	i64 endpos;
	i64 chunk_len;
	struct de_fourcc saved_container_fmt4cc;
	struct de_fourcc saved_container_contentstype4cc;
	int ret;

	if(level >= 16) { // An arbitrary recursion limit.
		return 0;
	}

	endpos = pos1+len;
	saved_container_fmt4cc = ictx->curr_container_fmt4cc;
	saved_container_contentstype4cc = ictx->curr_container_contentstype4cc;

	pos = pos1;
	while(pos < endpos) {
		ictx->curr_container_fmt4cc = saved_container_fmt4cc;
		ictx->curr_container_contentstype4cc = saved_container_contentstype4cc;

		if(ictx->handle_nonchunk_data_fn) {
			i64 skip_len = 0;

			ictx->level = level;
			// TODO: Currently, this is called unconditionally. Maybe we should
			// only call it when it looks like there is non-chunk data.
			ret = ictx->handle_nonchunk_data_fn(ictx, pos, &skip_len);
			if(ret && skip_len>0) {
				pos += de_pad_to_n(skip_len, ictx->alignment);
				continue;
			}
		}

		ret = do_iff_chunk(c, ictx, parent, pos, endpos-pos, level, &chunk_len);
		if(!ret) return 0;
		pos += chunk_len;
	}

	ictx->curr_container_fmt4cc = saved_container_fmt4cc;
	ictx->curr_container_contentstype4cc = saved_container_contentstype4cc;

	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
cmpl $0x10, -0x34(%rbp)
jl 0x18cab5
movl $0x0, -0x4(%rbp)
jmp 0x18cc44
movq -0x28(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rsi
addq $0xc8, %rsi
leaq -0x80(%rbp), %rdi
movl $0x30, %edx
callq 0x191e0
movq -0x18(%rbp), %rsi
addq $0xf8, %rsi
leaq -0xb0(%rbp), %rdi
movl $0x30, %edx
callq 0x191e0
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jge 0x18cc08
movq -0x18(%rbp), %rdi
addq $0xc8, %rdi
leaq -0x80(%rbp), %rsi
movl $0x30, %edx
callq 0x191e0
movq -0x18(%rbp), %rdi
addq $0xf8, %rdi
leaq -0xb0(%rbp), %rsi
movl $0x30, %edx
callq 0x191e0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x18cbb6
movq $0x0, -0xc0(%rbp)
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x64(%rax)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq *%rax
movl %eax, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
je 0x18cbb4
cmpq $0x0, -0xc0(%rbp)
jle 0x18cbb4
movq -0xc0(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rsi
callq 0x15ce90
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x18cafe
jmp 0x18cbb6
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
subq -0x40(%rbp), %r8
movl -0x34(%rbp), %r9d
leaq -0x50(%rbp), %rax
movq %rax, (%rsp)
callq 0x18cc50
movl %eax, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
jne 0x18cbf7
movl $0x0, -0x4(%rbp)
jmp 0x18cc44
movq -0x50(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x18cafe
movq -0x18(%rbp), %rdi
addq $0xc8, %rdi
leaq -0x80(%rbp), %rsi
movl $0x30, %edx
callq 0x191e0
movq -0x18(%rbp), %rdi
addq $0xf8, %rdi
leaq -0xb0(%rbp), %rsi
movl $0x30, %edx
callq 0x191e0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq