// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/src/deark-tar.c
// Function: de_tar_end_member_file
void de_tar_end_member_file(deark *c, dbuf *f)
{
	struct tar_ctx *tctx = (struct tar_ctx *)c->tar_data;
	struct tar_md *md = tctx->md;
	i64 padded_len;
	i64 saved_pos;
	i64 writepos;
	dbuf *mainhdr = NULL;
	dbuf *exthdr = NULL;
	dbuf *extdata = NULL;

	// Write any needed padding to the main tar file.
	padded_len = de_pad_to_n(f->len, 512);
	dbuf_write_zeroes(tctx->outf, padded_len - f->len);

	// Construct the headers, using temporary dbufs

	// Main header
	mainhdr = dbuf_create_membuf(c, 512, 0);
	make_main_header(c, tctx, f, mainhdr);

	if(md->has_exthdr) {
		// Extended header & data
		exthdr = dbuf_create_membuf(c, 512, 0);
		extdata = dbuf_create_membuf(c, 512*md->exthdr_num_data_blocks, 0);
		md->need_exthdr_size = (f->len > 0x1FFFFFFFFLL)?1:0;
		make_exthdrs(c, tctx, f, exthdr, extdata);
	}

	// Seek back and write the headers to the main tar file.
	// FIXME: This is a hack, sort of. A dbuf doesn't expect us to access its
	// fp pointer, or to mix copy_at with other 'write' functions.
	saved_pos = de_ftell(tctx->outf->fp);
	writepos = md->headers_pos;
	if(md->has_exthdr && exthdr && extdata) {
		dbuf_copy_at(exthdr, 0, 512, tctx->outf, writepos);
		writepos += 512;
		dbuf_copy_at(extdata, 0, 512*md->exthdr_num_data_blocks, tctx->outf, writepos);
		writepos += 512*md->exthdr_num_data_blocks;
	}
	dbuf_copy_at(mainhdr, 0, 512, tctx->outf, writepos);
	de_fseek(tctx->outf->fp, saved_pos, SEEK_SET);

	dbuf_close(mainhdr);
	dbuf_close(exthdr);
	dbuf_close(extdata);

	destroy_md(c, tctx->md);
	tctx->md = NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %rbp
movq %rdi, %rbx
movq 0x140(%rdi), %r15
movq 0x20(%r15), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsi), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0xdfbb6
movq 0x8(%r15), %rdi
subq 0x18(%rbp), %rax
movq %rax, %rsi
callq 0xe5d20
movl $0x200, %esi            # imm = 0x200
movq %rbx, 0x38(%rsp)
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe59cd
movq %rax, 0x20(%rsp)
movq 0x20(%r15), %rbx
movb $0x35, %r14b
movl $0x1ed, %r13d           # imm = 0x1ED
cmpb $0x0, (%rbx)
jne 0xe356f
movq 0xd0(%rbp), %rax
testq %rax, %rax
je 0xe3566
movb $0x30, %r14b
testb $0x2, 0x14(%rax)
jne 0xe356f
movb $0x30, %r14b
movl $0x1a4, %r13d           # imm = 0x1A4
movq %r15, %rdi
movq 0x20(%rsp), %r12
movq %r12, %rsi
callq 0xe3921
movq 0x38(%rbx), %rdi
movq $0x0, 0x18(%rsp)
pushq $0x64
popq %rbx
movq %rbx, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0xe39af
pushq $0x8
popq %rsi
movq %r13, %rdi
movq %r12, %rdx
movq %rbx, %rcx
callq 0xe39eb
movq 0x18(%rbp), %rdi
pushq $0xc
popq %rsi
pushq $0x7c
popq %rcx
movq %r12, %rdx
callq 0xe39eb
movzbl %r14b, %edx
movl $0x9c, %esi
movq %r12, %rdi
callq 0xe5e13
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdi
callq 0xe5eb2
movq 0x38(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xe3a2c
movq 0x10(%rsp), %rbx
cmpb $0x0, 0x1(%rbx)
movl $0x0, %r12d
je 0xe3840
movl $0x200, %esi            # imm = 0x200
movq %r13, %rdi
xorl %edx, %edx
callq 0xe59cd
movq %rax, %r12
movq 0x20(%rbx), %rsi
shlq $0x9, %rsi
movq %r13, %rdi
xorl %edx, %edx
callq 0xe59cd
movabsq $0x1ffffffff, %rcx      # imm = 0x1FFFFFFFF
cmpq %rcx, 0x18(%rbp)
movq %rax, 0x28(%rsp)
setg 0x2(%rbx)
movq 0x20(%r15), %r14
andq $0x0, 0x8(%rsp)
movq %r15, 0x30(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0xe3921
movq 0x68(%rbp), %rcx
leaq 0x585de(%rip), %rdx     # 0x13bc43
leaq 0x90(%rsp), %rbx
pushq $0x65
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde40c
pushq $0x64
popq %r15
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0xe39af
pushq $0x8
popq %rsi
movl $0x1a4, %edi            # imm = 0x1A4
movq %r12, %rdx
movq %r15, %rcx
callq 0xe39eb
pushq $0x78
popq %rdx
movl $0x9c, %esi
movq %r12, 0x18(%rsp)
movq %r12, %rdi
movq 0x28(%rsp), %r15
callq 0xe5e13
cmpb $0x0, 0x2(%r14)
je 0xe36f9
movq 0x18(%rbp), %rcx
leaq 0x38ed4(%rip), %rdx     # 0x11c5a1
leaq 0x40(%rsp), %rbx
pushq $0x50
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde40c
leaq 0x26b99(%rip), %rdx     # 0x10a27f
leaq 0x8(%rsp), %r8
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rcx
callq 0xe3b91
cmpb $0x0, 0x3(%r14)
je 0xe371b
movq 0x38(%r14), %rcx
leaq 0x4287c(%rip), %rdx     # 0x125f87
leaq 0x8(%rsp), %r8
movq %r13, %rdi
movq %r15, %rsi
callq 0xe3b91
cmpb $0x0, 0x58(%r14)
je 0xe373d
leaq 0x59(%r14), %rcx
leaq 0x4b209(%rip), %rdx     # 0x12e936
leaq 0x8(%rsp), %r8
movq %r13, %rdi
movq %r15, %rsi
callq 0xe3b91
cmpb $0x0, 0xd8(%r14)
je 0xe3765
leaq 0xd9(%r14), %rcx
leaq 0x4b38a(%rip), %rdx     # 0x12eadf
leaq 0x8(%rsp), %r8
movq %r13, %rdi
movq %r15, %rsi
callq 0xe3b91
cmpb $0x0, 0x118(%r14)
je 0xe378d
leaq 0x119(%r14), %rcx
leaq 0x4b368(%rip), %rdx     # 0x12eae5
leaq 0x8(%rsp), %r8
movq %r13, %rdi
movq %r15, %rsi
callq 0xe3b91
cmpb $0x0, 0x98(%r14)
je 0xe37b5
leaq 0x99(%r14), %rcx
leaq 0x4b359(%rip), %rdx     # 0x12eafe
leaq 0x8(%rsp), %r8
movq %r13, %rdi
movq %r15, %rsi
callq 0xe3b91
movq %r13, %r12
leaq 0x544a1(%rip), %r13     # 0x137c60
leaq 0x8(%rsp), %rbp
movq 0x8(%rsp), %rbx
movq 0x20(%r14), %rsi
shlq $0x9, %rsi
leaq -0x1ff(%rsi), %rax
cmpq %rax, %rbx
jge 0xe37f7
movq %r12, %rdi
movq %r15, %rsi
leaq 0x53bd8(%rip), %rdx     # 0x1373c2
movq %r13, %rcx
movq %rbp, %r8
callq 0xe3b91
jmp 0xe37c4
movq %r15, %rdi
callq 0xe5eb2
pushq $0xc
popq %rsi
pushq $0x7c
popq %rcx
movq %rbx, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rdx
callq 0xe39eb
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0xe5eb2
movq %r12, %r13
movq %r15, %r12
movq %r13, %rdi
movq 0x30(%rsp), %r15
movq %r15, %rsi
movq %rbx, %rdx
callq 0xe3a2c
movq 0x10(%rsp), %rbx
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
callq 0xfcb2e
movq 0x10(%rbx), %rbp
testq %r12, %r12
movq %rax, 0x10(%rsp)
je 0xe38b2
cmpb $0x0, 0x1(%rbx)
movq 0x18(%rsp), %r14
je 0xe38b7
testq %r14, %r14
je 0xe38b7
movq 0x8(%r15), %rcx
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
xorl %esi, %esi
movq %rbp, %r8
callq 0xe490d
leaq 0x200(%rbp), %r8
movq 0x20(%rbx), %rdx
shlq $0x9, %rdx
movq 0x8(%r15), %rcx
movq %r12, %rdi
xorl %esi, %esi
callq 0xe490d
movq 0x20(%rbx), %rax
shlq $0x9, %rax
addq %rax, %rbp
addq $0x200, %rbp            # imm = 0x200
jmp 0xe38b7
movq 0x18(%rsp), %r14
movq 0x8(%r15), %rcx
movl $0x200, %edx            # imm = 0x200
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
movq %rbp, %r8
callq 0xe490d
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rsp), %rsi
xorl %edx, %edx
callq 0xfcb29
movq %rbx, %rdi
callq 0xe5591
movq %r14, %rdi
callq 0xe5591
movq %r12, %rdi
callq 0xe5591
movq 0x20(%r15), %rsi
movq %r13, %rdi
callq 0xe3189
andq $0x0, 0x20(%r15)
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq