// File: /workspace/github_c_makefile_star2_O1/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 0x420e
movq %rax, 0x475d(%rip)      # 0x82c0
leaq 0x20e(%rip), %rdi       # 0x3d78
callq 0x42d0
movq 0x474a(%rip), %rsi      # 0x82c0
movl $0x5000, %ecx           # imm = 0x5000
movq %r14, %rdi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x2180
testl %eax, %eax
js 0x3d03
movq 0x4729(%rip), %rdi      # 0x82c0
callq 0x2190
testl %eax, %eax
js 0x3d0c
xorl %edi, %edi
callq 0x22d0
movl %eax, %r14d
leaq 0x1a3b(%rip), %r15      # 0x55f0
movq %r15, %rdi
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
leaq 0x1a2b(%rip), %rdi      # 0x55f4
leaq 0x1a2a(%rip), %r8       # 0x55fa
movq %r15, %rsi
movq %rdi, %rdx
xorl %ecx, %ecx
callq 0x2180
testl %eax, %eax
js 0x3d15
leaq 0x1a4a(%rip), %r15      # 0x5636
movq %r15, %rdi
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
leaq 0x1a3e(%rip), %rdi      # 0x563e
leaq 0x1a3e(%rip), %r8       # 0x5645
movq %r15, %rsi
movq %rdi, %rdx
xorl %ecx, %ecx
callq 0x2180
testl %eax, %eax
js 0x3d1e
leaq 0x1adf(%rip), %rdi      # 0x5702
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
movl %r14d, %edi
callq 0x22d0
testl %ebp, %ebp
js 0x3c4f
movl %ebp, %edi
callq 0x2040
leaq 0x152c(%rip), %rsi      # 0x5173
movq %rax, %rdi
callq 0x3d9d
leaq 0x1a38(%rip), %rdi      # 0x568e
leaq 0x1a32(%rip), %rsi      # 0x568f
callq 0x3d9d
leaq 0x16ff(%rip), %rdi      # 0x5368
leaq 0x16f9(%rip), %rsi      # 0x5369
callq 0x3d9d
leaq 0x1a1c(%rip), %rdi      # 0x5698
leaq 0x1a16(%rip), %rsi      # 0x5699
callq 0x3d9d
leaq 0x1a15(%rip), %rdi      # 0x56a4
leaq 0x1a0f(%rip), %rsi      # 0x56a5
callq 0x3d9d
leaq 0x1a0b(%rip), %rdi      # 0x56ad
leaq 0x1a05(%rip), %rsi      # 0x56ae
callq 0x3d9d
leaq 0x1a05(%rip), %rdi      # 0x56ba
leaq 0x19ff(%rip), %rsi      # 0x56bb
callq 0x3d9d
leaq 0x19fc(%rip), %rdi      # 0x56c4
leaq 0x19fe(%rip), %rsi      # 0x56cd
callq 0x21d0
testq %rbx, %rbx
je 0x3cf8
callq 0x24d0
testl %eax, %eax
je 0x3d31
cmpl $-0x1, %eax
je 0x3d65
movl %eax, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x425b
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x189f(%rip), %rsi      # 0x55a9
jmp 0x3d25
leaq 0x18b9(%rip), %rsi      # 0x55cc
jmp 0x3d25
leaq 0x18e8(%rip), %rsi      # 0x5604
jmp 0x3d25
leaq 0x1939(%rip), %rsi      # 0x565e
movl $0x1, %edi
xorl %eax, %eax
callq 0x21b0
leaq 0x131c(%rip), %rdi      # 0x5054
leaq 0x131d(%rip), %rdx      # 0x505c
movq %rdi, %rsi
movq %rbx, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x2480
leaq 0x1309(%rip), %rsi      # 0x505f
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2320
leaq 0x12c9(%rip), %rsi      # 0x5035
movl $0x1, %edi
xorl %eax, %eax
callq 0x2320