#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 */
typedef unsigned char uint8_t;
struct TYPE_2__ {
  scalar_t__ *sa_data;
};
struct ifreq {
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
void Ethernet_getInterfaceMACAddress(char *interfaceId, uint8_t *addr) {
  struct ifreq buffer;
  int sock = socket(PF_INET, SOCK_DGRAM, 0);
  memset(&buffer, 0x00, sizeof(buffer));
  strcpy(buffer.ifr_name, interfaceId);
  ioctl(sock, SIOCGIFHWADDR, &buffer);
  close(sock);
  int i;
  for (i = 0; i < 6; i++) {
    addr[i] = (unsigned char)buffer.ifr_hwaddr.sa_data[i];
  }
}


x86 assembly (clang, -O0):
<Ethernet_getInterfaceMACAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x24(%rbp),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x6,-0x28(%rbp)
jge    11ed <Ethernet_getInterfaceMACAddress+0x9d>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11bc <Ethernet_getInterfaceMACAddress+0x6c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Ethernet_getInterfaceMACAddress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x10(%rsp),%edi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r15,%rdx
call   1050 <ioctl@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%cl
mov    %cl,(%rbx)
mov    0x8(%rax),%cl
mov    %cl,0x1(%rbx)
mov    0x10(%rax),%cl
mov    %cl,0x2(%rbx)
mov    0x18(%rax),%cl
mov    %cl,0x3(%rbx)
mov    0x20(%rax),%cl
mov    %cl,0x4(%rbx)
mov    0x28(%rax),%al
mov    %al,0x5(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64* }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCGIFHWADDR = global i32 0
define void @Ethernet_getInterfaceMACAddress(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.ifreq
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i32, i32* @PF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %6
%11 = call i32 @memset(%struct.ifreq* %5, i32 0, i32 16)
%12 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 1
%13 = load i32, i32* %12
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i32 %13, i8* %14)
%16 = load i32, i32* %6
%17 = load i32, i32* @SIOCGIFHWADDR
%18 = call i32 @ioctl(i32 %16, i32 %17, %struct.ifreq* %5)
%19 = load i32, i32* %6
%20 = call i32 @close(i32 %19)
store i32 0, i32* %7
br label %21
21: ; preds = %37, %2
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 6
br i1 %23, label %24, label %40
24: ; preds = %21
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
%27 = load i64*, i64** %26
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i64, i64* %27, i64 %29
%31 = load i64, i64* %30
%32 = trunc i64 %31 to i8
%33 = load i8*, i8** %4
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
br label %37
37: ; preds = %24
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %21
40: ; preds = %21
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64* }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCGIFHWADDR = global i32 0
define void @Ethernet_getInterfaceMACAddress(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 16)
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%10 = load i32, i32* %9
%11 = call i32 @strcpy(i32 %10, i8* %0)
%12 = load i32, i32* @SIOCGIFHWADDR
%13 = call i32 @ioctl(i32 %7, i32 %12, %struct.ifreq* %3)
%14 = call i32 @close(i32 %7)
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0, i32 0
%16 = load i64*, i64** %15
%17 = load i64, i64* %16
%18 = trunc i64 %17 to i8
store i8 %18, i8* %1
%19 = getelementptr inbounds i64, i64* %16, i64 1
%20 = load i64, i64* %19
%21 = trunc i64 %20 to i8
%22 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %21, i8* %22
%23 = getelementptr inbounds i64, i64* %16, i64 2
%24 = load i64, i64* %23
%25 = trunc i64 %24 to i8
%26 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %25, i8* %26
%27 = getelementptr inbounds i64, i64* %16, i64 3
%28 = load i64, i64* %27
%29 = trunc i64 %28 to i8
%30 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %29, i8* %30
%31 = getelementptr inbounds i64, i64* %16, i64 4
%32 = load i64, i64* %31
%33 = trunc i64 %32 to i8
%34 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %33, i8* %34
%35 = getelementptr inbounds i64, i64* %16, i64 5
%36 = load i64, i64* %35
%37 = trunc i64 %36 to i8
%38 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %37, i8* %38
ret void
}