#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 PATH_MAX;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *, char const *, ...);
int maybe_mkdir(char *, int);
int mount(char const *, char *, char const *, unsigned long,
          int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *const, char const *);
void target_mount(char *const rootfs, const char *dir, const char *typ,
                  unsigned long flags) {
  char d[PATH_MAX];
  int r;
  snprintf(d, sizeof d, "%s%s", rootfs, dir);
  r = maybe_mkdir(d, 0611);
  if (r < 0)
    error(1, errno, "can't mkdir %s", d);
  r = mount(typ, d, typ, flags, 0);
  if (r < 0)
    error(1, errno, "can't mount %s under %s", dir, rootfs);
}


x86 assembly (clang, -O0):
<target_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe6b(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rdi
mov    $0x189,%esi
call   1050 <maybe_mkdir@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11d5 <target_mount+0x95>
mov    -0x40(%rbp),%rcx
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe37(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
xor    %r8d,%r8d
call   1030 <mount@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    121e <target_mount+0xde>
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    $0x1,%edi
lea    0xdfd(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<target_mount>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe82(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    $0x189,%esi
call   1050 <maybe_mkdir@plt>
test   %eax,%eax
jns    11bc <target_mount+0x7c>
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
lea    0xe58(%rip),%rdx
mov    $0x1,%edi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <error@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
xor    %r8d,%r8d
call   1030 <mount@plt>
test   %eax,%eax
jns    11f6 <target_mount+0xb6>
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    0xe30(%rip),%rdx
mov    $0x1,%edi
mov    %r14,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1060 <error@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"%s%s\00"
@errno = global i32 0
@.str.1 = [15 x i8] c"can't mkdir %s\00"
@.str.2 = [24 x i8] c"can't mount %s under %s\00"
define void @target_mount(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%12 = load i32, i32* @PATH_MAX
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %9
%15 = alloca i8, i64 %13
store i64 %13, i64* %10
%16 = trunc i64 %13 to i32
%17 = load i8*, i8** %5
%18 = load i8*, i8** %6
%19 = call i32 @snprintf(i8* %15, i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18)
%20 = call i32 @maybe_mkdir(i8* %15, i32 393)
store i32 %20, i32* %11
%21 = load i32, i32* %11
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %4
%24 = load i32, i32* @errno
%25 = call i32 (i32, i32, i8*, i8*, ...) @error(i32 1, i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %26
26: ; preds = %23, %4
%27 = load i8*, i8** %7
%28 = load i8*, i8** %7
%29 = load i64, i64* %8
%30 = call i32 @mount(i8* %27, i8* %15, i8* %28, i64 %29, i32 0)
store i32 %30, i32* %11
%31 = load i32, i32* %11
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %26
%34 = load i32, i32* @errno
%35 = load i8*, i8** %6
%36 = load i8*, i8** %5
%37 = call i32 (i32, i32, i8*, i8*, ...) @error(i32 1, i32 %34, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %36)
br label %38
38: ; preds = %33, %26
%39 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"%s%s\00"
@errno = global i32 0
@.str.1 = [15 x i8] c"can't mkdir %s\00"
@.str.2 = [24 x i8] c"can't mount %s under %s\00"
define void @target_mount(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @snprintf(i8* %7, i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = call i32 @maybe_mkdir(i8* %7, i32 393)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = load i32, i32* @errno
%13 = call i32 (i32, i32, i8*, i8*, ...) @error(i32 1, i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %14
14: ; preds = %11, %4
%15 = call i32 @mount(i8* %2, i8* %7, i8* %2, i64 %3, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @errno
%19 = call i32 (i32, i32, i8*, i8*, ...) @error(i32 1, i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %0)
br label %20
20: ; preds = %17, %14
ret void
}