// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/tests/stop_wait.c
// Function: main
int main() {
  libforks_ServerConn conn;

  check(pipe(pipe_fds) == 0);
  check(fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK) != -1);

  check(libforks_start(&conn) == libforks_OK);

  check(close(pipe_fds[1]) == 0);

  check(libforks_fork(
    conn,
    NULL, // pid_ptr
    NULL, // socket_fd_ptr
    NULL, // exit_fd_ptr
    child_main
  ) == libforks_OK);

  // Fails because the pipe is non-blocking and the child
  // is currently sleeping.
  char c;
  check(read(pipe_fds[0], &c, 1) == -1);
  check(errno == EAGAIN);

  check(libforks_stop(conn) == libforks_OK); // SIGTERM sent but ignored by the child

  while (true) {
    int r = read(pipe_fds[0], &c, 1);
    if (r == -1) {
      check(errno == EAGAIN);
    } else {
      check(r == 1);
      break;
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x0, -0x4(%rbp)
leaq 0x5dee(%rip), %rdi      # 0x7124
callq 0x1110
cmpl $0x0, %eax
jne 0x1342
jmp 0x135a
leaq 0x2cbb(%rip), %rdi      # 0x4004
leaq 0x2cc8(%rip), %rsi      # 0x4018
movl $0x1a, %edx
callq 0x1510
movl 0x5dc4(%rip), %edi      # 0x7124
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
movb $0x0, %al
callq 0x1080
cmpl $-0x1, %eax
je 0x1378
jmp 0x1390
leaq 0x2cab(%rip), %rdi      # 0x402a
leaq 0x2c92(%rip), %rsi      # 0x4018
movl $0x1b, %edx
callq 0x1510
leaq -0x10(%rbp), %rdi
callq 0x1c20
cmpl $0x0, %eax
jne 0x13a0
jmp 0x13b8
leaq 0x2cb1(%rip), %rdi      # 0x4058
leaq 0x2c6a(%rip), %rsi      # 0x4018
movl $0x1d, %edx
callq 0x1510
movl 0x5d6a(%rip), %edi      # 0x7128
callq 0x10f0
cmpl $0x0, %eax
jne 0x13ca
jmp 0x13e2
leaq 0x2cac(%rip), %rdi      # 0x407d
leaq 0x2c40(%rip), %rsi      # 0x4018
movl $0x1f, %edx
callq 0x1510
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
leaq 0x15f(%rip), %r8        # 0x1550
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x23f0
cmpl $0x0, %eax
jne 0x1403
jmp 0x141b
leaq 0x2c8b(%rip), %rdi      # 0x4095
leaq 0x2c07(%rip), %rsi      # 0x4018
movl $0x27, %edx
callq 0x1510
movl 0x5d03(%rip), %edi      # 0x7124
leaq -0x11(%rbp), %rsi
movl $0x1, %edx
callq 0x1120
cmpq $-0x1, %rax
jne 0x1437
jmp 0x144f
leaq 0x2c9a(%rip), %rdi      # 0x40d8
leaq 0x2bd3(%rip), %rsi      # 0x4018
movl $0x2c, %edx
callq 0x1510
callq 0x1050
cmpl $0xb, (%rax)
jne 0x145b
jmp 0x1473
leaq 0x2c95(%rip), %rdi      # 0x40f7
leaq 0x2baf(%rip), %rsi      # 0x4018
movl $0x2d, %edx
callq 0x1510
movq -0x10(%rbp), %rdi
callq 0x2680
cmpl $0x0, %eax
jne 0x1483
jmp 0x149b
leaq 0x2c7d(%rip), %rdi      # 0x4107
leaq 0x2b87(%rip), %rsi      # 0x4018
movl $0x2f, %edx
callq 0x1510
jmp 0x149d
movl 0x5c81(%rip), %edi      # 0x7124
leaq -0x11(%rbp), %rsi
movl $0x1, %edx
callq 0x1120
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x14e0
callq 0x1050
cmpl $0xb, (%rax)
jne 0x14c6
jmp 0x14de
leaq 0x2c2a(%rip), %rdi      # 0x40f7
leaq 0x2b44(%rip), %rsi      # 0x4018
movl $0x34, %edx
callq 0x1510
jmp 0x1502
cmpl $0x1, -0x18(%rbp)
jne 0x14e8
jmp 0x1500
leaq 0x2c3b(%rip), %rdi      # 0x412a
leaq 0x2b22(%rip), %rsi      # 0x4018
movl $0x36, %edx
callq 0x1510
jmp 0x1504
jmp 0x149d
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)