// File: /workspace/github_c_makefile_star2_O3/arachsys[P]containers/inject.c
// Function: main
int main(int argc, char **argv, char **envp) {
  char *end, *item = NULL, *path;
  pid_t child = -1, parent, pid;
  size_t size;
  struct dirent *entry;
  DIR *dir;
  FILE *file;

  seal(argv, envp);
  if (argc < 2)
    usage(argv[0]);

  parent = strtol(argv[1], &end, 10);
  if (end == argv[1] || *end)
    usage(argv[0]);

  if (geteuid() != getuid())
    errx(EXIT_FAILURE, "setuid installation is unsafe");
  else if (getegid() != getgid())
    errx(EXIT_FAILURE, "setgid installation is unsafe");

  join(parent, "user");
  setgid(0);
  setgroups(0, NULL);
  setuid(0);

  if (!(dir = opendir("/proc")))
    errx(EXIT_FAILURE, "Failed to list processes");
  while (child < 0 && (entry = readdir(dir))) {
    pid = strtol(entry->d_name, &end, 10);
    if (end == entry->d_name || *end)
      continue;
    if (getparent(pid) == parent) {
      path = string("/proc/%u/environ", pid);
      if ((file = fopen(path, "r"))) {
        while (getdelim(&item, &size, '\0', file) >= 0)
          if (strcmp(item, "container=contain") == 0)
            child = pid;
        fclose(file);
      }
      free(path);
    }
  }
  closedir(dir);
  if (item)
    free(item);

  if (child < 0)
    errx(EXIT_FAILURE, "PID %u is not a container supervisor", parent);

  join(child, "cgroup");
  join(child, "ipc");
  join(child, "net");
  join(child, "pid");
  join(child, "time");
  join(child, "uts");
  join(child, "mnt");

  if (chdir("/") < 0)
    errx(EXIT_FAILURE, "Failed to enter container root directory");

  switch (child = fork()) {
    case -1:
      err(EXIT_FAILURE, "fork");
    case 0:
      if (argv[2])
        execvp(argv[2], argv + 2);
      else if (getenv("SHELL"))
        execl(getenv("SHELL"), getenv("SHELL"), NULL);
      else
        execl(SHELL, SHELL, NULL);
      err(EXIT_FAILURE, "exec");
  }

  waitforexit(child);
  return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movl %edi, %ebx
movq $0x0, 0x10(%rsp)
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x34cc
cmpl $0x1, %ebx
jle 0x27dc
movq 0x8(%r14), %rdi
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
movl $0xa, %edx
callq 0x21c0
movq %rax, %r15
movq (%rbx), %rax
cmpq 0x8(%r14), %rax
je 0x27d4
cmpb $0x0, (%rax)
jne 0x27d4
callq 0x2130
movl %eax, %ebx
callq 0x2100
cmpl %eax, %ebx
jne 0x27e4
callq 0x2230
movl %eax, %ebx
callq 0x21d0
cmpl %eax, %ebx
jne 0x27ed
movq %r14, 0x30(%rsp)
leaq 0x1b31(%rip), %rsi      # 0x4040
movq %r15, 0x38(%rsp)
movl %r15d, %edi
callq 0x2890
xorl %edi, %edi
callq 0x2270
xorl %edi, %edi
xorl %esi, %esi
callq 0x2150
xorl %edi, %edi
callq 0x22e0
leaq 0x1b0b(%rip), %rdi      # 0x4045
callq 0x20c0
testq %rax, %rax
je 0x27f6
movq %rax, %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x18(%rsp), %r12
movq %r15, %rdi
callq 0x21e0
movq %rax, %r14
testq %rax, %rax
sete %r13b
je 0x2717
addq $0x13, %r14
movq %r14, %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x21c0
movq %rax, %rbx
movq 0x18(%rsp), %rax
cmpq %r14, %rax
je 0x2555
cmpb $0x0, (%rax)
jne 0x2555
movq $0x0, 0x20(%rsp)
leaq 0x1c00(%rip), %rdi      # 0x41a3
movl %ebx, %esi
xorl %eax, %eax
callq 0x35be
movq %rax, %r14
movq %rax, %rdi
leaq 0x1c39(%rip), %rsi      # 0x41f2
callq 0x22a0
movq %rax, 0x8(%rsp)
movq %r14, %rdi
callq 0x2040
movq 0x8(%rsp), %rdx
testq %rdx, %rdx
je 0x263b
leaq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x22c0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %rax, %rax
js 0x2649
movq 0x20(%rsp), %rdi
movl $0x29, %esi
callq 0x2120
testq %rax, %rax
je 0x2643
movq %rax, %r14
movq %rax, %rdi
callq 0x20e0
cmpq $0x4, %rax
jb 0x2643
leaq 0x4(%r14), %rdi
leaq 0x48(%rsp), %rsi
movl $0xa, %edx
callq 0x21c0
movq 0x48(%rsp), %rcx
cmpq %r14, %rcx
je 0x2643
cmpb $0x20, (%rcx)
jne 0x2643
movl %eax, %r14d
jmp 0x2649
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x2662
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rdi
callq 0x20b0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2662
callq 0x2040
cmpl 0x38(%rsp), %r14d
jne 0x270f
leaq 0x19f0(%rip), %rdi      # 0x4064
movl %ebx, %esi
xorl %eax, %eax
callq 0x35be
movq %rax, %r14
movq %rax, %rdi
leaq 0x1b68(%rip), %rsi      # 0x41f2
callq 0x22a0
testq %rax, %rax
je 0x2707
movq %r14, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rsi
xorl %edx, %edx
movq %rax, 0x28(%rsp)
movq %rax, %rcx
callq 0x2310
testq %rax, %rax
js 0x26f0
leaq 0x19b7(%rip), %r12      # 0x4075
movq 0x28(%rsp), %r14
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2170
testl %eax, %eax
cmovel %ebx, %ebp
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x2310
testq %rax, %rax
jns 0x26c3
jmp 0x26f5
movq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x20b0
leaq 0x18(%rsp), %r12
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x2040
testl %ebp, %ebp
js 0x2555
movq %r15, %rdi
callq 0x2160
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x272e
callq 0x2040
testb $0x1, %r13b
jne 0x27ff
leaq 0x196d(%rip), %rsi      # 0x40ac
movl %ebp, %edi
callq 0x2890
leaq 0x1966(%rip), %rsi      # 0x40b3
movl %ebp, %edi
callq 0x2890
leaq 0x195c(%rip), %rsi      # 0x40b7
movl %ebp, %edi
callq 0x2890
leaq 0x1c8b(%rip), %rsi      # 0x43f4
movl %ebp, %edi
callq 0x2890
leaq 0x1944(%rip), %rsi      # 0x40bb
movl %ebp, %edi
callq 0x2890
leaq 0x193b(%rip), %rsi      # 0x40c0
movl %ebp, %edi
callq 0x2890
leaq 0x1931(%rip), %rsi      # 0x40c4
movl %ebp, %edi
callq 0x2890
leaq 0x1927(%rip), %rdi      # 0x40c8
callq 0x20f0
testl %eax, %eax
js 0x2817
callq 0x2320
testl %eax, %eax
je 0x282a
cmpl $-0x1, %eax
je 0x2855
movl %eax, %edi
callq 0x36bf
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x2340
movq %r14, %rdi
callq 0x2364
leaq 0x1819(%rip), %rsi      # 0x4004
jmp 0x281e
leaq 0x182e(%rip), %rsi      # 0x4022
jmp 0x281e
leaq 0x184e(%rip), %rsi      # 0x404b
jmp 0x281e
leaq 0x1881(%rip), %rsi      # 0x4087
movl $0x1, %edi
movq 0x38(%rsp), %rdx
xorl %eax, %eax
callq 0x2110
leaq 0x18ac(%rip), %rsi      # 0x40ca
movl $0x1, %edi
xorl %eax, %eax
callq 0x2110
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
testq %rdi, %rdi
jne 0x285e
leaq 0x18b9(%rip), %rdi      # 0x40f8
callq 0x2030
testq %rax, %rax
jne 0x286e
leaq 0x18ae(%rip), %rdi      # 0x40fe
movq %rdi, %rsi
jmp 0x2874
leaq 0x1897(%rip), %rsi      # 0x40f3
jmp 0x2884
movq 0x30(%rsp), %rsi
addq $0x10, %rsi
callq 0x22b0
jmp 0x287d
movq %rax, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2300
leaq 0x1882(%rip), %rsi      # 0x4106
movl $0x1, %edi
xorl %eax, %eax
callq 0x21f0