#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_remotemac(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] |= 0x02;
    bdaddr[0] &= 0xfb;
    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:02:00:00:01\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_remotemac>:
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    1208 <read_remotemac+0xc8>
movsbl -0x9(%rbp),%eax
cmp    $0x19,%eax
jne    1208 <read_remotemac+0xc8>
movsbl -0x8(%rbp),%eax
cmp    $0x65,%eax
jne    1208 <read_remotemac+0xc8>
movsbl -0xa(%rbp),%eax
or     $0x2,%eax
mov    %al,-0xa(%rbp)
movsbl -0xa(%rbp),%eax
and    $0xfb,%eax
mov    %al,-0xa(%rbp)
mov    0x2e10(%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    0xe0c(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    121f <read_remotemac+0xdf>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_remotemac>:
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_remotemac+0x9e>
cmpb   $0x19,0x3(%rsp)
jne    11de <read_remotemac+0x9e>
cmpb   $0x65,0x4(%rsp)
jne    11de <read_remotemac+0x9e>
movb   $0x2,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    $0x2,%edx
mov    $0x19,%ecx
mov    $0x65,%r8d
xor    %eax,%eax
push   %rbx
push   %r10
call   1060 <fprintf@plt>
add    $0x10,%rsp
jmp    11f5 <read_remotemac+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:02:00:00:01\0A\00"
define i32 @read_remotemac(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 %56
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 %56
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 %56
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, 2
%30 = trunc i32 %29 to i8
store i8 %30, i8* %26
%31 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = and i32 %33, 251
%35 = trunc i32 %34 to i8
store i8 %35, i8* %31
%36 = load i32, i32* @stdout
%37 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 1
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 2
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 4
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 5
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %39, i32 %42, i32 %45, i32 %48, i32 %51, i32 %54)
br label %59
56: ; preds = %20, %15, %1
%57 = load i32, i32* @stdout
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %59
59: ; preds = %56, %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:02:00:00:01\0A\00"
define i32 @read_remotemac(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 2, 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 2, 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
}