// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
pushq %rax
movq 0x2b20(%rdi), %r14
testq %r14, %r14
je 0x384b
movq %rdi, %rbx
movl 0x28c(%rdi), %ebp
cmpl $0x64, %ebp
je 0x37eb
cmpl $0x0, 0x250(%rbx)
jne 0x3624
movl 0x24c(%rbx), %eax
movl %eax, 0x250(%rbx)
movq (%r14), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x20c0
cmpl $0x65, %ebp
jne 0x3643
testl %eax, %eax
je 0x3651
movl $0x1, 0x8(%r14)
jmp 0x3659
testl %eax, %eax
je 0x369b
movl $0x1, 0x8(%r14)
jmp 0x36a3
movq $0x0, 0x20(%r14)
movq 0x2b20(%rbx), %rdi
movl 0x27c(%rbx), %esi
callq 0x13968
movl 0x2b10(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x13968
movq 0x2b20(%rbx), %rdi
movl 0x294(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %r14
jmp 0x37eb
movq $0x0, 0x20(%r14)
movq %rbx, %rdi
callq 0x80e2
movq 0x2b20(%rbx), %rax
movq (%rax), %rdi
callq 0x2160
movq 0x2b20(%rbx), %r15
movl 0x20(%r15), %eax
movl %eax, 0x2b40(%rbx)
xorl %eax, %eax
cmpl $0x7d8, 0x250(%rbx)     # imm = 0x7D8
setge %al
leaq 0xc(,%rax,4), %r14
movq (%r15), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x20c0
testl %eax, %eax
je 0x36fd
movl $0x1, 0x8(%r15)
jmp 0x3701
movq %r14, 0x20(%r15)
cmpl $0x7d2, 0x250(%rbx)     # imm = 0x7D2
jg 0x371f
movq 0x2b20(%rbx), %rdi
movl 0x2b40(%rbx), %esi
callq 0x13968
cmpl $0x7d8, 0x250(%rbx)     # imm = 0x7D8
jl 0x373d
movl 0x2b40(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x13a38
movq 0x2b20(%rbx), %rax
movq (%rax), %rdi
callq 0x2160
movq 0x2b20(%rbx), %r15
movl 0x2b40(%rbx), %r14d
movq (%r15), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x20c0
testl %eax, %eax
je 0x3775
movl $0x1, 0x8(%r15)
jmp 0x3779
movq %r14, 0x20(%r15)
cmpl $0x7d7, 0x250(%rbx)     # imm = 0x7D7
jg 0x3791
cmpl $0x1326580, 0x284(%rbx) # imm = 0x1326580
jb 0x37a3
movq 0x2b20(%rbx), %rdi
movl 0x12b0(%rbx), %esi
callq 0x13968
cmpl $0x7d2, 0x250(%rbx)     # imm = 0x7D2
jg 0x37c1
movq 0x2b20(%rbx), %rdi
movl 0x2a0(%rbx), %esi
callq 0x13968
cmpl $0x7d8, 0x250(%rbx)     # imm = 0x7D8
jl 0x37df
movl 0x2a0(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x13a38
movq 0x2b20(%rbx), %r14
testq %r14, %r14
je 0x3844
movq (%r14), %rdi
testq %rdi, %rdi
je 0x3801
callq 0x2120
movq $0x0, (%r14)
jmp 0x3809
movl $0x1, 0x8(%r14)
xorl %eax, %eax
movq %rax, 0x20(%r14)
movq %rax, 0x10(%r14)
movb $0x0, 0xc(%r14)
movq 0x2b20(%rbx), %r14
testq %r14, %r14
je 0x3839
movq %r14, %rdi
callq 0x13b82
movl $0x28, %esi
movq %r14, %rdi
callq 0x2140
movq $0x0, 0x2b20(%rbx)
movb $0x0, 0x2b29(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq