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

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

    struct chunk *c = malloc(sizeof(struct chunk) + queued + CHUNK_OVERHEAD);
    if (!c) return;
    memset(c, 0, sizeof(struct chunk));
    c->done = CHUNK_PRE;

    ssize_t n;
    do {
      n = read(conn->outfd, c->data + CHUNK_PRE, queued);
    } while (n == -1 && errno == EINTR);

    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 + c->done;
      const char was_empty_q = conn->obsqhead ? 0 : 1;

      connection_obs_prepare(conn, c);
      chunk_nq(c, &conn->obsqhead, &conn->obsqtail);
      conn->obsqlen += c->length;

      if (was_empty_q) connection_obs_write(conn);
    }
  }

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

  connection_setevents(conn);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdx, %rbx
movl %esi, %ebp
testb $0x2, %bpl
jne 0x19dc
movzwl %bp, %eax
testb $0x4, %al
je 0x19cf
movq %rbx, %rdi
callq 0x1d7c
testl %eax, %eax
je 0x1b59
movq %rbx, %rdi
callq 0x1817
jmp 0x1b59
movl 0x1cc(%rbx), %edi
leaq 0xc(%rsp), %rdx
movl $0x541b, %esi           # imm = 0x541B
xorl %eax, %eax
callq 0x10d0
testl %eax, %eax
jne 0x1b45
movl 0xc(%rsp), %eax
testl %eax, %eax
jne 0x1a0e
movl $0x10, 0xc(%rsp)
pushq $0x10
popq %rax
movslq %eax, %rdi
addq $0x58, %rdi
callq 0x1160
testq %rax, %rax
je 0x1b59
movq %rax, %r14
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0x40, 0x14(%rax)
leaq 0x58(%rax), %r15
movl 0x1cc(%rbx), %edi
movslq 0xc(%rsp), %rdx
movq %r15, %rsi
callq 0x10f0
cmpq $-0x1, %rax
jne 0x1a66
callq 0x1050
movl (%rax), %eax
cmpl $0x4, %eax
je 0x1a3c
jmp 0x1b2a
testq %rax, %rax
js 0x1b23
je 0x1b3b
movl 0x14(%r14), %ecx
leal (%rcx,%rax), %edx
movl %edx, 0x10(%r14)
movq 0x2e0(%rbx), %r12
leaq (%r14,%rcx), %rdx
addq $0x18, %rdx
movl %eax, %ecx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x2e5e
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2ea3
movq 0x8(%r15), %rdx
cmpq $0x41, %rdx
jae 0x1b66
movl 0x14(%r14), %edi
subl %edx, %edi
movl %edi, 0x14(%r14)
addl %edx, 0x10(%r14)
movq %r14, %rax
addq $0x18, %rax
addq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x1140
movq 0x2e8(%rbx), %rax
movq %rax, 0x8(%r14)
andq $0x0, (%r14)
movq %r14, 0x2e8(%rbx)
cmpq $0x0, 0x2e0(%rbx)
jne 0x1b03
movq %r14, 0x2e0(%rbx)
movl 0x10(%r14), %eax
addl %eax, 0x304(%rbx)
testq %r12, %r12
jne 0x19b8
movq %rbx, %rdi
callq 0x1cfe
jmp 0x19b8
callq 0x1050
movl (%rax), %eax
cmpl $0xb, %eax
je 0x1b59
leaq 0x6635(%rip), %rdi      # 0x816b
callq 0x11c0
movq %r14, %rdi
callq 0x1030
jmp 0x1b51
leaq 0x6619(%rip), %rdi      # 0x8165
callq 0x11c0
movq %rbx, %rdi
callq 0x190b
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x1040