// File: /workspace/github_c_makefile_star2_O1/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 0x1aa4
movzwl %bp, %eax
testb $0x4, %al
je 0x1a97
movq %rbx, %rdi
callq 0x1e52
testl %eax, %eax
je 0x1c21
movq %rbx, %rdi
callq 0x18d9
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
cmpl $0x0, 0xc(%rsp)
jne 0x1ad2
movl $0x10, 0xc(%rsp)
movslq 0xc(%rsp), %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), %r12
movl 0x1cc(%rbx), %edi
movslq 0xc(%rsp), %rdx
movq %r12, %rsi
callq 0x10f0
movq %rax, %r15
cmpq $-0x1, %rax
jne 0x1b2b
callq 0x1050
cmpl $0x4, (%rax)
je 0x1b05
testq %r15, %r15
js 0x1bed
je 0x1c03
movl 0x14(%r14), %eax
leal (%rax,%r15), %ecx
movl %ecx, 0x10(%r14)
movq 0x2e0(%rbx), %r12
leaq (%r14,%rax), %rdx
addq $0x18, %rdx
movl %r15d, %ecx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x3241
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3286
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 0x1bcd
movq %r14, 0x2e0(%rbx)
movl 0x10(%r14), %eax
addl %eax, 0x304(%rbx)
testq %r12, %r12
jne 0x1a80
movq %rbx, %rdi
callq 0x1dcd
jmp 0x1a80
callq 0x1050
cmpl $0xb, (%rax)
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 0x19cd
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x1040