#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;
};
struct ether_addr {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ ether_ntoa(struct ether_addr *);
struct ifreq *get_ifreq(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
char *get_if_mac(char *ifname) {
  static char buf[18];
  bzero(buf, sizeof(buf));
  struct ifreq *ifr = get_ifreq(ifname, SIOCGIFHWADDR);
  strcpy(buf, ether_ntoa((struct ether_addr *)&ifr->ifr_hwaddr.sa_data));
  return buf;
}


x86 assembly (clang, -O0):
<get_if_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2efd(%rip),%rdi
mov    $0x12,%esi
call   1050 <bzero@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
call   1060 <get_ifreq@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ether_ntoa@plt>
mov    %eax,%esi
lea    0x2ecb(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ebf(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_if_mac>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x2f02(%rip),%r14
mov    %r14,%rdi
mov    $0x12,%esi
call   1050 <bzero@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <get_ifreq@plt>
mov    %rax,%rdi
call   1040 <ether_ntoa@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.ether_addr = type { i32 }
@get_if_mac.buf = internal global [18 x i8] zeroinitializer
@SIOCGIFHWADDR = global i32 0
define i8* @get_if_mac(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ifreq*
store i8* %0, i8** %2
%4 = call i32 @bzero(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_mac.buf, i64 0, i64 0), i32 18)
%5 = load i8*, i8** %2
%6 = load i32, i32* @SIOCGIFHWADDR
%7 = call %struct.ifreq* @get_ifreq(i8* %5, i32 %6)
store %struct.ifreq* %7, %struct.ifreq** %3
%8 = load %struct.ifreq*, %struct.ifreq** %3
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%10 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %9, i32 0, i32 0
%11 = bitcast i32* %10 to %struct.ether_addr*
%12 = call i32 @ether_ntoa(%struct.ether_addr* %11)
%13 = call i32 @strcpy(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_mac.buf, i64 0, i64 0), i32 %12)
ret i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_mac.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.ether_addr = type { i32 }
@get_if_mac.buf = internal global [18 x i8] zeroinitializer
@SIOCGIFHWADDR = global i32 0
define i8* @get_if_mac(i8* %0) {
%2 = tail call i32 @bzero(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_mac.buf, i64 0, i64 0), i32 18)
%3 = load i32, i32* @SIOCGIFHWADDR
%4 = tail call %struct.ifreq* @get_ifreq(i8* %0, i32 %3)
%5 = bitcast %struct.ifreq* %4 to %struct.ether_addr*
%6 = tail call i32 @ether_ntoa(%struct.ether_addr* %5)
%7 = tail call i32 @strcpy(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_mac.buf, i64 0, i64 0), i32 %6)
ret i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_mac.buf, i64 0, i64 0)
}