#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  scalar_t__ sa_data;
};
struct TYPE_3__ {
  int /*<<< orphan*/ sa_family;
};
struct ifreq {
  TYPE_2__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
  TYPE_1__ ifr_addr;
};
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ IFNAMSIZ;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char, unsigned char,
                          unsigned char, unsigned char, unsigned char);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, scalar_t__);
int main() {
  int fd;
  struct ifreq ifr;
  char *iface = "enp0s3";
  unsigned char *mac = NULL;
  memset(&ifr, 0, sizeof(ifr));
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  ifr.ifr_addr.sa_family = AF_INET;
  strncpy(ifr.ifr_name, iface, IFNAMSIZ - 1);
  if (0 == ioctl(fd, SIOCGIFHWADDR, &ifr)) {
    mac = (unsigned char *)ifr.ifr_hwaddr.sa_data;
    printf("Mac : %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", mac[0], mac[1], mac[2],
           mac[3], mac[4], mac[5]);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    0x2e00(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%edi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    124d <main+0xed>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%sil
mov    -0x28(%rbp),%rax
mov    0x1(%rax),%dl
mov    -0x28(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x28(%rbp),%rax
mov    0x3(%rax),%r8b
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%r9b
mov    -0x28(%rbp),%rax
lea    0xdd8(%rip),%rdi
movzbl %sil,%esi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl 0x5(%rax),%eax
mov    %eax,(%rsp)
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2e65(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x1c(%rsp)
mov    0x18(%rsp),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%rdx
add    $0xffffffffffffffff,%rdx
lea    0xe4a(%rip),%rsi
call   1030 <strncpy@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
jne    1200 <main+0xa0>
mov    0x10(%rsp),%rax
movzbl (%rax),%esi
movzbl 0x1(%rax),%edx
movzbl 0x2(%rax),%ecx
movzbl 0x3(%rax),%r8d
movzbl 0x4(%rax),%r9d
movzbl 0x5(%rax),%eax
mov    %eax,(%rsp)
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_4__, i32, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64 }
%struct.TYPE_3__ = type { i32 }
@.str = [7 x i8] c"enp0s3\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IFNAMSIZ = global i64 0
@SIOCGIFHWADDR = global i32 0
@.str.1 = [37 x i8] c"Mac : %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.ifreq
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* null, i8** %5
%6 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 16)
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %2
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 2
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 1
%14 = load i32, i32* %13
%15 = load i8*, i8** %4
%16 = load i64, i64* @IFNAMSIZ
%17 = sub nsw i64 %16, 1
%18 = call i32 @strncpy(i32 %14, i8* %15, i64 %17)
%19 = load i32, i32* %2
%20 = load i32, i32* @SIOCGIFHWADDR
%21 = call i64 @ioctl(i32 %19, i32 %20, %struct.ifreq* %3)
%22 = icmp eq i64 0, %21
br i1 %22, label %23, label %47
23: ; preds = %0
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %5
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = load i8, i8* %35
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 3
%39 = load i8, i8* %38
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i64 4
%42 = load i8, i8* %41
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 5
%45 = load i8, i8* %44
%46 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %30, i8 zeroext %33, i8 zeroext %36, i8 zeroext %39, i8 zeroext %42, i8 zeroext %45)
br label %47
47: ; preds = %23, %0
%48 = load i32, i32* %2
%49 = call i32 @close(i32 %48)
ret i32 0
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_4__, i32, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64 }
%struct.TYPE_3__ = type { i32 }
@.str = [7 x i8] c"enp0s3\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IFNAMSIZ = global i64 0
@SIOCGIFHWADDR = global i32 0
@.str.1 = [37 x i8] c"Mac : %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\0A\00"
define i32 @main() {
%1 = alloca %struct.ifreq
%2 = bitcast %struct.ifreq* %1 to i8*
%3 = call i32 @memset(%struct.ifreq* %1, i32 0, i32 16)
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 2, i32 0
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 1
%10 = load i32, i32* %9
%11 = load i64, i64* @IFNAMSIZ
%12 = add nsw i64 %11, -1
%13 = call i32 @strncpy(i32 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %12)
%14 = load i32, i32* @SIOCGIFHWADDR
%15 = call i64 @ioctl(i32 %6, i32 %14, %struct.ifreq* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %0
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 0, i32 0
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to i8*
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8, i8* %20, i64 1
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %20, i64 2
%25 = load i8, i8* %24
%26 = getelementptr inbounds i8, i8* %20, i64 3
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %20, i64 4
%29 = load i8, i8* %28
%30 = getelementptr inbounds i8, i8* %20, i64 5
%31 = load i8, i8* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %21, i8 zeroext %23, i8 zeroext %25, i8 zeroext %27, i8 zeroext %29, i8 zeroext %31)
br label %33
33: ; preds = %17, %0
%34 = call i32 @close(i32 %6)
ret i32 0
}