// File: /workspace/github_c_makefile_star2_O2/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 0x4ace(%rip), %rdi      # 0x6138
leaq 0x20d(%rip), %r8        # 0x187e
leaq 0x4(%rsp), %rdx
leaq 0xc(%rsp), %rcx
xorl %esi, %esi
callq 0x26ea
testl %eax, %eax
jne 0x1790
leaq 0x10(%rsp), %rdi
callq 0x1110
testl %eax, %eax
jne 0x17ac
movl 0x4(%rsp), %edi
leaq 0x1c53(%rip), %rsi      # 0x32fa
leaq 0x4a92(%rip), %rcx      # 0x6140
pushq $0x1
popq %rdx
movq %rdx, %r8
callq 0x1c5f
testl %eax, %eax
jne 0x17c8
movl 0x4(%rsp), %edi
leaq 0x14(%rsp), %rcx
leaq 0x1c74(%rip), %rsi      # 0x3345
pushq $0x1
popq %rdx
movq %rdx, %r8
callq 0x1c5f
testl %eax, %eax
jne 0x17e4
movl 0x10(%rsp), %edi
leaq 0xb(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x1120
cmpq $0x1, %rax
jne 0x17fd
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 0x1816
movl 0x4(%rsp), %edi
pushq $0x1
popq %rsi
callq 0x10a0
testl %eax, %eax
jne 0x182f
movl 0x4(%rsp), %edi
callq 0x10f0
testl %eax, %eax
jne 0x1848
movl 0xc(%rsp), %edi
leaq 0x18(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x1120
cmpq $0x8, %rax
jne 0x1861
movl 0xc(%rsp), %edi
callq 0x10f0
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x1add(%rip), %rdi      # 0x3274
leaq 0x188b(%rip), %rsi      # 0x3029
leaq 0x1b21(%rip), %rcx      # 0x32c6
pushq $0x40
jmp 0x1878
leaq 0x1b31(%rip), %rdi      # 0x32e4
leaq 0x186f(%rip), %rsi      # 0x3029
leaq 0x1b05(%rip), %rcx      # 0x32c6
pushq $0x43
jmp 0x1878
leaq 0x1b2d(%rip), %rdi      # 0x32fc
leaq 0x1853(%rip), %rsi      # 0x3029
leaq 0x1ae9(%rip), %rcx      # 0x32c6
pushq $0x45
jmp 0x1878
leaq 0x1b5c(%rip), %rdi      # 0x3347
leaq 0x1837(%rip), %rsi      # 0x3029
leaq 0x1acd(%rip), %rcx      # 0x32c6
pushq $0x46
jmp 0x1878
leaq 0x1b88(%rip), %rdi      # 0x338c
leaq 0x181e(%rip), %rsi      # 0x3029
leaq 0x1ab4(%rip), %rcx      # 0x32c6
pushq $0x4a
jmp 0x1878
leaq 0x1b8f(%rip), %rdi      # 0x33ac
leaq 0x1805(%rip), %rsi      # 0x3029
leaq 0x1a9b(%rip), %rcx      # 0x32c6
pushq $0x4e
jmp 0x1878
leaq 0x1bb4(%rip), %rdi      # 0x33ea
leaq 0x17ec(%rip), %rsi      # 0x3029
leaq 0x1a82(%rip), %rcx      # 0x32c6
pushq $0x52
jmp 0x1878
leaq 0x1ba2(%rip), %rdi      # 0x33f1
leaq 0x17d3(%rip), %rsi      # 0x3029
leaq 0x1a69(%rip), %rcx      # 0x32c6
pushq $0x53
jmp 0x1878
leaq 0x1931(%rip), %rdi      # 0x3199
leaq 0x17ba(%rip), %rsi      # 0x3029
leaq 0x1a50(%rip), %rcx      # 0x32c6
pushq $0x56
popq %rdx
callq 0x10e0