// File: /workspace/github_c_makefile_star2_O0/agl[P]obstcp/obstcp-redir.c
// Function: connection_obs_cb
static void
connection_obs_cb(int fd, short events, void *arg) {
  struct connection *conn = (struct connection *) arg;

  if (EV_READ & events) {
    int queued;
    if (ioctl(conn->fd, SIOCINQ, &queued)) {
      perror("ioctl");
      connection_free(conn);
      return;
    }
    if (!queued) queued = 16;

    struct chunk *c = malloc(sizeof(struct chunk) + queued);
    if (!c) return;
    memset(c, 0, sizeof(struct chunk));

    const ssize_t n =
      obstcp_rbuf_read_fd(&conn->rbuf, conn->fd, c->data, queued);

    if (n < 0) {
      if (errno == EAGAIN || errno == EWOULDBLOCK) return;
      perror("read");
      free(c);
      connection_free(conn);
      return;
    } else if (n == 0) {
      free(c);
      connection_free(conn);
      return;
    } else {
      c->length = n;
      const char was_empty_q = conn->outqhead ? 0 : 1;

      conn->outqlen += c->length;
      if (conn->pendingqhead) {
        chunks_move(&conn->outqhead, &conn->outqtail,
                    &conn->pendingqhead, &conn->pendingqtail);
      }
      chunk_nq(c, &conn->outqhead, &conn->outqtail);
      if (was_empty_q) if (!connection_out_write(conn)) return;
    }
  }

  if (EV_WRITE & events) {
    if (!connection_obs_write(conn)) return;
  }

  connection_setevents(conn);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movw %si, %ax
movl %edi, -0x4(%rbp)
movw %ax, -0x6(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movswl -0x6(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x20a8
movq -0x18(%rbp), %rax
movl 0x1c8(%rax), %edi
movl $0x541b, %esi           # imm = 0x541B
leaq -0x1c(%rbp), %rdx
movb $0x0, %al
callq 0x10f0
cmpl $0x0, %eax
je 0x1f27
leaq 0xb251(%rip), %rdi      # 0xd165
callq 0x11f0
movq -0x18(%rbp), %rdi
callq 0x1bc0
jmp 0x20cf
cmpl $0x0, -0x1c(%rbp)
jne 0x1f34
movl $0x10, -0x1c(%rbp)
movslq -0x1c(%rbp), %rdi
addq $0x18, %rdi
callq 0x1180
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x1f51
jmp 0x20cf
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x10e0
movq -0x18(%rbp), %rdi
addq $0x198, %rdi            # imm = 0x198
movq -0x18(%rbp), %rax
movl 0x1c8(%rax), %esi
movq -0x28(%rbp), %rdx
addq $0x18, %rdx
movslq -0x1c(%rbp), %rcx
callq 0x5d50
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jge 0x1fce
callq 0x1050
cmpl $0xb, (%rax)
je 0x1fa6
callq 0x1050
cmpl $0xb, (%rax)
jne 0x1fab
jmp 0x20cf
leaq 0xb1b9(%rip), %rdi      # 0xd16b
callq 0x11f0
movq -0x28(%rbp), %rdi
callq 0x1030
movq -0x18(%rbp), %rdi
callq 0x1bc0
jmp 0x20cf
cmpq $0x0, -0x30(%rbp)
jne 0x1fec
movq -0x28(%rbp), %rdi
callq 0x1030
movq -0x18(%rbp), %rdi
callq 0x1bc0
jmp 0x20cf
movq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x2d0(%rax), %rdx
movl $0x1, %eax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movb %al, -0x31(%rbp)
movq -0x28(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x18(%rbp), %rax
addl 0x300(%rax), %ecx
movl %ecx, 0x300(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x2f0(%rax)
je 0x206b
movq -0x18(%rbp), %rdi
addq $0x2d0, %rdi            # imm = 0x2D0
movq -0x18(%rbp), %rsi
addq $0x2d8, %rsi            # imm = 0x2D8
movq -0x18(%rbp), %rdx
addq $0x2f0, %rdx            # imm = 0x2F0
movq -0x18(%rbp), %rcx
addq $0x2f8, %rcx            # imm = 0x2F8
callq 0x24e0
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x2d0, %rsi            # imm = 0x2D0
movq -0x18(%rbp), %rdx
addq $0x2d8, %rdx            # imm = 0x2D8
callq 0x2190
cmpb $0x0, -0x31(%rbp)
je 0x20a2
movq -0x18(%rbp), %rdi
callq 0x22b0
cmpl $0x0, %eax
jne 0x20a0
jmp 0x20cf
jmp 0x20a2
jmp 0x20a4
jmp 0x20a6
jmp 0x20a8
movswl -0x6(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x20c6
movq -0x18(%rbp), %rdi
callq 0x21e0
cmpl $0x0, %eax
jne 0x20c4
jmp 0x20cf
jmp 0x20c6
movq -0x18(%rbp), %rdi
callq 0x1a50
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)