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

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ cctools_debug(long long, char *, char const *, ...);
int /*<<< orphan*/ errno;
scalar_t__ statfs(char const *, struct statfs *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int rmonitor_get_dsk_usage(const char *path, struct statfs *disk) {
  char cwd[PATH_MAX];
  cctools_debug((1LL << 39), "statfs on path: %s\n", path);
  if (statfs(path, disk) > 0) {
    cctools_debug((1LL << 39), "could not statfs on %s : %s\n", cwd,
                  strerror(errno));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rmonitor_get_dsk_usage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdx
movabs $0x8000000000,%rdi
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1030 <cctools_debug@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <statfs@plt>
cmp    $0x0,%rax
jle    11de <rmonitor_get_dsk_usage+0xae>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x38(%rbp),%rdx
mov    %eax,%ecx
movabs $0x8000000000,%rdi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1030 <cctools_debug@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11ec <rmonitor_get_dsk_usage+0xbc>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmonitor_get_dsk_usage>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r13
movabs $0x8000000000,%r14
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe91(%rip),%rsi
xor    %r15d,%r15d
mov    %r14,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1030 <cctools_debug@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <statfs@plt>
test   %rax,%rax
jle    11b9 <rmonitor_get_dsk_usage+0x89>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe70(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <cctools_debug@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.statfs = type { i32 }
@PATH_MAX = global i32 0
@.str = [20 x i8] c"statfs on path: %s\0A\00"
@.str.1 = [29 x i8] c"could not statfs on %s : %s\0A\00"
@errno = global i32 0
define i32 @rmonitor_get_dsk_usage(i8* %0, %struct.statfs* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.statfs*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store %struct.statfs* %1, %struct.statfs** %5
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i8*, i8** %4
%14 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 549755813888, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %4
%16 = load %struct.statfs*, %struct.statfs** %5
%17 = call i64 @statfs(i8* %15, %struct.statfs* %16)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 549755813888, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %21)
store i32 1, i32* %3
store i32 1, i32* %8
br label %24
23: ; preds = %2
store i32 0, i32* %3
store i32 1, i32* %8
br label %24
24: ; preds = %23, %19
%25 = load i8*, i8** %6
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.statfs = type { i32 }
@PATH_MAX = global i32 0
@.str = [20 x i8] c"statfs on path: %s\0A\00"
@.str.1 = [29 x i8] c"could not statfs on %s : %s\0A\00"
@errno = global i32 0
define i32 @rmonitor_get_dsk_usage(i8* %0, %struct.statfs* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 549755813888, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i64 @statfs(i8* %0, %struct.statfs* %1)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @errno
%11 = tail call i32 @strerror(i32 %10)
%12 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 549755813888, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %5, i32 %11)
br label %13
13: ; preds = %2, %9
%14 = phi i32 [ 1, %9 ], [ 0, %2 ]
ret i32 %14
}