#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 sockaddr_ll {
  int /*<<< orphan*/ sll_addr;
  int /*<<< orphan*/ sll_halen;
  int /*<<< orphan*/ sll_pkttype;
  int /*<<< orphan*/ sll_hatype;
  int /*<<< orphan*/ sll_ifindex;
  int /*<<< orphan*/ sll_protocol;
  int /*<<< orphan*/ sll_family;
};
struct TYPE_2__ {
  int /*<<< orphan*/ sa_data;
};
struct ifreq {
  char *ifc_buf;
  int ifc_len;
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_ifindex;
};
struct ifconf {
  char *ifc_buf;
  int ifc_len;
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_ifindex;
};
typedef int /*<<< orphan*/ ifbuf;

/* Variables and functions */
int /*<<< orphan*/ ARPHRD_ETHER;
int /*<<< orphan*/ ETH_ALEN;
int /*<<< orphan*/ ETH_P_PAUSE;
int /*<<< orphan*/ PACKET_OTHERHOST;
int /*<<< orphan*/ PF_PACKET;
int /*<<< orphan*/ SIOCGIFCONF;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SIOCGIFINDEX;
int /*<<< orphan*/ exit(int);
struct ifreq *find_ifreq(int, struct ifreq *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int sockaddr_init(int s, struct sockaddr_ll *socket_address) {
  unsigned char ifbuf[1024];
  struct ifconf iflist;
  struct ifreq *ifreq;
  iflist.ifc_buf = (char *)&ifbuf;
  iflist.ifc_len = sizeof(ifbuf);
  if (ioctl(s, SIOCGIFCONF, &iflist) == -1) {
    perror("siocgifconf");
    return -1;
  }
  ifreq = find_ifreq(s, &iflist);
  if (ifreq == NULL) {
    return -1;
  }
  if (ioctl(s, SIOCGIFINDEX, ifreq) == -1) {
    perror("siocgifindex");
    return -1;
  }
  socket_address->sll_family = PF_PACKET;
  socket_address->sll_protocol = htons(ETH_P_PAUSE);
  socket_address->sll_ifindex = ifreq->ifr_ifindex;
  socket_address->sll_hatype = ARPHRD_ETHER;
  socket_address->sll_pkttype = PACKET_OTHERHOST;
  if (ioctl(s, SIOCGIFHWADDR, ifreq) == -1) {
    perror("siocgifhwaddr");
    exit(1);
  }
  socket_address->sll_halen = ETH_ALEN;
  memcpy(socket_address->sll_addr, ifreq->ifr_hwaddr.sa_data, ETH_ALEN);
  return 0;
}


x86 assembly (clang, -O0):
<sockaddr_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x428(%rbp)
movl   $0x400,-0x420(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
lea    -0x428(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11c3 <sockaddr_init+0x63>
lea    0xe4e(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f0 <sockaddr_init+0x190>
mov    -0x8(%rbp),%edi
lea    -0x428(%rbp),%rsi
call   1060 <find_ifreq@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
jne    11f3 <sockaddr_init+0x93>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f0 <sockaddr_init+0x190>
mov    -0x8(%rbp),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
mov    -0x430(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    122c <sockaddr_init+0xcc>
lea    0xdf1(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f0 <sockaddr_init+0x190>
mov    0x2db5(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x430(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    0x2d65(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    0x2d3d(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%edi
mov    0x2d32(%rip),%rax
mov    (%rax),%esi
mov    -0x430(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    12bb <sockaddr_init+0x15b>
lea    0xd6d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x430(%rbp),%rax
mov    0xc(%rax),%esi
mov    0x2cf6(%rip),%rax
mov    (%rax),%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockaddr_init>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x428,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0x20(%rsp),%rax
mov    %rax,0x8(%rsp)
movl   $0x400,0x10(%rsp)
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     125b <sockaddr_init+0xfb>
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
call   1060 <find_ifreq@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     124a <sockaddr_init+0xea>
mov    %rax,%rbp
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbp,%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     126f <sockaddr_init+0x10f>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rbx)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rbx)
mov    0x10(%rbp),%eax
mov    %eax,0x10(%rbx)
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rbx)
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbp,%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     127d <sockaddr_init+0x11d>
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
mov    %edx,0x4(%rbx)
mov    (%rbx),%edi
mov    0xc(%rbp),%esi
call   1050 <memcpy@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9e(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%r15d
jmp    124a <sockaddr_init+0xea>
lea    0xd96(%rip),%rdi
call   1070 <perror@plt>
jmp    124a <sockaddr_init+0xea>
lea    0xd95(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_ll = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.ifconf = type { i8*, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.ifreq = type { i8*, i32, %struct.TYPE_2__, i32 }
@SIOCGIFCONF = global i32 0
@.str = [12 x i8] c"siocgifconf\00"
@SIOCGIFINDEX = global i32 0
@.str.1 = [13 x i8] c"siocgifindex\00"
@PF_PACKET = global i32 0
@ETH_P_PAUSE = global i32 0
@ARPHRD_ETHER = global i32 0
@PACKET_OTHERHOST = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str.2 = [14 x i8] c"siocgifhwaddr\00"
@ETH_ALEN = global i32 0
define i32 @sockaddr_init(i32 %0, %struct.sockaddr_ll* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_ll*
%6 = alloca [1024 x i8]
%7 = alloca %struct.ifconf
%8 = alloca %struct.ifreq*
store i32 %0, i32* %4
store %struct.sockaddr_ll* %1, %struct.sockaddr_ll** %5
%9 = bitcast [1024 x i8]* %6 to i8*
%10 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %7, i32 0, i32 0
store i8* %9, i8** %10
%11 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %7, i32 0, i32 1
store i32 1024, i32* %11
%12 = load i32, i32* %4
%13 = load i32, i32* @SIOCGIFCONF
%14 = bitcast %struct.ifconf* %7 to %struct.ifreq*
%15 = call i32 @ioctl(i32 %12, i32 %13, %struct.ifreq* %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %74
19: ; preds = %2
%20 = load i32, i32* %4
%21 = bitcast %struct.ifconf* %7 to %struct.ifreq*
%22 = call %struct.ifreq* @find_ifreq(i32 %20, %struct.ifreq* %21)
store %struct.ifreq* %22, %struct.ifreq** %8
%23 = load %struct.ifreq*, %struct.ifreq** %8
%24 = icmp eq %struct.ifreq* %23, null
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 -1, i32* %3
br label %74
26: ; preds = %19
%27 = load i32, i32* %4
%28 = load i32, i32* @SIOCGIFINDEX
%29 = load %struct.ifreq*, %struct.ifreq** %8
%30 = call i32 @ioctl(i32 %27, i32 %28, %struct.ifreq* %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %74
34: ; preds = %26
%35 = load i32, i32* @PF_PACKET
%36 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%37 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %36, i32 0, i32 6
store i32 %35, i32* %37
%38 = load i32, i32* @ETH_P_PAUSE
%39 = call i32 @htons(i32 %38)
%40 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%41 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %40, i32 0, i32 5
store i32 %39, i32* %41
%42 = load %struct.ifreq*, %struct.ifreq** %8
%43 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %42, i32 0, i32 3
%44 = load i32, i32* %43
%45 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%46 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %45, i32 0, i32 4
store i32 %44, i32* %46
%47 = load i32, i32* @ARPHRD_ETHER
%48 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%49 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %48, i32 0, i32 3
store i32 %47, i32* %49
%50 = load i32, i32* @PACKET_OTHERHOST
%51 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%52 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %51, i32 0, i32 2
store i32 %50, i32* %52
%53 = load i32, i32* %4
%54 = load i32, i32* @SIOCGIFHWADDR
%55 = load %struct.ifreq*, %struct.ifreq** %8
%56 = call i32 @ioctl(i32 %53, i32 %54, %struct.ifreq* %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %34
%59 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %34
%62 = load i32, i32* @ETH_ALEN
%63 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%64 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %63, i32 0, i32 1
store i32 %62, i32* %64
%65 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%66 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = load %struct.ifreq*, %struct.ifreq** %8
%69 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %68, i32 0, i32 2
%70 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = load i32, i32* @ETH_ALEN
%73 = call i32 @memcpy(i32 %67, i32 %71, i32 %72)
store i32 0, i32* %3
br label %74
74: ; preds = %61, %32, %25, %17
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
%struct.sockaddr_ll = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.ifconf = type { i8*, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.ifreq = type { i8*, i32, %struct.TYPE_2__, i32 }
@SIOCGIFCONF = global i32 0
@.str = [12 x i8] c"siocgifconf\00"
@SIOCGIFINDEX = global i32 0
@.str.1 = [13 x i8] c"siocgifindex\00"
@PF_PACKET = global i32 0
@ETH_P_PAUSE = global i32 0
@ARPHRD_ETHER = global i32 0
@PACKET_OTHERHOST = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str.2 = [14 x i8] c"siocgifhwaddr\00"
@ETH_ALEN = global i32 0
define i32 @sockaddr_init(i32 %0, %struct.sockaddr_ll* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.ifconf
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.ifconf* %4 to i8*
%7 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i64 0, i32 0
store i8* %5, i8** %7
%8 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i64 0, i32 1
store i32 1024, i32* %8
%9 = load i32, i32* @SIOCGIFCONF
%10 = bitcast %struct.ifconf* %4 to %struct.ifreq*
%11 = call i32 @ioctl(i32 %0, i32 %9, %struct.ifreq* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %51
15: ; preds = %2
%16 = call %struct.ifreq* @find_ifreq(i32 %0, %struct.ifreq* %10)
%17 = icmp eq %struct.ifreq* %16, null
br i1 %17, label %51, label %18
18: ; preds = %15
%19 = load i32, i32* @SIOCGIFINDEX
%20 = call i32 @ioctl(i32 %0, i32 %19, %struct.ifreq* %16)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %51
24: ; preds = %18
%25 = load i32, i32* @PF_PACKET
%26 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %1, i64 0, i32 6
store i32 %25, i32* %26
%27 = load i32, i32* @ETH_P_PAUSE
%28 = call i32 @htons(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %1, i64 0, i32 5
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %16, i64 0, i32 3
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %1, i64 0, i32 4
store i32 %31, i32* %32
%33 = load i32, i32* @ARPHRD_ETHER
%34 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %1, i64 0, i32 3
store i32 %33, i32* %34
%35 = load i32, i32* @PACKET_OTHERHOST
%36 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %1, i64 0, i32 2
store i32 %35, i32* %36
%37 = load i32, i32* @SIOCGIFHWADDR
%38 = call i32 @ioctl(i32 %0, i32 %37, %struct.ifreq* %16)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %24
%41 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %24
%44 = load i32, i32* @ETH_ALEN
%45 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %1, i64 0, i32 1
store i32 %44, i32* %45
%46 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %1, i64 0, i32 0
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %16, i64 0, i32 2, i32 0
%49 = load i32, i32* %48
%50 = call i32 @memcpy(i32 %47, i32 %49, i32 %44)
br label %51
51: ; preds = %15, %43, %22, %13
%52 = phi i32 [ -1, %13 ], [ -1, %22 ], [ 0, %43 ], [ -1, %15 ]
ret i32 %52
}