#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 {
  int totalram;
  int freeram;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int sysinfo(struct sysinfo *);
int main(void) {
  struct sysinfo info;
  int ret;
  ret = sysinfo(&info);
  if (ret != 0) {
    printf("Failed to get system information.\n");
    return -1;
  }
  printf("Total RAM: %u\n", info.totalram);
  printf("Free  RAM: %u\n", info.freeram);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <sysinfo@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     115f <main+0x3f>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <main+0x68>
mov    -0x10(%rbp),%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <sysinfo@plt>
test   %eax,%eax
je     1156 <main+0x26>
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    117c <main+0x4c>
mov    0x8(%rsp),%esi
lea    0xe9f(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sysinfo = type { i32, i32 }
@.str = [35 x i8] c"Failed to get system information.\0A\00"
@.str.1 = [15 x i8] c"Total RAM: %u\0A\00"
@.str.2 = [15 x i8] c"Free RAM: %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sysinfo
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @sysinfo(%struct.sysinfo* %2)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %16
9: ; preds = %0
%10 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 1
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %14)
store i32 0, i32* %1
br label %16
16: ; preds = %9, %7
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
%struct.sysinfo = type { i32, i32 }
@.str.1 = [15 x i8] c"Total RAM: %u\0A\00"
@.str.2 = [15 x i8] c"Free RAM: %u\0A\00"
@str = [34 x i8] c"Failed to get system information.\00"
define i32 @main() {
%1 = alloca %struct.sysinfo
%2 = bitcast %struct.sysinfo* %1 to i8*
%3 = call i32 @sysinfo(%struct.sysinfo* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %14
7: ; preds = %0
%8 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 1
%12 = load i32, i32* %11
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %7, %5
%15 = phi i32 [ -1, %5 ], [ 0, %7 ]
ret i32 %15
}