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

/* Variables and functions */
int /*<<< orphan*/ perror(char const *);
scalar_t__ statfs(char const *, struct statfs *);
float df(char *device, const char *mountPoint, int flag) {
  struct statfs s;
  long blocks_used;
  long blocks_percent_used;
  if (statfs(mountPoint, &s) != 0) {
    perror(mountPoint);
    return 1;
  }
  if (s.f_blocks > 0) {
    blocks_used = s.f_blocks - s.f_bfree;
    blocks_percent_used =
        (long)(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
  }
  switch (flag) {
  case 1:
    return (blocks_percent_used);
  case 2:
    return (long)(s.f_blocks * (s.f_bsize / 1024000.0));
  case 3:
    return (long)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024000.0));
  case 4:
    return (long)(s.f_bavail * (s.f_bsize / 1024000.0));
  default:
    return 0;
  }
}


x86 assembly (clang, -O0):
<df>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <statfs@plt>
cmp    $0x0,%rax
je     1165 <df+0x45>
mov    -0x18(%rbp),%rdi
call   1040 <perror@plt>
movss  0xebd(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1289 <df+0x169>
cmpq   $0x0,-0x40(%rbp)
jle    11b4 <df+0x94>
mov    -0x40(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
cvtsi2sdq -0x48(%rbp),%xmm0
movsd  0xe7e(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x48(%rbp),%rax
add    -0x30(%rbp),%rax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  0xe59(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x50(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x58(%rbp)
sub    $0x3,%eax
ja     1281 <df+0x161>
mov    -0x58(%rbp),%rax
lea    0xe48(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cvtsi2ssq -0x50(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1289 <df+0x169>
cvtsi2sdq -0x40(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe10(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1289 <df+0x169>
mov    -0x40(%rbp),%rax
sub    -0x38(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xdda(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1289 <df+0x169>
cvtsi2sdq -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xdab(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1289 <df+0x169>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<df>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1030 <statfs@plt>
test   %rax,%rax
jne    11e6 <df+0xc6>
mov    0x8(%rsp),%rax
test   %rax,%rax
jle    1186 <df+0x66>
mov    %rax,%rcx
sub    0x10(%rsp),%rcx
cvtsi2sd %rcx,%xmm0
mulsd  0xea7(%rip),%xmm0
add    0x18(%rsp),%rcx
cvtsi2sd %rcx,%xmm1
divsd  %xmm1,%xmm0
addsd  0xe99(%rip),%xmm0
cvttsd2si %xmm0,%rcx
xorps  %xmm0,%xmm0
cvtsi2ss %rcx,%xmm0
jmp    1189 <df+0x69>
xorps  %xmm0,%xmm0
add    $0xffffffff,%ebx
cmp    $0x3,%ebx
ja     11b0 <df+0x90>
lea    0xe88(%rip),%rcx
movslq (%rcx,%rbx,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
sub    0x10(%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
jmp    11bf <df+0x9f>
xorps  %xmm0,%xmm0
jmp    11de <df+0xbe>
xorps  %xmm0,%xmm0
cvtsi2sdq 0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
divsd  0xe4b(%rip),%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1040 <perror@plt>
movss  0xe0a(%rip),%xmm0
jmp    11de <df+0xbe>

LLVM IR (-O0):
%struct.statfs = type { i64, i64, i64, double }
define float @df(i8* %0, i8* %1, i32 %2) {
%4 = alloca float
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.statfs
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %6
%12 = call i64 @statfs(i8* %11, %struct.statfs* %8)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = call i32 @perror(i8* %15)
store float 1.000000e+00, float* %4
br label %77
17: ; preds = %3
%18 = getelementptr inbounds %struct.statfs, %struct.statfs* %8, i32 0, i32 0
%19 = load i64, i64* %18
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %17
%22 = getelementptr inbounds %struct.statfs, %struct.statfs* %8, i32 0, i32 0
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.statfs, %struct.statfs* %8, i32 0, i32 1
%25 = load i64, i64* %24
%26 = sub nsw i64 %23, %25
store i64 %26, i64* %9
%27 = load i64, i64* %9
%28 = sitofp i64 %27 to double
%29 = fmul double %28, 1.000000e+02
%30 = load i64, i64* %9
%31 = getelementptr inbounds %struct.statfs, %struct.statfs* %8, i32 0, i32 2
%32 = load i64, i64* %31
%33 = add nsw i64 %30, %32
%34 = sitofp i64 %33 to double
%35 = fdiv double %29, %34
%36 = fadd double %35, 5.000000e-01
%37 = fptosi double %36 to i64
store i64 %37, i64* %10
br label %38
38: ; preds = %21, %17
%39 = load i32, i32* %7
switch i32 %39, label %76 [
i32 1, label %40
i32 2, label %43
i32 3, label %53
i32 4, label %66
]
40: ; preds = %38
%41 = load i64, i64* %10
%42 = sitofp i64 %41 to float
store float %42, float* %4
br label %77
43: ; preds = %38
%44 = getelementptr inbounds %struct.statfs, %struct.statfs* %8, i32 0, i32 0
%45 = load i64, i64* %44
%46 = sitofp i64 %45 to double
%47 = getelementptr inbounds %struct.statfs, %struct.statfs* %8, i32 0, i32 3
%48 = load double, double* %47
%49 = fdiv double %48, 1.024000e+06
%50 = fmul double %46, %49
%51 = fptosi double %50 to i64
%52 = sitofp i64 %51 to float
store float %52, float* %4
br label %77
53: ; preds = %38
%54 = getelementptr inbounds %struct.statfs, %struct.statfs* %8, i32 0, i32 0
%55 = load i64, i64* %54
%56 = getelementptr inbounds %struct.statfs, %struct.statfs* %8, i32 0, i32 1
%57 = load i64, i64* %56
%58 = sub nsw i64 %55, %57
%59 = sitofp i64 %58 to double
%60 = getelementptr inbounds %struct.statfs, %struct.statfs* %8, i32 0, i32 3
%61 = load double, double* %60
%62 = fdiv double %61, 1.024000e+06
%63 = fmul double %59, %62
%64 = fptosi double %63 to i64
%65 = sitofp i64 %64 to float
store float %65, float* %4
br label %77
66: ; preds = %38
%67 = getelementptr inbounds %struct.statfs, %struct.statfs* %8, i32 0, i32 2
%68 = load i64, i64* %67
%69 = sitofp i64 %68 to double
%70 = getelementptr inbounds %struct.statfs, %struct.statfs* %8, i32 0, i32 3
%71 = load double, double* %70
%72 = fdiv double %71, 1.024000e+06
%73 = fmul double %69, %72
%74 = fptosi double %73 to i64
%75 = sitofp i64 %74 to float
store float %75, float* %4
br label %77
76: ; preds = %38
store float 0.000000e+00, float* %4
br label %77
77: ; preds = %76, %66, %53, %43, %40, %14
%78 = load float, float* %4
ret float %78
}

LLVM IR (-O2):
%struct.statfs = type { i64, i64, i64, double }
define float @df(i8* nocapture readnone %0, i8* %1, i32 %2) {
%4 = alloca %struct.statfs
%5 = bitcast %struct.statfs* %4 to i8*
%6 = call i64 @statfs(i8* %1, %struct.statfs* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = call i32 @perror(i8* %1)
br label %60
10: ; preds = %3
%11 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i64 0, i32 0
%12 = load i64, i64* %11
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i64 0, i32 1
%16 = load i64, i64* %15
%17 = sub nsw i64 %12, %16
%18 = sitofp i64 %17 to double
%19 = fmul double %18, 1.000000e+02
%20 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i64 0, i32 2
%21 = load i64, i64* %20
%22 = add nsw i64 %17, %21
%23 = sitofp i64 %22 to double
%24 = fdiv double %19, %23
%25 = fadd double %24, 5.000000e-01
%26 = fptosi double %25 to i64
%27 = sitofp i64 %26 to float
br label %28
28: ; preds = %14, %10
%29 = phi float [ %27, %14 ], [ 0.000000e+00, %10 ]
switch i32 %2, label %59 [
i32 1, label %60
i32 2, label %30
i32 3, label %38
i32 4, label %49
]
30: ; preds = %28
%31 = sitofp i64 %12 to double
%32 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i64 0, i32 3
%33 = load double, double* %32
%34 = fdiv double %33, 1.024000e+06
%35 = fmul double %34, %31
%36 = fptosi double %35 to i64
%37 = sitofp i64 %36 to float
br label %60
38: ; preds = %28
%39 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i64 0, i32 1
%40 = load i64, i64* %39
%41 = sub nsw i64 %12, %40
%42 = sitofp i64 %41 to double
%43 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i64 0, i32 3
%44 = load double, double* %43
%45 = fdiv double %44, 1.024000e+06
%46 = fmul double %45, %42
%47 = fptosi double %46 to i64
%48 = sitofp i64 %47 to float
br label %60
49: ; preds = %28
%50 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i64 0, i32 2
%51 = load i64, i64* %50
%52 = sitofp i64 %51 to double
%53 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i64 0, i32 3
%54 = load double, double* %53
%55 = fdiv double %54, 1.024000e+06
%56 = fmul double %55, %52
%57 = fptosi double %56 to i64
%58 = sitofp i64 %57 to float
br label %60
59: ; preds = %28
br label %60
60: ; preds = %28, %59, %49, %38, %30, %8
%61 = phi float [ 1.000000e+00, %8 ], [ 0.000000e+00, %59 ], [ %58, %49 ], [ %48, %38 ], [ %37, %30 ], [ %29, %28 ]
ret float %61
}