// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-tar.c
// Function: de_tar_start_member_file
void de_tar_start_member_file(deark *c, dbuf *f)
{
	struct tar_ctx *tctx = NULL;
	struct tar_md *md = NULL;
	int tsidx;

	if(!c->tar_data) {
		de_tar_create_file(c);
	}
	tctx = (struct tar_ctx *)c->tar_data;
	if(!tctx) return;
	destroy_md(c, tctx->md);
	tctx->md = de_malloc(c, sizeof(struct tar_md));
	md = tctx->md;

	f->parent_dbuf = tctx->outf;

	md->headers_pos = tctx->outf->len;

	if(c->preserve_file_times_archives && f->fi_copy) {
		for(tsidx=0; tsidx<DE_TIMESTAMPIDX_COUNT; tsidx++) {
			//if(tsidx != DE_TIMESTAMPIDX_MODIFY) continue;

			if(f->fi_copy->timestamp[tsidx].is_valid) {
				md->tsdata[tsidx].timestamp = f->fi_copy->timestamp[tsidx];
			}
			else if(tsidx == DE_TIMESTAMPIDX_MODIFY) {
				// Special handling if we don't have a mod time.
				if(c->reproducible_output) {
					de_get_reproducible_timestamp(c, &md->tsdata[tsidx].timestamp);
				}
				else {
					de_cached_current_time_to_timestamp(c, &md->tsdata[tsidx].timestamp);
					// Although c->current_time is probably high precision, we treat it as
					// low precision, so as not to write an "mtime" extended header.
					// TODO: If we write "mtime" for some other reason, it can be high prec.
					md->tsdata[tsidx].timestamp.precision = DE_TSPREC_1SEC;
				}
			}
			else {
				// Unavailable timestamp that isn't the mod time.
				continue;
			}

			md->tsdata[tsidx].timestamp_unix = de_timestamp_to_unix_time(&md->tsdata[tsidx].timestamp);
		}
	}

	if(f->fi_copy && f->fi_copy->is_directory) {
		md->is_dir = 1;
	}

	md->namelen = de_strlen(f->name);
	if(md->is_dir) {
		// Append a '/' to directory names
		md->filename = de_malloc(c, (i64)md->namelen+2);
		de_snprintf(md->filename, md->namelen+2, "%s/", f->name);
		md->namelen = de_strlen(md->filename);
	}
	else {
		md->filename = de_strdup(c, f->name);
	}

	if(md->namelen>100) {
		md->need_exthdr_path = 1;
	}
	else if(!de_is_ascii((const u8*)md->filename, md->namelen)) {
		md->need_exthdr_path = 1;
	}

	md->extdata_nbytes_needed += 23; // For "size"; this is enough for 10TB

	if(md->need_exthdr_path) {
		// Likely an overestimate: up to 6 bytes for the item size,
		// 4 for the "path" string, 3 for field separators.
		md->extdata_nbytes_needed += (i64)md->namelen + 13;
	}

	prepare_timestamp_exthdr(c, md, DE_TIMESTAMPIDX_MODIFY);
	prepare_timestamp_exthdr(c, md, DE_TIMESTAMPIDX_ACCESS);
	prepare_timestamp_exthdr(c, md, DE_TIMESTAMPIDX_ATTRCHANGE);
	prepare_timestamp_exthdr(c, md, DE_TIMESTAMPIDX_CREATE);

	if(md->extdata_nbytes_needed>0) {
		md->has_exthdr = 1;
	}

	if(md->has_exthdr) {
		md->exthdr_num_data_blocks = (md->extdata_nbytes_needed+511)/512;
		md->headers_size = (1 + md->exthdr_num_data_blocks + 1) * 512;
	}
	else {
		md->exthdr_num_data_blocks = 0;
		md->headers_size = 512;
	}

	// Reserve space for the tar headers. We won't know the member file size
	// until it has been completely written, so we can't write the headers
	// yet. Instead we'll write them to headers_tmpdbuf, and seek back later
	// and patch them into the main tar file.
	dbuf_write_zeroes(tctx->outf, md->headers_size);

	f->offset_into_parent_dbuf = tctx->outf->len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x140(%rax)
jne 0x163b37
movq -0x8(%rbp), %rdi
callq 0x163900
movq -0x8(%rbp), %rax
movq 0x140(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x163b52
jmp 0x163f04
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x163ac0
movq -0x8(%rbp), %rdi
movl $0x180, %esi            # imm = 0x180
callq 0x15b780
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movzbl 0xdd(%rax), %eax
cmpl $0x0, %eax
je 0x163ceb
movq -0x10(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x163ceb
movl $0x0, -0x24(%rbp)
cmpl $0x5, -0x24(%rbp)
jge 0x163ce9
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rax
addq $0x18, %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpb $0x0, (%rax)
je 0x163c3f
movq -0x20(%rbp), %rax
addq $0x40, %rax
movslq -0x24(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movq 0xd0(%rcx), %rcx
addq $0x18, %rcx
movslq -0x24(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x163ca9
cmpl $0x0, -0x24(%rbp)
jne 0x163ca5
movq -0x8(%rbp), %rax
cmpb $0x0, 0xdf(%rax)
je 0x163c70
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x40, %rsi
movslq -0x24(%rbp), %rax
shlq $0x6, %rax
addq %rax, %rsi
callq 0x15f5e0
jmp 0x163ca3
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x40, %rsi
movslq -0x24(%rbp), %rax
shlq $0x6, %rax
addq %rax, %rsi
callq 0x15e330
movq -0x20(%rbp), %rax
addq $0x40, %rax
movslq -0x24(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movb $0x1e, 0x2(%rax)
jmp 0x163ca7
jmp 0x163cdb
jmp 0x163ca9
movq -0x20(%rbp), %rdi
addq $0x40, %rdi
movslq -0x24(%rbp), %rax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x15dd00
movq %rax, %rcx
movq -0x20(%rbp), %rax
addq $0x40, %rax
movslq -0x24(%rbp), %rdx
shlq $0x6, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x163bd9
jmp 0x163ceb
movq -0x10(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x163d14
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rax
movzbl 0x9(%rax), %eax
cmpl $0x0, %eax
je 0x163d14
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x190e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
cmpb $0x0, (%rax)
je 0x163d99
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x2, %rsi
callq 0x15b780
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x2, %rsi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
leaq 0x70dac(%rip), %rdx     # 0x1d4b24
movb $0x0, %al
callq 0x15a980
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x190e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x163db5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rsi
callq 0x15c630
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x20(%rbp), %rax
cmpq $0x64, 0x8(%rax)
jbe 0x163dca
movq -0x20(%rbp), %rax
movb $0x1, 0x3(%rax)
jmp 0x163dee
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x1610f0
cmpl $0x0, %eax
jne 0x163dec
movq -0x20(%rbp), %rax
movb $0x1, 0x3(%rax)
jmp 0x163dee
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x17, %rcx
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rax
cmpb $0x0, 0x3(%rax)
je 0x163e20
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0xd, %rcx
movq -0x20(%rbp), %rax
addq 0x28(%rax), %rcx
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x163f10
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x2, %edx
callq 0x163f10
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x3, %edx
callq 0x163f10
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x1, %edx
callq 0x163f10
movq -0x20(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jle 0x163e78
movq -0x20(%rbp), %rax
movb $0x1, 0x1(%rax)
movq -0x20(%rbp), %rax
cmpb $0x0, 0x1(%rax)
je 0x163ec3
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
addq $0x1ff, %rax            # imm = 0x1FF
movl $0x200, %ecx            # imm = 0x200
cqto
idivq %rcx
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
addq $0x1, %rcx
shlq $0x9, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x163edb
movq -0x20(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x20(%rbp), %rax
movq $0x200, 0x18(%rax)      # imm = 0x200
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x1685f0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)