#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__ {
  char *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;
int /*<<< orphan*/ ARPHRD_ETHER;
int /*<<< orphan*/ SIOCSIFHWADDR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *, char *, char *,
                          char *, char *);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int main() {
  struct ifreq ifreq;
  int socket_id;
  int ret, i;
  char ifname[] = "eth0";
  char mac_addr[18] = "08:00:27:61:76:1e";
  char temp[6] = {0};
  socket_id = socket(AF_INET, SOCK_STREAM, 0);
  ifreq.ifr_addr.sa_family = ARPHRD_ETHER;
  strcpy(ifreq.ifr_name, ifname);
  sscanf(mac_addr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &temp[0], &temp[1],
         &temp[2], &temp[3], &temp[4], &temp[5]);
  for (i = 0; i < 6; i++) {
    ifreq.ifr_hwaddr.sa_data[i] = temp[i];
    printf("%x:", ifreq.ifr_hwaddr.sa_data[i]);
  }
  ret = ioctl(socket_id, SIOCSIFHWADDR, &ifreq);
  if (ret < 0) {
    perror("error ioctl");
    return -1;
  }
  close(socket_id);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe6b(%rip),%eax
mov    %eax,-0x29(%rbp)
mov    0xe66(%rip),%al
mov    %al,-0x25(%rbp)
mov    0xe98(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe95(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe92(%rip),%ax
mov    %ax,-0x30(%rbp)
lea    -0x46(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1050 <memset@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x29(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
lea    -0x46(%rbp),%rdx
lea    -0x46(%rbp),%rcx
add    $0x1,%rcx
lea    -0x46(%rbp),%r8
add    $0x2,%r8
lea    -0x46(%rbp),%r9
add    $0x3,%r9
lea    -0x46(%rbp),%r10
add    $0x4,%r10
lea    -0x46(%rbp),%rax
add    $0x5,%rax
lea    0xdc8(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1080 <sscanf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x6,-0x24(%rbp)
jge    1295 <main+0x115>
movslq -0x24(%rbp),%rax
mov    -0x46(%rbp,%rax,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
lea    0xda5(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1252 <main+0xd2>
mov    -0x1c(%rbp),%edi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12cf <main+0x14f>
lea    0xd69(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12de <main+0x15e>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movb   $0x0,0xc(%rsp)
movl   $0x30687465,0x8(%rsp)
30
movaps 0xee7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x65,0x20(%rsp)
movw   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0x4(%rsp),%rbx
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
lea    0x8(%rsp),%rsi
call   1030 <strcpy@plt>
lea    0x1(%rsp),%rcx
lea    0x2(%rsp),%r8
lea    0x3(%rsp),%r9
lea    0x5(%rsp),%rax
lea    0xe5f(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rsp,%rdx
push   %rax
push   %rbx
call   1040 <sscanf@plt>

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_4__, i32, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i8* }
%struct.TYPE_3__ = type { i32 }
@__const.main.ifname = [5 x i8] c"eth0\00"
@__const.main.mac_addr = [18 x i8] c"08:00:27:61:76:1e\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@ARPHRD_ETHER = global i32 0
@.str = [30 x i8] c"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\00"
@.str.1 = [4 x i8] c"%x:\00"
@SIOCSIFHWADDR = global i32 0
@.str.2 = [12 x i8] c"error ioctl\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.ifreq
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [5 x i8]
%7 = alloca [18 x i8]
%8 = alloca [6 x i8]
store i32 0, i32* %1
%9 = bitcast [5 x i8]* %6 to i8*
%10 = bitcast [18 x i8]* %7 to i8*
%11 = bitcast [6 x i8]* %8 to i8*
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %3
%15 = load i32, i32* @ARPHRD_ETHER
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 2
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%21 = call i32 @strcpy(i32 %19, i8* %20)
%22 = getelementptr inbounds [18 x i8], [18 x i8]* %7, i64 0, i64 0
%23 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 1
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 2
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 3
%27 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 4
%28 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 5
%29 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %24, i8* %25, i8* %26, i8* %27, i8* %28)
store i32 0, i32* %5
br label %30
30: ; preds = %52, %0
%31 = load i32, i32* %5
%32 = icmp slt i32 %31, 6
br i1 %32, label %33, label %55
33: ; preds = %30
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 0
%39 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 %37, i8* %43
%44 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 0
%45 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %50)
br label %52
52: ; preds = %33
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %30
55: ; preds = %30
%56 = load i32, i32* %3
%57 = load i32, i32* @SIOCSIFHWADDR
%58 = call i32 @ioctl(i32 %56, i32 %57, %struct.ifreq* %2)
store i32 %58, i32* %4
%59 = load i32, i32* %4
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %66
63: ; preds = %55
%64 = load i32, i32* %3
%65 = call i32 @close(i32 %64)
store i32 0, i32* %1
br label %66
66: ; preds = %63, %61
%67 = load i32, i32* %1
ret i32 %67
}

LLVM IR (-O2):
@__const.main.ifname = [5 x i8] c"eth0\00"
@__const.main.mac_addr = [18 x i8] c"08:00:27:61:76:1e\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@ARPHRD_ETHER = global i32 0
@.str = [30 x i8] c"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\00"
@SIOCSIFHWADDR = global i32 0
define i32 @main() {
%1 = alloca [5 x i8]
%2 = alloca [18 x i8]
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = call i32 @strcpy(i32 undef, i8* %4)
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 1
%12 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 2
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 3
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 4
%15 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 5
%16 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %11, i8* %12, i8* %13, i8* %14, i8* %15)
unreachable
}