#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 {
  int f_bsize;
  int f_bavail;
};

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int statfs(char *, struct statfs *);
long long kbytes_left_in_dir(char *dir_path) {
  struct statfs buf;
  if (statfs(dir_path, &buf) == -1) {
    perror(dir_path);
    return -1;
  }
  return (buf.f_bsize * buf.f_bavail) / 1024;
}


x86 assembly (clang, -O0):
<kbytes_left_in_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <statfs@plt>
cmp    $0xffffffff,%eax
jne    1158 <kbytes_left_in_dir+0x38>
mov    -0x10(%rbp),%rdi
call   1040 <perror@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    116d <kbytes_left_in_dir+0x4d>
mov    -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kbytes_left_in_dir>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <statfs@plt>
cmp    $0xffffffff,%eax
je     1157 <kbytes_left_in_dir+0x37>
mov    0xc(%rsp),%eax
imul   0x8(%rsp),%eax
lea    0x3ff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0xa,%ecx
movslq %ecx,%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    %rbx,%rdi
call   1040 <perror@plt>
mov    $0xffffffffffffffff,%rax
jmp    1151 <kbytes_left_in_dir+0x31>

LLVM IR (-O0):
%struct.statfs = type { i32, i32 }
define i64 @kbytes_left_in_dir(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca %struct.statfs
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @statfs(i8* %5, %struct.statfs* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @perror(i8* %9)
store i64 -1, i64* %2
br label %19
11: ; preds = %1
%12 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.statfs, %struct.statfs* %4, i32 0, i32 1
%15 = load i32, i32* %14
%16 = mul nsw i32 %13, %15
%17 = sdiv i32 %16, 1024
%18 = sext i32 %17 to i64
store i64 %18, i64* %2
br label %19
19: ; preds = %11, %8
%20 = load i64, i64* %2
ret i64 %20
}

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