// File: /workspace/github_c_makefile_star2_O2/arachsys[P]init/seal.c
// Function: main
int main(int argc, char **argv, char **envp) {
  char *dir, *file, *path;
  int src, dst;
  ssize_t length;

  if (argc < 2) {
    fprintf(stderr, "Usage: %s PROG [ARG]...\n", argv[0]);
    return 64;
  }

  path = getenv("PATH");
  src = -1;

  if (strchr(argv[1], '/')) {
    if (access(file = argv[1], X_OK) < 0)
      err(EXIT_FAILURE, "%s", file);
    if (src = open(file, O_RDONLY), src < 0)
      err(EXIT_FAILURE, "open %s", file);
  }

  while (src < 0 && path) {
    dir = strsep(&path, ":");
    if (asprintf(&file, "%s%s%s", dir, *dir ? "/" : "", argv[1]) < 0)
      err(EXIT_FAILURE, "malloc");
    if (access(file, X_OK) < 0)
      free(file);
    else if (src = open(file, O_RDONLY), src < 0)
      err(EXIT_FAILURE, "open %s", file);
  }

  if (src < 0) {
    errno = ENOENT;
    err(EXIT_FAILURE, "%s", argv[1]);
  }

  dst = memfd_create(file, MFD_CLOEXEC | MFD_ALLOW_SEALING);
  if (dst < 0)
    err(EXIT_FAILURE, "memfd_create");

  while (length = sendfile(dst, src, NULL, BUFSIZ), length != 0)
    if (length < 0 && errno != EAGAIN && errno != EINTR)
      err(EXIT_FAILURE, "sendfile");
  close(src);
  free(file);

  if (fcntl(dst, F_ADD_SEALS, seals) < 0)
    err(1, "fcntl F_ADD_SEALS");
  fexecve(dst, argv + 1, envp);
  err(1, "fexecve");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
cmpl $0x1, %edi
jg 0x125f
movq 0x2dbf(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0xdc2(%rip), %rsi       # 0x2008
xorl %eax, %eax
callq 0x10b0
pushq $0x40
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, 0x10(%rsp)
leaq 0xdb6(%rip), %rdi       # 0x2021
callq 0x1030
movq %rax, %r12
movq %rax, 0x8(%rsp)
movq 0x8(%rbx), %r14
pushq $0x2f
popq %rsi
movq %r14, %rdi
callq 0x1080
pushq $-0x1
popq %rbp
testq %rax, %rax
jne 0x132c
addq $0x8, %rbx
leaq 0xd92(%rip), %r13       # 0x2030
movq %rsp, %r14
pushq $0x1
popq %r15
testl %ebp, %ebp
jns 0x136d
testq %r12, %r12
je 0x136d
leaq 0x8(%rsp), %rdi
leaq 0xd6c(%rip), %rsi       # 0x202e
callq 0x10d0
cmpb $0x0, (%rax)
leaq 0xd4f(%rip), %rcx       # 0x2020
je 0x12da
leaq 0xd5d(%rip), %rcx       # 0x2037
movq (%rbx), %r8
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x10f0
testl %eax, %eax
js 0x1388
movq (%rsp), %rdi
movl %r15d, %esi
callq 0x1110
movq (%rsp), %rdi
testl %eax, %eax
js 0x131a
xorl %esi, %esi
xorl %eax, %eax
callq 0x1100
movl %eax, %ebp
testl %eax, %eax
jns 0x1322
jmp 0x1394
callq 0x1040
pushq $-0x1
popq %rbp
movq 0x8(%rsp), %r12
jmp 0x12a5
movq %r14, (%rsp)
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x1110
testl %eax, %eax
jns 0x1348
leaq 0xce5(%rip), %rsi       # 0x202b
jmp 0x1365
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x1100
movl %eax, %ebp
testl %eax, %eax
jns 0x1293
leaq 0xcc1(%rip), %rsi       # 0x2026
pushq $0x1
popq %rdi
movq %r14, %rdx
jmp 0x13a2
testl %ebp, %ebp
jns 0x13a9
callq 0x1050
movl $0x2, (%rax)
movq (%rbx), %rdx
leaq 0xca5(%rip), %rsi       # 0x202b
jmp 0x139f
leaq 0xcaa(%rip), %rsi       # 0x2039
jmp 0x143d
movq (%rsp), %rdx
leaq 0xc87(%rip), %rsi       # 0x2026
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x10c0
movq (%rsp), %rdi
pushq $0x3
popq %rsi
callq 0x1060
testl %eax, %eax
jns 0x13c2
leaq 0xc80(%rip), %rsi       # 0x2040
jmp 0x143d
movl %eax, %r14d
movl $0x2000, %ecx           # imm = 0x2000
movl %r14d, %edi
movl %ebp, %esi
xorl %edx, %edx
callq 0x10e0
testq %rax, %rax
je 0x13f7
jns 0x13c5
callq 0x1050
movl (%rax), %eax
cmpl $0x4, %eax
je 0x13c5
cmpl $0xb, %eax
je 0x13c5
leaq 0xc58(%rip), %rsi       # 0x204d
jmp 0x143d
movl %ebp, %edi
callq 0x1090
movq (%rsp), %rdi
callq 0x1040
pushq $0xf
popq %rdx
movl %r14d, %edi
movl $0x409, %esi            # imm = 0x409
xorl %eax, %eax
callq 0x1070
testl %eax, %eax
jns 0x1426
leaq 0xc32(%rip), %rsi       # 0x2056
jmp 0x143d
movl %r14d, %edi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
callq 0x10a0
leaq 0xc2b(%rip), %rsi       # 0x2068
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x10c0