// File: /workspace/github_cpp_makefile_star2_O2/jstaursky[P]hutch/src/Sleigh/filemanage.cc
// Function: FileManage::discoverGhidraRoot[abi:cxx11](char const*)
string FileManage::discoverGhidraRoot(const char *argv0)

{ // Find the root of the ghidra distribution based on current working directory and passed in path
  vector<string> pathels;
  string cur(argv0);
  string base;
  int skiplevel = 0;
  bool isAbs = isAbsolutePath(cur);

  for(;;) {
    int sizebefore = cur.size();
    splitPath(cur,cur,base);
    if (cur.size() == sizebefore) break;
    if (base == ".")
      skiplevel += 1;
    else if (base == "..")
      skiplevel += 2;
    if (skiplevel > 0)
      skiplevel -= 1;
    else
      pathels.push_back(base);
  }
  if (!isAbs) {
    FileManage curdir;
    curdir.addCurrentDir();
    cur = curdir.pathlist[0];
    for(;;) {
      int sizebefore = cur.size();
      splitPath(cur,cur,base);
      if (cur.size() == sizebefore) break;
      pathels.push_back(base);
    }
  }

  for(int i=0;i<pathels.size();++i) {
    if (pathels[i] != "Ghidra") continue;
    string root;
    if (testDevelopmentPath(pathels,i,root))
      return root;
    if (testInstallPath(pathels,i,root))
      return root;
  }
  return "";
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x515e0
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x28(%rsp), %rbp
xorl %r13d, %r13d
testq %rbp, %rbp
je 0x5e215
movq 0x20(%rsp), %rax
movb (%rax), %al
movq 0x50dbf(%rip), %rcx     # 0xaefc8
cmpb (%rcx), %al
sete %al
movq %rax, 0x18(%rsp)
jmp 0x5e21e
movq $0x0, 0x18(%rsp)
leaq 0x20(%rsp), %r14
leaq 0x58(%rsp), %r15
leaq 0x28b61(%rip), %r12     # 0x86d90
movq %r14, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4e550
movslq %ebp, %rax
cmpq %rax, 0x28(%rsp)
je 0x5e293
movq %r15, %rdi
movq %r12, %rsi
callq 0x520f0
testb %al, %al
je 0x5e25b
incl %r13d
jmp 0x5e277
movq %r15, %rdi
leaq 0x28b2a(%rip), %rsi     # 0x86d8f
callq 0x520f0
leal 0x2(%r13), %ecx
testb %al, %al
cmovel %r13d, %ecx
movl %ecx, %r13d
testl %r13d, %r13d
jle 0x5e281
decl %r13d
jmp 0x5e28c
movq %rsp, %rdi
movq %r15, %rsi
callq 0x4e310
movq 0x28(%rsp), %rbp
jmp 0x5e22f
cmpb $0x0, 0x18(%rsp)
jne 0x5e2ff
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
callq 0x4e370
movq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x4e400
leaq 0x20(%rsp), %r14
leaq 0x58(%rsp), %r15
movq %rsp, %r12
movq 0x28(%rsp), %r13
movq %r14, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4e550
movslq %r13d, %rax
cmpq %rax, 0x28(%rsp)
je 0x5e2f5
movq %r12, %rdi
movq %r15, %rsi
callq 0x4e310
jmp 0x5e2cb
leaq 0x40(%rsp), %rdi
callq 0x4ea80
leaq 0x10(%rbx), %r13
xorl %ebp, %ebp
leaq 0x28a99(%rip), %r14     # 0x86da5
movq %rsp, %r15
xorl %r12d, %r12d
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %r12, %rax
jbe 0x5e377
addq %rbp, %rdi
movq %r14, %rsi
callq 0x4ee50
testb %al, %al
jne 0x5e36e
movq %r13, (%rbx)
andq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
movq %r15, %rdi
movl %r12d, %esi
movq %rbx, %rdx
callq 0x509b0
testb %al, %al
jne 0x5e38b
movq %r15, %rdi
movl %r12d, %esi
movq %rbx, %rdx
callq 0x502e0
testb %al, %al
jne 0x5e38b
movq %rbx, %rdi
callq 0x4e020
incq %r12
addq $0x20, %rbp
jmp 0x5e312
leaq 0x29e42(%rip), %rsi     # 0x881c0
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x515e0
leaq 0x58(%rsp), %rdi
callq 0x4e020
leaq 0x20(%rsp), %rdi
callq 0x4e020
movq %rsp, %rdi
callq 0x4ea80
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5e3e0
jmp 0x5e3d1
movq %rax, %r14
jmp 0x5e3f7
movq %rax, %r14
movq %rbx, %rdi
callq 0x4e020
jmp 0x5e3e3
jmp 0x5e3e0
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x4ea80
jmp 0x5e3e3
movq %rax, %r14
leaq 0x58(%rsp), %rdi
callq 0x4e020
leaq 0x20(%rsp), %rdi
callq 0x4e020
movq %rsp, %rdi
callq 0x4ea80
movq %r14, %rdi
callq 0x518c0
nop