#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 */
struct sysinfo {
  int totalram;
  int mem_unit;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned long *,
                          unsigned long *, unsigned long *, unsigned long *,
                          unsigned long *, unsigned long *, unsigned long *);
unsigned long getpagesize();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
scalar_t__ sysinfo(struct sysinfo *);
int CheckUsage(const char *filename) {
  struct sysinfo info;
  if (sysinfo(&info) != 0)
    perror("Sysinfo\n");
  unsigned long TotalRam = 0;
  TotalRam = (info.totalram * info.mem_unit) / 1024;
  printf("%10s %12s %13s", "Total Ram", "Application", "Percentage\n");
  while (1) {
    FILE *FP;
    FP = fopen(filename, "r");
    if (FP == NULL) {
      fprintf(stderr, "Application close or File '%s' does not exists\n",
              filename);
      return 1;
    }
    unsigned long size = 0;
    unsigned long resident = 0;
    unsigned long share = 0;
    unsigned long text = 0;
    unsigned long lib = 0;
    unsigned long data = 0;
    unsigned long dt = 0;
    fscanf(FP, "%lu %lu %lu %lu %lu %lu %lu", &size, &resident, &share, &text,
           &lib, &data, &dt);
    unsigned long TotalUsage = (resident * getpagesize());
    float Percentage = 0.0f;
    Percentage = (float)(((float)TotalUsage / 1024) / (float)TotalRam) * 100;
    printf("%10lukB %10lukB %10.3f%%\n", TotalRam, TotalUsage / 1024,
           Percentage);
    fclose(FP);
    sleep(1);
  }
  return 1;
}


