// File: /workspace/github_c_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movq %rsi, %rbp
movq %rdi, %rbx
movq 0x140(%rdi), %r15
movq 0x20(%r15), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rsi), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0xea80b
movq 0x8(%r15), %rdi
subq 0x18(%rbp), %rax
movq %rax, %rsi
callq 0xf1346
movl $0x200, %esi            # imm = 0x200
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf0faf
movq %rax, %r13
movq 0x20(%r15), %rbx
movb $0x35, %r14b
movl $0x1ed, %r12d           # imm = 0x1ED
cmpb $0x0, (%rbx)
jne 0xee6f9
movq 0xd0(%rbp), %rax
testq %rax, %rax
je 0xee6f0
movb $0x30, %r14b
testb $0x2, 0x14(%rax)
jne 0xee6f9
movb $0x30, %r14b
movl $0x1a4, %r12d           # imm = 0x1A4
movq %r15, %rdi
movq %r13, %rsi
callq 0xeeb27
movq 0x38(%rbx), %rdi
movq $0x0, 0x10(%rsp)
movl $0x64, %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xeec08
leaq 0x50(%rsp), %rbx
movl $0x8, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq 0xeecee
movl $0x64, %esi
movl $0x8, %ecx
movq %r13, %rdi
movq %rbx, %rdx
callq 0xf11f9
movq 0x18(%rbp), %rdi
leaq 0x50(%rsp), %rbx
movl $0xc, %edx
movq %rbx, %rsi
callq 0xeecee
movl $0x7c, %esi
movl $0xc, %ecx
movq %r13, %rdi
movq %rbx, %rdx
callq 0xf11f9
movzbl %r14b, %edx
movl $0x9c, %esi
movq %r13, %rdi
callq 0xf148e
movl $0x200, %esi            # imm = 0x200
movq %r13, %rdi
callq 0xf152a
movq 0x18(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xeec44
movq 0x8(%rsp), %rbx
cmpb $0x0, 0x1(%rbx)
movq %rbp, %r14
movl $0x0, %ebp
je 0xeea45
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdi
xorl %edx, %edx
callq 0xf0faf
movq %rax, %rbp
movq 0x20(%rbx), %rsi
shlq $0x9, %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0xf0faf
movabsq $0x1ffffffff, %rcx      # imm = 0x1FFFFFFFF
cmpq %rcx, 0x18(%r14)
setg 0x2(%rbx)
movq %rax, 0x20(%rsp)
movq 0x20(%r15), %rax
movq %rax, 0x28(%rsp)
movq $0x0, (%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0xeeb27
movq 0x68(%r14), %rcx
leaq 0x5a35c(%rip), %rdx     # 0x148b7b
leaq 0x50(%rsp), %rbx
movl $0x65, %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8d67
movl $0x64, %esi
movq %rbx, %rdi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0xeec08
leaq 0xc0(%rsp), %rbx
movl $0x1a4, %edi            # imm = 0x1A4
movl $0x8, %edx
movq %rbx, %rsi
callq 0xeecee
movl $0x64, %esi
movl $0x8, %ecx
movq %rbp, %rdi
movq %rbx, %rdx
callq 0xf11f9
movl $0x9c, %esi
movq %rbp, 0x10(%rsp)
movq %rbp, %rdi
movq 0x20(%rsp), %rbp
movl $0x78, %edx
callq 0xf148e
movq 0x28(%rsp), %rax
movq %rax, %rbx
cmpb $0x0, 0x2(%rax)
je 0xee8d8
movq 0x18(%r14), %rcx
leaq 0x3ad08(%rip), %rdx     # 0x1295b1
leaq 0xc0(%rsp), %r14
movl $0x50, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8d67
leaq 0x289a8(%rip), %rdx     # 0x11726f
movq %rsp, %r8
movq %r12, %rdi
movq %rbp, %rsi
movq %r14, %rcx
callq 0xeedb1
cmpb $0x0, 0x3(%rbx)
je 0xee8f7
movq 0x38(%rbx), %rcx
leaq 0x4457e(%rip), %rdx     # 0x132e67
movq %rsp, %r8
movq %r12, %rdi
movq %rbp, %rsi
callq 0xeedb1
cmpb $0x0, 0x58(%rbx)
je 0xee916
leaq 0x59(%rbx), %rcx
leaq 0x4cfa4(%rip), %rdx     # 0x13b8ac
movq %rsp, %r8
movq %r12, %rdi
movq %rbp, %rsi
callq 0xeedb1
cmpb $0x0, 0xd8(%rbx)
je 0xee93b
leaq 0xd9(%rbx), %rcx
leaq 0x4d128(%rip), %rdx     # 0x13ba55
movq %rsp, %r8
movq %r12, %rdi
movq %rbp, %rsi
callq 0xeedb1
movq %r15, 0x38(%rsp)
cmpb $0x0, 0x118(%rbx)
je 0xee965
leaq 0x119(%rbx), %rcx
leaq 0x4d104(%rip), %rdx     # 0x13ba5b
movq %rsp, %r8
movq %r12, %rdi
movq %rbp, %rsi
callq 0xeedb1
movq %r13, 0x30(%rsp)
cmpb $0x0, 0x98(%rbx)
je 0xee98f
leaq 0x99(%rbx), %rcx
leaq 0x4d0f3(%rip), %rdx     # 0x13ba74
movq %rsp, %r8
movq %r12, %rdi
movq %rbp, %rsi
callq 0xeedb1
movq %r12, %r13
movq (%rsp), %r12
movq 0x20(%rbx), %rsi
shlq $0x9, %rsi
leaq -0x1ff(%rsi), %rax
cmpq %rax, %r12
jge 0xee9e4
leaq 0x5621f(%rip), %r15     # 0x144bd0
movq %rsp, %r14
movq %r13, %rdi
movq %rbp, %rsi
leaq 0x55971(%rip), %rdx     # 0x144332
movq %r15, %rcx
movq %r14, %r8
callq 0xeedb1
movq (%rsp), %r12
movq 0x20(%rbx), %rsi
shlq $0x9, %rsi
leaq -0x1ff(%rsi), %rax
cmpq %rax, %r12
jl 0xee9b4
movq %rbp, %rdi
callq 0xf152a
leaq 0x44(%rsp), %rbx
movl $0xc, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq 0xeecee
movl $0x7c, %esi
movl $0xc, %ecx
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
callq 0xf11f9
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
callq 0xf152a
movq %r13, %rdi
movq 0x38(%rsp), %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0xeec44
movq 0x30(%rsp), %r13
movq 0x8(%rsp), %rbx
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
callq 0x109ad1
movq 0x10(%rbx), %r12
testq %rbp, %rbp
movq %rax, 0x8(%rsp)
je 0xeeab8
cmpb $0x0, 0x1(%rbx)
movq 0x10(%rsp), %r14
je 0xeeabd
testq %r14, %r14
je 0xeeabd
movq 0x8(%r15), %rcx
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %r8
callq 0xefe16
leaq 0x200(%r12), %r8
movq 0x20(%rbx), %rdx
shlq $0x9, %rdx
movq 0x8(%r15), %rcx
movq %rbp, %rdi
xorl %esi, %esi
callq 0xefe16
movq 0x20(%rbx), %rax
shlq $0x9, %rax
addq %rax, %r12
addq $0x200, %r12            # imm = 0x200
jmp 0xeeabd
movq 0x10(%rsp), %r14
movq 0x8(%r15), %rcx
movl $0x200, %edx            # imm = 0x200
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %r8
callq 0xefe16
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
movq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0x109acc
movq %r13, %rdi
callq 0xf0b13
movq %r14, %rdi
callq 0xf0b13
movq %rbp, %rdi
callq 0xf0b13
movq 0x20(%r15), %rsi
movq 0x18(%rsp), %rdi
callq 0xee318
movq $0x0, 0x20(%r15)
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq