#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 *);
unsigned long long sysconf(int /*<<< orphan*/);
int get_mem(unsigned long long *mem) {
  long pagesize;
  if ((*mem = sysconf(_SC_PHYS_PAGES)) == -1) {
    logger(-1, errno, "Unable to get total phys pages");
    return -1;
  }
  if ((pagesize = get_pagesize()) < 0)
    return -1;
  *mem *= 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    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0xffffffffffffffff,%rax
jne    1181 <get_mem+0x51>
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
lea    0xe90(%rip),%rdx
call   1040 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <get_mem+0x88>
mov    $0x0,%al
call   1030 <get_pagesize@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11a2 <get_mem+0x72>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <get_mem+0x88>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
imul   (%rax),%rcx
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   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e9b(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %rax,(%rbx)
cmp    $0xffffffffffffffff,%rax
je     1164 <get_mem+0x34>
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <get_pagesize@plt>
test   %rax,%rax
js     1185 <get_mem+0x55>
imul   (%rbx),%rax
mov    %rax,(%rbx)
jmp    118a <get_mem+0x5a>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdx
mov    $0xffffffff,%ebp
mov    $0xffffffff,%edi
call   1040 <logger@plt>
jmp    118a <get_mem+0x5a>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
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
store i64* %0, i64** %3
%5 = load i32, i32* @_SC_PHYS_PAGES
%6 = call i64 @sysconf(i32 %5)
%7 = load i64*, i64** %3
store i64 %6, i64* %7
%8 = icmp eq i64 %6, -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* %4
%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** %3
%19 = load i64, i64* %18
%20 = mul i64 %19, %17
store i64 %20, i64* %18
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 %0) {
%2 = load i32, i32* @_SC_PHYS_PAGES
%3 = tail call i64 @sysconf(i32 %2)
store i64 %3, i64* %0
%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 %14
8: ; preds = %1
%9 = tail call i64 (...) @get_pagesize()
%10 = icmp slt i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i64, i64* %0
%13 = mul i64 %12, %9
store i64 %13, i64* %0
br label %14
14: ; preds = %8, %11, %5
%15 = phi i32 [ -1, %5 ], [ 0, %11 ], [ -1, %8 ]
ret i32 %15
}