// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/classes/gui/application/application.cpp
// Function: smooth::GUI::Application::GetApplicationDirectory()
S::String S::GUI::Application::GetApplicationDirectory()
{
	if (applicationDirectory != NIL) return applicationDirectory;

#if defined __WIN32__
	Buffer<wchar_t>	 buffer(32768 + 1);
#else
	Buffer<char>	 buffer(PATH_MAX + 1);
#endif

	buffer.Zero();

#if defined __WIN32__
	/* On Windows, use GetModuleFileName to get the exe file name.
	 */
	GetModuleFileName(NIL, buffer, buffer.Size() - 1);

	applicationDirectory = buffer;
#elif defined __APPLE__
	/* On macOS, get the path using the proc_pidpath call.
	 */
	if (proc_pidpath(getpid(), buffer, buffer.Size()) > 0) applicationDirectory = buffer;

	/* Resort to using lsof -p <pid>, which returns the path to the current binary in the first
	 * txt section, in case lookup failed or we got the path to the Rosetta binary translator.
	 */
	if (applicationDirectory == NIL || applicationDirectory == "/usr/libexec/oah/translate")
	{
		FILE	*pstdin = popen(String("lsof -p ").Append(String::FromInt(getpid())).Append(" | awk '$4 == \"txt\" { print substr($0, index($0, $9)) }'"), "r");

		if (fscanf(pstdin, String("%[^\n]").Append(String::FromInt(buffer.Size() - 1)), (char *) buffer) > 0) applicationDirectory = buffer;

		pclose(pstdin);
	}
#elif defined __FreeBSD__
	/* On FreeBSD, the KERN_PROC_PATHNAME sysctl with pid -1 provides the path to the current binary.
	 */
	int	 mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
	size_t	 len	= buffer.Size();

	if (sysctl(mib, 4, buffer, &len, NULL, 0) == 0) applicationDirectory = buffer;
#elif defined __sun
	/* On Solaris, /proc/<pid>/path/a.out links to the current binary.
	 */
	if (readlink(String("/proc/").Append(String::FromInt(getpid())).Append("/path/a.out"), buffer, buffer.Size() - 1) > 0) applicationDirectory = buffer;
#elif defined __linux__ || defined __NetBSD__
	/* On Linux and NetBSD, /proc/<pid>/exe links to the current binary.
	 */
	if (readlink(String("/proc/").Append(String::FromInt(getpid())).Append("/exe"), buffer, buffer.Size() - 1) > 0) applicationDirectory = buffer;
#elif defined __HAIKU__
	/* On Haiku, get the path from application info.
	 */
	BApplication	*app = Backends::BackendHaiku::GetApplication();
	app_info	 ai;

	if (app->GetAppInfo(&ai) == B_OK) applicationDirectory.ImportFrom("UTF-8", BPath(&ai.ref).Path());
#endif

	if (applicationDirectory == NIL)
	{
		/* No system specific way to get the current binary path.
		 * Try concatenating the startup directory and command.
		 */
		String	 binary	= (command.StartsWith("/") ? String() : GetStartupDirectory()).Append(command).Replace("/./", "/");

		if (!File(binary).Exists())
		{
			/* Search the path for command.
			 */
			String			 path  = getenv("PATH");
			const Array<String>	&paths = path.Explode(":");

			foreach (const String &path, paths)
			{
				/* Check for command in this path.
				 */
				if (File(String(path).Append("/").Append(command)).Exists())
				{
					binary = String(path).Append("/").Append(command);

					break;
				}
			}
		}

		applicationDirectory = binary;
	}

	applicationDirectory[applicationDirectory.FindLast(Directory::GetDirectoryDelimiter()) + 1] = 0;

#if defined __APPLE__
	/* Change the returned path to Resources for macOS application bundles.
	 */
	if (applicationDirectory.EndsWith(".app/Contents/MacOS/")) applicationDirectory.Replace(".app/Contents/MacOS/", ".app/Contents/Resources/");
#endif

	return applicationDirectory;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x360, %rsp            # imm = 0x360
movq %rdi, -0x2a8(%rbp)
movq %rdi, %rax
movq %rax, -0x2a0(%rbp)
movq %rdi, -0x8(%rbp)
movq 0x194ad1(%rip), %rdi    # 0x208568
xorl %esi, %esi
callq 0x5b110
testb $0x1, %al
jne 0x73aa4
jmp 0x73abc
movq -0x2a8(%rbp), %rdi
movq 0x194ab6(%rip), %rsi    # 0x208568
callq 0x5b6d0
jmp 0x74361
leaq -0x20(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
movl $0x1001, %esi           # imm = 0x1001
callq 0x65e10
movq -0x2b0(%rbp), %rdi
callq 0x74780
jmp 0x73adf
leaq 0x113b42(%rip), %rsi    # 0x187628
leaq -0x48(%rbp), %rdi
callq 0x5c1f0
jmp 0x73af1
callq 0x5d6f0
movslq %eax, %rsi
leaq -0x60(%rbp), %rdi
callq 0x5b290
jmp 0x73b04
leaq -0x48(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x5a710
movq %rax, -0x2b8(%rbp)
jmp 0x73b1a
leaq 0x113b0e(%rip), %rsi    # 0x18762f
leaq -0x78(%rbp), %rdi
callq 0x5c1f0
jmp 0x73b2c
movq -0x2b8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x5a710
movq %rax, -0x2c0(%rbp)
jmp 0x73b45
movq -0x2c0(%rbp), %rdi
callq 0x5d090
movq %rax, -0x2c8(%rbp)
jmp 0x73b5a
leaq -0x20(%rbp), %rdi
callq 0x65e90
movq %rax, -0x2d0(%rbp)
jmp 0x73b6c
leaq -0x20(%rbp), %rdi
callq 0x65ed0
movl %eax, -0x2d4(%rbp)
jmp 0x73b7d
movq -0x2d0(%rbp), %rsi
movq -0x2c8(%rbp), %rdi
movl -0x2d4(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rdx
callq 0x5a0f0
movq %rax, -0x2e0(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5df00
leaq -0x60(%rbp), %rdi
callq 0x5df00
leaq -0x48(%rbp), %rdi
callq 0x5df00
movq -0x2e0(%rbp), %rax
cmpq $0x0, %rax
jle 0x73c51
leaq -0x20(%rbp), %rdi
callq 0x65e90
movq %rax, -0x2e8(%rbp)
jmp 0x73be1
movq -0x2e8(%rbp), %rsi
movq 0x194979(%rip), %rdi    # 0x208568
callq 0x5a230
jmp 0x73bf6
jmp 0x73c51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x74356
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x73c43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x73c3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5df00
leaq -0x60(%rbp), %rdi
callq 0x5df00
leaq -0x48(%rbp), %rdi
callq 0x5df00
jmp 0x74356
movq 0x194910(%rip), %rdi    # 0x208568
xorl %esi, %esi
callq 0x59320
movb %al, -0x2e9(%rbp)
jmp 0x73c67
movb -0x2e9(%rbp), %al
testb $0x1, %al
jne 0x73c76
jmp 0x742aa
leaq 0x1139b9(%rip), %rsi    # 0x187636
leaq -0xc0(%rbp), %rdi
callq 0x5c1f0
jmp 0x73c8b
movq 0x194a16(%rip), %rdi    # 0x2086a8
leaq -0xc0(%rbp), %rsi
callq 0x5bf60
movb %al, -0x2ea(%rbp)
jmp 0x73ca6
movb -0x2ea(%rbp), %al
testb $0x1, %al
jne 0x73cb2
jmp 0x73cc4
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
callq 0x5da90
jmp 0x73cc2
jmp 0x73cd4
leaq -0xa8(%rbp), %rdi
callq 0x5cfc0
jmp 0x73cd2
jmp 0x73cd4
movq 0x1949cd(%rip), %rsi    # 0x2086a8
leaq -0xa8(%rbp), %rdi
callq 0x5a710
movq %rax, -0x2f8(%rbp)
jmp 0x73cf0
leaq 0x11393d(%rip), %rsi    # 0x187634
leaq -0xd8(%rbp), %rdi
callq 0x5c1f0
jmp 0x73d05
leaq 0x11392a(%rip), %rsi    # 0x187636
leaq -0xf0(%rbp), %rdi
callq 0x5c1f0
jmp 0x73d1a
movq -0x2f8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0xf0(%rbp), %rdx
callq 0x5bd30
movq %rax, -0x300(%rbp)
jmp 0x73d3d
movq -0x300(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x5b6d0
jmp 0x73d52
leaq -0xf0(%rbp), %rdi
callq 0x5df00
leaq -0xd8(%rbp), %rdi
callq 0x5df00
leaq -0xa8(%rbp), %rdi
callq 0x5df00
leaq -0xc0(%rbp), %rdi
callq 0x5df00
leaq -0x138(%rbp), %rdi
xorl %esi, %esi
callq 0x5da90
jmp 0x73d92
leaq -0x120(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x138(%rbp), %rdx
callq 0x5acf0
jmp 0x73dae
leaq -0x120(%rbp), %rdi
callq 0x5b4b0
movb %al, -0x301(%rbp)
jmp 0x73dc2
movb -0x301(%rbp), %al
xorb $-0x1, %al
movb %al, -0x302(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x5de78
leaq -0x138(%rbp), %rdi
callq 0x5df00
movb -0x302(%rbp), %al
testb $0x1, %al
jne 0x73df7
jmp 0x74276
leaq 0x132039(%rip), %rdi    # 0x1a5e37
callq 0x5bea0
movq %rax, %rsi
leaq -0x150(%rbp), %rdi
callq 0x5c1f0
jmp 0x73e14
leaq 0x1132b3(%rip), %rsi    # 0x1870ce
leaq -0x1c8(%rbp), %rdi
callq 0x5c1f0
jmp 0x73e29
leaq -0x1b0(%rbp), %rdi
leaq -0x150(%rbp), %rsi
leaq -0x1c8(%rbp), %rdx
callq 0x5c820
jmp 0x73e45
leaq -0x1c8(%rbp), %rdi
callq 0x5df00
leaq -0x1b0(%rbp), %rax
movq %rax, -0x158(%rbp)
movl $0x0, -0x1cc(%rbp)
movl $0xffffffff, -0x1d0(%rbp) # imm = 0xFFFFFFFF
xorl %eax, %eax
cmpl $0x0, -0x1cc(%rbp)
movb %al, -0x303(%rbp)
jne 0x73ebe
movl -0x1d0(%rbp), %eax
movl %eax, -0x30c(%rbp)
movq -0x158(%rbp), %rdi
callq 0x5c990
movl %eax, -0x308(%rbp)
jmp 0x73ea4
movl -0x30c(%rbp), %eax
movl -0x308(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
setl %al
movb %al, -0x303(%rbp)
movb -0x303(%rbp), %al
testb $0x1, %al
jne 0x73ecd
jmp 0x74242
movq -0x158(%rbp), %rdi
movl -0x1d0(%rbp), %esi
incl %esi
movl %esi, -0x1d0(%rbp)
callq 0x74720
movq %rax, -0x318(%rbp)
jmp 0x73ef0
movq -0x318(%rbp), %rax
movq %rax, -0x1d8(%rbp)
cmpl $0x0, -0x1cc(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x73f13
jmp 0x7422c
movq -0x1d8(%rbp), %rsi
leaq -0x220(%rbp), %rdi
callq 0x5b6d0
jmp 0x73f28
leaq 0x113707(%rip), %rsi    # 0x187636
leaq -0x238(%rbp), %rdi
callq 0x5c1f0
jmp 0x73f3d
leaq -0x220(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x5a710
movq %rax, -0x320(%rbp)
jmp 0x73f59
movq -0x320(%rbp), %rdi
movq 0x194741(%rip), %rsi    # 0x2086a8
callq 0x5a710
movq %rax, -0x328(%rbp)
jmp 0x73f75
leaq -0x250(%rbp), %rdi
xorl %esi, %esi
callq 0x5da90
jmp 0x73f85
movq -0x328(%rbp), %rsi
leaq -0x208(%rbp), %rdi
leaq -0x250(%rbp), %rdx
callq 0x5acf0
jmp 0x73fa1
leaq -0x208(%rbp), %rdi
callq 0x5b4b0
movb %al, -0x329(%rbp)
jmp 0x73fb5
leaq -0x208(%rbp), %rdi
callq 0x5de78
leaq -0x250(%rbp), %rdi
callq 0x5df00
leaq -0x238(%rbp), %rdi
callq 0x5df00
leaq -0x220(%rbp), %rdi
callq 0x5df00
movb -0x329(%rbp), %al
testb $0x1, %al
jne 0x73ff4
jmp 0x74216
movq -0x1d8(%rbp), %rsi
leaq -0x268(%rbp), %rdi
callq 0x5b6d0
jmp 0x74009
leaq 0x113626(%rip), %rsi    # 0x187636
leaq -0x280(%rbp), %rdi
callq 0x5c1f0
jmp 0x7401e
leaq -0x268(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x5a710
movq %rax, -0x338(%rbp)
jmp 0x7403a
movq -0x338(%rbp), %rdi
movq 0x194660(%rip), %rsi    # 0x2086a8
callq 0x5a710
movq %rax, -0x340(%rbp)
jmp 0x74056
movq -0x340(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x59760
jmp 0x7406b
leaq -0x280(%rbp), %rdi
callq 0x5df00
leaq -0x268(%rbp), %rdi
callq 0x5df00
jmp 0x7422c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x740e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x740d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x740ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x5df00
leaq -0xd8(%rbp), %rdi
callq 0x5df00
leaq -0xa8(%rbp), %rdi
callq 0x5df00
leaq -0xc0(%rbp), %rdi
callq 0x5df00
jmp 0x74356
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x74299
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x7412a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x5de78
leaq -0x138(%rbp), %rdi
callq 0x5df00
jmp 0x74299
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x74268
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x5df00
jmp 0x74268
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x7425c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x741d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x741c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x741bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x5de78
leaq -0x250(%rbp), %rdi
callq 0x5df00
leaq -0x238(%rbp), %rdi
callq 0x5df00
leaq -0x220(%rbp), %rdi
callq 0x5df00
jmp 0x7425c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x74208
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x5df00
leaq -0x268(%rbp), %rdi
callq 0x5df00
jmp 0x7425c
jmp 0x74218
movl -0x1cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1cc(%rbp)
jmp 0x73efe
jmp 0x7422e
movl -0x1cc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1cc(%rbp)
jmp 0x73e73
leaq -0x1b0(%rbp), %rdi
callq 0x74690
leaq -0x150(%rbp), %rdi
callq 0x5df00
jmp 0x74276
leaq -0x1b0(%rbp), %rdi
callq 0x74690
leaq -0x150(%rbp), %rdi
callq 0x5df00
jmp 0x74299
movq 0x1942eb(%rip), %rdi    # 0x208568
leaq -0x90(%rbp), %rsi
callq 0x59760
jmp 0x7428b
leaq -0x90(%rbp), %rdi
callq 0x5df00
jmp 0x742aa
leaq -0x90(%rbp), %rdi
callq 0x5df00
jmp 0x74356
callq 0x59460
movq %rax, -0x348(%rbp)
jmp 0x742b8
movq -0x348(%rbp), %rsi
leaq -0x298(%rbp), %rdi
callq 0x5c1f0
jmp 0x742cd
movq 0x194294(%rip), %rdi    # 0x208568
leaq -0x298(%rbp), %rsi
callq 0x5d590
movl %eax, -0x34c(%rbp)
jmp 0x742e8
movl -0x34c(%rbp), %esi
incl %esi
movq 0x194271(%rip), %rdi    # 0x208568
callq 0x5d4e0
movq %rax, -0x358(%rbp)
jmp 0x74305
movq -0x358(%rbp), %rax
movl $0x0, (%rax)
leaq -0x298(%rbp), %rdi
callq 0x5df00
movq -0x2a8(%rbp), %rdi
movq 0x19423c(%rip), %rsi    # 0x208568
callq 0x5b6d0
jmp 0x74333
leaq -0x20(%rbp), %rdi
callq 0x65ef0
jmp 0x74361
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x5df00
leaq -0x20(%rbp), %rdi
callq 0x65ef0
jmp 0x74371
movq -0x2a0(%rbp), %rax
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x5b6b0
nopw (%rax,%rax)