// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x126a
movq 0x2db1(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xdb0(%rip), %rsi       # 0x2008
movb $0x0, %al
callq 0x10b0
movl $0x40, %eax
addq $0x50, %rsp
popq %rbp
retq
leaq 0xdb0(%rip), %rdi       # 0x2021
callq 0x1030
movq %rax, -0x30(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x2f, %esi
callq 0x1080
cmpq $0x0, %rax
je 0x12fa
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq %rdi, -0x28(%rbp)
movl $0x1, %esi
callq 0x1110
cmpl $0x0, %eax
jge 0x12cb
movq -0x28(%rbp), %rdx
movl $0x1, %edi
leaq 0xd67(%rip), %rsi       # 0x202b
movb $0x0, %al
callq 0x10c0
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x1100
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x12f8
movq -0x28(%rbp), %rdx
movl $0x1, %edi
leaq 0xd35(%rip), %rsi       # 0x2026
movb $0x0, %al
callq 0x10c0
jmp 0x12fa
jmp 0x12fc
xorl %eax, %eax
cmpl $0x0, -0x34(%rbp)
movb %al, -0x41(%rbp)
jge 0x1312
cmpq $0x0, -0x30(%rbp)
setne %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x131e
jmp 0x13d6
leaq -0x30(%rbp), %rdi
leaq 0xd05(%rip), %rsi       # 0x202e
callq 0x10d0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdx
movq -0x20(%rbp), %rax
movsbl (%rax), %esi
leaq 0xcdc(%rip), %rcx       # 0x2020
leaq 0xcec(%rip), %rax       # 0x2037
cmpl $0x0, %esi
cmovneq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %r8
leaq -0x28(%rbp), %rdi
leaq 0xccb(%rip), %rsi       # 0x2030
movb $0x0, %al
callq 0x10f0
cmpl $0x0, %eax
jge 0x1384
movl $0x1, %edi
leaq 0xcbc(%rip), %rsi       # 0x2039
movb $0x0, %al
callq 0x10c0
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x1110
cmpl $0x0, %eax
jge 0x13a2
movq -0x28(%rbp), %rdi
callq 0x1040
jmp 0x13d1
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x1100
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x13cf
movq -0x28(%rbp), %rdx
movl $0x1, %edi
leaq 0xc5e(%rip), %rsi       # 0x2026
movb $0x0, %al
callq 0x10c0
jmp 0x13d1
jmp 0x12fc
cmpl $0x0, -0x34(%rbp)
jge 0x1402
callq 0x1050
movl $0x2, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x1, %edi
leaq 0xc30(%rip), %rsi       # 0x202b
movb $0x0, %al
callq 0x10c0
movq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0x1060
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jge 0x142c
movl $0x1, %edi
leaq 0xc1b(%rip), %rsi       # 0x2040
movb $0x0, %al
callq 0x10c0
jmp 0x142e
movl -0x38(%rbp), %edi
movl -0x34(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
movl $0x2000, %ecx           # imm = 0x2000
callq 0x10e0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x147d
cmpq $0x0, -0x40(%rbp)
jge 0x147b
callq 0x1050
cmpl $0xb, (%rax)
je 0x147b
callq 0x1050
cmpl $0x4, (%rax)
je 0x147b
movl $0x1, %edi
leaq 0xbd9(%rip), %rsi       # 0x204d
movb $0x0, %al
callq 0x10c0
jmp 0x142e
movl -0x34(%rbp), %edi
callq 0x1090
movq -0x28(%rbp), %rdi
callq 0x1040
movl -0x38(%rbp), %edi
movl $0x409, %esi            # imm = 0x409
movl $0xf, %edx
movb $0x0, %al
callq 0x1070
cmpl $0x0, %eax
jge 0x14ba
movl $0x1, %edi
leaq 0xba3(%rip), %rsi       # 0x2056
movb $0x0, %al
callq 0x10c0
movl -0x38(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
movq -0x18(%rbp), %rdx
callq 0x10a0
movl $0x1, %edi
leaq 0xb8e(%rip), %rsi       # 0x2068
movb $0x0, %al
callq 0x10c0