// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/tar.c
// Function: read_member
static int read_member(deark *c, lctx *d, i64 pos1, i64 *bytes_consumed_member)
{
	int saved_indent_level;
	int retval = 0;
	struct member_data *md = NULL;
	struct phys_member_data *pmd = NULL;
	struct extattr_data *ea = NULL;
	dbuf *outf = NULL;
	unsigned int snflags;
	int tsidx;
	i64 pos = pos1;

	de_dbg_indent_save(c, &saved_indent_level);

	de_dbg(c, "logical archive member at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);

	md = de_malloc(c, sizeof(struct member_data));
	md->fi = de_finfo_create(c);
	md->fi->detect_root_dot_dir = 1;
	md->filename = ucstring_create(c);

	ea = de_malloc(c, sizeof(struct extattr_data));

	while(1) {
		int is_supplemental_item = 0;

		if(pos >= c->infile->len) goto done;
		if(pmd) {
			destroy_pmd(c, pmd);
		}
		pmd = de_malloc(c, sizeof(struct phys_member_data));

		if(!read_phys_member_header(c, d, pmd, pos)) {
			goto done;
		}
		pos += 512;

		if(pmd->linkflag=='L' || pmd->linkflag=='K') {
			is_supplemental_item = 1;
			read_gnu_longpath(c, d, pmd, ea);
		}
		else if(pmd->linkflag == 'x' || pmd->linkflag == 'X') {
			is_supplemental_item = 1;
			read_exthdr(c, d, pmd, ea);
		}
		else if(pmd->linkflag == 'g') {
			read_exthdr(c, d, pmd, d->global_ea);
		}
		// TODO: linkflag 'K'

		if(!is_supplemental_item) {
			break;
		}

		// Prepare to read the next physical member
		pos += de_pad_to_n(pmd->filesize, 512);
	}
	if(!pmd) goto done;

	// At this point, pmd is the main physical member for this logical file.
	// Any other 'pmd's have been discarded, other than extended attributes
	// that were recorded in ea.

	if(ea->has_alt_size) {
		pmd->filesize = ea->alt_size;
	}
	pos += de_pad_to_n(pmd->filesize, 512);

	retval = 1;

	if((pmd->checksum != pmd->checksum_calc) && c->extract_level<2) {
		// TODO: This little more than a hack, so that we don't extract so
		// much garbage if the file is corrupt, or we go off the rails.
		// There are more robust ways to deal with such issues.
		de_dbg(c, "[not extracting, due to bad checksum]");
		goto done;
	}

	// Decide on a filename
	if(ucstring_isnonempty(ea->alt_name)) {
		ucstring_append_ucstring(md->filename, ea->alt_name);
	}
	else {
		if(ucstring_isnonempty(pmd->prefix)) {
			ucstring_append_ucstring(md->filename, pmd->prefix);
			ucstring_append_char(md->filename, '/');
		}
		if(ucstring_isnonempty(pmd->name)) {
			ucstring_append_ucstring(md->filename, pmd->name);
		}
	}

	// Try to figure out what kind of "file" this is.

	if(pmd->linkflag=='2') {
		md->is_symlink = 1;
	}
	else if(pmd->fmt==TARFMT_POSIX || pmd->fmt==TARFMT_STAR) {
		if(pmd->linkflag=='0' || pmd->linkflag==0) {
			md->is_regular_file = 1;
		}
		else if(pmd->linkflag=='5') {
			md->is_dir = 1;
		}
	}
	else if(pmd->fmt==TARFMT_GNU) {
		if(pmd->linkflag=='0' || pmd->linkflag=='7' || pmd->linkflag==0) {
			md->is_regular_file = 1;
		}
		else if(pmd->linkflag=='5') {
			md->is_dir = 1;
		}
	}
	else {
		if(pmd->name->len>=1 && pmd->name->str[pmd->name->len-1]=='/') {
			md->is_dir = 1;
		}
		else if(pmd->linkflag==0 || pmd->linkflag=='0') {
			md->is_regular_file = 1;
		}
	}

	if(ea->main_file_is_special) {
		md->is_regular_file = 0;
	}

	de_dbg(c, "file data at %"I64_FMT", len=%"I64_FMT, pmd->file_data_pos,
		pmd->filesize);

	for(tsidx=0; tsidx<DE_TIMESTAMPIDX_COUNT; tsidx++) {
		if(ea->alt_timestamps[tsidx].is_valid) {
			md->fi->timestamp[tsidx] = ea->alt_timestamps[tsidx];
		}
		else if(pmd->timestamps[tsidx].is_valid) {
			md->fi->timestamp[tsidx] = pmd->timestamps[tsidx];
		}
	}

	if(!md->is_regular_file && !md->is_dir) {
		de_warn(c, "\"%s\" is a %s. It will not be extracted as such.",
			ucstring_getpsz(md->filename),
			md->is_symlink?"symlink":"special file");
	}

	snflags = DE_SNFLAG_FULLPATH;
	if(md->is_dir) {
		md->fi->is_directory = 1;
		snflags |= DE_SNFLAG_STRIPTRAILINGSLASH;
	}
	else if(md->is_regular_file) {
		if((pmd->mode & 0111)!=0) {
			md->fi->mode_flags |= DE_MODEFLAG_EXE;
		}
		else {
			md->fi->mode_flags |= DE_MODEFLAG_NONEXE;
		}
	}
	de_finfo_set_name_from_ucstring(c, md->fi, md->filename, snflags);
	md->fi->original_filename_flag = 1;

	if(pmd->file_data_pos + pmd->filesize > c->infile->len) goto done;

	outf = dbuf_create_output_file(c, NULL, md->fi, 0);

	// If a symlink has no data, write the 'linkname' field instead.
	if(md->is_symlink && pmd->filesize==0) {
		if(ucstring_isnonempty(ea->linkname)) {
			ucstring_write_as_utf8(c, ea->linkname, outf, 0);
			goto done;
		}
		else if(pmd->linkname) {
			dbuf_write(outf, (const u8*)pmd->linkname->sz,
				(i64)pmd->linkname->sz_strlen);
			goto done;
		}
	}

	dbuf_copy(c->infile, pmd->file_data_pos, pmd->filesize, outf);

done:
	dbuf_close(outf);
	*bytes_consumed_member = pos - pos1;
	destroy_pmd(c, pmd);
	destroy_extattr_data(c, ea);
	if(md) {
		ucstring_destroy(md->filename);
		de_finfo_destroy(c, md->fi);
		de_free(c, md);
	}
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// 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)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x9e50f(%rip), %rsi     # 0x1c7382
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movl $0x20, %esi
callq 0x15b780
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movb $0x1, 0xc(%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movl $0x70, %esi
callq 0x15b780
movq %rax, -0x40(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x58(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x128efd
jmp 0x129505
cmpq $0x0, -0x38(%rbp)
je 0x128f11
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x1295c0
movq -0x8(%rbp), %rdi
movl $0x98, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x129620
cmpl $0x0, %eax
jne 0x128f42
jmp 0x129505
movq -0x58(%rbp), %rax
addq $0x200, %rax            # imm = 0x200
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x4c, %eax
je 0x128f6a
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x4b, %eax
jne 0x128f88
movl $0x1, -0x5c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x129da0
jmp 0x128fea
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x78, %eax
je 0x128fa2
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x58, %eax
jne 0x128fc0
movl $0x1, -0x5c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x129f40
jmp 0x128fe8
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x67, %eax
jne 0x128fe6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
callq 0x129f40
jmp 0x128fe8
jmp 0x128fea
cmpl $0x0, -0x5c(%rbp)
jne 0x128ff2
jmp 0x129011
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x15ce90
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x128edf
cmpq $0x0, -0x38(%rbp)
jne 0x12901d
jmp 0x129505
movq -0x40(%rbp), %rax
cmpb $0x0, 0x11(%rax)
je 0x129037
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x15ce90
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x1, -0x28(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x28(%rcx), %rax
je 0x12908e
movq -0x8(%rbp), %rax
cmpl $0x2, 0x90(%rax)
jge 0x12908e
movq -0x8(%rbp), %rdi
leaq 0x9e31e(%rip), %rsi     # 0x1c73a0
movb $0x0, %al
callq 0x15b0d0
jmp 0x129505
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0x1717f0
cmpl $0x0, %eax
je 0x1290b4
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rsi
callq 0x171460
jmp 0x129113
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x1717f0
cmpl $0x0, %eax
je 0x1290eb
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0x171460
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movl $0x2f, %esi
callq 0x1714c0
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x1717f0
cmpl $0x0, %eax
je 0x129111
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x171460
jmp 0x129113
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x32, %eax
jne 0x129130
movq -0x30(%rbp), %rax
movl $0x1, 0x18(%rax)
jmp 0x12924c
movq -0x38(%rbp), %rax
cmpl $0x1, (%rax)
je 0x129142
movq -0x38(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x129188
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x30, %eax
je 0x12915c
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
jne 0x129169
movq -0x30(%rbp), %rax
movl $0x1, 0x14(%rax)
jmp 0x129183
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x35, %eax
jne 0x129181
movq -0x30(%rbp), %rax
movl $0x1, 0x10(%rax)
jmp 0x129183
jmp 0x12924a
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x1291e1
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x30, %eax
je 0x1291b8
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x37, %eax
je 0x1291b8
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
jne 0x1291c5
movq -0x30(%rbp), %rax
movl $0x1, 0x14(%rax)
jmp 0x1291df
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x35, %eax
jne 0x1291dd
movq -0x30(%rbp), %rax
movl $0x1, 0x10(%rax)
jmp 0x1291df
jmp 0x129248
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
cmpq $0x1, 0x10(%rax)
jl 0x12921f
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq 0x10(%rcx), %rcx
subq $0x1, %rcx
cmpl $0x2f, (%rax,%rcx,4)
jne 0x12921f
movq -0x30(%rbp), %rax
movl $0x1, 0x10(%rax)
jmp 0x129246
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
je 0x129239
movq -0x38(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x30, %eax
jne 0x129244
movq -0x30(%rbp), %rax
movl $0x1, 0x14(%rax)
jmp 0x129246
jmp 0x129248
jmp 0x12924a
jmp 0x12924c
movq -0x40(%rbp), %rax
cmpb $0x0, 0x10(%rax)
je 0x129261
movq -0x30(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rcx
leaq 0x9a0e7(%rip), %rsi     # 0x1c3363
movb $0x0, %al
callq 0x15b0d0
movl $0x0, -0x50(%rbp)
cmpl $0x5, -0x50(%rbp)
jge 0x129348
movq -0x40(%rbp), %rax
addq $0x20, %rax
movslq -0x50(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpb $0x0, (%rax)
je 0x1292e6
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x18, %rax
movslq -0x50(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x40(%rbp), %rcx
addq $0x20, %rcx
movslq -0x50(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x129338
movq -0x38(%rbp), %rax
addq $0x48, %rax
movslq -0x50(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpb $0x0, (%rax)
je 0x129336
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x18, %rax
movslq -0x50(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x38(%rbp), %rcx
addq $0x48, %rcx
movslq -0x50(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x129338
jmp 0x12933a
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x12928a
movq -0x30(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jne 0x1293a1
movq -0x30(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x1293a1
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x172500
movq -0x68(%rbp), %rdi
movq %rax, %rdx
movq -0x30(%rbp), %rax
movl 0x18(%rax), %esi
leaq 0x9e071(%rip), %rcx     # 0x1c73f6
leaq 0xaef48(%rip), %rax     # 0x1d82d4
cmpl $0x0, %esi
cmovneq %rax, %rcx
leaq 0x9e02c(%rip), %rsi     # 0x1c73c6
movb $0x0, %al
callq 0x15bc10
movl $0x1, -0x4c(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x1293c9
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movb $0x1, 0x9(%rax)
movl -0x4c(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x4c(%rbp)
jmp 0x12940d
movq -0x30(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0x12940b
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x49, %rax
cmpq $0x0, %rax
je 0x1293f8
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x14(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x14(%rax)
jmp 0x129409
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x14(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x12940b
jmp 0x12940d
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rdx
movl -0x4c(%rbp), %ecx
callq 0x15d2c0
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movb $0x1, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
addq 0x18(%rcx), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x129457
jmp 0x129505
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %eax, %eax
movl %eax, %esi
xorl %ecx, %ecx
callq 0x166c60
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x1294e4
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x1294e4
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1717f0
cmpl $0x0, %eax
je 0x1294b2
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x48(%rbp), %rdx
xorl %ecx, %ecx
callq 0x172150
jmp 0x129505
movq -0x38(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x1294e0
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rdx
callq 0x166170
jmp 0x129505
jmp 0x1294e2
jmp 0x1294e4
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x48(%rbp), %rcx
callq 0x166070
movq -0x48(%rbp), %rdi
callq 0x1676a0
movq -0x58(%rbp), %rcx
subq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x1295c0
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x129580
cmpq $0x0, -0x30(%rbp)
je 0x129568
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x15b5a0
movl -0x28(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)