#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_AVPHYS_PAGES;
int /*<<< orphan*/ _SC_NPROCESSORS_CONF;
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ _SC_PHYS_PAGES;
int /*<<< orphan*/ printf(char *, long long, ...);
long sysconf(int /*<<< orphan*/);
int main(void) {
  long num_procs;
  long page_size;
  long num_pages;
  long free_pages;
  long long mem;
  long long free_mem;
  num_procs = sysconf(_SC_NPROCESSORS_CONF);
  printf("CPU: %ld ¸ö\n", num_procs);
  page_size = sysconf(_SC_PAGESIZE);
  printf("PAGESIZE: %ld K\n", page_size / 1024);
  num_pages = sysconf(_SC_PHYS_PAGES);
  printf("PHYS_PAGES: %ld ¸ö\n", num_pages);
  free_pages = sysconf(_SC_AVPHYS_PAGES);
  printf("FREE_PAGES: %ld ¸ö\n", free_pages);
  mem = (long long)((long long)num_pages * (long long)page_size);
  mem /= (1024 * 1024);
  free_mem = (long long)free_pages * (long long)page_size;
  free_mem /= (1024 * 1024);
  printf("×Ü¹²ÓÐ %lld MB µÄÎïÀíÄÚ´æ, ¿ÕÏÐµÄÎïÀíÄÚ´æÓÐ: %lld MB\n", mem,
         free_mem);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %rax,%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    $0x100000,%ecx
cqto
idiv   %rcx
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    $0x100000,%ecx
cqto
idiv   %rcx
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
lea    0xec6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,%r14
lea    0x3ff(%rax),%rsi
test   %rax,%rax
cmovns %rax,%rsi
sar    $0xa,%rsi
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,%r15
lea    0xe93(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,%rbx
lea    0xe87(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
imul   %r14,%r15
lea    0xfffff(%r15),%rsi
test   %r15,%r15
cmovns %r15,%rsi
sar    $0x14,%rsi
imul   %r14,%rbx
lea    0xfffff(%rbx),%rdx
test   %rbx,%rbx
cmovns %rbx,%rdx
sar    $0x14,%rdx
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@_SC_NPROCESSORS_CONF = global i32 0
@.str = [15 x i8] c"CPU: %ld \C2\B8\C3\B6\0A\00"
@_SC_PAGESIZE = global i32 0
@.str.1 = [17 x i8] c"PAGESIZE: %ld K\0A\00"
@_SC_PHYS_PAGES = global i32 0
@.str.2 = [22 x i8] c"PHYS_PAGES: %ld \C2\B8\C3\B6\0A\00"
@_SC_AVPHYS_PAGES = global i32 0
@.str.3 = [22 x i8] c"FREE_PAGES: %ld \C2\B8\C3\B6\0A\00"
@.str.4 = [86 x i8] c"\C3\97\C3\9C\C2\B9\C2\B2\C3\93\C3\90 %lld MB \C2\B5\C3\84\C3\8E\C3\AF\C3\80\C3\AD\C3\84\C3\9A\C2\B4\C3\A6, \C2\BF\C3\95\C3\8F\C3\90\C2\B5\C3\84\C3\8E\C3\AF\C3\80\C3\AD\C3\84\C3\9A\C2\B4\C3\A6\C3\93\C3\90: %lld MB\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = load i32, i32* @_SC_NPROCESSORS_CONF
%9 = call i64 @sysconf(i32 %8)
store i64 %9, i64* %2
%10 = load i64, i64* %2
%11 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = load i32, i32* @_SC_PAGESIZE
%13 = call i64 @sysconf(i32 %12)
store i64 %13, i64* %3
%14 = load i64, i64* %3
%15 = sdiv i64 %14, 1024
%16 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %15)
%17 = load i32, i32* @_SC_PHYS_PAGES
%18 = call i64 @sysconf(i32 %17)
store i64 %18, i64* %4
%19 = load i64, i64* %4
%20 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%21 = load i32, i32* @_SC_AVPHYS_PAGES
%22 = call i64 @sysconf(i32 %21)
store i64 %22, i64* %5
%23 = load i64, i64* %5
%24 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %23)
%25 = load i64, i64* %4
%26 = load i64, i64* %3
%27 = mul nsw i64 %25, %26
store i64 %27, i64* %6
%28 = load i64, i64* %6
%29 = sdiv i64 %28, 1048576
store i64 %29, i64* %6
%30 = load i64, i64* %5
%31 = load i64, i64* %3
%32 = mul nsw i64 %30, %31
store i64 %32, i64* %7
%33 = load i64, i64* %7
%34 = sdiv i64 %33, 1048576
store i64 %34, i64* %7
%35 = load i64, i64* %6
%36 = load i64, i64* %7
%37 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.4, i64 0, i64 0), i64 %35, i64 %36)
ret i32 0
}

LLVM IR (-O2):
@_SC_NPROCESSORS_CONF = global i32 0
@.str = [15 x i8] c"CPU: %ld \C2\B8\C3\B6\0A\00"
@_SC_PAGESIZE = global i32 0
@.str.1 = [17 x i8] c"PAGESIZE: %ld K\0A\00"
@_SC_PHYS_PAGES = global i32 0
@.str.2 = [22 x i8] c"PHYS_PAGES: %ld \C2\B8\C3\B6\0A\00"
@_SC_AVPHYS_PAGES = global i32 0
@.str.3 = [22 x i8] c"FREE_PAGES: %ld \C2\B8\C3\B6\0A\00"
@.str.4 = [86 x i8] c"\C3\97\C3\9C\C2\B9\C2\B2\C3\93\C3\90 %lld MB \C2\B5\C3\84\C3\8E\C3\AF\C3\80\C3\AD\C3\84\C3\9A\C2\B4\C3\A6, \C2\BF\C3\95\C3\8F\C3\90\C2\B5\C3\84\C3\8E\C3\AF\C3\80\C3\AD\C3\84\C3\9A\C2\B4\C3\A6\C3\93\C3\90: %lld MB\0A\00"
define i32 @main() {
%1 = load i32, i32* @_SC_NPROCESSORS_CONF
%2 = tail call i64 @sysconf(i32 %1)
%3 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %2)
%4 = load i32, i32* @_SC_PAGESIZE
%5 = tail call i64 @sysconf(i32 %4)
%6 = sdiv i64 %5, 1024
%7 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %6)
%8 = load i32, i32* @_SC_PHYS_PAGES
%9 = tail call i64 @sysconf(i32 %8)
%10 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %9)
%11 = load i32, i32* @_SC_AVPHYS_PAGES
%12 = tail call i64 @sysconf(i32 %11)
%13 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %12)
%14 = mul nsw i64 %9, %5
%15 = sdiv i64 %14, 1048576
%16 = mul nsw i64 %12, %5
%17 = sdiv i64 %16, 1048576
%18 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.4, i64 0, i64 0), i64 %15, i64 %17)
ret i32 0
}