// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq 0x5a7d(%rip), %rdi      # 0x7140
xorl %eax, %eax
movl %eax, %esi
leaq -0xc(%rbp), %rdx
leaq -0x10(%rbp), %rcx
leaq 0x23a(%rip), %r8        # 0x1910
callq 0x2950
cmpl $0x0, %eax
jne 0x16e2
jmp 0x1701
leaq 0x2b8b(%rip), %rdi      # 0x4274
leaq 0x2939(%rip), %rsi      # 0x4029
movl $0x40, %edx
leaq 0x2bca(%rip), %rcx      # 0x42c6
callq 0x10e0
leaq -0x18(%rbp), %rdi
callq 0x1120
cmpl $0x0, %eax
jne 0x1711
jmp 0x1730
leaq 0x2bcc(%rip), %rdi      # 0x42e4
leaq 0x290a(%rip), %rsi      # 0x4029
movl $0x43, %edx
leaq 0x2b9b(%rip), %rcx      # 0x42c6
callq 0x10e0
movl -0xc(%rbp), %edi
leaq 0x2bc0(%rip), %rsi      # 0x42fa
movl $0x1, %r8d
leaq 0x5a01(%rip), %rcx      # 0x7148
movq %r8, %rdx
callq 0x1f10
cmpl $0x0, %eax
jne 0x1756
jmp 0x1775
leaq 0x2b9f(%rip), %rdi      # 0x42fc
leaq 0x28c5(%rip), %rsi      # 0x4029
movl $0x45, %edx
leaq 0x2b56(%rip), %rcx      # 0x42c6
callq 0x10e0
movl -0xc(%rbp), %edi
leaq -0x18(%rbp), %rcx
addq $0x4, %rcx
leaq 0x2bbe(%rip), %rsi      # 0x4345
movl $0x1, %r8d
movq %r8, %rdx
callq 0x1f10
cmpl $0x0, %eax
jne 0x179c
jmp 0x17bb
leaq 0x2ba4(%rip), %rdi      # 0x4347
leaq 0x287f(%rip), %rsi      # 0x4029
movl $0x46, %edx
leaq 0x2b10(%rip), %rcx      # 0x42c6
callq 0x10e0
movl -0x18(%rbp), %edi
leaq -0x19(%rbp), %rsi
movl $0x1, %edx
callq 0x1130
cmpq $0x1, %rax
jne 0x17d4
jmp 0x17f3
leaq 0x2bb1(%rip), %rdi      # 0x438c
leaq 0x2847(%rip), %rsi      # 0x4029
movl $0x4a, %edx
leaq 0x2ad8(%rip), %rcx      # 0x42c6
callq 0x10e0
movl -0x18(%rbp), %edi
callq 0x1100
movl -0x14(%rbp), %edi
callq 0x1100
movl -0xc(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10b0
movl -0x3c(%rbp), %edi
movq -0x38(%rbp), %rsi
movq %rax, %rdx
callq 0x1080
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq -0x30(%rbp), %rax
cmpq %rcx, %rax
jne 0x1844
jmp 0x1863
leaq 0x2b61(%rip), %rdi      # 0x43ac
leaq 0x27d7(%rip), %rsi      # 0x4029
movl $0x4e, %edx
leaq 0x2a68(%rip), %rcx      # 0x42c6
callq 0x10e0
movl -0xc(%rbp), %edi
movl $0x1, %esi
callq 0x10a0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x187b
jmp 0x189a
leaq 0x2b68(%rip), %rdi      # 0x43ea
leaq 0x27a0(%rip), %rsi      # 0x4029
movl $0x52, %edx
leaq 0x2a31(%rip), %rcx      # 0x42c6
callq 0x10e0
movl -0xc(%rbp), %edi
callq 0x1100
cmpl $0x0, %eax
jne 0x18a9
jmp 0x18c8
leaq 0x2b41(%rip), %rdi      # 0x43f1
leaq 0x2772(%rip), %rsi      # 0x4029
movl $0x53, %edx
leaq 0x2a03(%rip), %rcx      # 0x42c6
callq 0x10e0
movl -0x10(%rbp), %edi
leaq -0x28(%rbp), %rsi
movl $0x8, %edx
callq 0x1130
cmpq $0x8, %rax
jne 0x18e1
jmp 0x1900
leaq 0x28b1(%rip), %rdi      # 0x4199
leaq 0x273a(%rip), %rsi      # 0x4029
movl $0x56, %edx
leaq 0x29cb(%rip), %rcx      # 0x42c6
callq 0x10e0
movl -0x10(%rbp), %edi
callq 0x1100
addq $0x40, %rsp
popq %rbp
retq
nop