// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
leaq 0x5dda(%rip), %rdi      # 0x7140
callq 0x2180
cmpl $0x0, %eax
jne 0x1372
jmp 0x1391
leaq 0x2c8b(%rip), %rdi      # 0x4004
leaq 0x2ca9(%rip), %rsi      # 0x4029
movl $0x73, %edx
leaq 0x2cba(%rip), %rcx      # 0x4046
callq 0x10e0
movq 0x5da8(%rip), %rdi      # 0x7140
xorl %eax, %eax
movl %eax, %esi
leaq 0x5da5(%rip), %rdx      # 0x7148
leaq -0x8(%rbp), %rcx
leaq 0x1f2(%rip), %r8        # 0x15a0
callq 0x2950
cmpl $0x0, %eax
jne 0x13ba
jmp 0x13d9
leaq 0x2c90(%rip), %rdi      # 0x4051
leaq 0x2c61(%rip), %rsi      # 0x4029
movl $0x7d, %edx
leaq 0x2c72(%rip), %rcx      # 0x4046
callq 0x10e0
leaq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
leaq 0x258(%rip), %rdx       # 0x1640
movq %rcx, %rsi
callq 0x11c0
cmpl $0x0, %eax
jne 0x13f7
jmp 0x1416
leaq 0x2ca7(%rip), %rdi      # 0x40a5
leaq 0x2c24(%rip), %rsi      # 0x4029
movl $0x80, %edx
leaq 0x2c35(%rip), %rcx      # 0x4046
callq 0x10e0
leaq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
leaq 0x6eb(%rip), %rdx       # 0x1b10
movq %rcx, %rsi
callq 0x11c0
cmpl $0x0, %eax
jne 0x1434
jmp 0x1453
leaq 0x2ca0(%rip), %rdi      # 0x40db
leaq 0x2be7(%rip), %rsi      # 0x4029
movl $0x81, %edx
leaq 0x2bf8(%rip), %rcx      # 0x4046
callq 0x10e0
movq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1210
cmpl $0x0, %eax
jne 0x1467
jmp 0x1486
leaq 0x2ca3(%rip), %rdi      # 0x4111
leaq 0x2bb4(%rip), %rsi      # 0x4029
movl $0x84, %edx
leaq 0x2bc5(%rip), %rcx      # 0x4046
callq 0x10e0
movq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1210
cmpl $0x0, %eax
jne 0x149a
jmp 0x14b9
leaq 0x2c90(%rip), %rdi      # 0x4131
leaq 0x2b81(%rip), %rsi      # 0x4029
movl $0x85, %edx
leaq 0x2b92(%rip), %rcx      # 0x4046
callq 0x10e0
movl 0x5c89(%rip), %edi      # 0x7148
movl $0x1, %esi
callq 0x10a0
cmpl $0x0, %eax
jne 0x14d0
jmp 0x14ef
leaq 0x2c7a(%rip), %rdi      # 0x4151
leaq 0x2b4b(%rip), %rsi      # 0x4029
movl $0x88, %edx
leaq 0x2b5c(%rip), %rcx      # 0x4046
callq 0x10e0
movl 0x5c53(%rip), %edi      # 0x7148
callq 0x1100
cmpl $0x0, %eax
jne 0x1501
jmp 0x1520
leaq 0x2c73(%rip), %rdi      # 0x417b
leaq 0x2b1a(%rip), %rsi      # 0x4029
movl $0x89, %edx
leaq 0x2b2b(%rip), %rcx      # 0x4046
callq 0x10e0
movl -0x8(%rbp), %edi
leaq -0x28(%rbp), %rsi
movl $0x8, %edx
callq 0x1130
cmpq $0x8, %rax
jne 0x1539
jmp 0x1558
leaq 0x2c59(%rip), %rdi      # 0x4199
leaq 0x2ae2(%rip), %rsi      # 0x4029
movl $0x90, %edx
leaq 0x2af3(%rip), %rcx      # 0x4046
callq 0x10e0
movl -0x8(%rbp), %edi
callq 0x1100
movq 0x5bd9(%rip), %rdi      # 0x7140
callq 0x2be0
cmpl $0x0, %eax
jne 0x1573
jmp 0x1592
leaq 0x2c4a(%rip), %rdi      # 0x41c4
leaq 0x2aa8(%rip), %rsi      # 0x4029
movl $0x93, %edx
leaq 0x2ab9(%rip), %rcx      # 0x4046
callq 0x10e0
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)