#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_WRITE;
scalar_t__ ioctl(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ sscanf(char const *, char *, unsigned int *, unsigned int *,
                          unsigned int *, unsigned int *, unsigned int *,
                          unsigned int *);
int write_bdaddr(int fd, const char *value) {
  char bdaddr[6];
  unsigned int tmp[6];
  int i;
  sscanf(value, "%02x:%02x:%02x:%02x:%02x:%02x", &tmp[0], &tmp[1], &tmp[2],
         &tmp[3], &tmp[4], &tmp[5]);
  for (i = 0; i < 6; i++) {
    bdaddr[i] = tmp[i];
  }
  if (ioctl(fd, _IOC(_IOC_WRITE, 0x21, 14, 6), bdaddr) < 0) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<write_bdaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
add    $0x4,%rcx
lea    -0x30(%rbp),%r8
add    $0x8,%r8
lea    -0x30(%rbp),%r9
add    $0xc,%r9
lea    -0x30(%rbp),%r10
add    $0x10,%r10
lea    -0x30(%rbp),%rax
add    $0x14,%rax
lea    0xe8a(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <sscanf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x6,-0x34(%rbp)
jge    11b5 <write_bdaddr+0x85>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %al,%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x16(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118b <write_bdaddr+0x5b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    $0x21,%esi
mov    $0xe,%edx
mov    $0x6,%ecx
call   1030 <_IOC@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%esi
lea    -0x16(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11fc <write_bdaddr+0xcc>
movl   $0x1,-0x4(%rbp)
jmp    1203 <write_bdaddr+0xd3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_bdaddr>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rax
mov    %edi,%ebp
lea    0x14(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x1c(%rsp),%r9
lea    0x20(%rsp),%r10
lea    0x24(%rsp),%rbx
lea    0xeb5(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
push   %rbx
push   %r10
call   1050 <sscanf@plt>
add    $0x10,%rsp
movdqa 0x10(%rsp),%xmm0
pand   0xe83(%rip),%xmm0
packuswb %xmm0,%xmm0
packuswb %xmm0,%xmm0
movd   %xmm0,0x8(%rsp)
mov    0x20(%rsp),%al
mov    %al,0xc(%rsp)
mov    0x24(%rsp),%al
mov    %al,0xd(%rsp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    $0x21,%esi
mov    $0xe,%edx
mov    $0x6,%ecx
call   1030 <_IOC@plt>
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
shr    $0x3f,%rax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
@_IOC_WRITE = global i32 0
define i32 @write_bdaddr(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [6 x i8]
%7 = alloca [6 x i32]
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 0
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 1
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 2
%13 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 3
%14 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 4
%15 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 5
%16 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32* %10, i32* %11, i32* %12, i32* %13, i32* %14, i32* %15)
store i32 0, i32* %8
br label %17
17: ; preds = %29, %2
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 6
br i1 %19, label %20, label %32
20: ; preds = %17
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = trunc i32 %24 to i8
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 %27
store i8 %25, i8* %28
br label %29
29: ; preds = %20
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %17
32: ; preds = %17
%33 = load i32, i32* %4
%34 = load i32, i32* @_IOC_WRITE
%35 = call i32 @_IOC(i32 %34, i32 33, i32 14, i32 6)
%36 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%37 = call i64 @ioctl(i32 %33, i32 %35, i8* %36)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %32
store i32 1, i32* %3
br label %41
40: ; preds = %32
store i32 0, i32* %3
br label %41
41: ; preds = %40, %39
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
@_IOC_WRITE = global i32 0
define i32 @write_bdaddr(i32 %0, i8* nocapture %1) {
%3 = alloca [6 x i8]
%4 = alloca [6 x i32]
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%6 = bitcast [6 x i32]* %4 to i8*
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%8 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 1
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 2
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 3
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 4
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 5
%13 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32* %7, i32* %8, i32* %9, i32* %10, i32* %11, i32* %12)
%14 = bitcast [6 x i32]* %4 to <4 x i32>*
%15 = load <4 x i32>, <4 x i32>* %14
%16 = trunc <4 x i32> %15 to <4 x i8>
%17 = bitcast [6 x i8]* %3 to <4 x i8>*
store <4 x i8> %16, <4 x i8>* %17
%18 = load i32, i32* %11
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 4
store i8 %19, i8* %20
%21 = load i32, i32* %12
%22 = trunc i32 %21 to i8
%23 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 5
store i8 %22, i8* %23
%24 = load i32, i32* @_IOC_WRITE
%25 = call i32 @_IOC(i32 %24, i32 33, i32 14, i32 6)
%26 = call i64 @ioctl(i32 %0, i32 %25, i8* %5)
%27 = lshr i64 %26, 63
%28 = trunc i64 %27 to i32
ret i32 %28
}