// File: /workspace/github_c_makefile_star2_O3/motet-a[P]libforks/examples/fizz_buzz_threads.c
// Function: main
int main() {
  assert(libforks_start(&conn) == libforks_OK);

  int exit_fd;

  assert(libforks_fork(
    conn,
    NULL, // pid_ptr
    &threads_output_fd, // socket_fd_ptr
    &exit_fd, // exit_fd_ptr
    sort_main
  ) == libforks_OK);

  pthread_t fizzer, buzzer;
  assert(pthread_create(&fizzer, NULL, fizzer_main, NULL) == 0);
  assert(pthread_create(&buzzer, NULL, buzzer_main, NULL) == 0);

  void *res;
  assert(pthread_join(fizzer, &res) == 0);
  assert(pthread_join(buzzer, &res) == 0);

  // `shutdown` is necessary here to send EOF to sort’s stdin
  assert(shutdown(threads_output_fd, SHUT_WR) == 0);
  assert(close(threads_output_fd) == 0);

  // `sort` exits here, the fork server receives SIGCHLD and writes
  // the exit event to `exit_fd`. The event stays in the `exit_fd`
  // buffer until we read it so there’s no race condition.

  libforks_ExitEvent ee;
  assert(read(exit_fd, &ee, sizeof ee) == sizeof ee);
  close(exit_fd);

  assert(libforks_stop(conn) == libforks_OK);
  return 0;
}

// Assembly:
subq $0x28, %rsp
leaq 0x4dd1(%rip), %rdi      # 0x6138
callq 0x1ea7
testl %eax, %eax
jne 0x1471
movq 0x4dbd(%rip), %rdi      # 0x6138
leaq 0x4dbe(%rip), %rdx      # 0x6140
leaq 0x21e(%rip), %r8        # 0x15a7
leaq 0x4(%rsp), %rcx
xorl %esi, %esi
callq 0x2834
testl %eax, %eax
jne 0x1490
leaq 0x286(%rip), %rdx       # 0x162a
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x11b0
testl %eax, %eax
jne 0x14af
leaq 0x71a(%rip), %rdx       # 0x1adb
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x11b0
testl %eax, %eax
jne 0x14ce
movq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1200
testl %eax, %eax
jne 0x14ed
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1200
testl %eax, %eax
jne 0x150c
movl 0x4d35(%rip), %edi      # 0x6140
movl $0x1, %esi
callq 0x10a0
testl %eax, %eax
jne 0x152b
movl 0x4d1d(%rip), %edi      # 0x6140
callq 0x10f0
testl %eax, %eax
jne 0x154a
movl 0x4(%rsp), %edi
leaq 0x20(%rsp), %rsi
movl $0x8, %edx
callq 0x1120
cmpq $0x8, %rax
jne 0x1569
movl 0x4(%rsp), %edi
callq 0x10f0
movq 0x4cdb(%rip), %rdi      # 0x6138
callq 0x29ef
testl %eax, %eax
jne 0x1588
xorl %eax, %eax
addq $0x28, %rsp
retq
leaq 0x1b8c(%rip), %rdi      # 0x3004
leaq 0x1baa(%rip), %rsi      # 0x3029
leaq 0x1bc0(%rip), %rcx      # 0x3046
movl $0x73, %edx
callq 0x10e0
leaq 0x1bba(%rip), %rdi      # 0x3051
leaq 0x1b8b(%rip), %rsi      # 0x3029
leaq 0x1ba1(%rip), %rcx      # 0x3046
movl $0x7d, %edx
callq 0x10e0
leaq 0x1bef(%rip), %rdi      # 0x30a5
leaq 0x1b6c(%rip), %rsi      # 0x3029
leaq 0x1b82(%rip), %rcx      # 0x3046
movl $0x80, %edx
callq 0x10e0
leaq 0x1c06(%rip), %rdi      # 0x30db
leaq 0x1b4d(%rip), %rsi      # 0x3029
leaq 0x1b63(%rip), %rcx      # 0x3046
movl $0x81, %edx
callq 0x10e0
leaq 0x1c1d(%rip), %rdi      # 0x3111
leaq 0x1b2e(%rip), %rsi      # 0x3029
leaq 0x1b44(%rip), %rcx      # 0x3046
movl $0x84, %edx
callq 0x10e0
leaq 0x1c1e(%rip), %rdi      # 0x3131
leaq 0x1b0f(%rip), %rsi      # 0x3029
leaq 0x1b25(%rip), %rcx      # 0x3046
movl $0x85, %edx
callq 0x10e0
leaq 0x1c1f(%rip), %rdi      # 0x3151
leaq 0x1af0(%rip), %rsi      # 0x3029
leaq 0x1b06(%rip), %rcx      # 0x3046
movl $0x88, %edx
callq 0x10e0
leaq 0x1c2a(%rip), %rdi      # 0x317b
leaq 0x1ad1(%rip), %rsi      # 0x3029
leaq 0x1ae7(%rip), %rcx      # 0x3046
movl $0x89, %edx
callq 0x10e0
leaq 0x1c29(%rip), %rdi      # 0x3199
leaq 0x1ab2(%rip), %rsi      # 0x3029
leaq 0x1ac8(%rip), %rcx      # 0x3046
movl $0x90, %edx
callq 0x10e0
leaq 0x1c35(%rip), %rdi      # 0x31c4
leaq 0x1a93(%rip), %rsi      # 0x3029
leaq 0x1aa9(%rip), %rcx      # 0x3046
movl $0x93, %edx
callq 0x10e0