// File: /workspace/github_cpp_makefile_star2_O2/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::CloseOutputLMF()
void LMF_IO::CloseOutputLMF()
/////////////////////////////////////////////////////////////////
{
	if (!output_lmf) return;

	if (DAQ_ID_output == DAQ_ID_RAW32BIT) {
		output_lmf->close(); delete output_lmf; output_lmf = 0;
		OutputFileIsOpen = false;
		return;
	}

	if (Cobold_Header_version_output == 0) Cobold_Header_version_output = Cobold_Header_version;
	
	if (DAQ_ID_output == DAQ_ID_SIMPLE) {
		output_lmf->seek(0);

		*output_lmf << SIMPLE_DAQ_ID_Orignial;
		unsigned __int32 dummy = __int32(uint64_number_of_written_events);
		*output_lmf << dummy;
		*output_lmf << data_format_in_userheader_output;

		output_lmf->close(); delete output_lmf; output_lmf = 0;
		OutputFileIsOpen = false;
		return;
	}

//	if (out_ar) {
		output_lmf->seek(0);

		WriteFirstHeader();

		output_lmf->flush();
		Headersize_output = (unsigned __int32)(output_lmf->tell());
		unsigned __int64 seek_value;
		if (Cobold_Header_version_output <= 2002) seek_value = 3*sizeof(unsigned __int32);
		if (Cobold_Header_version_output >= 2008) seek_value = 2*sizeof(unsigned __int32) + sizeof(unsigned __int64);

		output_lmf->seek(seek_value);
		if (Cobold_Header_version_output <= 2002) *output_lmf << Headersize_output;
		if (Cobold_Header_version_output >= 2008) {
			unsigned __int64 temp = Headersize_output;
			*output_lmf << temp;
		}
		output_lmf->flush();
		output_lmf->seek(Headersize_output);

		if (Cobold_Header_version_output >= 2008 || DAQVersion_output >= 20080000) {
			*output_lmf << LMF_Header_version;
		}

		if (Cobold_Header_version_output <= 2002) *output_lmf << User_header_size_output;
		if (Cobold_Header_version_output >= 2008) {
			unsigned __int64 temp = User_header_size_output;
			*output_lmf << temp;
		}
		
		//out_ar->Close(); out_ar=0;
//	}
	
	if (output_lmf) {output_lmf->close(); delete output_lmf; output_lmf = 0;}
	OutputFileIsOpen = false;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x2b20(%rdi), %rdi
testq %rdi, %rdi
je 0x33c1
movl 0x28c(%rbx), %ebp
cmpl $0x64, %ebp
je 0x338e
cmpl $0x0, 0x250(%rbx)
jne 0x322f
movl 0x24c(%rbx), %eax
movl %eax, 0x250(%rbx)
xorl %esi, %esi
callq 0x235c
cmpl $0x65, %ebp
jne 0x327d
movq 0x2b20(%rbx), %rdi
movl 0x27c(%rbx), %esi
callq 0x10d1e
movl 0x2b10(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x10d1e
movq 0x2b20(%rbx), %rdi
movl 0x294(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
jmp 0x338e
movq %rbx, %rdi
callq 0x6e70
movq 0x2b20(%rbx), %rdi
callq 0x110dc
movq 0x2b20(%rbx), %rdi
movl 0x20(%rdi), %eax
movl %eax, 0x2b40(%rbx)
xorl %eax, %eax
cmpl $0x7d8, 0x250(%rbx)     # imm = 0x7D8
setge %al
leaq 0xc(,%rax,4), %rsi
callq 0x235c
movl 0x250(%rbx), %eax
cmpl $0x7d2, %eax            # imm = 0x7D2
jg 0x32e2
movq 0x2b20(%rbx), %rdi
movl 0x2b40(%rbx), %esi
callq 0x10d1e
movl 0x250(%rbx), %eax
cmpl $0x7d8, %eax            # imm = 0x7D8
jl 0x32fb
movl 0x2b40(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x10e18
movq 0x2b20(%rbx), %rdi
callq 0x110dc
movq 0x2b20(%rbx), %rdi
movl 0x2b40(%rbx), %esi
callq 0x235c
movl 0x250(%rbx), %eax
cmpl $0x7d7, %eax            # imm = 0x7D7
jg 0x3332
cmpl $0x1326580, 0x284(%rbx) # imm = 0x1326580
jb 0x334a
movq 0x2b20(%rbx), %rdi
movl 0x12b0(%rbx), %esi
callq 0x10d1e
movl 0x250(%rbx), %eax
cmpl $0x7d2, %eax            # imm = 0x7D2
jg 0x3369
movq 0x2b20(%rbx), %rdi
movl 0x2a0(%rbx), %esi
callq 0x10d1e
movl 0x250(%rbx), %eax
cmpl $0x7d8, %eax            # imm = 0x7D8
jl 0x3382
movl 0x2a0(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x10e18
movq 0x2b20(%rbx), %rdi
testq %rdi, %rdi
je 0x33ba
callq 0x10f80
movq 0x2b20(%rbx), %r14
testq %r14, %r14
je 0x33a7
movq %r14, %rdi
callq 0x10fae
pushq $0x28
popq %rsi
movq %r14, %rdi
callq 0x2140
andq $0x0, 0x2b20(%rbx)
movb $0x0, 0x2b29(%rbx)
popq %rbx
popq %r14
popq %rbp
retq