#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 WaitCDSPBitRelease(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 (0 == (bData & bBit)) {
      sdRet = ((signed long)0);
      break;
    }
    McSrv_Sleep(dCycleTime);
    dCycles++;
  }
  return sdRet;
}


x86 assembly (clang, -O0):
<WaitCDSPBitRelease>:
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    11dc <WaitCDSPBitRelease+0xac>
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),%ecx
movzbl -0x5(%rbp),%eax
and    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11c2 <WaitCDSPBitRelease+0x92>
movq   $0x0,-0x30(%rbp)
jmp    11dc <WaitCDSPBitRelease+0xac>
mov    -0x10(%rbp),%rdi
call   1050 <McSrv_Sleep@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116e <WaitCDSPBitRelease+0x3e>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WaitCDSPBitRelease>:
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     11a3 <WaitCDSPBitRelease+0x73>
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>
test   %r12b,%al
je     11a0 <WaitCDSPBitRelease+0x70>
mov    %r15,%rdi
call   1050 <McSrv_Sleep@plt>
add    $0xffffffffffffffff,%rbx
jne    1170 <WaitCDSPBitRelease+0x40>
jmp    11a3 <WaitCDSPBitRelease+0x73>
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 @WaitCDSPBitRelease(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 = %36, %5
%20 = load i64, i64* %12
%21 = load i64, i64* %10
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %41
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 = icmp eq i32 0, %33
br i1 %34, label %35, label %36
35: ; preds = %23
store i64 0, i64* %13
br label %41
36: ; preds = %23
%37 = load i64, i64* %9
%38 = call i32 @McSrv_Sleep(i64 %37)
%39 = load i64, i64* %12
%40 = add i64 %39, 1
store i64 %40, i64* %12
br label %19
41: ; preds = %35, %19
%42 = load i64, i64* %13
ret i64 %42
}

LLVM IR (-O2):
define i64 @WaitCDSPBitRelease(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, 0
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
}