// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x15b580
movq -0x18(%rbp), %rdi
callq 0xf40b0
cmpq $0x4, %rax
jge 0xf998a
jmp 0xf9b92
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
leaq 0xc615e(%rip), %rsi     # 0x1bfafc
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
cmpl $0x0, -0x1c(%rbp)
je 0xf99f1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xf9bc0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0xc6136(%rip), %rsi     # 0x1bfb15
movb $0x0, %al
callq 0x15b0d0
leaq -0x28(%rbp), %rdi
callq 0x15f830
jmp 0xf99fe
movq -0x18(%rbp), %rdi
callq 0xf40b0
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0x60(%rbp), %rdi
callq 0xf3380
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x1, -0x20(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x50(%rbp), %rax
jl 0xf9a33
jmp 0xf9b92
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
leaq -0x60(%rbp), %rsi
callq 0xf9c30
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jge 0xf9a69
movl $0x1, -0x40(%rbp)
xorl %eax, %eax
subq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0xf9a78
movl $0x0, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0xc60ad(%rip), %rsi     # 0x1bfb36
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %edx
leaq 0xc60a8(%rip), %rsi     # 0x1bfb46
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x10, %esi
callq 0x15b780
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq $0x0, (%rax)
movq -0x80(%rbp), %rax
movq $0x0, 0x8(%rax)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0xf9b69
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
movq -0x60(%rbp), %rax
movl %eax, %ecx
leaq 0xc6062(%rip), %rsi     # 0x1bfb5d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
leaq -0x78(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xf3580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x80(%rbp), %rcx
leaq -0x78(%rbp), %rdx
callq 0xf9c80
cmpl $0x0, %eax
jne 0xf9b39
jmp 0xf9b92
leaq -0x78(%rbp), %rdi
callq 0xf3820
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xf9ad6
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl %eax, %edx
movq -0x80(%rbp), %rax
movq (%rax), %rax
movl %eax, %ecx
movq -0x80(%rbp), %rax
movq 0x8(%rax), %r8
leaq 0xc5fe9(%rip), %rsi     # 0x1bfb74
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x15b5a0
movq -0x8(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x15b820
movl -0x20(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)