// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-dbuf.c
// Function: dbuf_close
void dbuf_close(dbuf *f)
{
	deark *c;
	if(!f) return;
	c = f->c;

	if(f->wbuffer_bytes_used!=0) dbuf_flush(f);

	if(c->enable_oinfo && f->is_managed) {
		u32 crc = 0;

		if(f->crco_for_oinfo) {
			crc = de_crcobj_getval(f->crco_for_oinfo);
		}
		de_msg(c, "Output file info: ID=%d CRC=%08x size=%"I64_FMT, f->file_id,
			crc, f->len);
	}

	if(f->btype==DBUF_TYPE_OFILE || f->btype==DBUF_TYPE_STDOUT) {
		c->total_output_size += f->len;
	}

	if(f->btype==DBUF_TYPE_MEMBUF && f->write_memfile_to_zip_archive) {
		de_zip_add_file_to_archive(c, f);
		if(f->name) {
			de_dbg3(c, "closing memfile %s", f->name);
		}
	}
	else if(f->writing_to_tar_archive) {
		de_tar_end_member_file(c, f);
	}

	switch(f->btype) {
	case DBUF_TYPE_IFILE:
	case DBUF_TYPE_OFILE:
		if(f->name) {
			de_dbg3(c, "closing file %s", f->name);
		}
		de_fclose(f->fp);
		f->fp = NULL;

		if(f->btype==DBUF_TYPE_OFILE && f->is_managed) {
			de_update_file_attribs(f, c->preserve_file_times);
		}
		break;
	case DBUF_TYPE_FIFO:
		de_fclose(f->fp);
		f->fp = NULL;
		break;
	case DBUF_TYPE_STDOUT:
		if(f->name && f->is_managed) {
			de_dbg3(c, "finished writing %s to stdout", f->name);
		}
		else if(!f->is_managed) {
			de_dbg3(c, "finished writing %s", f->name);
		}
		f->fp = NULL;
		break;
	case DBUF_TYPE_MEMBUF:
	case DBUF_TYPE_IDBUF:
	case DBUF_TYPE_ODBUF:
	case DBUF_TYPE_STDIN:
	case DBUF_TYPE_CUSTOM:
	case DBUF_TYPE_NULL:
		break;
	default:
		de_internal_err_nonfatal(c, "Don't know how to close this type of file (%d)", f->btype);
	}

	de_free(c, f->membuf_buf);
	de_free(c, f->name);
	de_free(c, f->rcache);
	de_free(c, f->wbuffer);
	if(f->crco_for_oinfo) de_crcobj_destroy(f->crco_for_oinfo);
	if(f->fi_copy) de_finfo_destroy(c, f->fi_copy);
	de_free(c, f);

	if(c->total_output_size > c->max_total_output_size) {
		// FIXME: Since we only do this check when a file is closed, it can
		// potentially be subverted in the (rare) case that Deark has multiple
		// output files open simultaneously.
		de_err(c, "Maximum total output size of %"I64_FMT" bytes exceeded",
			c->max_total_output_size);
		de_fatalerror(c);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x1676b8
jmp 0x1679ce
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x1676d8
movq -0x8(%rbp), %rdi
callq 0x167c30
movq -0x10(%rbp), %rax
movzbl 0x96(%rax), %eax
cmpl $0x0, %eax
je 0x167741
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
je 0x167741
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x16771d
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x15f340
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x64(%rax), %edx
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %r8
leaq 0x6d793(%rip), %rsi     # 0x1d4ecd
movb $0x0, %al
callq 0x15c190
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
je 0x167753
movq -0x8(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x167767
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
addq 0x40(%rax), %rcx
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x1677b1
movq -0x8(%rbp), %rax
movzbl 0x60(%rax), %eax
cmpl $0x0, %eax
je 0x1677b1
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x162520
movq -0x8(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x1677af
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdx
leaq 0x6d74f(%rip), %rsi     # 0x1d4ef7
movb $0x0, %al
callq 0x15b400
jmp 0x1677ca
movq -0x8(%rbp), %rax
cmpb $0x0, 0x61(%rax)
je 0x1677c8
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x164040
jmp 0x1677ca
movq -0x8(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x20(%rbp)
subq $0x9, %rax
ja 0x1678e7
movq -0x20(%rbp), %rax
leaq 0x6d4eb(%rip), %rcx     # 0x1d4cd4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x167817
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdx
leaq 0x6d6fa(%rip), %rsi     # 0x1d4f0a
movb $0x0, %al
callq 0x15b400
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x18fc60
movq -0x8(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x16785a
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
je 0x16785a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0xdc(%rax), %esi
callq 0x18fe50
jmp 0x1678ff
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x18fc60
movq -0x8(%rbp), %rax
movq $0x0, 0x10(%rax)
jmp 0x1678ff
movq -0x8(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x1678b1
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
je 0x1678b1
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdx
leaq 0x6d672(%rip), %rsi     # 0x1d4f1a
movb $0x0, %al
callq 0x15b400
jmp 0x1678d7
movq -0x8(%rbp), %rax
cmpb $0x0, 0x4(%rax)
jne 0x1678d5
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdx
leaq 0x6d66a(%rip), %rsi     # 0x1d4f38
movb $0x0, %al
callq 0x15b400
jmp 0x1678d7
movq -0x8(%rbp), %rax
movq $0x0, 0x10(%rax)
jmp 0x1678ff
jmp 0x1678ff
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movl (%rax), %edx
leaq 0x6d654(%rip), %rsi     # 0x1d4f4c
movb $0x0, %al
callq 0x15c380
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rsi
callq 0x15b820
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rsi
callq 0x15b820
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rsi
callq 0x15b820
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x167964
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x15f2e0
movq -0x8(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x167986
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rsi
callq 0x15d260
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x15b820
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0xb8(%rcx), %rax
jle 0x1679ce
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rdx
leaq 0x6d5bd(%rip), %rsi     # 0x1d4f7b
movb $0x0, %al
callq 0x15bfb0
movq -0x10(%rbp), %rdi
callq 0x15c250
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)