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


x86 assembly (clang, -O0):
<WaitCDSPBitSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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
movb   $0x30,-0x32(%rbp)
mov    -0x4(%rbp),%ax
mov    %al,-0x31(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11de <WaitCDSPBitSet+0xae>
mov    -0x1(%rbp),%al
lea    -0x32(%rbp),%rsi
mov    $0x2,%edx
movzbl %al,%edi
call   1030 <McSrv_WriteI2C@plt>
mov    $0x19,%esi
movzbl -0x1(%rbp),%edi
call   1040 <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    11c4 <WaitCDSPBitSet+0x94>
movq   $0x0,-0x30(%rbp)
jmp    11de <WaitCDSPBitSet+0xae>
mov    -0x10(%rbp),%rdi
call   1050 <McSrv_Sleep@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116e <WaitCDSPBitSet+0x3e>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WaitCDSPBitSet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0x30,0x6(%rsp)
mov    %sil,0x7(%rsp)
mov    $0xfffffffffffffffe,%r14
test   %r8,%r8
je     11a5 <WaitCDSPBitSet+0x75>
mov    %r8,%rbx
mov    %rcx,%r15
mov    %edx,%r12d
movzbl %dil,%ebp
lea    0x6(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x2,%edx
call   1030 <McSrv_WriteI2C@plt>
mov    %ebp,%edi
mov    $0x19,%esi
call   1040 <McSrv_ReadI2C@plt>
not    %al
test   %al,%r12b
je     11a2 <WaitCDSPBitSet+0x72>
mov    %r15,%rdi
call   1050 <McSrv_Sleep@plt>
add    $0xffffffffffffffff,%rbx
jne    1170 <WaitCDSPBitSet+0x40>
jmp    11a5 <WaitCDSPBitSet+0x75>
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 @WaitCDSPBitSet(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
%14 = alloca [2 x i8]
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
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 0
store i8 48, i8* %15
%16 = load i16, i16* %7
%17 = trunc i16 %16 to i8
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 1
store i8 %17, i8* %18
br label %19
19: ; preds = %38, %5
%20 = load i64, i64* %12
%21 = load i64, i64* %10
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %43
23: ; preds = %19
%24 = load i8, i8* %6
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 0
%26 = call i32 @McSrv_WriteI2C(i8 zeroext %24, i8* %25, i32 2)
%27 = load i8, i8* %6
%28 = call zeroext i8 @McSrv_ReadI2C(i8 zeroext %27, i32 25)
store i8 %28, i8* %11
%29 = load i8, i8* %11
%30 = zext i8 %29 to i32
%31 = load i8, i8* %8
%32 = zext i8 %31 to i32
%33 = and i32 %30, %32
%34 = load i8, i8* %8
%35 = zext i8 %34 to i32
%36 = icmp eq i32 %33, %35
br i1 %36, label %37, label %38
37: ; preds = %23
store i64 0, i64* %13
br label %43
38: ; preds = %23
%39 = load i64, i64* %9
%40 = call i32 @McSrv_Sleep(i64 %39)
%41 = load i64, i64* %12
%42 = add i64 %41, 1
store i64 %42, i64* %12
br label %19
43: ; preds = %37, %19
%44 = load i64, i64* %13
ret i64 %44
}

LLVM IR (-O2):
define i64 @WaitCDSPBitSet(i8 zeroext %0, i16 zeroext %1, i8 zeroext %2, i64 %3, i64 %4) {
%6 = alloca [2 x i8]
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 48, i8* %7
%8 = trunc i16 %1 to i8
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 %8, i8* %9
%10 = icmp eq i64 %4, 0
br i1 %10, label %21, label %11
11: ; preds = %5, %17
%12 = phi i64 [ %19, %17 ], [ 0, %5 ]
%13 = call i32 @McSrv_WriteI2C(i8 zeroext %0, i8* %7, i32 2)
%14 = call zeroext i8 @McSrv_ReadI2C(i8 zeroext %0, i32 25)
%15 = and i8 %14, %2
%16 = icmp eq i8 %15, %2
br i1 %16, label %21, label %17
17: ; preds = %11
%18 = call i32 @McSrv_Sleep(i64 %3)
%19 = add nuw i64 %12, 1
%20 = icmp eq i64 %19, %4
br i1 %20, label %21, label %11
21: ; preds = %17, %11, %5
%22 = phi i64 [ -2, %5 ], [ 0, %11 ], [ -2, %17 ]
ret i64 %22
}