// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/psd.c
// Function: do_layer_and_mask_info_section
static int do_layer_and_mask_info_section(deark *c, lctx *d, zztype *zz)
{
	i64 layer_and_mask_info_section_len; // The "Length" field. Whole section is 4 bytes longer.
	i64 gl_layer_mask_info_len;
	zztype lmidataczz;
	zztype czz;
	int saved_indent_level;
	int retval = 0;

	de_dbg_indent_save(c, &saved_indent_level);

	// The "layer and mask section" contains up to 3 sub-sections:
	// 1. layer info
	// 2. global layer mask info
	// 3. tagged blocks

	de_dbg(c, "layer & mask info section at %d", (int)zz->pos);
	de_dbg_indent(c, 1);

	layer_and_mask_info_section_len = psd_getu32or64zz(c, d, zz);
	de_dbg(c, "layer & mask info section total data len: %d", (int)layer_and_mask_info_section_len);
	de_sanitize_length(&layer_and_mask_info_section_len);
	if(zz->pos + layer_and_mask_info_section_len > zz->endpos) {
		de_err(c, "Unexpected end of PSD file");
		goto done;
	}
	zz_init_with_len(&lmidataczz, zz, layer_and_mask_info_section_len);

	// We won't use zz again (we'll use lmidataczz instead), so we can go ahead and
	// advance its ->pos field.
	zz->pos += layer_and_mask_info_section_len;
	// Now that we know the size of this element, we can treat this function as "successful".
	retval = 1;

	///// 1. layer info /////

	zz_init(&czz, &lmidataczz);
	if(!do_layer_info_section(c, d, &lmidataczz, 1)) {
		goto done;
	}
	if(czz.endpos > lmidataczz.endpos) {
		de_warn(c, "Oversized Layer Info section");
		goto done;
	}
	lmidataczz.pos += zz_used(&czz);

	/////

	if(lmidataczz.pos >= lmidataczz.endpos) {
		goto done;
	}

	///// 2. global layer mask info /////

	de_dbg(c, "global layer mask info at %d", (int)lmidataczz.pos);
	de_dbg_indent(c, 1);
	gl_layer_mask_info_len = psd_getu32zz(&lmidataczz);
	de_dbg(c, "length of global layer mask info section: %"I64_FMT, gl_layer_mask_info_len);
	de_dbg_indent(c, -1);
	if(lmidataczz.pos+gl_layer_mask_info_len > lmidataczz.endpos) {
		de_warn(c, "Oversized Global Layer Mask Info section");
		goto done;
	}
	lmidataczz.pos += gl_layer_mask_info_len;

	/////

	if(lmidataczz.pos >= lmidataczz.endpos) {
		goto done;
	}

	///// 3. tagged blocks /////

	de_dbg(c, "tagged blocks at %d", (int)lmidataczz.pos);
	de_dbg_indent(c, 1);
	de_dbg(c, "expected length of tagged blocks section: %d", (int)(lmidataczz.endpos-lmidataczz.pos));
	zz_init(&czz, &lmidataczz);
	do_tagged_blocks(c, d, &czz, 0);
	de_dbg_indent(c, -1);

done:
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
leaq 0xccc49(%rip), %rsi     # 0x1c0235
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xf9bc0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0xccc2e(%rip), %rsi     # 0x1c0255
movb $0x0, %al
callq 0x15b0d0
leaq -0x20(%rbp), %rdi
callq 0x15f830
movq -0x18(%rbp), %rax
movq (%rax), %rax
addq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jle 0xf3663
movq -0x8(%rbp), %rdi
leaq 0xccc2b(%rip), %rsi     # 0x1c0282
movb $0x0, %al
callq 0x15bfb0
jmp 0xf380a
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0xf3380
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x1, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xf3580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x40(%rbp), %rdx
movl $0x1, %ecx
callq 0xf9940
cmpl $0x0, %eax
jne 0xf36b6
jmp 0xf380a
movq -0x48(%rbp), %rax
cmpq -0x30(%rbp), %rax
jle 0xf36d7
movq -0x8(%rbp), %rdi
leaq 0xccbd2(%rip), %rsi     # 0x1c029d
movb $0x0, %al
callq 0x15bc10
jmp 0xf380a
leaq -0x58(%rbp), %rdi
callq 0xf3820
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
jl 0xf36f7
jmp 0xf380a
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0xccbb2(%rip), %rsi     # 0x1c02ba
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
leaq -0x40(%rbp), %rsi
callq 0xf3330
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0xccb8f(%rip), %rsi     # 0x1c02d7
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jle 0xf3782
movq -0x8(%rbp), %rdi
leaq 0xccb8f(%rip), %rsi     # 0x1c0305
movb $0x0, %al
callq 0x15bc10
jmp 0xf380a
movq -0x28(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
jl 0xf379a
jmp 0xf380a
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0xccb83(%rip), %rsi     # 0x1c032e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
subq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0xccb6d(%rip), %rsi     # 0x1c0342
movb $0x0, %al
callq 0x15b0d0
leaq -0x58(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xf3580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x58(%rbp), %rdx
xorl %ecx, %ecx
callq 0xf7ce0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x15b5a0
movl -0x60(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop