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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char, unsigned char,
                            unsigned char, unsigned char, unsigned char,
                            unsigned char);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
void get_hwaddr(char *if_name, char *address, int length) {
  unsigned char *hwaddr;
  struct ifreq interface;
  int s = socket(AF_INET, SOCK_DGRAM, 0);
  strcpy(interface.ifr_name, if_name);
  ioctl(s, SIOCGIFHWADDR, &interface);
  close(s);
  hwaddr = interface.ifr_hwaddr.sa_data;
  snprintf(address, length, "%02X:%02X:%02X:%02X:%02X:%02X", hwaddr[0],
           hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]);
}


x86 assembly (clang, -O0):
<get_hwaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x34(%rbp),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%r8b
mov    -0x20(%rbp),%rax
mov    0x2(%rax),%r9b
mov    -0x20(%rbp),%rax
mov    0x3(%rax),%r11b
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%r10b
mov    -0x20(%rbp),%rax
lea    0xe18(%rip),%rdx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl %r11b,%r11d
mov    %r11d,(%rsp)
movzbl %r10b,%r10d
mov    %r10d,0x8(%rsp)
movzbl 0x5(%rax),%eax
mov    %eax,0x10(%rsp)
call   1040 <snprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hwaddr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x8(%rsp),%rax
movzbl (%rax),%ecx
movzbl 0x1(%rax),%r8d
movzbl 0x2(%rax),%r9d
movzbl 0x3(%rax),%ebp
movzbl 0x4(%rax),%ebx
movzbl 0x5(%rax),%eax
sub    $0x8,%rsp
lea    0xe35(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
push   %rax
push   %rbx
push   %rbp
call   1040 <snprintf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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