// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-tar.c
// Function: make_exthdrs
static void make_exthdrs(deark *c, struct tar_ctx *tctx,
	dbuf *f, dbuf *exthdr, dbuf *extdata)
{
	struct tar_md *md = tctx->md;
	i64 extdata_len = 0;
	char namebuf[101];
	char buf[80];

	set_common_header_fields(c, tctx, exthdr);

	// "name"
	// This pseudo-filename will be ignored by any decent untar program.
	// The template used here is similar to what bsdtar does.
	// (Using f->name here instead of md->filename, because we don't
	// want directory names to have a '/' appended.)
	de_snprintf(namebuf, sizeof(namebuf), "PaxHeader/%s", f->name);
	format_and_write_ascii_field(c, tctx, namebuf, 100, exthdr, 0);

	// "mode"
	format_and_write_ascii_octal_field(c, tctx, 0644, 8, exthdr, 100);

	// typeflag
	dbuf_writebyte_at(exthdr, 156, 'x');

	// Extended data

	if(md->need_exthdr_size) {
		de_snprintf(buf, sizeof(buf), "%"I64_FMT, f->len);
		add_exthdr_item(c, tctx, extdata, "size", buf, &extdata_len);
	}

	if(md->need_exthdr_path) {
		add_exthdr_item(c, tctx, extdata, "path", md->filename, &extdata_len);
	}

	if(md->tsdata[DE_TIMESTAMPIDX_MODIFY].need_exthdr) {
		add_exthdr_item(c, tctx, extdata, "mtime", md->tsdata[DE_TIMESTAMPIDX_MODIFY].exthdr_sz, &extdata_len);
	}
	if(md->tsdata[DE_TIMESTAMPIDX_ACCESS].need_exthdr) {
		add_exthdr_item(c, tctx, extdata, "atime", md->tsdata[DE_TIMESTAMPIDX_ACCESS].exthdr_sz, &extdata_len);
	}
	if(md->tsdata[DE_TIMESTAMPIDX_ATTRCHANGE].need_exthdr) {
		add_exthdr_item(c, tctx, extdata, "ctime", md->tsdata[DE_TIMESTAMPIDX_ATTRCHANGE].exthdr_sz, &extdata_len);
	}
	if(md->tsdata[DE_TIMESTAMPIDX_CREATE].need_exthdr) {
		add_exthdr_item(c, tctx, extdata, "LIBARCHIVE.creationtime", md->tsdata[DE_TIMESTAMPIDX_CREATE].exthdr_sz, &extdata_len);
	}

	// We have to use exactly the number of exthdr data blocks that we
	// precalculated, no more and no fewer. But it is possible that we
	// overestimated. If so, we have to pad the data somehow, and using
	// empty "comment" items is one way to do that.
	while(extdata_len < (512*md->exthdr_num_data_blocks - 511)) {
		add_exthdr_item(c, tctx, extdata, "comment", "", &extdata_len);
	}
	dbuf_truncate(extdata, 512*md->exthdr_num_data_blocks);

	// "size"
	format_and_write_ascii_octal_field(c, tctx, extdata_len, 12, exthdr, 124);

	dbuf_truncate(exthdr, 512);
	set_checksum_field(c, tctx, exthdr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x164660
leaq -0xa0(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rcx
movl $0x65, %esi
leaq 0x70874(%rip), %rdx     # 0x1d4c73
movb $0x0, %al
callq 0x15a980
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
movq -0x20(%rbp), %r8
movl $0x64, %ecx
xorl %eax, %eax
movl %eax, %r9d
callq 0x164750
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %r8
movl $0x1a4, %edx            # imm = 0x1A4
movl $0x8, %ecx
movl $0x64, %r9d
callq 0x1647e0
movq -0x20(%rbp), %rdi
movl $0x9c, %esi
movl $0x78, %edx
callq 0x168790
movq -0x30(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x1644ab
leaq -0xf0(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
movl $0x50, %esi
leaq 0x50c8e(%rip), %rdx     # 0x1b510f
movb $0x0, %al
callq 0x15a980
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0xf0(%rbp), %r8
leaq 0x3ec13(%rip), %rcx     # 0x1a30b5
leaq -0x38(%rbp), %r9
callq 0x164ae0
movq -0x30(%rbp), %rax
cmpb $0x0, 0x3(%rax)
je 0x1644d9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x38(%rax), %r8
leaq 0x5a7d6(%rip), %rcx     # 0x1beca6
leaq -0x38(%rbp), %r9
callq 0x164ae0
movq -0x30(%rbp), %rax
cmpb $0x0, 0x58(%rax)
je 0x16450b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %r8
addq $0x40, %r8
addq $0x19, %r8
leaq 0x62f59(%rip), %rcx     # 0x1c745b
leaq -0x38(%rbp), %r9
callq 0x164ae0
movq -0x30(%rbp), %rax
cmpb $0x0, 0xd8(%rax)
je 0x164547
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %r8
addq $0x40, %r8
addq $0x80, %r8
addq $0x19, %r8
leaq 0x630c6(%rip), %rcx     # 0x1c7604
leaq -0x38(%rbp), %r9
callq 0x164ae0
movq -0x30(%rbp), %rax
cmpb $0x0, 0x118(%rax)
je 0x164583
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %r8
addq $0x40, %r8
addq $0xc0, %r8
addq $0x19, %r8
leaq 0x63090(%rip), %rcx     # 0x1c760a
leaq -0x38(%rbp), %r9
callq 0x164ae0
movq -0x30(%rbp), %rax
cmpb $0x0, 0x98(%rax)
je 0x1645bc
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %r8
addq $0x40, %r8
addq $0x40, %r8
addq $0x19, %r8
leaq 0x63070(%rip), %rcx     # 0x1c7623
leaq -0x38(%rbp), %r9
callq 0x164ae0
jmp 0x1645be
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x20(%rcx), %rcx
shlq $0x9, %rcx
subq $0x1ff, %rcx            # imm = 0x1FF
cmpq %rcx, %rax
jge 0x1645ff
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq 0x6bd58(%rip), %rcx     # 0x1d0345
leaq 0x6c5dc(%rip), %r8      # 0x1d0bd0
leaq -0x38(%rbp), %r9
callq 0x164ae0
jmp 0x1645be
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rsi
shlq $0x9, %rsi
callq 0x168900
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %r8
movl $0xc, %ecx
movl $0x7c, %r9d
callq 0x1647e0
movq -0x20(%rbp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x168900
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x164840
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)