#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_blocks;
  scalar_t__ f_bfree;
};

/* Variables and functions */
char const *bprintf(char *, int);
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_perc(const char *mnt) {
  int perc;
  struct statvfs fs;
  if (statvfs(mnt, &fs) < 0) {
    fprintf(stderr, "statvfs '%s': %s\n", mnt, strerror(errno));
    return NULL;
  }
  perc = 100 * (1.0f - ((float)fs.f_bfree / (float)fs.f_blocks));
  return bprintf("%d", perc);
}


x86 assembly (clang, -O0):
<disk_perc>:
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_perc+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    0xe72(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ea <disk_perc+0xaa>
cvtsi2ssq -0x20(%rbp),%xmm0
cvtsi2ssq -0x28(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  0xe44(%rip),%xmm1
subss  %xmm0,%xmm1
movss  0xe34(%rip),%xmm0
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe39(%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_perc>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <statvfs@plt>
test   %rax,%rax
js     1190 <disk_perc+0x50>
cvtsi2ssq 0x10(%rsp),%xmm0
cvtsi2ssq 0x8(%rsp),%xmm1
divss  %xmm1,%xmm0
movss  0xe8e(%rip),%xmm1
subss  %xmm0,%xmm1
mulss  0xe86(%rip),%xmm1
cvttss2si %xmm1,%esi
lea    0xe91(%rip),%rdi
call   1030 <bprintf@plt>
jmp    11bd <disk_perc+0x7d>
mov    0x2e49(%rip),%rax
mov    (%rax),%ebp
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe5a(%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 }
@stderr = global i32 0
@.str = [18 x i8] c"statvfs '%s': %s\0A\00"
@errno = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i8* @disk_perc(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.statvfs
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @statvfs(i8* %6, %struct.statvfs* %5)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %3
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %13)
store i8* null, i8** %2
br label %28
15: ; preds = %1
%16 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %5, i32 0, i32 1
%17 = load i64, i64* %16
%18 = sitofp i64 %17 to float
%19 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %5, i32 0, i32 0
%20 = load i64, i64* %19
%21 = sitofp i64 %20 to float
%22 = fdiv float %18, %21
%23 = fsub float 1.000000e+00, %22
%24 = fmul float 1.000000e+02, %23
%25 = fptosi float %24 to i32
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %26)
store i8* %27, i8** %2
br label %28
28: ; preds = %15, %9
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
%struct.statvfs = type { 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"%d\00"
define i8* @disk_perc(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 %23
11: ; preds = %1
%12 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %2, i64 0, i32 1
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to float
%15 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %2, i64 0, i32 0
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to float
%18 = fdiv float %14, %17
%19 = fsub float 1.000000e+00, %18
%20 = fmul float %19, 1.000000e+02
%21 = fptosi float %20 to i32
%22 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %11, %6
%24 = phi i8* [ null, %6 ], [ %22, %11 ]
ret i8* %24
}