#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 st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ MS_BIND;
int S_ISVTX;
int /*<<< orphan*/ W_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ err(int, char *, ...);
int /*<<< orphan*/ errx(int, char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ mount(char *, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                 int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "usage: 9bind old new\n");
    return 1;
  }
  char *old = argv[1];
  char *new = argv[2];
  struct stat st;
  if (stat(new, &st) || access(new, W_OK))
    err(1, "%s", new);
  if (st.st_mode & S_ISVTX)
    errx(1, "%s: refusing to bind over sticky directory", new);
  if (mount(old, new, 0, MS_BIND, 0))
    err(1, "mount");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a1 <main+0x41>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126d <main+0x10d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jne    11ec <main+0x8c>
mov    -0x20(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0x0,%rax
je     1203 <main+0xa3>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1070 <err@plt>
mov    -0x28(%rbp),%eax
mov    0x2ddb(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     122d <main+0xcd>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xdf1(%rip),%rsi
call   1040 <errx@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2da4(%rip),%rax
mov    (%rax),%ecx
xor    %r8d,%r8d
mov    %r8d,%edx
call   1030 <mount@plt>
cmp    $0x0,%rax
je     1266 <main+0x106>
mov    $0x1,%edi
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   1070 <err@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    120f <main+0xaf>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
test   %rax,%rax
jne    11a1 <main+0x41>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <access@plt>
test   %rax,%rax
je     11b7 <main+0x57>
lea    0xe6e(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <err@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
test   %eax,0x8(%rsp)
je     11da <main+0x7a>
lea    0xe4c(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
call   1040 <errx@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%ecx
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %r8d,%r8d
call   1030 <mount@plt>
test   %rax,%rax
je     1229 <main+0xc9>
lea    0xe43(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <err@plt>
jmp    1229 <main+0xc9>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"usage: 9bind old new\0A\00"
@W_OK = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@S_ISVTX = global i32 0
@.str.2 = [43 x i8] c"%s: refusing to bind over sticky directory\00"
@MS_BIND = global i32 0
@.str.3 = [6 x i8] c"mount\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %50
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = call i64 @stat(i8* %21, %struct.stat* %8)
%23 = icmp ne i64 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %14
%25 = load i8*, i8** %7
%26 = load i32, i32* @W_OK
%27 = call i64 @access(i8* %25, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24, %14
%30 = load i8*, i8** %7
%31 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %24
%33 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%34 = load i32, i32* %33
%35 = load i32, i32* @S_ISVTX
%36 = and i32 %34, %35
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = load i8*, i8** %7
%40 = call i32 @errx(i32 1, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38, %32
%42 = load i8*, i8** %6
%43 = load i8*, i8** %7
%44 = load i32, i32* @MS_BIND
%45 = call i64 @mount(i8* %42, i8* %43, i32 0, i32 %44, i32 0)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %41
store i32 0, i32* %3
br label %50
50: ; preds = %49, %11
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"usage: 9bind old new\0A\00"
@W_OK = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@S_ISVTX = global i32 0
@.str.2 = [43 x i8] c"%s: refusing to bind over sticky directory\00"
@MS_BIND = global i32 0
@.str.3 = [6 x i8] c"mount\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp eq i32 %0, 3
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %37
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = bitcast %struct.stat* %3 to i8*
%14 = call i64 @stat(i8* %12, %struct.stat* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %8
%17 = load i32, i32* @W_OK
%18 = call i64 @access(i8* %12, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16, %8
%21 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %22
22: ; preds = %20, %16
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%24 = load i32, i32* %23
%25 = load i32, i32* @S_ISVTX
%26 = and i32 %25, %24
%27 = icmp eq i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %22
%29 = call i32 @errx(i32 1, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %30
30: ; preds = %28, %22
%31 = load i32, i32* @MS_BIND
%32 = call i64 @mount(i8* %10, i8* %12, i32 0, i32 %31, i32 0)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
br label %37
37: ; preds = %36, %5
%38 = phi i32 [ 1, %5 ], [ 0, %36 ]
ret i32 %38
}