#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 */
typedef int uint64_t;
struct sysinfo {
  int mem_unit;
  int totalram;
  int freeram;
  int sharedram;
  int bufferram;
  int totalswap;
  int freeswap;
};

/* Variables and functions */
int sysinfo(struct sysinfo *);
void gather_meminfo(uint64_t *ram_total, uint64_t *ram_free,
                    uint64_t *ram_shared, uint64_t *ram_buffer,
                    uint64_t *swap_total, uint64_t *swap_free) {
  struct sysinfo si;
  if (sysinfo(&si) != -1) {
    uint64_t pagesize = si.mem_unit;
    *ram_total = si.totalram * pagesize;
    *ram_free = si.freeram * pagesize;
    *ram_shared = si.sharedram * pagesize;
    *ram_buffer = si.bufferram * pagesize;
    *swap_total = si.totalswap * pagesize;
    *swap_free = si.freeswap * pagesize;
  }
}


x86 assembly (clang, -O0):
<gather_meminfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <sysinfo@plt>
cmp    $0xffffffff,%eax
je     1196 <gather_meminfo+0x86>
mov    -0x50(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x4c(%rbp),%ecx
imul   -0x54(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x48(%rbp),%ecx
imul   -0x54(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x44(%rbp),%ecx
imul   -0x54(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%ecx
imul   -0x54(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x3c(%rbp),%ecx
imul   -0x54(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%ecx
imul   -0x54(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gather_meminfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x8(%rsp),%rdi
call   1030 <sysinfo@plt>
cmp    $0xffffffff,%eax
je     117e <gather_meminfo+0x6e>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
imul   %eax,%ecx
mov    %ecx,0x0(%rbp)
mov    0x10(%rsp),%ecx
imul   %eax,%ecx
mov    %ecx,(%rbx)
mov    0x14(%rsp),%ecx
imul   %eax,%ecx
mov    %ecx,0x0(%r13)
mov    0x18(%rsp),%ecx
imul   %eax,%ecx
mov    %ecx,(%r12)
mov    0x1c(%rsp),%ecx
imul   %eax,%ecx
mov    %ecx,(%r15)
imul   0x20(%rsp),%eax
mov    %eax,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sysinfo = type { i32, i32, i32, i32, i32, i32, i32 }
define void @gather_meminfo(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca %struct.sysinfo
%14 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%15 = call i32 @sysinfo(%struct.sysinfo* %13)
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %50
17: ; preds = %6
%18 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %13, i32 0, i32 0
%19 = load i32, i32* %18
store i32 %19, i32* %14
%20 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %13, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load i32, i32* %14
%23 = mul nsw i32 %21, %22
%24 = load i32*, i32** %7
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %13, i32 0, i32 2
%26 = load i32, i32* %25
%27 = load i32, i32* %14
%28 = mul nsw i32 %26, %27
%29 = load i32*, i32** %8
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %13, i32 0, i32 3
%31 = load i32, i32* %30
%32 = load i32, i32* %14
%33 = mul nsw i32 %31, %32
%34 = load i32*, i32** %9
store i32 %33, i32* %34
%35 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %13, i32 0, i32 4
%36 = load i32, i32* %35
%37 = load i32, i32* %14
%38 = mul nsw i32 %36, %37
%39 = load i32*, i32** %10
store i32 %38, i32* %39
%40 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %13, i32 0, i32 5
%41 = load i32, i32* %40
%42 = load i32, i32* %14
%43 = mul nsw i32 %41, %42
%44 = load i32*, i32** %11
store i32 %43, i32* %44
%45 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %13, i32 0, i32 6
%46 = load i32, i32* %45
%47 = load i32, i32* %14
%48 = mul nsw i32 %46, %47
%49 = load i32*, i32** %12
store i32 %48, i32* %49
br label %50
50: ; preds = %17, %6
ret void
}

LLVM IR (-O2):
%struct.sysinfo = type { i32, i32, i32, i32, i32, i32, i32 }
define void @gather_meminfo(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5) {
%7 = alloca %struct.sysinfo
%8 = bitcast %struct.sysinfo* %7 to i8*
%9 = call i32 @sysinfo(%struct.sysinfo* %7)
%10 = icmp eq i32 %9, -1
br i1 %10, label %32, label %11
11: ; preds = %6
%12 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %7, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %7, i64 0, i32 1
%15 = load i32, i32* %14
%16 = mul nsw i32 %15, %13
store i32 %16, i32* %0
%17 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %7, i64 0, i32 2
%18 = load i32, i32* %17
%19 = mul nsw i32 %18, %13
store i32 %19, i32* %1
%20 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %7, i64 0, i32 3
%21 = load i32, i32* %20
%22 = mul nsw i32 %21, %13
store i32 %22, i32* %2
%23 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %7, i64 0, i32 4
%24 = load i32, i32* %23
%25 = mul nsw i32 %24, %13
store i32 %25, i32* %3
%26 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %7, i64 0, i32 5
%27 = load i32, i32* %26
%28 = mul nsw i32 %27, %13
store i32 %28, i32* %4
%29 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %7, i64 0, i32 6
%30 = load i32, i32* %29
%31 = mul nsw i32 %30, %13
store i32 %31, i32* %5
br label %32
32: ; preds = %11, %6
ret void
}