#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 */
typedef int uint8_t;

/* Variables and functions */
scalar_t__ bmp_ReadInt(int, int *, int, int);
int /*<<< orphan*/ usleep(int);
int WaitForConversion(int fd) {
  uint8_t rValues[3];
  int counter = 0;
  do {
    usleep((2) * 1000);
    if (bmp_ReadInt(fd, rValues, 0xF4, 1) != 0)
      return -1;
    counter++;
  } while (((rValues[0] & 0x20) != 0) && counter < 20);
  return 0;
}


x86 assembly (clang, -O0):
<WaitForConversion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x7d0,%edi
call   1040 <usleep@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0xf4,%edx
mov    $0x1,%ecx
call   1030 <bmp_ReadInt@plt>
cmp    $0x0,%rax
je     1168 <WaitForConversion+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <WaitForConversion+0x81>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
and    $0x20,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     118f <WaitForConversion+0x6f>
cmpl   $0x14,-0x18(%rbp)
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1132 <WaitForConversion+0x12>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WaitForConversion>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
xor    %ebx,%ebx
lea    0x4(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x7d0,%edi
call   1040 <usleep@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xf4,%edx
mov    $0x1,%ecx
call   1030 <bmp_ReadInt@plt>
test   %rax,%rax
jne    1178 <WaitForConversion+0x58>
xor    %eax,%eax
testb  $0x20,0x4(%rsp)
je     117d <WaitForConversion+0x5d>
lea    0x1(%rbx),%ecx
cmp    $0x13,%ebx
mov    %ecx,%ebx
jb     1140 <WaitForConversion+0x20>
jmp    117d <WaitForConversion+0x5d>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @WaitForConversion(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [3 x i32]
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
br label %6
6: ; preds = %24, %1
%7 = call i32 @usleep(i32 2000)
%8 = load i32, i32* %3
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%10 = call i64 @bmp_ReadInt(i32 %8, i32* %9, i32 244, i32 1)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %6
store i32 -1, i32* %2
br label %27
13: ; preds = %6
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
br label %16
16: ; preds = %13
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%18 = load i32, i32* %17
%19 = and i32 %18, 32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 20
br label %24
24: ; preds = %21, %16
%25 = phi i1 [ false, %16 ], [ %23, %21 ]
br i1 %25, label %6, label %26
26: ; preds = %24
store i32 0, i32* %2
br label %27
27: ; preds = %26, %12
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
define i32 @WaitForConversion(i32 %0) {
%2 = alloca [3 x i32]
%3 = bitcast [3 x i32]* %2 to i8*
%4 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
br label %5
5: ; preds = %10, %1
%6 = phi i32 [ 0, %1 ], [ %11, %10 ]
%7 = call i32 @usleep(i32 2000)
%8 = call i64 @bmp_ReadInt(i32 %0, i32* %4, i32 244, i32 1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %5
%11 = add nuw nsw i32 %6, 1
%12 = load i32, i32* %4
%13 = and i32 %12, 32
%14 = icmp ne i32 %13, 0
%15 = icmp ult i32 %6, 19
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %5, label %17
17: ; preds = %10, %5
%18 = phi i32 [ -1, %5 ], [ 0, %10 ]
ret i32 %18
}