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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, size_t, char *, unsigned long long);
scalar_t__ sysctlbyname(char *, unsigned long long *, size_t *,
                        int /*<<< orphan*/ *, int /*<<< orphan*/);
void get_ram(char *buffer, size_t size) {
  unsigned long long ram = 0;
  size_t sz = sizeof(ram);
  if (sysctlbyname("hw.memsize", &ram, &sz, NULL, 0) != 0)
    return;
  snprintf(buffer, size, "(%llu MB)", (ram / 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)
movq   $0x0,-0x18(%rbp)
movq   $0x8,-0x20(%rbp)
lea    0xeb9(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1040 <sysctlbyname@plt>
cmp    $0x0,%rax
je     116a <get_ram+0x4a>
jmp    1191 <get_ram+0x71>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
shr    $0xa,%rcx
add    $0x200,%rcx
shr    $0xa,%rcx
lea    0xe7f(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ram>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x8,0x10(%rsp)
lea    0xeba(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <sysctlbyname@plt>
test   %rax,%rax
jne    1185 <get_ram+0x65>
mov    0x8(%rsp),%rcx
shr    $0xa,%rcx
add    $0x200,%rcx
shr    $0xa,%rcx
lea    0xe91(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <snprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"hw.memsize\00"
@.str.1 = [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
store i64 0, i64* %5
store i64 8, i64* %6
%7 = call i64 @sysctlbyname(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64* %5, i64* %6, i32* null, i32 0)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
br label %18
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load i64, i64* %4
%13 = load i64, i64* %5
%14 = udiv i64 %13, 1024
%15 = add i64 %14, 512
%16 = udiv i64 %15, 1024
%17 = call i32 @snprintf(i8* %11, i64 %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %16)
br label %18
18: ; preds = %10, %9
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"hw.memsize\00"
@.str.1 = [10 x i8] c"(%llu MB)\00"
define void @get_ram(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = bitcast i64* %4 to i8*
store i64 8, i64* %4
%7 = call i64 @sysctlbyname(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64* %3, i64* %4, i32* null, i32 0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i64, i64* %3
%11 = lshr i64 %10, 10
%12 = add nuw nsw i64 %11, 512
%13 = lshr i64 %12, 10
%14 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %13)
br label %15
15: ; preds = %2, %9
ret void
}