#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 {
  TYPE_1__ ifr_hwaddr;
};

/* Variables and functions */
int /*<<< orphan*/ SIOCGIFHWADDR;
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memcpy(void *, int /*<<< orphan*/, int);
int __attribute__((unused)) hwaddr_get(int fd, void *dst) {
  struct ifreq ifr;
  if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1)
    return -1;
  memcpy(dst, ifr.ifr_hwaddr.sa_data, 6);
  return 0;
}


x86 assembly (clang, -O0):
<hwaddr_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1159 <hwaddr_get+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1171 <hwaddr_get+0x51>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x6,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hwaddr_get>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1155 <hwaddr_get+0x35>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
mov    $0x6,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
jmp    115a <hwaddr_get+0x3a>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@SIOCGIFHWADDR = global i32 0
define i32 @hwaddr_get(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.ifreq
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i32, i32* %4
%8 = load i32, i32* @SIOCGIFHWADDR
%9 = call i32 @ioctl(i32 %7, i32 %8, %struct.ifreq* %6)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %18
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @memcpy(i8* %13, i32 %16, i32 6)
store i32 0, i32* %3
br label %18
18: ; preds = %12, %11
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@SIOCGIFHWADDR = global i32 0
define i32 @hwaddr_get(i32 %0, i8* %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @SIOCGIFHWADDR
%6 = call i32 @ioctl(i32 %0, i32 %5, %struct.ifreq* %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 @memcpy(i8* %1, i32 %10, i32 6)
br label %12
12: ; preds = %2, %8
%13 = phi i32 [ 0, %8 ], [ -1, %2 ]
ret i32 %13
}