#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 */
int MS_BIND;
int MS_RDONLY;
int MS_REC;
int MS_REMOUNT;
int /*<<< orphan*/ free(char *);
int mount(char *, char *, char *, int, char *);
char *path_parts(char const **);
int /*<<< orphan*/ perror(char *);
int mountbind_parts(const char **src, const char **target, int ro) {
  char *src_path, *target_path;
  int ret;
  if ((src_path = path_parts(src)) == NULL ||
      (target_path = path_parts(target)) == NULL) {
    free(src_path);
    return -1;
  }
  ret = mount(src_path, target_path, "", MS_BIND | MS_REC, "");
  if (ret != 0) {
    perror("mount failed");
  }
  if (ro != 0 && ret == 0) {
    ret = mount("", target_path, "", MS_REMOUNT | MS_BIND | MS_RDONLY, "");
  }
  free(target_path);
  free(src_path);
  return ret;
}


x86 assembly (clang, -O0):
<mountbind_parts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <path_parts@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1181 <mountbind_parts+0x41>
mov    -0x18(%rbp),%rdi
call   1050 <path_parts@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1196 <mountbind_parts+0x56>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1238 <mountbind_parts+0xf8>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2e43(%rip),%rax
mov    (%rax),%ecx
mov    0x2e32(%rip),%rax
or     (%rax),%ecx
lea    0xe55(%rip),%r8
mov    %r8,%rdx
call   1040 <mount@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11d8 <mountbind_parts+0x98>
lea    0xe2d(%rip),%rdi
call   1060 <perror@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1220 <mountbind_parts+0xe0>
cmpl   $0x0,-0x34(%rbp)
jne    1220 <mountbind_parts+0xe0>
mov    -0x30(%rbp),%rsi
mov    0x2dd1(%rip),%rax
mov    (%rax),%ecx
mov    0x2de8(%rip),%rax
or     (%rax),%ecx
mov    0x2dcf(%rip),%rax
or     (%rax),%ecx
lea    0xdfa(%rip),%r8
mov    %r8,%rdi
mov    %r8,%rdx
call   1040 <mount@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mountbind_parts>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%rbp
call   1050 <path_parts@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11cc <mountbind_parts+0x8c>
mov    %rbp,%rdi
call   1050 <path_parts@plt>
test   %rax,%rax
je     11cc <mountbind_parts+0x8c>
mov    %rax,%r14
mov    0x2e76(%rip),%r12
mov    0x2e67(%rip),%rax
mov    (%rax),%ecx
or     (%r12),%ecx
lea    0xe86(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rdx,%r8
call   1040 <mount@plt>
test   %eax,%eax
jne    11f8 <mountbind_parts+0xb8>
test   %r15d,%r15d
je     11db <mountbind_parts+0x9b>
mov    0x2e24(%rip),%rax
mov    (%r12),%ecx
or     (%rax),%ecx
mov    0x2e27(%rip),%rax
or     (%rax),%ecx
lea    0xe52(%rip),%rdi
mov    %r14,%rsi
mov    %rdi,%rdx
mov    %rdi,%r8
call   1040 <mount@plt>
mov    %eax,%ebp
jmp    11dd <mountbind_parts+0x9d>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%ebp
jmp    11ed <mountbind_parts+0xad>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0xdff(%rip),%rdi
call   1060 <perror@plt>
jmp    11dd <mountbind_parts+0x9d>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@MS_BIND = global i32 0
@MS_REC = global i32 0
@.str.1 = [13 x i8] c"mount failed\00"
@MS_REMOUNT = global i32 0
@MS_RDONLY = global i32 0
define i32 @mountbind_parts(i8** %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8** %0, i8*** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%11 = load i8**, i8*** %5
%12 = call i8* @path_parts(i8** %11)
store i8* %12, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %18, label %14
14: ; preds = %3
%15 = load i8**, i8*** %6
%16 = call i8* @path_parts(i8** %15)
store i8* %16, i8** %9
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14, %3
%19 = load i8*, i8** %8
%20 = call i32 @free(i8* %19)
store i32 -1, i32* %4
br label %52
21: ; preds = %14
%22 = load i8*, i8** %8
%23 = load i8*, i8** %9
%24 = load i32, i32* @MS_BIND
%25 = load i32, i32* @MS_REC
%26 = or i32 %24, %25
%27 = call i32 @mount(i8* %22, i8* %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 %26, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %27, i32* %10
%28 = load i32, i32* %10
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %21
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %46
35: ; preds = %32
%36 = load i32, i32* %10
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %35
%39 = load i8*, i8** %9
%40 = load i32, i32* @MS_REMOUNT
%41 = load i32, i32* @MS_BIND
%42 = or i32 %40, %41
%43 = load i32, i32* @MS_RDONLY
%44 = or i32 %42, %43
%45 = call i32 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %39, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 %44, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %45, i32* %10
br label %46
46: ; preds = %38, %35, %32
%47 = load i8*, i8** %9
%48 = call i32 @free(i8* %47)
%49 = load i8*, i8** %8
%50 = call i32 @free(i8* %49)
%51 = load i32, i32* %10
store i32 %51, i32* %4
br label %52
52: ; preds = %46, %18
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@MS_BIND = global i32 0
@MS_REC = global i32 0
@.str.1 = [13 x i8] c"mount failed\00"
@MS_REMOUNT = global i32 0
@MS_RDONLY = global i32 0
define i32 @mountbind_parts(i8** %0, i8** %1, i32 %2) {
%4 = tail call i8* @path_parts(i8** %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i8* @path_parts(i8** %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6, %3
%10 = tail call i32 @free(i8* %4)
br label %32
11: ; preds = %6
%12 = load i32, i32* @MS_BIND
%13 = load i32, i32* @MS_REC
%14 = or i32 %13, %12
%15 = tail call i32 @mount(i8* %4, i8* %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %28
19: ; preds = %11
%20 = icmp eq i32 %2, 0
br i1 %20, label %28, label %21
21: ; preds = %19
%22 = load i32, i32* @MS_REMOUNT
%23 = load i32, i32* @MS_BIND
%24 = or i32 %23, %22
%25 = load i32, i32* @MS_RDONLY
%26 = or i32 %24, %25
%27 = tail call i32 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 %26, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %17, %21, %19
%29 = phi i32 [ %27, %21 ], [ 0, %19 ], [ %15, %17 ]
%30 = tail call i32 @free(i8* %7)
%31 = tail call i32 @free(i8* %4)
br label %32
32: ; preds = %28, %9
%33 = phi i32 [ -1, %9 ], [ %29, %28 ]
ret i32 %33
}