#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  scalar_t__ sa_data;
};
struct TYPE_3__ {
  int /*<<< orphan*/ sa_family;
};
struct ifreq {
  TYPE_2__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
  TYPE_1__ ifr_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ IFNAMSIZ;
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*/ sprintf(char *, char *, unsigned char, unsigned char,
                           unsigned char, unsigned char, unsigned char,
                           unsigned char);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, scalar_t__);
int get_mac_adress(char **return_mac) {
  int fd;
  struct ifreq ifr;
  char *iface = "eth0";
  unsigned char *mac;
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  ifr.ifr_addr.sa_family = AF_INET;
  strncpy(ifr.ifr_name, iface, IFNAMSIZ - 1);
  ioctl(fd, SIOCGIFHWADDR, &ifr);
  close(fd);
  mac = (unsigned char *)ifr.ifr_hwaddr.sa_data;
  sprintf(*return_mac, "%.2x%.2x%.2x%.2x%.2x%.2x\0", mac[0], mac[1], mac[2],
          mac[3], mac[4], mac[5]);
  return 0;
}


x86 assembly (clang, -O0):
<get_mac_adress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    0x2e2b(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0xc(%rbp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%dl
mov    -0x30(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x30(%rbp),%rax
mov    0x2(%rax),%r8b
mov    -0x30(%rbp),%rax
mov    0x3(%rax),%r9b
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%r10b
mov    -0x30(%rbp),%rax
lea    0xe00(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl %r10b,%r10d
mov    %r10d,(%rsp)
movzbl 0x5(%rax),%eax
mov    %eax,0x8(%rsp)
call   1060 <sprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mac_adress>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e86(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    0x2e45(%rip),%rax
mov    (%rax),%rdx
add    $0xffffffffffffffff,%rdx
lea    0xe6f(%rip),%rsi
call   1030 <strncpy@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    (%rsp),%rax
mov    (%r14),%rdi
movzbl (%rax),%edx
movzbl 0x1(%rax),%ecx
movzbl 0x2(%rax),%r8d
movzbl 0x3(%rax),%r9d
movzbl 0x4(%rax),%ebp
movzbl 0x5(%rax),%eax
lea    0xe2e(%rip),%rsi
push   %rax
push   %rbp
call   1060 <sprintf@plt>
add    $0x10,%rsp
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_4__, i32, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64 }
%struct.TYPE_3__ = type { i32 }
@.str = [5 x i8] c"eth0\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IFNAMSIZ = global i64 0
@SIOCGIFHWADDR = global i32 0
@.str.1 = [26 x i8] c"%.2x%.2x%.2x%.2x%.2x%.2x\00\00"
define i32 @get_mac_adress(i8** nocapture %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 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 2, i32 0
store i32 %7, i32* %8
%9 = load i64, i64* @IFNAMSIZ
%10 = add nsw i64 %9, -1
%11 = tail call i32 @strncpy(i32 undef, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = load i32, i32* @SIOCGIFHWADDR
%13 = call i32 @ioctl(i32 %6, i32 %12, %struct.ifreq* %2)
%14 = call i32 @close(i32 %6)
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0, i32 0
%16 = load i64, i64* %15
%17 = inttoptr i64 %16 to i8*
%18 = load i8*, i8** %0
%19 = load i8, i8* %17
%20 = getelementptr inbounds i8, i8* %17, i64 1
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8, i8* %17, i64 2
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %17, i64 3
%25 = load i8, i8* %24
%26 = getelementptr inbounds i8, i8* %17, i64 4
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %17, i64 5
%29 = load i8, i8* %28
%30 = call i32 @sprintf(i8* dereferenceable(1) %18, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %19, i8 zeroext %21, i8 zeroext %23, i8 zeroext %25, i8 zeroext %27, i8 zeroext %29)
ret i32 0
}