#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 {
  unsigned long long f_bfree;
  unsigned long long f_bsize;
};

/* Variables and functions */
int /*<<< orphan*/ statfs(char const *, struct statfs *);
int GetFreeSpace(const char *path) {
  struct statfs diskInfo;
  unsigned long long freeDisk = 0;
  if (path == NULL)
    return -1;
  statfs(path, &diskInfo);
  freeDisk = diskInfo.f_bfree * diskInfo.f_bsize;
  if (freeDisk > 0x7FFFFFFFUL)
    freeDisk = 0x7FFFFFFF;
  return (int)freeDisk;
}


x86 assembly (clang, -O0):
<GetFreeSpace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113b <GetFreeSpace+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1172 <GetFreeSpace+0x62>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <statfs@plt>
mov    -0x20(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x7fffffff,-0x28(%rbp)
7f
jbe    116b <GetFreeSpace+0x5b>
movq   $0x7fffffff,-0x28(%rbp)
7f
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetFreeSpace>:
test   %rdi,%rdi
je     1142 <GetFreeSpace+0x32>
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
call   1030 <statfs@plt>
mov    0x10(%rsp),%rcx
imul   0x8(%rsp),%rcx
cmp    $0x7fffffff,%rcx
mov    $0x7fffffff,%eax
cmovb  %ecx,%eax
add    $0x18,%rsp
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.statfs = type { i64, i64 }
define i32 @GetFreeSpace(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.statfs
%5 = alloca i64
store i8* %0, i8** %3
store i64 0, i64* %5
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %23
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @statfs(i8* %10, %struct.statfs* %4)
%12 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i32 0, i32 0
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i32 0, i32 1
%15 = load i64, i64* %14
%16 = mul i64 %13, %15
store i64 %16, i64* %5
%17 = load i64, i64* %5
%18 = icmp ugt i64 %17, 2147483647
br i1 %18, label %19, label %20
19: ; preds = %9
store i64 2147483647, i64* %5
br label %20
20: ; preds = %19, %9
%21 = load i64, i64* %5
%22 = trunc i64 %21 to i32
store i32 %22, i32* %2
br label %23
23: ; preds = %20, %8
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.statfs = type { i64, i64 }
define i32 @GetFreeSpace(i8* %0) {
%2 = alloca %struct.statfs
%3 = bitcast %struct.statfs* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = call i32 @statfs(i8* %0, %struct.statfs* %2)
%7 = getelementptr inbounds %struct.statfs, %struct.statfs* %2, i64 0, i32 0
%8 = load i64, i64* %7
%9 = getelementptr inbounds %struct.statfs, %struct.statfs* %2, i64 0, i32 1
%10 = load i64, i64* %9
%11 = mul i64 %10, %8
%12 = icmp ult i64 %11, 2147483647
%13 = select i1 %12, i64 %11, i64 2147483647
%14 = trunc i64 %13 to i32
br label %15
15: ; preds = %1, %5
%16 = phi i32 [ %14, %5 ], [ -1, %1 ]
ret i32 %16
}