#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 *, char, char, char, char,
                           char, char);
scalar_t__ ioctl(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ stdout;
int read_bdaddr(int fd) {
  char bdaddr[6];
  if (ioctl(fd, _IOC(_IOC_READ, 0x21, 15, 6), bdaddr) < 0) {
    return 1;
  }
  fprintf(stdout, "%02X:%02X:%02X:%02X:%02X:%02X\n", bdaddr[0], bdaddr[1],
          bdaddr[2], bdaddr[3], bdaddr[4], bdaddr[5]);
  return 0;
}


x86 assembly (clang, -O0):
<read_bdaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    $0x21,%esi
mov    $0xf,%edx
mov    $0x6,%ecx
call   1030 <_IOC@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%esi
lea    -0xe(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1182 <read_bdaddr+0x52>
movl   $0x1,-0x4(%rbp)
jmp    11cb <read_bdaddr+0x9b>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    -0xe(%rbp),%dl
mov    -0xd(%rbp),%cl
mov    -0xc(%rbp),%r8b
mov    -0xb(%rbp),%r9b
mov    -0xa(%rbp),%al
lea    0xe5d(%rip),%rsi
movsbl %dl,%edx
movsbl %cl,%ecx
movsbl %r8b,%r8d
movsbl %r9b,%r9d
movsbl %al,%eax
mov    %eax,(%rsp)
movsbl -0x9(%rbp),%eax
mov    %eax,0x8(%rsp)
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_bdaddr>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    $0x21,%esi
mov    $0xf,%edx
mov    $0x6,%ecx
call   1030 <_IOC@plt>
lea    0xa(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
test   %rax,%rax
js     11a6 <read_bdaddr+0x76>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
movsbl 0xa(%rsp),%edx
movsbl 0xb(%rsp),%ecx
movsbl 0xc(%rsp),%r8d
movsbl 0xd(%rsp),%r9d
movsbl 0xe(%rsp),%eax
movsbl 0xf(%rsp),%ebx
lea    0xe69(%rip),%rsi
push   %rbx
push   %rax
call   1050 <fprintf@plt>
add    $0x10,%rsp
xor    %eax,%eax
jmp    11ab <read_bdaddr+0x7b>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
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"
define i32 @read_bdaddr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [6 x i8]
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @_IOC_READ
%7 = call i32 @_IOC(i32 %6, i32 33, i32 15, i32 6)
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%9 = call i64 @ioctl(i32 %5, i32 %7, i8* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %2
br label %27
12: ; preds = %1
%13 = load i32, i32* @stdout
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%15 = load i8, i8* %14
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 1
%17 = load i8, i8* %16
%18 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 2
%19 = load i8, i8* %18
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 3
%21 = load i8, i8* %20
%22 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 4
%23 = load i8, i8* %22
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 5
%25 = load i8, i8* %24
%26 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8 signext %15, i8 signext %17, i8 signext %19, i8 signext %21, i8 signext %23, i8 signext %25)
store i32 0, i32* %2
br label %27
27: ; preds = %12, %11
%28 = load i32, i32* %2
ret i32 %28
}

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"
define i32 @read_bdaddr(i32 %0) {
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @_IOC_READ
%5 = tail call i32 @_IOC(i32 %4, i32 33, i32 15, i32 6)
%6 = call i64 @ioctl(i32 %0, i32 %5, i8* %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %1
%9 = load i32, i32* @stdout
%10 = load i8, i8* %3
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 1
%12 = load i8, i8* %11
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 2
%14 = load i8, i8* %13
%15 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 3
%16 = load i8, i8* %15
%17 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 4
%18 = load i8, i8* %17
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 5
%20 = load i8, i8* %19
%21 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8 signext %10, i8 signext %12, i8 signext %14, i8 signext %16, i8 signext %18, i8 signext %20)
br label %22
22: ; preds = %1, %8
%23 = phi i32 [ 0, %8 ], [ 1, %1 ]
ret i32 %23
}