// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movq 0x8(%rbx), %r14
movq %r14, %rdi
movl $0x2f, %esi
callq 0x1080
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
jne 0x1358
addq $0x8, %rbx
movl %ebp, %eax
shrl $0x1f, %eax
testl %ebp, %ebp
jns 0x1344
cmpq $0x0, 0x8(%rsp)
je 0x1344
leaq 0x8(%rsp), %r12
leaq 0xd61(%rip), %r15       # 0x2020
leaq 0xd6a(%rip), %r13       # 0x2030
movq %rsp, %r14
movq %r12, %rdi
leaq 0xd5b(%rip), %rsi       # 0x202e
callq 0x10d0
cmpb $0x0, (%rax)
movq %r15, %rcx
je 0x12e7
leaq 0xd50(%rip), %rcx       # 0x2037
movq (%rbx), %r8
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x10f0
testl %eax, %eax
js 0x13c5
movq (%rsp), %rdi
movl $0x1, %esi
callq 0x1110
movq (%rsp), %rdi
testl %eax, %eax
js 0x1329
xorl %esi, %esi
xorl %eax, %eax
callq 0x1100
movl %eax, %ebp
testl %eax, %eax
jns 0x1333
jmp 0x1390
callq 0x1040
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
shrl $0x1f, %eax
testl %ebp, %ebp
jns 0x1344
cmpq $0x0, 0x8(%rsp)
jne 0x12c9
testb %al, %al
je 0x13a7
callq 0x1050
movl $0x2, (%rax)
movq (%rbx), %rdx
jmp 0x1371
movq %r14, (%rsp)
movq %r14, %rdi
movl $0x1, %esi
callq 0x1110
movq (%rsp), %rdx
testl %eax, %eax
jns 0x137a
leaq 0xcb3(%rip), %rsi       # 0x202b
jmp 0x139b
movq %rdx, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x1100
movl %eax, %ebp
testl %eax, %eax
jns 0x1296
movq (%rsp), %rdx
leaq 0xc8b(%rip), %rsi       # 0x2026
movl $0x1, %edi
xorl %eax, %eax
callq 0x10c0
movq (%rsp), %rdi
movl $0x3, %esi
callq 0x1060
testl %eax, %eax
jns 0x13d1
leaq 0xc80(%rip), %rsi       # 0x2040
jmp 0x1451
leaq 0xc6d(%rip), %rsi       # 0x2039
jmp 0x1451
movl %eax, %r15d
movl $0x2000, %ecx           # imm = 0x2000
movl %r15d, %edi
movl %ebp, %esi
xorl %edx, %edx
callq 0x10e0
testq %rax, %rax
je 0x1409
testq %rax, %rax
jns 0x13d4
callq 0x1050
movl (%rax), %eax
cmpl $0x4, %eax
je 0x13d4
cmpl $0xb, %eax
je 0x13d4
leaq 0xc46(%rip), %rsi       # 0x204d
jmp 0x1451
movl %ebp, %edi
callq 0x1090
movq (%rsp), %rdi
callq 0x1040
movl %r15d, %edi
movl $0x409, %esi            # imm = 0x409
movl $0xf, %edx
xorl %eax, %eax
callq 0x1070
testl %eax, %eax
jns 0x143a
leaq 0xc1e(%rip), %rsi       # 0x2056
jmp 0x1451
movl %r15d, %edi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
callq 0x10a0
leaq 0xc17(%rip), %rsi       # 0x2068
movl $0x1, %edi
xorl %eax, %eax
callq 0x10c0