#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 */

/* Variables and functions */
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ _SC_PHYS_PAGES;
int /*<<< orphan*/ snprintf(char *, size_t, char *, unsigned long long);
long sysconf(int /*<<< orphan*/);
void get_ram(char *buffer, size_t size) {
  long pages = sysconf(_SC_PHYS_PAGES);
  long page_size = sysconf(_SC_PAGESIZE);
  if (pages == -1 || page_size == -1)
    return;
  snprintf(buffer, size, "(%llu MB)",
           ((unsigned long long)pages * page_size / 1024 + 512) / 1024);
}


x86 assembly (clang, -O0):
<get_ram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
je     116a <get_ram+0x4a>
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    116f <get_ram+0x4f>
jmp    119b <get_ram+0x7b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
imul   -0x20(%rbp),%rcx
shr    $0xa,%rcx
add    $0x200,%rcx
shr    $0xa,%rcx
lea    0xe6a(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ram>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,%rbx
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
cmp    $0xffffffffffffffff,%rbx
je     1182 <get_ram+0x62>
cmp    $0xffffffffffffffff,%rax
je     1182 <get_ram+0x62>
imul   %rbx,%rax
shr    $0xa,%rax
add    $0x200,%rax
shr    $0xa,%rax
lea    0xe91(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rcx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <snprintf@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@_SC_PHYS_PAGES = global i32 0
@_SC_PAGESIZE = global i32 0
@.str = [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 i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i32, i32* @_SC_PHYS_PAGES
%8 = call i64 @sysconf(i32 %7)
store i64 %8, i64* %5
%9 = load i32, i32* @_SC_PAGESIZE
%10 = call i64 @sysconf(i32 %9)
store i64 %10, i64* %6
%11 = load i64, i64* %5
%12 = icmp eq i64 %11, -1
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i64, i64* %6
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %13, %2
br label %27
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = load i64, i64* %4
%20 = load i64, i64* %5
%21 = load i64, i64* %6
%22 = mul i64 %20, %21
%23 = udiv i64 %22, 1024
%24 = add i64 %23, 512
%25 = udiv i64 %24, 1024
%26 = call i32 @snprintf(i8* %18, i64 %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %25)
br label %27
27: ; preds = %17, %16
ret void
}

LLVM IR (-O2):
@_SC_PHYS_PAGES = global i32 0
@_SC_PAGESIZE = global i32 0
@.str = [10 x i8] c"(%llu MB)\00"
define void @get_ram(i8* %0, i64 %1) {
%3 = load i32, i32* @_SC_PHYS_PAGES
%4 = tail call i64 @sysconf(i32 %3)
%5 = load i32, i32* @_SC_PAGESIZE
%6 = tail call i64 @sysconf(i32 %5)
%7 = icmp eq i64 %4, -1
%8 = icmp eq i64 %6, -1
%9 = select i1 %7, i1 true, i1 %8
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = mul i64 %6, %4
%12 = lshr i64 %11, 10
%13 = add nuw nsw i64 %12, 512
%14 = lshr i64 %13, 10
%15 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %14)
br label %16
16: ; preds = %2, %10
ret void
}