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

/* Variables and functions */
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int sysconf(int /*<<< orphan*/);
scalar_t__ sysinfo(struct sysinfo *);
int main() {
  struct sysinfo info;
  if (sysinfo(&info) != 0)
    error("sysinfo: error reading system statistics");
  printf("Uptime: %ld:%ld:%ld\n", info.uptime / 3600, info.uptime % 3600 / 60,
         info.uptime % 60);
  printf("Total RAM: %ld MB\n", info.totalram / 1024 / 1024);
  printf("Free RAM: %ld MB\n", (info.totalram - info.freeram) / 1024 / 1024);
  printf("Process count: %d\n", info.procs);
  printf("Page size: %ld bytes\n", sysconf(_SC_PAGESIZE));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <sysinfo@plt>
cmp    $0x0,%rax
je     116e <main+0x2e>
lea    0xe97(%rip),%rdi
call   1040 <error@plt>
mov    -0x18(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x18(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x1c(%rbp),%edx
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %eax,%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
call   1060 <sysinfo@plt>
test   %rax,%rax
je     115f <main+0x1f>
lea    0xea6(%rip),%rdi
call   1040 <error@plt>
movslq 0x8(%rsp),%rcx
imul   $0xffffffff91a2b3c5,%rcx,%rsi
shr    $0x20,%rsi
add    %ecx,%esi
mov    %esi,%eax
shr    $0x1f,%eax
sar    $0xb,%esi
add    %eax,%esi
imul   $0xe10,%esi,%eax
mov    %ecx,%edx
sub    %eax,%edx
movswl %dx,%eax
imul   $0xffff8889,%eax,%eax
shr    $0x10,%eax
add    %edx,%eax
movzwl %ax,%eax
movswl %ax,%edx
shr    $0xf,%eax
sar    $0x5,%edx
add    %eax,%edx
movswl %dx,%edx
imul   $0xffffffff88888889,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edi
shr    $0x1f,%edi
sar    $0x5,%eax
add    %edi,%eax
imul   $0x3c,%eax,%eax
sub    %eax,%ecx
lea    0xe62(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
lea    0xfffff(%rax),%esi
test   %eax,%eax
cmovns %eax,%esi
sar    $0x14,%esi
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
sub    0x10(%rsp),%eax
lea    0xfffff(%rax),%esi
test   %eax,%eax
cmovns %eax,%esi
sar    $0x14,%esi
lea    0xe46(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x14(%rsp),%esi
lea    0xe46(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
lea    0xe3d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sysinfo = type { i32, i32, i32, i32 }
@.str = [41 x i8] c"sysinfo: error reading system statistics\00"
@.str.1 = [21 x i8] c"Uptime: %ld:%ld:%ld\0A\00"
@.str.2 = [19 x i8] c"Total RAM: %ld MB\0A\00"
@.str.3 = [18 x i8] c"Free RAM: %ld MB\0A\00"
@.str.4 = [19 x i8] c"Process count: %d\0A\00"
@.str.5 = [22 x i8] c"Page size: %ld bytes\0A\00"
@_SC_PAGESIZE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sysinfo
store i32 0, i32* %1
%3 = call i64 @sysinfo(%struct.sysinfo* %2)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @error(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 0
%9 = load i32, i32* %8
%10 = sdiv i32 %9, 3600
%11 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 0
%12 = load i32, i32* %11
%13 = srem i32 %12, 3600
%14 = sdiv i32 %13, 60
%15 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 0
%16 = load i32, i32* %15
%17 = srem i32 %16, 60
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %14, i32 %17)
%19 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 1
%20 = load i32, i32* %19
%21 = sdiv i32 %20, 1024
%22 = sdiv i32 %21, 1024
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 2
%27 = load i32, i32* %26
%28 = sub nsw i32 %25, %27
%29 = sdiv i32 %28, 1024
%30 = sdiv i32 %29, 1024
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %2, i32 0, i32 3
%33 = load i32, i32* %32
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @_SC_PAGESIZE
%36 = call i32 @sysconf(i32 %35)
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %36)
ret i32 0
}

LLVM IR (-O2):
%struct.sysinfo = type { i32, i32, i32, i32 }
@.str = [41 x i8] c"sysinfo: error reading system statistics\00"
@.str.1 = [21 x i8] c"Uptime: %ld:%ld:%ld\0A\00"
@.str.2 = [19 x i8] c"Total RAM: %ld MB\0A\00"
@.str.3 = [18 x i8] c"Free RAM: %ld MB\0A\00"
@.str.4 = [19 x i8] c"Process count: %d\0A\00"
@.str.5 = [22 x i8] c"Page size: %ld bytes\0A\00"
@_SC_PAGESIZE = global i32 0
define i32 @main() {
%1 = alloca %struct.sysinfo
%2 = bitcast %struct.sysinfo* %1 to i8*
%3 = call i64 @sysinfo(%struct.sysinfo* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @error(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = sdiv i32 %9, 3600
%11 = srem i32 %9, 3600
%12 = trunc i32 %11 to i16
%13 = sdiv i16 %12, 60
%14 = sext i16 %13 to i32
%15 = srem i32 %9, 60
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %14, i32 %15)
%17 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 1
%18 = load i32, i32* %17
%19 = sdiv i32 %18, 1048576
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %17
%22 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 2
%23 = load i32, i32* %22
%24 = sub nsw i32 %21, %23
%25 = sdiv i32 %24, 1048576
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 3
%28 = load i32, i32* %27
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @_SC_PAGESIZE
%31 = call i32 @sysconf(i32 %30)
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %31)
ret i32 0
}