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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, float *);
float nmem() {
  FILE *fp;
  char res[128];
  memset(res, 0, 128);
  fp = popen("/usr/bin/head -n1 /proc/meminfo", "r");
  fread(res, 1, sizeof(res) - 1, fp);
  float val;
  sscanf(res, "MemTotal: %f kB\n", &val);
  fclose(fp);
  return val / 1024.0 / 1024.0;
}


x86 assembly (clang, -O0):
<nmem>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xe93(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x7f,%edx
call   1030 <fread@plt>
lea    -0x90(%rbp),%rdi
lea    0xe7d(%rip),%rsi
lea    -0x94(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
movss  -0x94(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
movsd  0xe2a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe1e(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nmem>:
push   %r14
push   %rbx
sub    $0x98,%rsp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xe93(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x7f,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
lea    0xe8a(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1060 <sscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe39(%rip),%xmm1
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [32 x i8] c"/usr/bin/head -n1 /proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"MemTotal: %f kB\0A\00"
define float @nmem() {
%1 = alloca i32*
%2 = alloca [128 x i8]
%3 = alloca float
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 128)
%6 = call i32* @popen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %1
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%8 = load i32*, i32** %1
%9 = call i32 @fread(i8* %7, i32 1, i32 127, i32* %8)
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), float* %3)
%12 = load i32*, i32** %1
%13 = call i32 @fclose(i32* %12)
%14 = load float, float* %3
%15 = fpext float %14 to double
%16 = fdiv double %15, 1.024000e+03
%17 = fdiv double %16, 1.024000e+03
%18 = fptrunc double %17 to float
ret float %18
}

LLVM IR (-O2):
@.str = [32 x i8] c"/usr/bin/head -n1 /proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"MemTotal: %f kB\0A\00"
define float @nmem() {
%1 = alloca [128 x i8]
%2 = alloca float
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 128)
%5 = call i32* @popen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @fread(i8* %3, i32 1, i32 127, i32* %5)
%7 = bitcast float* %2 to i8*
%8 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), float* %2)
%9 = call i32 @fclose(i32* %5)
%10 = load float, float* %2
%11 = fpext float %10 to double
%12 = fmul double %11, 0x3F50000000000000
%13 = fmul double %12, 0x3F50000000000000
%14 = fptrunc double %13 to float
ret float %14
}