#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 statvfs {
  unsigned long f_bsize;
  unsigned long f_blocks;
  unsigned long f_bavail;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned long *);
int /*<<< orphan*/ printf(char *, unsigned long);
scalar_t__ statvfs(char *, struct statvfs *);
int main(int argc, char *argv[]) {
  struct statvfs vfs;
  if (statvfs("/", &vfs) == 0) {
    unsigned long total_space = vfs.f_bsize * vfs.f_blocks;
    unsigned long free_space = vfs.f_bsize * vfs.f_bavail;
    printf("total disk space: %lu\n", total_space / 1024);
    printf("free disk space: %lu\n", free_space / 1024);
    FILE *fp;
    unsigned long total_mem;
    unsigned long free_mem;
    if ((fp = fopen("/proc/meminfo", "r")) != NULL) {
      fscanf(fp, "MemTotal: %lu kB\n", &total_mem);
      fscanf(fp, "MemFree: %lu kB\n", &free_mem);
      printf("MemTotal: %lu kB\n", total_mem);
      printf("MemFree: %lu kB\n", free_mem);
    }
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <statvfs@plt>
cmp    $0x0,%rax
jne    1234 <main+0xe4>
mov    -0x28(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
shr    $0xa,%rsi
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsi
shr    $0xa,%rsi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe66(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     122b <main+0xdb>
mov    -0x40(%rbp),%rdi
lea    0xe51(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x40(%rbp),%rdi
lea    0xe4f(%rip),%rsi
lea    -0x50(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x48(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
mov    -0x50(%rbp),%rsi
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0xea0(%rip),%rdi
lea    0x18(%rsp),%rsi
call   1060 <statvfs@plt>
test   %rax,%rax
jne    1215 <main+0xc5>
mov    0x18(%rsp),%rbx
mov    0x20(%rsp),%rsi
imul   %rbx,%rsi
imul   0x28(%rsp),%rbx
shr    $0xa,%rsi
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
shr    $0xa,%rbx
lea    0xe77(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     120d <main+0xbd>
lea    0xe73(%rip),%r14
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fscanf@plt>
lea    0xe6e(%rip),%r15
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fscanf@plt>
mov    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.statvfs = type { i64, i64, i64 }
@.str = [2 x i8] c"/\00"
@.str.1 = [23 x i8] c"total disk space: %lu\0A\00"
@.str.2 = [22 x i8] c"free disk space: %lu\0A\00"
@.str.3 = [14 x i8] c"/proc/meminfo\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [18 x i8] c"MemTotal: %lu kB\0A\00"
@.str.6 = [17 x i8] c"MemFree: %lu kB\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.statvfs
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i64 @statvfs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.statvfs* %6)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %45
14: ; preds = %2
%15 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %6, i32 0, i32 0
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %6, i32 0, i32 1
%18 = load i64, i64* %17
%19 = mul i64 %16, %18
store i64 %19, i64* %7
%20 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %6, i32 0, i32 0
%21 = load i64, i64* %20
%22 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %6, i32 0, i32 2
%23 = load i64, i64* %22
%24 = mul i64 %21, %23
store i64 %24, i64* %8
%25 = load i64, i64* %7
%26 = udiv i64 %25, 1024
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %26)
%28 = load i64, i64* %8
%29 = udiv i64 %28, 1024
%30 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %29)
%31 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %31, i32** %9
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %42
33: ; preds = %14
%34 = load i32*, i32** %9
%35 = call i32 @fscanf(i32* %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64* %10)
%36 = load i32*, i32** %9
%37 = call i32 @fscanf(i32* %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i64* %11)
%38 = load i64, i64* %10
%39 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64 %38)
%40 = load i64, i64* %11
%41 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i64 %40)
br label %42
42: ; preds = %33, %14
%43 = load i32*, i32** %9
%44 = call i32 @fclose(i32* %43)
br label %45
45: ; preds = %42, %2
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.statvfs = type { i64, i64, i64 }
@.str = [2 x i8] c"/\00"
@.str.1 = [23 x i8] c"total disk space: %lu\0A\00"
@.str.2 = [22 x i8] c"free disk space: %lu\0A\00"
@.str.3 = [14 x i8] c"/proc/meminfo\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [18 x i8] c"MemTotal: %lu kB\0A\00"
@.str.6 = [17 x i8] c"MemFree: %lu kB\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.statvfs
%4 = alloca i64
%5 = alloca i64
%6 = bitcast %struct.statvfs* %3 to i8*
%7 = call i64 @statvfs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.statvfs* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %35
9: ; preds = %2
%10 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i64 0, i32 0
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i64 0, i32 1
%13 = load i64, i64* %12
%14 = mul i64 %13, %11
%15 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i64 0, i32 2
%16 = load i64, i64* %15
%17 = mul i64 %16, %11
%18 = lshr i64 %14, 10
%19 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %18)
%20 = lshr i64 %17, 10
%21 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %20)
%22 = bitcast i64* %4 to i8*
%23 = bitcast i64* %5 to i8*
%24 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %33, label %26
26: ; preds = %9
%27 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64* %4)
%28 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i64* %5)
%29 = load i64, i64* %4
%30 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64 %29)
%31 = load i64, i64* %5
%32 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i64 %31)
br label %33
33: ; preds = %26, %9
%34 = call i32 @fclose(i32* %24)
br label %35
35: ; preds = %33, %2
ret i32 0
}