#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;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int IFHWADDRLEN;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
void getMacAddress(char *interface) {
  int i;
  int fd;
  unsigned char mac[IFHWADDRLEN];
  struct ifreq ifstruct;
  strcpy(ifstruct.ifr_name, interface);
  fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
  ioctl(fd, SIOCGIFHWADDR, &ifstruct);
  memcpy(mac, ifstruct.ifr_hwaddr.sa_data, IFHWADDRLEN);
  printf("\nMAC ADDRESS : ");
  for (i = 0; i < IFHWADDRLEN; i++)
    printf("%02X:", (unsigned int)(mac[i]));
  printf("\n\n");
}


x86 assembly (clang, -O0):
<getMacAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
call   1060 <memcpy@plt>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2db8(%rip),%rcx
cmp    (%rcx),%eax
jge    1230 <getMacAddress+0xe0>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11f6 <getMacAddress+0xa6>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMacAddress>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e42(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rdi,%rsi
call   1030 <strcpy@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    0x2e0f(%rip),%rcx
mov    (%rcx),%esi
lea    -0x28(%rbp),%rdx
mov    %eax,%edi
call   1060 <ioctl@plt>
mov    -0x28(%rbp),%esi
mov    (%r15),%edx
mov    %r12,%rdi
call   1070 <memcpy@plt>
lea    0xe25(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,(%r15)
jle    121b <getMacAddress+0xbb>
lea    0xe21(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq (%r15),%rax
cmp    %rax,%rbx
jl     1200 <getMacAddress+0xa0>
lea    0xdf4(%rip),%rdi
call   1040 <puts@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@IFHWADDRLEN = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str = [16 x i8] c"\0AMAC ADDRESS : \00"
@.str.1 = [6 x i8] c"%02X:\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
define void @getMacAddress(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.ifreq
store i8* %0, i8** %2
%8 = load i32, i32* @IFHWADDRLEN
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 1
%13 = load i32, i32* %12
%14 = load i8*, i8** %2
%15 = call i32 @strcpy(i32 %13, i8* %14)
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = load i32, i32* @IPPROTO_IP
%19 = call i32 @socket(i32 %16, i32 %17, i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = load i32, i32* @SIOCGIFHWADDR
%22 = call i32 @ioctl(i32 %20, i32 %21, %struct.ifreq* %7)
%23 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = load i32, i32* @IFHWADDRLEN
%27 = call i32 @memcpy(i8* %11, i32 %25, i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %29
29: ; preds = %40, %1
%30 = load i32, i32* %3
%31 = load i32, i32* @IFHWADDRLEN
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %43
33: ; preds = %29
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %11, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %33
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %29
43: ; preds = %29
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%45 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@IFHWADDRLEN = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str = [16 x i8] c"\0AMAC ADDRESS : \00"
@.str.1 = [6 x i8] c"%02X:\00"
@str = [2 x i8] c"\0A\00"
define void @getMacAddress(i8* %0) {
%2 = alloca %struct.ifreq
%3 = load i32, i32* @IFHWADDRLEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast %struct.ifreq* %2 to i8*
%7 = tail call i32 @strcpy(i32 undef, i8* %0)
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = load i32, i32* @IPPROTO_IP
%11 = tail call i32 @socket(i32 %8, i32 %9, i32 %10)
%12 = load i32, i32* @SIOCGIFHWADDR
%13 = call i32 @ioctl(i32 %11, i32 %12, %struct.ifreq* %2)
%14 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i32, i32* @IFHWADDRLEN
%17 = call i32 @memcpy(i8* %5, i32 %15, i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @IFHWADDRLEN
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %1, %21
%22 = phi i64 [ %27, %21 ], [ 0, %1 ]
%23 = getelementptr inbounds i8, i8* %5, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %22, 1
%28 = load i32, i32* @IFHWADDRLEN
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %21, label %31
31: ; preds = %21, %1
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}