#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned long long *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, unsigned long long);
void get_ram(char *buffer, size_t size) {
  unsigned long long ram = 0;
  FILE *meminfo = fopen("/proc/meminfo", "r");
  if (meminfo == NULL)
    return;
  if (fscanf(meminfo, "MemTotal: %llu kB", &ram) != 1) {
    fclose(meminfo);
    return;
  }
  fclose(meminfo);
  if (ram == 0)
    return;
  snprintf(buffer, size, "(%llu MB)", (ram + 512) / 1024);
}


x86 assembly (clang, -O0):
<get_ram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xea1(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117f <get_ram+0x3f>
jmp    11e6 <get_ram+0xa6>
mov    -0x20(%rbp),%rdi
lea    0xe86(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
je     11aa <get_ram+0x6a>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11e6 <get_ram+0xa6>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <get_ram+0x83>
jmp    11e6 <get_ram+0xa6>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
add    $0x200,%rcx
shr    $0xa,%rcx
lea    0xe41(%rip),%rdx
call   1040 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ram>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
movq   $0x0,(%rsp)
lea    0xea4(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b7 <get_ram+0x77>
mov    %rax,%rbx
lea    0xe99(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%ebp
jne    11b7 <get_ram+0x77>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     11b7 <get_ram+0x77>
add    $0x200,%rcx
shr    $0xa,%rcx
lea    0xe76(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <snprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"MemTotal: %llu kB\00"
@.str.3 = [10 x i8] c"(%llu MB)\00"
define void @get_ram(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32*
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %5
%7 = 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* %7, i32** %6
%8 = load i32*, i32** %6
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
br label %31
11: ; preds = %2
%12 = load i32*, i32** %6
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64* %5)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32*, i32** %6
%17 = call i32 @fclose(i32* %16)
br label %31
18: ; preds = %11
%19 = load i32*, i32** %6
%20 = call i32 @fclose(i32* %19)
%21 = load i64, i64* %5
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
br label %31
24: ; preds = %18
%25 = load i8*, i8** %3
%26 = load i64, i64* %4
%27 = load i64, i64* %5
%28 = add i64 %27, 512
%29 = udiv i64 %28, 1024
%30 = call i32 @snprintf(i8* %25, i64 %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 %29)
br label %31
31: ; preds = %24, %23, %15, %10
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"MemTotal: %llu kB\00"
@.str.3 = [10 x i8] c"(%llu MB)\00"
define void @get_ram(i8* %0, i64 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%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 %18, label %7
7: ; preds = %2
%8 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64* %3)
%9 = icmp eq i32 %8, 1
%10 = call i32 @fclose(i32* %5)
br i1 %9, label %11, label %18
11: ; preds = %7
%12 = load i64, i64* %3
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = add i64 %12, 512
%16 = lshr i64 %15, 10
%17 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 %16)
br label %18
18: ; preds = %7, %11, %2, %14
ret void
}