// File: JD297[P]cedit/src/cedit.cpp
// Function: cedit::Cedit::event_save()
void Cedit::event_save()
{
	if(this->filename.empty())
	{
		if(!this->menu.type(FILE_SAVE)) {
			return;
		}

		this->filename = this->menu.content;

		this->refreshHeader = true;
	}

	std::ofstream f(this->filename.c_str());

	auto itEnd = std::prev(this->content.end());

	if(!itEnd->empty())
	{
		itEnd->append("\n");
		this->content.emplace_back("");
	}

	for(auto it = this->content.begin(); it != this->content.end(); it++)
	{
		f << *it;
	}

	f.close();

	if(!f)
	{
		if(errno)
		{
			this->menu.display(std::string(FAIL_WRITE) + std::string("\"") + std::string(filename) + "\": " + std::strerror(errno), COLOR_RED);
		}

		return;
	}

	this->menu.display(std::to_string(content.size()-1) + " " + SAVE);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3d0, %rsp            # imm = 0x3D0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x3a0(%rbp)
addq $0x70, %rdi
callq 0x46c0
testb $0x1, %al
jne 0x5749
jmp 0x579c
movq -0x3a0(%rbp), %rdi
addq $0xb0, %rdi
leaq 0x88a6(%rip), %rsi      # 0xe004
leaq 0x8b14(%rip), %rdx      # 0xe279
callq 0xd910
testb $0x1, %al
jne 0x5773
jmp 0x5c8c
movq -0x3a0(%rbp), %rdi
movq %rdi, %rsi
addq $0xb0, %rsi
addq $0x18, %rsi
addq $0x70, %rdi
callq 0x4050
movq -0x3a0(%rbp), %rax
movb $0x1, 0x6d(%rax)
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
callq 0x4220
movq %rax, %rsi
leaq -0x208(%rbp), %rdi
movl $0x10, %edx
callq 0x44b0
movq -0x3a0(%rbp), %rdi
callq 0x92c0
movq %rax, -0x218(%rbp)
movq -0x218(%rbp), %rdi
movl $0x1, %esi
callq 0x9280
movq %rax, -0x3a8(%rbp)
jmp 0x57ed
movq -0x3a8(%rbp), %rax
movq %rax, -0x210(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x92f0
movq %rax, %rdi
callq 0x46c0
testb $0x1, %al
jne 0x585e
leaq -0x210(%rbp), %rdi
callq 0x92f0
movq %rax, %rdi
leaq 0x8a4f(%rip), %rsi      # 0xe278
callq 0x4740
jmp 0x5830
movq -0x3a0(%rbp), %rdi
leaq 0x8a3b(%rip), %rsi      # 0xe279
callq 0x9170
jmp 0x5845
jmp 0x585e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x5cf3
movq -0x3a0(%rbp), %rdi
callq 0x91c0
movq %rax, -0x230(%rbp)
movq -0x3a0(%rbp), %rdi
callq 0x92c0
movq %rax, -0x238(%rbp)
leaq -0x230(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x9310
testb $0x1, %al
jne 0x589d
jmp 0x58d3
leaq -0x230(%rbp), %rdi
callq 0x9340
movq %rax, %rsi
leaq -0x208(%rbp), %rdi
callq 0x43d0
jmp 0x58ba
jmp 0x58bc
leaq -0x230(%rbp), %rdi
xorl %esi, %esi
callq 0x9360
movq %rax, -0x240(%rbp)
jmp 0x5871
leaq -0x208(%rbp), %rdi
callq 0x45f0
jmp 0x58e1
movq -0x208(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x208(%rbp,%rax), %rdi
callq 0x4280
movb %al, -0x3a9(%rbp)
jmp 0x5901
movb -0x3a9(%rbp), %al
testb $0x1, %al
jne 0x5910
jmp 0x5bd3
callq 0x4060
cmpl $0x0, (%rax)
je 0x5bc4
movq -0x3a0(%rbp), %rax
addq $0xb0, %rax
movq %rax, -0x3c0(%rbp)
leaq -0x2e1(%rbp), %rdi
movq %rdi, -0x3b8(%rbp)
callq 0x4710
movq -0x3b8(%rbp), %rdx
leaq 0x86ce(%rip), %rsi      # 0xe021
leaq -0x2e0(%rbp), %rdi
callq 0x90c0
jmp 0x5961
leaq -0x309(%rbp), %rdi
movq %rdi, -0x3c8(%rbp)
callq 0x4710
movq -0x3c8(%rbp), %rdx
leaq 0x86b9(%rip), %rsi      # 0xe03b
leaq -0x308(%rbp), %rdi
callq 0x90c0
jmp 0x5990
leaq -0x2c0(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
leaq -0x308(%rbp), %rdx
callq 0x93e0
jmp 0x59ac
movq -0x3a0(%rbp), %rsi
addq $0x70, %rsi
leaq -0x330(%rbp), %rdi
callq 0x4240
jmp 0x59c5
leaq -0x2a0(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
leaq -0x330(%rbp), %rdx
callq 0x93e0
jmp 0x59e1
leaq 0x8655(%rip), %rdx      # 0xe03d
leaq -0x280(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x9390
jmp 0x59fd
callq 0x4060
movl (%rax), %edi
callq 0x41a0
movq %rax, %rdx
leaq -0x260(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x9390
jmp 0x5a21
movq -0x3c0(%rbp), %rdi
leaq -0x260(%rbp), %rsi
movl $0x1, %edx
callq 0xd4f0
jmp 0x5a3b
leaq -0x260(%rbp), %rdi
callq 0x42d0
leaq -0x280(%rbp), %rdi
callq 0x42d0
leaq -0x2a0(%rbp), %rdi
callq 0x42d0
leaq -0x330(%rbp), %rdi
callq 0x42d0
leaq -0x2c0(%rbp), %rdi
callq 0x42d0
leaq -0x308(%rbp), %rdi
callq 0x42d0
leaq -0x309(%rbp), %rdi
callq 0x44a0
leaq -0x2e0(%rbp), %rdi
callq 0x42d0
leaq -0x2e1(%rbp), %rdi
callq 0x44a0
jmp 0x5bc4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x5bb3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x5b9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x5b8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x5b83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x5b77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x5b6b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x5b5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x42d0
leaq -0x280(%rbp), %rdi
callq 0x42d0
leaq -0x2a0(%rbp), %rdi
callq 0x42d0
leaq -0x330(%rbp), %rdi
callq 0x42d0
leaq -0x2c0(%rbp), %rdi
callq 0x42d0
leaq -0x308(%rbp), %rdi
callq 0x42d0
leaq -0x309(%rbp), %rdi
callq 0x44a0
leaq -0x2e0(%rbp), %rdi
callq 0x42d0
leaq -0x2e1(%rbp), %rdi
callq 0x44a0
jmp 0x5cf3
movl $0x1, -0x334(%rbp)
jmp 0x5c80
movq -0x3a0(%rbp), %rdi
movq %rdi, %rax
addq $0xb0, %rax
movq %rax, -0x3d0(%rbp)
callq 0x9590
movq %rax, %rsi
decq %rsi
leaq -0x398(%rbp), %rdi
callq 0x94b0
jmp 0x5c03
leaq 0x853a(%rip), %rdx      # 0xe144
leaq -0x378(%rbp), %rdi
leaq -0x398(%rbp), %rsi
callq 0x9390
jmp 0x5c1f
leaq 0x841b(%rip), %rdx      # 0xe041
leaq -0x358(%rbp), %rdi
leaq -0x378(%rbp), %rsi
callq 0x9390
jmp 0x5c3b
movq -0x3d0(%rbp), %rdi
leaq -0x358(%rbp), %rsi
xorl %edx, %edx
callq 0xd4f0
jmp 0x5c52
leaq -0x358(%rbp), %rdi
callq 0x42d0
leaq -0x378(%rbp), %rdi
callq 0x42d0
leaq -0x398(%rbp), %rdi
callq 0x42d0
movl $0x0, -0x334(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x4620
addq $0x3d0, %rsp            # imm = 0x3D0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x5ce7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x5cdb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x358(%rbp), %rdi
callq 0x42d0
leaq -0x378(%rbp), %rdi
callq 0x42d0
leaq -0x398(%rbp), %rdi
callq 0x42d0
leaq -0x208(%rbp), %rdi
callq 0x4620
movq -0x220(%rbp), %rdi
callq 0x4700
nopl (%rax,%rax)