// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/init_tun.c
// Function: create_tun
int create_tun(char *path, char *name, int mtu, char *addr, char *netmask,
               char *addr6, int prefixlen) {
  struct sockaddr_in sai;
  int fd, sockfd, sock6fd;
  struct ifreq ifr;
  struct in6_ifreq ifr6;

  /* get fd */
  fd = open(path, O_RDWR);
  ASSERT(fd != -1);

  /* set name */
  memset(&ifr, 0, sizeof(ifr));
  ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
  strncpy(ifr.ifr_name, name, IFNAMSIZ);
  ASSERT(ioctl(fd, TUNSETIFF, &ifr) != -1);

  /* socket to connect kernel */
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  ASSERT(sockfd != -1);

  /* set addr */
  memset(&sai, 0, sizeof(sai));
  sai.sin_family = AF_INET;
  inet_pton(AF_INET, addr, &sai.sin_addr.s_addr);
  memcpy(&ifr.ifr_addr, &sai, sizeof(sai));
  ASSERT(ioctl(sockfd, SIOCSIFADDR, &ifr) != -1);

  /* set netmask */
  inet_pton(AF_INET, netmask, &sai.sin_addr);
  memcpy(&ifr.ifr_addr, &sai, sizeof(sai));
  ASSERT(ioctl(sockfd, SIOCSIFNETMASK, &ifr) != -1);

  /* ipv6 */
  if (addr6 && prefixlen) {
    /* socket to connect kernel */
    sock6fd = socket(AF_INET6, SOCK_DGRAM, 0);
    ASSERT(sock6fd != -1);

    /* address and prefixlen*/
    inet_pton(AF_INET6, addr6, &ifr6.ifr6_addr);
    ifr6.ifr6_prefixlen = prefixlen;
    ASSERT(-1 != (ioctl(sock6fd, SIOGIFINDEX, &ifr)));
    ifr6.ifr6_ifindex = ifr.ifr_ifindex;
    ASSERT(ioctl(sock6fd, SIOCSIFADDR, &ifr6) != -1);

    close(sock6fd);
  }

  /* set mtu */
  ifr.ifr_mtu = mtu;
  ASSERT(ioctl(sockfd, SIOCSIFMTU, &ifr) != -1);

  /* start device */
  ifr.ifr_flags |= IFF_UP;
  ASSERT(ioctl(sockfd, SIOCSIFFLAGS, &ifr) != -1);

  close(sockfd);
  return fd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2, %esi
movb $0x0, %al
callq 0x21e0
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x23f4
movq 0x2cc43(%rip), %rax     # 0x2eff8
movq (%rax), %rax
movq %rax, -0x98(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x2220
movq -0x98(%rbp), %rdi
movq %rax, %r8
leaq 0x24c28(%rip), %rsi     # 0x27004
leaq 0x24c44(%rip), %rdx     # 0x27027
movl $0x1a, %ecx
movb $0x0, %al
callq 0x2170
callq 0x2040
jmp 0x23f6
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x20f0
movw $0x1001, -0x68(%rbp)    # imm = 0x1001
leaq -0x78(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x10, %edx
callq 0x2060
movl -0x44(%rbp), %edi
movl $0x400454ca, %esi       # imm = 0x400454CA
leaq -0x78(%rbp), %rdx
movb $0x0, %al
callq 0x2100
cmpl $-0x1, %eax
jne 0x247c
movq 0x2cbbb(%rip), %rax     # 0x2eff8
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x2220
movq -0xa0(%rbp), %rdi
movq %rax, %r8
leaq 0x24ba0(%rip), %rsi     # 0x27004
leaq 0x24bbc(%rip), %rdx     # 0x27027
movl $0x20, %ecx
movb $0x0, %al
callq 0x2170
callq 0x2040
jmp 0x247e
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x2260
movl %eax, -0x48(%rbp)
cmpl $-0x1, -0x48(%rbp)
jne 0x24db
movq 0x2cb5c(%rip), %rax     # 0x2eff8
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x2220
movq -0xa8(%rbp), %rdi
movq %rax, %r8
leaq 0x24b41(%rip), %rsi     # 0x27004
leaq 0x24b5d(%rip), %rdx     # 0x27027
movl $0x24, %ecx
movb $0x0, %al
callq 0x2170
callq 0x2040
jmp 0x24dd
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x20f0
movw $0x2, -0x40(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x40(%rbp), %rdx
addq $0x4, %rdx
movl $0x2, %edi
callq 0x2190
movq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x48(%rbp), %edi
movl $0x8916, %esi           # imm = 0x8916
leaq -0x78(%rbp), %rdx
movb $0x0, %al
callq 0x2100
cmpl $-0x1, %eax
jne 0x2577
movq 0x2cac0(%rip), %rax     # 0x2eff8
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x2220
movq -0xb0(%rbp), %rdi
movq %rax, %r8
leaq 0x24aa5(%rip), %rsi     # 0x27004
leaq 0x24ac1(%rip), %rdx     # 0x27027
movl $0x2b, %ecx
movb $0x0, %al
callq 0x2170
callq 0x2040
jmp 0x2579
movq -0x28(%rbp), %rsi
leaq -0x40(%rbp), %rdx
addq $0x4, %rdx
movl $0x2, %edi
callq 0x2190
movq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x48(%rbp), %edi
movl $0x891c, %esi           # imm = 0x891C
leaq -0x78(%rbp), %rdx
movb $0x0, %al
callq 0x2100
cmpl $-0x1, %eax
jne 0x25fd
movq 0x2ca3a(%rip), %rax     # 0x2eff8
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x2220
movq -0xb8(%rbp), %rdi
movq %rax, %r8
leaq 0x24a1f(%rip), %rsi     # 0x27004
leaq 0x24a3b(%rip), %rdx     # 0x27027
movl $0x30, %ecx
movb $0x0, %al
callq 0x2170
callq 0x2040
jmp 0x25ff
cmpq $0x0, -0x30(%rbp)
je 0x2768
cmpl $0x0, 0x10(%rbp)
je 0x2768
movl $0xa, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x2260
movl %eax, -0x4c(%rbp)
cmpl $-0x1, -0x4c(%rbp)
jne 0x2674
movq 0x2c9c3(%rip), %rax     # 0x2eff8
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x2220
movq -0xc0(%rbp), %rdi
movq %rax, %r8
leaq 0x249a8(%rip), %rsi     # 0x27004
leaq 0x249c4(%rip), %rdx     # 0x27027
movl $0x36, %ecx
movb $0x0, %al
callq 0x2170
callq 0x2040
jmp 0x2676
movq -0x30(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movl $0xa, %edi
callq 0x2190
movl 0x10(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x4c(%rbp), %edi
movl $0x8933, %esi           # imm = 0x8933
leaq -0x78(%rbp), %rdx
movb $0x0, %al
callq 0x2100
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x26f5
movq 0x2c942(%rip), %rax     # 0x2eff8
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x2220
movq -0xc8(%rbp), %rdi
movq %rax, %r8
leaq 0x24927(%rip), %rsi     # 0x27004
leaq 0x24943(%rip), %rdx     # 0x27027
movl $0x3b, %ecx
movb $0x0, %al
callq 0x2170
callq 0x2040
jmp 0x26f7
movl -0x68(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x4c(%rbp), %edi
movl $0x8916, %esi           # imm = 0x8916
leaq -0x90(%rbp), %rdx
movb $0x0, %al
callq 0x2100
cmpl $-0x1, %eax
jne 0x275e
movq 0x2c8d9(%rip), %rax     # 0x2eff8
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x2220
movq -0xd0(%rbp), %rdi
movq %rax, %r8
leaq 0x248be(%rip), %rsi     # 0x27004
leaq 0x248da(%rip), %rdx     # 0x27027
movl $0x3d, %ecx
movb $0x0, %al
callq 0x2170
callq 0x2040
jmp 0x2760
movl -0x4c(%rbp), %edi
callq 0x2120
movl -0x14(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x48(%rbp), %edi
movl $0x8922, %esi           # imm = 0x8922
leaq -0x78(%rbp), %rdx
movb $0x0, %al
callq 0x2100
cmpl $-0x1, %eax
jne 0x27cc
movq 0x2c86b(%rip), %rax     # 0x2eff8
movq (%rax), %rax
movq %rax, -0xd8(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x2220
movq -0xd8(%rbp), %rdi
movq %rax, %r8
leaq 0x24850(%rip), %rsi     # 0x27004
leaq 0x2486c(%rip), %rdx     # 0x27027
movl $0x44, %ecx
movb $0x0, %al
callq 0x2170
callq 0x2040
jmp 0x27ce
movswl -0x68(%rbp), %eax
orl $0x1, %eax
movw %ax, -0x68(%rbp)
movl -0x48(%rbp), %edi
movl $0x8914, %esi           # imm = 0x8914
leaq -0x78(%rbp), %rdx
movb $0x0, %al
callq 0x2100
cmpl $-0x1, %eax
jne 0x2837
movq 0x2c800(%rip), %rax     # 0x2eff8
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x2220
movq -0xe0(%rbp), %rdi
movq %rax, %r8
leaq 0x247e5(%rip), %rsi     # 0x27004
leaq 0x24801(%rip), %rdx     # 0x27027
movl $0x48, %ecx
movb $0x0, %al
callq 0x2170
callq 0x2040
jmp 0x2839
movl -0x48(%rbp), %edi
callq 0x2120
movl -0x44(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax)