// File: /workspace/github_cpp_makefile_star2_O1/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)
movq $0x0, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x41d30
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %r13d, %r13d
cmpq $0x0, 0x20(%rsp)
je 0x5150f
movq 0x18(%rsp), %rax
movb (%rax), %al
movq 0x51acd(%rip), %rcx     # 0xa2fd0
cmpb (%rcx), %al
sete %al
movq %rax, 0x38(%rsp)
jmp 0x51518
movq $0x0, 0x38(%rsp)
leaq 0x18(%rsp), %r14
leaq 0x40(%rsp), %r15
movq 0x20(%rsp), %r12
movq %r14, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3fd20
movq 0x20(%rsp), %rbp
movslq %r12d, %r12
cmpq %r12, %rbp
je 0x5158b
movq %r15, %rdi
leaq 0x2e864(%rip), %rsi     # 0x7fdb0
callq 0x3f590
testl %eax, %eax
je 0x51573
movq %r15, %rdi
leaq 0x2e850(%rip), %rsi     # 0x7fdaf
callq 0x3f590
leal 0x2(%r13), %ecx
testl %eax, %eax
cmovnel %r13d, %ecx
movl %ecx, %r13d
jmp 0x51576
incl %r13d
testl %r13d, %r13d
jle 0x51580
decl %r13d
jmp 0x5158b
movq %rsp, %rdi
movq %r15, %rsi
callq 0x3fbc0
cmpq %r12, %rbp
jne 0x51522
cmpb $0x0, 0x38(%rsp)
jne 0x51605
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x3fbe0
movq 0x60(%rsp), %rsi
leaq 0x18(%rsp), %rdi
callq 0x3fc60
leaq 0x18(%rsp), %r14
leaq 0x40(%rsp), %r15
movq %rsp, %r12
movq 0x20(%rsp), %rbp
movq %r14, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3fd20
movq 0x20(%rsp), %r13
movslq %ebp, %rbp
cmpq %rbp, %r13
je 0x515fb
movq %r12, %rdi
movq %r15, %rsi
callq 0x3fbc0
cmpq %rbp, %r13
jne 0x515cb
leaq 0x60(%rsp), %rdi
callq 0x40090
movq (%rsp), %rdi
cmpq %rdi, 0x8(%rsp)
je 0x516ad
leaq 0x10(%rbx), %r13
xorl %ebp, %ebp
leaq 0x2e7a4(%rip), %r14     # 0x7fdc5
xorl %r12d, %r12d
addq %rbp, %rdi
movq %r14, %rsi
callq 0x3f590
testl %eax, %eax
jne 0x5168d
movq %r13, (%rbx)
movq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
movq %rsp, %rdi
movl %r12d, %esi
movq %rbx, %rdx
callq 0x414c0
testb %al, %al
je 0x5165b
movb $0x1, %al
xorl %r15d, %r15d
jmp 0x51670
movq %rsp, %rdi
movl %r12d, %esi
movq %rbx, %rdx
callq 0x40fe0
movl %eax, %r15d
xorb $0x1, %r15b
testb %al, %al
jne 0x51688
movq (%rbx), %rdi
cmpq %r13, %rdi
je 0x51688
movq (%r13), %rsi
incq %rsi
callq 0x40870
testb %r15b, %r15b
je 0x516c6
incq %r12
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %rbp
cmpq %r12, %rax
ja 0x51624
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x2fb35(%rip), %rdx     # 0x811f0
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x3f8a0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x516e2
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x40870
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x516fd
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x40870
movq %rsp, %rdi
callq 0x40090
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x51748
jmp 0x51739
movq %rax, %r14
jmp 0x51782
movq %rax, %r14
movq (%rbx), %rdi
cmpq %r13, %rdi
je 0x5174b
movq (%r13), %rsi
incq %rsi
callq 0x40870
jmp 0x5174b
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x40090
jmp 0x5174b
movq %rax, %r14
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x51767
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x40870
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x51782
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x40870
movq %rsp, %rdi
callq 0x40090
movq %r14, %rdi
callq 0x41f00