// File: JenTus[P]TCEM/src_TCEM/utils.cc
// Function: getCurrentMemoryUsage()
float getCurrentMemoryUsage() { //megabyte verii
	string pid = intToStr(unsigned(getpid()));
	string outfile = "temp/tmp_" + pid + ".txt";
	string command = "pmap " + pid + " | grep -i Total | awk '{print $2}' > " + outfile;	
	system(command.c_str());
	
	string mem_str;
	ifstream ifs(outfile.c_str());
	std::getline(ifs, mem_str);
	ifs.close();
	
	mem_str = mem_str.substr(0, mem_str.size()-1);
	float mem = (float)strToInt(mem_str);
	
	return mem/1024; // in MB
}

// Assembly:
subq $0x378, %rsp            # imm = 0x378
callq 0x4540
movl %eax, %esi
leaq 0x358(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x1c800
movq 0x30(%rsp), %rdx
leaq 0x87f4(%rip), %rsi      # 0x24660
leaq 0x318(%rsp), %rdi
callq 0x1c890
jmp 0x1be7b
leaq 0x85a5(%rip), %rdx      # 0x24427
leaq 0x338(%rsp), %rdi
leaq 0x318(%rsp), %rsi
callq 0xf440
jmp 0x1be99
leaq 0x318(%rsp), %rdi
callq 0x41f0
leaq 0x87bd(%rip), %rsi      # 0x2466a
leaq 0x2a8(%rsp), %rdi
leaq 0x358(%rsp), %rdx
callq 0x1c890
jmp 0x1bec4
leaq 0x87a5(%rip), %rdx      # 0x24670
leaq 0x2c8(%rsp), %rdi
leaq 0x2a8(%rsp), %rsi
callq 0xf440
jmp 0x1bee2
leaq 0x2e8(%rsp), %rdi
leaq 0x2c8(%rsp), %rsi
leaq 0x338(%rsp), %rdx
callq 0xf3f0
jmp 0x1bf01
leaq 0x2c8(%rsp), %rdi
callq 0x41f0
leaq 0x2a8(%rsp), %rdi
callq 0x41f0
leaq 0x2e8(%rsp), %rdi
callq 0x4130
movq %rax, %rdi
callq 0x42f0
jmp 0x1bf32
leaq 0x288(%rsp), %rdi
callq 0x4500
leaq 0x338(%rsp), %rdi
callq 0x4130
movq %rax, %rsi
leaq 0x80(%rsp), %rdi
movl $0x8, %edx
callq 0x46b0
jmp 0x1bf63
leaq 0x80(%rsp), %rdi
leaq 0x288(%rsp), %rsi
callq 0x40a0
jmp 0x1bf7a
leaq 0x80(%rsp), %rdi
callq 0x40b0
jmp 0x1bf89
leaq 0x288(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x4250
movq 0x28(%rsp), %rsi
movq %rax, %rcx
decq %rcx
xorl %eax, %eax
movl %eax, %edx
leaq 0x60(%rsp), %rdi
callq 0x43a0
jmp 0x1bfb6
leaq 0x288(%rsp), %rdi
movq %rdi, 0x20(%rsp)
leaq 0x60(%rsp), %rsi
movq %rsi, 0x18(%rsp)
callq 0x4450
movq 0x18(%rsp), %rdi
callq 0x41f0
movq 0x20(%rsp), %rsi
leaq 0x38(%rsp), %rdi
callq 0x4140
jmp 0x1bfed
leaq 0x38(%rsp), %rdi
callq 0xf1f0
movl %eax, 0x14(%rsp)
jmp 0x1bffd
movl 0x14(%rsp), %eax
movl %eax, %eax
cvtsi2ss %rax, %xmm0
movss %xmm0, 0xc(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x41f0
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x5c(%rsp)
movss 0x5c(%rsp), %xmm0
movss 0x862a(%rip), %xmm1     # 0x2465c
divss %xmm1, %xmm0
movss %xmm0, 0x10(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x40d0
leaq 0x288(%rsp), %rdi
callq 0x41f0
leaq 0x2e8(%rsp), %rdi
callq 0x41f0
leaq 0x338(%rsp), %rdi
callq 0x41f0
leaq 0x358(%rsp), %rdi
callq 0x41f0
movss 0x10(%rsp), %xmm0
addq $0x378, %rsp            # imm = 0x378
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x310(%rsp)
movl %eax, 0x30c(%rsp)
jmp 0x1c1c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x310(%rsp)
movl %eax, 0x30c(%rsp)
leaq 0x318(%rsp), %rdi
callq 0x41f0
jmp 0x1c1c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x310(%rsp)
movl %eax, 0x30c(%rsp)
jmp 0x1c1b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x310(%rsp)
movl %eax, 0x30c(%rsp)
jmp 0x1c11a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x310(%rsp)
movl %eax, 0x30c(%rsp)
leaq 0x2c8(%rsp), %rdi
callq 0x41f0
leaq 0x2a8(%rsp), %rdi
callq 0x41f0
jmp 0x1c1b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x310(%rsp)
movl %eax, 0x30c(%rsp)
jmp 0x1c1a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x310(%rsp)
movl %eax, 0x30c(%rsp)
jmp 0x1c199
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x310(%rsp)
movl %eax, 0x30c(%rsp)
jmp 0x1c18c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x310(%rsp)
movl %eax, 0x30c(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x41f0
leaq 0x80(%rsp), %rdi
callq 0x40d0
leaq 0x288(%rsp), %rdi
callq 0x41f0
leaq 0x2e8(%rsp), %rdi
callq 0x41f0
leaq 0x338(%rsp), %rdi
callq 0x41f0
leaq 0x358(%rsp), %rdi
callq 0x41f0
movq 0x310(%rsp), %rdi
callq 0x4680
nopw (%rax,%rax)