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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ IPPROTO_RAW;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ether_etoa(char *, unsigned char *);
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ printf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int /*<<< orphan*/);
void get_mac(char *p, char *ifname) {
  int s;
  struct ifreq ifr;
  s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  if (s < 0) {
  err:
    printf("Can't get the MAC address of %s.\n", ifname);
    exit(-1);
  }
  strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
  if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0)
    ether_etoa(p, (unsigned char *)ifr.ifr_hwaddr.sa_data);
  else
    goto err;
  close(s);
}


x86 assembly (clang, -O0):
<get_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11cc <get_mac+0x5c>
jmp    11b2 <get_mac+0x42>
mov    -0x10(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jne    1212 <get_mac+0xa2>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <ether_etoa@plt>
jmp    1217 <get_mac+0xa7>
jmp    11b2 <get_mac+0x42>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mac>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
test   %eax,%eax
js     11e9 <get_mac+0x79>
mov    %eax,%ebp
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
test   %rax,%rax
jne    11e9 <get_mac+0x79>
mov    (%rsp),%rsi
mov    %rbx,%rdi
call   1080 <ether_etoa@plt>
mov    %ebp,%edi
call   1060 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe10(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@.str = [34 x i8] c"Can't get the MAC address of %s.\0A\00"
@IFNAMSIZ = global i32 0
@SIOCGIFHWADDR = global i32 0
define void @get_mac(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.ifreq
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_RAW
%9 = load i32, i32* @IPPROTO_RAW
%10 = call i32 @socket(i32 %7, i32 %8, i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
br label %14
14: ; preds = %35, %13
%15 = load i8*, i8** %4
%16 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%20 = load i32, i32* %19
%21 = load i8*, i8** %4
%22 = load i32, i32* @IFNAMSIZ
%23 = call i32 @strncpy(i32 %20, i8* %21, i32 %22)
%24 = load i32, i32* %5
%25 = load i32, i32* @SIOCGIFHWADDR
%26 = call i64 @ioctl(i32 %24, i32 %25, %struct.ifreq* %6)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %18
%29 = load i8*, i8** %3
%30 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
%32 = load i64, i64* %31
%33 = inttoptr i64 %32 to i8*
%34 = call i32 @ether_etoa(i8* %29, i8* %33)
br label %36
35: ; preds = %18
br label %14
36: ; preds = %28
%37 = load i32, i32* %5
%38 = call i32 @close(i32 %37)
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@.str = [34 x i8] c"Can't get the MAC address of %s.\0A\00"
@IFNAMSIZ = global i32 0
@SIOCGIFHWADDR = global i32 0
define void @get_mac(i8* %0, i8* %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_RAW
%7 = load i32, i32* @IPPROTO_RAW
%8 = tail call i32 @socket(i32 %5, i32 %6, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %13, %2
%11 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %1)
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = load i32, i32* @IFNAMSIZ
%15 = tail call i32 @strncpy(i32 undef, i8* %1, i32 %14)
%16 = load i32, i32* @SIOCGIFHWADDR
%17 = call i64 @ioctl(i32 %8, i32 %16, %struct.ifreq* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %10
19: ; preds = %13
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0, i32 0
%21 = load i64, i64* %20
%22 = inttoptr i64 %21 to i8*
%23 = call i32 @ether_etoa(i8* %0, i8* %22)
%24 = call i32 @close(i32 %8)
ret void
}