// File: /workspace/github_c_makefile_star2_O3/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 0x419a
movq %rax, 0x47c9(%rip)      # 0x82b8
leaq 0x20e(%rip), %rdi       # 0x3d04
callq 0x4260
movq 0x47b6(%rip), %rsi      # 0x82b8
movl $0x5000, %ecx           # imm = 0x5000
movq %r14, %rdi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x2180
testl %eax, %eax
js 0x3c8f
movq 0x4795(%rip), %rdi      # 0x82b8
callq 0x2190
testl %eax, %eax
js 0x3c98
xorl %edi, %edi
callq 0x22c0
movl %eax, %r14d
leaq 0x1aa9(%rip), %r15      # 0x55ea
movq %r15, %rdi
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
leaq 0x1a99(%rip), %rdi      # 0x55ee
leaq 0x1a98(%rip), %r8       # 0x55f4
movq %r15, %rsi
movq %rdi, %rdx
xorl %ecx, %ecx
callq 0x2180
testl %eax, %eax
js 0x3ca1
leaq 0x1ab8(%rip), %r15      # 0x5630
movq %r15, %rdi
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
leaq 0x1aac(%rip), %rdi      # 0x5638
leaq 0x1aac(%rip), %r8       # 0x563f
movq %r15, %rsi
movq %rdi, %rdx
xorl %ecx, %ecx
callq 0x2180
testl %eax, %eax
js 0x3caa
leaq 0x1b4d(%rip), %rdi      # 0x56fc
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
movl %r14d, %edi
callq 0x22c0
testl %ebp, %ebp
js 0x3bdb
movl %ebp, %edi
callq 0x2040
leaq 0x15a0(%rip), %rsi      # 0x5173
movq %rax, %rdi
callq 0x3d29
leaq 0x1aa6(%rip), %rdi      # 0x5688
leaq 0x1aa0(%rip), %rsi      # 0x5689
callq 0x3d29
leaq 0x1773(%rip), %rdi      # 0x5368
leaq 0x176d(%rip), %rsi      # 0x5369
callq 0x3d29
leaq 0x1a8a(%rip), %rdi      # 0x5692
leaq 0x1a84(%rip), %rsi      # 0x5693
callq 0x3d29
leaq 0x1a83(%rip), %rdi      # 0x569e
leaq 0x1a7d(%rip), %rsi      # 0x569f
callq 0x3d29
leaq 0x1a79(%rip), %rdi      # 0x56a7
leaq 0x1a73(%rip), %rsi      # 0x56a8
callq 0x3d29
leaq 0x1a73(%rip), %rdi      # 0x56b4
leaq 0x1a6d(%rip), %rsi      # 0x56b5
callq 0x3d29
leaq 0x1a6a(%rip), %rdi      # 0x56be
leaq 0x1a6c(%rip), %rsi      # 0x56c7
callq 0x21d0
testq %rbx, %rbx
je 0x3c84
callq 0x24c0
testl %eax, %eax
je 0x3cbd
cmpl $-0x1, %eax
je 0x3cf1
movl %eax, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x41e7
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x190d(%rip), %rsi      # 0x55a3
jmp 0x3cb1
leaq 0x1927(%rip), %rsi      # 0x55c6
jmp 0x3cb1
leaq 0x1956(%rip), %rsi      # 0x55fe
jmp 0x3cb1
leaq 0x19a7(%rip), %rsi      # 0x5658
movl $0x1, %edi
xorl %eax, %eax
callq 0x21b0
leaq 0x1390(%rip), %rdi      # 0x5054
leaq 0x1391(%rip), %rdx      # 0x505c
movq %rdi, %rsi
movq %rbx, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x2470
leaq 0x137d(%rip), %rsi      # 0x505f
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2310
leaq 0x133d(%rip), %rsi      # 0x5035
movl $0x1, %edi
xorl %eax, %eax
callq 0x2310