#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*/ bt_cmd(char *);
int /*<<< orphan*/ bt_cmd_mode(char);
int /*<<< orphan*/ bt_error(char *);
int /*<<< orphan*/ bt_repeat_cmd(char *, char *, int);
scalar_t__ bt_rx();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
void bt_init_local(void) {
  printf("Config BT \n");
  if (!bt_cmd_mode('$')) {
    bt_error("Config FAILED");
  }
  bt_cmd("SF,1");
  bt_cmd("SM,1");
  bt_cmd("SA,4");
  bt_cmd("SO,%");
  bt_cmd("ST,255");
  bt_cmd("R,1");
  printf("DONE\n");
  sleep(1);
  if (!bt_cmd_mode('$')) {
    bt_error("FAILED to open");
  }
  printf("Inquiry \n");
  bt_repeat_cmd("I", "Found", 5);
  printf("Found\n");
  while (bt_rx() == 0)
    ;
  printf("Pairing \n");
  bt_cmd("SR,I");
  bt_repeat_cmd("C", "%CONNECT", 8);
  printf("DONE\n");
  sleep(1);
  printf("RemoteCnf \n");
  if (!bt_cmd_mode('$')) {
    bt_error("RemoteCnf Failed");
  }
  bt_cmd("ST,255");
  bt_cmd("R,1");
  printf("DONE\n");
  sleep(1);
}


