// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/tcp.c
// Function: epoll_to_lwip
static void epoll_to_lwip(tun_data_t *data) {
  ELOG(__FUNCTION__);

  int nread, send_len;
  extern int errno;
  err_t err;

  nread = read(data->fd, data->server_buf + data->server_buf_len,
               TUN_TCP_SIZE - data->server_buf_len);
  if (nread == -1 && errno != EAGAIN) {
    ELOG("read()");
    tun_tcp_close(data);
    return;
  } else if (nread == 0) {
    if (data->client_status == TUN_CLOSE) {
      tun_tcp_close(data);
      return;
    } else {
      data->server_status = TUN_CLOSE;
    }
  } else if (nread > 0) {
    data->server_buf_len += nread;

    send_len = (data->server_buf_len < tcp_sndbuf(data->tpcb))
                   ? data->server_buf_len
                   : tcp_sndbuf(data->tpcb);

    err =
        tcp_write(data->tpcb, data->server_buf, send_len, TCP_WRITE_FLAG_COPY);
    if (err == ERR_OK) {
      data->server_buf_len -= send_len;
      tcp_output(data->tpcb);
    } else if (err != ERR_MEM) {
      ELOG("tcp_write()");
      tun_tcp_close(data);
      return;
    }
  }

  /* TUN_CLOSE and no buf left, should shutdown write side */
  if (data->server_buf_len == 0 && data->server_status == TUN_CLOSE) {
    ELOG("shutdown server write");

    tcp_shutdown(data->tpcb, 0, 1);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq 0x2b5c5(%rip), %rax     # 0x2eff8
movq (%rax), %rdi
leaq 0x2362d(%rip), %rsi     # 0x2706a
leaq 0x2433b(%rip), %rdx     # 0x27d7f
movl $0xd7, %ecx
leaq 0x237b4(%rip), %r8      # 0x27204
movb $0x0, %al
callq 0x2170
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x8(%rbp), %rax
movslq 0x2c(%rax), %rax
addq %rax, %rsi
movq -0x8(%rbp), %rcx
movl $0xffff, %eax           # imm = 0xFFFF
subl 0x2c(%rcx), %eax
movslq %eax, %rdx
callq 0x2140
movl %eax, -0xc(%rbp)
cmpl $-0x1, -0xc(%rbp)
jne 0x3ad3
callq 0x2050
cmpl $0xb, (%rax)
je 0x3ad3
jmp 0x3a9a
movq 0x2b557(%rip), %rax     # 0x2eff8
movq (%rax), %rdi
leaq 0x235bf(%rip), %rsi     # 0x2706a
leaq 0x242cd(%rip), %rdx     # 0x27d7f
movl $0xe0, %ecx
leaq 0x23754(%rip), %r8      # 0x27212
movb $0x0, %al
callq 0x2170
movq -0x8(%rbp), %rdi
callq 0x3610
jmp 0x3c3e
cmpl $0x0, -0xc(%rbp)
jne 0x3b01
movq -0x8(%rbp), %rax
cmpl $0x2, 0x10(%rax)
jne 0x3af1
movq -0x8(%rbp), %rdi
callq 0x3610
jmp 0x3c3e
movq -0x8(%rbp), %rax
movl $0x2, 0x14(%rax)
jmp 0x3be7
cmpl $0x0, -0xc(%rbp)
jle 0x3be5
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0x2c(%rax), %ecx
movl %ecx, 0x2c(%rax)
movq -0x8(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movzwl 0x9c(%rcx), %ecx
cmpl %ecx, %eax
jge 0x3b3e
movq -0x8(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x18(%rbp)
jmp 0x3b50
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movzwl 0x9c(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movl -0x10(%rbp), %eax
movl $0x1, %ecx
movzwl %ax, %edx
callq 0x12a00
movb %al, -0x11(%rbp)
movsbl -0x11(%rbp), %eax
cmpl $0x0, %eax
jne 0x3ba0
movl -0x10(%rbp), %edx
movq -0x8(%rbp), %rax
movl 0x2c(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x2c(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x14b70
jmp 0x3be3
movsbl -0x11(%rbp), %eax
cmpl $-0x1, %eax
je 0x3be1
jmp 0x3bab
movq 0x2b446(%rip), %rax     # 0x2eff8
movq (%rax), %rdi
leaq 0x234ae(%rip), %rsi     # 0x2706a
leaq 0x241bc(%rip), %rdx     # 0x27d7f
movl $0xf7, %ecx
leaq 0x2364a(%rip), %r8      # 0x27219
movb $0x0, %al
callq 0x2170
movq -0x8(%rbp), %rdi
callq 0x3610
jmp 0x3c3e
jmp 0x3be3
jmp 0x3be5
jmp 0x3be7
jmp 0x3be9
movq -0x8(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jne 0x3c3e
movq -0x8(%rbp), %rax
cmpl $0x2, 0x14(%rax)
jne 0x3c3e
jmp 0x3bff
movq 0x2b3f2(%rip), %rax     # 0x2eff8
movq (%rax), %rdi
leaq 0x2345a(%rip), %rsi     # 0x2706a
leaq 0x24168(%rip), %rdx     # 0x27d7f
movl $0xff, %ecx
leaq 0x23602(%rip), %r8      # 0x27225
movb $0x0, %al
callq 0x2170
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0xb640
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)