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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int ST_RDONLY;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char const *);
int statvfs(char const *, struct statvfs *);
int path_is_on_readonly_fs(const char *path) {
  struct statvfs stvfsbuf;
  if (statvfs(path, &stvfsbuf) == -1)
    err(EXIT_FAILURE, "statvfs(%s)", path);
  return (stvfsbuf.f_flag & ST_RDONLY) != 0;
}


x86 assembly (clang, -O0):
<path_is_on_readonly_fs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <statvfs@plt>
cmp    $0xffffffff,%eax
jne    115b <path_is_on_readonly_fs+0x3b>
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xeaa(%rip),%rsi
call   1030 <err@plt>
mov    -0x10(%rbp),%eax
mov    0x2e7b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_is_on_readonly_fs>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <statvfs@plt>
cmp    $0xffffffff,%eax
jne    114f <path_is_on_readonly_fs+0x2f>
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    0xeb9(%rip),%rsi
mov    %rbx,%rdx
call   1030 <err@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%ecx
xor    %eax,%eax
and    0x8(%rsp),%ecx
setne  %al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.statvfs = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [12 x i8] c"statvfs(%s)\00"
@ST_RDONLY = global i32 0
define i32 @path_is_on_readonly_fs(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.statvfs
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @statvfs(i8* %4, %struct.statvfs* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @EXIT_FAILURE
%9 = load i8*, i8** %2
%10 = call i32 @err(i32 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %7, %1
%12 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = load i32, i32* @ST_RDONLY
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i32
ret i32 %17
}

LLVM IR (-O2):
%struct.statvfs = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [12 x i8] c"statvfs(%s)\00"
@ST_RDONLY = global i32 0
define i32 @path_is_on_readonly_fs(i8* %0) {
%2 = alloca %struct.statvfs
%3 = bitcast %struct.statvfs* %2 to i8*
%4 = call i32 @statvfs(i8* %0, %struct.statvfs* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @err(i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %6, %1
%10 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @ST_RDONLY
%13 = and i32 %12, %11
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i32
ret i32 %15
}