#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 BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int system_get_mem_stat(int *mem_free, int *mem_total, int *swp_free,
                        int *swp_total) {
  FILE *f;
  char buf[BUFSIZ];
  f = fopen("/proc/meminfo", "rt");
  if (f == NULL) {
    return 0;
  }
  *mem_free = 0;
  *mem_total = 0;
  *swp_free = 0;
  *swp_total = 0;
  while (fgets(buf, BUFSIZ, f)) {
    sscanf(buf, "MemTotal: %d", mem_total);
    sscanf(buf, "MemFree: %d", mem_free);
    sscanf(buf, "SwapTotal: %d", swp_total);
    sscanf(buf, "SwapFree: %d", swp_free);
  }
  fclose(f);
  return 1;
}


x86 assembly (clang, -O0):
<system_get_mem_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
lea    0xe75(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b9 <system_get_mem_stat+0x79>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    126d <system_get_mem_stat+0x12d>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x50(%rbp),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1256 <system_get_mem_stat+0x116>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe01(%rip),%rsi
call   1050 <sscanf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdfa(%rip),%rsi
call   1050 <sscanf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xdf2(%rip),%rsi
call   1050 <sscanf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdec(%rip),%rsi
call   1050 <sscanf@plt>
jmp    11e1 <system_get_mem_stat+0xa1>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system_get_mem_stat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,-0x30(%rbp)
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe84(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1233 <system_get_mem_stat+0xf3>
mov    %rax,%r14
movl   $0x0,0x0(%r13)
movl   $0x0,(%r12)
movl   $0x0,(%r15)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1224 <system_get_mem_stat+0xe4>
mov    %rbx,%rdi
lea    0xe2e(%rip),%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
mov    %rbx,%rdi
lea    0xe29(%rip),%rsi
mov    %r13,%rdx
call   1050 <sscanf@plt>
mov    %rbx,%rdi
lea    0xe23(%rip),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %rbx,%rdi
lea    0xe1e(%rip),%rsi
mov    %r15,%rdx
call   1050 <sscanf@plt>
jmp    11c0 <system_get_mem_stat+0x80>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    1235 <system_get_mem_stat+0xf5>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [13 x i8] c"MemTotal: %d\00"
@.str.3 = [12 x i8] c"MemFree: %d\00"
@.str.4 = [14 x i8] c"SwapTotal: %d\00"
@.str.5 = [13 x i8] c"SwapFree: %d\00"
define i32 @system_get_mem_stat(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%14 = load i32, i32* @BUFSIZ
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %11
%17 = alloca i8, i64 %15
store i64 %15, i64* %12
%18 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %10
%19 = load i32*, i32** %10
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %4
store i32 0, i32* %5
store i32 1, i32* %13
br label %44
22: ; preds = %4
%23 = load i32*, i32** %6
store i32 0, i32* %23
%24 = load i32*, i32** %7
store i32 0, i32* %24
%25 = load i32*, i32** %8
store i32 0, i32* %25
%26 = load i32*, i32** %9
store i32 0, i32* %26
br label %27
27: ; preds = %32, %22
%28 = load i32, i32* @BUFSIZ
%29 = load i32*, i32** %10
%30 = call i64 @fgets(i8* %17, i32 %28, i32* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = load i32*, i32** %7
%34 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32* %33)
%35 = load i32*, i32** %6
%36 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32* %35)
%37 = load i32*, i32** %9
%38 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32* %37)
%39 = load i32*, i32** %8
%40 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32* %39)
br label %27
41: ; preds = %27
%42 = load i32*, i32** %10
%43 = call i32 @fclose(i32* %42)
store i32 1, i32* %5
store i32 1, i32* %13
br label %44
44: ; preds = %41, %21
%45 = load i8*, i8** %11
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [13 x i8] c"MemTotal: %d\00"
@.str.3 = [12 x i8] c"MemFree: %d\00"
@.str.4 = [14 x i8] c"SwapTotal: %d\00"
@.str.5 = [13 x i8] c"SwapFree: %d\00"
define i32 @system_get_mem_stat(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %24, label %10
10: ; preds = %4
store i32 0, i32* %0
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%11 = load i32, i32* @BUFSIZ
%12 = call i64 @fgets(i8* %7, i32 %11, i32* %8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %10, %14
%15 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%16 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32* %0)
%17 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%18 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%19 = load i32, i32* @BUFSIZ
%20 = call i64 @fgets(i8* %7, i32 %19, i32* %8)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %14
22: ; preds = %14, %10
%23 = call i32 @fclose(i32* %8)
br label %24
24: ; preds = %4, %22
%25 = phi i32 [ 1, %22 ], [ 0, %4 ]
ret i32 %25
}