#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ sa_data;
};
struct ifreq {
  int ifr_ifindex;
  int /*<<< orphan*/ ifr_flags;
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ AF_PACKET;
int /*<<< orphan*/ ETH_P_ALL;
int /*<<< orphan*/ IFF_PROMISC;
int /*<<< orphan*/ IFF_UP;
int IFNAMSIZ;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SIOCGIFINDEX;
int /*<<< orphan*/ SIOCSIFFLAGS;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BINDTODEVICE;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ bzero(struct ifreq *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int init_ethernet_device(char *name, unsigned char *mac, int *idx) {
  int fd, ret, sockopt;
  struct ifreq if_idx;
  if (name == NULL) {
    return -1;
  }
  fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  if (fd < 0) {
    perror("Couldn't open socket");
    return -1;
  }
  memset(&if_idx, 0, sizeof(struct ifreq));
  strncpy(if_idx.ifr_name, name, IFNAMSIZ - 1);
  if_idx.ifr_flags |= IFF_PROMISC;
  if (ioctl(fd, SIOCGIFINDEX, &if_idx) < 0)
    perror("SIOCGIFINDEX");
  *idx = if_idx.ifr_ifindex;
  bzero(&if_idx, sizeof(struct ifreq));
  strncpy(if_idx.ifr_name, name, IFNAMSIZ - 1);
  if (ioctl(fd, SIOCGIFHWADDR, &if_idx) < 0)
    perror("SIOCGIFHWADDR");
  memcpy(mac, if_idx.ifr_hwaddr.sa_data, 6);
  if (ioctl(fd, SIOCGIFFLAGS, &if_idx) < 0)
    perror("SIOCGIFFLAGS");
  if_idx.ifr_flags |= IFF_UP;
  if (ioctl(fd, SIOCSIFFLAGS, &if_idx) < 0)
    perror("SIOCSIFFLAGS");
  if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof sockopt) ==
      -1) {
    perror("setsockopt");
    close(fd);
    return -1;
  }
  if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, name, IFNAMSIZ - 1) == -1) {
    perror("SO_BINDTODEVICE");
    close(fd);
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<init_ethernet_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cb <init_ethernet_device+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1401 <init_ethernet_device+0x261>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1050 <htons@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%esi
mov    %eax,%edx
call   10c0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1223 <init_ethernet_device+0x83>
lea    0xdee(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1401 <init_ethernet_device+0x261>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    -0x34(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2d5f(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    1285 <init_ethernet_device+0xe5>
lea    0xd95(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x40(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x40(%rbp),%rdi
mov    $0x10,%esi
call   10b0 <bzero@plt>
mov    -0x34(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2cf6(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x24(%rbp),%edi
mov    0x2cea(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    12df <init_ethernet_device+0x13f>
lea    0xd48(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    $0x6,%edx
call   1090 <memcpy@plt>
mov    -0x24(%rbp),%edi
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    131b <init_ethernet_device+0x17b>
lea    0xd1a(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cae(%rip),%rax
mov    (%rax),%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2cc4(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    1355 <init_ethernet_device+0x1b5>
lea    0xced(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x24(%rbp),%edi
mov    0x2c81(%rip),%rax
mov    (%rax),%esi
mov    0x2c28(%rip),%rax
mov    (%rax),%edx
lea    -0x2c(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    13a4 <init_ethernet_device+0x204>
lea    0xcbf(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1401 <init_ethernet_device+0x261>
mov    -0x24(%rbp),%edi
mov    0x2c32(%rip),%rax
mov    (%rax),%esi
mov    0x2bd1(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    0x2bdc(%rip),%rax
mov    (%rax),%r8d
sub    $0x1,%r8d
mov    $0x0,%al
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    13fb <init_ethernet_device+0x25b>
lea    0xc73(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1401 <init_ethernet_device+0x261>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_ethernet_device>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     133d <init_ethernet_device+0x19d>
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r13
mov    0x2de4(%rip),%rax
mov    (%rax),%ebp
mov    0x2e03(%rip),%rax
mov    (%rax),%ebx
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1050 <htons@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     134c <init_ethernet_device+0x1ac>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0xc(%rsp),%edi
mov    0x2d89(%rip),%r14
mov    (%r14),%edx
add    $0xffffffff,%edx
mov    %r13,%rsi
call   1030 <strncpy@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
or     %eax,0x4(%rsp)
mov    0x2d3f(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1070 <ioctl@plt>
test   %rax,%rax
js     135a <init_ethernet_device+0x1ba>
mov    (%rsp),%eax
mov    %eax,(%r12)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x10,%esi
call   10b0 <bzero@plt>
mov    0xc(%rsp),%edi
mov    (%r14),%edx
add    $0xffffffff,%edx
mov    %r13,%rsi
call   1030 <strncpy@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1070 <ioctl@plt>
test   %rax,%rax
js     136b <init_ethernet_device+0x1cb>
mov    0x8(%rsp),%esi
mov    %r15,%rdi
mov    $0x6,%edx
call   1090 <memcpy@plt>
mov    0x2d1d(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1070 <ioctl@plt>
test   %rax,%rax
js     137c <init_ethernet_device+0x1dc>
mov    0x2d09(%rip),%rax
mov    (%rax),%eax
or     %eax,0x4(%rsp)
mov    0x2d24(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1070 <ioctl@plt>
test   %rax,%rax
js     138d <init_ethernet_device+0x1ed>
mov    0x2cf0(%rip),%rbx
mov    (%rbx),%esi
mov    0x2c97(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%rcx
mov    $0x4,%r8d
mov    %ebp,%edi
xor    %eax,%eax
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     139e <init_ethernet_device+0x1fe>
mov    (%rbx),%esi
mov    0x2c67(%rip),%rax
mov    (%rax),%edx
mov    (%r14),%r8d
add    $0xffffffff,%r8d
mov    %ebp,%edi
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     13a7 <init_ethernet_device+0x207>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcad(%rip),%rdi
call   10a0 <perror@plt>
jmp    13ba <init_ethernet_device+0x21a>
lea    0xcb4(%rip),%rdi
call   10a0 <perror@plt>
jmp    124e <init_ethernet_device+0xae>
lea    0xcb0(%rip),%rdi
call   10a0 <perror@plt>
jmp    1293 <init_ethernet_device+0xf3>
lea    0xcad(%rip),%rdi
call   10a0 <perror@plt>
jmp    12c0 <init_ethernet_device+0x120>
lea    0xca9(%rip),%rdi
call   10a0 <perror@plt>
jmp    12e9 <init_ethernet_device+0x149>
lea    0xca5(%rip),%rdi
jmp    13ae <init_ethernet_device+0x20e>
lea    0xca7(%rip),%rdi
call   10a0 <perror@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0xffffffff,%eax
jmp    133d <init_ethernet_device+0x19d>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_ALL = global i32 0
@.str = [21 x i8] c"Couldn't open socket\00"
@IFNAMSIZ = global i32 0
@IFF_PROMISC = global i32 0
@SIOCGIFINDEX = global i32 0
@.str.1 = [13 x i8] c"SIOCGIFINDEX\00"
@SIOCGIFHWADDR = global i32 0
@.str.2 = [14 x i8] c"SIOCGIFHWADDR\00"
@SIOCGIFFLAGS = global i32 0
@.str.3 = [13 x i8] c"SIOCGIFFLAGS\00"
@IFF_UP = global i32 0
@SIOCSIFFLAGS = global i32 0
@.str.4 = [13 x i8] c"SIOCSIFFLAGS\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [11 x i8] c"setsockopt\00"
@SO_BINDTODEVICE = global i32 0
@.str.6 = [16 x i8] c"SO_BINDTODEVICE\00"
define i32 @init_ethernet_device(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.ifreq
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %108
15: ; preds = %3
%16 = load i32, i32* @AF_PACKET
%17 = load i32, i32* @SOCK_RAW
%18 = load i32, i32* @ETH_P_ALL
%19 = call i32 @htons(i32 %18)
%20 = call i32 @socket(i32 %16, i32 %17, i32 %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %108
25: ; preds = %15
%26 = call i32 @memset(%struct.ifreq* %11, i32 0, i32 16)
%27 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 3
%28 = load i32, i32* %27
%29 = load i8*, i8** %5
%30 = load i32, i32* @IFNAMSIZ
%31 = sub nsw i32 %30, 1
%32 = call i32 @strncpy(i32 %28, i8* %29, i32 %31)
%33 = load i32, i32* @IFF_PROMISC
%34 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 1
%35 = load i32, i32* %34
%36 = or i32 %35, %33
store i32 %36, i32* %34
%37 = load i32, i32* %8
%38 = load i32, i32* @SIOCGIFINDEX
%39 = call i64 @ioctl(i32 %37, i32 %38, %struct.ifreq* %11)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %25
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %25
%44 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 0
%45 = load i32, i32* %44
%46 = load i32*, i32** %7
store i32 %45, i32* %46
%47 = call i32 @bzero(%struct.ifreq* %11, i32 16)
%48 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 3
%49 = load i32, i32* %48
%50 = load i8*, i8** %5
%51 = load i32, i32* @IFNAMSIZ
%52 = sub nsw i32 %51, 1
%53 = call i32 @strncpy(i32 %49, i8* %50, i32 %52)
%54 = load i32, i32* %8
%55 = load i32, i32* @SIOCGIFHWADDR
%56 = call i64 @ioctl(i32 %54, i32 %55, %struct.ifreq* %11)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %43
%59 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %58, %43
%61 = load i8*, i8** %6
%62 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 2
%63 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %62, i32 0, i32 0
%64 = load i32, i32* %63
%65 = call i32 @memcpy(i8* %61, i32 %64, i32 6)
%66 = load i32, i32* %8
%67 = load i32, i32* @SIOCGIFFLAGS
%68 = call i64 @ioctl(i32 %66, i32 %67, %struct.ifreq* %11)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %60
%71 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %72
72: ; preds = %70, %60
%73 = load i32, i32* @IFF_UP
%74 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 1
%75 = load i32, i32* %74
%76 = or i32 %75, %73
store i32 %76, i32* %74
%77 = load i32, i32* %8
%78 = load i32, i32* @SIOCSIFFLAGS
%79 = call i64 @ioctl(i32 %77, i32 %78, %struct.ifreq* %11)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %72
%82 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %83
83: ; preds = %81, %72
%84 = load i32, i32* %8
%85 = load i32, i32* @SOL_SOCKET
%86 = load i32, i32* @SO_REUSEADDR
%87 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %84, i32 %85, i32 %86, i32* %10, i64 4)
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %93
89: ; preds = %83
%90 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%91 = load i32, i32* %8
%92 = call i32 @close(i32 %91)
store i32 -1, i32* %4
br label %108
93: ; preds = %83
%94 = load i32, i32* %8
%95 = load i32, i32* @SOL_SOCKET
%96 = load i32, i32* @SO_BINDTODEVICE
%97 = load i8*, i8** %5
%98 = load i32, i32* @IFNAMSIZ
%99 = sub nsw i32 %98, 1
%100 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %94, i32 %95, i32 %96, i8* %97, i32 %99)
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %106
102: ; preds = %93
%103 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%104 = load i32, i32* %8
%105 = call i32 @close(i32 %104)
store i32 -1, i32* %4
br label %108
106: ; preds = %93
%107 = load i32, i32* %8
store i32 %107, i32* %4
br label %108
108: ; preds = %106, %102, %89, %23, %14
%109 = load i32, i32* %4
ret i32 %109
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_ALL = global i32 0
@.str = [21 x i8] c"Couldn't open socket\00"
@IFNAMSIZ = global i32 0
@IFF_PROMISC = global i32 0
@SIOCGIFINDEX = global i32 0
@.str.1 = [13 x i8] c"SIOCGIFINDEX\00"
@SIOCGIFHWADDR = global i32 0
@.str.2 = [14 x i8] c"SIOCGIFHWADDR\00"
@SIOCGIFFLAGS = global i32 0
@.str.3 = [13 x i8] c"SIOCGIFFLAGS\00"
@IFF_UP = global i32 0
@SIOCSIFFLAGS = global i32 0
@.str.4 = [13 x i8] c"SIOCSIFFLAGS\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [11 x i8] c"setsockopt\00"
@SO_BINDTODEVICE = global i32 0
@.str.6 = [16 x i8] c"SO_BINDTODEVICE\00"
define i32 @init_ethernet_device(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca %struct.ifreq
%6 = bitcast i32* %4 to i8*
%7 = bitcast %struct.ifreq* %5 to i8*
%8 = icmp eq i8* %0, null
br i1 %8, label %83, label %9
9: ; preds = %3
%10 = load i32, i32* @AF_PACKET
%11 = load i32, i32* @SOCK_RAW
%12 = load i32, i32* @ETH_P_ALL
%13 = tail call i32 @htons(i32 %12)
%14 = tail call i32 @socket(i32 %10, i32 %11, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %83
18: ; preds = %9
%19 = call i32 @memset(%struct.ifreq* %5, i32 0, i32 16)
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 3
%21 = load i32, i32* %20
%22 = load i32, i32* @IFNAMSIZ
%23 = add nsw i32 %22, -1
%24 = call i32 @strncpy(i32 %21, i8* %0, i32 %23)
%25 = load i32, i32* @IFF_PROMISC
%26 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 1
%27 = load i32, i32* %26
%28 = or i32 %27, %25
store i32 %28, i32* %26
%29 = load i32, i32* @SIOCGIFINDEX
%30 = call i64 @ioctl(i32 %14, i32 %29, %struct.ifreq* %5)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %18
%33 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %18
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 0
%36 = load i32, i32* %35
store i32 %36, i32* %2
%37 = call i32 @bzero(%struct.ifreq* %5, i32 16)
%38 = load i32, i32* %20
%39 = load i32, i32* @IFNAMSIZ
%40 = add nsw i32 %39, -1
%41 = call i32 @strncpy(i32 %38, i8* %0, i32 %40)
%42 = load i32, i32* @SIOCGIFHWADDR
%43 = call i64 @ioctl(i32 %14, i32 %42, %struct.ifreq* %5)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %34
%46 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %34
%48 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 2, i32 0
%49 = load i32, i32* %48
%50 = call i32 @memcpy(i8* %1, i32 %49, i32 6)
%51 = load i32, i32* @SIOCGIFFLAGS
%52 = call i64 @ioctl(i32 %14, i32 %51, %struct.ifreq* %5)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %47
%55 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %54, %47
%57 = load i32, i32* @IFF_UP
%58 = load i32, i32* %26
%59 = or i32 %58, %57
store i32 %59, i32* %26
%60 = load i32, i32* @SIOCSIFFLAGS
%61 = call i64 @ioctl(i32 %14, i32 %60, %struct.ifreq* %5)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %56
%64 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %65
65: ; preds = %63, %56
%66 = load i32, i32* @SOL_SOCKET
%67 = load i32, i32* @SO_REUSEADDR
%68 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %14, i32 %66, i32 %67, i32* %4, i64 4)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %73
70: ; preds = %65
%71 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%72 = call i32 @close(i32 %14)
br label %83
73: ; preds = %65
%74 = load i32, i32* @SOL_SOCKET
%75 = load i32, i32* @SO_BINDTODEVICE
%76 = load i32, i32* @IFNAMSIZ
%77 = add nsw i32 %76, -1
%78 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %14, i32 %74, i32 %75, i8* %0, i32 %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %83
80: ; preds = %73
%81 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%82 = call i32 @close(i32 %14)
br label %83
83: ; preds = %73, %3, %80, %70, %16
%84 = phi i32 [ -1, %16 ], [ -1, %70 ], [ -1, %80 ], [ -1, %3 ], [ %14, %73 ]
ret i32 %84
}