#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
scalar_t__ read_string(char *, char *, int);
int sscanf(char *, char *, unsigned long long *);
scalar_t__ strncmp(char *, char *, int);
long long unsigned int system_available_physical_mem() {
  char buf[256];
  long long unsigned int res = 0;
  if (0 < read_string("/proc/meminfo", buf, sizeof(buf))) {
    if (strncmp(buf, "MemTotal:", 9) == 0) {
      if (sscanf(buf, "%*s %llu", &res) != 1) {
        perror("parse error in /proc/meminfo");
      }
    }
  } else {
    perror("read from /proc/meminfo");
  }
  return res * 1024;
}


x86 assembly (clang, -O0):
<system_available_physical_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movq   $0x0,-0x108(%rbp)
lea    -0x100(%rbp),%rsi
lea    0xed6(%rip),%rdi
mov    $0x100,%edx
call   1060 <read_string@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    11d7 <system_available_physical_mem+0x97>
lea    -0x100(%rbp),%rdi
lea    0xe76(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11d2 <system_available_physical_mem+0x92>
lea    -0x100(%rbp),%rdi
lea    0xe5e(%rip),%rsi
lea    -0x108(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     11cd <system_available_physical_mem+0x8d>
lea    0xe4b(%rip),%rdi
call   1050 <perror@plt>
jmp    11d2 <system_available_physical_mem+0x92>
jmp    11e3 <system_available_physical_mem+0xa3>
lea    0xe52(%rip),%rdi
call   1050 <perror@plt>
mov    -0x108(%rbp),%rax
shl    $0xa,%rax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system_available_physical_mem>:
sub    $0x118,%rsp
movq   $0x0,0x8(%rsp)
lea    0xee3(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x100,%edx
call   1060 <read_string@plt>
test   %rax,%rax
jle    11b2 <system_available_physical_mem+0x72>
lea    0xe8e(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11a1 <system_available_physical_mem+0x61>
lea    0xe7d(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11bb <system_available_physical_mem+0x7b>
mov    0x8(%rsp),%rax
shl    $0xa,%rax
add    $0x118,%rsp
ret
lea    0xe77(%rip),%rdi
jmp    11c2 <system_available_physical_mem+0x82>
lea    0xe51(%rip),%rdi
call   1050 <perror@plt>
jmp    11a1 <system_available_physical_mem+0x61>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [10 x i8] c"MemTotal:\00"
@.str.2 = [9 x i8] c"%*s %llu\00"
@.str.3 = [29 x i8] c"parse error in /proc/meminfo\00"
@.str.4 = [24 x i8] c"read from /proc/meminfo\00"
define i64 @system_available_physical_mem() {
%1 = alloca [256 x i8]
%2 = alloca i64
store i64 0, i64* %2
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = call i64 @read_string(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %3, i32 256)
%5 = icmp slt i64 0, %4
br i1 %5, label %6, label %18
6: ; preds = %0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%8 = call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
br label %17
17: ; preds = %16, %6
br label %20
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %17
%21 = load i64, i64* %2
%22 = mul i64 %21, 1024
ret i64 %22
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [10 x i8] c"MemTotal:\00"
@.str.2 = [9 x i8] c"%*s %llu\00"
@.str.3 = [29 x i8] c"parse error in /proc/meminfo\00"
@.str.4 = [24 x i8] c"read from /proc/meminfo\00"
define i64 @system_available_physical_mem() {
%1 = alloca [256 x i8]
%2 = alloca i64
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = call i64 @read_string(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %3, i32 256)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %0
%8 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %16, label %13
13: ; preds = %0, %10
%14 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), %10 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), %0 ]
%15 = call i32 @perror(i8* %14)
br label %16
16: ; preds = %13, %7, %10
%17 = load i64, i64* %2
%18 = shl i64 %17, 10
ret i64 %18
}