#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*/ SYS_exit;
int /*<<< orphan*/ SYS_sysinfo;
int /*<<< orphan*/ print(char const *);
int /*<<< orphan*/ print_k_value(char *, unsigned long, int /*<<< orphan*/);
int syscall(int /*<<< orphan*/, ...);
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 = syscall(SYS_sysinfo, &info);
  if (ccode < 0) {
    print("not ok 1");
    print(test_name);
    print(" ---\n reason: \"could not get sysinfo\"\n ...\n");
    syscall(SYS_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");
  syscall(SYS_exit, 0);
}


x86 assembly (clang, -O0):
<_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeda(%rip),%rdi
call   1040 <print@plt>
lea    0xede(%rip),%rdi
call   1040 <print@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1050 <syscall@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11a8 <_start+0x78>
lea    0xec9(%rip),%rdi
call   1040 <print@plt>
mov    0x2eb4(%rip),%rdi
call   1040 <print@plt>
lea    0xeba(%rip),%rdi
call   1040 <print@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    $0x0,%al
call   1050 <syscall@plt>
lea    0xe96(%rip),%rdi
call   1040 <print@plt>
mov    0x2e7d(%rip),%rdi
call   1040 <print@plt>
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe9f(%rip),%rdi
call   1040 <print@plt>
lea    0xec9(%rip),%rdi
call   1040 <print@plt>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xebc(%rip),%rdi
call   1030 <print_k_value@plt>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xeb3(%rip),%rdi
call   1030 <print_k_value@plt>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xeaa(%rip),%rdi
call   1030 <print_k_value@plt>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xea1(%rip),%rdi
call   1030 <print_k_value@plt>
lea    0xe35(%rip),%rdi
call   1040 <print@plt>
lea    0xe93(%rip),%rdi
call   1040 <print@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0x0,%al
call   1050 <syscall@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_start>:
push   %rbx
sub    $0x20,%rsp
lea    0xedd(%rip),%rdi
call   1040 <print@plt>
lea    0xee1(%rip),%rdi
call   1040 <print@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <syscall@plt>
test   %eax,%eax
jns    119c <_start+0x6c>
mov    %eax,%ebx
lea    0xed4(%rip),%rdi
call   1040 <print@plt>
lea    0xe87(%rip),%rdi
call   1040 <print@plt>
lea    0xec5(%rip),%rdi
call   1040 <print@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <syscall@plt>
lea    0xea2(%rip),%rdi
call   1040 <print@plt>
lea    0xe51(%rip),%rdi
call   1040 <print@plt>
mov    (%rsp),%rbx
mov    0x8(%rsp),%rax
add    0x10(%rsp),%rax
sub    %rax,%rbx
lea    0xeaa(%rip),%rdi
call   1040 <print@plt>
lea    0xed4(%rip),%rdi
call   1040 <print@plt>
mov    (%rsp),%rsi
mov    0x18(%rsp),%edx
lea    0xec6(%rip),%rdi
call   1030 <print_k_value@plt>
mov    0x8(%rsp),%rsi
mov    0x18(%rsp),%edx
lea    0xebb(%rip),%rdi
call   1030 <print_k_value@plt>
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%edx
lea    0xeb0(%rip),%rdi
call   1030 <print_k_value@plt>
mov    0x18(%rsp),%edx
lea    0xeaa(%rip),%rdi
mov    %rbx,%rsi
call   1030 <print_k_value@plt>
lea    0xe3b(%rip),%rdi
call   1040 <print@plt>
lea    0xe99(%rip),%rdi
call   1040 <print@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <syscall@plt>
add    $0x20,%rsp
pop    %rbx
ret

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"
@SYS_sysinfo = global i32 0
@.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"
@SYS_exit = global i32 0
@.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 = load i32, i32* @SYS_sysinfo
%7 = call i32 (i32, ...) @syscall(i32 %6, %struct.sysinfo* %2)
store i32 %7, i32* %1
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %0
%11 = call i32 @print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%12 = load i8*, i8** @_start.test_name
%13 = call i32 @print(i8* %12)
%14 = call i32 @print(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%15 = load i32, i32* @SYS_exit
%16 = load i32, i32* %1
%17 = call i32 (i32, ...) @syscall(i32 %15, i32 %16)
br label %18
18: ; preds = %10, %0
%19 = call i32 @print(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%20 = load i8*, i8** @_start.test_name
%21 = call i32 @print(i8* %20)
%22 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 0
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 1
%25 = load i64, i64* %24
%26 = sub i64 %23, %25
%27 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 2
%28 = load i64, i64* %27
%29 = sub i64 %26, %28
store i64 %29, i64* %3
%30 = call i32 @print(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0))
%31 = call i32 @print(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%32 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 0
%33 = load i64, i64* %32
%34 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 3
%35 = load i32, i32* %34
%36 = call i32 @print_k_value(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i64 %33, i32 %35)
%37 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 1
%38 = load i64, i64* %37
%39 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 3
%40 = load i32, i32* %39
%41 = call i32 @print_k_value(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i64 %38, i32 %40)
%42 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 2
%43 = load i64, i64* %42
%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 ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i64 %43, i32 %45)
%47 = load i64, i64* %3
%48 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 3
%49 = load i32, i32* %48
%50 = call i32 @print_k_value(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i64 %47, i32 %49)
%51 = call i32 @print(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0))
%52 = call i32 @print(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0))
%53 = load i32, i32* @SYS_exit
%54 = call i32 (i32, ...) @syscall(i32 %53, i32 0)
ret void
}

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"
@SYS_sysinfo = global i32 0
@.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"
@SYS_exit = global i32 0
@.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 = load i32, i32* @SYS_sysinfo
%6 = call i32 (i32, ...) @syscall(i32 %5, %struct.sysinfo* %1)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = call i32 @print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @print(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%12 = load i32, i32* @SYS_exit
%13 = call i32 (i32, ...) @syscall(i32 %12, i32 %6)
br label %14
14: ; preds = %8, %0
%15 = call i32 @print(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%16 = call i32 @print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 0
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 1
%20 = load i64, i64* %19
%21 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 2
%22 = load i64, i64* %21
%23 = add i64 %20, %22
%24 = sub i64 %18, %23
%25 = call i32 @print(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0))
%26 = call i32 @print(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%27 = load i64, i64* %17
%28 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 3
%29 = load i32, i32* %28
%30 = call i32 @print_k_value(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i64 %27, i32 %29)
%31 = load i64, i64* %19
%32 = load i32, i32* %28
%33 = call i32 @print_k_value(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i64 %31, i32 %32)
%34 = load i64, i64* %21
%35 = load i32, i32* %28
%36 = call i32 @print_k_value(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i64 %34, i32 %35)
%37 = load i32, i32* %28
%38 = call i32 @print_k_value(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i64 %24, i32 %37)
%39 = call i32 @print(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0))
%40 = call i32 @print(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0))
%41 = load i32, i32* @SYS_exit
%42 = call i32 (i32, ...) @syscall(i32 %41, i32 0)
ret void
}