#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 */
struct sysinfo {
  unsigned long totalram;
  unsigned long freeram;
};

/* Variables and functions */
int errno;
int sysinfo(struct sysinfo *);
int get_system_ram(unsigned long *total_ram, unsigned long *free_ram) {
  struct sysinfo info;
  int error = sysinfo(&info);
  if (error < 0)
    return errno;
  *total_ram = info.totalram;
  *free_ram = info.freeram;
  return 0;
}


x86 assembly (clang, -O0):
<get_system_ram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <sysinfo@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1147 <get_system_ram+0x37>
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1164 <get_system_ram+0x54>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_system_ram>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1030 <sysinfo@plt>
test   %eax,%eax
js     113f <get_system_ram+0x2f>
mov    0x8(%rsp),%rax
mov    %rax,(%rbx)
mov    0x10(%rsp),%rax
mov    %rax,(%r14)
xor    %eax,%eax
jmp    1148 <get_system_ram+0x38>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sysinfo = type { i64, i64 }
@errno = global i32 0
define i32 @get_system_ram(i64* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca %struct.sysinfo
%7 = alloca i32
store i64* %0, i64** %4
store i64* %1, i64** %5
%8 = call i32 @sysinfo(%struct.sysinfo* %6)
store i32 %8, i32* %7
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* @errno
store i32 %12, i32* %3
br label %20
13: ; preds = %2
%14 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %6, i32 0, i32 0
%15 = load i64, i64* %14
%16 = load i64*, i64** %4
store i64 %15, i64* %16
%17 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %6, i32 0, i32 1
%18 = load i64, i64* %17
%19 = load i64*, i64** %5
store i64 %18, i64* %19
store i32 0, i32* %3
br label %20
20: ; preds = %13, %11
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.sysinfo = type { i64, i64 }
@errno = global i32 0
define i32 @get_system_ram(i64* nocapture writeonly %0, i64* nocapture writeonly %1) {
%3 = alloca %struct.sysinfo
%4 = bitcast %struct.sysinfo* %3 to i8*
%5 = call i32 @sysinfo(%struct.sysinfo* %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = load i32, i32* @errno
br label %14
9: ; preds = %2
%10 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %3, i64 0, i32 0
%11 = load i64, i64* %10
store i64 %11, i64* %0
%12 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %3, i64 0, i32 1
%13 = load i64, i64* %12
store i64 %13, i64* %1
br label %14
14: ; preds = %9, %7
%15 = phi i32 [ %8, %7 ], [ 0, %9 ]
ret i32 %15
}