#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 */
struct sysinfo {
  unsigned long totalram;
  unsigned long freeram;
  unsigned long bufferram;
  int /*<<< orphan*/ mem_unit;
};

/* Variables and functions */
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ print(char *);
int /*<<< orphan*/ print_k_value(char *, unsigned long, int /*<<< orphan*/);
int sysinfo(struct sysinfo *);
void _start(void) {
  int ccode;
  struct sysinfo info;
  unsigned long used;
  print("Testing system size.\n");
  print("1..1\n");
  ccode = sysinfo(&info);
  if (ccode < 0) {
    print("not ok 1 get runtime memory use\n");
    print("# could not get sysinfo\n");
    _exit(ccode);
  }
  used = info.totalram - info.freeram - info.bufferram;
  print_k_value("ok 1 get runtime memory use # size = ", used, info.mem_unit);
  print("# System runtime memory report (units in Kilobytes):\n");
  print_k_value("#   Total:  ", info.totalram, info.mem_unit);
  print_k_value("#   Free:   ", info.freeram, info.mem_unit);
  print_k_value("#   Buffer: ", info.bufferram, info.mem_unit);
  print_k_value("#   In use: ", used, info.mem_unit);
  _exit(0);
}


x86 assembly (clang, -O0):
<_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
call   1050 <print@plt>
lea    0xebb(%rip),%rdi
call   1050 <print@plt>
lea    -0x28(%rbp),%rdi
call   1060 <sysinfo@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1196 <_start+0x56>
lea    0xe9f(%rip),%rdi
call   1050 <print@plt>
lea    0xeb4(%rip),%rdi
call   1050 <print@plt>
mov    -0x4(%rbp),%edi
call   1030 <_exit@plt>
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xea2(%rip),%rdi
call   1040 <print_k_value@plt>
lea    0xebc(%rip),%rdi
call   1050 <print@plt>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xedf(%rip),%rdi
call   1040 <print_k_value@plt>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xed9(%rip),%rdi
call   1040 <print_k_value@plt>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xed3(%rip),%rdi
call   1040 <print_k_value@plt>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xecd(%rip),%rdi
call   1040 <print_k_value@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<_start>:
push   %rbx
sub    $0x20,%rsp
lea    0xeb4(%rip),%rdi
call   1050 <print@plt>
lea    0xebe(%rip),%rdi
call   1050 <print@plt>
mov    %rsp,%rdi
call   1060 <sysinfo@plt>
test   %eax,%eax
jns    118a <_start+0x4a>
mov    %eax,%ebx
lea    0xeaa(%rip),%rdi
call   1050 <print@plt>
lea    0xebf(%rip),%rdi
call   1050 <print@plt>
mov    %ebx,%edi
call   1030 <_exit@plt>
mov    (%rsp),%rbx
mov    0x8(%rsp),%rax
add    0x10(%rsp),%rax
sub    %rax,%rbx
mov    0x18(%rsp),%edx
lea    0xeb0(%rip),%rdi
mov    %rbx,%rsi
call   1040 <print_k_value@plt>
lea    0xec7(%rip),%rdi
call   1050 <print@plt>
mov    (%rsp),%rsi
mov    0x18(%rsp),%edx
lea    0xee9(%rip),%rdi
call   1040 <print_k_value@plt>
mov    0x8(%rsp),%rsi
mov    0x18(%rsp),%edx
lea    0xee1(%rip),%rdi
call   1040 <print_k_value@plt>
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%edx
lea    0xed9(%rip),%rdi
call   1040 <print_k_value@plt>
mov    0x18(%rsp),%edx
lea    0xed6(%rip),%rdi
mov    %rbx,%rsi
call   1040 <print_k_value@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.sysinfo = type { i64, i64, i64, i32 }
@.str = [22 x i8] c"Testing system size.\0A\00"
@.str.1 = [6 x i8] c"1..1\0A\00"
@.str.2 = [33 x i8] c"not ok 1 get runtime memory use\0A\00"
@.str.3 = [25 x i8] c"# could not get sysinfo\0A\00"
@.str.4 = [38 x i8] c"ok 1 get runtime memory use # size = \00"
@.str.5 = [54 x i8] c"# System runtime memory report (units in Kilobytes):\0A\00"
@.str.6 = [13 x i8] c"# Total: \00"
@.str.7 = [13 x i8] c"# Free: \00"
@.str.8 = [13 x i8] c"# Buffer: \00"
@.str.9 = [13 x i8] c"# In use: \00"
define void @_start() {
%1 = alloca i32
%2 = alloca %struct.sysinfo
%3 = alloca i64
%4 = call i32 @print(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @print(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @sysinfo(%struct.sysinfo* %2)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%12 = load i32, i32* %1
%13 = call i32 @_exit(i32 %12)
unreachable
14: ; preds = %0
%15 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 0
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 1
%18 = load i64, i64* %17
%19 = sub i64 %16, %18
%20 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 2
%21 = load i64, i64* %20
%22 = sub i64 %19, %21
store i64 %22, i64* %3
%23 = load i64, i64* %3
%24 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 3
%25 = load i32, i32* %24
%26 = call i32 @print_k_value(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i64 %23, i32 %25)
%27 = call i32 @print(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
%28 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 0
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 3
%31 = load i32, i32* %30
%32 = call i32 @print_k_value(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i64 %29, i32 %31)
%33 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 1
%34 = load i64, i64* %33
%35 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 3
%36 = load i32, i32* %35
%37 = call i32 @print_k_value(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i64 %34, i32 %36)
%38 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 2
%39 = load i64, i64* %38
%40 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 3
%41 = load i32, i32* %40
%42 = call i32 @print_k_value(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i64 %39, i32 %41)
%43 = load i64, i64* %3
%44 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 3
%45 = load i32, i32* %44
%46 = call i32 @print_k_value(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i64 %43, i32 %45)
%47 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sysinfo = type { i64, i64, i64, i32 }
@.str = [22 x i8] c"Testing system size.\0A\00"
@.str.1 = [6 x i8] c"1..1\0A\00"
@.str.2 = [33 x i8] c"not ok 1 get runtime memory use\0A\00"
@.str.3 = [25 x i8] c"# could not get sysinfo\0A\00"
@.str.4 = [38 x i8] c"ok 1 get runtime memory use # size = \00"
@.str.5 = [54 x i8] c"# System runtime memory report (units in Kilobytes):\0A\00"
@.str.6 = [13 x i8] c"# Total: \00"
@.str.7 = [13 x i8] c"# Free: \00"
@.str.8 = [13 x i8] c"# Buffer: \00"
@.str.9 = [13 x i8] c"# In use: \00"
define void @_start() {
%1 = alloca %struct.sysinfo
%2 = bitcast %struct.sysinfo* %1 to i8*
%3 = tail call i32 @print(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @print(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @sysinfo(%struct.sysinfo* %1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @_exit(i32 %5)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 0
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 1
%15 = load i64, i64* %14
%16 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 2
%17 = load i64, i64* %16
%18 = add i64 %15, %17
%19 = sub i64 %13, %18
%20 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 3
%21 = load i32, i32* %20
%22 = call i32 @print_k_value(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i64 %19, i32 %21)
%23 = call i32 @print(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
%24 = load i64, i64* %12
%25 = load i32, i32* %20
%26 = call i32 @print_k_value(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i64 %24, i32 %25)
%27 = load i64, i64* %14
%28 = load i32, i32* %20
%29 = call i32 @print_k_value(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i64 %27, i32 %28)
%30 = load i64, i64* %16
%31 = load i32, i32* %20
%32 = call i32 @print_k_value(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i64 %30, i32 %31)
%33 = load i32, i32* %20
%34 = call i32 @print_k_value(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i64 %19, i32 %33)
%35 = call i32 @_exit(i32 0)
unreachable
}