x86 assembly (clang, -O0):
<bt_init_local>:
push   %rbp
mov    %rsp,%rbp
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
mov    $0x24,%edi
call   1050 <bt_cmd_mode@plt>
cmp    $0x0,%eax
jne    119f <bt_init_local+0x2f>
lea    0xe72(%rip),%rdi
call   1060 <bt_error@plt>
lea    0xe74(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xe6d(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xe66(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xe5f(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xe58(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xe53(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    $0x24,%edi
call   1050 <bt_cmd_mode@plt>
cmp    $0x0,%eax
jne    121c <bt_init_local+0xac>
lea    0xe28(%rip),%rdi
call   1060 <bt_error@plt>
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe43(%rip),%rdi
lea    0xe22(%rip),%rsi
mov    $0x5,%edx
call   1030 <bt_repeat_cmd@plt>
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <bt_rx@plt>
cmp    $0x0,%rax
jne    1262 <bt_init_local+0xf2>
jmp    124c <bt_init_local+0xdc>
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
lea    0xdfa(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xdf3(%rip),%rdi
lea    0xdee(%rip),%rsi
mov    $0x8,%edx
call   1030 <bt_repeat_cmd@plt>
lea    0xda0(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0xdd0(%rip),%rdi
call   1040 <printf@plt>
mov    $0x24,%edi
call   1050 <bt_cmd_mode@plt>
cmp    $0x0,%eax
jne    12d3 <bt_init_local+0x163>
lea    0xdbd(%rip),%rdi
call   1060 <bt_error@plt>
lea    0xd54(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xd4f(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xd47(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<bt_init_local>:
push   %rbx
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x24,%edi
call   1050 <bt_cmd_mode@plt>
test   %eax,%eax
jne    1197 <bt_init_local+0x27>
lea    0xe6e(%rip),%rdi
call   1060 <bt_error@plt>
lea    0xe70(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xe69(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xe62(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xe5b(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xe54(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xe4f(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    $0x24,%edi
call   1050 <bt_cmd_mode@plt>
test   %eax,%eax
jne    120f <bt_init_local+0x9f>
lea    0xe23(%rip),%rdi
call   1060 <bt_error@plt>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1d(%rip),%rdi
lea    0xe48(%rip),%rbx
mov    %rbx,%rsi
mov    $0x5,%edx
call   1040 <bt_repeat_cmd@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1080 <bt_rx@plt>
test   %rax,%rax
je     1240 <bt_init_local+0xd0>
lea    0xe24(%rip),%rdi
call   1030 <puts@plt>
lea    0xddd(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xdd6(%rip),%rdi
lea    0xdd1(%rip),%rsi
mov    $0x8,%edx
call   1040 <bt_repeat_cmd@plt>
lea    0xe08(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0xde7(%rip),%rdi
call   1030 <puts@plt>
mov    $0x24,%edi
call   1050 <bt_cmd_mode@plt>
test   %eax,%eax
jne    12b8 <bt_init_local+0x148>
lea    0xd99(%rip),%rdi
call   1060 <bt_error@plt>
lea    0xd63(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xd5e(%rip),%rdi
call   1070 <bt_cmd@plt>
lea    0xdb4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
pop    %rbx
jmp    1090 <sleep@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"Config BT \0A\00"
@.str.1 = [14 x i8] c"Config FAILED\00"
@.str.2 = [5 x i8] c"SF,1\00"
@.str.3 = [5 x i8] c"SM,1\00"
@.str.4 = [5 x i8] c"SA,4\00"
@.str.5 = [5 x i8] c"SO,%\00"
@.str.6 = [7 x i8] c"ST,255\00"
@.str.7 = [4 x i8] c"R,1\00"
@.str.8 = [6 x i8] c"DONE\0A\00"
@.str.9 = [15 x i8] c"FAILED to open\00"
@.str.10 = [10 x i8] c"Inquiry \0A\00"
@.str.11 = [2 x i8] c"I\00"
@.str.12 = [6 x i8] c"Found\00"
@.str.13 = [7 x i8] c"Found\0A\00"
@.str.14 = [10 x i8] c"Pairing \0A\00"
@.str.15 = [5 x i8] c"SR,I\00"
@.str.16 = [2 x i8] c"C\00"
@.str.17 = [9 x i8] c"%CONNECT\00"
@.str.18 = [12 x i8] c"RemoteCnf \0A\00"
@.str.19 = [17 x i8] c"RemoteCnf Failed\00"
define void @bt_init_local() {
%1 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%2 = call i32 @bt_cmd_mode(i8 signext 36)
%3 = icmp ne i32 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = call i32 @bt_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = call i32 @bt_cmd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @bt_cmd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @bt_cmd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 @bt_cmd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 @bt_cmd(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%12 = call i32 @bt_cmd(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%14 = call i32 @sleep(i32 1)
%15 = call i32 @bt_cmd_mode(i8 signext 36)
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %6
%18 = call i32 @bt_error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %19
19: ; preds = %17, %6
%20 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
%21 = call i32 @bt_repeat_cmd(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i32 5)
%22 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
br label %23
23: ; preds = %26, %19
%24 = call i64 (...) @bt_rx()
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
br label %23
27: ; preds = %23
%28 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0))
%29 = call i32 @bt_cmd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%30 = call i32 @bt_repeat_cmd(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.17, i64 0, i64 0), i32 8)
%31 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%32 = call i32 @sleep(i32 1)
%33 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0))
%34 = call i32 @bt_cmd_mode(i8 signext 36)
%35 = icmp ne i32 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %27
%37 = call i32 @bt_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.19, i64 0, i64 0))
br label %38
38: ; preds = %36, %27
%39 = call i32 @bt_cmd(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 @bt_cmd(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%41 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%42 = call i32 @sleep(i32 1)
ret void
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"Config FAILED\00"
@.str.2 = [5 x i8] c"SF,1\00"
@.str.3 = [5 x i8] c"SM,1\00"
@.str.4 = [5 x i8] c"SA,4\00"
@.str.5 = [5 x i8] c"SO,%\00"
@.str.6 = [7 x i8] c"ST,255\00"
@.str.7 = [4 x i8] c"R,1\00"
@.str.9 = [15 x i8] c"FAILED to open\00"
@.str.11 = [2 x i8] c"I\00"
@.str.15 = [5 x i8] c"SR,I\00"
@.str.16 = [2 x i8] c"C\00"
@.str.17 = [9 x i8] c"%CONNECT\00"
@.str.19 = [17 x i8] c"RemoteCnf Failed\00"
@str = [11 x i8] c"Config BT \00"
@str.21 = [9 x i8] c"Inquiry \00"
@str.22 = [6 x i8] c"Found\00"
@str.23 = [9 x i8] c"Pairing \00"
@str.25 = [11 x i8] c"RemoteCnf \00"
@str.26 = [5 x i8] c"DONE\00"
define void @bt_init_local() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @bt_cmd_mode(i8 signext 36)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @bt_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = tail call i32 @bt_cmd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @bt_cmd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 @bt_cmd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i32 @bt_cmd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%11 = tail call i32 @bt_cmd(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%12 = tail call i32 @bt_cmd(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.26, i64 0, i64 0))
%14 = tail call i32 @sleep(i32 1)
%15 = tail call i32 @bt_cmd_mode(i8 signext 36)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %6
%18 = tail call i32 @bt_error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %19
19: ; preds = %17, %6
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.21, i64 0, i64 0))
%21 = tail call i32 @bt_repeat_cmd(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.22, i64 0, i64 0), i32 5)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.22, i64 0, i64 0))
br label %23
23: ; preds = %23, %19
%24 = tail call i64 (...) @bt_rx()
%25 = icmp eq i64 %24, 0
br i1 %25, label %23, label %26
26: ; preds = %23
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.23, i64 0, i64 0))
%28 = tail call i32 @bt_cmd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%29 = tail call i32 @bt_repeat_cmd(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.17, i64 0, i64 0), i32 8)
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.26, i64 0, i64 0))
%31 = tail call i32 @sleep(i32 1)
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.25, i64 0, i64 0))
%33 = tail call i32 @bt_cmd_mode(i8 signext 36)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = tail call i32 @bt_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.19, i64 0, i64 0))
br label %37
37: ; preds = %35, %26
%38 = tail call i32 @bt_cmd(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%39 = tail call i32 @bt_cmd(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.26, i64 0, i64 0))
%41 = tail call i32 @sleep(i32 1)
ret void
}