#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 stat {
  scalar_t__ st_dev;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int S_IFBLK;
int S_IXGRP;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ logger(int, int /*<<< orphan*/, char *, ...);
scalar_t__ mknod(char *, int, scalar_t__);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
scalar_t__ stat(char *, struct stat *);
scalar_t__ symlink(char *, char *);
int /*<<< orphan*/ unlink(char *);
char *vz_fs_get_name();
int mk_quota_link() {
  struct stat st;
  const char *fs;
  char buf[64];
  if (stat("/", &st)) {
    logger(-1, errno, "Unable to stat /");
    return -1;
  }
  fs = vz_fs_get_name();
  snprintf(buf, sizeof(buf), "/dev/%s", fs);
  unlink(buf);
  logger(3, 0, "Setup quota dev %s", buf);
  if (mknod(buf, S_IFBLK | S_IXGRP, st.st_dev))
    logger(-1, errno, "Unable to create %s", buf);
  snprintf(buf, sizeof(buf),
           "/proc/vz/vzaquota/"
           "%08lx"
           "/aquota.user",
           (unsigned long)st.st_dev);
  unlink("/aquota.user");
  if (symlink(buf, "/aquota.user"))
    logger(-1, errno, "Unable to create symlink %s", buf);
  snprintf(buf, sizeof(buf),
           "/proc/vz/vzaquota/"
           "%08lx"
           "/aquota.group",
           (unsigned long)st.st_dev);
  unlink("/aquota.group");
  if (symlink(buf, "/aquota.group"))
    logger(-1, errno, "Unable to create symlink %s", buf);
  return 0;
}


