// File: 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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x9606(%rip), %rdi      # 0x12510
leaq 0x986c(%rip), %rsi      # 0x1277d
callq 0x50e0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x8f49
leaq 0xf4f4(%rip), %rax      # 0x1841c
cmpl $0x1, (%rax)
jle 0x8f40
movq 0xf07c(%rip), %rdi      # 0x17fb0
leaq 0x95fd(%rip), %rsi      # 0x12538
callq 0x5380
movb $0x0, -0x1(%rbp)
jmp 0x91b8
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rdx
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x5520
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5590
cmpl $-0x1, -0x34(%rbp)
je 0x8f83
cmpq $0x3, -0x30(%rbp)
jae 0x8ffb
leaq 0xf492(%rip), %rax      # 0x1841c
cmpl $0x1, (%rax)
jle 0x8ff2
movq 0xf01a(%rip), %rdi      # 0x17fb0
leaq 0x95c7(%rip), %rsi      # 0x12564
callq 0x5380
movq %rax, %rdi
movl -0x34(%rbp), %esi
callq 0x5690
movq %rax, %rdi
leaq 0x95c8(%rip), %rsi      # 0x1257f
callq 0x5380
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x5080
movq %rax, %rdi
leaq 0x95b6(%rip), %rsi      # 0x12588
callq 0x5380
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x5380
movq %rax, %rdi
leaq 0x97e1(%rip), %rsi      # 0x127ce
callq 0x5380
movb $0x0, -0x1(%rbp)
jmp 0x91b8
movq -0x28(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x56c0
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x7600
jmp 0x902f
leaq -0x59(%rbp), %rdi
callq 0x53f0
leaq -0x58(%rbp), %rdi
leaq 0x9550(%rip), %rsi      # 0x12593
xorl %eax, %eax
movl %eax, %edx
callq 0x5790
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0xcc(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x55e0
movq %rax, %rcx
movl -0xcc(%rbp), %eax
cmpl %ecx, %eax
jle 0x9112
leaq 0xf3a3(%rip), %rax      # 0x1841c
cmpl $0x1, (%rax)
jle 0x9102
movq 0xef27(%rip), %rdi      # 0x17fb0
leaq 0x9505(%rip), %rsi      # 0x12595
callq 0x5380
movq %rax, -0xd8(%rbp)
jmp 0x909e
movq -0xd8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x5380
movq %rax, -0xe0(%rbp)
jmp 0x90b7
movq -0xe0(%rbp), %rdi
leaq 0x9709(%rip), %rsi      # 0x127ce
callq 0x5380
jmp 0x90cc
jmp 0x9102
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x53f0
jmp 0x91c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5230
jmp 0x91c6
movb $0x0, -0x1(%rbp)
movl $0x1, -0x74(%rbp)
jmp 0x91af
movslq -0x70(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x98(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x53c0
jmp 0x912c
leaq -0x98(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x5170
movq %rax, %rdi
callq 0x5610
movq -0xe8(%rbp), %rdi
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
callq 0x5230
movl -0x70(%rbp), %eax
incl %eax
movslq %eax, %rdx
leaq -0xb8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movq $-0x1, %rcx
callq 0x53c0
jmp 0x917c
leaq -0xb8(%rbp), %rdi
callq 0x5170
movq %rax, %rdi
callq 0x5610
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
leaq -0xb8(%rbp), %rdi
callq 0x5230
movb $0x1, -0x1(%rbp)
movl $0x1, -0x74(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5230
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xf0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x56b0
nop