#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 */
typedef int /*<<< orphan*/ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ MS_REMOUNT;
int /*<<< orphan*/ QCMD(int /*<<< orphan*/, int);
int /*<<< orphan*/ QFMT_VFS_V1;
int /*<<< orphan*/ Q_QUOTAON;
scalar_t__ access(char *, int /*<<< orphan*/);
int asprintf(char **, char *, char const *, char *);
int /*<<< orphan*/ free(char *);
int init_project_quota(char *);
int mount(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/ *,
          int /*<<< orphan*/, char *);
int quotactl(int /*<<< orphan*/, char const *, int /*<<< orphan*/,
             int /*<<< orphan*/);
int project_quota_on(const char *device, const char *root_path) {
  char *quota_path;
  int ret;
  ret = mount(NULL, root_path, NULL, MS_REMOUNT, "quota");
  if (ret)
    return ret;
  ret = asprintf(&quota_path, "%s/%s", root_path, "quota.project");
  if (ret < 0)
    return ret;
  if (access(quota_path, F_OK)) {
    ret = init_project_quota(quota_path);
    if (ret)
      goto out;
  }
  ret = quotactl(QCMD(Q_QUOTAON, 2), device, QFMT_VFS_V1, (caddr_t)quota_path);
out:
  free(quota_path);
  return ret;
}


x86 assembly (clang, -O0):
<project_quota_on>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e45(%rip),%rax
mov    (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edx
lea    0xe68(%rip),%r8
mov    %rdx,%rdi
call   1050 <mount@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11b8 <project_quota_on+0x48>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1266 <project_quota_on+0xf6>
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    0xe3f(%rip),%rsi
lea    0xe3e(%rip),%rcx
call   1070 <asprintf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11eb <project_quota_on+0x7b>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1266 <project_quota_on+0xf6>
mov    -0x20(%rbp),%rdi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0x0,%rax
je     1227 <project_quota_on+0xb7>
mov    -0x20(%rbp),%rdi
call   1060 <init_project_quota@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1222 <project_quota_on+0xb2>
jmp    1257 <project_quota_on+0xe7>
jmp    1227 <project_quota_on+0xb7>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
call   1090 <QCMD@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
mov    0x2da1(%rip),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
call   1040 <quotactl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<project_quota_on>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e4b(%rip),%rax
mov    (%rax),%ecx
lea    0xe72(%rip),%r8
xor    %edi,%edi
xor    %edx,%edx
call   1050 <mount@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1222 <project_quota_on+0xb2>
lea    0xe5e(%rip),%rsi
lea    0xe5d(%rip),%rcx
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
call   1070 <asprintf@plt>
test   %eax,%eax
js     1220 <project_quota_on+0xb0>
mov    0x8(%rsp),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
test   %rax,%rax
je     11e8 <project_quota_on+0x78>
mov    0x8(%rsp),%rdi
call   1060 <init_project_quota@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1214 <project_quota_on+0xa4>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
call   1090 <QCMD@plt>
mov    0x2de6(%rip),%rcx
mov    (%rcx),%edx
mov    0x8(%rsp),%ecx
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <quotactl@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    1222 <project_quota_on+0xb2>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@MS_REMOUNT = global i32 0
@.str = [6 x i8] c"quota\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [14 x i8] c"quota.project\00"
@F_OK = global i32 0
@Q_QUOTAON = global i32 0
@QFMT_VFS_V1 = global i32 0
define i32 @project_quota_on(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = load i32, i32* @MS_REMOUNT
%10 = call i32 @mount(i32* null, i8* %8, i32* null, i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %7
store i32 %14, i32* %3
br label %46
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i32, i32* %7
store i32 %21, i32* %3
br label %46
22: ; preds = %15
%23 = load i8*, i8** %6
%24 = load i32, i32* @F_OK
%25 = call i64 @access(i8* %23, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i8*, i8** %6
%29 = call i32 @init_project_quota(i8* %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
br label %42
33: ; preds = %27
br label %34
34: ; preds = %33, %22
%35 = load i32, i32* @Q_QUOTAON
%36 = call i32 @QCMD(i32 %35, i32 2)
%37 = load i8*, i8** %4
%38 = load i32, i32* @QFMT_VFS_V1
%39 = load i8*, i8** %6
%40 = ptrtoint i8* %39 to i32
%41 = call i32 @quotactl(i32 %36, i8* %37, i32 %38, i32 %40)
store i32 %41, i32* %7
br label %42
42: ; preds = %34, %32
%43 = load i8*, i8** %6
%44 = call i32 @free(i8* %43)
%45 = load i32, i32* %7
store i32 %45, i32* %3
br label %46
46: ; preds = %42, %20, %13
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@MS_REMOUNT = global i32 0
@.str = [6 x i8] c"quota\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [14 x i8] c"quota.project\00"
@F_OK = global i32 0
@Q_QUOTAON = global i32 0
@QFMT_VFS_V1 = global i32 0
define i32 @project_quota_on(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i32, i32* @MS_REMOUNT
%6 = tail call i32 @mount(i32* null, i8* %1, i32* null, i32 %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %32
8: ; preds = %2
%9 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp slt i32 %9, 0
br i1 %10, label %32, label %11
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load i32, i32* @F_OK
%14 = call i64 @access(i8* %12, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = call i32 @init_project_quota(i8* %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %16, %11
%21 = load i32, i32* @Q_QUOTAON
%22 = call i32 @QCMD(i32 %21, i32 2)
%23 = load i32, i32* @QFMT_VFS_V1
%24 = load i8*, i8** %3
%25 = ptrtoint i8* %24 to i64
%26 = trunc i64 %25 to i32
%27 = call i32 @quotactl(i32 %22, i8* %0, i32 %23, i32 %26)
br label %28
28: ; preds = %16, %20
%29 = phi i32 [ %18, %16 ], [ %27, %20 ]
%30 = load i8*, i8** %3
%31 = call i32 @free(i8* %30)
br label %32
32: ; preds = %8, %2, %28
%33 = phi i32 [ %29, %28 ], [ %6, %2 ], [ %9, %8 ]
ret i32 %33
}