// File: /workspace/github_c_makefile_star2_O3/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 0x4aa0(%rip), %rdi      # 0x6138
leaq 0x246(%rip), %r8        # 0x18e5
leaq 0x4(%rsp), %rdx
leaq 0xc(%rsp), %rcx
xorl %esi, %esi
callq 0x2834
testl %eax, %eax
jne 0x17ce
leaq 0x10(%rsp), %rdi
callq 0x1110
testl %eax, %eax
jne 0x17ed
movl 0x4(%rsp), %edi
leaq 0x1c25(%rip), %rsi      # 0x32fa
leaq 0x4a64(%rip), %rcx      # 0x6140
movl $0x1, %edx
movl $0x1, %r8d
callq 0x1d1b
testl %eax, %eax
jne 0x180c
movl 0x4(%rsp), %edi
leaq 0x14(%rsp), %rcx
leaq 0x1c41(%rip), %rsi      # 0x3345
movl $0x1, %edx
movl $0x1, %r8d
callq 0x1d1b
testl %eax, %eax
jne 0x182b
movl 0x10(%rsp), %edi
leaq 0xb(%rsp), %rsi
movl $0x1, %edx
callq 0x1120
cmpq $0x1, %rax
jne 0x184a
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 0x1869
movl 0x4(%rsp), %edi
movl $0x1, %esi
callq 0x10a0
testl %eax, %eax
jne 0x1888
movl 0x4(%rsp), %edi
callq 0x10f0
testl %eax, %eax
jne 0x18a7
movl 0xc(%rsp), %edi
leaq 0x18(%rsp), %rsi
movl $0x8, %edx
callq 0x1120
cmpq $0x8, %rax
jne 0x18c6
movl 0xc(%rsp), %edi
callq 0x10f0
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x1a9f(%rip), %rdi      # 0x3274
leaq 0x184d(%rip), %rsi      # 0x3029
leaq 0x1ae3(%rip), %rcx      # 0x32c6
movl $0x40, %edx
callq 0x10e0
leaq 0x1af0(%rip), %rdi      # 0x32e4
leaq 0x182e(%rip), %rsi      # 0x3029
leaq 0x1ac4(%rip), %rcx      # 0x32c6
movl $0x43, %edx
callq 0x10e0
leaq 0x1ae9(%rip), %rdi      # 0x32fc
leaq 0x180f(%rip), %rsi      # 0x3029
leaq 0x1aa5(%rip), %rcx      # 0x32c6
movl $0x45, %edx
callq 0x10e0
leaq 0x1b15(%rip), %rdi      # 0x3347
leaq 0x17f0(%rip), %rsi      # 0x3029
leaq 0x1a86(%rip), %rcx      # 0x32c6
movl $0x46, %edx
callq 0x10e0
leaq 0x1b3b(%rip), %rdi      # 0x338c
leaq 0x17d1(%rip), %rsi      # 0x3029
leaq 0x1a67(%rip), %rcx      # 0x32c6
movl $0x4a, %edx
callq 0x10e0
leaq 0x1b3c(%rip), %rdi      # 0x33ac
leaq 0x17b2(%rip), %rsi      # 0x3029
leaq 0x1a48(%rip), %rcx      # 0x32c6
movl $0x4e, %edx
callq 0x10e0
leaq 0x1b5b(%rip), %rdi      # 0x33ea
leaq 0x1793(%rip), %rsi      # 0x3029
leaq 0x1a29(%rip), %rcx      # 0x32c6
movl $0x52, %edx
callq 0x10e0
leaq 0x1b43(%rip), %rdi      # 0x33f1
leaq 0x1774(%rip), %rsi      # 0x3029
leaq 0x1a0a(%rip), %rcx      # 0x32c6
movl $0x53, %edx
callq 0x10e0
leaq 0x18cc(%rip), %rdi      # 0x3199
leaq 0x1755(%rip), %rsi      # 0x3029
leaq 0x19eb(%rip), %rcx      # 0x32c6
movl $0x56, %edx
callq 0x10e0