// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-zip.c
// Function: de_zip_add_file_to_archive
void de_zip_add_file_to_archive(deark *c, dbuf *f)
{
	struct zipw_ctx *zzz;
	struct zipw_md *md = NULL;
	int write_ntfs_times = 0;
	int write_UT_time = 0;

	md = de_malloc(c, sizeof(struct zipw_md));

	if(!c->zip_data) {
		// ZIP file hasn't been created yet
		if(!de_zip_create_file(c)) {
			de_fatalerror(c);
			goto done;
		}
	}

	zzz = (struct zipw_ctx*)c->zip_data;

	de_dbg(c, "adding to zip: name=%s len=%"I64_FMT, f->name, f->len);

	if(f->fi_copy) {
		if(f->fi_copy->is_directory) {
			md->is_directory = 1;
		}
		else if(f->fi_copy->is_volume_label) {
			md->is_volume_label = 1;
		}

		if(f->fi_copy->mode_flags&DE_MODEFLAG_EXE) {
			md->is_executable = 1;
		}
	}

	if(c->preserve_file_times_archives && f->fi_copy && f->fi_copy->timestamp[DE_TIMESTAMPIDX_MODIFY].is_valid) {
		md->modtime = f->fi_copy->timestamp[DE_TIMESTAMPIDX_MODIFY];
		if(md->modtime.precision>DE_TSPREC_1SEC) {
			write_ntfs_times = 1;
		}
	}
	else if(c->reproducible_output) {
		de_get_reproducible_timestamp(c, &md->modtime);
	}
	else {
		de_cached_current_time_to_timestamp(c, &md->modtime);

		// We only write the current time because ZIP format leaves us little
		// choice.
		// Note that although c->current_time is probably high precision,
		// we don't consider that good enough reason to force NTFS timestamps
		// to be written.
	}

	// Note: Timestamps other than the modification time are a low priority.
	// We'll write them in some cases, when it is easy to do so.
	if(c->preserve_file_times_archives && f->fi_copy) {
		md->actime = f->fi_copy->timestamp[DE_TIMESTAMPIDX_ACCESS];
		md->crtime = f->fi_copy->timestamp[DE_TIMESTAMPIDX_CREATE];
	}

	md->modtime_unix = de_timestamp_to_unix_time(&md->modtime);
	set_dos_modtime(md);

	if(is_valid_32bit_unix_time(md->modtime_unix)) {
		// Always write a Unix timestamp if we can.
		write_UT_time = 1;

		if(md->modtime_unix < 0) {
			// This negative Unix time is in range, but problematic,
			// so write NTFS times as well.
			write_ntfs_times = 1;
		}
	}
	else { // Out of range of ZIP's (signed int32) Unix style timestamps
		write_ntfs_times = 1;
	}

	if(write_ntfs_times) {
		md->modtime_as_FILETIME = de_timestamp_to_FILETIME(&md->modtime);
		if(md->modtime_as_FILETIME == 0) {
			write_ntfs_times = 0;
		}
		else {
			md->actime_as_FILETIME = de_timestamp_to_FILETIME(&md->actime);
			md->crtime_as_FILETIME = de_timestamp_to_FILETIME(&md->crtime);
		}
	}

	// Create ZIP "extra data" "Extended Timestamp" and "NTFS" fields,
	// containing the UTC timestamp.

	// Use temporary dbufs to help construct the extra field data.
	md->eflocal = dbuf_create_membuf(c, 256, 0);
	md->efcentral = dbuf_create_membuf(c, 256, 0);

	if(write_UT_time) {
		do_UT_times(c, md, md->eflocal, 0);
		do_UT_times(c, md, md->efcentral, 1);
	}

	if(write_ntfs_times) {
		// Note: Info-ZIP says: "In the current implementations, this field [...]
		// is only stored as local extra field.
		// But 7-Zip supports it *only* as a central extra field.
		// So we'll write both.
		do_ntfs_times(c, md, md->eflocal, 0);
		do_ntfs_times(c, md, md->efcentral, 1);
	}

	if(f->fi_copy && f->fi_copy->has_riscos_data) {
		do_riscos_attribs(c, md, f->fi_copy, md->eflocal);
		do_riscos_attribs(c, md, f->fi_copy, md->efcentral);
	}

	if(md->is_directory) {
		size_t nlen;
		char *name2;

		// Append a "/" to the name
		nlen = de_strlen(f->name);
		name2 = de_malloc(c, (i64)nlen+2);
		de_snprintf(name2, nlen+2, "%s/", f->name);

		zipw_add_memberfile(c, zzz, md, f, name2, MZ_NO_COMPRESSION);

		de_free(c, name2);
	}
	else {
		zipw_add_memberfile(c, zzz, md, f, f->name, zzz->cmprlevel);
	}

done:
	if(md) {
		dbuf_close(md->eflocal);
		dbuf_close(md->efcentral);
		de_free(c, md);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl $0x70, %esi
callq 0x15b780
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x138(%rax)
jne 0x162584
movq -0x8(%rbp), %rdi
callq 0x162310
cmpl $0x0, %eax
jne 0x162582
movq -0x8(%rbp), %rdi
callq 0x15c250
jmp 0x162961
jmp 0x162584
movq -0x8(%rbp), %rax
movq 0x138(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
leaq 0x72557(%rip), %rsi     # 0x1d4b05
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x162619
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rax
cmpb $0x0, 0x9(%rax)
je 0x1625de
movq -0x20(%rbp), %rax
movb $0x1, 0x59(%rax)
jmp 0x1625f9
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rax
cmpb $0x0, 0xa(%rax)
je 0x1625f7
movq -0x20(%rbp), %rax
movb $0x1, 0x5a(%rax)
jmp 0x1625f9
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rax
movl 0x14(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x162617
movq -0x20(%rbp), %rax
movb $0x1, 0x58(%rax)
jmp 0x162619
movq -0x8(%rbp), %rax
movzbl 0xdd(%rax), %eax
cmpl $0x0, %eax
je 0x16267f
movq -0x10(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x16267f
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rax
movzbl 0x18(%rax), %eax
cmpl $0x0, %eax
je 0x16267f
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0xd0(%rcx), %rcx
movq 0x18(%rcx), %rdx
movq %rdx, (%rax)
movq 0x20(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x1e, %eax
jle 0x16267d
movl $0x1, -0x24(%rbp)
jmp 0x1626aa
movq -0x8(%rbp), %rax
cmpb $0x0, 0xdf(%rax)
je 0x16269b
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15f5e0
jmp 0x1626a8
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15e330
jmp 0x1626aa
movq -0x8(%rbp), %rax
movzbl 0xdd(%rax), %eax
cmpl $0x0, %eax
je 0x162706
movq -0x10(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x162706
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0xd0(%rcx), %rcx
movq 0x38(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x40(%rcx), %rcx
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0xd0(%rcx), %rcx
movq 0x28(%rcx), %rdx
movq %rdx, 0x20(%rax)
movq 0x30(%rcx), %rcx
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rdi
callq 0x15dd00
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rdi
callq 0x1629a0
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x162a70
cmpl $0x0, %eax
je 0x162750
movl $0x1, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jge 0x16274e
movl $0x1, -0x24(%rbp)
jmp 0x162757
movl $0x1, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x1627b7
movq -0x20(%rbp), %rdi
callq 0x15d6d0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x162785
movl $0x0, -0x24(%rbp)
jmp 0x1627b5
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
callq 0x15d6d0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
callq 0x15d6d0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x50(%rax)
jmp 0x1627b7
movq -0x8(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x168020
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x168020
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x68(%rax)
cmpl $0x0, -0x28(%rbp)
je 0x162824
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rdx
xorl %ecx, %ecx
callq 0x162aa0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x68(%rax), %rdx
movl $0x1, %ecx
callq 0x162aa0
cmpl $0x0, -0x24(%rbp)
je 0x16285b
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rdx
xorl %ecx, %ecx
callq 0x162c20
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x68(%rax), %rdx
movl $0x1, %ecx
callq 0x162c20
movq -0x10(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x1628bd
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rax
movzbl 0x10(%rax), %eax
cmpl $0x0, %eax
je 0x1628bd
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rcx
callq 0x162d10
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x68(%rax), %rcx
callq 0x162d10
movq -0x20(%rbp), %rax
cmpb $0x0, 0x59(%rax)
je 0x16293a
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x190e0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
leaq 0x7221c(%rip), %rdx     # 0x1d4b24
movb $0x0, %al
callq 0x15a980
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq -0x38(%rbp), %r8
xorl %r9d, %r9d
callq 0x162df0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
jmp 0x16295f
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x68(%rax), %r8
movq -0x18(%rbp), %rax
movl 0x10(%rax), %r9d
callq 0x162df0
jmp 0x162961
cmpq $0x0, -0x20(%rbp)
je 0x16298f
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x1676a0
movq -0x20(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)