// File: /workspace/github_c_makefile_star2_O3/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, (%rsp)
movq %rdi, %rbx
leaq 0x2c(%rsp), %rsi
callq 0xe8a1c
movq (%r15), %rdx
movq 0x10(%r15), %rax
cmpq %rax, %rdx
jge 0xaab1c
movq 0x8(%r15), %rcx
cmpq %rcx, %rdx
cmovgq %rdx, %rcx
subq %rcx, %rax
cmpq $0x4, %rax
jge 0xaab4e
xorl %r15d, %r15d
xorl %r14d, %r14d
movl 0x2c(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
movl %r15d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x89560(%rip), %rsi     # 0x1340b5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
testl %ebp, %ebp
je 0xaabb3
movq %rbx, %rdi
movq (%rsp), %rsi
movq %r15, %rdx
callq 0xab121
leaq 0x80(%rsp), %r12
movq %rax, (%r12)
leaq 0x8953c(%rip), %rsi     # 0x1340ce
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq %r12, %rdi
callq 0xebad2
movq (%r12), %rax
movq (%r15), %rbp
movq 0x10(%r15), %rcx
jmp 0xaabdd
movq (%r15), %rbp
movq 0x10(%r15), %rcx
movq %rcx, %rax
subq %rbp, %rax
jle 0xaabd3
movq 0x8(%r15), %rdx
cmpq %rdx, %rbp
jge 0xaabd5
movq %rcx, %rax
subq %rdx, %rax
jmp 0xaabd5
xorl %eax, %eax
movq %rax, 0x80(%rsp)
xorl %r12d, %r12d
testq %rax, %rax
movl $0x0, %edx
cmovgq %rax, %rdx
addq %rbp, %rdx
cmpq %rcx, %rdx
cmovgeq %rcx, %rdx
addq %rbp, %rax
movq %rax, (%r15)
movl $0x1, %r15d
movq %rdx, 0x58(%rsp)
cmpq %rdx, %rbp
jge 0xaab1f
movq 0x18(%rbx), %rdi
movq (%rsp), %rax
movl 0x4(%rax), %edx
movq %rbp, %rsi
callq 0xeef8a
movq %rax, %r15
addq $0x2, %rbp
movq %rax, %rdx
negq %rdx
cmovsq %rax, %rdx
movq %rax, %r13
shrq $0x3f, %r13
leaq 0x894ad(%rip), %rsi     # 0x1340ef
movq %rbx, %rdi
movq %rdx, 0x50(%rsp)
xorl %eax, %eax
callq 0xe8617
leaq 0x894a7(%rip), %rsi     # 0x1340ff
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe8617
movl $0x10, %esi
movq %rbx, %rdi
callq 0xe8b2b
xorps %xmm0, %xmm0
movq %rax, 0x8(%rsp)
movups %xmm0, (%rax)
testq %r15, %r15
je 0xab0c4
leaq 0x10(%rsp), %r15
xorl %edx, %edx
movq %rbx, %rdi
leaq 0x8947f(%rip), %rsi     # 0x134116
movq %rdx, 0x70(%rsp)
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbp, 0x18(%rsp)
movq %rbp, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
movq (%rsp), %r14
movq %r14, %rsi
movq %r15, %rdx
leaq 0x88bff(%rip), %rcx     # 0x1338d9
callq 0xa76cc
movq 0x18(%rbx), %rdi
movl 0x4(%r14), %edx
movq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0xeef43
movq %rax, %r12
addq $0x2, %r15
movq %r15, 0x10(%rsp)
movq %rbx, %rdi
leaq 0x73ff6(%rip), %rsi     # 0x11ed00
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
testq %r12, %r12
movq %rbp, 0x78(%rsp)
jle 0xaad9d
xorl %r15d, %r15d
movq 0x18(%rbx), %rdi
movq (%rsp), %r14
movl 0x4(%r14), %edx
movq 0x10(%rsp), %rbp
movq %rbp, %rsi
callq 0xeef8a
movq %rax, %r13
addq $0x2, %rbp
movq %rbp, 0x10(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x10(%rsp), %rdx
callq 0xab121
movq %rax, 0x48(%rsp)
movq %rbx, %rdi
leaq 0x89402(%rip), %rsi     # 0x134167
movl %r15d, %edx
movl %r13d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0xe8617
leaq 0x48(%rsp), %rdi
callq 0xebad2
movq 0x8(%rsp), %rdx
incq (%rdx)
movq 0x48(%rsp), %rax
addq %rax, 0x8(%rdx)
incq %r15
cmpq %r15, %r12
jne 0xaad21
movq 0x10(%rsp), %r15
movq 0x18(%rbx), %rdi
xorl %r8d, %r8d
movq (%rsp), %rax
cmpl $0x0, 0x4(%rax)
setne %r8b
movq %r15, %rsi
leaq 0x88(%rsp), %r12
movq %r12, %rdx
movl $0x4, %ecx
callq 0xf1762
leaq 0x4(%r15), %rdx
cmpl $0x3842494d, 0x8c(%rsp) # imm = 0x3842494D
jne 0xab0ed
movq 0x18(%rbx), %rdi
xorl %r8d, %r8d
movq (%rsp), %r14
cmpl $0x0, 0x4(%r14)
setne %r8b
movq %rdx, %rsi
movq %r12, %rdx
movl $0x4, %ecx
callq 0xf1762
leaq 0x8(%r15), %r12
movq %rbx, %rdi
leaq 0x893a6(%rip), %rsi     # 0x1341b5
leaq 0x98(%rsp), %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeead3
leaq 0x9(%r15), %r12
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x8938b(%rip), %rsi     # 0x1341c6
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeead3
leaq 0xa(%r15), %r12
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x89373(%rip), %rsi     # 0x1341d2
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeead3
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x851f7(%rip), %rsi     # 0x130076
xorl %eax, %eax
callq 0xe8617
leaq 0xc(%r15), %rsi
movq 0x18(%rbx), %rdi
movl 0x4(%r14), %edx
callq 0xeeff3
movq %rax, %r12
addq %r15, %rax
addq $0x10, %rax
movq 0x20(%rsp), %rcx
cmpq %rcx, %rax
jg 0xab0fc
leaq 0x10(%r15), %r14
testq %r12, %r12
movl $0x0, %eax
cmovleq %rax, %r12
addq %r14, %r12
cmpq %rcx, %r12
movq %rcx, 0x68(%rsp)
cmovgeq %rcx, %r12
movq %r12, 0x10(%rsp)
movq (%rsp), %rax
movl 0x4(%rax), %edx
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeeff3
movq %rax, %r13
movq %rbx, %rdi
leaq 0x89332(%rip), %rsi     # 0x134225
movl %r13d, %edx
xorl %eax, %eax
callq 0xe8617
movq %r12, %rax
movl $0x0, %ebp
subq %r14, %rax
jle 0xaaf1f
leaq (%r15,%r13), %rbp
addq $0x14, %rbp
cmpq %r12, %rbp
jle 0xaaf1c
movq %rax, %rbp
jmp 0xaaf1f
subq %r14, %rbp
addq %r14, %rbp
movq (%rsp), %rax
movl 0x4(%rax), %edx
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeeff3
movq %rax, %r15
movq %rbx, %rdi
leaq 0x892fc(%rip), %rsi     # 0x13423e
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq %r12, %r13
subq %rbp, %r13
jle 0xaaf69
leaq (%r15,%rbp), %rax
addq $0x4, %rax
cmpq %r12, %rax
jg 0xaaf6c
subq %rbp, %rax
movq %rax, %r13
jmp 0xaaf6c
xorl %r13d, %r13d
addq %rbp, %r13
movq %r13, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movq %r12, 0x40(%rsp)
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r15
movq %rbx, %rdi
movq (%rsp), %rsi
movq %rax, %rdx
leaq 0x30(%rsp), %rcx
callq 0xa5fe3
movq %r15, 0x60(%rsp)
movq %r15, %rdi
callq 0xf705c
movq %rbx, %rdi
leaq 0x892ae(%rip), %rsi     # 0x134262
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rbp
movq %rbp, %r15
subq %rax, %r15
jle 0xaafe2
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
jle 0xaafe9
movq %rax, %r14
movq %r15, %rdi
jmp 0xaafef
movq %rax, %r14
xorl %edi, %edi
jmp 0xaafef
movq %rax, %r14
subq %rax, %rdi
callq 0xe9c87
leaq (%rax,%r14), %rcx
cmpq %rbp, %rcx
cmovleq %rax, %r15
cmpq %r14, %rbp
movl $0x0, %eax
cmovleq %rax, %r15
movq 0x60(%rsp), %rdi
callq 0xf6753
addq %r13, %r15
cmpq %r15, %r12
jle 0xab073
movl %r12d, %ecx
subl %r15d, %ecx
movq %rbx, %rdi
leaq 0x891cf(%rip), %rsi     # 0x1341fc
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %r15, 0x38(%rsp)
movq %r15, 0x30(%rsp)
movq %r12, 0x40(%rsp)
movq %rbx, %rdi
movq (%rsp), %rsi
leaq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq 0xa8d66
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x18(%rsp), %rax
subq %rax, %r12
cmpq %rax, 0x68(%rsp)
movl $0x0, %eax
cmovleq %rax, %r12
movq 0x78(%rsp), %rbp
addq %r12, %rbp
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x70(%rsp), %rdx
incq %rdx
cmpq 0x50(%rsp), %rdx
leaq 0x10(%rsp), %r15
jne 0xaac8d
movq 0x8(%rsp), %r14
movl (%r14), %r12d
movq 0x8(%r14), %r8
jmp 0xab0cc
xorl %r8d, %r8d
movq 0x8(%rsp), %r14
leaq 0x8905a(%rip), %rsi     # 0x13412d
movq %rbx, %rdi
movl %ebp, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe8617
movl $0x1, %r15d
jmp 0xaab22
addl $-0x4, %edx
leaq 0x89090(%rip), %rsi     # 0x134187
movq %rbx, %rdi
jmp 0xab10a
movl 0x18(%rsp), %edx
leaq 0x890d8(%rip), %rsi     # 0x1341df
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
movl $0x1, %r15d
movq 0x8(%rsp), %r14
jmp 0xaab22