#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 *, ...);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int /*<<< orphan*/);
int sw_random_btmac(char *);
int sw_read_mac_from_file(char *);
int /*<<< orphan*/ sw_write_mac_file(char *);
int sw_get_btaddrstr(char *bdaddr_str) {
  int ret;
  char addr[20] = {0};
  ret = sw_read_mac_from_file(addr);
  if (!ret) {
    printf("found mac file 'bt.mac', mac %s\n", addr);
    strncpy(bdaddr_str, addr, strlen(addr));
    goto out;
  }
  ret = sw_random_btmac(addr);
  if (!ret) {
    printf("generate mac file 'bt.mac'\n");
    strncpy(bdaddr_str, addr, strlen(addr));
  }
  sw_write_mac_file(bdaddr_str);
out:
  return 0;
}


x86 assembly (clang, -O0):
<sw_get_btaddrstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
lea    -0x20(%rbp),%rdi
call   1080 <sw_read_mac_from_file@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11e1 <sw_get_btaddrstr+0x71>
lea    -0x20(%rbp),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
jmp    1236 <sw_get_btaddrstr+0xc6>
lea    -0x20(%rbp),%rdi
call   1090 <sw_random_btmac@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    122d <sw_get_btaddrstr+0xbd>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rdi
call   1030 <sw_write_mac_file@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sw_get_btaddrstr>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
mov    %rsp,%rdi
call   1080 <sw_read_mac_from_file@plt>
test   %eax,%eax
je     11cf <sw_get_btaddrstr+0x5f>
mov    %rsp,%rdi
call   1090 <sw_random_btmac@plt>
test   %eax,%eax
jne    11c5 <sw_get_btaddrstr+0x55>
lea    0xe79(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    %rbx,%rdi
call   1030 <sw_write_mac_file@plt>
jmp    11f8 <sw_get_btaddrstr+0x88>
lea    0xe2a(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [33 x i8] c"found mac file 'bt.mac', mac %s\0A\00"
@.str.1 = [28 x i8] c"generate mac file 'bt.mac'\0A\00"
define i32 @sw_get_btaddrstr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [20 x i8]
store i8* %0, i8** %2
%5 = bitcast [20 x i8]* %4 to i8*
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = call i32 @sw_read_mac_from_file(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %1
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %2
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @strncpy(i8* %13, i8* %14, i32 %16)
br label %33
18: ; preds = %1
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%20 = call i32 @sw_random_btmac(i8* %19)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %2
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @strncpy(i8* %25, i8* %26, i32 %28)
br label %30
30: ; preds = %23, %18
%31 = load i8*, i8** %2
%32 = call i32 @sw_write_mac_file(i8* %31)
br label %33
33: ; preds = %30, %10
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"found mac file 'bt.mac', mac %s\0A\00"
@str = [27 x i8] c"generate mac file 'bt.mac'\00"
define i32 @sw_get_btaddrstr(i8* %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = call i32 @sw_read_mac_from_file(i8* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %3)
%8 = call i32 @strlen(i8* %3)
%9 = call i32 @strncpy(i8* %0, i8* %3, i32 %8)
br label %19
10: ; preds = %1
%11 = call i32 @sw_random_btmac(i8* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%15 = call i32 @strlen(i8* %3)
%16 = call i32 @strncpy(i8* %0, i8* %3, i32 %15)
br label %17
17: ; preds = %13, %10
%18 = call i32 @sw_write_mac_file(i8* %0)
br label %19
19: ; preds = %17, %6
ret i32 0
}