// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
callq 0x4800
movq %rax, 0x42c1(%rip)      # 0x82c0
leaq 0x23a(%rip), %rdi       # 0x4240
callq 0x4920
movq -0x8(%rbp), %rdi
movq 0x42aa(%rip), %rsi      # 0x82c0
xorl %eax, %eax
movl %eax, %r8d
movl $0x5000, %ecx           # imm = 0x5000
movq %r8, %rdx
callq 0x2180
cmpl $0x0, %eax
jge 0x4040
movl $0x1, %edi
leaq 0x1598(%rip), %rsi      # 0x55d1
movb $0x0, %al
callq 0x21b0
movq 0x4279(%rip), %rdi      # 0x82c0
callq 0x2190
cmpl $0x0, %eax
jge 0x4064
movl $0x1, %edi
leaq 0x1597(%rip), %rsi      # 0x55f4
movb $0x0, %al
callq 0x21b0
jmp 0x4066
xorl %edi, %edi
callq 0x22d0
movl %eax, -0x1c(%rbp)
leaq 0x15a1(%rip), %rdi      # 0x5618
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
leaq 0x1594(%rip), %rdx      # 0x561c
leaq 0x1589(%rip), %rsi      # 0x5618
xorl %eax, %eax
movl %eax, %ecx
leaq 0x1588(%rip), %r8       # 0x5622
movq %rdx, %rdi
callq 0x2180
cmpl $0x0, %eax
jge 0x40ba
movl $0x1, %edi
leaq 0x1579(%rip), %rsi      # 0x562c
movb $0x0, %al
callq 0x21b0
leaq 0x159d(%rip), %rdi      # 0x565e
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
leaq 0x1594(%rip), %rdx      # 0x5666
leaq 0x1585(%rip), %rsi      # 0x565e
xorl %eax, %eax
movl %eax, %ecx
leaq 0x1589(%rip), %r8       # 0x566d
movq %rdx, %rdi
callq 0x2180
cmpl $0x0, %eax
jge 0x4104
movl $0x1, %edi
leaq 0x1589(%rip), %rsi      # 0x5686
movb $0x0, %al
callq 0x21b0
leaq 0x161f(%rip), %rdi      # 0x572a
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x20b0
movl -0x1c(%rbp), %edi
callq 0x22d0
cmpl $0x0, -0xc(%rbp)
jl 0x413a
movl -0xc(%rbp), %edi
callq 0x2040
movq %rax, %rdi
leaq 0x1066(%rip), %rsi      # 0x519b
callq 0x4270
leaq 0x1575(%rip), %rdi      # 0x56b6
leaq 0x156f(%rip), %rsi      # 0x56b7
callq 0x4270
leaq 0x123c(%rip), %rdi      # 0x5390
leaq 0x1236(%rip), %rsi      # 0x5391
callq 0x4270
leaq 0x1559(%rip), %rdi      # 0x56c0
leaq 0x1553(%rip), %rsi      # 0x56c1
callq 0x4270
leaq 0x1552(%rip), %rdi      # 0x56cc
leaq 0x154c(%rip), %rsi      # 0x56cd
callq 0x4270
leaq 0x1548(%rip), %rdi      # 0x56d5
leaq 0x1542(%rip), %rsi      # 0x56d6
callq 0x4270
leaq 0x1542(%rip), %rdi      # 0x56e2
leaq 0x153c(%rip), %rsi      # 0x56e3
callq 0x4270
leaq 0x1539(%rip), %rdi      # 0x56ec
leaq 0x153b(%rip), %rsi      # 0x56f5
callq 0x21e0
cmpq $0x0, -0x18(%rbp)
je 0x4238
callq 0x24d0
movl %eax, -0x20(%rbp)
movl %eax, %ecx
movl %ecx, -0x24(%rbp)
subl $-0x1, %eax
je 0x41e3
jmp 0x41da
movl -0x24(%rbp), %eax
testl %eax, %eax
je 0x41f6
jmp 0x422e
movl $0x1, %edi
leaq 0xe6e(%rip), %rsi       # 0x505d
movb $0x0, %al
callq 0x2320
movq -0x18(%rbp), %rcx
leaq 0xe7b(%rip), %rsi       # 0x507c
leaq 0xe7c(%rip), %rdx       # 0x5084
xorl %eax, %eax
movl %eax, %r8d
movq %rsi, %rdi
movb $0x0, %al
callq 0x2480
movq -0x18(%rbp), %rdx
movl $0x1, %edi
leaq 0xe60(%rip), %rsi       # 0x5087
movb $0x0, %al
callq 0x2320
movl -0x20(%rbp), %edi
callq 0x4860
jmp 0x4238
addq $0x30, %rsp
popq %rbp
retq
nop