#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 */
typedef int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *, int *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
scalar_t__ strcmp(char *, char *);
void put_mem_usage(char *out, void *arg) {
  FILE *statf = fopen("/proc/meminfo", "r");
  if (statf == NULL) {
    sprintf(out, "??%%");
    return;
  }
  uint32_t mem_free = 0, mem_buff = 0, mem_bufb = 0, mem_bufc = 0,
           mem_inuse = 0, mem_total = 0, value = 0;
  char name[512];
  while (fscanf(statf, "%s %u %*s\n", name, &value) != EOF) {
    if (strcmp("MemTotal:", name) == 0)
      mem_total = value;
    else if (strcmp("MemFree:", name) == 0)
      mem_buff = value;
    else if (strcmp("Buffers:", name) == 0)
      mem_bufb = value;
    else if (strcmp("Cached:", name) == 0)
      mem_bufc = value;
  }
  fclose(statf);
  mem_free = mem_buff + mem_bufb + mem_bufc;
  mem_inuse = mem_total - mem_free;
  sprintf(out, "%2d%%", (mem_inuse * 100) / mem_total);
}


x86 assembly (clang, -O0):
<put_mem_usage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe96(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119c <put_mem_usage+0x4c>
mov    -0x8(%rbp),%rdi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    12e1 <put_mem_usage+0x191>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x240(%rbp),%rdx
lea    0xe36(%rip),%rsi
lea    -0x34(%rbp),%rcx
call   1040 <fscanf@plt>
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%rax
je     12a7 <put_mem_usage+0x157>
lea    -0x240(%rbp),%rsi
lea    0xe1a(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1220 <put_mem_usage+0xd0>
mov    -0x34(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    12a2 <put_mem_usage+0x152>
lea    -0x240(%rbp),%rsi
lea    0xdfc(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1248 <put_mem_usage+0xf8>
mov    -0x34(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    129d <put_mem_usage+0x14d>
lea    -0x240(%rbp),%rsi
lea    0xddd(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1270 <put_mem_usage+0x120>
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1298 <put_mem_usage+0x148>
lea    -0x240(%rbp),%rsi
lea    0xdbe(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1293 <put_mem_usage+0x143>
mov    -0x34(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1298 <put_mem_usage+0x148>
jmp    129d <put_mem_usage+0x14d>
jmp    12a2 <put_mem_usage+0x152>
jmp    11cd <put_mem_usage+0x7d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
imul   $0x64,-0x2c(%rbp),%eax
cltd
idivl  -0x30(%rbp)
mov    %eax,%edx
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_mem_usage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rdi,%rbx
lea    0xe95(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1218 <put_mem_usage+0xc8>
mov    %rax,%r12
mov    %rbx,0x18(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe7e(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    0x2e38(%rip),%rcx
xor    %r14d,%r14d
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x14(%rsp)
cmp    (%rcx),%rax
jne    123a <put_mem_usage+0xea>
add    0x10(%rsp),%r14d
add    0xc(%rsp),%r14d
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    0x14(%rsp),%ecx
mov    %ecx,%eax
sub    %r14d,%eax
imul   $0x64,%eax,%eax
cltd
idiv   %ecx
lea    0xe4c(%rip),%rsi
mov    0x18(%rsp),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <sprintf@plt>
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf1(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <sprintf@plt>
movl   $0x0,0x14(%rsp)
lea    0xdd7(%rip),%r15
lea    0x20(%rsp),%rbx
lea    0xdc0(%rip),%r13
lea    0x8(%rsp),%rbp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x10(%rsp)
xor    %r14d,%r14d
jmp    1299 <put_mem_usage+0x149>
nop
mov    0x8(%rsp),%eax
mov    %eax,0x14(%rsp)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1040 <fscanf@plt>
mov    0x2d58(%rip),%rcx
cmp    (%rcx),%rax
je     11d0 <put_mem_usage+0x80>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1270 <put_mem_usage+0x120>
lea    0xd7a(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     12f0 <put_mem_usage+0x1a0>
lea    0xd6f(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     12f7 <put_mem_usage+0x1a7>
lea    0xd64(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1278 <put_mem_usage+0x128>
mov    0x8(%rsp),%eax
mov    %eax,0xc(%rsp)
jmp    1278 <put_mem_usage+0x128>
nop
mov    0x8(%rsp),%r14d
jmp    1278 <put_mem_usage+0x128>
mov    0x8(%rsp),%eax
mov    %eax,0x10(%rsp)
jmp    1278 <put_mem_usage+0x128>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"??%%\00"
@.str.3 = [11 x i8] c"%s %u %*s\0A\00"
@EOF = global i64 0
@.str.4 = [10 x i8] c"MemTotal:\00"
@.str.5 = [9 x i8] c"MemFree:\00"
@.str.6 = [9 x i8] c"Buffers:\00"
@.str.7 = [8 x i8] c"Cached:\00"
@.str.8 = [6 x i8] c"%2d%%\00"
define void @put_mem_usage(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [512 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%14 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %72
20: ; preds = %2
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %21
21: ; preds = %54, %20
%22 = load i32*, i32** %5
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%24 = call i64 @fscanf(i32* %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %23, i32* %12)
%25 = load i64, i64* @EOF
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %55
27: ; preds = %21
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%29 = call i64 @strcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i32, i32* %12
store i32 %32, i32* %11
br label %54
33: ; preds = %27
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%35 = call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = load i32, i32* %12
store i32 %38, i32* %7
br label %53
39: ; preds = %33
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%41 = call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = load i32, i32* %12
store i32 %44, i32* %8
br label %52
45: ; preds = %39
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%47 = call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = load i32, i32* %12
store i32 %50, i32* %9
br label %51
51: ; preds = %49, %45
br label %52
52: ; preds = %51, %43
br label %53
53: ; preds = %52, %37
br label %54
54: ; preds = %53, %31
br label %21
55: ; preds = %21
%56 = load i32*, i32** %5
%57 = call i32 @fclose(i32* %56)
%58 = load i32, i32* %7
%59 = load i32, i32* %8
%60 = add nsw i32 %58, %59
%61 = load i32, i32* %9
%62 = add nsw i32 %60, %61
store i32 %62, i32* %6
%63 = load i32, i32* %11
%64 = load i32, i32* %6
%65 = sub nsw i32 %63, %64
store i32 %65, i32* %10
%66 = load i8*, i8** %3
%67 = load i32, i32* %10
%68 = mul nsw i32 %67, 100
%69 = load i32, i32* %11
%70 = sdiv i32 %68, %69
%71 = call i32 (i8*, i8*, ...) @sprintf(i8* %66, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %55, %17
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"??%%\00"
@.str.3 = [11 x i8] c"%s %u %*s\0A\00"
@EOF = global i64 0
@.str.4 = [10 x i8] c"MemTotal:\00"
@.str.5 = [9 x i8] c"MemFree:\00"
@.str.6 = [9 x i8] c"Buffers:\00"
@.str.7 = [8 x i8] c"Cached:\00"
@.str.8 = [6 x i8] c"%2d%%\00"
define void @put_mem_usage(i8* nocapture writeonly %0, i8* nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [512 x i8]
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %59
9: ; preds = %2
%10 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%12 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %11, i32* %3)
%13 = load i64, i64* @EOF
%14 = icmp eq i64 %12, %13
br i1 %14, label %47, label %15
15: ; preds = %9, %39
%16 = phi i32 [ %43, %39 ], [ 0, %9 ]
%17 = phi i32 [ %42, %39 ], [ 0, %9 ]
%18 = phi i32 [ %41, %39 ], [ 0, %9 ]
%19 = phi i32 [ %40, %39 ], [ 0, %9 ]
%20 = call i64 @strcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = load i32, i32* %3
br label %39
24: ; preds = %15
%25 = call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %11)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = load i32, i32* %3
br label %39
29: ; preds = %24
%30 = call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %11)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = load i32, i32* %3
br label %39
34: ; preds = %29
%35 = call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %11)
%36 = icmp eq i64 %35, 0
%37 = load i32, i32* %3
%38 = select i1 %36, i32 %37, i32 %17
br label %39
39: ; preds = %34, %27, %32, %22
%40 = phi i32 [ %19, %22 ], [ %28, %27 ], [ %19, %32 ], [ %19, %34 ]
%41 = phi i32 [ %18, %22 ], [ %18, %27 ], [ %33, %32 ], [ %18, %34 ]
%42 = phi i32 [ %17, %22 ], [ %17, %27 ], [ %17, %32 ], [ %38, %34 ]
%43 = phi i32 [ %23, %22 ], [ %16, %27 ], [ %16, %32 ], [ %16, %34 ]
%44 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %11, i32* %3)
%45 = load i64, i64* @EOF
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %15
47: ; preds = %39, %9
%48 = phi i32 [ 0, %9 ], [ %40, %39 ]
%49 = phi i32 [ 0, %9 ], [ %41, %39 ]
%50 = phi i32 [ 0, %9 ], [ %42, %39 ]
%51 = phi i32 [ 0, %9 ], [ %43, %39 ]
%52 = call i32 @fclose(i32* %5)
%53 = add i32 %49, %48
%54 = add i32 %53, %50
%55 = sub i32 %51, %54
%56 = mul nsw i32 %55, 100
%57 = sdiv i32 %56, %51
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %47, %7
ret void
}