// File: /workspace/github_c_makefile_star2_O2/arachsys[P]containers/mount.c
// Function: createroot
void createroot(char *src, int console, char *helper) {
  mode_t mask;
  pid_t child;

  root = tmpdir();
  atexit(cleanup);

  if (mount(src, root, NULL, MS_BIND | MS_REC, NULL) < 0)
    errx(EXIT_FAILURE, "Failed to bind new root filesystem");
  else if (chdir(root) < 0)
    errx(EXIT_FAILURE, "Failed to enter new root filesystem");

  mask = umask(0);
  mkdir("dev" , 0755);
  if (mount("tmpfs", "dev", "tmpfs", 0, "mode=0755") < 0)
    errx(EXIT_FAILURE, "Failed to mount /dev tmpfs in new root filesystem");

  mkdir("dev/pts", 0755);
  if (mount("devpts", "dev/pts", "devpts", 0, "newinstance,ptmxmode=666") < 0)
    errx(EXIT_FAILURE, "Failed to mount /dev/pts in new root filesystem");

  mkdir("dev/tmp", 0755);
  umask(mask);

  if (console >= 0)
    bindnode(ptsname(console), "dev/console");
  bindnode("/dev/full", "dev/full");
  bindnode("/dev/null", "dev/null");
  bindnode("/dev/random", "dev/random");
  bindnode("/dev/tty", "dev/tty");
  bindnode("/dev/urandom", "dev/urandom");
  bindnode("/dev/zero", "dev/zero");
  symlink("pts/ptmx", "dev/ptmx");

  if (helper)
    switch (child = fork()) {
      case -1:
        err(EXIT_FAILURE, "fork");
      case 0:
        execlp(SHELL, SHELL, "-c", helper, NULL);
        err(EXIT_FAILURE, "exec %s", helper);
      default:
        waitforexit(child);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
callq 0x3f09
movq %rax, 0x3a31(%rip)      # 0x72b8
leaq 0x208(%rip), %rdi       # 0x3a96
callq 0x3fc0
movq 0x3a1e(%rip), %rsi      # 0x72b8
movl $0x5000, %ecx           # imm = 0x5000
movq %r14, %rdi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x2180
testl %eax, %eax
js 0x3a27
movq 0x39fd(%rip), %rdi      # 0x72b8
callq 0x2190
testl %eax, %eax
js 0x3a30
xorl %edi, %edi
callq 0x22c0
movl %eax, %r14d
leaq 0xd11(%rip), %r15       # 0x45ea
movq %r15, %rdi
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
leaq 0xd01(%rip), %rdi       # 0x45ee
leaq 0xd00(%rip), %r8        # 0x45f4
movq %r15, %rsi
movq %rdi, %rdx
xorl %ecx, %ecx
callq 0x2180
testl %eax, %eax
js 0x3a39
leaq 0xd20(%rip), %r15       # 0x4630
movq %r15, %rdi
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
leaq 0xd14(%rip), %rdi       # 0x4638
leaq 0xd14(%rip), %r8        # 0x463f
movq %r15, %rsi
movq %rdi, %rdx
xorl %ecx, %ecx
callq 0x2180
testl %eax, %eax
js 0x3a42
leaq 0xdb5(%rip), %rdi       # 0x46fc
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
movl %r14d, %edi
callq 0x22c0
testl %ebp, %ebp
js 0x3973
movl %ebp, %edi
callq 0x2040
leaq 0x808(%rip), %rsi       # 0x4173
movq %rax, %rdi
callq 0x3ab9
leaq 0xd0e(%rip), %rdi       # 0x4688
leaq 0xd08(%rip), %rsi       # 0x4689
callq 0x3ab9
leaq 0x9db(%rip), %rdi       # 0x4368
leaq 0x9d5(%rip), %rsi       # 0x4369
callq 0x3ab9
leaq 0xcf2(%rip), %rdi       # 0x4692
leaq 0xcec(%rip), %rsi       # 0x4693
callq 0x3ab9
leaq 0xceb(%rip), %rdi       # 0x469e
leaq 0xce5(%rip), %rsi       # 0x469f
callq 0x3ab9
leaq 0xce1(%rip), %rdi       # 0x46a7
leaq 0xcdb(%rip), %rsi       # 0x46a8
callq 0x3ab9
leaq 0xcdb(%rip), %rdi       # 0x46b4
leaq 0xcd5(%rip), %rsi       # 0x46b5
callq 0x3ab9
leaq 0xcd2(%rip), %rdi       # 0x46be
leaq 0xcd4(%rip), %rsi       # 0x46c7
callq 0x21d0
testq %rbx, %rbx
je 0x3a1c
callq 0x24c0
testl %eax, %eax
je 0x3a53
cmpl $-0x1, %eax
je 0x3a85
movl %eax, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3f52
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb75(%rip), %rsi       # 0x45a3
jmp 0x3a49
leaq 0xb8f(%rip), %rsi       # 0x45c6
jmp 0x3a49
leaq 0xbbe(%rip), %rsi       # 0x45fe
jmp 0x3a49
leaq 0xc0f(%rip), %rsi       # 0x4658
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x21b0
leaq 0x5fa(%rip), %rdi       # 0x4054
leaq 0x5fb(%rip), %rdx       # 0x405c
movq %rdi, %rsi
movq %rbx, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x2470
leaq 0x5e7(%rip), %rsi       # 0x405f
pushq $0x1
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2310
leaq 0x5a9(%rip), %rsi       # 0x4035
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x2310