#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 int64_t;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ sysctlbyname(char *, int *, size_t *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/);
char const *get_ram(void) {
  static char ret[255];
  int64_t mem;
  size_t len = 255;
  if (sysctlbyname("hw.memsize", &mem, &len, NULL, 0))
    return NULL;
  mem = mem / 1024 / 1024 / 1024;
  snprintf(ret, 255, "%lld GiB", mem);
  return ret;
}


x86 assembly (clang, -O0):
<get_ram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0xff,-0x18(%rbp)
lea    0xec9(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1040 <sysctlbyname@plt>
cmp    $0x0,%rax
je     1162 <get_ram+0x42>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <get_ram+0x86>
mov    -0xc(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
lea    0x2eb6(%rip),%rdi
mov    $0xff,%esi
lea    0xe75(%rip),%rdx
call   1030 <snprintf@plt>
lea    0x2e9e(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ram>:
push   %rbx
sub    $0x10,%rsp
movq   $0xff,0x8(%rsp)
lea    0xecb(%rip),%rdi
xor    %ebx,%ebx
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <sysctlbyname@plt>
test   %rax,%rax
jne    1181 <get_ram+0x61>
mov    0x4(%rsp),%eax
lea    0x3fffffff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x1e,%ecx
mov    %ecx,0x4(%rsp)
lea    0x2ed3(%rip),%rbx
lea    0xe97(%rip),%rdx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@get_ram.ret = internal global [255 x i8] zeroinitializer
@.str = [11 x i8] c"hw.memsize\00"
@.str.1 = [9 x i8] c"%lld GiB\00"
define i8* @get_ram() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i64
store i64 255, i64* %3
%4 = call i64 @sysctlbyname(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %2, i64* %3, i32* null, i32 0)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i8* null, i8** %1
br label %14
7: ; preds = %0
%8 = load i32, i32* %2
%9 = sdiv i32 %8, 1024
%10 = sdiv i32 %9, 1024
%11 = sdiv i32 %10, 1024
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = call i32 @snprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_ram.ret, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_ram.ret, i64 0, i64 0), i8** %1
br label %14
14: ; preds = %7, %6
%15 = load i8*, i8** %1
ret i8* %15
}

LLVM IR (-O2):
@get_ram.ret = internal global [255 x i8] zeroinitializer
@.str = [11 x i8] c"hw.memsize\00"
@.str.1 = [9 x i8] c"%lld GiB\00"
define i8* @get_ram() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i32* %1 to i8*
%4 = bitcast i64* %2 to i8*
store i64 255, i64* %2
%5 = call i64 @sysctlbyname(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %1, i64* %2, i32* null, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* %1
%9 = sdiv i32 %8, 1073741824
store i32 %9, i32* %1
%10 = call i32 @snprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_ram.ret, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %0, %7
%12 = phi i8* [ getelementptr inbounds ([255 x i8], [255 x i8]* @get_ram.ret, i64 0, i64 0), %7 ], [ null, %0 ]
ret i8* %12
}