// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/psd.c
// Function: do_filter_effect
static void do_filter_effect(deark *c, lctx *d, zztype *zz)
{
	i64 ver2;
	i64 dlen2;
	de_ucstring *s = NULL;
	i64 x;
	i64 ch;
	i64 max_channels;
	u8 b;
	zztype czz;
	int saved_indent_level;
	i64 filter_effects_savedpos;

	de_dbg_indent_save(c, &saved_indent_level);

	s = ucstring_create(c);

	ucstring_empty(s);
	read_pascal_string_to_ucstring(c, d, s, zz);
	de_dbg(c, "identifier: \"%s\"", ucstring_getpsz(s));

	// Note the clear similarites to the "virtual memory array lists" used in
	// Pattern data. But it is not the same. Maybe some of the code should be
	// consolidated.

	ver2 = psd_getu32zz(zz);
	de_dbg(c, "version: %d", (int)ver2);
	if(ver2 != 1) goto done;

	dlen2 = psd_geti64zz(zz);
	de_dbg(c, "length: %"I64_FMT"", dlen2);
	de_sanitize_length(&dlen2);
	filter_effects_savedpos = zz->pos;

	read_rectangle_tlbr(c, d, zz, "rectangle");

	x = psd_getu32zz(zz);
	de_dbg(c, "depth: %d", (int)x);

	max_channels = psd_getu32zz(zz);
	de_dbg(c, "max channels: %d", (int)max_channels);

	for(ch=0; ch<max_channels+2; ch++) {
		i64 is_written;

		if(zz->pos >= zz->endpos) goto done;

		// Look ahead at the array-is-written flag.
		is_written = psd_getu32(zz->pos);

		de_dbg(c, "channel[%d] at %d%s", (int)ch, (int)zz->pos,
			is_written?"":" (empty)");

		if(is_written) {
			zz_init(&czz, zz);
			de_dbg_indent(c, 1);
			do_filter_effect_channel(c, d, &czz);
			de_dbg_indent(c, -1);
			zz->pos += zz_used(&czz);
		}
		else {
			zz->pos += 4;
		}
	}

	if(zz->pos < (filter_effects_savedpos + dlen2)) {
		de_dbg(c, "[%d unknown bytes at %d]", (int)(filter_effects_savedpos + dlen2 - zz->pos),
			(int)zz->pos);
	}

	zz->pos = filter_effects_savedpos + dlen2;

	b = psd_getbytezz(zz);
	de_dbg(c, "next-items-present: %d", (int)b);

	if(b) {
		x = psd_getu16zz(zz);
		dbg_print_compression_method(c, d, x);
	}

	de_dbg(c, "[%d bytes at %d]", (int)zz_avail(zz), (int)zz->pos);
	zz->pos = zz->endpos;

done:
	ucstring_destroy(s);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x171210
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0xf3e30
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %rdi
callq 0x172500
movq -0x88(%rbp), %rdi
movq %rax, %rdx
leaq 0xc521a(%rip), %rsi     # 0x1c00e6
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf3330
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0xc5310(%rip), %rsi     # 0x1c0210
movb $0x0, %al
callq 0x15b0d0
cmpq $0x1, -0x20(%rbp)
je 0xfaf13
jmp 0xfb1cf
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf8890
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0xa7b59(%rip), %rsi     # 0x1a2a97
movb $0x0, %al
callq 0x15b0d0
leaq -0x28(%rbp), %rdi
callq 0x15f830
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0xb01ba(%rip), %rcx     # 0x1ab126
callq 0xf5820
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf3330
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0xb2d51(%rip), %rsi     # 0x1adcef
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf3330
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
leaq 0xc5125(%rip), %rsi     # 0x1c00f7
movb $0x0, %al
callq 0x15b0d0
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
addq $0x2, %rcx
cmpq %rcx, %rax
jge 0xfb0e0
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jl 0xfb00c
jmp 0xfb1cf
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
callq 0x1658c0
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %ecx
movq -0x80(%rbp), %rsi
leaq 0xc4e16(%rip), %r8      # 0x1bfe5f
leaq 0xd5b80(%rip), %rax     # 0x1d0bd0
cmpq $0x0, %rsi
cmovneq %rax, %r8
leaq 0xc50a9(%rip), %rsi     # 0x1c0108
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0x80(%rbp)
je 0xfb0bf
movq -0x18(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0xf3580
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0xfb1f0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
leaq -0x68(%rbp), %rdi
callq 0xf3820
movq %rax, %rcx
movq -0x18(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0xfb0cd
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
movq %rcx, (%rax)
jmp 0xfb0cf
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xfafe1
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x78(%rbp), %rcx
addq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jge 0xfb120
movq -0x8(%rbp), %rdi
movq -0x78(%rbp), %rax
addq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
subq (%rcx), %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %ecx
leaq 0xc5003(%rip), %rsi     # 0x1c011c
movb $0x0, %al
callq 0x15b0d0
movq -0x78(%rbp), %rcx
addq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0xf4120
movb %al, -0x49(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x49(%rbp), %edx
leaq 0xc4fe3(%rip), %rsi     # 0x1c0135
movb $0x0, %al
callq 0x15b0d0
cmpb $0x0, -0x49(%rbp)
je 0xfb18c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf3de0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0xfadb0
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rdi
callq 0xf40b0
movq -0x90(%rbp), %rdi
movl %eax, %edx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %ecx
leaq 0xc4f93(%rip), %rsi     # 0x1c014c
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movl -0x6c(%rbp), %esi
callq 0x15b5a0
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)