#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 imu_waitByte(int);
int /*<<< orphan*/ printf(char *);
void imu_waitSync(int fd) {
  int fs = 0;
  int syncLen = 0;
  while (fs != 4) {
    if (imu_waitByte(fd) == 0xFF)
      fs++;
    else
      fs = 0;
    syncLen++;
  }
  if (syncLen > 4)
    printf("Warning! IMU sync sequence took longer than 4 bytes!!\n");
}


x86 assembly (clang, -O0):
<imu_waitSync>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1179 <imu_waitSync+0x59>
mov    -0x4(%rbp),%edi
call   1030 <imu_waitByte@plt>
cmp    $0xff,%eax
jne    1164 <imu_waitSync+0x44>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116b <imu_waitSync+0x4b>
movl   $0x0,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <imu_waitSync+0x19>
cmpl   $0x4,-0xc(%rbp)
jle    118f <imu_waitSync+0x6f>
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imu_waitSync>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
xor    %r14d,%r14d
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%edi
call   1040 <imu_waitByte@plt>
add    $0x1,%ebx
cmp    $0xff,%eax
cmovne %r14d,%ebx
add    $0x1,%ebp
cmp    $0x4,%ebx
jne    1140 <imu_waitSync+0x20>
cmp    $0x4,%ebp
jb     1177 <imu_waitSync+0x57>
lea    0xe98(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"Warning! IMU sync sequence took longer than 4 bytes!!\0A\00"
define void @imu_waitSync(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %16, %1
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 4
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i32 @imu_waitByte(i32 %9)
%11 = icmp eq i32 %10, 255
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %16
15: ; preds = %8
store i32 0, i32* %3
br label %16
16: ; preds = %15, %12
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %5
19: ; preds = %5
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 4
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
@str = [54 x i8] c"Warning! IMU sync sequence took longer than 4 bytes!!\00"
define void @imu_waitSync(i32 %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 0, %1 ], [ %8, %2 ]
%4 = phi i32 [ 0, %1 ], [ %9, %2 ]
%5 = tail call i32 @imu_waitByte(i32 %0)
%6 = icmp eq i32 %5, 255
%7 = add nsw i32 %4, 1
%8 = add nuw nsw i32 %3, 1
%9 = select i1 %6, i32 %7, i32 0
%10 = icmp eq i32 %9, 4
br i1 %10, label %11, label %2
11: ; preds = %2
%12 = icmp ugt i32 %3, 3
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %11
ret void
}