// File: /workspace/github_cpp_makefile_star2_O1/merelin[P]mediasmartserverd/src/update_monitor.cpp
// Function: UpdateMonitor::GetUpdateStatus(int*, int*)
bool UpdateMonitor::GetUpdateStatus(int* update_count, int* security_update_count)
{
	//For some reason stderr has the result not stdout so we redirect it to stdout.
	FILE* apt_check = popen("/usr/lib/update-notifier/apt-check 2>&1", "r");
	if (apt_check == NULL)
	{
		if (verbose > 1)
		{
			std::cout << "apt-check does not exist or can't be read.\n";
		}
		return false;
	}
	char* line = NULL;
	size_t len = 0;
	int res = getline(&line, &len, apt_check);
	pclose(apt_check);
	if (res == -1 || len < 3)
	{
		if (verbose > 1)
		{
			std::cout << "Couldn't read line. res = " << res << "; len = " << len
				<< "; line = \"" << line << "\"\n";
		}
		return false;
	}
	std::string str_line(line);
	int pos_delim = str_line.find(";");
	if (pos_delim > (int)str_line.length())
	{
		if (verbose > 1)
		{
			std::cout << "Couldn't find seperator ; in apt-check string: \""
				<< line << "\"\n";
		}
		return false;
	}
	*update_count = atoi(str_line.substr(0, pos_delim).c_str());
	*security_update_count = atoi(str_line.substr(pos_delim+1).c_str());
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x4e22(%rip), %rdi      # 0xb529
leaq 0x4fab(%rip), %rsi      # 0xb6b9
callq 0x40a0
testq %rax, %rax
je 0x682f
movq %rax, %r12
xorl %eax, %eax
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq %r12, %rdx
callq 0x43c0
movq %rax, %rbx
movq %r12, %rdi
callq 0x4400
cmpl $-0x1, %ebx
je 0x6857
cmpq $0x2, 0x10(%rsp)
jbe 0x6857
movq 0x8(%rsp), %rsi
leaq 0x38(%rsp), %rbx
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
callq 0x5baa
leaq 0x4e35(%rip), %rsi      # 0xb5ac
movl $0x1, %ecx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4540
movq %rax, %r12
cmpl 0x8(%rbx), %r12d
setle %bl
jg 0x68e9
movslq %r12d, %rcx
leaq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0x42d0
shlq $0x20, %r12
leaq 0x28(%rsp), %rbp
movq -0x10(%rbp), %r13
movq %r13, %rdi
callq 0x44a0
movl %eax, (%r15)
cmpq %rbp, %r13
je 0x67d7
movq 0x28(%rsp), %rsi
incq %rsi
movq %r13, %rdi
callq 0x42c0
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r12
sarq $0x20, %r12
leaq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movq %r12, %rdx
movq $-0x1, %rcx
callq 0x42d0
movq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x44a0
movl %eax, (%r14)
cmpq %rbp, %r15
je 0x699b
movq 0x28(%rsp), %rsi
incq %rsi
movq %r15, %rdi
callq 0x42c0
jmp 0x699b
leaq 0x9b1e(%rip), %rax      # 0x10354
cmpl $0x2, (%rax)
jl 0x6967
movq 0x976a(%rip), %rdi      # 0xffb0
leaq 0x4d04(%rip), %rsi      # 0xb551
movl $0x2b, %edx
jmp 0x6962
leaq 0x9af6(%rip), %rax      # 0x10354
cmpl $0x2, (%rax)
jl 0x6967
movq 0x9742(%rip), %r14      # 0xffb0
leaq 0x4d08(%rip), %rsi      # 0xb57d
movl $0x1a, %edx
movq %r14, %rdi
callq 0x4310
movq %r14, %rdi
movl %ebx, %esi
callq 0x4530
movq %rax, %rbx
leaq 0x4d02(%rip), %rsi      # 0xb598
movl $0x8, %edx
movq %rax, %rdi
callq 0x4310
movq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x41a0
movq %rax, %rbx
leaq 0x4ce7(%rip), %rsi      # 0xb5a1
movl $0xa, %edx
movq %rax, %rdi
callq 0x4310
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x693a
movq %r14, %rdi
callq 0x4130
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x4310
jmp 0x6953
leaq 0x9a64(%rip), %rax      # 0x10354
cmpl $0x2, (%rax)
jl 0x699b
movq 0x96b0(%rip), %r14      # 0xffb0
leaq 0x4ca7(%rip), %rsi      # 0xb5ae
movl $0x30, %edx
movq %r14, %rdi
callq 0x4310
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x696b
movq %r15, %rdi
callq 0x4130
movq 0x9683(%rip), %rdi      # 0xffb0
movq %r15, %rsi
movq %rax, %rdx
callq 0x4310
jmp 0x6983
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %rbx, %rdi
addq %rax, %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x4510
leaq 0x4db0(%rip), %rsi      # 0xb70a
movl $0x2, %edx
movq %rbx, %rdi
callq 0x4310
xorl %ebx, %ebx
jmp 0x69b6
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x4510
movq 0x9626(%rip), %rdi      # 0xffb0
leaq 0x4d79(%rip), %rsi      # 0xb70a
movl $0x2, %edx
callq 0x4310
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x69b6
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x42c0
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x69cb
jmp 0x69cb
movq %rax, %rbx
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x69e9
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x42c0
movq %rbx, %rdi
callq 0x4550
nop