#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 {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int MS_BIND;
int MS_REC;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int mount(char const *, char const *, int /*<<< orphan*/, int,
          int /*<<< orphan*/);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *);
int stat(char const *, struct stat *);
int checked_mount(const char *source, const char *target) {
  struct stat mount_data;
  if (stat(target, &mount_data) == -1) {
    printf("Stat error on dir: %s\n", target);
    perror(0);
  }
  if (!S_ISDIR(mount_data.st_mode)) {
    printf("Error, %s is not directory (or found)\n", target);
    exit(1);
  }
  return mount(source, target, 0, MS_BIND | MS_REC, 0);
}


x86 assembly (clang, -O0):
<checked_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    119d <checked_mount+0x3d>
mov    -0x10(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <perror@plt>
mov    -0x18(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    11c8 <checked_mount+0x68>
mov    -0x10(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e11(%rip),%rax
mov    (%rax),%ecx
mov    0x2e00(%rip),%rax
or     (%rax),%ecx
xor    %r8d,%r8d
mov    %r8d,%edx
call   1030 <mount@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checked_mount>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    1190 <checked_mount+0x30>
lea    0xe7f(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <perror@plt>
mov    (%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %eax,%eax
je     11c5 <checked_mount+0x65>
mov    0x2e45(%rip),%rax
mov    0x2e36(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %r8d,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <mount@plt>
lea    0xe4b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [23 x i8] c"Stat error on dir: %s\0A\00"
@.str.1 = [39 x i8] c"Error, %s is not directory (or found)\0A\00"
@MS_BIND = global i32 0
@MS_REC = global i32 0
define i32 @checked_mount(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i32 @stat(i8* %6, %struct.stat* %5)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32 @perror(i32 0)
br label %13
13: ; preds = %9, %2
%14 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @S_ISDIR(i32 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i8*, i8** %3
%24 = load i8*, i8** %4
%25 = load i32, i32* @MS_BIND
%26 = load i32, i32* @MS_REC
%27 = or i32 %25, %26
%28 = call i32 @mount(i8* %23, i8* %24, i32 0, i32 %27, i32 0)
ret i32 %28
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [23 x i8] c"Stat error on dir: %s\0A\00"
@.str.1 = [39 x i8] c"Error, %s is not directory (or found)\0A\00"
@MS_BIND = global i32 0
@MS_REC = global i32 0
define i32 @checked_mount(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @stat(i8* %1, %struct.stat* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = tail call i32 @perror(i32 0)
br label %10
10: ; preds = %7, %2
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @S_ISDIR(i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = load i32, i32* @MS_BIND
%20 = load i32, i32* @MS_REC
%21 = or i32 %20, %19
%22 = tail call i32 @mount(i8* %0, i8* %1, i32 0, i32 %21, i32 0)
ret i32 %22
}