#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_MGC_VAL;
char *malloc(int);
scalar_t__ mount(char *, char *, int /*<<< orphan*/ *, int,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
char *strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int bind_mount(char *path, char *dir) {
  char *tmp_path;
  tmp_path = malloc(512 * sizeof(char));
  strcpy(tmp_path, path);
  strcpy(tmp_path, strcat(tmp_path, dir));
  if (mount(dir, tmp_path, NULL, MS_MGC_VAL | MS_BIND, NULL) != 0) {
    printf("error: mounting\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<bind_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e2d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e34(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   1040 <mount@plt>
cmp    $0x0,%rax
je     11e5 <bind_mount+0x95>
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ec <bind_mount+0x9c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bind_mount>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    0x2e48(%rip),%rax
mov    0x2e51(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %r15d,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %r8d,%r8d
call   1050 <mount@plt>
test   %rax,%rax
je     11c5 <bind_mount+0x75>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@MS_MGC_VAL = global i32 0
@MS_BIND = global i32 0
@.str = [17 x i8] c"error: mounting\0A\00"
define i32 @bind_mount(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = call i8* @malloc(i32 512)
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = load i8*, i8** %4
%10 = call i32 @strcpy(i8* %8, i8* %9)
%11 = load i8*, i8** %6
%12 = load i8*, i8** %6
%13 = load i8*, i8** %5
%14 = call i8* @strcat(i8* %12, i8* %13)
%15 = call i32 @strcpy(i8* %11, i8* %14)
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = load i32, i32* @MS_MGC_VAL
%19 = load i32, i32* @MS_BIND
%20 = or i32 %18, %19
%21 = call i64 @mount(i8* %16, i8* %17, i32* null, i32 %20, i32* null)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %26
25: ; preds = %2
store i32 0, i32* %3
br label %26
26: ; preds = %25, %23
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@MS_MGC_VAL = global i32 0
@MS_BIND = global i32 0
@str = [16 x i8] c"error: mounting\00"
define i32 @bind_mount(i8* %0, i8* %1) {
%3 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%4 = tail call i32 @strcpy(i8* %3, i8* %0)
%5 = tail call i8* @strcat(i8* dereferenceable(1) %3, i8* dereferenceable(1) %1)
%6 = tail call i32 @strcpy(i8* %3, i8* %3)
%7 = load i32, i32* @MS_MGC_VAL
%8 = load i32, i32* @MS_BIND
%9 = or i32 %8, %7
%10 = tail call i64 @mount(i8* %1, i8* %3, i32* null, i32 %9, i32* null)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %2, %12
%15 = phi i32 [ 1, %12 ], [ 0, %2 ]
ret i32 %15
}