#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 */
unsigned char McSrv_ReadI2C(unsigned char, unsigned short);
int /*<<< orphan*/ McSrv_Sleep(unsigned long);
signed long WaitBitSet(unsigned char bSlaveAddr, unsigned short wRegAddr,
                       unsigned char bBit, unsigned long dCycleTime,
                       unsigned long dTimeOut) {
  unsigned char bData;
  unsigned long dCycles;
  signed long sdRet;
  dCycles = 0;
  sdRet = (-2);
  while (dCycles < dTimeOut) {
    bData = McSrv_ReadI2C(bSlaveAddr, wRegAddr);
    if ((bData & bBit) == bBit) {
      sdRet = ((signed long)0);
      break;
    }
    McSrv_Sleep(dCycleTime);
    dCycles++;
  }
  return sdRet;
}


x86 assembly (clang, -O0):
<WaitBitSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %si,%dx
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %dx,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %rcx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0xfffffffffffffffe,-0x30(%rbp)
ff
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11b0 <WaitBitSet+0x90>
mov    -0x1(%rbp),%al
movzbl %al,%edi
movzwl -0x4(%rbp),%esi
call   1030 <McSrv_ReadI2C@plt>
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
movzbl -0x5(%rbp),%ecx
and    %ecx,%eax
movzbl -0x5(%rbp),%ecx
cmp    %ecx,%eax
jne    1196 <WaitBitSet+0x76>
movq   $0x0,-0x30(%rbp)
jmp    11b0 <WaitBitSet+0x90>
mov    -0x10(%rbp),%rdi
call   1040 <McSrv_Sleep@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1153 <WaitBitSet+0x33>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WaitBitSet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xfffffffffffffffe,%r14
test   %r8,%r8
je     1174 <WaitBitSet+0x54>
mov    %r8,%rbx
mov    %rcx,%r15
mov    %edx,%r12d
movzbl %dil,%r13d
movzwl %si,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %ebp,%esi
call   1030 <McSrv_ReadI2C@plt>
not    %al
test   %al,%r12b
je     1171 <WaitBitSet+0x51>
mov    %r15,%rdi
call   1040 <McSrv_Sleep@plt>
add    $0xffffffffffffffff,%rbx
jne    1150 <WaitBitSet+0x30>
jmp    1174 <WaitBitSet+0x54>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @WaitBitSet(i8 zeroext %0, i16 zeroext %1, i8 zeroext %2, i64 %3, i64 %4) {
%6 = alloca i8
%7 = alloca i16
%8 = alloca i8
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8
%12 = alloca i64
%13 = alloca i64
store i8 %0, i8* %6
store i16 %1, i16* %7
store i8 %2, i8* %8
store i64 %3, i64* %9
store i64 %4, i64* %10
store i64 0, i64* %12
store i64 -2, i64* %13
br label %14
14: ; preds = %31, %5
%15 = load i64, i64* %12
%16 = load i64, i64* %10
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load i8, i8* %6
%20 = load i16, i16* %7
%21 = call zeroext i8 @McSrv_ReadI2C(i8 zeroext %19, i16 zeroext %20)
store i8 %21, i8* %11
%22 = load i8, i8* %11
%23 = zext i8 %22 to i32
%24 = load i8, i8* %8
%25 = zext i8 %24 to i32
%26 = and i32 %23, %25
%27 = load i8, i8* %8
%28 = zext i8 %27 to i32
%29 = icmp eq i32 %26, %28
br i1 %29, label %30, label %31
30: ; preds = %18
store i64 0, i64* %13
br label %36
31: ; preds = %18
%32 = load i64, i64* %9
%33 = call i32 @McSrv_Sleep(i64 %32)
%34 = load i64, i64* %12
%35 = add i64 %34, 1
store i64 %35, i64* %12
br label %14
36: ; preds = %30, %14
%37 = load i64, i64* %13
ret i64 %37
}

LLVM IR (-O2):
define i64 @WaitBitSet(i8 zeroext %0, i16 zeroext %1, i8 zeroext %2, i64 %3, i64 %4) {
%6 = icmp eq i64 %4, 0
br i1 %6, label %16, label %7
7: ; preds = %5, %12
%8 = phi i64 [ %14, %12 ], [ 0, %5 ]
%9 = tail call zeroext i8 @McSrv_ReadI2C(i8 zeroext %0, i16 zeroext %1)
%10 = and i8 %9, %2
%11 = icmp eq i8 %10, %2
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = tail call i32 @McSrv_Sleep(i64 %3)
%14 = add nuw i64 %8, 1
%15 = icmp eq i64 %14, %4
br i1 %15, label %16, label %7
16: ; preds = %12, %7, %5
%17 = phi i64 [ -2, %5 ], [ 0, %7 ], [ -2, %12 ]
ret i64 %17
}