// File: /workspace/github_c_makefile_star2_O3/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 0x1a9c
movzwl %bp, %eax
testb $0x4, %al
je 0x1a8f
movq %rbx, %rdi
callq 0x1e65
testl %eax, %eax
je 0x1c21
movq %rbx, %rdi
callq 0x18d1
jmp 0x1c21
movl 0x1cc(%rbx), %edi
leaq 0xc(%rsp), %rdx
movl $0x541b, %esi           # imm = 0x541B
xorl %eax, %eax
callq 0x10d0
testl %eax, %eax
jne 0x1c0d
movl 0xc(%rsp), %eax
testl %eax, %eax
jne 0x1ad0
movl $0x10, 0xc(%rsp)
movl $0x10, %eax
movslq %eax, %rdi
addq $0x58, %rdi
callq 0x1160
testq %rax, %rax
je 0x1c21
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%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 0x1b2b
callq 0x1050
movl (%rax), %eax
cmpl $0x4, %eax
je 0x1b01
jmp 0x1bf2
testq %rax, %rax
js 0x1beb
je 0x1c03
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 0x3034
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3079
movq 0x8(%r15), %rdx
cmpq $0x41, %rdx
jae 0x1c2e
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)
movq $0x0, (%r14)
movq %r14, 0x2e8(%rbx)
cmpq $0x0, 0x2e0(%rbx)
jne 0x1bcb
movq %r14, 0x2e0(%rbx)
movl 0x10(%r14), %eax
addl %eax, 0x304(%rbx)
testq %r12, %r12
jne 0x1a78
movq %rbx, %rdi
callq 0x1de0
jmp 0x1a78
callq 0x1050
movl (%rax), %eax
cmpl $0xb, %eax
je 0x1c21
leaq 0x656d(%rip), %rdi      # 0x816b
callq 0x11c0
movq %r14, %rdi
callq 0x1030
jmp 0x1c19
leaq 0x6551(%rip), %rdi      # 0x8165
callq 0x11c0
movq %rbx, %rdi
callq 0x19c5
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x1040