// File: /workspace/github_cpp_makefile_star2_O3/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 $0x88, %rsp
movq %rdi, 0x48(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x41d40
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x28(%rsp), %rbx
xorl %r13d, %r13d
testq %rbx, %rbx
je 0x513ea
movq 0x20(%rsp), %rax
movb (%rax), %al
movq 0x51bf2(%rip), %rcx     # 0xa2fd0
cmpb (%rcx), %al
sete %al
movq %rax, 0x40(%rsp)
jmp 0x513f3
movq $0x0, 0x40(%rsp)
leaq 0x20(%rsp), %r14
leaq 0x50(%rsp), %r15
leaq 0x2e9ac(%rip), %r12     # 0x7fdb0
leaq 0x2e9a4(%rip), %rbp     # 0x7fdaf
movq %r14, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3fd20
movslq %ebx, %rax
cmpq %rax, 0x28(%rsp)
je 0x5146b
movq %r15, %rdi
movq %r12, %rsi
callq 0x3f590
testl %eax, %eax
je 0x5144c
movq %r15, %rdi
movq %rbp, %rsi
callq 0x3f590
leal 0x2(%r13), %ecx
testl %eax, %eax
cmovnel %r13d, %ecx
movl %ecx, %r13d
jmp 0x5144f
incl %r13d
testl %r13d, %r13d
jle 0x51459
decl %r13d
jmp 0x51464
movq %rsp, %rdi
movq %r15, %rsi
callq 0x3fbc0
movq 0x28(%rsp), %rbx
jmp 0x5140b
cmpb $0x0, 0x40(%rsp)
movq 0x48(%rsp), %rbx
jne 0x514e4
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x3fbe0
movq 0x70(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x3fc60
leaq 0x20(%rsp), %r14
leaq 0x50(%rsp), %r15
movq %rsp, %r12
movq 0x28(%rsp), %rbx
movq %r14, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3fd20
movslq %ebx, %rax
cmpq %rax, 0x28(%rsp)
je 0x514d5
movq %r12, %rdi
movq %r15, %rsi
callq 0x3fbc0
jmp 0x514ab
leaq 0x70(%rsp), %rdi
callq 0x400a0
movq 0x48(%rsp), %rbx
movq (%rsp), %rdi
cmpq %rdi, 0x8(%rsp)
je 0x51578
leaq 0x10(%rbx), %r13
xorl %ebp, %ebp
leaq 0x2e8c5(%rip), %r14     # 0x7fdc5
movq %rsp, %r15
xorl %r12d, %r12d
addq %rbp, %rdi
movq %r14, %rsi
callq 0x3f590
testl %eax, %eax
jne 0x5155c
movq %r13, (%rbx)
movq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
movq %r15, %rdi
movl %r12d, %esi
movq %rbx, %rdx
callq 0x414d0
testb %al, %al
jne 0x51591
movq %r15, %rdi
movl %r12d, %esi
movq %rbx, %rdx
callq 0x40ff0
testb %al, %al
jne 0x51591
movq (%rbx), %rdi
cmpq %r13, %rdi
je 0x5155c
movq (%r13), %rsi
incq %rsi
callq 0x40880
incq %r12
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %rbp
cmpq %r12, %rax
ja 0x51506
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x2fc6a(%rip), %rdx     # 0x811f0
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x3f8a0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x515ad
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x40880
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x515c8
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x40880
movq %rsp, %rdi
callq 0x400a0
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x51616
jmp 0x51607
movq %rax, %r14
jmp 0x51650
movq %rax, %r14
movq (%rbx), %rdi
cmpq %r13, %rdi
je 0x51619
movq (%r13), %rsi
incq %rsi
callq 0x40880
jmp 0x51619
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x400a0
jmp 0x51619
movq %rax, %r14
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x51635
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x40880
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x51650
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x40880
movq %rsp, %rdi
callq 0x400a0
movq %r14, %rdi
callq 0x41f10