#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 */
long long get_arch_specific_mem_size();
long long get_mem_size_iomem();
long long get_mem_size_meminfo();
long long get_mem_size_stat();
long long get_mem_size_sysinfo();
long long get_mem_size(void) {
  long long mem_size = 0;
  mem_size = get_arch_specific_mem_size();
  if (mem_size == -2) {
    mem_size = 0;
    goto use_meminfo;
  }
  if (mem_size == -1) {
    mem_size = 0;
    goto use_sysinfo;
  }
  if (mem_size == 0)
    mem_size = get_mem_size_iomem();
  if (mem_size == 0)
    mem_size = get_mem_size_stat();
use_sysinfo:
  if (mem_size == 0)
    mem_size = get_mem_size_sysinfo();
use_meminfo:
  if (mem_size == 0)
    mem_size = get_mem_size_meminfo();
  return mem_size;
}


x86 assembly (clang, -O0):
<get_mem_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1050 <get_arch_specific_mem_size@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0xfffffffffffffffe,-0x8(%rbp)
jne    1183 <get_mem_size+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11e7 <get_mem_size+0x97>
cmpq   $0xffffffffffffffff,-0x8(%rbp)
jne    119b <get_mem_size+0x4b>
movq   $0x0,-0x8(%rbp)
jmp    11cc <get_mem_size+0x7c>
cmpq   $0x0,-0x8(%rbp)
jne    11b1 <get_mem_size+0x61>
mov    $0x0,%al
call   1070 <get_mem_size_iomem@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c7 <get_mem_size+0x77>
mov    $0x0,%al
call   1040 <get_mem_size_stat@plt>
mov    %rax,-0x8(%rbp)
jmp    11cc <get_mem_size+0x7c>
cmpq   $0x0,-0x8(%rbp)
jne    11e2 <get_mem_size+0x92>
mov    $0x0,%al
call   1030 <get_mem_size_sysinfo@plt>
mov    %rax,-0x8(%rbp)
jmp    11e7 <get_mem_size+0x97>
cmpq   $0x0,-0x8(%rbp)
jne    11fd <get_mem_size+0xad>
mov    $0x0,%al
call   1060 <get_mem_size_meminfo@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mem_size>:
push   %rax
xor    %eax,%eax
call   1050 <get_arch_specific_mem_size@plt>
cmp    $0xfffffffffffffffe,%rax
je     118f <get_mem_size+0x3f>
cmp    $0xffffffffffffffff,%rax
je     1181 <get_mem_size+0x31>
test   %rax,%rax
jne    118d <get_mem_size+0x3d>
xor    %eax,%eax
call   1070 <get_mem_size_iomem@plt>
test   %rax,%rax
jne    118d <get_mem_size+0x3d>
xor    %eax,%eax
call   1040 <get_mem_size_stat@plt>
test   %rax,%rax
jne    118d <get_mem_size+0x3d>
xor    %eax,%eax
call   1030 <get_mem_size_sysinfo@plt>
test   %rax,%rax
je     118f <get_mem_size+0x3f>
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
jmp    1060 <get_mem_size_meminfo@plt>

LLVM IR (-O0):
define i64 @get_mem_size() {
%1 = alloca i64
store i64 0, i64* %1
%2 = call i64 (...) @get_arch_specific_mem_size()
store i64 %2, i64* %1
%3 = load i64, i64* %1
%4 = icmp eq i64 %3, -2
br i1 %4, label %5, label %6
5: ; preds = %0
store i64 0, i64* %1
br label %27
6: ; preds = %0
%7 = load i64, i64* %1
%8 = icmp eq i64 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %6
store i64 0, i64* %1
br label %21
10: ; preds = %6
%11 = load i64, i64* %1
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i64 (...) @get_mem_size_iomem()
store i64 %14, i64* %1
br label %15
15: ; preds = %13, %10
%16 = load i64, i64* %1
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i64 (...) @get_mem_size_stat()
store i64 %19, i64* %1
br label %20
20: ; preds = %18, %15
br label %21
21: ; preds = %20, %9
%22 = load i64, i64* %1
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i64 (...) @get_mem_size_sysinfo()
store i64 %25, i64* %1
br label %26
26: ; preds = %24, %21
br label %27
27: ; preds = %26, %5
%28 = load i64, i64* %1
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i64 (...) @get_mem_size_meminfo()
store i64 %31, i64* %1
br label %32
32: ; preds = %30, %27
%33 = load i64, i64* %1
ret i64 %33
}

LLVM IR (-O2):
define i64 @get_mem_size() {
%1 = tail call i64 (...) @get_arch_specific_mem_size()
switch i64 %1, label %13 [
i64 -2, label %11
i64 -1, label %8
i64 0, label %2
]
2: ; preds = %0
%3 = tail call i64 (...) @get_mem_size_iomem()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = tail call i64 (...) @get_mem_size_stat()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0, %5
%9 = tail call i64 (...) @get_mem_size_sysinfo()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0, %8
%12 = tail call i64 (...) @get_mem_size_meminfo()
br label %13
13: ; preds = %0, %2, %5, %11, %8
%14 = phi i64 [ %12, %11 ], [ %9, %8 ], [ %6, %5 ], [ %3, %2 ], [ %1, %0 ]
ret i64 %14
}