// File: /workspace/github_c_makefile_star2_O1/motet-a[P]libforks/examples/fizz_buzz_threads.c
// Function: echo_upper
static void echo_upper(const char *text) {
  int socket_fd;
  int exit_fd;

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

  int ready_pipe[2];
  assert(pipe(ready_pipe) == 0);

  assert(libforks_write_socket_fds(socket_fd, "a", 1, &threads_output_fd, 1) == 0);
  assert(libforks_write_socket_fds(socket_fd, "b", 1, &ready_pipe[1], 1) == 0);

  // wait until the child process finishes to setup its file descriptors
  char c;
  assert(read(ready_pipe[0], &c, 1) == 1);
  close(ready_pipe[0]);
  close(ready_pipe[1]);

  assert(write(socket_fd, text, strlen(text)) == (ssize_t)strlen(text));

  // `shutdown` is necessary here to send EOF
  int r = shutdown(socket_fd, SHUT_WR);
  assert(r == 0);
  assert(close(socket_fd) == 0);

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

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movq 0x4a9a(%rip), %rdi      # 0x6138
leaq 0x246(%rip), %r8        # 0x18eb
leaq 0x4(%rsp), %rdx
leaq 0xc(%rsp), %rcx
xorl %esi, %esi
callq 0x2907
testl %eax, %eax
jne 0x17d4
leaq 0x10(%rsp), %rdi
callq 0x1110
testl %eax, %eax
jne 0x17f3
movl 0x4(%rsp), %edi
leaq 0x1c1f(%rip), %rsi      # 0x32fa
leaq 0x4a5e(%rip), %rcx      # 0x6140
movl $0x1, %edx
movl $0x1, %r8d
callq 0x1d27
testl %eax, %eax
jne 0x1812
movl 0x4(%rsp), %edi
leaq 0x14(%rsp), %rcx
leaq 0x1c3b(%rip), %rsi      # 0x3345
movl $0x1, %edx
movl $0x1, %r8d
callq 0x1d27
testl %eax, %eax
jne 0x1831
movl 0x10(%rsp), %edi
leaq 0xb(%rsp), %rsi
movl $0x1, %edx
callq 0x1120
cmpq $0x1, %rax
jne 0x1850
movl 0x10(%rsp), %edi
callq 0x10f0
movl 0x14(%rsp), %edi
callq 0x10f0
movl 0x4(%rsp), %ebp
movq %rbx, %rdi
callq 0x10b0
movl %ebp, %edi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1080
movq %rax, %r14
movq %rbx, %rdi
callq 0x10b0
cmpq %rax, %r14
jne 0x186f
movl 0x4(%rsp), %edi
movl $0x1, %esi
callq 0x10a0
testl %eax, %eax
jne 0x188e
movl 0x4(%rsp), %edi
callq 0x10f0
testl %eax, %eax
jne 0x18ad
movl 0xc(%rsp), %edi
leaq 0x18(%rsp), %rsi
movl $0x8, %edx
callq 0x1120
cmpq $0x8, %rax
jne 0x18cc
movl 0xc(%rsp), %edi
callq 0x10f0
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x1a99(%rip), %rdi      # 0x3274
leaq 0x1847(%rip), %rsi      # 0x3029
leaq 0x1add(%rip), %rcx      # 0x32c6
movl $0x40, %edx
callq 0x10e0
leaq 0x1aea(%rip), %rdi      # 0x32e4
leaq 0x1828(%rip), %rsi      # 0x3029
leaq 0x1abe(%rip), %rcx      # 0x32c6
movl $0x43, %edx
callq 0x10e0
leaq 0x1ae3(%rip), %rdi      # 0x32fc
leaq 0x1809(%rip), %rsi      # 0x3029
leaq 0x1a9f(%rip), %rcx      # 0x32c6
movl $0x45, %edx
callq 0x10e0
leaq 0x1b0f(%rip), %rdi      # 0x3347
leaq 0x17ea(%rip), %rsi      # 0x3029
leaq 0x1a80(%rip), %rcx      # 0x32c6
movl $0x46, %edx
callq 0x10e0
leaq 0x1b35(%rip), %rdi      # 0x338c
leaq 0x17cb(%rip), %rsi      # 0x3029
leaq 0x1a61(%rip), %rcx      # 0x32c6
movl $0x4a, %edx
callq 0x10e0
leaq 0x1b36(%rip), %rdi      # 0x33ac
leaq 0x17ac(%rip), %rsi      # 0x3029
leaq 0x1a42(%rip), %rcx      # 0x32c6
movl $0x4e, %edx
callq 0x10e0
leaq 0x1b55(%rip), %rdi      # 0x33ea
leaq 0x178d(%rip), %rsi      # 0x3029
leaq 0x1a23(%rip), %rcx      # 0x32c6
movl $0x52, %edx
callq 0x10e0
leaq 0x1b3d(%rip), %rdi      # 0x33f1
leaq 0x176e(%rip), %rsi      # 0x3029
leaq 0x1a04(%rip), %rcx      # 0x32c6
movl $0x53, %edx
callq 0x10e0
leaq 0x18c6(%rip), %rdi      # 0x3199
leaq 0x174f(%rip), %rsi      # 0x3029
leaq 0x19e5(%rip), %rcx      # 0x32c6
movl $0x56, %edx
callq 0x10e0