// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/psd.c
// Function: do_layer_record
static int do_layer_record(deark *c, lctx *d, zztype *zz, struct channel_data *cd)
{
	i64 nchannels;
	i64 extra_data_len;
	struct de_fourcc tmp4cc;
	i64 ch_id, ch_dlen;
	u8 b;
	int i;
	zztype czz;
	zztype extradatazz;
	int retval = 0;

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

	nchannels = psd_getu16zz(zz);
	de_dbg(c, "number of channels: %d", (int)nchannels);

	for(i=0; i<nchannels; i++) {
		ch_id = psd_geti16zz(zz);
		ch_dlen = psd_getu32or64zz(c, d, zz);
		de_dbg(c, "channel[%d] id=%d, data len=%"I64_FMT"", (int)i, (int)ch_id, ch_dlen);
		de_sanitize_length(&ch_dlen);
		cd->num_channels++;
		cd->total_len += ch_dlen;
	}

	psd_read_fourcc_zz(c, d, zz, &tmp4cc);
	if(tmp4cc.id != CODE_8BIM) {
		de_warn(c, "Expected blend mode signature not found at %d", (int)(zz->pos-4));
		goto done;
	}

	psd_read_fourcc_zz(c, d, zz, &tmp4cc);
	de_dbg(c, "blend mode: '%s'", tmp4cc.id_dbgstr);

	b = psd_getbytezz(zz);
	de_dbg(c, "opacity: %d", (int)b);

	b = psd_getbytezz(zz);
	de_dbg(c, "clipping: %d", (int)b);

	b = psd_getbytezz(zz);
	de_dbg(c, "flags: 0x%02x", (unsigned int)b);

	zz->pos += 1; // filler

	extra_data_len = psd_getu32zz(zz);

	if(zz->pos + extra_data_len > zz->endpos) {
		de_warn(c, "Malformed layer record at %d", (int)zz->startpos);
		goto done;
	}

	zz_init_with_len(&extradatazz, zz, extra_data_len);
	zz->pos = extradatazz.endpos;

	zz_init(&czz, &extradatazz);
	do_layer_mask_data(c, d, &czz);
	extradatazz.pos += zz_used(&czz);

	zz_init(&czz, &extradatazz);
	do_layer_blending_ranges(c, d, &czz);
	extradatazz.pos += zz_used(&czz);

	zz_init(&czz, &extradatazz);
	do_layer_name(c, d, &czz);
	extradatazz.pos += zz_used(&czz);

	if(extradatazz.pos < extradatazz.endpos) {
		// The rest of the layer record data seems to be undocumented,
		// or unclearly documented.
		de_dbg(c, "layer record tagged blocks at %d, len=%d",
			(int)extradatazz.pos, (int)(extradatazz.endpos-extradatazz.pos));
		de_dbg_indent(c, 1);
		zz_init(&czz, &extradatazz);
		do_tagged_blocks(c, d, &czz, 0);
		de_dbg_indent(c, -1);
	}

	retval = 1;
done:
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0xac(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0xc5668(%rip), %rcx     # 0x1bf320
callq 0xf5820
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf3de0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0xb0b92(%rip), %rsi     # 0x1aa87c
movb $0x0, %al
callq 0x15b0d0
movl $0x0, -0x78(%rbp)
movslq -0x78(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0xf9d8b
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf9c30
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xf9bc0
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movl -0x78(%rbp), %edx
movq -0x68(%rbp), %rax
movl %eax, %ecx
movq -0x70(%rbp), %r8
leaq 0xc5e5f(%rip), %rsi     # 0x1bfbae
movb $0x0, %al
callq 0x15b0d0
leaq -0x70(%rbp), %rdi
callq 0x15f830
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x70(%rbp), %rcx
movq -0x20(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0xf9cf8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x60(%rbp), %rcx
callq 0xf3d80
cmpl $0x3842494d, -0x5c(%rbp) # imm = 0x3842494D
je 0xf9dcd
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
subq $0x4, %rax
movl %eax, %edx
leaq 0xc5e0d(%rip), %rsi     # 0x1bfbce
movb $0x0, %al
callq 0x15bc10
jmp 0xfa049
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x60(%rbp), %rcx
callq 0xf3d80
movq -0x8(%rbp), %rdi
leaq -0x60(%rbp), %rdx
addq $0x10, %rdx
leaq 0xc5e07(%rip), %rsi     # 0x1bfbfc
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0xf4120
movb %al, -0x71(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x71(%rbp), %edx
leaq 0xc5dee(%rip), %rsi     # 0x1bfc0d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0xf4120
movb %al, -0x71(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x71(%rbp), %edx
leaq 0xc5dd0(%rip), %rsi     # 0x1bfc19
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0xf4120
movb %al, -0x71(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x71(%rbp), %edx
leaq 0xc1ca6(%rip), %rsi     # 0x1bbb19
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf3330
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
addq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jle 0xf9eda
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
leaq 0xc5d58(%rip), %rsi     # 0x1bfc26
movb $0x0, %al
callq 0x15bc10
jmp 0xfa049
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
callq 0xf3380
movq -0x98(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
leaq -0x90(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xf3580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0xfa060
leaq -0x90(%rbp), %rdi
callq 0xf3820
addq -0xa8(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xf3580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0xfa0c0
leaq -0x90(%rbp), %rdi
callq 0xf3820
addq -0xa8(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xf3580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0xfa120
leaq -0x90(%rbp), %rdi
callq 0xf3820
addq -0xa8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0x98(%rbp), %rax
jge 0xfa03f
movq -0x8(%rbp), %rdi
movq -0xa8(%rbp), %rax
movl %eax, %edx
movq -0x98(%rbp), %rax
subq -0xa8(%rbp), %rax
movl %eax, %ecx
leaq 0xc5c50(%rip), %rsi     # 0x1bfc43
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
leaq -0x90(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xf3580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x90(%rbp), %rdx
xorl %ecx, %ecx
callq 0xf7ce0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl $0x1, -0xac(%rbp)
movl -0xac(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax,%rax)