// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/udp.c
// Function: handle_epoll_udp
void handle_epoll_udp(uint32_t events, tun_data_t *data) {
  ELOG(__FUNCTION__);

  static char *buf = NULL;
  int nread;
  ip_addr_t saddr, daddr;
  struct pbuf *p;

  printf("%d %d\n", data->sport, data->dport);

  /* get data from udp socket fd */
  if (!buf) {
    buf = MALLOC(MTU);
  }
  nread = read(data->fd, buf, MTU);
  if (nread <= 0 || nread == MTU) {
    ELOG("error udp packet size");
    return;
  }

  /* destination information */
  if (data->type == TUN_UDP) {
    saddr.type = IPADDR_TYPE_V4;
    memcpy(&saddr.u_addr, &data->saddr, 4);
    daddr.type = IPADDR_TYPE_V4;
    memcpy(&daddr.u_addr, &data->daddr, 4);
  } else if (data->type == TUN_UDP6) {
    saddr.type = IPADDR_TYPE_V6;
    memcpy(&saddr.u_addr, &data->saddr, 16);
    daddr.type = IPADDR_TYPE_V6;
    memcpy(&daddr.u_addr, &data->daddr, 16);
  }

  /* pack data and sendto */
  p = pbuf_alloc_reference(buf, nread, PBUF_ROM);
  if (!p) {
    ELOG("pbuf_alloc_reference");
    return;
  }

  udp_sendto(data->upcb, p, &saddr, data->sport, &daddr, data->dport);

  close(data->fd);
  FREE(data);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x2add2(%rip), %rax     # 0x2eff8
movq (%rax), %rdi
leaq 0x22e3a(%rip), %rsi     # 0x2706a
leaq 0x2512d(%rip), %rdx     # 0x29364
movl $0x4f, %ecx
leaq 0x23032(%rip), %r8      # 0x27275
movb $0x0, %al
callq 0x2170
movq -0x10(%rbp), %rax
movzwl 0x30(%rax), %esi
movq -0x10(%rbp), %rax
movzwl 0x32(%rax), %edx
leaq 0x22fe7(%rip), %rdi     # 0x27248
movb $0x0, %al
callq 0x20d0
cmpq $0x0, 0x2b4f8(%rip)     # 0x2f768
jne 0x4283
movl $0x5dc, %edi            # imm = 0x5DC
callq 0x31e0
movq %rax, 0x2b4e5(%rip)     # 0x2f768
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
movq 0x2b4d7(%rip), %rsi     # 0x2f768
movl $0x5dc, %edx            # imm = 0x5DC
callq 0x2140
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x42ad
cmpl $0x5dc, -0x14(%rbp)     # imm = 0x5DC
jne 0x42df
jmp 0x42af
movq 0x2ad42(%rip), %rax     # 0x2eff8
movq (%rax), %rdi
leaq 0x22daa(%rip), %rsi     # 0x2706a
leaq 0x2509d(%rip), %rdx     # 0x29364
movl $0x5e, %ecx
leaq 0x22fb3(%rip), %r8      # 0x27286
movb $0x0, %al
callq 0x2170
jmp 0x43dc
movq -0x10(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x4306
movb $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x2c(%rbp)
movb $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0x4341
movq -0x10(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x433f
movb $0x6, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x2c(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x24(%rbp)
movb $0x6, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x44(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0x3c(%rbp)
jmp 0x4341
movq 0x2b420(%rip), %rdi     # 0x2f768
movl -0x14(%rbp), %eax
movl $0x1, %edx
movzwl %ax, %esi
callq 0x71a0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x4392
jmp 0x4365
movq 0x2ac8c(%rip), %rax     # 0x2eff8
movq (%rax), %rdi
leaq 0x22cf4(%rip), %rsi     # 0x2706a
leaq 0x24fe7(%rip), %rdx     # 0x29364
movl $0x72, %ecx
leaq 0x22f13(%rip), %r8      # 0x2729c
movb $0x0, %al
callq 0x2170
jmp 0x43dc
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x50(%rbp), %rsi
movq -0x10(%rbp), %rax
movw 0x30(%rax), %cx
movq -0x10(%rbp), %rax
leaq -0x2c(%rbp), %rdx
leaq -0x44(%rbp), %r8
movzwl %cx, %ecx
movzwl 0x32(%rax), %r9d
callq 0x17620
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x2120
movq -0x10(%rbp), %rdi
callq 0x2030
movq $0x0, -0x10(%rbp)
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)