// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/macrsrc.c
// Function: do_resource_data
static void do_resource_data(deark *c, lctx *d, struct rsrctypeinfo *rti,
	struct rsrcinstanceinfo *rii)
{
	i64 dpos, dlen;
	const char *ext = "bin";
	int extr_flag = 0;
	int is_pict = 0;
	int handled = 0;

	de_dbg(c, "resource data at %d", (int)rii->data_offset);
	de_dbg_indent(c, 1);
	dlen = de_getu32be(rii->data_offset);
	dpos = rii->data_offset+4;
	de_dbg(c, "dpos: %d, dlen: %d", (int)dpos, (int)dlen);
	if(dpos+dlen > c->infile->len) goto done;

	if(d->extract_raw) {
		extract_raw_rsrc(c, d, rti, rii, dpos, dlen);
		goto done;
	}

	if(rii->attribs&0x01) {
		; // Compressed. Don't know how to handle this.
	}
	else if(rti->fcc.id==CODE_PICT && looks_like_pict(c, d, rii, dpos, dlen)) {
		ext = "pict";
		extr_flag = 1;
		is_pict = 1;
	}
	else if(rti->fcc.id==CODE_icns) {
		ext = "icns";
		extr_flag = 1;
	}
	else if(rti->fcc.id==CODE_moov) {
		ext = "mov";
		extr_flag = 1;
	}
	else if(rti->fcc.id==CODE_ANPA && rii->id==10000) {
		de_dbg(c, "IPTC data at %"I64_FMT, dpos);
		de_dbg_indent(c, 1);
		fmtutil_handle_iptc(c, c->infile, dpos, dlen, 0x0);
		de_dbg_indent(c, -1);
		handled = 1;
	}
	else if(rti->is_icns_type) {
		dbuf *icns_dbuf;

		de_dbg(c, "[icns resource]");
		icns_dbuf = get_icns_stream(c, d, rii->id);
		dbuf_write(icns_dbuf, rti->fcc.bytes, 4);
		dbuf_writeu32be(icns_dbuf, 8+dlen);
		dbuf_copy(c->infile, dpos, dlen, icns_dbuf);
		handled = 1;
	}
	else if(rti->is_psrc_type) {
		do_psrc_resource(c, d, rti, rii, dpos, dlen);
		handled = 1;
	}
	else if(rti->fcc.id==CODE_CURS || rti->fcc.id==CODE_crsr) {
		do_crsr_CURS_resource(c, d, rti, rii, dpos, dlen);
		handled = 1;
	}
	else if(rti->fcc.id==CODE_cicn) {
		do_cicn_resource(c, d, rti, rii, dpos, dlen);
		handled = 1;
	}
	else if(rti->fcc.id==CODE_SICN) {
		do_SICN_resource(c, d, rti, rii, dpos, dlen);
		handled = 1;
	}

	if(extr_flag) {
		dbuf *outf = NULL;
		de_finfo *fi = NULL;

		fi = de_finfo_create(c);
		set_resource_filename(c, d, fi, rti, rii, ext);
		outf = dbuf_create_output_file(c, NULL, fi, 0);
		de_finfo_destroy(c, fi);
		if(is_pict) {
			dbuf_write_zeroes(outf, 512);
		}
		dbuf_copy(c->infile, dpos, dlen, outf);
		dbuf_close(outf);
		handled = 1;
	}

	if(!handled && c->debug_level>=2) {
		de_dbg_hexdump(c, c->infile, dpos, dlen, 256, NULL, 0x1);
	}

done:
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq 0xee1f8(%rip), %rax     # 0x1c1207
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %edx
leaq 0xe78d5(%rip), %rsi     # 0x1ba912
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x165470
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
movq -0x30(%rbp), %rax
movl %eax, %ecx
leaq 0xe7894(%rip), %rsi     # 0x1ba926
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
addq -0x30(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xd30b4
jmp 0xd343d
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0xd30df
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
callq 0xd3460
jmp 0xd343d
movq -0x20(%rbp), %rax
movzbl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xd30f4
jmp 0xd335c
movq -0x18(%rbp), %rax
cmpl $0x50494354, 0x4(%rax)  # imm = 0x50494354
jne 0xd313d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0xd3560
cmpl $0x0, %eax
je 0xd313d
leaq 0xcec02(%rip), %rax     # 0x1a1d28
movq %rax, -0x38(%rbp)
movl $0x1, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0xd335a
movq -0x18(%rbp), %rax
cmpl $0x69636e73, 0x4(%rax)  # imm = 0x69636E73
jne 0xd3161
leaq 0xdf7ca(%rip), %rax     # 0x1b291b
movq %rax, -0x38(%rbp)
movl $0x1, -0x3c(%rbp)
jmp 0xd3358
movq -0x18(%rbp), %rax
cmpl $0x6d6f6f76, 0x4(%rax)  # imm = 0x6D6F6F76
jne 0xd3185
leaq 0xe77c4(%rip), %rax     # 0x1ba939
movq %rax, -0x38(%rbp)
movl $0x1, -0x3c(%rbp)
jmp 0xd3356
movq -0x18(%rbp), %rax
cmpl $0x414e5041, 0x4(%rax)  # imm = 0x414E5041
jne 0xd31f8
movq -0x20(%rbp), %rax
cmpl $0x2710, (%rax)         # imm = 0x2710
jne 0xd31f8
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0xe7790(%rip), %rsi     # 0x1ba93d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
xorl %r8d, %r8d
callq 0x173700
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl $0x1, -0x44(%rbp)
jmp 0xd3354
movq -0x18(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0xd3273
movq -0x8(%rbp), %rdi
leaq 0xe7741(%rip), %rsi     # 0x1ba94e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rax
movl (%rax), %edx
callq 0xd3600
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x4, %edx
callq 0x166170
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
callq 0x168b80
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x166070
movl $0x1, -0x44(%rbp)
jmp 0xd3352
movq -0x18(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0xd32a6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
callq 0xd3710
movl $0x1, -0x44(%rbp)
jmp 0xd3350
movq -0x18(%rbp), %rax
cmpl $0x43555253, 0x4(%rax)  # imm = 0x43555253
je 0xd32c0
movq -0x18(%rbp), %rax
cmpl $0x63727372, 0x4(%rax)  # imm = 0x63727372
jne 0xd32e6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
callq 0xd3850
movl $0x1, -0x44(%rbp)
jmp 0xd334e
movq -0x18(%rbp), %rax
cmpl $0x6369636e, 0x4(%rax)  # imm = 0x6369636E
jne 0xd3319
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
callq 0xd3e10
movl $0x1, -0x44(%rbp)
jmp 0xd334c
movq -0x18(%rbp), %rax
cmpl $0x5349434e, 0x4(%rax)  # imm = 0x5349434E
jne 0xd334a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
callq 0xd4620
movl $0x1, -0x44(%rbp)
jmp 0xd334c
jmp 0xd334e
jmp 0xd3350
jmp 0xd3352
jmp 0xd3354
jmp 0xd3356
jmp 0xd3358
jmp 0xd335a
jmp 0xd335c
cmpl $0x0, -0x3c(%rbp)
je 0xd3401
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x38(%rbp), %r9
callq 0xd46c0
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
xorl %ecx, %ecx
callq 0x166c60
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x15d260
cmpl $0x0, -0x40(%rbp)
je 0xd33d8
movq -0x58(%rbp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x1685f0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x166070
movq -0x58(%rbp), %rdi
callq 0x1676a0
movl $0x1, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0xd343b
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0xd343b
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, (%rsp)
callq 0x15b840
jmp 0xd343d
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)