// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/psd.c
// Function: do_layer_info_section
static int do_layer_info_section(deark *c, lctx *d, zztype *zz, int has_len_field)
{
	int retval = 0;
	i64 layer_info_len;
	i64 layer_count_raw, layer_count;
	int saved_indent_level;
	int merged_result_flag;
	i64 layer_idx;
	zztype datazz;
	zztype czz;
	struct channel_data *cd = NULL;

	de_dbg_indent_save(c, &saved_indent_level);
	if(zz_avail(zz)<4) goto done;

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

	if(has_len_field) {
		layer_info_len = psd_getu32or64zz(c, d, zz);
		de_dbg(c, "length of layer info section: %d", (int)layer_info_len);
		de_sanitize_length(&layer_info_len);
	}
	else {
		layer_info_len = zz_avail(zz);
	}
	zz_init_with_len(&datazz, zz, layer_info_len);
	zz->pos += layer_info_len;
	retval = 1;

	if(datazz.pos>=datazz.endpos) {
		// If the length field is 0, it's legal for this section to end here.
		goto done;
	}

	layer_count_raw = psd_geti16zz(&datazz);
	if(layer_count_raw<0) {
		merged_result_flag = 1;
		layer_count = -layer_count_raw;
	}
	else {
		merged_result_flag = 0;
		layer_count = layer_count_raw;
	}
	de_dbg(c, "layer count: %d", (int)layer_count);
	de_dbg(c, "merged result flag: %d", (int)merged_result_flag);

	// Due to the recursive possibilities of PSD format, it would probably
	// be a bad idea to store this channel information in the 'd' struct.
	// Instead, we'll use a local variable.
	cd = de_malloc(c, sizeof(struct channel_data));
	cd->num_channels = 0;
	cd->total_len = 0;

	for(layer_idx=0; layer_idx<layer_count; layer_idx++) {
		de_dbg(c, "layer record[%d] at %d", (int)layer_idx, (int)datazz.pos);
		de_dbg_indent(c, 1);
		zz_init(&czz, &datazz);
		if(!do_layer_record(c, d, &czz, cd))
			goto done;
		datazz.pos += zz_used(&czz);
		de_dbg_indent(c, -1);
	}

	de_dbg(c, "channel image data records at %d, count=%d, total len=%"I64_FMT"",
		(int)datazz.pos, (int)cd->num_channels, cd->total_len);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x4c(%rsp), %rsi
callq 0xe958c
movq (%r15), %rdx
movq 0x10(%r15), %rcx
movq %rcx, %rax
subq %rdx, %rax
jle 0xab57c
movq 0x8(%r15), %rsi
cmpq %rsi, %rdx
jge 0xab57e
subq %rsi, %rcx
movq %rcx, %rax
jmp 0xab57e
xorl %eax, %eax
cmpq $0x4, %rax
jge 0xab592
movq $0x0, 0x38(%rsp)
jmp 0xabb8d
leaq 0x88724(%rip), %rsi     # 0x133cbd
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
testl %ebp, %ebp
je 0xab5e8
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xabbfd
leaq 0x50(%rsp), %r12
movq %rax, (%r12)
leaq 0x88704(%rip), %rsi     # 0x133cd6
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq %r12, %rdi
callq 0xec0d1
jmp 0xab60f
movq (%r15), %rdx
movq 0x10(%r15), %rcx
movq %rcx, %rax
subq %rdx, %rax
jle 0xab608
movq 0x8(%r15), %rsi
cmpq %rsi, %rdx
jge 0xab60a
subq %rsi, %rcx
movq %rcx, %rax
jmp 0xab60a
xorl %eax, %eax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
testq %rax, %rax
movl $0x0, %edx
cmovgq %rax, %rdx
movq (%r15), %r13
movq 0x10(%r15), %rcx
addq %r13, %rdx
cmpq %rcx, %rdx
cmovgeq %rcx, %rdx
addq %r13, %rax
movq %rax, (%r15)
movl $0x1, %eax
movq %rax, 0x38(%rsp)
movq %rdx, 0x68(%rsp)
cmpq %rdx, %r13
jge 0xabb8d
movq 0x18(%rbx), %rdi
movl 0x4(%r14), %edx
movq %r13, %rsi
callq 0xef5b7
movq %rax, %r15
addq $0x2, %r13
movq %rax, %rdx
negq %rdx
cmovsq %rax, %rdx
movq %rax, %r12
shrq $0x3f, %r12
leaq 0x88679(%rip), %rsi     # 0x133cf7
movq %rbx, %rdi
movq %rdx, 0x60(%rsp)
xorl %eax, %eax
callq 0xe9226
leaq 0x88673(%rip), %rsi     # 0x133d07
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
movl $0x10, %esi
movq %rbx, %rdi
callq 0xe969b
xorps %xmm0, %xmm0
movq %rax, 0x40(%rsp)
movups %xmm0, (%rax)
testq %r15, %r15
je 0xabb6b
movq %rsp, %r15
xorl %edx, %edx
movq %r14, 0x30(%rsp)
movq %rbx, %rdi
leaq 0x88648(%rip), %rsi     # 0x133d1e
movq %rdx, 0x78(%rsp)
movl %r13d, %ecx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %r13, 0x8(%rsp)
movq %r13, 0x80(%rsp)
movq %r13, (%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
leaq 0x87dc4(%rip), %rcx     # 0x1334e1
callq 0xa80fd
movq 0x18(%rbx), %rdi
movl 0x4(%r14), %edx
movq (%rsp), %r13
movq %r13, %rsi
callq 0xef570
movq %rax, %r15
addq $0x2, %r13
movq %r13, (%rsp)
movq %rbx, %rdi
leaq 0x734ad(%rip), %rsi     # 0x11ebf8
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
testq %r15, %r15
movq %rbx, %rbp
jle 0xab7d5
xorl %r13d, %r13d
movq 0x18(%rbp), %rdi
movl 0x4(%r14), %edx
movq %rbp, %rbx
movq (%rsp), %rbp
movq %rbp, %rsi
callq 0xef5b7
movq %rax, %r12
addq $0x2, %rbp
movq %rbp, (%rsp)
movq %rbx, %rbp
movq %rbx, %rdi
movq %r14, %rsi
movq %rsp, %rdx
callq 0xabbfd
movq %rax, 0x58(%rsp)
movq %rbx, %rdi
leaq 0x885cd(%rip), %rsi     # 0x133d6f
movl %r13d, %edx
movl %r12d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0xe9226
leaq 0x58(%rsp), %rdi
callq 0xec0d1
movq 0x40(%rsp), %rcx
incq (%rcx)
movq 0x58(%rsp), %rax
addq %rax, 0x8(%rcx)
incq %r13
cmpq %r13, %r15
jne 0xab760
movq 0x18(%rbp), %rdi
movq (%rsp), %r13
xorl %r8d, %r8d
cmpl $0x0, 0x4(%r14)
setne %r8b
movq %r13, %rsi
leaq 0x88(%rsp), %r12
movq %r12, %rdx
movl $0x4, %ecx
callq 0xf1d74
leaq 0x4(%r13), %rdx
movq %rdx, (%rsp)
cmpl $0x3842494d, 0x8c(%rsp) # imm = 0x3842494D
jne 0xabbbe
movq 0x18(%rbp), %rdi
xorl %r8d, %r8d
cmpl $0x0, 0x4(%r14)
setne %r8b
movq %rdx, %rsi
movq %r12, %rdx
movl $0x4, %ecx
callq 0xf1d74
leaq 0x8(%r13), %rbx
movq %rbx, (%rsp)
movq %rbp, %rdi
leaq 0x88571(%rip), %rsi     # 0x133dbd
leaq 0x98(%rsp), %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbp), %rdi
movq %rbx, %rsi
callq 0xef0d5
leaq 0x9(%r13), %rbx
movq %rbx, (%rsp)
movzbl %al, %edx
movq %rbp, %rdi
leaq 0x88552(%rip), %rsi     # 0x133dce
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbp), %rdi
movq %rbx, %rsi
callq 0xef0d5
leaq 0xa(%r13), %rbx
movq %rbx, (%rsp)
movzbl %al, %edx
movq %rbp, %rdi
leaq 0x88536(%rip), %rsi     # 0x133dda
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbp), %rdi
movq %rbx, %rsi
callq 0xef0d5
leaq 0xb(%r13), %rcx
movq %rcx, (%rsp)
movzbl %al, %edx
movq %rbp, %rdi
leaq 0x8449e(%rip), %rsi     # 0x12fd6a
xorl %eax, %eax
callq 0xe9226
leaq 0xc(%r13), %rsi
movq %rsi, (%rsp)
movq 0x18(%rbp), %rdi
movl 0x4(%r14), %edx
callq 0xef614
movq %rbp, %rbx
movq %rax, %rbp
movq %r14, %rdx
leaq 0x10(%r13), %r14
movq %r14, (%rsp)
leaq (%rax,%r13), %rcx
addq $0x10, %rcx
movq 0x10(%rsp), %rax
cmpq %rax, %rcx
jg 0xabbd7
testq %rbp, %rbp
movl $0x0, %ecx
cmovleq %rcx, %rbp
addq %r14, %rbp
cmpq %rax, %rbp
cmovgeq %rax, %rbp
movq %rbp, (%rsp)
movq %r14, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movq %rbp, 0x28(%rsp)
movq 0x18(%rbx), %rdi
movl 0x4(%rdx), %edx
movq %r14, %rsi
callq 0xef614
movq %rax, %r12
leaq 0x14(%r13), %rax
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
leaq 0x884d0(%rip), %rsi     # 0x133e2d
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
leaq (%r12,%r13), %rax
addq $0x14, %rax
movq %rax, 0x18(%rsp)
movq %rbp, %rcx
movl $0x0, %r15d
subq %r14, %rcx
jle 0xab992
cmpq %rbp, %rax
jle 0xab98c
movq %rcx, %r15
jmp 0xab992
subq %r14, %rax
movq %rax, %r15
leaq (%r15,%r14), %r13
movq %r13, 0x20(%rsp)
movq %r13, 0x18(%rsp)
movq %rbp, 0x28(%rsp)
movq 0x18(%rbx), %rdi
movq 0x30(%rsp), %rax
movl 0x4(%rax), %edx
movq %r13, %rsi
callq 0xef614
movq %rax, %r12
leaq (%r15,%r14), %rax
addq $0x4, %rax
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
leaq 0x88473(%rip), %rsi     # 0x133e46
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
leaq (%r12,%r13), %rax
addq $0x4, %rax
movq %rax, 0x18(%rsp)
movq %rbp, %r12
subq %r13, %r12
jle 0xab9ff
cmpq %rbp, %rax
jg 0xaba02
subq %r13, %rax
movq %rax, %r12
jmp 0xaba02
xorl %r12d, %r12d
movq 0x30(%rsp), %r14
addq %r13, %r12
movq %r12, 0x20(%rsp)
movq %r12, 0x18(%rsp)
movq %rbp, 0x28(%rsp)
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
leaq 0x18(%rsp), %rcx
callq 0xa696e
movq %r15, 0x70(%rsp)
movq %r15, %rdi
callq 0xf74bd
movq %rbx, %rdi
leaq 0x8841c(%rip), %rsi     # 0x133e6a
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %r13
movq %r13, %r15
subq %rax, %r15
jle 0xaba7c
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
jle 0xaba83
movq %rax, %r14
movq %r15, %rdi
jmp 0xaba89
movq %rax, %r14
xorl %edi, %edi
jmp 0xaba89
movq %rax, %r14
subq %rax, %rdi
callq 0xea7de
leaq (%rax,%r14), %rcx
cmpq %r13, %rcx
cmovleq %rax, %r15
cmpq %r14, %r13
movq %rcx, 0x18(%rsp)
movl $0x0, %eax
cmovleq %rax, %r15
movq 0x70(%rsp), %rdi
callq 0xf6bb0
addq %r12, %r15
cmpq %r15, %rbp
movq 0x30(%rsp), %r14
jle 0xabb15
movl %ebp, %ecx
subl %r15d, %ecx
movq %rbx, %rdi
leaq 0x88334(%rip), %rsi     # 0x133e04
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %r15, 0x20(%rsp)
movq %r15, 0x18(%rsp)
movq %rbp, 0x28(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x18(%rsp), %rdx
xorl %ecx, %ecx
callq 0xa9600
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rsi
movq %rsi, %rax
subq %rcx, %rax
movq 0x80(%rsp), %r13
jle 0xabb43
movq (%rsp), %rdx
cmpq %rsi, %rdx
movq %rsp, %r15
jg 0xabb48
subq %rcx, %rdx
movq %rdx, %rax
jmp 0xabb48
xorl %eax, %eax
movq %rsp, %r15
addq %rax, %r13
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x78(%rsp), %rdx
incq %rdx
cmpq 0x60(%rsp), %rdx
jne 0xab6cc
movq 0x40(%rsp), %r14
movl (%r14), %ecx
movq 0x8(%r14), %r8
leaq 0x881b7(%rip), %rsi     # 0x133d35
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
jmp 0xabb90
xorl %r14d, %r14d
movl 0x4c(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movq 0x38(%rsp), %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl $-0x4, %edx
leaq 0x881c7(%rip), %rsi     # 0x133d8f
movq %rbp, %rdi
xorl %eax, %eax
callq 0xe9b27
movq %rbp, %rbx
jmp 0xabbec
movl 0x8(%rsp), %edx
leaq 0x88205(%rip), %rsi     # 0x133de7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
movl $0x1, %eax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %r14
jmp 0xabb90