#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*/ printf(char *, char *);
int rand();
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int, int);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/);
int sw_random_btmac(char *bdaddr_str) {
  unsigned char addr[3] = {0};
  srand((unsigned)time(0));
  addr[0] = 0x100 * rand() % (0xff);
  addr[1] = 0x100 * rand() % (0xff);
  addr[2] = 0x100 * rand() % (0xff);
  sprintf(bdaddr_str, "%s:%02x:%02x:%02x", "41:57:73", 0xff & addr[2],
          0xff & addr[1], 0xff & addr[0]);
  printf("mac %s\n", bdaddr_str);
  return 0;
}


x86 assembly (clang, -O0):
<sw_random_btmac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0xb(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x0,%al
call   1080 <rand@plt>
shl    $0x8,%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0xb(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
shl    $0x8,%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0xa(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
shl    $0x8,%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
movzbl -0x9(%rbp),%ecx
and    $0xff,%ecx
movzbl -0xa(%rbp),%r8d
and    $0xff,%r8d
movzbl -0xb(%rbp),%r9d
and    $0xff,%r9d
lea    0xe04(%rip),%rsi
lea    0xe0f(%rip),%rdx
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe08(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sw_random_btmac>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1070 <rand@plt>
shl    $0x8,%eax
cltq
imul   $0xffffffff80808081,%rax,%r15
shr    $0x20,%r15
add    %eax,%r15d
mov    %r15d,%ecx
shr    $0x1f,%ecx
shr    $0x7,%r15d
add    %ecx,%r15d
add    %eax,%r15d
xor    %eax,%eax
call   1070 <rand@plt>
shl    $0x8,%eax
cltq
imul   $0xffffffff80808081,%rax,%rbx
shr    $0x20,%rbx
add    %eax,%ebx
mov    %ebx,%ecx
shr    $0x1f,%ecx
shr    $0x7,%ebx
add    %ecx,%ebx
add    %eax,%ebx
xor    %eax,%eax
call   1070 <rand@plt>
shl    $0x8,%eax
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
movzbl %cl,%ecx
movzbl %bl,%r8d
movzbl %r15b,%r9d
lea    0xe14(%rip),%rsi
lea    0xe1f(%rip),%rdx
mov    %r14,%rdi
call   1060 <sprintf@plt>
lea    0xe19(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"%s:%02x:%02x:%02x\00"
@.str.1 = [9 x i8] c"41:57:73\00"
@.str.2 = [8 x i8] c"mac %s\0A\00"
define i32 @sw_random_btmac(i8* %0) {
%2 = alloca i8*
%3 = alloca [3 x i8]
store i8* %0, i8** %2
%4 = bitcast [3 x i8]* %3 to i8*
%5 = call i64 @time(i32 0)
%6 = trunc i64 %5 to i32
%7 = call i32 @srand(i32 %6)
%8 = call i32 (...) @rand()
%9 = mul nsw i32 256, %8
%10 = srem i32 %9, 255
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
store i8 %11, i8* %12
%13 = call i32 (...) @rand()
%14 = mul nsw i32 256, %13
%15 = srem i32 %14, 255
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
store i8 %16, i8* %17
%18 = call i32 (...) @rand()
%19 = mul nsw i32 256, %18
%20 = srem i32 %19, 255
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 %21, i8* %22
%23 = load i8*, i8** %2
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = and i32 255, %26
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = and i32 255, %30
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = and i32 255, %34
%36 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %31, i32 %35)
%37 = load i8*, i8** %2
%38 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"%s:%02x:%02x:%02x\00"
@.str.1 = [9 x i8] c"41:57:73\00"
@.str.2 = [8 x i8] c"mac %s\0A\00"
define i32 @sw_random_btmac(i8* %0) {
%2 = tail call i64 @time(i32 0)
%3 = trunc i64 %2 to i32
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 (...) @rand()
%6 = shl nsw i32 %5, 8
%7 = srem i32 %6, 255
%8 = tail call i32 (...) @rand()
%9 = shl nsw i32 %8, 8
%10 = srem i32 %9, 255
%11 = tail call i32 (...) @rand()
%12 = shl nsw i32 %11, 8
%13 = srem i32 %12, 255
%14 = and i32 %13, 255
%15 = and i32 %10, 255
%16 = and i32 %7, 255
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %15, i32 %16)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %0)
ret i32 0
}