// File: /workspace/github_c_makefile_star2_O3/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 $0x108, %rsp            # imm = 0x108
movq %rsi, %rbp
movq %rdi, %r14
movq 0x140(%rdi), %rbx
movq %rbx, 0x20(%rsp)
movq 0x20(%rbx), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsi), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0xe9cb4
movq 0x8(%rbx), %rdi
subq 0x18(%rbp), %rax
movq %rax, %rsi
callq 0xf0d35
movl $0x200, %esi            # imm = 0x200
movq %r14, 0x28(%rsp)
movq %r14, %rdi
xorl %edx, %edx
callq 0xf09c5
movq %rax, %r14
movq 0x20(%rbx), %r13
movb $0x35, %r15b
movl $0x1ed, %r12d           # imm = 0x1ED
cmpb $0x0, (%r13)
jne 0xee0fc
movq 0xd0(%rbp), %rax
testq %rax, %rax
je 0xee0f3
movb $0x30, %r15b
testb $0x2, 0x14(%rax)
jne 0xee0fc
movb $0x30, %r15b
movl $0x1a4, %r12d           # imm = 0x1A4
movq %r13, %rdi
movq %r14, %rsi
callq 0xee54a
movq 0x38(%r13), %rbx
movq %rbx, %rdi
callq 0x180e0
cmpq $0x64, %rax
movl $0x64, %ecx
cmovaeq %rcx, %rax
movq $0x0, 0x8(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %rax, %rcx
callq 0xf0c11
leaq 0x40(%rsp), %rbx
movl $0x8, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq 0xee6d7
movl $0x64, %esi
movl $0x8, %ecx
movq %r14, %rdi
movq %rbx, %rdx
callq 0xf0c11
movq 0x18(%rbp), %rdi
leaq 0x40(%rsp), %rbx
movl $0xc, %edx
movq %rbx, %rsi
callq 0xee6d7
movl $0x7c, %esi
movl $0xc, %ecx
movq %r14, %rdi
movq %rbx, %rdx
callq 0xf0c11
movzbl %r15b, %edx
movl $0x9c, %esi
movq %r14, %rdi
callq 0xf0e8b
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
callq 0xf0f27
movq 0x28(%rsp), %r15
movq %r15, %rdi
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
movq %r14, 0x18(%rsp)
movq %r14, %rdx
callq 0xee62a
movq 0x10(%rsp), %r13
cmpb $0x0, 0x1(%r13)
movl $0x0, %r12d
je 0xee45b
movl $0x200, %esi            # imm = 0x200
movq %r15, %rdi
xorl %edx, %edx
callq 0xf09c5
movq %rax, %r14
movq 0x20(%r13), %rsi
shlq $0x9, %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0xf09c5
movabsq $0x1ffffffff, %rcx      # imm = 0x1FFFFFFFF
cmpq %rcx, 0x18(%rbp)
setg 0x2(%r13)
movq %rax, %r12
movq 0x20(%rbx), %r13
movq $0x0, (%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0xee54a
movq 0x68(%rbp), %rcx
leaq 0x5aed8(%rip), %rdx     # 0x149113
leaq 0x40(%rsp), %rbx
movl $0x65, %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8193
movq %rbx, %rdi
callq 0x180e0
cmpq $0x64, %rax
movl $0x64, %ecx
cmovaeq %rcx, %rax
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %rax, %rcx
callq 0xf0c11
leaq 0xb0(%rsp), %rbx
movl $0x1a4, %edi            # imm = 0x1A4
movl $0x8, %edx
movq %rbx, %rsi
callq 0xee6d7
movl $0x64, %esi
movl $0x8, %ecx
movq %r14, %rdi
movq %rbx, %rdx
callq 0xf0c11
movl $0x9c, %esi
movq %r14, 0x8(%rsp)
movq %r14, %rdi
movl $0x78, %edx
callq 0xf0e8b
cmpb $0x0, 0x2(%r13)
je 0xee2fb
movq 0x18(%rbp), %rcx
leaq 0x3b515(%rip), %rdx     # 0x1297e1
leaq 0xb0(%rsp), %rbx
movl $0x50, %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8193
leaq 0x29025(%rip), %rdx     # 0x11730f
movq %rsp, %r8
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rcx
callq 0xee79a
cmpb $0x0, 0x3(%r13)
je 0xee31b
movq 0x38(%r13), %rcx
leaq 0x44f52(%rip), %rdx     # 0x13325f
movq %rsp, %r8
movq %r15, %rdi
movq %r12, %rsi
callq 0xee79a
cmpb $0x0, 0x58(%r13)
je 0xee33b
leaq 0x59(%r13), %rcx
leaq 0x4d8f9(%rip), %rdx     # 0x13bc26
movq %rsp, %r8
movq %r15, %rdi
movq %r12, %rsi
callq 0xee79a
cmpb $0x0, 0xd8(%r13)
je 0xee361
leaq 0xd9(%r13), %rcx
leaq 0x4da7c(%rip), %rdx     # 0x13bdcf
movq %rsp, %r8
movq %r15, %rdi
movq %r12, %rsi
callq 0xee79a
cmpb $0x0, 0x118(%r13)
je 0xee387
leaq 0x119(%r13), %rcx
leaq 0x4da5c(%rip), %rdx     # 0x13bdd5
movq %rsp, %r8
movq %r15, %rdi
movq %r12, %rsi
callq 0xee79a
cmpb $0x0, 0x98(%r13)
je 0xee3ad
leaq 0x99(%r13), %rcx
leaq 0x4da4f(%rip), %rdx     # 0x13bdee
movq %rsp, %r8
movq %r15, %rdi
movq %r12, %rsi
callq 0xee79a
movq (%rsp), %rbp
movq 0x20(%r13), %rsi
shlq $0x9, %rsi
leaq -0x1ff(%rsi), %rax
cmpq %rax, %rbp
jge 0xee3ff
leaq 0x56ce4(%rip), %rbx     # 0x1450b0
movq %rsp, %r14
movq %r15, %rdi
movq %r12, %rsi
leaq 0x56436(%rip), %rdx     # 0x144812
movq %rbx, %rcx
movq %r14, %r8
callq 0xee79a
movq (%rsp), %rbp
movq 0x20(%r13), %rsi
shlq $0x9, %rsi
leaq -0x1ff(%rsi), %rax
cmpq %rax, %rbp
jl 0xee3cf
movq %r12, %rdi
callq 0xf0f27
leaq 0x34(%rsp), %rbx
movl $0xc, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xee6d7
movl $0x7c, %esi
movl $0xc, %ecx
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
callq 0xf0c11
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
callq 0xf0f27
movq %r15, %rdi
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
movq %r14, %rdx
callq 0xee62a
movq 0x10(%rsp), %r13
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rdi
callq 0x1095b9
movq 0x10(%r13), %rbp
movq %r12, %r15
testq %r12, %r12
movq %rax, 0x10(%rsp)
je 0xee4d6
cmpb $0x0, 0x1(%r13)
movq 0x18(%rsp), %r14
je 0xee4db
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0xee4e0
movq 0x8(%rbx), %rcx
movl $0x200, %edx            # imm = 0x200
movq %r12, %rdi
xorl %esi, %esi
movq %rbp, %r8
callq 0xef82b
leaq 0x200(%rbp), %r8
movq 0x20(%r13), %rdx
shlq $0x9, %rdx
movq 0x8(%rbx), %rcx
movq %r15, %rdi
xorl %esi, %esi
callq 0xef82b
movq 0x20(%r13), %rax
shlq $0x9, %rax
addq %rax, %rbp
addq $0x200, %rbp            # imm = 0x200
jmp 0xee4e0
movq 0x18(%rsp), %r14
movq 0x8(%rsp), %r12
movq 0x8(%rbx), %rcx
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
xorl %esi, %esi
movq %rbp, %r8
callq 0xef82b
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rsp), %rsi
xorl %edx, %edx
callq 0x1095b4
movq %r14, %rdi
callq 0xf052b
movq %r12, %rdi
callq 0xf052b
movq %r15, %rdi
callq 0xf052b
movq 0x20(%rbx), %rsi
movq 0x28(%rsp), %rdi
callq 0xedccc
movq $0x0, 0x20(%rbx)
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq