// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/apm.c
// Function: do_extract_partition
static void do_extract_partition(deark *c, lctx *d, struct partition_info *pi)
{
	de_finfo *fi = NULL;
	const char *ext = "partition";
	i64 len_to_extract;
	int use_pname_in_name = 1;
	int use_ptype_in_name = 1;
	de_ucstring *outfname = NULL;

	if(pi->partition_startpos >= c->infile->len) goto done;
	len_to_extract = pi->partition_size_in_bytes;
	if(pi->partition_startpos + len_to_extract > c->infile->len) {
		de_warn(c, "Partition at %"I64_FMT" goes beyond end of file", pi->partition_startpos);
		len_to_extract = c->infile->len - pi->partition_startpos;
	}

	fi = de_finfo_create(c);
	outfname = ucstring_create(c);

	if(!de_strcmp(pi->ptype->sz, "Apple_partition_map")) {
		ext = "bin";
		use_pname_in_name = 0;
	}
	else if(!de_strcmp(pi->ptype->sz, "Apple_HFS")) {
		unsigned int sig = (unsigned int)de_getu16be(pi->partition_startpos+1024);
		if(sig==0x4244) { // "BD"
			ext = "hfs";
			use_ptype_in_name = 0;
		}
		else if(sig==0x482b) { // "H+"
			ext="hfs+.hfs";
			use_ptype_in_name = 0;
		}
		else if(sig==0x4858) { // "HX"
			ext="hfsx.hfs";
			use_ptype_in_name = 0;
		}
	}

	if(use_pname_in_name && ucstring_isnonempty(pi->pname)) {
		ucstring_append_ucstring(outfname, pi->pname);
	}
	if(use_ptype_in_name && ucstring_isnonempty(pi->ptype->str)) {
		if(outfname->len>1) {
			ucstring_append_sz(outfname, ".", DE_ENCODING_LATIN1);
		}
		ucstring_append_ucstring(outfname, pi->ptype->str);
	}
	if(outfname->len>1) {
		de_finfo_set_name_from_ucstring(c, fi, outfname, 0);
	}

	dbuf_create_file_from_slice(c->infile, pi->partition_startpos,
		len_to_extract, ext, fi, 0);

done:
	de_finfo_destroy(c, fi);
	ucstring_destroy(outfname);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
leaq 0x1719af(%rip), %rax    # 0x1a01d2
movq %rax, -0x28(%rbp)
movl $0x1, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x2e858
jmp 0x2ea53
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x30(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x2e8b0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x17194b(%rip), %rsi    # 0x1a01dc
movb $0x0, %al
callq 0x15bc10
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
subq 0x8(%rcx), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x171928(%rip), %rsi    # 0x1a0205
callq 0x191a0
cmpl $0x0, %eax
jne 0x2e8fe
leaq 0x192919(%rip), %rax    # 0x1c1207
movq %rax, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
jmp 0x2e997
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x171908(%rip), %rsi    # 0x1a0219
callq 0x191a0
cmpl $0x0, %eax
jne 0x2e995
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x400, %rsi            # imm = 0x400
callq 0x1651d0
movl %eax, -0x44(%rbp)
cmpl $0x4244, -0x44(%rbp)    # imm = 0x4244
jne 0x2e957
leaq 0x1718de(%rip), %rax    # 0x1a0228
movq %rax, -0x28(%rbp)
movl $0x0, -0x38(%rbp)
jmp 0x2e993
cmpl $0x482b, -0x44(%rbp)    # imm = 0x482B
jne 0x2e974
leaq 0x1718bc(%rip), %rax    # 0x1a0223
movq %rax, -0x28(%rbp)
movl $0x0, -0x38(%rbp)
jmp 0x2e991
cmpl $0x4858, -0x44(%rbp)    # imm = 0x4858
jne 0x2e98f
leaq 0x1718a8(%rip), %rax    # 0x1a022c
movq %rax, -0x28(%rbp)
movl $0x0, -0x38(%rbp)
jmp 0x2e991
jmp 0x2e993
jmp 0x2e995
jmp 0x2e997
cmpl $0x0, -0x34(%rbp)
je 0x2e9c0
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x1717f0
cmpl $0x0, %eax
je 0x2e9c0
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x171460
cmpl $0x0, -0x38(%rbp)
je 0x2ea11
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x1717f0
cmpl $0x0, %eax
je 0x2ea11
movq -0x40(%rbp), %rax
cmpq $0x1, 0x10(%rax)
jle 0x2e9fc
movq -0x40(%rbp), %rdi
leaq 0x1987b1(%rip), %rsi    # 0x1c71a3
movl $0x5, %edx
callq 0x1715e0
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x18(%rax), %rsi
callq 0x171460
movq -0x40(%rbp), %rax
cmpq $0x1, 0x10(%rax)
jle 0x2ea2f
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x40(%rbp), %rdx
xorl %ecx, %ecx
callq 0x15d2c0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %r8
xorl %r9d, %r9d
callq 0x166be0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15d260
movq -0x40(%rbp), %rdi
callq 0x171750
addq $0x50, %rsp
popq %rbp
retq
nop