#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 */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ _IOC(int /*<<< orphan*/, int, int, int);
int /*<<< orphan*/ _IOC_READ;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stdout;
int read_localmac(int fd) {
  char bdaddr[6];
  memset(bdaddr, 0, 6);
  ioctl(fd, _IOC(_IOC_READ, 0x21, 15, 6), bdaddr);
  if (bdaddr[0] == 0x00 && bdaddr[1] == 0x19 && bdaddr[2] == 0x65) {
    bdaddr[0] |= 0x06;
    fprintf(stdout, "%02X:%02X:%02X:%02X:%02X:%02X\n", bdaddr[0], bdaddr[1],
            bdaddr[2], bdaddr[3], bdaddr[4], bdaddr[5]);
  } else {
    fprintf(stdout, "40:00:01:00:00:01\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_localmac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xa(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    $0x21,%esi
mov    $0xf,%edx
mov    $0x6,%ecx
call   1030 <_IOC@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
lea    -0xa(%rbp),%rdx
call   1050 <ioctl@plt>
movsbl -0xa(%rbp),%eax
cmp    $0x0,%eax
jne    11fc <read_localmac+0xbc>
movsbl -0x9(%rbp),%eax
cmp    $0x19,%eax
jne    11fc <read_localmac+0xbc>
movsbl -0x8(%rbp),%eax
cmp    $0x65,%eax
jne    11fc <read_localmac+0xbc>
movsbl -0xa(%rbp),%eax
or     $0x6,%eax
mov    %al,-0xa(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
movsbl -0xa(%rbp),%edx
movsbl -0x9(%rbp),%ecx
movsbl -0x8(%rbp),%r8d
movsbl -0x7(%rbp),%r9d
movsbl -0x6(%rbp),%r10d
movsbl -0x5(%rbp),%eax
lea    0xe18(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1213 <read_localmac+0xd3>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_localmac>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x2(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1040 <memset@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    $0x21,%esi
mov    $0xf,%edx
mov    $0x6,%ecx
call   1030 <_IOC@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    %r14,%rdx
call   1050 <ioctl@plt>
cmpb   $0x0,0x2(%rsp)
jne    11de <read_localmac+0x9e>
cmpb   $0x19,0x3(%rsp)
jne    11de <read_localmac+0x9e>
cmpb   $0x65,0x4(%rsp)
jne    11de <read_localmac+0x9e>
movb   $0x6,0x2(%rsp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
movsbl 0x5(%rsp),%r9d
movsbl 0x6(%rsp),%r10d
movsbl 0x7(%rsp),%ebx
lea    0xe42(%rip),%rsi
mov    $0x6,%edx
mov    $0x19,%ecx
mov    $0x65,%r8d
xor    %eax,%eax
push   %rbx
push   %r10
call   1060 <fprintf@plt>
add    $0x10,%rsp
jmp    11f5 <read_localmac+0xb5>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@_IOC_READ = global i32 0
@stdout = global i32 0
@.str = [31 x i8] c"%02X:%02X:%02X:%02X:%02X:%02X\0A\00"
@.str.1 = [19 x i8] c"40:00:01:00:00:01\0A\00"
define i32 @read_localmac(i32 %0) {
%2 = alloca i32
%3 = alloca [6 x i8]
store i32 %0, i32* %2
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 6)
%6 = load i32, i32* %2
%7 = load i32, i32* @_IOC_READ
%8 = call i32 @_IOC(i32 %7, i32 33, i32 15, i32 6)
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%10 = call i32 @ioctl(i32 %6, i32 %8, i8* %9)
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %51
15: ; preds = %1
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 25
br i1 %19, label %20, label %51
20: ; preds = %15
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 2
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 101
br i1 %24, label %25, label %51
25: ; preds = %20
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = or i32 %28, 6
%30 = trunc i32 %29 to i8
store i8 %30, i8* %26
%31 = load i32, i32* @stdout
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 1
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 2
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 3
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 4
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 5
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %37, i32 %40, i32 %43, i32 %46, i32 %49)
br label %54
51: ; preds = %20, %15, %1
%52 = load i32, i32* @stdout
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %54
54: ; preds = %51, %25
ret i32 0
}

LLVM IR (-O2):
@_IOC_READ = global i32 0
@stdout = global i32 0
@.str = [31 x i8] c"%02X:%02X:%02X:%02X:%02X:%02X\0A\00"
@.str.1 = [19 x i8] c"40:00:01:00:00:01\0A\00"
define i32 @read_localmac(i32 %0) {
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 6)
%5 = load i32, i32* @_IOC_READ
%6 = call i32 @_IOC(i32 %5, i32 33, i32 15, i32 6)
%7 = call i32 @ioctl(i32 %0, i32 %6, i8* %3)
%8 = load i8, i8* %3
%9 = icmp eq i8 %8, 0
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 25
%13 = select i1 %9, i1 %12, i1 false
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 2
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 101
%17 = select i1 %13, i1 %16, i1 false
br i1 %17, label %18, label %30
18: ; preds = %1
store i8 6, i8* %3
%19 = load i32, i32* @stdout
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 3
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 5
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 6, i32 25, i32 101, i32 %22, i32 %25, i32 %28)
br label %33
30: ; preds = %1
%31 = load i32, i32* @stdout
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %30, %18
ret i32 0
}