#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *parse_proc(char *, char *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
float memory_percentage(char *path, long totalmem) {
  float total_usage, total_mem_percent;
  char *percentage = parse_proc(path, "VmSize:\t");
  if (percentage != NULL) {
    total_usage = (float)strtol(percentage, NULL, 10);
    free(percentage);
    total_mem_percent = (total_usage / totalmem) * 100;
  } else
    total_mem_percent = 0.0;
  return total_mem_percent;
}


x86 assembly (clang, -O0):
<memory_percentage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <parse_proc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a9 <memory_percentage+0x79>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movss  -0x14(%rbp),%xmm0
cvtsi2ssq -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  0xe65(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    11b1 <memory_percentage+0x81>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory_percentage>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xec6(%rip),%rsi
call   1050 <parse_proc@plt>
test   %rax,%rax
je     118c <memory_percentage+0x5c>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,0x4(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %r14,%xmm0
movss  0x4(%rsp),%xmm1
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
mulss  0xe76(%rip),%xmm0
jmp    118f <memory_percentage+0x5f>
xorps  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"VmSize:\09\00"
define float @memory_percentage(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca float
%6 = alloca float
%7 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = load i8*, i8** %3
%9 = call i8* @parse_proc(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = load i8*, i8** %7
%14 = call i64 @strtol(i8* %13, i32* null, i32 10)
%15 = sitofp i64 %14 to float
store float %15, float* %5
%16 = load i8*, i8** %7
%17 = call i32 @free(i8* %16)
%18 = load float, float* %5
%19 = load i64, i64* %4
%20 = sitofp i64 %19 to float
%21 = fdiv float %18, %20
%22 = fmul float %21, 1.000000e+02
store float %22, float* %6
br label %24
23: ; preds = %2
store float 0.000000e+00, float* %6
br label %24
24: ; preds = %23, %12
%25 = load float, float* %6
ret float %25
}

LLVM IR (-O2):
@.str = [9 x i8] c"VmSize:\09\00"
define float @memory_percentage(i8* %0, i64 %1) {
%3 = tail call i8* @parse_proc(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = tail call i64 @strtol(i8* nocapture %3, i32* null, i32 10)
%7 = sitofp i64 %6 to float
%8 = tail call i32 @free(i8* %3)
%9 = sitofp i64 %1 to float
%10 = fdiv float %7, %9
%11 = fmul float %10, 1.000000e+02
br label %12
12: ; preds = %2, %5
%13 = phi float [ %11, %5 ], [ 0.000000e+00, %2 ]
ret float %13
}