#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_PHYS_PAGES;
int /*<<< orphan*/ errno;
long get_pagesize();
int /*<<< orphan*/ logger(int, int /*<<< orphan*/, char *);
long sysconf(int /*<<< orphan*/);
int get_mem(unsigned long long *mem) {
  long pages, pagesize;
  if ((pages = sysconf(_SC_PHYS_PAGES)) == -1) {
    logger(-1, errno, "Unable to get total phys pages");
    return -1;
  }
  if ((pagesize = get_pagesize()) < 0)
    return -1;
  *mem = (unsigned long long)pages * pagesize;
  return 0;
}


x86 assembly (clang, -O0):
<get_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %rax,-0x18(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    117e <get_mem+0x4e>
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
lea    0xe93(%rip),%rdx
call   1040 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <get_mem+0x86>
mov    $0x0,%al
call   1030 <get_pagesize@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    119f <get_mem+0x6f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <get_mem+0x86>
mov    -0x18(%rbp),%rcx
imul   -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mem>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
cmp    $0xffffffffffffffff,%rax
je     1165 <get_mem+0x35>
mov    %rax,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <get_pagesize@plt>
test   %rax,%rax
js     1186 <get_mem+0x56>
imul   %rbx,%rax
mov    %rax,(%r14)
jmp    118b <get_mem+0x5b>
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdx
mov    $0xffffffff,%ebp
mov    $0xffffffff,%edi
call   1040 <logger@plt>
jmp    118b <get_mem+0x5b>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@_SC_PHYS_PAGES = global i32 0
@errno = global i32 0
@.str = [31 x i8] c"Unable to get total phys pages\00"
define i32 @get_mem(i64* %0) {
%2 = alloca i32
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i64
store i64* %0, i64** %3
%6 = load i32, i32* @_SC_PHYS_PAGES
%7 = call i64 @sysconf(i32 %6)
store i64 %7, i64* %4
%8 = icmp eq i64 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = call i32 @logger(i32 -1, i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %21
12: ; preds = %1
%13 = call i64 (...) @get_pagesize()
store i64 %13, i64* %5
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 -1, i32* %2
br label %21
16: ; preds = %12
%17 = load i64, i64* %4
%18 = load i64, i64* %5
%19 = mul i64 %17, %18
%20 = load i64*, i64** %3
store i64 %19, i64* %20
store i32 0, i32* %2
br label %21
21: ; preds = %16, %15, %9
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@_SC_PHYS_PAGES = global i32 0
@errno = global i32 0
@.str = [31 x i8] c"Unable to get total phys pages\00"
define i32 @get_mem(i64* nocapture writeonly %0) {
%2 = load i32, i32* @_SC_PHYS_PAGES
%3 = tail call i64 @sysconf(i32 %2)
%4 = icmp eq i64 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = tail call i32 @logger(i32 -1, i32 %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %13
8: ; preds = %1
%9 = tail call i64 (...) @get_pagesize()
%10 = icmp slt i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = mul i64 %9, %3
store i64 %12, i64* %0
br label %13
13: ; preds = %8, %11, %5
%14 = phi i32 [ -1, %5 ], [ 0, %11 ], [ -1, %8 ]
ret i32 %14
}