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

  const int nfd = accept(fd, NULL, NULL);
  if (nfd < 0) {
    perror("accept");
    return;
  }

  struct connection *conn = (struct connection *) calloc(sizeof(struct connection), 1);
  if (!conn) {
    close(nfd);
    return;
  }

  obstcp_server_ctx_init(&conn->ctx, cfg->keys);
  conn->fd = nfd;
  obstcp_rbuf_server_init(&conn->rbuf, &conn->ctx);

  conn->outfd = socket(PF_INET, SOCK_STREAM, 0);
  if (conn->outfd < 0) {
    perror("socket");
    goto out;
  }

  struct sockaddr_in sin;
  memset(&sin, 0, sizeof(sin));
  sin.sin_addr.s_addr = cfg->target_ip;
  sin.sin_port = htons(cfg->target_port);
  sin.sin_family = AF_INET;

  fcntl(conn->outfd, F_SETFL, O_NONBLOCK);
  fcntl(conn->fd, F_SETFL, O_NONBLOCK);

  int n;
  do {
    n = connect(conn->outfd, (struct sockaddr *) &sin, sizeof(sin));
  } while (n == -1 && errno == EINTR);

  if (n < 0) {
    if (errno != EINPROGRESS) {
      perror("connect");
      close(conn->outfd);
      goto out;
    }

    event_set(&conn->outevent, conn->outfd, EV_WRITE, connect_cb, conn);
    event_add(&conn->outevent, NULL);
  } else {
    connection_setevents(conn);
  }

  return;

out:
  close(nfd);
  free(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)
movl -0x4(%rbp), %edi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x1200
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x17d7
leaq 0xb952(%rip), %rdi      # 0xd11f
callq 0x11f0
jmp 0x1995
movl $0x308, %edi            # imm = 0x308
movl $0x1, %esi
callq 0x1130
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x17fe
movl -0x1c(%rbp), %edi
callq 0x1100
jmp 0x1995
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x3520
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1c8(%rax)
movq -0x28(%rbp), %rdi
addq $0x198, %rdi            # imm = 0x198
movq -0x28(%rbp), %rsi
callq 0x5520
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x1260
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1cc(%rax)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x1cc(%rax)
jge 0x186b
leaq 0xb891(%rip), %rdi      # 0xd0f2
callq 0x11f0
jmp 0x1984
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x10e0
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x4(%rax), %edi
callq 0x10a0
movw %ax, -0x36(%rbp)
movw $0x2, -0x38(%rbp)
movq -0x28(%rbp), %rax
movl 0x1cc(%rax), %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
movb $0x0, %al
callq 0x1080
movq -0x28(%rbp), %rax
movl 0x1c8(%rax), %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
movb $0x0, %al
callq 0x1080
movq -0x28(%rbp), %rax
movl 0x1cc(%rax), %edi
leaq -0x38(%rbp), %rsi
movl $0x10, %edx
callq 0x1220
movl %eax, -0x3c(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x3c(%rbp)
movb %al, -0x3d(%rbp)
jne 0x1905
callq 0x1050
cmpl $0x4, (%rax)
sete %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0x18d1
cmpl $0x0, -0x3c(%rbp)
jge 0x1979
callq 0x1050
cmpl $0x73, (%rax)
je 0x1939
leaq 0xb803(%rip), %rdi      # 0xd126
callq 0x11f0
movq -0x28(%rbp), %rax
movl 0x1cc(%rax), %edi
callq 0x1100
jmp 0x1984
movq -0x28(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
movq -0x28(%rbp), %rax
movl 0x1cc(%rax), %esi
movq -0x28(%rbp), %r8
movl $0x4, %edx
leaq 0x42(%rip), %rcx        # 0x19a0
callq 0x11c0
movq -0x28(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
xorl %eax, %eax
movl %eax, %esi
callq 0x1140
jmp 0x1982
movq -0x28(%rbp), %rdi
callq 0x1a50
jmp 0x1995
movl -0x1c(%rbp), %edi
callq 0x1100
movq -0x28(%rbp), %rdi
callq 0x1030
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)