#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 *);
scalar_t__ suart_io(int, char *, char *, int, int, int *, int);
int discover(int fd) {
  char ib, ob;
  int rxed = 0;
  while (1) {
    if (suart_io(fd, &ob, &ib, 0, 1, &rxed, 100) == 0) {
      if (rxed == 1)
        if (ib == 'B')
          printf("Detect B!\n");
    };
    ob = 255;
    if (suart_io(fd, &ob, &ib, 1, 1, &rxed, 300) == 0) {
      if (rxed == 1)
        if (ib == 0x55) {
          printf("Found!\n");
          return 1;
        }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<discover>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x6(%rbp),%rsi
lea    -0x5(%rbp),%rdx
xor    %ecx,%ecx
mov    $0x1,%r8d
lea    -0xc(%rbp),%r9
movl   $0x64,(%rsp)
call   1040 <suart_io@plt>
cmp    $0x0,%rax
jne    118c <discover+0x6c>
cmpl   $0x1,-0xc(%rbp)
jne    1187 <discover+0x67>
movsbl -0x5(%rbp),%eax
cmp    $0x42,%eax
jne    1182 <discover+0x62>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
jmp    1187 <discover+0x67>
jmp    118c <discover+0x6c>
movb   $0xff,-0x6(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x6(%rbp),%rsi
lea    -0x5(%rbp),%rdx
mov    $0x1,%r8d
lea    -0xc(%rbp),%r9
mov    %r8d,%ecx
movl   $0x12c,(%rsp)
call   1040 <suart_io@plt>
cmp    $0x0,%rax
jne    11f6 <discover+0xd6>
cmpl   $0x1,-0xc(%rbp)
jne    11f1 <discover+0xd1>
movsbl -0x5(%rbp),%eax
cmp    $0x55,%eax
jne    11ec <discover+0xcc>
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    11f1 <discover+0xd1>
jmp    11f6 <discover+0xd6>
jmp    1132 <discover+0x12>

x86 assembly (clang, -O2):
<discover>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x0,0xc(%rsp)
lea    0xb(%rsp),%r14
lea    0xa(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0xeba(%rip),%r13
nopl   (%rax)
movl   $0x64,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %ecx,%ecx
mov    $0x1,%r8d
mov    %r12,%r9
call   1040 <suart_io@plt>
test   %rax,%rax
jne    118a <discover+0x6a>
cmpl   $0x1,0xc(%rsp)
jne    118a <discover+0x6a>
cmpb   $0x42,0xa(%rsp)
jne    118a <discover+0x6a>
mov    %r13,%rdi
call   1030 <puts@plt>
movb   $0xff,0xb(%rsp)
movl   $0x12c,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    $0x1,%ecx
mov    $0x1,%r8d
mov    %r12,%r9
call   1040 <suart_io@plt>
test   %rax,%rax
jne    1150 <discover+0x30>
cmpl   $0x1,0xc(%rsp)
jne    1150 <discover+0x30>
cmpb   $0x55,0xa(%rsp)
jne    1150 <discover+0x30>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Detect B!\0A\00"
@.str.1 = [8 x i8] c"Found!\0A\00"
define i32 @discover(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
br label %6
6: ; preds = %1, %36
%7 = load i32, i32* %2
%8 = call i64 @suart_io(i32 %7, i8* %4, i8* %3, i32 0, i32 1, i32* %5, i32 100)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 66
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
br label %20
20: ; preds = %19, %10
br label %21
21: ; preds = %20, %6
store i8 -1, i8* %4
%22 = load i32, i32* %2
%23 = call i64 @suart_io(i32 %22, i8* %4, i8* %3, i32 1, i32 1, i32* %5, i32 300)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i8, i8* %3
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 85
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
ret i32 1
34: ; preds = %28
br label %35
35: ; preds = %34, %25
br label %36
36: ; preds = %35, %21
br label %6
}

LLVM IR (-O2):
@str = [7 x i8] c"Found!\00"
@str.2 = [10 x i8] c"Detect B!\00"
define i32 @discover(i32 %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %6
6: ; preds = %17, %1
%7 = call i64 @suart_io(i32 %0, i8* %3, i8* %2, i32 0, i32 1, i32* %4, i32 100)
%8 = icmp eq i64 %7, 0
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
%11 = select i1 %8, i1 %10, i1 false
%12 = load i8, i8* %2
%13 = icmp eq i8 %12, 66
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %6
store i8 -1, i8* %3
%18 = call i64 @suart_io(i32 %0, i8* %3, i8* %2, i32 1, i32 1, i32* %4, i32 300)
%19 = icmp eq i64 %18, 0
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 1
%22 = select i1 %19, i1 %21, i1 false
%23 = load i8, i8* %2
%24 = icmp eq i8 %23, 85
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %26, label %6
26: ; preds = %17
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
ret i32 1
}