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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int snprintf0(char *, int, char *, int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int fill_mem_usage(char *str, int n) {
  FILE *meminfo = fopen("/proc/meminfo", "r");
  if (meminfo == NULL) {
    fprintf(stderr, "Could not open '/proc/meminfo'\n");
    exit(1);
  }
  int memtotal, memfree, buffers, cached, swaptotal, swapfree;
  char line[256];
  while (NULL != fgets(line, 256, meminfo)) {
    sscanf(line, "MemTotal: %d", &memtotal);
    sscanf(line, "MemFree: %d", &memfree);
    sscanf(line, "Buffers: %d", &buffers);
    sscanf(line, "Cached: %d", &cached);
    sscanf(line, "SwapTotal: %d", &swaptotal);
    sscanf(line, "SwapFree: %d", &swapfree);
  }
  fclose(meminfo);
  float mem_usage = 1.0 - (float)(memfree + buffers + cached) / memtotal;
  float swap_usage = 1.0 - (float)swapfree / swaptotal;
  int single_digit_mem_usage =
      ((9) < ((int)(mem_usage * 10)) ? (9) : ((int)(mem_usage * 10)));
  int single_digit_swap_usage =
      ((9) < ((int)(swap_usage * 10)) ? (9) : ((int)(swap_usage * 10)));
  return snprintf0(str, n, "%d%d", single_digit_mem_usage,
                   single_digit_swap_usage);
}


x86 assembly (clang, -O0):
<fill_mem_usage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <fill_mem_usage+0x53>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11c8 <fill_mem_usage+0x58>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     127a <fill_mem_usage+0x10a>
lea    -0x130(%rbp),%rdi
lea    0xe47(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <sscanf@plt>
lea    -0x130(%rbp),%rdi
lea    0xe3d(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <sscanf@plt>
lea    -0x130(%rbp),%rdi
lea    0xe32(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1060 <sscanf@plt>
lea    -0x130(%rbp),%rdi
lea    0xe27(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <sscanf@plt>
lea    -0x130(%rbp),%rdi
lea    0xe1b(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1060 <sscanf@plt>
lea    -0x130(%rbp),%rdi
lea    0xe12(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <sscanf@plt>
jmp    11c8 <fill_mem_usage+0x58>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
cvtsi2ss %eax,%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd63(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x134(%rbp)
ff
cvtsi2ssl -0x30(%rbp),%xmm0
cvtsi2ssl -0x2c(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd39(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x138(%rbp)
ff
movss  0xd19(%rip),%xmm0
mulss  -0x134(%rbp),%xmm0
ff
cvttss2si %xmm0,%ecx
mov    $0x9,%eax
cmp    %ecx,%eax
jge    1310 <fill_mem_usage+0x1a0>
mov    $0x9,%eax
mov    %eax,-0x144(%rbp)
jmp    132a <fill_mem_usage+0x1ba>
movss  0xce8(%rip),%xmm0
mulss  -0x134(%rbp),%xmm0
ff
cvttss2si %xmm0,%eax
mov    %eax,-0x144(%rbp)
mov    -0x144(%rbp),%eax
mov    %eax,-0x13c(%rbp)
movss  0xcc2(%rip),%xmm0
mulss  -0x138(%rbp),%xmm0
ff
cvttss2si %xmm0,%ecx
mov    $0x9,%eax
cmp    %ecx,%eax
jge    1367 <fill_mem_usage+0x1f7>
mov    $0x9,%eax
mov    %eax,-0x148(%rbp)
jmp    1381 <fill_mem_usage+0x211>
movss  0xc91(%rip),%xmm0
mulss  -0x138(%rbp),%xmm0
ff
cvttss2si %xmm0,%eax
mov    %eax,-0x148(%rbp)
mov    -0x148(%rbp),%eax
mov    %eax,-0x140(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x13c(%rbp),%ecx
mov    -0x140(%rbp),%r8d
lea    0xce3(%rip),%rdx
call   1070 <snprintf0@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_mem_usage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %esi,0xc(%rsp)
mov    %rdi,0x28(%rsp)
lea    0xe9f(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     131e <fill_mem_usage+0x1ae>
mov    %rax,%rbp
lea    0x30(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1275 <fill_mem_usage+0x105>
lea    0x30(%rsp),%rbx
lea    0xec0(%rip),%r12
lea    0x14(%rsp),%r13
lea    0xec2(%rip),%r14
lea    0x10(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xe66(%rip),%rsi
lea    0x24(%rsp),%rdx
call   1060 <sscanf@plt>
mov    %rbx,%rdi
lea    0xe5f(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1060 <sscanf@plt>
mov    %rbx,%rdi
lea    0xe57(%rip),%rsi
lea    0x1c(%rsp),%rdx
call   1060 <sscanf@plt>
mov    %rbx,%rdi
lea    0xe4f(%rip),%rsi
lea    0x18(%rsp),%rdx
call   1060 <sscanf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1060 <sscanf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <sscanf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rbp,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11f0 <fill_mem_usage+0x80>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    0x1c(%rsp),%eax
add    0x20(%rsp),%eax
add    0x18(%rsp),%eax
movd   %eax,%xmm0
movd   0x10(%rsp),%xmm1
punpckldq %xmm0,%xmm1
cvtdq2ps %xmm1,%xmm0
movss  0x24(%rsp),%xmm1
movss  0x14(%rsp),%xmm2
unpcklps %xmm1,%xmm2
cvtdq2ps %xmm2,%xmm1
divps  %xmm1,%xmm0
movaps 0xd4a(%rip),%xmm1
subps  %xmm0,%xmm1
mulps  0xd50(%rip),%xmm1
cvttps2dq %xmm1,%xmm0
movdqa 0xd54(%rip),%xmm1
pcmpgtd %xmm0,%xmm1
pshufd $0x50,%xmm1,%xmm1
movmskpd %xmm1,%eax
pshufd $0x55,%xmm0,%xmm1
movd   %xmm1,%ecx
test   $0x2,%al
mov    $0x9,%edx
cmove  %edx,%ecx
movd   %xmm0,%r8d
test   $0x1,%al
cmove  %edx,%r8d
lea    0xdad(%rip),%rdx
mov    0x28(%rsp),%rdi
mov    0xc(%rsp),%esi
call   1070 <snprintf0@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
lea    0xd12(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Could not open '/proc/meminfo'\0A\00"
@.str.3 = [13 x i8] c"MemTotal: %d\00"
@.str.4 = [12 x i8] c"MemFree: %d\00"
@.str.5 = [12 x i8] c"Buffers: %d\00"
@.str.6 = [11 x i8] c"Cached: %d\00"
@.str.7 = [14 x i8] c"SwapTotal: %d\00"
@.str.8 = [13 x i8] c"SwapFree: %d\00"
@.str.9 = [5 x i8] c"%d%d\00"
define i32 @fill_mem_usage(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [256 x i8]
%13 = alloca float
%14 = alloca float
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%17 = 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* %17, i32** %5
%18 = load i32*, i32** %5
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
br label %25
25: ; preds = %30, %24
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%27 = load i32*, i32** %5
%28 = call i32* @fgets(i8* %26, i32 256, i32* %27)
%29 = icmp ne i32* null, %28
br i1 %29, label %30, label %43
30: ; preds = %25
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%32 = call i32 @sscanf(i8* %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%34 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32* %7)
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%36 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32* %8)
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%38 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32* %9)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%40 = call i32 @sscanf(i8* %39, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32* %10)
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%42 = call i32 @sscanf(i8* %41, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32* %11)
br label %25
43: ; preds = %25
%44 = load i32*, i32** %5
%45 = call i32 @fclose(i32* %44)
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = add nsw i32 %46, %47
%49 = load i32, i32* %9
%50 = add nsw i32 %48, %49
%51 = sitofp i32 %50 to float
%52 = load i32, i32* %6
%53 = sitofp i32 %52 to float
%54 = fdiv float %51, %53
%55 = fpext float %54 to double
%56 = fsub double 1.000000e+00, %55
%57 = fptrunc double %56 to float
store float %57, float* %13
%58 = load i32, i32* %11
%59 = sitofp i32 %58 to float
%60 = load i32, i32* %10
%61 = sitofp i32 %60 to float
%62 = fdiv float %59, %61
%63 = fpext float %62 to double
%64 = fsub double 1.000000e+00, %63
%65 = fptrunc double %64 to float
store float %65, float* %14
%66 = load float, float* %13
%67 = fmul float %66, 1.000000e+01
%68 = fptosi float %67 to i32
%69 = icmp slt i32 9, %68
br i1 %69, label %70, label %71
70: ; preds = %43
br label %75
71: ; preds = %43
%72 = load float, float* %13
%73 = fmul float %72, 1.000000e+01
%74 = fptosi float %73 to i32
br label %75
75: ; preds = %71, %70
%76 = phi i32 [ 9, %70 ], [ %74, %71 ]
store i32 %76, i32* %15
%77 = load float, float* %14
%78 = fmul float %77, 1.000000e+01
%79 = fptosi float %78 to i32
%80 = icmp slt i32 9, %79
br i1 %80, label %81, label %82
81: ; preds = %75
br label %86
82: ; preds = %75
%83 = load float, float* %14
%84 = fmul float %83, 1.000000e+01
%85 = fptosi float %84 to i32
br label %86
86: ; preds = %82, %81
%87 = phi i32 [ 9, %81 ], [ %85, %82 ]
store i32 %87, i32* %16
%88 = load i8*, i8** %3
%89 = load i32, i32* %4
%90 = load i32, i32* %15
%91 = load i32, i32* %16
%92 = call i32 @snprintf0(i8* %88, i32 %89, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %90, i32 %91)
ret i32 %92
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Could not open '/proc/meminfo'\0A\00"
@.str.3 = [13 x i8] c"MemTotal: %d\00"
@.str.4 = [12 x i8] c"MemFree: %d\00"
@.str.5 = [12 x i8] c"Buffers: %d\00"
@.str.6 = [11 x i8] c"Cached: %d\00"
@.str.7 = [14 x i8] c"SwapTotal: %d\00"
@.str.8 = [13 x i8] c"SwapFree: %d\00"
@.str.9 = [5 x i8] c"%d%d\00"
define i32 @fill_mem_usage(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = 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))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = bitcast i32* %3 to i8*
%18 = bitcast i32* %4 to i8*
%19 = bitcast i32* %5 to i8*
%20 = bitcast i32* %6 to i8*
%21 = bitcast i32* %7 to i8*
%22 = bitcast i32* %8 to i8*
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%24 = call i32* @fgets(i8* %23, i32 256, i32* %10)
%25 = icmp eq i32* %24, null
br i1 %25, label %35, label %26
26: ; preds = %16, %26
%27 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%28 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%29 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32* %5)
%30 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32* %6)
%31 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32* %7)
%32 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32* %8)
%33 = call i32* @fgets(i8* %23, i32 256, i32* %10)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %26
35: ; preds = %26, %16
%36 = call i32 @fclose(i32* %10)
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = add nsw i32 %38, %37
%40 = load i32, i32* %6
%41 = add nsw i32 %39, %40
%42 = load i32, i32* %3
%43 = load i32, i32* %8
%44 = insertelement <2 x i32> poison, i32 %43, i64 0
%45 = insertelement <2 x i32> %44, i32 %41, i64 1
%46 = sitofp <2 x i32> %45 to <2 x float>
%47 = load i32, i32* %7
%48 = insertelement <2 x i32> poison, i32 %47, i64 0
%49 = insertelement <2 x i32> %48, i32 %42, i64 1
%50 = sitofp <2 x i32> %49 to <2 x float>
%51 = fdiv <2 x float> %46, %50
%52 = fsub <2 x float> <float 1.000000e+00, float 1.000000e+00>, %51
%53 = fmul <2 x float> %52, <float 1.000000e+01, float 1.000000e+01>
%54 = fptosi <2 x float> %53 to <2 x i32>
%55 = icmp slt <2 x i32> %54, <i32 9, i32 9>
%56 = extractelement <2 x i1> %55, i64 1
%57 = extractelement <2 x i32> %54, i64 1
%58 = select i1 %56, i32 %57, i32 9
%59 = extractelement <2 x i1> %55, i64 0
%60 = extractelement <2 x i32> %54, i64 0
%61 = select i1 %59, i32 %60, i32 9
%62 = call i32 @snprintf0(i8* %0, i32 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %58, i32 %61)
ret i32 %62
}