#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 ST_RDONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ statvfs(char *, struct statvfs *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  struct statvfs stat;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s PATH", argv[0]);
    exit(2);
  }
  if (statvfs(argv[1], &stat) != 0) {
    perror("statvfs");
    exit(3);
  }
  if (stat.f_flag & ST_RDONLY)
    exit(0);
  else
    exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1186 <main+0x46>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <statvfs@plt>
cmp    $0x0,%rax
je     11b7 <main+0x77>
lea    0xe67(%rip),%rdi
call   1050 <perror@plt>
mov    $0x3,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%eax
mov    0x2e17(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11d3 <main+0x93>
xor    %edi,%edi
call   1060 <exit@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x2,%edi
jne    116f <main+0x2f>
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
call   1040 <statvfs@plt>
test   %rax,%rax
jne    1191 <main+0x51>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
test   %eax,(%rsp)
jne    11a7 <main+0x67>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe7e(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
lea    0xe77(%rip),%rdi
call   1050 <perror@plt>
mov    $0x3,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.statvfs = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"Usage: %s PATH\00"
@.str.1 = [8 x i8] c"statvfs\00"
@ST_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.statvfs
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 2)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @statvfs(i8* %19, %struct.statvfs* %6)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 3)
unreachable
25: ; preds = %16
%26 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %6, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load i32, i32* @ST_RDONLY
%29 = and i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %25
%34 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
%struct.statvfs = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"Usage: %s PATH\00"
@.str.1 = [8 x i8] c"statvfs\00"
@ST_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.statvfs
%4 = bitcast %struct.statvfs* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 2)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @statvfs(i8* %13, %struct.statvfs* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 3)
unreachable
19: ; preds = %11
%20 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i64 0, i32 0
%21 = load i32, i32* %20
%22 = load i32, i32* @ST_RDONLY
%23 = and i32 %22, %21
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %19
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %19
%28 = call i32 @exit(i32 1)
unreachable
}