// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x37c0
cmpl $0x2, -0x8(%rbp)
jge 0x248b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2800
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x20(%rbp), %rsi
movl $0xa, %edx
callq 0x21d0
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x24be
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x24ca
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2800
callq 0x2140
movl %eax, -0x64(%rbp)
callq 0x2100
movl %eax, %ecx
movl -0x64(%rbp), %eax
cmpl %ecx, %eax
je 0x24f3
movl $0x1, %edi
leaq 0x1b18(%rip), %rsi      # 0x4004
movb $0x0, %al
callq 0x2110
callq 0x2240
movl %eax, -0x68(%rbp)
callq 0x21e0
movl %eax, %ecx
movl -0x68(%rbp), %eax
cmpl %ecx, %eax
je 0x251c
movl $0x1, %edi
leaq 0x1b0d(%rip), %rsi      # 0x4022
movb $0x0, %al
callq 0x2110
jmp 0x251e
movl -0x38(%rbp), %edi
leaq 0x1b18(%rip), %rsi      # 0x4040
callq 0x2840
xorl %edi, %edi
callq 0x2280
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x2160
xorl %edi, %edi
callq 0x22f0
leaq 0x1af7(%rip), %rdi      # 0x4045
callq 0x20c0
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
jne 0x2570
movl $0x1, %edi
leaq 0x1ae2(%rip), %rsi      # 0x404b
movb $0x0, %al
callq 0x2110
jmp 0x2572
xorl %eax, %eax
cmpl $0x0, -0x34(%rbp)
movb %al, -0x69(%rbp)
jge 0x2594
movq -0x58(%rbp), %rdi
callq 0x21f0
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
setne %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x25a0
jmp 0x2663
movq -0x50(%rbp), %rdi
addq $0x13, %rdi
leaq -0x20(%rbp), %rsi
movl $0xa, %edx
callq 0x21d0
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movq -0x50(%rbp), %rcx
addq $0x13, %rcx
cmpq %rcx, %rax
je 0x25d6
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x25d8
jmp 0x2572
movl -0x3c(%rbp), %edi
callq 0x2930
cmpl -0x38(%rbp), %eax
jne 0x265e
movl -0x3c(%rbp), %esi
leaq 0x1a75(%rip), %rdi      # 0x4064
movb $0x0, %al
callq 0x3900
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x1bed(%rip), %rsi      # 0x41f2
callq 0x22b0
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0x2655
jmp 0x2616
movq -0x60(%rbp), %rcx
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
xorl %edx, %edx
callq 0x2320
cmpq $0x0, %rax
jl 0x264c
movq -0x28(%rbp), %rdi
leaq 0x1a3b(%rip), %rsi      # 0x4075
callq 0x2180
cmpl $0x0, %eax
jne 0x264a
movl -0x3c(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x2616
movq -0x60(%rbp), %rdi
callq 0x20b0
movq -0x30(%rbp), %rdi
callq 0x2040
jmp 0x2572
movq -0x58(%rbp), %rdi
callq 0x2170
cmpq $0x0, -0x28(%rbp)
je 0x267c
movq -0x28(%rbp), %rdi
callq 0x2040
cmpl $0x0, -0x34(%rbp)
jge 0x2698
movl -0x38(%rbp), %edx
movl $0x1, %edi
leaq 0x19f6(%rip), %rsi      # 0x4087
movb $0x0, %al
callq 0x2110
movl -0x34(%rbp), %edi
leaq 0x1a0a(%rip), %rsi      # 0x40ac
callq 0x2840
movl -0x34(%rbp), %edi
leaq 0x1a02(%rip), %rsi      # 0x40b3
callq 0x2840
movl -0x34(%rbp), %edi
leaq 0x19f7(%rip), %rsi      # 0x40b7
callq 0x2840
movl -0x34(%rbp), %edi
leaq 0x1d2b(%rip), %rsi      # 0x43fa
callq 0x2840
movl -0x34(%rbp), %edi
leaq 0x19dd(%rip), %rsi      # 0x40bb
callq 0x2840
movl -0x34(%rbp), %edi
leaq 0x19d3(%rip), %rsi      # 0x40c0
callq 0x2840
movl -0x34(%rbp), %edi
leaq 0x19c8(%rip), %rsi      # 0x40c4
callq 0x2840
leaq 0x19c0(%rip), %rdi      # 0x40c8
callq 0x20f0
cmpl $0x0, %eax
jge 0x2725
movl $0x1, %edi
leaq 0x19ac(%rip), %rsi      # 0x40ca
movb $0x0, %al
callq 0x2110
callq 0x2330
movl %eax, -0x34(%rbp)
movl %eax, %ecx
movl %ecx, -0x70(%rbp)
subl $-0x1, %eax
je 0x2745
jmp 0x2739
movl -0x70(%rbp), %eax
testl %eax, %eax
je 0x2758
jmp 0x27e6
movl $0x1, %edi
leaq 0x19a2(%rip), %rsi      # 0x40f3
movb $0x0, %al
callq 0x2200
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x277a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
callq 0x22c0
jmp 0x27d3
leaq 0x1977(%rip), %rdi      # 0x40f8
callq 0x2030
cmpq $0x0, %rax
je 0x27bc
leaq 0x1965(%rip), %rdi      # 0x40f8
callq 0x2030
movq %rax, -0x78(%rbp)
leaq 0x1955(%rip), %rdi      # 0x40f8
callq 0x2030
movq -0x78(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x2310
jmp 0x27d1
leaq 0x193b(%rip), %rsi      # 0x40fe
xorl %eax, %eax
movl %eax, %edx
movq %rsi, %rdi
movb $0x0, %al
callq 0x2310
jmp 0x27d3
movl $0x1, %edi
leaq 0x1927(%rip), %rsi      # 0x4106
movb $0x0, %al
callq 0x2200
movl -0x34(%rbp), %edi
callq 0x3a20
xorl %eax, %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)