// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/dosbackup.c
// Function: do_one_volume33
static void do_one_volume33(deark *c, lctx *d, int vol,
	dbuf *ctrl_inf, dbuf *data_inf)
{
	i64 ctrl_pos;
	int saved_indent_level;
	struct fragment_ctx *fr = NULL;
	int num_file_items_remaining = 0;
	u8 expecting_another_dir_item = 1;
	char tmps[20];

	de_dbg_indent_save(c, &saved_indent_level);
	ctrl_pos = (i64)dbuf_getbyte(ctrl_inf, 0); // Expecting 139 (0x8b)

	while(1) {
		i64 item_pos;
		i64 item_len;
		u8 item_is_dir;

		if(num_file_items_remaining>0) {
			item_is_dir = 0;
		}
		else if(expecting_another_dir_item) {
			item_is_dir = 1;
		}
		else {
			goto done;
		}

		item_pos = ctrl_pos;
		if(item_pos >= ctrl_inf->len) {
			d->errflag = 1;
			d->need_errmsg = 1;
			goto done;
		}

		if(item_is_dir) {
			de_dbg(c, "dir item at %"I64_FMT, item_pos);
		}
		else {
			de_dbg(c, "file item at %"I64_FMT, item_pos);
		}

		de_dbg_indent(c, 1);

		item_len = dbuf_getbyte_p(ctrl_inf, &ctrl_pos);
		de_dbg(c, "item len: %"I64_FMT, item_len);

		if(item_is_dir) {
			i64 next_dir_pos;

			if(item_len!=70) {
				d->errflag = 1;
				d->need_errmsg = 1;
				goto done;
			}

			ucstring_empty(d->v33_cur_dir_name);
			dbuf_read_to_ucstring(ctrl_inf, ctrl_pos, 63, d->v33_cur_dir_name,
				DE_CONVFLAG_STOP_AT_NUL, d->input_encoding);
			ctrl_pos += 63;
			de_dbg(c, "dir name: \"%s\"", ucstring_getpsz_d(d->v33_cur_dir_name));
			de_arch_fixup_path(d->v33_cur_dir_name, 0x1);

			num_file_items_remaining = (int)dbuf_getu16le_p(ctrl_inf, &ctrl_pos);
			de_dbg(c, "num entries: %d", num_file_items_remaining);

			next_dir_pos = dbuf_getu32le_p(ctrl_inf, &ctrl_pos);
			if(next_dir_pos==0xffffffffLL) {
				de_strlcpy(tmps, "(none)", sizeof(tmps));
				expecting_another_dir_item = 0;
			}
			else {
				de_snprintf(tmps, sizeof(tmps), "%"I64_FMT, next_dir_pos);
				expecting_another_dir_item = 1;
			}
			de_dbg(c, "next dir pos: %s", tmps);
		}
		else { // "file" item
			if(item_len!=34) {
				d->errflag = 1;
				d->need_errmsg = 1;
				goto done;
			}

			if(fr) {
				destroy_fragment_ctx(c, fr);
			}
			fr = de_malloc(c, sizeof(struct fragment_ctx));
			fr->filename_srd = dbuf_read_string(ctrl_inf, ctrl_pos, 12, 12,
				DE_CONVFLAG_STOP_AT_NUL, d->input_encoding);
			ctrl_pos += 12;
			de_dbg(c, "file name: \"%s\"", ucstring_getpsz_d(fr->filename_srd->str));
			fixup_filename(fr->filename_srd->str);

			fr->fragment_flags = dbuf_getbyte_p(ctrl_inf, &ctrl_pos);
			// 0x01=last frg; 0x02=backed up OK; 0x04=has ext. attr.
			de_dbg(c, "frg flags: 0x%02x", (UI)fr->fragment_flags);
			fr->orig_size = dbuf_getu32le_p(ctrl_inf, &ctrl_pos);
			de_dbg(c, "total file size: %"I64_FMT, fr->orig_size);
			fr->fragment_num = (int)dbuf_getu16le_p(ctrl_inf, &ctrl_pos);
			de_dbg(c, "frg num: %d", fr->fragment_num);
			fr->pos_in_datafile = dbuf_getu32le_p(ctrl_inf, &ctrl_pos);
			de_dbg(c, "pos in data file: %"I64_FMT, fr->pos_in_datafile);
			fr->len_in_datafile = dbuf_getu32le_p(ctrl_inf, &ctrl_pos);
			de_dbg(c, "len in data file: %"I64_FMT, fr->len_in_datafile);
			fr->attribs = (UI)dbuf_getu16le_p(ctrl_inf, &ctrl_pos);
			dbg_attribs(c, fr->attribs);

			fr->dostm = dbuf_getu16le_p(ctrl_inf, &ctrl_pos);
			fr->dosdt = dbuf_getu16le_p(ctrl_inf, &ctrl_pos);
			de_dos_datetime_to_timestamp(&fr->mod_time, fr->dosdt, fr->dostm);
			fr->mod_time.tzcode = DE_TZCODE_LOCAL;
			dbg_timestamp(c, &fr->mod_time);

			v33_extract_fragment(c, d, fr, data_inf);

			num_file_items_remaining--;
		}

		ctrl_pos = item_pos + item_len;
		de_dbg_indent(c, -1);
	}
done:
	destroy_fragment_ctx(c, fr);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movb $0x1, -0x45(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x15b580
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x44(%rbp)
jle 0x6ce0e
movb $0x0, -0x71(%rbp)
jmp 0x6ce21
cmpb $0x0, -0x45(%rbp)
je 0x6ce1a
movb $0x1, -0x71(%rbp)
jmp 0x6ce1f
jmp 0x6d272
jmp 0x6ce21
movq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jl 0x6ce4c
movq -0x10(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x9(%rax)
jmp 0x6d272
cmpb $0x0, -0x71(%rbp)
je 0x6ce6a
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rdx
leaq 0x13d80a(%rip), %rsi    # 0x1aa66b
movb $0x0, %al
callq 0x15b0d0
jmp 0x6ce80
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rdx
leaq 0x13d802(%rip), %rsi    # 0x1aa67b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rdx
leaq 0x13d637(%rip), %rsi    # 0x1aa4e8
movb $0x0, %al
callq 0x15b0d0
cmpb $0x0, -0x71(%rbp)
je 0x6cff6
cmpq $0x46, -0x70(%rbp)
je 0x6cede
movq -0x10(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x9(%rax)
jmp 0x6d272
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x171210
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x10(%rbp), %rax
movl (%rax), %r9d
movl $0x3f, %edx
movl $0x1, %r8d
callq 0x1669f0
movq -0x30(%rbp), %rax
addq $0x3f, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x172650
movq -0x88(%rbp), %rdi
movq %rax, %rdx
leaq 0x13d745(%rip), %rsi    # 0x1aa68c
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movl $0x1, %esi
callq 0x17c2b0
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %edx
leaq 0x138b9d(%rip), %rsi    # 0x1a5b1b
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movq %rax, -0x80(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x80(%rbp)
jne 0x6cfbc
leaq -0x60(%rbp), %rdi
leaq 0x160576(%rip), %rsi    # 0x1cd522
movl $0x14, %edx
callq 0x15aa30
movb $0x0, -0x45(%rbp)
jmp 0x6cfdb
leaq -0x60(%rbp), %rdi
movq -0x80(%rbp), %rcx
movl $0x14, %esi
leaq 0x14813f(%rip), %rdx    # 0x1b510f
movb $0x0, %al
callq 0x15a980
movb $0x1, -0x45(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x60(%rbp), %rdx
leaq 0x13d6b1(%rip), %rsi    # 0x1aa69b
movb $0x0, %al
callq 0x15b0d0
jmp 0x6d253
cmpq $0x22, -0x70(%rbp)
je 0x6d012
movq -0x10(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x9(%rax)
jmp 0x6d272
cmpq $0x0, -0x40(%rbp)
je 0x6d026
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x6d2a0
movq -0x8(%rbp), %rdi
movl $0x50, %esi
callq 0x15b780
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movl (%rax), %r9d
movl $0xc, %ecx
movl $0x1, %r8d
movq %rcx, %rdx
callq 0x1664c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x30(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0x90(%rbp), %rdi
movq %rax, %rdx
leaq 0x152c6f(%rip), %rsi    # 0x1bfd0d
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x6d2e0
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movzbl (%rax), %edx
leaq 0x13d5cf(%rip), %rsi    # 0x1aa6ac
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x13d5af(%rip), %rsi    # 0x1aa6be
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl 0x4(%rax), %edx
leaq 0x13d595(%rip), %rsi    # 0x1aa6d3
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x13d56f(%rip), %rsi    # 0x1aa6df
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x13d553(%rip), %rsi    # 0x1aa6f5
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl 0x34(%rax), %esi
callq 0x6d370
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rdi
addq $0x40, %rdi
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rdx
callq 0x15d750
movq -0x40(%rbp), %rax
movb $0x2, 0x41(%rax)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x40, %rsi
callq 0x6d3e0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x6d420
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x68(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0x6ce02
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x6d2a0
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x15b5a0
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)