// File: /workspace/github_c_makefile_star2_O3/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 0x1261
movq 0x2dbf(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0xdc2(%rip), %rsi       # 0x2008
xorl %eax, %eax
callq 0x10b0
movl $0x40, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, 0x10(%rsp)
leaq 0xdb4(%rip), %rdi       # 0x2021
callq 0x1030
movq %rax, %r15
movq %rax, 0x8(%rsp)
movq 0x8(%rbx), %r12
addq $0x8, %rbx
movq %r12, %rdi
movl $0x2f, %esi
callq 0x1080
testq %rax, %rax
jne 0x132e
testq %r15, %r15
je 0x1312
leaq 0xd8a(%rip), %r15       # 0x202e
leaq 0x8(%rsp), %r12
leaq 0xd70(%rip), %r14       # 0x2020
leaq 0xd79(%rip), %r13       # 0x2030
movq %rsp, %rbp
movq %r12, %rdi
movq %r15, %rsi
callq 0x10d0
cmpb $0x0, (%rax)
movq %r14, %rcx
je 0x12d4
leaq 0xd63(%rip), %rcx       # 0x2037
movq (%rbx), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x10f0
testl %eax, %eax
js 0x1372
movq (%rsp), %rdi
movl $0x1, %esi
callq 0x1110
movq (%rsp), %rdi
testl %eax, %eax
jns 0x137e
callq 0x1040
cmpq $0x0, 0x8(%rsp)
jne 0x12ba
callq 0x1050
movl $0x2, (%rax)
movq (%rbx), %rdx
leaq 0xd04(%rip), %rsi       # 0x202b
movl $0x1, %edi
jmp 0x136b
movq %r12, (%rsp)
movq %r12, %rdi
movl $0x1, %esi
callq 0x1110
testl %eax, %eax
jns 0x134c
leaq 0xce1(%rip), %rsi       # 0x202b
jmp 0x1363
movq %r12, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x1100
testl %eax, %eax
jns 0x1398
leaq 0xcc3(%rip), %rsi       # 0x2026
movl $0x1, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x10c0
leaq 0xcc0(%rip), %rsi       # 0x2039
jmp 0x1434
xorl %esi, %esi
xorl %eax, %eax
callq 0x1100
testl %eax, %eax
jns 0x1398
movq (%rsp), %rdx
leaq 0xc90(%rip), %rsi       # 0x2026
jmp 0x1327
movl %eax, %r15d
movq (%rsp), %rdi
movl $0x3, %esi
callq 0x1060
testl %eax, %eax
jns 0x13b6
leaq 0xc8c(%rip), %rsi       # 0x2040
jmp 0x1434
movl %eax, %ebp
movl $0x2000, %ecx           # imm = 0x2000
movl %ebp, %edi
movl %r15d, %esi
xorl %edx, %edx
callq 0x10e0
testq %rax, %rax
je 0x13ed
testq %rax, %rax
jns 0x13b8
callq 0x1050
movl (%rax), %eax
cmpl $0x4, %eax
je 0x13b8
cmpl $0xb, %eax
je 0x13b8
leaq 0xc62(%rip), %rsi       # 0x204d
jmp 0x1434
movl %r15d, %edi
callq 0x1090
movq (%rsp), %rdi
callq 0x1040
movl %ebp, %edi
movl $0x409, %esi            # imm = 0x409
movl $0xf, %edx
xorl %eax, %eax
callq 0x1070
testl %eax, %eax
jns 0x141e
leaq 0xc3a(%rip), %rsi       # 0x2056
jmp 0x1434
movl %ebp, %edi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
callq 0x10a0
leaq 0xc34(%rip), %rsi       # 0x2068
movl $0x1, %edi
xorl %eax, %eax
callq 0x10c0