// File: chlunde[P]qtar/qtar.cc
// Function: Traverser<CScan>::addfile(us_dirent&)
void addfile(struct us_dirent& file) {
		std::string fq = file.fq();
		char buff[1024 * 128];
		std::string rel = fq.substr(root.length() + 1);
		std::string uname, gname;
		const struct stat& st = file.stat();
		uname = lookup_uname(st.st_uid);
		gname = lookup_gname(st.st_gid);
#if 0
		std::cout << "addfile " << fq << "\t" << file.d_ino << "\t" << file.is_file() << "\t" << uname << "\t" << gname << "\t" << rel << std::endl;
#endif

		struct archive_entry *entry = archive_entry_new();

		archive_entry_copy_stat(entry, &file.stat());
		if (uname.size())
			archive_entry_set_uname(entry, uname.c_str());
		if (gname.size())
			archive_entry_set_gname(entry, gname.c_str());
		archive_entry_set_pathname(entry, rel.c_str());
		int r = archive_write_header(a, entry);
		if (r != ARCHIVE_OK)
			errx(EXIT_FAILURE, "archive_write_header failed: %s, %s", rel.c_str(), archive_error_string(a));

		//std::cout << file.d_name << std::endl;
		int fd = open(fq.c_str(), O_RDONLY);
		if (fd < 0)
			err(EXIT_FAILURE, "open(%s) failed", fq.c_str());

		ssize_t len = read(fd, buff, sizeof(buff));
		ssize_t written = 0;
		while (len > 0) {
			int bytes_written = archive_write_data(a, buff, len);
			written += bytes_written;
			//std::cout << "write " << len << " - " << bytes_written << std::endl;
			if (written < st.st_size)
				len = read(fd, buff, sizeof(buff));
			else
				break;
		}
		close(fd);
		archive_entry_free(entry);
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x201a0, %rsp          # imm = 0x201A0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20120(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0x20118(%rbp)
callq 0x61b0
movq -0x20120(%rbp), %rdi
addq $0x8, %rdi
callq 0x3410
movq -0x20118(%rbp), %rsi
movq %rax, %rdx
incq %rdx
leaq -0x20050(%rbp), %rdi
movq $-0x1, %rcx
callq 0x32d0
jmp 0x5d84
leaq -0x20080(%rbp), %rdi
callq 0x33a0
leaq -0x200a0(%rbp), %rdi
callq 0x33a0
movq -0x10(%rbp), %rdi
callq 0x5440
movq %rax, -0x20128(%rbp)
jmp 0x5dae
movq -0x20120(%rbp), %rsi
movq -0x20128(%rbp), %rax
movq %rax, -0x200a8(%rbp)
movq -0x200a8(%rbp), %rax
movl 0x1c(%rax), %edx
leaq -0x200c8(%rbp), %rdi
callq 0x8d60
jmp 0x5ddb
leaq -0x20080(%rbp), %rdi
leaq -0x200c8(%rbp), %rsi
movq %rsi, -0x20130(%rbp)
callq 0x3370
movq -0x20130(%rbp), %rdi
callq 0x31c0
movq -0x20120(%rbp), %rsi
movq -0x200a8(%rbp), %rax
movl 0x20(%rax), %edx
leaq -0x200e8(%rbp), %rdi
callq 0x8f00
jmp 0x5e20
leaq -0x200a0(%rbp), %rdi
leaq -0x200e8(%rbp), %rsi
movq %rsi, -0x20140(%rbp)
callq 0x3370
movq -0x20140(%rbp), %rdi
callq 0x31c0
callq 0x3060
movq %rax, -0x20138(%rbp)
jmp 0x5e54
movq -0x20138(%rbp), %rax
movq %rax, -0x200f0(%rbp)
movq -0x200f0(%rbp), %rax
movq %rax, -0x20150(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5440
movq %rax, -0x20148(%rbp)
jmp 0x5e82
movq -0x20148(%rbp), %rsi
movq -0x20150(%rbp), %rdi
callq 0x3110
jmp 0x5e97
leaq -0x20080(%rbp), %rdi
callq 0x31f0
cmpq $0x0, %rax
je 0x5f28
movq -0x200f0(%rbp), %rax
movq %rax, -0x20158(%rbp)
leaq -0x20080(%rbp), %rdi
callq 0x3130
movq -0x20158(%rbp), %rdi
movq %rax, %rsi
callq 0x31d0
jmp 0x5ed4
jmp 0x5f28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20058(%rbp)
movl %eax, -0x2005c(%rbp)
jmp 0x6195
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20058(%rbp)
movl %eax, -0x2005c(%rbp)
leaq -0x200a0(%rbp), %rdi
callq 0x31c0
leaq -0x20080(%rbp), %rdi
callq 0x31c0
leaq -0x20050(%rbp), %rdi
callq 0x31c0
jmp 0x6195
leaq -0x200a0(%rbp), %rdi
callq 0x31f0
cmpq $0x0, %rax
je 0x5f67
movq -0x200f0(%rbp), %rax
movq %rax, -0x20160(%rbp)
leaq -0x200a0(%rbp), %rdi
callq 0x3130
movq -0x20160(%rbp), %rdi
movq %rax, %rsi
callq 0x33c0
jmp 0x5f65
jmp 0x5f67
movq -0x200f0(%rbp), %rax
movq %rax, -0x20168(%rbp)
leaq -0x20050(%rbp), %rdi
callq 0x3130
movq -0x20168(%rbp), %rdi
movq %rax, %rsi
callq 0x3170
jmp 0x5f92
movq -0x20120(%rbp), %rax
movq (%rax), %rdi
movq -0x200f0(%rbp), %rsi
callq 0x33e0
movl %eax, -0x2016c(%rbp)
jmp 0x5fb0
movl -0x2016c(%rbp), %eax
movl %eax, -0x200f4(%rbp)
cmpl $0x0, -0x200f4(%rbp)
je 0x6016
leaq -0x20050(%rbp), %rdi
callq 0x3130
movq %rax, %rcx
movq -0x20120(%rbp), %rax
movq %rcx, -0x20180(%rbp)
movq (%rax), %rdi
callq 0x3250
movq %rax, -0x20178(%rbp)
jmp 0x5ff3
movq -0x20178(%rbp), %rcx
movq -0x20180(%rbp), %rdx
leaq 0x7058(%rip), %rsi      # 0xd060
xorl %eax, %eax
movl $0x1, %edi
callq 0x34d0
jmp 0x6016
leaq -0x30(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
xorl %esi, %esi
movb %sil, %al
callq 0x3220
movl %eax, -0x20184(%rbp)
jmp 0x6034
movl -0x20184(%rbp), %eax
movl %eax, -0x200f8(%rbp)
cmpl $0x0, -0x200f8(%rbp)
jge 0x606a
leaq -0x30(%rbp), %rdi
callq 0x3130
movq %rax, %rdx
leaq 0x7028(%rip), %rsi      # 0xd084
xorl %eax, %eax
movl $0x1, %edi
callq 0x3290
jmp 0x606a
movl -0x200f8(%rbp), %edi
leaq -0x20030(%rbp), %rsi
movl $0x20000, %edx          # imm = 0x20000
callq 0x33f0
movq %rax, -0x20190(%rbp)
jmp 0x608a
movq -0x20190(%rbp), %rax
movq %rax, -0x20100(%rbp)
movq $0x0, -0x20108(%rbp)
cmpq $0x0, -0x20100(%rbp)
jle 0x6144
movq -0x20120(%rbp), %rax
movq (%rax), %rdi
movq -0x20100(%rbp), %rdx
leaq -0x20030(%rbp), %rsi
callq 0x3350
movq %rax, -0x20198(%rbp)
jmp 0x60d7
movq -0x20198(%rbp), %rax
movl %eax, -0x2010c(%rbp)
movslq -0x2010c(%rbp), %rax
addq -0x20108(%rbp), %rax
movq %rax, -0x20108(%rbp)
movq -0x20108(%rbp), %rax
movq -0x200a8(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jge 0x613d
movl -0x200f8(%rbp), %edi
leaq -0x20030(%rbp), %rsi
movl $0x20000, %edx          # imm = 0x20000
callq 0x33f0
movq %rax, -0x201a0(%rbp)
jmp 0x612d
movq -0x201a0(%rbp), %rax
movq %rax, -0x20100(%rbp)
jmp 0x613f
jmp 0x6144
jmp 0x60a3
movl -0x200f8(%rbp), %edi
callq 0x3520
jmp 0x6151
movq -0x200f0(%rbp), %rdi
callq 0x3070
jmp 0x615f
leaq -0x200a0(%rbp), %rdi
callq 0x31c0
leaq -0x20080(%rbp), %rdi
callq 0x31c0
leaq -0x20050(%rbp), %rdi
callq 0x31c0
leaq -0x30(%rbp), %rdi
callq 0x31c0
addq $0x201a0, %rsp          # imm = 0x201A0
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x31c0
movq -0x20058(%rbp), %rdi
callq 0x3480
nopw (%rax,%rax)