// File: wangyufei95[P]watchdog_linux/watchdog.cpp
// Function: PidTracker::findMainPID(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
int PidTracker::findMainPID(const std::string& mainPidFileHint) 
{
	  std::vector<int> candidates;

	  if (!mainPidFileHint.empty()) 
	  {
		std::ifstream ifs(mainPidFileHint);
		std::string pids;
		ifs >> pids;
		printf("PidTracker: main-PID hint: %s\n", pids.c_str());
		int pid = std::stoi(pids);
		if (pid != 0) 
		{
		  return pid;
		}
	  }

	  for (int pid : collectAll()) 
	  {
		if (getppid(pid) == getpid()) 
		{
		  if (getExe(pid) == mainExe_) 
		  {
			candidates.push_back(pid);
		  }
		}
	  }

	  return !candidates.empty() ? candidates.front() : 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x2d0(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x77e0
movq -0x18(%rbp), %rdi
callq 0x36b0
testb $0x1, %al
jne 0x60c7
movq -0x18(%rbp), %rsi
leaq -0x238(%rbp), %rdi
movl $0x8, %edx
callq 0x3650
jmp 0x5fbf
leaq -0x268(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x3560
movq -0x2d8(%rbp), %rsi
leaq -0x238(%rbp), %rdi
callq 0x34e0
jmp 0x5fe7
leaq -0x268(%rbp), %rdi
callq 0x3150
movq %rax, %rsi
leaq 0x61bc(%rip), %rdi      # 0xc1b9
xorl %eax, %eax
callq 0x3050
jmp 0x6006
xorl %eax, %eax
movl %eax, %esi
leaq -0x268(%rbp), %rdi
movl $0xa, %edx
callq 0x7830
movl %eax, -0x2dc(%rbp)
jmp 0x6023
movl -0x2dc(%rbp), %eax
movl %eax, -0x26c(%rbp)
cmpl $0x0, -0x26c(%rbp)
je 0x6093
movl -0x26c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x270(%rbp)
jmp 0x609d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x625a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x3260
leaq -0x238(%rbp), %rdi
callq 0x30b0
jmp 0x625a
movl $0x0, -0x270(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x3260
leaq -0x238(%rbp), %rdi
callq 0x30b0
movl -0x270(%rbp), %eax
testl %eax, %eax
jne 0x6245
jmp 0x60c5
jmp 0x60c7
movq -0x2d0(%rbp), %rsi
leaq -0x290(%rbp), %rdi
callq 0x5dd0
jmp 0x60dc
leaq -0x290(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rdi
callq 0x78d0
movq %rax, -0x298(%rbp)
movq -0x278(%rbp), %rdi
callq 0x7900
movq %rax, -0x2a0(%rbp)
leaq -0x298(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x7930
testb $0x1, %al
jne 0x6142
movl $0x2, -0x270(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x7870
jmp 0x6208
leaq -0x298(%rbp), %rdi
callq 0x7970
movl (%rax), %eax
movl %eax, -0x2a4(%rbp)
movl -0x2a4(%rbp), %edi
callq 0x6270
movl %eax, -0x2e0(%rbp)
jmp 0x6169
callq 0x35e0
movl %eax, %ecx
movl -0x2e0(%rbp), %eax
cmpl %ecx, %eax
jne 0x61f5
movl -0x2a4(%rbp), %esi
leaq -0x2c8(%rbp), %rdi
callq 0x62f0
jmp 0x618e
movq -0x2d0(%rbp), %rsi
leaq -0x2c8(%rbp), %rdi
callq 0x7990
movb %al, -0x2e1(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x3260
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x61bf
jmp 0x61f3
leaq -0x30(%rbp), %rdi
leaq -0x2a4(%rbp), %rsi
callq 0x7a20
jmp 0x61d1
jmp 0x61f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x7870
jmp 0x625a
jmp 0x61f5
jmp 0x61f7
leaq -0x298(%rbp), %rdi
callq 0x7a90
jmp 0x6110
leaq -0x30(%rbp), %rdi
callq 0x7ab0
testb $0x1, %al
jne 0x6228
leaq -0x30(%rbp), %rdi
callq 0x7af0
movl (%rax), %eax
movl %eax, -0x2e8(%rbp)
jmp 0x6232
xorl %eax, %eax
movl %eax, -0x2e8(%rbp)
jmp 0x6232
movl -0x2e8(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x270(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x7870
movl -0x4(%rbp), %eax
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x7870
movq -0x240(%rbp), %rdi
callq 0x36e0
nop