// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x140(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x15ce90
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rax
subq 0x18(%rax), %rsi
callq 0x1685f0
movq -0x8(%rbp), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x168020
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x164270
movq -0x20(%rbp), %rax
cmpb $0x0, 0x1(%rax)
je 0x164155
movq -0x8(%rbp), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x168020
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rsi
shlq $0x9, %rsi
xorl %edx, %edx
callq 0x168020
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movabsq $0x1ffffffff, %rsi      # imm = 0x1FFFFFFFF
xorl %eax, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmovgl %ecx, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %r8
callq 0x1643a0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rdi
callq 0x18fe20
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x1641f6
cmpq $0x0, -0x48(%rbp)
je 0x1641f6
cmpq $0x0, -0x50(%rbp)
je 0x1641f6
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %r8
xorl %eax, %eax
movl %eax, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x166410
movq -0x38(%rbp), %rax
addq $0x200, %rax            # imm = 0x200
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdx
shlq $0x9, %rdx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %r8
xorl %eax, %eax
movl %eax, %esi
callq 0x166410
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
shlq $0x9, %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %r8
xorl %eax, %eax
movl %eax, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x166410
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x18fdf0
movq -0x40(%rbp), %rdi
callq 0x1676a0
movq -0x48(%rbp), %rdi
callq 0x1676a0
movq -0x50(%rbp), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x163ac0
movq -0x18(%rbp), %rax
movq $0x0, 0x20(%rax)
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)