// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/tests/main.c
// Function: main
int main() {
  DIR *dir = opendir(".");
  check(dir);

  int exit_status = 0;

  const struct dirent *entry;
  while ((entry = readdir(dir)) != NULL) {
    if (strchr(entry->d_name, '.')) {
      continue;
    }
    if (strcmp(entry->d_name, "main") == 0) {
      continue;
    }

    printf("testing %s...", entry->d_name);
    fflush(stdout);
    char exec_path[64];
    check(snprintf(exec_path, sizeof exec_path, "./%s", entry->d_name) != -1);

    char *argv[] = {exec_path, NULL};
    char *envp[] = {
      "MALLOC_OPTIONS=S", // security options for OpenBSD
      NULL
    };

    pid_t child_pid = fork();
    check(child_pid != -1);

    if (child_pid == 0) {
      check(setpgid(getpid(), getpid()) == 0);
      check(execve(exec_path, argv, envp));
      abort();
    }

    char failure[99];
    failure[0] = '\0';

    int wait_status;
    check(waitpid(child_pid, &wait_status, 0) > 0);
    if (WIFEXITED(wait_status)) {
      if (WEXITSTATUS(wait_status) != 0) {
        snprintf(failure, sizeof failure, "exited with status %d", WEXITSTATUS(wait_status));
      }
    } else if (WIFSIGNALED(wait_status)) {
      snprintf(failure, sizeof failure, "received signal %d", WTERMSIG(wait_status));
    } else {
      abort();
    }

    // kill the whole process group
    int kill_res = killpg(child_pid, SIGKILL);
    if (kill_res == 0) {
      snprintf(failure, sizeof failure, "children were still running");
    } else {
      if (errno != ESRCH) {
        perror("killpg");
        abort();
      }
    }

    if (*failure) {
      exit_status = 1;
      printf(" error: %s\n", failure);
    } else {
      printf(" ok\n");
    }
  }

  check(closedir(dir) == 0);

  return exit_status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movl $0x0, -0x4(%rbp)
leaq 0x2c6d(%rip), %rdi      # 0x4026
callq 0x10a0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x13cb
jmp 0x13e3
leaq 0x2c32(%rip), %rdi      # 0x4004
leaq 0x2c2f(%rip), %rsi      # 0x4008
movl $0x8, %edx
callq 0x1700
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x11d0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x16c1
movq -0x20(%rbp), %rdi
addq $0x13, %rdi
movl $0x2e, %esi
callq 0x10b0
cmpq $0x0, %rax
je 0x141b
jmp 0x13ea
movq -0x20(%rbp), %rdi
addq $0x13, %rdi
leaq 0x2beb(%rip), %rsi      # 0x4015
callq 0x1160
cmpl $0x0, %eax
jne 0x1436
jmp 0x13ea
movq -0x20(%rbp), %rsi
addq $0x13, %rsi
leaq 0x2bd5(%rip), %rdi      # 0x401a
movb $0x0, %al
callq 0x10c0
movq 0x5b7d(%rip), %rax      # 0x6fd0
movq (%rax), %rdi
callq 0x11f0
leaq -0x60(%rbp), %rdi
movq -0x20(%rbp), %rcx
addq $0x13, %rcx
movl $0x40, %esi
leaq 0x2bb5(%rip), %rdx      # 0x4028
movb $0x0, %al
callq 0x10d0
cmpl $-0x1, %eax
je 0x1481
jmp 0x1499
leaq 0x2ba5(%rip), %rdi      # 0x402d
leaq 0x2b79(%rip), %rsi      # 0x4008
movl $0x18, %edx
callq 0x1700
leaq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq 0x5920(%rip), %rax      # 0x6dd0
movq %rax, -0x80(%rbp)
movq 0x591d(%rip), %rax      # 0x6dd8
movq %rax, -0x78(%rbp)
callq 0x1290
movl %eax, -0x84(%rbp)
cmpl $-0x1, -0x84(%rbp)
je 0x14d5
jmp 0x14ed
leaq 0x2ba5(%rip), %rdi      # 0x4081
leaq 0x2b25(%rip), %rsi      # 0x4008
movl $0x21, %edx
callq 0x1700
cmpl $0x0, -0x84(%rbp)
jne 0x1567
callq 0x1090
movl %eax, -0xfc(%rbp)
callq 0x1090
movl -0xfc(%rbp), %edi
movl %eax, %esi
callq 0x1260
cmpl $0x0, %eax
jne 0x151a
jmp 0x1532
leaq 0x2b70(%rip), %rdi      # 0x4091
leaq 0x2ae0(%rip), %rsi      # 0x4008
movl $0x24, %edx
callq 0x1700
leaq -0x60(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x1150
cmpl $0x0, %eax
je 0x154a
jmp 0x1562
leaq 0x2b61(%rip), %rdi      # 0x40b2
leaq 0x2ab0(%rip), %rsi      # 0x4008
movl $0x25, %edx
callq 0x1700
callq 0x1040
movb $0x0, -0xf0(%rbp)
movl -0x84(%rbp), %edi
leaq -0xf4(%rbp), %rsi
xorl %edx, %edx
callq 0x1230
cmpl $0x0, %eax
jle 0x1589
jmp 0x15a1
leaq 0x2b40(%rip), %rdi      # 0x40d0
leaq 0x2a71(%rip), %rsi      # 0x4008
movl $0x2d, %edx
callq 0x1700
movl -0xf4(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x15ed
movl -0xf4(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
cmpl $0x0, %eax
je 0x15eb
leaq -0xf0(%rbp), %rdi
movl -0xf4(%rbp), %ecx
andl $0xff00, %ecx           # imm = 0xFF00
sarl $0x8, %ecx
movl $0x63, %esi
leaq 0x2b14(%rip), %rdx      # 0x40f8
movb $0x0, %al
callq 0x10d0
jmp 0x162f
movl -0xf4(%rbp), %eax
andl $0x7f, %eax
addl $0x1, %eax
movsbl %al, %eax
sarl %eax
cmpl $0x0, %eax
jle 0x1628
leaq -0xf0(%rbp), %rdi
movl -0xf4(%rbp), %ecx
andl $0x7f, %ecx
movl $0x63, %esi
leaq 0x2aef(%rip), %rdx      # 0x410e
movb $0x0, %al
callq 0x10d0
jmp 0x162d
callq 0x1040
jmp 0x162f
movl -0x84(%rbp), %edi
movl $0x9, %esi
callq 0x1200
movl %eax, -0xf8(%rbp)
cmpl $0x0, -0xf8(%rbp)
jne 0x166a
leaq -0xf0(%rbp), %rdi
movl $0x63, %esi
leaq 0x2ac0(%rip), %rdx      # 0x4121
movb $0x0, %al
callq 0x10d0
jmp 0x1687
callq 0x1050
cmpl $0x3, (%rax)
je 0x1685
leaq 0x2ac2(%rip), %rdi      # 0x413d
callq 0x1250
callq 0x1040
jmp 0x1687
cmpb $0x0, -0xf0(%rbp)
je 0x16ae
movl $0x1, -0x14(%rbp)
leaq -0xf0(%rbp), %rsi
leaq 0x2a9f(%rip), %rdi      # 0x4144
movb $0x0, %al
callq 0x10c0
jmp 0x16bc
leaq 0x2a9b(%rip), %rdi      # 0x4150
movb $0x0, %al
callq 0x10c0
jmp 0x13ea
movq -0x10(%rbp), %rdi
callq 0x1130
cmpl $0x0, %eax
jne 0x16d1
jmp 0x16e9
leaq 0x2a7d(%rip), %rdi      # 0x4155
leaq 0x2929(%rip), %rsi      # 0x4008
movl $0x4b, %edx
callq 0x1700
movl -0x14(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw %cs:(%rax,%rax)