// File: /workspace/github_c_makefile_star2_O0/arachsys[P]containers/contain.c
// Function: main
int main(int argc, char **argv) {
  char *gidmap = NULL, *inside = NULL, *outside = NULL, *uidmap = NULL;
  int hostnet = 0, master, option, stdio = 0;
  pid_t child, parent;

  while ((option = getopt(argc, argv, "+:cg:i:no:u:")) > 0)
    switch (option) {
      case 'c':
        stdio++;
        break;
      case 'g':
        gidmap = optarg;
        break;
      case 'i':
        inside = optarg;
        break;
      case 'n':
        hostnet++;
        break;
      case 'o':
        outside = optarg;
        break;
      case 'u':
        uidmap = optarg;
        break;
      default:
        usage(argv[0]);
    }

  if (argc <= optind)
    usage(argv[0]);

  parent = getpid();
  switch (child = fork()) {
    case -1:
      err(EXIT_FAILURE, "fork");
    case 0:
      raise(SIGSTOP);
      if (geteuid() != 0)
        denysetgroups(parent);
      writemap(parent, GID, gidmap);
      writemap(parent, UID, uidmap);

      if (outside) {
        if (setgid(getgid()) < 0 || setuid(getuid()) < 0)
          errx(EXIT_FAILURE, "Failed to drop privileges");
        prctl(PR_SET_DUMPABLE, 1);
        execlp(SHELL, SHELL, "-c", outside, NULL);
        err(EXIT_FAILURE, "exec %s", outside);
      }

      exit(EXIT_SUCCESS);
  }

  if (setgid(getgid()) < 0 || setuid(getuid()) < 0)
    errx(EXIT_FAILURE, "Failed to drop privileges");
  prctl(PR_SET_DUMPABLE, 1);

  if (unshare(CLONE_NEWUSER) < 0)
    errx(EXIT_FAILURE, "Failed to unshare user namespace");

#ifdef CLONE_NEWCGROUP
  if (unshare(CLONE_NEWCGROUP) < 0)
    errx(EXIT_FAILURE, "Failed to unshare cgroup namespace");
#endif

  if (unshare(CLONE_NEWIPC) < 0)
    errx(EXIT_FAILURE, "Failed to unshare IPC namespace");

  if (!hostnet && unshare(CLONE_NEWNET) < 0)
    errx(EXIT_FAILURE, "Failed to unshare network namespace");

  if (unshare(CLONE_NEWNS) < 0)
    errx(EXIT_FAILURE, "Failed to unshare mount namespace");

#ifdef CLONE_NEWTIME
  if (unshare(CLONE_NEWTIME) < 0)
    errx(EXIT_FAILURE, "Failed to unshare time namespace");
#endif

  if (unshare(CLONE_NEWUTS) < 0)
    errx(EXIT_FAILURE, "Failed to unshare UTS namespace");

  waitforstop(child);
  kill(child, SIGCONT);
  waitforexit(child);

  setgid(0);
  setgroups(0, NULL);
  setuid(0);

  master = stdio ? -1 : getconsole();
  createroot(argv[optind], master, inside);

  if (unshare(CLONE_NEWPID) < 0)
    errx(EXIT_FAILURE, "Failed to unshare PID namespace");

  switch (child = fork()) {
    case -1:
      err(EXIT_FAILURE, "fork");
    case 0:
      mountproc();
      if (!hostnet)
        mountsys();
      enterroot();

      if (master >= 0) {
        close(master);
        setconsole("/dev/console");
      }

      clearenv();
      putenv("container=contain");

      if (argv[optind + 1])
        execv(argv[optind + 1], argv + optind + 1);
      else
        execl(SHELL, SHELL, NULL);
      err(EXIT_FAILURE, "exec");
  }

  return supervise(child, master);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x2a1e(%rip), %rdx      # 0x5050
callq 0x2410
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
jle 0x26cf
movl -0x3c(%rbp), %eax
addl $-0x63, %eax
movl %eax, %ecx
movq %rcx, -0x50(%rbp)
subl $0x12, %eax
ja 0x26be
movq -0x50(%rbp), %rax
leaq 0x29a5(%rip), %rcx      # 0x5004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x26ca
movq 0x595e(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x26ca
movq 0x594e(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x26ca
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x26ca
movq 0x5933(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x26ca
movq 0x5923(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x26ca
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2ac0
jmp 0x2624
movl -0x8(%rbp), %eax
movq 0x58f7(%rip), %rcx      # 0x7fd0
cmpl (%rcx), %eax
jg 0x26e9
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2ac0
callq 0x2100
movl %eax, -0x48(%rbp)
callq 0x24d0
movl %eax, -0x44(%rbp)
movl %eax, %ecx
movl %ecx, -0x54(%rbp)
subl $-0x1, %eax
je 0x2711
jmp 0x2705
movl -0x54(%rbp), %eax
testl %eax, %eax
je 0x2724
jmp 0x27eb
movl $0x1, %edi
leaq 0x2940(%rip), %rsi      # 0x505d
movb $0x0, %al
callq 0x2320
movl $0x13, %edi
callq 0x2060
callq 0x21f0
cmpl $0x0, %eax
je 0x2740
movl -0x48(%rbp), %edi
callq 0x3390
movl -0x48(%rbp), %edi
movq -0x18(%rbp), %rdx
xorl %esi, %esi
callq 0x3460
movl -0x48(%rbp), %edi
movq -0x30(%rbp), %rdx
movl $0x1, %esi
callq 0x3460
cmpq $0x0, -0x28(%rbp)
je 0x27e4
callq 0x2310
movl %eax, %edi
callq 0x23b0
cmpl $0x0, %eax
jl 0x2788
callq 0x21a0
movl %eax, %edi
callq 0x2460
cmpl $0x0, %eax
jge 0x279b
movl $0x1, %edi
leaq 0x28ce(%rip), %rsi      # 0x5062
movb $0x0, %al
callq 0x21b0
movl $0x4, %edi
movl $0x1, %esi
movb $0x0, %al
callq 0x22f0
movq -0x28(%rbp), %rcx
leaq 0x28c5(%rip), %rsi      # 0x507c
leaq 0x28c6(%rip), %rdx      # 0x5084
xorl %eax, %eax
movl %eax, %r8d
movq %rsi, %rdi
movb $0x0, %al
callq 0x2480
movq -0x28(%rbp), %rdx
movl $0x1, %edi
leaq 0x28aa(%rip), %rsi      # 0x5087
movb $0x0, %al
callq 0x2320
xorl %edi, %edi
callq 0x2450
callq 0x2310
movl %eax, %edi
callq 0x23b0
cmpl $0x0, %eax
jl 0x280d
callq 0x21a0
movl %eax, %edi
callq 0x2460
cmpl $0x0, %eax
jge 0x2820
movl $0x1, %edi
leaq 0x2849(%rip), %rsi      # 0x5062
movb $0x0, %al
callq 0x21b0
movl $0x4, %edi
movl $0x1, %esi
movb $0x0, %al
callq 0x22f0
movl $0x10000000, %edi       # imm = 0x10000000
callq 0x20d0
cmpl $0x0, %eax
jge 0x2853
movl $0x1, %edi
leaq 0x2843(%rip), %rsi      # 0x508f
movb $0x0, %al
callq 0x21b0
movl $0x2000000, %edi        # imm = 0x2000000
callq 0x20d0
cmpl $0x0, %eax
jge 0x2875
movl $0x1, %edi
leaq 0x2842(%rip), %rsi      # 0x50b0
movb $0x0, %al
callq 0x21b0
movl $0x8000000, %edi        # imm = 0x8000000
callq 0x20d0
cmpl $0x0, %eax
jge 0x2897
movl $0x1, %edi
leaq 0x2843(%rip), %rsi      # 0x50d3
movb $0x0, %al
callq 0x21b0
cmpl $0x0, -0x34(%rbp)
jne 0x28bf
movl $0x40000000, %edi       # imm = 0x40000000
callq 0x20d0
cmpl $0x0, %eax
jge 0x28bf
movl $0x1, %edi
leaq 0x283b(%rip), %rsi      # 0x50f3
movb $0x0, %al
callq 0x21b0
movl $0x20000, %edi          # imm = 0x20000
callq 0x20d0
cmpl $0x0, %eax
jge 0x28e1
movl $0x1, %edi
leaq 0x283d(%rip), %rsi      # 0x5117
movb $0x0, %al
callq 0x21b0
movl $0x80, %edi
callq 0x20d0
cmpl $0x0, %eax
jge 0x2903
movl $0x1, %edi
leaq 0x283d(%rip), %rsi      # 0x5139
movb $0x0, %al
callq 0x21b0
movl $0x4000000, %edi        # imm = 0x4000000
callq 0x20d0
cmpl $0x0, %eax
jge 0x2925
movl $0x1, %edi
leaq 0x283c(%rip), %rsi      # 0x515a
movb $0x0, %al
callq 0x21b0
movl -0x44(%rbp), %edi
callq 0x48c0
movl -0x44(%rbp), %edi
movl $0x12, %esi
callq 0x2300
movl -0x44(%rbp), %edi
callq 0x4860
xorl %edi, %edi
callq 0x23b0
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x2230
xorl %edi, %edi
callq 0x2460
cmpl $0x0, -0x40(%rbp)
je 0x296c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x58(%rbp)
jmp 0x2974
callq 0x2b00
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x564b(%rip), %rcx      # 0x7fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movl -0x38(%rbp), %esi
movq -0x20(%rbp), %rdx
callq 0x3fe0
movl $0x20000000, %edi       # imm = 0x20000000
callq 0x20d0
cmpl $0x0, %eax
jge 0x29ba
movl $0x1, %edi
leaq 0x27c7(%rip), %rsi      # 0x517a
movb $0x0, %al
callq 0x21b0
callq 0x24d0
movl %eax, -0x44(%rbp)
movl %eax, %ecx
movl %ecx, -0x5c(%rbp)
subl $-0x1, %eax
je 0x29da
jmp 0x29ce
movl -0x5c(%rbp), %eax
testl %eax, %eax
je 0x29ed
jmp 0x2aa6
movl $0x1, %edi
leaq 0x2677(%rip), %rsi      # 0x505d
movb $0x0, %al
callq 0x2320
callq 0x43c0
cmpl $0x0, -0x34(%rbp)
jne 0x29fd
callq 0x4430
callq 0x42f0
cmpl $0x0, -0x38(%rbp)
jl 0x2a1c
movl -0x38(%rbp), %edi
callq 0x2220
leaq 0x2783(%rip), %rdi      # 0x519a
callq 0x2c00
callq 0x2150
leaq 0x277f(%rip), %rdi      # 0x51a7
callq 0x2260
movq -0x10(%rbp), %rax
movq 0x5598(%rip), %rcx      # 0x7fd0
movl (%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x2a7e
movq -0x10(%rbp), %rax
movq 0x557e(%rip), %rcx      # 0x7fd0
movl (%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rsi
movq 0x5567(%rip), %rax      # 0x7fd0
movslq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
addq $0x8, %rsi
callq 0x24c0
jmp 0x2a93
leaq 0x25f7(%rip), %rsi      # 0x507c
xorl %eax, %eax
movl %eax, %edx
movq %rsi, %rdi
movb $0x0, %al
callq 0x2490
movl $0x1, %edi
leaq 0x271a(%rip), %rsi      # 0x51b9
movb $0x0, %al
callq 0x2320
movl -0x44(%rbp), %edi
movl -0x38(%rbp), %esi
callq 0x2ce0
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)