#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 if_dqblk {
  unsigned long long dqb_bhardlimit;
  unsigned long long dqb_ihardlimit;
  int /*<<< orphan*/ dqb_valid;
};
typedef int /*<<< orphan*/ quota;
typedef int /*<<< orphan*/ *caddr_t;

/* Variables and functions */
int /*<<< orphan*/ QCMD(int /*<<< orphan*/, int);
unsigned long long QIF_DQBLKSIZE;
int /*<<< orphan*/ QIF_LIMITS;
int /*<<< orphan*/ Q_SETQUOTA;
int /*<<< orphan*/ Q_SYNC;
scalar_t__ get_project(char const *, unsigned int *);
int /*<<< orphan*/ memset(struct if_dqblk *, int /*<<< orphan*/, int);
scalar_t__ quotactl(int /*<<< orphan*/, char const *, unsigned int,
                    int /*<<< orphan*/ *);
int ext4_resize_project(const char *device, const char *path,
                        unsigned long long max_bytes,
                        unsigned long long max_inodes) {
  struct if_dqblk quota;
  unsigned project;
  if (get_project(path, &project))
    return -1;
  memset(&quota, 0, sizeof(quota));
  quota.dqb_bhardlimit = (max_bytes + QIF_DQBLKSIZE - 1) / QIF_DQBLKSIZE;
  quota.dqb_ihardlimit = max_inodes;
  quota.dqb_valid = QIF_LIMITS;
  if (quotactl(QCMD(Q_SETQUOTA, 2), device, project, (caddr_t)&quota))
    return -1;
  quotactl(QCMD(Q_SYNC, 2), device, 0, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<ext4_resize_project>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x44(%rbp),%rsi
call   1060 <get_project@plt>
cmp    $0x0,%rax
je     117b <ext4_resize_project+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <ext4_resize_project+0xe7>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
mov    0x2e4a(%rip),%rcx
add    (%rcx),%rax
sub    $0x1,%rax
mov    0x2e3c(%rip),%rcx
xor    %edx,%edx
divq   (%rcx)
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
call   1050 <QCMD@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
mov    -0x44(%rbp),%edx
lea    -0x40(%rbp),%rcx
call   1030 <quotactl@plt>
cmp    $0x0,%rax
je     11fc <ext4_resize_project+0xbc>
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <ext4_resize_project+0xe7>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
call   1050 <QCMD@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <quotactl@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ext4_resize_project>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
call   1060 <get_project@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
jne    1213 <ext4_resize_project+0xd3>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%rcx
lea    (%rbx,%rcx,1),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     11a9 <ext4_resize_project+0x69>
xor    %edx,%edx
div    %rcx
jmp    11ad <ext4_resize_project+0x6d>
xor    %edx,%edx
div    %ecx
mov    %rax,0x10(%rsp)
mov    %r15,0x18(%rsp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
call   1050 <QCMD@plt>
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rcx
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <quotactl@plt>
test   %rax,%rax
jne    1213 <ext4_resize_project+0xd3>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
call   1050 <QCMD@plt>
xor    %r12d,%r12d
mov    %eax,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <quotactl@plt>
mov    %r12d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.if_dqblk = type { i64, i64, i32 }
@QIF_DQBLKSIZE = global i64 0
@QIF_LIMITS = global i32 0
@Q_SETQUOTA = global i32 0
@Q_SYNC = global i32 0
define i32 @ext4_resize_project(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca %struct.if_dqblk
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%12 = load i8*, i8** %7
%13 = call i64 @get_project(i8* %12, i32* %11)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 -1, i32* %5
br label %42
16: ; preds = %4
%17 = call i32 @memset(%struct.if_dqblk* %10, i32 0, i32 24)
%18 = load i64, i64* %8
%19 = load i64, i64* @QIF_DQBLKSIZE
%20 = add i64 %18, %19
%21 = sub i64 %20, 1
%22 = load i64, i64* @QIF_DQBLKSIZE
%23 = udiv i64 %21, %22
%24 = getelementptr inbounds %struct.if_dqblk, %struct.if_dqblk* %10, i32 0, i32 0
store i64 %23, i64* %24
%25 = load i64, i64* %9
%26 = getelementptr inbounds %struct.if_dqblk, %struct.if_dqblk* %10, i32 0, i32 1
store i64 %25, i64* %26
%27 = load i32, i32* @QIF_LIMITS
%28 = getelementptr inbounds %struct.if_dqblk, %struct.if_dqblk* %10, i32 0, i32 2
store i32 %27, i32* %28
%29 = load i32, i32* @Q_SETQUOTA
%30 = call i32 @QCMD(i32 %29, i32 2)
%31 = load i8*, i8** %6
%32 = load i32, i32* %11
%33 = bitcast %struct.if_dqblk* %10 to i32*
%34 = call i64 @quotactl(i32 %30, i8* %31, i32 %32, i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %16
store i32 -1, i32* %5
br label %42
37: ; preds = %16
%38 = load i32, i32* @Q_SYNC
%39 = call i32 @QCMD(i32 %38, i32 2)
%40 = load i8*, i8** %6
%41 = call i64 @quotactl(i32 %39, i8* %40, i32 0, i32* null)
store i32 0, i32* %5
br label %42
42: ; preds = %37, %36, %15
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
%struct.if_dqblk = type { i64, i64, i32 }
@QIF_DQBLKSIZE = global i64 0
@QIF_LIMITS = global i32 0
@Q_SETQUOTA = global i32 0
@Q_SYNC = global i32 0
define i32 @ext4_resize_project(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca %struct.if_dqblk
%6 = alloca i32
%7 = bitcast %struct.if_dqblk* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i64 @get_project(i8* %1, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %4
%12 = call i32 @memset(%struct.if_dqblk* %5, i32 0, i32 24)
%13 = load i64, i64* @QIF_DQBLKSIZE
%14 = add i64 %2, -1
%15 = add i64 %14, %13
%16 = udiv i64 %15, %13
%17 = getelementptr inbounds %struct.if_dqblk, %struct.if_dqblk* %5, i64 0, i32 0
store i64 %16, i64* %17
%18 = getelementptr inbounds %struct.if_dqblk, %struct.if_dqblk* %5, i64 0, i32 1
store i64 %3, i64* %18
%19 = load i32, i32* @QIF_LIMITS
%20 = getelementptr inbounds %struct.if_dqblk, %struct.if_dqblk* %5, i64 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @Q_SETQUOTA
%22 = call i32 @QCMD(i32 %21, i32 2)
%23 = load i32, i32* %6
%24 = bitcast %struct.if_dqblk* %5 to i32*
%25 = call i64 @quotactl(i32 %22, i8* %0, i32 %23, i32* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %11
%28 = load i32, i32* @Q_SYNC
%29 = call i32 @QCMD(i32 %28, i32 2)
%30 = call i64 @quotactl(i32 %29, i8* %0, i32 0, i32* null)
br label %31
31: ; preds = %11, %4, %27
%32 = phi i32 [ 0, %27 ], [ -1, %4 ], [ -1, %11 ]
ret i32 %32
}