#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 dvl_waitByte(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int dvl_waitSync(int fd) {
  int syncLen = 0;
  while (syncLen < 2000) {
    if (dvl_waitByte(fd) == 0x7D) {
      if (dvl_waitByte(fd) == 0x00)
        break;
    }
    syncLen++;
  }
  if (syncLen >= 2000) {
    fprintf(stderr, "UNABLE TO SYCHRONIZE WITH DVL!\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<dvl_waitSync>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x7d0,-0xc(%rbp)
jge    1179 <dvl_waitSync+0x59>
mov    -0x8(%rbp),%edi
call   1040 <dvl_waitByte@plt>
cmp    $0x7d,%eax
jne    116b <dvl_waitSync+0x4b>
mov    -0x8(%rbp),%edi
call   1040 <dvl_waitByte@plt>
cmp    $0x0,%eax
jne    1166 <dvl_waitSync+0x46>
jmp    1179 <dvl_waitSync+0x59>
jmp    116b <dvl_waitSync+0x4b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1132 <dvl_waitSync+0x12>
cmpl   $0x7d0,-0xc(%rbp)
jl     11a7 <dvl_waitSync+0x87>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <dvl_waitSync+0x8e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dvl_waitSync>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x7d0,%ebp
jmp    1135 <dvl_waitSync+0x15>
nopl   0x0(%rax)
add    $0xffffffff,%ebp
je     1150 <dvl_waitSync+0x30>
mov    %ebx,%edi
call   1040 <dvl_waitByte@plt>
cmp    $0x7d,%eax
jne    1130 <dvl_waitSync+0x10>
mov    %ebx,%edi
call   1040 <dvl_waitByte@plt>
test   %eax,%eax
jne    1130 <dvl_waitSync+0x10>
xor    %eax,%eax
jmp    116a <dvl_waitSync+0x4a>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"UNABLE TO SYCHRONIZE WITH DVL!\0A\00"
define i32 @dvl_waitSync(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %18, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 2000
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load i32, i32* %3
%10 = call i32 @dvl_waitByte(i32 %9)
%11 = icmp eq i32 %10, 125
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = load i32, i32* %3
%14 = call i32 @dvl_waitByte(i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
br label %21
17: ; preds = %12
br label %18
18: ; preds = %17, %8
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %5
21: ; preds = %16, %5
%22 = load i32, i32* %4
%23 = icmp sge i32 %22, 2000
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %28
27: ; preds = %21
store i32 0, i32* %2
br label %28
28: ; preds = %27, %24
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"UNABLE TO SYCHRONIZE WITH DVL!\0A\00"
define i32 @dvl_waitSync(i32 %0) {
br label %2
2: ; preds = %1, %9
%3 = phi i32 [ 0, %1 ], [ %10, %9 ]
%4 = tail call i32 @dvl_waitByte(i32 %0)
%5 = icmp eq i32 %4, 125
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @dvl_waitByte(i32 %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %6, %2
%10 = add nuw nsw i32 %3, 1
%11 = icmp eq i32 %10, 2000
br i1 %11, label %12, label %2
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %6, %12
%16 = phi i32 [ -1, %12 ], [ 0, %6 ]
ret i32 %16
}