x86 assembly (clang, -O0):
<CheckUsage>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1090 <sysinfo@plt>
cmp    $0x0,%rax
je     11be <CheckUsage+0x2e>
lea    0xe4f(%rip),%rdi
call   1080 <perror@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x18(%rbp)
lea    0xe2f(%rip),%rdi
lea    0xe37(%rip),%rsi
lea    0xe3a(%rip),%rdx
lea    0xe3f(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1244 <CheckUsage+0xb4>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe13(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0xa0,%rsp
pop    %rbp
ret
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
mov    %rsp,%rax
lea    -0x58(%rbp),%rcx
mov    %rcx,0x10(%rax)
lea    -0x50(%rbp),%rcx
mov    %rcx,0x8(%rax)
lea    -0x48(%rbp),%rcx
mov    %rcx,(%rax)
lea    0xdd3(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
lea    -0x40(%rbp),%r9
call   1050 <fscanf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x78(%rbp)
xor    %eax,%eax
call   10a0 <getpagesize@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
imul   %rcx,%rax
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x6c(%rbp)
test   %rax,%rax
movss  %xmm0,-0x68(%rbp)
js     1318 <CheckUsage+0x188>
movss  -0x6c(%rbp),%xmm0
movss  %xmm0,-0x68(%rbp)
movss  -0x68(%rbp),%xmm0
movss  0xcdf(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x84(%rbp)
ff
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x80(%rbp)
test   %rax,%rax
movss  %xmm0,-0x7c(%rbp)
js     136e <CheckUsage+0x1de>
movss  -0x80(%rbp),%xmm0
movss  %xmm0,-0x7c(%rbp)
movss  -0x84(%rbp),%xmm0
ff
movss  -0x7c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  0xc79(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x64(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x60(%rbp),%rdx
shr    $0xa,%rdx
movss  -0x64(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xce4(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
jmp    11fe <CheckUsage+0x6e>

x86 assembly (clang, -O2):
<CheckUsage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%r14
lea    0x10(%rsp),%rdi
call   1090 <sysinfo@plt>
test   %rax,%rax
jne    138f <CheckUsage+0x1ff>
mov    0x14(%rsp),%eax
imul   0x10(%rsp),%eax
lea    0x3ff(%rax),%ebp
test   %eax,%eax
cmovns %eax,%ebp
lea    0xe42(%rip),%rdi
lea    0xe4a(%rip),%rsi
lea    0xe4d(%rip),%rdx
lea    0xe52(%rip),%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe50(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1363 <CheckUsage+0x1d3>
mov    %rax,%rbx
sar    $0xa,%ebp
movslq %ebp,%r15
test   %r15,%r15
js     1217 <CheckUsage+0x87>
cvtsi2ss %ebp,%xmm0
jmp    122f <CheckUsage+0x9f>
mov    %r15,%rax
shr    %rax
mov    %r15d,%ecx
and    $0x1,%ecx
or     %rax,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
lea    0xe54(%rip),%rbp
lea    0xdff(%rip),%r12
jmp    12af <CheckUsage+0x11f>
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mulss  0xda0(%rip),%xmm0
divss  0x4(%rsp),%xmm0
mulss  0xd96(%rip),%xmm0
shr    $0xa,%rax
cvtss2sd %xmm0,%xmm0
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
mov    $0x1,%al
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1363 <CheckUsage+0x1d3>
movq   $0x0,0x40(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x38(%rsp)
movq   $0x0,0x30(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x20(%rsp)
movq   $0x0,0x18(%rsp)
sub    $0x8,%rsp
mov    %rbx,%rdi
lea    0xd78(%rip),%rsi
lea    0x48(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x40(%rsp),%r8
lea    0x38(%rsp),%r9
lea    0x20(%rsp),%rax
push   %rax
lea    0x30(%rsp),%rax
push   %rax
lea    0x40(%rsp),%rax
push   %rax
call   1050 <fscanf@plt>
add    $0x20,%rsp
mov    0x8(%rsp),%r13
xor    %eax,%eax
call   10a0 <getpagesize@plt>
imul   %r13,%rax
test   %rax,%rax
jns    1250 <CheckUsage+0xc0>
mov    %rax,%rcx
shr    %rcx
mov    %eax,%edx
and    $0x1,%edx
or     %rcx,%rdx
xorps  %xmm0,%xmm0
cvtsi2ss %rdx,%xmm0
addss  %xmm0,%xmm0
jmp    1258 <CheckUsage+0xc8>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
lea    0xcd1(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc72(%rip),%rdi
call   1080 <perror@plt>
jmp    11b4 <CheckUsage+0x24>

LLVM IR (-O0):
%struct.sysinfo = type { i32, i32 }
@.str = [9 x i8] c"Sysinfo\0A\00"
@.str.1 = [15 x i8] c"%10s %12s %13s\00"
@.str.2 = [10 x i8] c"Total Ram\00"
@.str.3 = [12 x i8] c"Application\00"
@.str.4 = [12 x i8] c"Percentage\0A\00"
@.str.5 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.6 = [48 x i8] c"Application close or File '%s' does not exists\0A\00"
@.str.7 = [28 x i8] c"%lu %lu %lu %lu %lu %lu %lu\00"
@.str.8 = [26 x i8] c"%10lukB %10lukB %10.3f%%\0A\00"
define i32 @CheckUsage(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.sysinfo
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca float
store i8* %0, i8** %2
%15 = call i64 @sysinfo(%struct.sysinfo* %3)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %1
store i64 0, i64* %4
%20 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %3, i32 0, i32 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %3, i32 0, i32 1
%23 = load i32, i32* %22
%24 = mul nsw i32 %21, %23
%25 = sdiv i32 %24, 1024
%26 = sext i32 %25 to i64
store i64 %26, i64* %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %19, %37
%29 = load i8*, i8** %2
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %30, i32** %5
%31 = load i32*, i32** %5
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %2
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i8* %35)
ret i32 1
37: ; preds = %28
store i64 0, i64* %6
store i64 0, i64* %7
store i64 0, i64* %8
store i64 0, i64* %9
store i64 0, i64* %10
store i64 0, i64* %11
store i64 0, i64* %12
%38 = load i32*, i32** %5
%39 = call i32 @fscanf(i32* %38, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i64* %6, i64* %7, i64* %8, i64* %9, i64* %10, i64* %11, i64* %12)
%40 = load i64, i64* %7
%41 = call i64 (...) @getpagesize()
%42 = mul i64 %40, %41
store i64 %42, i64* %13
store float 0.000000e+00, float* %14
%43 = load i64, i64* %13
%44 = uitofp i64 %43 to float
%45 = fdiv float %44, 1.024000e+03
%46 = load i64, i64* %4
%47 = uitofp i64 %46 to float
%48 = fdiv float %45, %47
%49 = fmul float %48, 1.000000e+02
store float %49, float* %14
%50 = load i64, i64* %4
%51 = load i64, i64* %13
%52 = udiv i64 %51, 1024
%53 = load float, float* %14
%54 = fpext float %53 to double
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i64 %50, i64 %52, double %54)
%56 = load i32*, i32** %5
%57 = call i32 @fclose(i32* %56)
%58 = call i32 @sleep(i32 1)
br label %28
}

LLVM IR (-O2):
%struct.sysinfo = type { i32, i32 }
@.str = [9 x i8] c"Sysinfo\0A\00"
@.str.1 = [15 x i8] c"%10s %12s %13s\00"
@.str.2 = [10 x i8] c"Total Ram\00"
@.str.3 = [12 x i8] c"Application\00"
@.str.4 = [12 x i8] c"Percentage\0A\00"
@.str.5 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.6 = [48 x i8] c"Application close or File '%s' does not exists\0A\00"
@.str.7 = [28 x i8] c"%lu %lu %lu %lu %lu %lu %lu\00"
@.str.8 = [26 x i8] c"%10lukB %10lukB %10.3f%%\0A\00"
define i32 @CheckUsage(i8* %0) {
%2 = alloca %struct.sysinfo
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = bitcast %struct.sysinfo* %2 to i8*
%11 = call i64 @sysinfo(%struct.sysinfo* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i64 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i64 0, i32 1
%19 = load i32, i32* %18
%20 = mul nsw i32 %19, %17
%21 = sdiv i32 %20, 1024
%22 = sext i32 %21 to i64
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %52, label %26
26: ; preds = %15
%27 = bitcast i64* %3 to i8*
%28 = bitcast i64* %4 to i8*
%29 = bitcast i64* %5 to i8*
%30 = bitcast i64* %6 to i8*
%31 = bitcast i64* %7 to i8*
%32 = bitcast i64* %8 to i8*
%33 = bitcast i64* %9 to i8*
%34 = uitofp i64 %22 to float
br label %35
35: ; preds = %26, %35
%36 = phi i32* [ %24, %26 ], [ %50, %35 ]
store i64 0, i64* %3
store i64 0, i64* %4
store i64 0, i64* %5
store i64 0, i64* %6
store i64 0, i64* %7
store i64 0, i64* %8
store i64 0, i64* %9
%37 = call i32 @fscanf(i32* %36, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i64* %3, i64* %4, i64* %5, i64* %6, i64* %7, i64* %8, i64* %9)
%38 = load i64, i64* %4
%39 = call i64 (...) @getpagesize()
%40 = mul i64 %39, %38
%41 = uitofp i64 %40 to float
%42 = fmul float %41, 0x3F50000000000000
%43 = fdiv float %42, %34
%44 = fmul float %43, 1.000000e+02
%45 = lshr i64 %40, 10
%46 = fpext float %44 to double
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i64 %22, i64 %45, double %46)
%48 = call i32 @fclose(i32* %36)
%49 = call i32 @sleep(i32 1)
%50 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %35
52: ; preds = %35, %15
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i8* %0)
ret i32 1
}