#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 const *);
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;
  static const char *test_name = " get runtime memory use\n";
  print("TAP version 13\n");
  print("# Testing system size.\n");
  ccode = sysinfo(&info);
  if (ccode < 0) {
    print("not ok 1");
    print(test_name);
    print(" ---\n reason: \"could not get sysinfo\"\n ...\n");
    _exit(ccode);
  }
  print("ok 1");
  print(test_name);
  used = info.totalram - info.freeram - info.bufferram;
  print("# System runtime memory report (units in Kilobytes):\n");
  print(" ---\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);
  print(" ...\n");
  print("1..1\n");
  _exit(0);
}


x86 assembly (clang, -O0):
<_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeca(%rip),%rdi
call   1050 <print@plt>
lea    0xece(%rip),%rdi
call   1050 <print@plt>
lea    -0x28(%rbp),%rdi
call   1060 <sysinfo@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11a2 <_start+0x62>
lea    0xec4(%rip),%rdi
call   1050 <print@plt>
mov    0x2eb7(%rip),%rdi
call   1050 <print@plt>
lea    0xeb5(%rip),%rdi
call   1050 <print@plt>
mov    -0x4(%rbp),%edi
call   1030 <_exit@plt>
lea    0xe9c(%rip),%rdi
call   1050 <print@plt>
mov    0x2e8b(%rip),%rdi
call   1050 <print@plt>
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xea5(%rip),%rdi
call   1050 <print@plt>
lea    0xecf(%rip),%rdi
call   1050 <print@plt>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xec2(%rip),%rdi
call   1040 <print_k_value@plt>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xeb9(%rip),%rdi
call   1040 <print_k_value@plt>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xeb0(%rip),%rdi
call   1040 <print_k_value@plt>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xea7(%rip),%rdi
call   1040 <print_k_value@plt>
lea    0xe3b(%rip),%rdi
call   1050 <print@plt>
lea    0xe99(%rip),%rdi
call   1050 <print@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<_start>:
push   %rbx
sub    $0x20,%rsp
lea    0xecd(%rip),%rdi
call   1050 <print@plt>
lea    0xed1(%rip),%rdi
call   1050 <print@plt>
mov    %rsp,%rdi
call   1060 <sysinfo@plt>
test   %eax,%eax
jns    1196 <_start+0x56>
mov    %eax,%ebx
lea    0xecf(%rip),%rdi
call   1050 <print@plt>
lea    0xe82(%rip),%rdi
call   1050 <print@plt>
lea    0xec0(%rip),%rdi
call   1050 <print@plt>
mov    %ebx,%edi
call   1030 <_exit@plt>
lea    0xea8(%rip),%rdi
call   1050 <print@plt>
lea    0xe57(%rip),%rdi
call   1050 <print@plt>
mov    (%rsp),%rbx
mov    0x8(%rsp),%rax
add    0x10(%rsp),%rax
sub    %rax,%rbx
lea    0xeb0(%rip),%rdi
call   1050 <print@plt>
lea    0xeda(%rip),%rdi
call   1050 <print@plt>
mov    (%rsp),%rsi
mov    0x18(%rsp),%edx
lea    0xecc(%rip),%rdi
call   1040 <print_k_value@plt>
mov    0x8(%rsp),%rsi
mov    0x18(%rsp),%edx
lea    0xec1(%rip),%rdi
call   1040 <print_k_value@plt>
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%edx
lea    0xeb6(%rip),%rdi
call   1040 <print_k_value@plt>
mov    0x18(%rsp),%edx
lea    0xeb0(%rip),%rdi
mov    %rbx,%rsi
call   1040 <print_k_value@plt>
lea    0xe41(%rip),%rdi
call   1050 <print@plt>
lea    0xe9f(%rip),%rdi
call   1050 <print@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

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

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