#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 {
  scalar_t__ f_bfree;
  scalar_t__ f_blocks;
  scalar_t__ f_bsize;
};

/* Variables and functions */
char const *bprintf(char *, float);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
scalar_t__ statvfs(char const *, struct statvfs *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
const char *disk_used(const char *mnt) {
  struct statvfs fs;
  if (statvfs(mnt, &fs) < 0) {
    fprintf(stderr, "statvfs '%s': %s\n", mnt, strerror(errno));
    return NULL;
  }
  return bprintf("%f", (float)fs.f_bsize *
                           ((float)fs.f_blocks - (float)fs.f_bfree) / 1024 /
                           1024 / 1024);
}


x86 assembly (clang, -O0):
<disk_used>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <statvfs@plt>
cmp    $0x0,%rax
jge    11a8 <disk_used+0x68>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe6e(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f6 <disk_used+0xb6>
cvtsi2ssq -0x18(%rbp),%xmm0
cvtsi2ssq -0x20(%rbp),%xmm1
cvtsi2ssq -0x28(%rbp),%xmm2
subss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
movss  0xe36(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xe2a(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xe1e(%rip),%xmm1
divss  %xmm1,%xmm0
lea    0xe29(%rip),%rdi
call   1030 <bprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disk_used>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1050 <statvfs@plt>
test   %rax,%rax
js     1194 <disk_used+0x54>
cvtsi2ssq 0x10(%rsp),%xmm1
cvtsi2ssq 0x8(%rsp),%xmm0
cvtsi2ssq (%rsp),%xmm2
subss  %xmm2,%xmm0
mulss  %xmm1,%xmm0
movss  0xe86(%rip),%xmm1
mulss  %xmm1,%xmm0
mulss  %xmm1,%xmm0
mulss  %xmm1,%xmm0
lea    0xe89(%rip),%rdi
call   1030 <bprintf@plt>
jmp    11c1 <disk_used+0x81>
mov    0x2e45(%rip),%rax
mov    (%rax),%ebp
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe52(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.statvfs = type { i64, i64, i64 }
@stderr = global i32 0
@.str = [18 x i8] c"statvfs '%s': %s\0A\00"
@errno = global i32 0
@.str.1 = [3 x i8] c"%f\00"
define i8* @disk_used(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.statvfs
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @statvfs(i8* %5, %struct.statvfs* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %3
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %12)
store i8* null, i8** %2
br label %30
14: ; preds = %1
%15 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %4, i32 0, i32 2
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to float
%18 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %4, i32 0, i32 1
%19 = load i64, i64* %18
%20 = sitofp i64 %19 to float
%21 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %4, i32 0, i32 0
%22 = load i64, i64* %21
%23 = sitofp i64 %22 to float
%24 = fsub float %20, %23
%25 = fmul float %17, %24
%26 = fdiv float %25, 1.024000e+03
%27 = fdiv float %26, 1.024000e+03
%28 = fdiv float %27, 1.024000e+03
%29 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float %28)
store i8* %29, i8** %2
br label %30
30: ; preds = %14, %8
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
%struct.statvfs = type { i64, i64, i64 }
@stderr = global i32 0
@.str = [18 x i8] c"statvfs '%s': %s\0A\00"
@errno = global i32 0
@.str.1 = [3 x i8] c"%f\00"
define i8* @disk_used(i8* %0) {
%2 = alloca %struct.statvfs
%3 = bitcast %struct.statvfs* %2 to i8*
%4 = call i64 @statvfs(i8* %0, %struct.statvfs* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %9)
br label %27
11: ; preds = %1
%12 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %2, i64 0, i32 2
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to float
%15 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %2, i64 0, i32 1
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to float
%18 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %2, i64 0, i32 0
%19 = load i64, i64* %18
%20 = sitofp i64 %19 to float
%21 = fsub float %17, %20
%22 = fmul float %21, %14
%23 = fmul float %22, 0x3F50000000000000
%24 = fmul float %23, 0x3F50000000000000
%25 = fmul float %24, 0x3F50000000000000
%26 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float %25)
br label %27
27: ; preds = %11, %6
%28 = phi i8* [ null, %6 ], [ %26, %11 ]
ret i8* %28
}