#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_family;
  int /*<<< orphan*/ sa_data;
};
struct ifreq {
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ SIOCADDMULTI;
int /*<<< orphan*/ SIOCDELMULTI;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int errno;
int ioctl(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, char *, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int rcvhwaddr_op(char *ifname, char *addr, int addrlen, int addF) {
  struct ifreq ifr;
  int fd = socket(AF_INET, SOCK_DGRAM, 0);
  int ret;
  if (fd < 0)
    return (-1);
  strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
  memcpy(ifr.ifr_hwaddr.sa_data, addr, addrlen);
  ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
  ret = ioctl(fd, addF ? SIOCADDMULTI : SIOCDELMULTI, (char *)&ifr);
  if (ret) {
    printf("Can't %s on %s. errno=%d\n", addF ? "SIOCADDMULTI" : "SIOCDELMULTI",
           ifname, errno);
  }
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<rcvhwaddr_op>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11a8 <rcvhwaddr_op+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    125c <rcvhwaddr_op+0xfc>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <memcpy@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11f5 <rcvhwaddr_op+0x95>
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    1201 <rcvhwaddr_op+0xa1>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x40(%rbp),%esi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     124e <rcvhwaddr_op+0xee>
mov    -0x20(%rbp),%ecx
lea    0xe00(%rip),%rsi
lea    0xdec(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x10(%rbp),%rdx
mov    0x2d80(%rip),%rax
mov    (%rax),%ecx
lea    0xdb7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rcvhwaddr_op>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11c9 <rcvhwaddr_op+0x69>
mov    %eax,%ebp
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rsi
mov    %r12d,%edx
call   1070 <memcpy@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
test   %r15d,%r15d
jne    11d0 <rcvhwaddr_op+0x70>
mov    0x2e19(%rip),%rax
jmp    11d7 <rcvhwaddr_op+0x77>
mov    $0xffffffff,%ebx
jmp    121d <rcvhwaddr_op+0xbd>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1216 <rcvhwaddr_op+0xb6>
test   %r15d,%r15d
lea    0xe34(%rip),%rax
lea    0xe20(%rip),%rsi
cmove  %rax,%rsi
mov    0x2dbb(%rip),%rax
mov    (%rax),%ecx
lea    0xdf2(%rip),%rdi
mov    %r14,%rdx
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_UNSPEC = global i32 0
@SIOCADDMULTI = global i32 0
@SIOCDELMULTI = global i32 0
@.str = [26 x i8] c"Can't %s on %s. errno=%d\0A\00"
@.str.1 = [13 x i8] c"SIOCADDMULTI\00"
@.str.2 = [13 x i8] c"SIOCDELMULTI\00"
@errno = global i32 0
define i32 @rcvhwaddr_op(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.ifreq
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 -1, i32* %5
br label %58
19: ; preds = %4
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load i8*, i8** %6
%23 = call i32 @strncpy(i32 %21, i8* %22, i32 4)
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = load i8*, i8** %7
%28 = load i32, i32* %8
%29 = call i32 @memcpy(i32 %26, i8* %27, i32 %28)
%30 = load i32, i32* @AF_UNSPEC
%31 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = load i32, i32* %11
%34 = load i32, i32* %9
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %19
%37 = load i32, i32* @SIOCADDMULTI
br label %40
38: ; preds = %19
%39 = load i32, i32* @SIOCDELMULTI
br label %40
40: ; preds = %38, %36
%41 = phi i32 [ %37, %36 ], [ %39, %38 ]
%42 = bitcast %struct.ifreq* %10 to i8*
%43 = call i32 @ioctl(i32 %33, i32 %41, i8* %42)
store i32 %43, i32* %12
%44 = load i32, i32* %12
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %40
%47 = load i32, i32* %9
%48 = icmp ne i32 %47, 0
%49 = zext i1 %48 to i64
%50 = select i1 %48, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0)
%51 = load i8*, i8** %6
%52 = load i32, i32* @errno
%53 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %50, i8* %51, i32 %52)
br label %54
54: ; preds = %46, %40
%55 = load i32, i32* %11
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* %12
store i32 %57, i32* %5
br label %58
58: ; preds = %54, %18
%59 = load i32, i32* %5
ret i32 %59
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_UNSPEC = global i32 0
@SIOCADDMULTI = global i32 0
@SIOCDELMULTI = global i32 0
@.str = [26 x i8] c"Can't %s on %s. errno=%d\0A\00"
@.str.1 = [13 x i8] c"SIOCADDMULTI\00"
@.str.2 = [13 x i8] c"SIOCDELMULTI\00"
@errno = global i32 0
define i32 @rcvhwaddr_op(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca %struct.ifreq
%6 = bitcast %struct.ifreq* %5 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %4
%12 = tail call i32 @strncpy(i32 undef, i8* %0, i32 4)
%13 = tail call i32 @memcpy(i32 undef, i8* %1, i32 %2)
%14 = load i32, i32* @AF_UNSPEC
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 0, i32 0
store i32 %14, i32* %15
%16 = icmp eq i32 %3, 0
%17 = load i32, i32* @SIOCADDMULTI
%18 = load i32, i32* @SIOCDELMULTI
%19 = select i1 %16, i32 %18, i32 %17
%20 = call i32 @ioctl(i32 %9, i32 %19, i8* %6)
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %11
%23 = select i1 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0)
%24 = load i32, i32* @errno
%25 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %0, i32 %24)
br label %26
26: ; preds = %22, %11
%27 = call i32 @close(i32 %9)
br label %28
28: ; preds = %4, %26
%29 = phi i32 [ %20, %26 ], [ -1, %4 ]
ret i32 %29
}