#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*/ IPPROTO_IP;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int GetMACAddress(unsigned char *buffer) {
  int fd;
  unsigned char *hw;
  struct ifreq ifreq;
  fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
  strcpy(ifreq.ifr_name, "eth0");
  ioctl(fd, SIOCGIFHWADDR, &ifreq);
  hw = (unsigned char *)ifreq.ifr_hwaddr.sa_data;
  buffer[0] = hw[0];
  buffer[1] = hw[1];
  buffer[2] = hw[2];
  buffer[3] = hw[3];
  buffer[4] = hw[4];
  buffer[5] = hw[5];
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<GetMACAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0xc(%rbp)
mov    -0x20(%rbp),%edi
lea    0xe87(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%rax
mov    0x3(%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x18(%rbp),%rax
mov    0x5(%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetMACAddress>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,%ebp
lea    0xe8e(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%cl
mov    %cl,(%rbx)
mov    0x1(%rax),%cl
mov    %cl,0x1(%rbx)
mov    0x2(%rax),%cl
mov    %cl,0x2(%rbx)
mov    0x3(%rax),%cl
mov    %cl,0x3(%rbx)
mov    0x4(%rax),%cl
mov    %cl,0x4(%rbx)
mov    0x5(%rax),%al
mov    %al,0x5(%rbx)
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@.str = [5 x i8] c"eth0\00"
@SIOCGIFHWADDR = global i32 0
define i32 @GetMACAddress(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.ifreq
store i8* %0, i8** %2
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = load i32, i32* @IPPROTO_IP
%9 = call i32 @socket(i32 %6, i32 %7, i32 %8)
store i32 %9, i32* %3
%10 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 1
%11 = load i32, i32* %10
%12 = call i32 @strcpy(i32 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %3
%14 = load i32, i32* @SIOCGIFHWADDR
%15 = call i32 @ioctl(i32 %13, i32 %14, %struct.ifreq* %5)
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
%18 = load i64, i64* %17
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 %22, i8* %24
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 %27, i8* %29
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = load i8, i8* %31
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8 %32, i8* %34
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 3
%37 = load i8, i8* %36
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i64 3
store i8 %37, i8* %39
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 4
%42 = load i8, i8* %41
%43 = load i8*, i8** %2
%44 = getelementptr inbounds i8, i8* %43, i64 4
store i8 %42, i8* %44
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i64 5
%47 = load i8, i8* %46
%48 = load i8*, i8** %2
%49 = getelementptr inbounds i8, i8* %48, i64 5
store i8 %47, i8* %49
%50 = load i32, i32* %3
%51 = call i32 @close(i32 %50)
ret i32 0
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@.str = [5 x i8] c"eth0\00"
@SIOCGIFHWADDR = global i32 0
define i32 @GetMACAddress(i8* nocapture writeonly %0) {
%2 = alloca %struct.ifreq
%3 = bitcast %struct.ifreq* %2 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = load i32, i32* @IPPROTO_IP
%7 = tail call i32 @socket(i32 %4, i32 %5, i32 %6)
%8 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @SIOCGIFHWADDR
%10 = call i32 @ioctl(i32 %7, i32 %9, %struct.ifreq* %2)
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0, i32 0
%12 = load i64, i64* %11
%13 = inttoptr i64 %12 to i8*
%14 = load i8, i8* %13
store i8 %14, i8* %0
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %16, i8* %17
%18 = getelementptr inbounds i8, i8* %13, i64 2
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %19, i8* %20
%21 = getelementptr inbounds i8, i8* %13, i64 3
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %22, i8* %23
%24 = getelementptr inbounds i8, i8* %13, i64 4
%25 = load i8, i8* %24
%26 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %25, i8* %26
%27 = getelementptr inbounds i8, i8* %13, i64 5
%28 = load i8, i8* %27
%29 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %28, i8* %29
%30 = call i32 @close(i32 %7)
ret i32 0
}