// File: /workspace/github_cpp_makefile_star2_O3/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 0x38e9
movq %rdi, %rbx
movl 0x28c(%rdi), %ebp
cmpl $0x64, %ebp
je 0x3854
cmpl $0x0, 0x250(%rbx)
jne 0x3684
movl 0x24c(%rbx), %eax
movl %eax, 0x250(%rbx)
movq (%r14), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x20c0
cmpl $0x65, %ebp
jne 0x36a3
testl %eax, %eax
je 0x36b1
movl $0x1, 0x8(%r14)
jmp 0x36b9
testl %eax, %eax
je 0x36fb
movl $0x1, 0x8(%r14)
jmp 0x3703
movq $0x0, 0x20(%r14)
movq 0x2b20(%rbx), %rdi
movl 0x27c(%rbx), %esi
callq 0x13378
movl 0x2b10(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x13378
movq 0x2b20(%rbx), %rdi
movl 0x294(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %r14
jmp 0x3854
movq $0x0, 0x20(%r14)
movq %rbx, %rdi
callq 0x7fae
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 0x375d
movl $0x1, 0x8(%r15)
jmp 0x3761
movq %r14, 0x20(%r15)
movl 0x250(%rbx), %eax
cmpl $0x7d2, %eax            # imm = 0x7D2
jg 0x3786
movq 0x2b20(%rbx), %rdi
movl 0x2b40(%rbx), %esi
callq 0x13378
movl 0x250(%rbx), %eax
cmpl $0x7d8, %eax            # imm = 0x7D8
jl 0x379f
movl 0x2b40(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x13448
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 0x37d7
movl $0x1, 0x8(%r15)
jmp 0x37db
movq %r14, 0x20(%r15)
movl 0x250(%rbx), %eax
cmpl $0x7d7, %eax            # imm = 0x7D7
jg 0x37f4
cmpl $0x1326580, 0x284(%rbx) # imm = 0x1326580
jb 0x380c
movq 0x2b20(%rbx), %rdi
movl 0x12b0(%rbx), %esi
callq 0x13378
movl 0x250(%rbx), %eax
cmpl $0x7d2, %eax            # imm = 0x7D2
jg 0x382b
movq 0x2b20(%rbx), %rdi
movl 0x2a0(%rbx), %esi
callq 0x13378
movl 0x250(%rbx), %eax
cmpl $0x7d8, %eax            # imm = 0x7D8
jl 0x3844
movl 0x2a0(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x13448
movq 0x2b20(%rbx), %r14
testq %r14, %r14
je 0x38e2
movq (%r14), %rdi
testq %rdi, %rdi
je 0x3884
callq 0x2120
xorl %edi, %edi
movq %rdi, (%r14)
movq 0x2b20(%rbx), %rax
movq %rdi, 0x20(%r14)
movq %rdi, 0x10(%r14)
movb $0x0, 0xc(%r14)
movq %rax, %r14
testq %rax, %rax
jne 0x389b
jmp 0x38cd
movl $0x1, 0x8(%r14)
xorl %eax, %eax
movq %rax, 0x20(%r14)
movq %rax, 0x10(%r14)
movb $0x0, 0xc(%r14)
movq (%r14), %rax
movq %r14, %rdi
testq %rax, %rax
je 0x38b8
movq %rax, %rdi
callq 0x2120
movq $0x0, (%r14)
movq %r14, %rdi
xorl %eax, %eax
movq %rax, 0x20(%rdi)
movq %rax, 0x10(%rdi)
movl $0x0, 0x8(%rdi)
movb $0x0, 0xc(%rdi)
movl $0x28, %esi
callq 0x2140
movq $0x0, 0x2b20(%rbx)
movb $0x0, 0x2b29(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq