// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/cpio.c
// Function: read_member
static int read_member(deark *c, lctx *d, i64 pos1,
	i64 *bytes_consumed_member)
{
	int retval = 0;
	struct member_data *md = NULL;
	i64 pos = pos1;
	unsigned int unix_filetype;
	enum { CPIOFT_SPECIAL=0, CPIOFT_REGULAR,
		CPIOFT_DIR, CPIOFT_TRAILER } cpio_filetype;
	dbuf *outf = NULL;
	unsigned int snflags;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);

	de_dbg(c, "member at %"I64_FMT, pos);
	de_dbg_indent(c, 1);

	de_dbg(c, "fixed header at %"I64_FMT, pos);
	de_dbg_indent(c, 1);

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

	identify_cpio_internal(c, md->startpos, &md->subfmt);

	if(md->subfmt==SUBFMT_ASCII_PORTABLE) {
		read_header_ascii_portable(c, d, md);
	}
	else if(md->subfmt==SUBFMT_ASCII_NEW || md->subfmt==SUBFMT_ASCII_NEWCRC) {
		read_header_ascii_new(c, d, md);
	}
	else if(md->subfmt==SUBFMT_BINARY_LE) {
		md->is_le = 1;
		read_header_binary(c, d, md);
	}
	else if(md->subfmt==SUBFMT_BINARY_BE) {
		read_header_binary(c, d, md);
	}
	else {
		de_err(c, "Unknown cpio format at %"I64_FMT, md->startpos);
		goto done;
	}

	de_dbg_indent(c, -1);
	de_dbg(c, "member name at %"I64_FMT, (i64)(md->startpos + md->fixed_header_size));
	de_dbg_indent(c, 1);
	read_member_name(c, d, md);

	pos = md->startpos + md->fixed_header_size + md->namesize_padded;
	de_dbg_indent(c, -1);

	de_dbg(c, "member data at %"I64_FMT", len=%"I64_FMT, pos, md->filesize);
	de_dbg_indent(c, 1);

	if(pos + md->filesize > c->infile->len) {
		goto done;
	}

	retval = 1;

	unix_filetype = (unsigned int)md->mode & 0170000;

	if(unix_filetype==040000) {
		cpio_filetype = CPIOFT_DIR;
	}
	else if(unix_filetype==0100000) {
		cpio_filetype = CPIOFT_REGULAR;
	}
	else {
		cpio_filetype = CPIOFT_SPECIAL;
		if(md->mode==0 && md->namesize==11) {
			if(!de_strcmp(md->filename_srd->sz, "TRAILER!!!")) {
				cpio_filetype = CPIOFT_TRAILER;
				de_dbg(c, "[Trailer. Not extracting.]");
				d->trailer_found = 1;
			}
		}

		if(cpio_filetype==CPIOFT_SPECIAL) {
			de_dbg(c, "[Not a regular file. Skipping.]");
		}
	}

	if(cpio_filetype!=CPIOFT_REGULAR && cpio_filetype!=CPIOFT_DIR) {
		goto done; // Not extracting this member
	}

	snflags = DE_SNFLAG_FULLPATH;
	if(cpio_filetype==CPIOFT_DIR) {
		md->fi->is_directory = 1;
		// Directory members might or might not end in a slash.
		snflags |= DE_SNFLAG_STRIPTRAILINGSLASH;
	}
	else if((md->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_srd->str, snflags);
	md->fi->original_filename_flag = 1;

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

	if(md->subfmt==SUBFMT_ASCII_NEWCRC) {
		de_crcobj_reset(d->crco_cksum);
		dbuf_set_writelistener(outf, de_writelistener_for_crc, (void*)d->crco_cksum);
	}

	dbuf_copy(c->infile, pos, md->filesize, outf);

	if(md->subfmt==SUBFMT_ASCII_NEWCRC) {
		md->checksum_calculated = (UI)de_crcobj_getval(d->crco_cksum);
		de_dbg(c, "checksum (calculated): %u", (unsigned int)md->checksum_calculated);
		if(md->checksum_calculated != md->checksum_reported) {
			de_warn(c, "Checksum failed for file %s: Expected %u, got %u",
				ucstring_getpsz_d(md->filename_srd->str),
				(unsigned int)md->checksum_reported, (unsigned int)md->checksum_calculated);
		}
	}

done:
	dbuf_close(outf);
	if(retval && md) {
		*bytes_consumed_member = md->fixed_header_size + md->namesize_padded + md->filesize_padded;
	}
	if(md) {
		de_destroy_stringreaderdata(c, md->filename_srd);
		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 $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x1714af(%rip), %rsi    # 0x1c7392
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x1500ea(%rip), %rsi    # 0x1a5ff1
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movl $0x60, %esi
callq 0x15b780
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
movb $0x1, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rdx
callq 0x55cc0
movq -0x30(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x55f8e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x563b0
jmp 0x5601b
movq -0x30(%rbp), %rax
cmpl $0x4, (%rax)
je 0x55fa0
movq -0x30(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x55fb3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x56650
jmp 0x56019
movq -0x30(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x55fda
movq -0x30(%rbp), %rax
movl $0x1, 0x4(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x569a0
jmp 0x56017
movq -0x30(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x55ff6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x569a0
jmp 0x56015
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x14fffc(%rip), %rsi    # 0x1a6005
movb $0x0, %al
callq 0x15bfb0
jmp 0x56321
jmp 0x56017
jmp 0x56019
jmp 0x5601b
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x30(%rbp), %rax
addq 0x10(%rax), %rdx
leaq 0x14ffdc(%rip), %rsi    # 0x1a6020
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x56c70
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
addq 0x10(%rcx), %rax
movq -0x30(%rbp), %rcx
addq 0x20(%rcx), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rcx
leaq 0x14ff88(%rip), %rsi    # 0x1a6033
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
addq 0x28(%rcx), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x560df
jmp 0x56321
movl $0x1, -0x24(%rbp)
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
andl $0xf000, %eax           # imm = 0xF000
movl %eax, -0x3c(%rbp)
cmpl $0x4000, -0x3c(%rbp)    # imm = 0x4000
jne 0x5610b
movl $0x2, -0x40(%rbp)
jmp 0x56199
cmpl $0x8000, -0x3c(%rbp)    # imm = 0x8000
jne 0x5611d
movl $0x1, -0x40(%rbp)
jmp 0x56197
movl $0x0, -0x40(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x5617d
movq -0x30(%rbp), %rax
cmpq $0xb, 0x18(%rax)
jne 0x5617d
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x14ff02(%rip), %rsi    # 0x1a604f
callq 0x191a0
cmpl $0x0, %eax
jne 0x5617b
movl $0x3, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x14fef1(%rip), %rsi    # 0x1a605a
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movl $0x1, 0x4(%rax)
jmp 0x5617d
cmpl $0x0, -0x40(%rbp)
jne 0x56195
movq -0x8(%rbp), %rdi
leaq 0x14fee7(%rip), %rsi    # 0x1a6075
movb $0x0, %al
callq 0x15b0d0
jmp 0x56197
jmp 0x56199
cmpl $0x1, -0x40(%rbp)
je 0x561aa
cmpl $0x2, -0x40(%rbp)
je 0x561aa
jmp 0x56321
movl $0x1, -0x4c(%rbp)
cmpl $0x2, -0x40(%rbp)
jne 0x561ce
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
movb $0x1, 0x9(%rax)
movl -0x4c(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x4c(%rbp)
jmp 0x56206
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
andq $0x49, %rax
cmpq $0x0, %rax
je 0x561f3
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
movl 0x14(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x14(%rax)
jmp 0x56204
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
movl 0x14(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x56206
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x18(%rax), %rdx
movl -0x4c(%rbp), %ecx
callq 0x15d2c0
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
movb $0x1, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rdx
xorl %eax, %eax
movl %eax, %esi
xorl %ecx, %ecx
callq 0x166c60
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x5627b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x15f250
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x11305a(%rip), %rsi    # 0x1692d0
callq 0x169280
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rdx
movq -0x48(%rbp), %rcx
callq 0x166070
movq -0x30(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x5631f
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x15f340
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x58(%rax), %edx
leaq 0x14fdcc(%rip), %rsi    # 0x1a6095
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
movl 0x58(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x40(%rcx), %eax
je 0x5631d
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0x58(%rbp), %rdi
movq %rax, %rdx
movq -0x30(%rbp), %rax
movl 0x40(%rax), %ecx
movq -0x30(%rbp), %rax
movl 0x58(%rax), %r8d
leaq 0x14fd99(%rip), %rsi    # 0x1a60af
movb $0x0, %al
callq 0x15bc10
jmp 0x5631f
jmp 0x56321
movq -0x48(%rbp), %rdi
callq 0x1676a0
cmpl $0x0, -0x24(%rbp)
je 0x56356
cmpq $0x0, -0x30(%rbp)
je 0x56356
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
addq 0x20(%rax), %rcx
movq -0x30(%rbp), %rax
addq 0x30(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x5638c
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rsi
callq 0x166830
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl -0x50(%rbp), %esi
callq 0x15b5a0
movl -0x24(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)