x86 assembly (clang, -O0):
<mk_quota_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xe90(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
je     11ba <mk_quota_link+0x4a>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
lea    0xe59(%rip),%rdx
mov    $0x0,%al
call   1080 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <mk_quota_link+0x1a4>
mov    $0x0,%al
call   1090 <vz_fs_get_name@plt>
mov    %rax,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x40,%esi
lea    0xe38(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    -0x60(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x60(%rbp),%rcx
mov    $0x3,%edi
xor    %esi,%esi
lea    0xe1e(%rip),%rdx
mov    $0x0,%al
call   1080 <logger@plt>
lea    -0x60(%rbp),%rdi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    0x2dd2(%rip),%rax
or     (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1070 <mknod@plt>
cmp    $0x0,%rax
je     124b <mk_quota_link+0xdb>
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xde8(%rip),%rdx
mov    $0x0,%al
call   1080 <logger@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x40,%esi
lea    0xde1(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    0xdea(%rip),%rdi
call   1030 <unlink@plt>
lea    -0x60(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1040 <symlink@plt>
cmp    $0x0,%rax
je     12ac <mk_quota_link+0x13c>
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xdbf(%rip),%rdx
mov    $0x0,%al
call   1080 <logger@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x40,%esi
lea    0xdc0(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    0xdc9(%rip),%rdi
call   1030 <unlink@plt>
lea    -0x60(%rbp),%rdi
lea    0xdb9(%rip),%rsi
call   1040 <symlink@plt>
cmp    $0x0,%rax
je     130d <mk_quota_link+0x19d>
mov    0x2cdc(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xd5e(%rip),%rdx
mov    $0x0,%al
call   1080 <logger@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mk_quota_link>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
lea    0xe8f(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
je     11b5 <mk_quota_link+0x45>
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdx
mov    $0xffffffff,%ebx
mov    $0xffffffff,%edi
xor    %eax,%eax
call   1080 <logger@plt>
jmp    1303 <mk_quota_link+0x193>
xor    %eax,%eax
call   1090 <vz_fs_get_name@plt>
lea    0xe4e(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0xe30(%rip),%rdx
mov    $0x3,%edi
xor    %esi,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <logger@plt>
mov    0x2dd7(%rip),%rax
mov    0x2de0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <mknod@plt>
test   %rax,%rax
je     123f <mk_quota_link+0xcf>
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
lea    0xdfe(%rip),%rdx
lea    0x10(%rsp),%rcx
mov    $0xffffffff,%edi
xor    %eax,%eax
call   1080 <logger@plt>
mov    0x8(%rsp),%rcx
lea    0xdf5(%rip),%rdx
xor    %ebx,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x40,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0xdef(%rip),%r15
mov    %r15,%rdi
call   1030 <unlink@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <symlink@plt>
test   %rax,%rax
je     12a1 <mk_quota_link+0x131>
mov    0x2d49(%rip),%rax
mov    (%rax),%esi
lea    0xdd4(%rip),%rdx
lea    0x10(%rsp),%rcx
mov    $0xffffffff,%edi
xor    %eax,%eax
call   1080 <logger@plt>
mov    0x8(%rsp),%rcx
lea    0xdd3(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x40,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0xdcf(%rip),%r15
mov    %r15,%rdi
call   1030 <unlink@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <symlink@plt>
test   %rax,%rax
je     1303 <mk_quota_link+0x193>
mov    0x2ce9(%rip),%rax
mov    (%rax),%esi
lea    0xd74(%rip),%rdx
xor    %ebx,%ebx
lea    0x10(%rsp),%rcx
mov    $0xffffffff,%edi
xor    %eax,%eax
call   1080 <logger@plt>
mov    %ebx,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [2 x i8] c"/\00"
@errno = global i32 0
@.str.1 = [17 x i8] c"Unable to stat /\00"
@.str.2 = [8 x i8] c"/dev/%s\00"
@.str.3 = [19 x i8] c"Setup quota dev %s\00"
@S_IFBLK = global i32 0
@S_IXGRP = global i32 0
@.str.4 = [20 x i8] c"Unable to create %s\00"
@.str.5 = [36 x i8] c"/proc/vz/vzaquota/%08lx/aquota.user\00"
@.str.6 = [13 x i8] c"/aquota.user\00"
@.str.7 = [28 x i8] c"Unable to create symlink %s\00"
@.str.8 = [37 x i8] c"/proc/vz/vzaquota/%08lx/aquota.group\00"
@.str.9 = [14 x i8] c"/aquota.group\00"
define i32 @mk_quota_link() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca i8*
%4 = alloca [64 x i8]
%5 = call i64 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %58
10: ; preds = %0
%11 = call i8* (...) @vz_fs_get_name()
store i8* %11, i8** %3
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %12, i32 64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%16 = call i32 @unlink(i8* %15)
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%18 = call i32 (i32, i32, i8*, ...) @logger(i32 3, i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%20 = load i32, i32* @S_IFBLK
%21 = load i32, i32* @S_IXGRP
%22 = or i32 %20, %21
%23 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%24 = load i64, i64* %23
%25 = call i64 @mknod(i8* %19, i32 %22, i64 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %10
%28 = load i32, i32* @errno
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%30 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %27, %10
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%33 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%34 = load i64, i64* %33
%35 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %32, i32 64, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i64 %34)
%36 = call i32 @unlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%38 = call i64 @symlink(i8* %37, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %31
%41 = load i32, i32* @errno
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%43 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %41, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %40, %31
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%46 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%47 = load i64, i64* %46
%48 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %45, i32 64, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i64 %47)
%49 = call i32 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%51 = call i64 @symlink(i8* %50, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %44
%54 = load i32, i32* @errno
%55 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%56 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %54, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %53, %44
store i32 0, i32* %1
br label %58
58: ; preds = %57, %7
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [2 x i8] c"/\00"
@errno = global i32 0
@.str.1 = [17 x i8] c"Unable to stat /\00"
@.str.2 = [8 x i8] c"/dev/%s\00"
@.str.3 = [19 x i8] c"Setup quota dev %s\00"
@S_IFBLK = global i32 0
@S_IXGRP = global i32 0
@.str.4 = [20 x i8] c"Unable to create %s\00"
@.str.5 = [36 x i8] c"/proc/vz/vzaquota/%08lx/aquota.user\00"
@.str.6 = [13 x i8] c"/aquota.user\00"
@.str.7 = [28 x i8] c"Unable to create symlink %s\00"
@.str.8 = [37 x i8] c"/proc/vz/vzaquota/%08lx/aquota.group\00"
@.str.9 = [14 x i8] c"/aquota.group\00"
define i32 @mk_quota_link() {
%1 = alloca %struct.stat
%2 = alloca [64 x i8]
%3 = bitcast %struct.stat* %1 to i8*
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = call i64 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %43
10: ; preds = %0
%11 = call i8* (...) @vz_fs_get_name()
%12 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = call i32 @unlink(i8* %4)
%14 = call i32 (i32, i32, i8*, ...) @logger(i32 3, i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%15 = load i32, i32* @S_IFBLK
%16 = load i32, i32* @S_IXGRP
%17 = or i32 %16, %15
%18 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%19 = load i64, i64* %18
%20 = call i64 @mknod(i8* %4, i32 %17, i64 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %10
%23 = load i32, i32* @errno
%24 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %23, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %25
25: ; preds = %22, %10
%26 = load i64, i64* %18
%27 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i64 %26)
%28 = call i32 @unlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%29 = call i64 @symlink(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %25
%32 = load i32, i32* @errno
%33 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %32, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %4)
br label %34
34: ; preds = %31, %25
%35 = load i64, i64* %18
%36 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i64 %35)
%37 = call i32 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%38 = call i64 @symlink(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %34
%41 = load i32, i32* @errno
%42 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %41, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %4)
br label %43
43: ; preds = %34, %40, %7
%44 = phi i32 [ -1, %7 ], [ 0, %40 ], [ 0, %34 ]
ret i32 %44
}