#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 */

/* Variables and functions */
scalar_t__ EEXIST;
int /*<<< orphan*/ S_IRWXU;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, ...);
scalar_t__ mkdir(char const *, int /*<<< orphan*/);
scalar_t__ mount(char const *, char const *, char const *, unsigned long,
                 void const *);
int /*<<< orphan*/ rmdir(char const *);
int /*<<< orphan*/ stderr;
int create_and_mount(const char *source, const char *target, const char *fstype,
                     unsigned long flags, const void *data) {
  if (mkdir(target, S_IRWXU) != 0 && errno != EEXIST) {
    fprintf(stderr, "Cannot create directory %s (error code %d)\n", target,
            errno);
    return -1;
  }
  int new_directory = errno == EEXIST ? 0 : 1;
  if (mount(source, target, fstype, flags, data) != 0) {
    fprintf(stderr, "Cannot mount %s on %s with fstype %s (error code %d)\n",
            source, target, fstype, errno);
    if (new_directory) {
      rmdir(target);
    }
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<create_and_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     11c3 <create_and_mount+0x83>
mov    0x2e49(%rip),%rax
mov    (%rax),%rax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%rax
je     11c3 <create_and_mount+0x83>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    0x2e22(%rip),%rax
mov    (%rax),%rcx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125d <create_and_mount+0x11d>
mov    0x2dfe(%rip),%rax
mov    (%rax),%rdx
mov    0x2e04(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    %rsi,%rdx
cmove  %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1050 <mount@plt>
cmp    $0x0,%rax
je     1256 <create_and_mount+0x116>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    0x2da2(%rip),%rax
mov    (%rax),%r9
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmpl   $0x0,-0x34(%rbp)
je     124a <create_and_mount+0x10a>
mov    -0x18(%rbp),%rdi
call   1040 <rmdir@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125d <create_and_mount+0x11d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_and_mount>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,(%rsp)
mov    %rcx,%rbp
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%r12
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <mkdir@plt>
mov    0x2e55(%rip),%rcx
mov    (%rcx),%r15
mov    0x2e5b(%rip),%rcx
mov    (%rcx),%r14
test   %rax,%rax
je     118d <create_and_mount+0x4d>
cmp    %r14,%r15
mov    %r15,%r14
jne    11e5 <create_and_mount+0xa5>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
mov    (%rsp),%r8
call   1050 <mount@plt>
test   %rax,%rax
je     1209 <create_and_mount+0xc9>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%r9
lea    0xe6b(%rip),%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebp
cmp    %r14,%r15
je     120b <create_and_mount+0xcb>
mov    %rbx,%rdi
call   1040 <rmdir@plt>
jmp    120b <create_and_mount+0xcb>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    120b <create_and_mount+0xcb>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@S_IRWXU = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [44 x i8] c"Cannot create directory %s (error code %d)\0A\00"
@.str.1 = [54 x i8] c"Cannot mount %s on %s with fstype %s (error code %d)\0A\00"
define i32 @create_and_mount(i8* %0, i8* %1, i8* %2, i64 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i8* %4, i8** %11
%13 = load i8*, i8** %8
%14 = load i32, i32* @S_IRWXU
%15 = call i64 @mkdir(i8* %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %5
%18 = load i64, i64* @errno
%19 = load i64, i64* @EEXIST
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %8
%24 = load i64, i64* @errno
%25 = inttoptr i64 %24 to i8*
%26 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %25)
store i32 -1, i32* %6
br label %54
27: ; preds = %17, %5
%28 = load i64, i64* @errno
%29 = load i64, i64* @EEXIST
%30 = icmp eq i64 %28, %29
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 0, i32 1
store i32 %32, i32* %12
%33 = load i8*, i8** %7
%34 = load i8*, i8** %8
%35 = load i8*, i8** %9
%36 = load i64, i64* %10
%37 = load i8*, i8** %11
%38 = call i64 @mount(i8* %33, i8* %34, i8* %35, i64 %36, i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %53
40: ; preds = %27
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %7
%43 = load i8*, i8** %8
%44 = load i8*, i8** %9
%45 = load i64, i64* @errno
%46 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %43, i8* %44, i64 %45)
%47 = load i32, i32* %12
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %40
%50 = load i8*, i8** %8
%51 = call i32 @rmdir(i8* %50)
br label %52
52: ; preds = %49, %40
store i32 -1, i32* %6
br label %54
53: ; preds = %27
store i32 0, i32* %6
br label %54
54: ; preds = %53, %52, %21
%55 = load i32, i32* %6
ret i32 %55
}

LLVM IR (-O2):
@S_IRWXU = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [44 x i8] c"Cannot create directory %s (error code %d)\0A\00"
@.str.1 = [54 x i8] c"Cannot mount %s on %s with fstype %s (error code %d)\0A\00"
define i32 @create_and_mount(i8* %0, i8* %1, i8* %2, i64 %3, i8* %4) {
%6 = load i32, i32* @S_IRWXU
%7 = tail call i64 @mkdir(i8* %1, i32 %6)
%8 = icmp eq i64 %7, 0
%9 = load i64, i64* @errno
%10 = load i64, i64* @EEXIST
br i1 %8, label %17, label %11
11: ; preds = %5
%12 = icmp eq i64 %9, %10
br i1 %12, label %17, label %13
13: ; preds = %11
%14 = load i32, i32* @stderr
%15 = inttoptr i64 %9 to i8*
%16 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %15)
br label %28
17: ; preds = %5, %11
%18 = phi i64 [ %9, %11 ], [ %10, %5 ]
%19 = tail call i64 @mount(i8* %0, i8* %1, i8* %2, i64 %3, i8* %4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %17
%22 = icmp eq i64 %9, %18
%23 = load i32, i32* @stderr
%24 = load i64, i64* @errno
%25 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* %2, i64 %24)
br i1 %22, label %28, label %26
26: ; preds = %21
%27 = tail call i32 @rmdir(i8* %1)
br label %28
28: ; preds = %26, %21, %17, %13
%29 = phi i32 [ -1, %13 ], [ -1, %26 ], [ -1, %21 ], [ 0, %17 ]
ret i32 %29
}