#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_bavail;
};

/* Variables and functions */
char const *bprintf(char *, int);
scalar_t__ statvfs(char const *, struct statvfs *);
int /*<<< orphan*/ warn(char *, char const *);
const char *disk_perc(const char *path) {
  struct statvfs fs;
  if (statvfs(path, &fs) < 0) {
    warn("statvfs '%s':", path);
    return NULL;
  }
  return bprintf(
      "%d", (int)(100 * (1.0f - ((float)fs.f_bavail / (float)fs.f_blocks))));
}


x86 assembly (clang, -O0):
<disk_perc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <statvfs@plt>
cmp    $0x0,%rax
jge    1170 <disk_perc+0x40>
mov    -0x10(%rbp),%rsi
lea    0xeaa(%rip),%rdi
call   1030 <warn@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ac <disk_perc+0x7c>
cvtsi2ssq -0x18(%rbp),%xmm0
cvtsi2ssq -0x20(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  0xe7c(%rip),%xmm1
subss  %xmm0,%xmm1
movss  0xe6c(%rip),%xmm0
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%esi
lea    0xe73(%rip),%rdi
call   1040 <bprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disk_perc>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1050 <statvfs@plt>
test   %rax,%rax
js     117c <disk_perc+0x4c>
cvtsi2ssq 0x8(%rsp),%xmm0
cvtsi2ssq (%rsp),%xmm1
divss  %xmm1,%xmm0
movss  0xea2(%rip),%xmm1
subss  %xmm0,%xmm1
mulss  0xe9a(%rip),%xmm1
cvttss2si %xmm1,%esi
lea    0xea1(%rip),%rdi
call   1040 <bprintf@plt>
jmp    118d <disk_perc+0x5d>
lea    0xe85(%rip),%rdi
mov    %rbx,%rsi
call   1030 <warn@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.statvfs = type { i64, i64 }
@.str = [14 x i8] c"statvfs '%s':\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @disk_perc(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 %11
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @warn(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %9)
store i8* null, i8** %2
br label %23
11: ; preds = %1
%12 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %4, i32 0, i32 1
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to float
%15 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %4, i32 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 1.000000e+02, %19
%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)
store i8* %22, i8** %2
br label %23
23: ; preds = %11, %8
%24 = load i8*, i8** %2
ret i8* %24
}

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