// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/misc/init.cpp
// Function: smooth::Free()
S::Void S::Free()
{
	/* Delete all remaining callers left
	 * from nonblocking function calls.
	 */
	NonBlocking::CleanUp();

	/* Call ObjectCleanup() to make sure other
	 * DLLs are unloaded before we continue.
	 */
	Object::ObjectCleanup();

	if (--initCount) return;

#ifdef DEBUG
	if (Object::GetNOfObjects() != 0) GUI::Dialogs::QuickMessage(String("Incomplete smooth library shutdown!\n\n").Append(String::FromInt(Object::GetNOfObjects())).Append(" objects are still alive.\n\nPlease make sure to delete any smooth objects\nyou create before exiting the program."), "Error", GUI::Dialogs::Message::Buttons::Ok, GUI::Dialogs::Message::Icon::Error);
#endif

	/* Stop running threads.
	 */
	if (Threads::Thread::GetNOfRunningThreads() > 0)
	{
		for (Int i = 0; i < Object::GetNOfObjects(); i++)
		{
			Object	*object = Object::GetNthObject(i);

			if (object == NIL) continue;

			if (object->GetObjectType() == Threads::Thread::classID &&
			    !(object->GetFlags() & Threads::THREAD_KILLFLAG_WAIT)) ((Threads::Thread *) object)->Stop();
		}
	}

	/* Wait for remaining threads to finish.
	 */
	while (Threads::Thread::GetNOfRunningThreads() > 0) System::System::Sleep(10);

	/* Delete translator object and free iconv library.
	 */
	delete I18n::Translator::defaultTranslator;

#if defined __WIN32__
	if (Setup::useIconv) FreeIconvDLL();
#endif

	/* Call registered free functions.
	 */
	foreach (Int (*freeFunction)(), (*freeFunctions))
	{
		freeFunction();
	}

	initFunctions->RemoveAll();
	freeFunctions->RemoveAll();

	delete initFunctions;
	delete freeFunctions;

	/* Deinit system backends.
	 */
	Backends::Backend::DeinitBackends();

	/* All pending objects should be marked for
	 * deletion now, so let's call ObjectCleanup()
	 * again to actually free them.
	 */
	Object::ObjectCleanup();
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
callq 0x57250
callq 0x59138
decl 0xbd21f(%rip)           # 0x1778e0
je 0xba6c8
popq %rbx
popq %r14
popq %rbp
retq
movq 0xb1fc9(%rip), %rdi     # 0x16c698
callq 0x56cd0
testw %ax, %ax
jle 0xba726
callq 0x575e0
testl %eax, %eax
jle 0xba726
movq 0xb2347(%rip), %rax     # 0x16ca30
xorl %ebx, %ebx
movswl (%rax), %ebp
movl %ebx, %edi
callq 0x58800
testq %rax, %rax
je 0xba71b
movq %rax, %r14
leaq 0x20(%rax), %rdi
movl %ebp, %esi
callq 0x57520
testb %al, %al
je 0xba71b
testb $0x1, 0x30(%r14)
jne 0xba71b
movq %r14, %rdi
callq 0x56260
incl %ebx
callq 0x575e0
cmpl %eax, %ebx
jl 0xba6ee
movq 0xb1f6b(%rip), %rdi     # 0x16c698
callq 0x56cd0
testw %ax, %ax
jle 0xba755
movq 0xb1f5a(%rip), %rbx     # 0x16c698
movl $0xa, %edi
callq 0x578c0
movq %rbx, %rdi
callq 0x56cd0
testw %ax, %ax
jg 0xba73e
movq 0xb1c8c(%rip), %rax     # 0x16c3e8
movq (%rax), %rdi
testq %rdi, %rdi
je 0xba76a
movq (%rdi), %rax
callq *0x8(%rax)
movq 0xbd17f(%rip), %rdi     # 0x1778f0
cmpl $0x0, 0x8(%rdi)
jle 0xba797
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
incl %ebx
movl %ebx, %esi
callq 0x60a40
callq *(%rax)
movq 0xbd162(%rip), %rdi     # 0x1778f0
movl 0x8(%rdi), %eax
decl %eax
cmpl %eax, %ebx
jl 0xba77c
movq 0xbd14a(%rip), %rdi     # 0x1778e8
movq (%rdi), %rax
callq *0x20(%rax)
movq 0xbd145(%rip), %rdi     # 0x1778f0
movq (%rdi), %rax
callq *0x20(%rax)
movq 0xbd130(%rip), %rdi     # 0x1778e8
testq %rdi, %rdi
je 0xba7c3
movq (%rdi), %rax
callq *0x8(%rax)
movq 0xbd126(%rip), %rdi     # 0x1778f0
testq %rdi, %rdi
je 0xba7d5
movq (%rdi), %rax
callq *0x8(%rax)
callq 0x5ab60
popq %rbx
popq %r14
popq %rbp
jmp 0x59138
nop