// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, 0x2b20(%rax)
jne 0x3d93
jmp 0x40cd
movq -0x30(%rbp), %rax
cmpl $0x64, 0x28c(%rax)
jne 0x3df7
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
callq 0x1cec0
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x3ddc
movq -0x38(%rbp), %rdi
callq 0x1cf20
movq -0x38(%rbp), %rdi
movl $0x28, %esi
callq 0x21a0
movq -0x30(%rbp), %rax
movq $0x0, 0x2b20(%rax)
movb $0x0, 0x2b29(%rax)
jmp 0x40cd
movq -0x30(%rbp), %rax
cmpl $0x0, 0x250(%rax)
jne 0x3e14
movq -0x30(%rbp), %rax
movl 0x24c(%rax), %ecx
movl %ecx, 0x250(%rax)
movq -0x30(%rbp), %rax
cmpl $0x65, 0x28c(%rax)
jne 0x3ed9
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2440
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x27c(%rax), %esi
callq 0x1caf0
movq -0x30(%rbp), %rax
movq 0x2b10(%rax), %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl -0xc(%rbp), %esi
callq 0x1caf0
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x294(%rax), %esi
callq 0x1d170
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
callq 0x1cec0
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x3ebe
movq -0x40(%rbp), %rdi
callq 0x1cf20
movq -0x40(%rbp), %rdi
movl $0x28, %esi
callq 0x21a0
movq -0x30(%rbp), %rax
movq $0x0, 0x2b20(%rax)
movb $0x0, 0x2b29(%rax)
jmp 0x40cd
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2440
movq -0x30(%rbp), %rdi
callq 0xa760
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
callq 0x1d1d0
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
callq 0x1d110
movq %rax, %rcx
movq -0x30(%rbp), %rax
movl %ecx, 0x2b40(%rax)
cmpl $0x7d2, 0x250(%rax)     # imm = 0x7D2
jg 0x3f37
movq $0xc, -0x18(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x7d8, 0x250(%rax)     # imm = 0x7D8
jl 0x3f4f
movq $0x10, -0x18(%rbp)
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x2440
movq -0x30(%rbp), %rax
cmpl $0x7d2, 0x250(%rax)     # imm = 0x7D2
jg 0x3f89
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x2b40(%rax), %esi
callq 0x1caf0
movq -0x30(%rbp), %rax
cmpl $0x7d8, 0x250(%rax)     # imm = 0x7D8
jl 0x3fb7
movq -0x30(%rbp), %rax
movl 0x2b40(%rax), %ecx
movq %rcx, -0x20(%rbp)
movq 0x2b20(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x1cce0
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
callq 0x1d1d0
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x2b40(%rax), %eax
movl %eax, %esi
callq 0x2440
movq -0x30(%rbp), %rax
cmpl $0x7d8, 0x250(%rax)     # imm = 0x7D8
jge 0x3fff
movq -0x30(%rbp), %rax
cmpl $0x1326580, 0x284(%rax) # imm = 0x1326580
jb 0x4015
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x12b0(%rax), %esi
callq 0x1caf0
movq -0x30(%rbp), %rax
cmpl $0x7d2, 0x250(%rax)     # imm = 0x7D2
jg 0x403b
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x2a0(%rax), %esi
callq 0x1caf0
movq -0x30(%rbp), %rax
cmpl $0x7d8, 0x250(%rax)     # imm = 0x7D8
jl 0x4069
movq -0x30(%rbp), %rax
movl 0x2a0(%rax), %ecx
movq %rcx, -0x28(%rbp)
movq 0x2b20(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x1cce0
movq -0x30(%rbp), %rax
cmpq $0x0, 0x2b20(%rax)
je 0x40c2
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rdi
callq 0x1cec0
movq -0x30(%rbp), %rax
movq 0x2b20(%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x40b3
movq -0x48(%rbp), %rdi
callq 0x1cf20
movq -0x48(%rbp), %rdi
movl $0x28, %esi
callq 0x21a0
movq -0x30(%rbp), %rax
movq $0x0, 0x2b20(%rax)
movq -0x30(%rbp), %rax
movb $0x0, 0x2b29(%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)