// File: /workspace/github_c_makefile_star2_O3/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 0xbd06c(%rip)           # 0x1768e0
je 0xb987b
popq %rbx
popq %r14
popq %rbp
retq
movq 0xb1e16(%rip), %rdi     # 0x16b698
callq 0x56cd0
testw %ax, %ax
jle 0xb98d9
callq 0x575e0
testl %eax, %eax
jle 0xb98d9
movq 0xb2194(%rip), %rax     # 0x16ba30
xorl %ebx, %ebx
movswl (%rax), %ebp
movl %ebx, %edi
callq 0x58800
testq %rax, %rax
je 0xb98ce
movq %rax, %r14
leaq 0x20(%rax), %rdi
movl %ebp, %esi
callq 0x57520
testb %al, %al
je 0xb98ce
testb $0x1, 0x30(%r14)
jne 0xb98ce
movq %r14, %rdi
callq 0x56260
incl %ebx
callq 0x575e0
cmpl %eax, %ebx
jl 0xb98a1
movq 0xb1db8(%rip), %rdi     # 0x16b698
callq 0x56cd0
testw %ax, %ax
jle 0xb9908
movq 0xb1da7(%rip), %rbx     # 0x16b698
movl $0xa, %edi
callq 0x578c0
movq %rbx, %rdi
callq 0x56cd0
testw %ax, %ax
jg 0xb98f1
movq 0xb1ad9(%rip), %rax     # 0x16b3e8
movq (%rax), %rdi
testq %rdi, %rdi
je 0xb991d
movq (%rdi), %rax
callq *0x8(%rax)
movq 0xbcfcc(%rip), %rdi     # 0x1768f0
cmpl $0x0, 0x8(%rdi)
jle 0xb994a
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
incl %ebx
movl %ebx, %esi
callq 0x60a9a
callq *(%rax)
movq 0xbcfaf(%rip), %rdi     # 0x1768f0
movl 0x8(%rdi), %eax
decl %eax
cmpl %eax, %ebx
jl 0xb992f
movq 0xbcf97(%rip), %rdi     # 0x1768e8
movq (%rdi), %rax
callq *0x20(%rax)
movq 0xbcf92(%rip), %rdi     # 0x1768f0
movq (%rdi), %rax
callq *0x20(%rax)
movq 0xbcf7d(%rip), %rdi     # 0x1768e8
testq %rdi, %rdi
je 0xb9976
movq (%rdi), %rax
callq *0x8(%rax)
movq 0xbcf73(%rip), %rdi     # 0x1768f0
testq %rdi, %rdi
je 0xb9988
movq (%rdi), %rax
callq *0x8(%rax)
callq 0x5ab42
popq %rbx
popq %r14
popq %rbp
jmp 0x59138