// File: /workspace/github_c_makefile_star2_O2/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 0x58440
callq 0x5a4b8
decl 0xb8f4d(%rip)           # 0x16caa0
je 0xb3b5a
popq %rbx
popq %r14
popq %rbp
retq
callq 0x571f0
testw %ax, %ax
jle 0xb3bb2
movq 0xadec5(%rip), %rax     # 0x161a30
xorl %ebx, %ebx
movswl (%rax), %ebp
callq 0x587f0
cmpl %eax, %ebx
jge 0xb3bb2
movl %ebx, %edi
callq 0x59b10
testq %rax, %rax
je 0xb3ba6
movq %rax, %r14
leaq 0x20(%rax), %rdi
movl %ebp, %esi
callq 0x58720
testb %al, %al
je 0xb3ba6
testb $0x1, 0x30(%r14)
jne 0xb3ba6
movq %r14, %rdi
callq 0x57350
incl %ebx
jmp 0xb3b70
pushq $0xa
popq %rdi
callq 0x58b10
callq 0x571f0
testw %ax, %ax
jg 0xb3baa
movq 0xad825(%rip), %rax     # 0x1613e8
movq (%rax), %rdi
testq %rdi, %rdi
je 0xb3bd1
movq (%rdi), %rax
callq *0x8(%rax)
xorl %ebx, %ebx
leal -0x1(%rbx), %eax
movq 0xb8ed3(%rip), %rdi     # 0x16cab0
movl 0x8(%rdi), %ecx
decl %ecx
cmpl %ecx, %eax
jge 0xb3bf3
movl %ebx, %esi
callq 0x6180a
callq *(%rax)
incl %ebx
jmp 0xb3bd3
movq 0xb8eae(%rip), %rdi     # 0x16caa8
movq (%rdi), %rax
callq *0x20(%rax)
movq 0xb8ea9(%rip), %rdi     # 0x16cab0
movq (%rdi), %rax
callq *0x20(%rax)
movq 0xb8e94(%rip), %rdi     # 0x16caa8
testq %rdi, %rdi
je 0xb3c1f
movq (%rdi), %rax
callq *0x8(%rax)
movq 0xb8e8a(%rip), %rdi     # 0x16cab0
testq %rdi, %rdi
je 0xb3c31
movq (%rdi), %rax
callq *0x8(%rax)
callq 0x5bc58
popq %rbx
popq %r14
popq %rbp
jmp 0x5a4b8
nop