#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 /*<<< orphan*/ Delay(int);
int TwMasterTransact(int, int /*<<< orphan*/, int /*<<< orphan*/,
                     unsigned char *, int, int /*<<< orphan*/);
int NvMemWaitReady(void) {
  unsigned char poll;
  int cnt = 20;
  while (--cnt && TwMasterTransact(0x57, 0, 0, &poll, 1, 0) == -1) {
    Delay(1);
  }
  return cnt ? 0 : -1;
}


x86 assembly (clang, -O0):
<NvMemWaitReady>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x14,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x9(%rbp)
je     116c <NvMemWaitReady+0x4c>
mov    $0x57,%edi
xor    %r9d,%r9d
lea    -0x1(%rbp),%rcx
mov    $0x1,%r8d
mov    %r9d,%esi
mov    %r9d,%edx
call   1040 <TwMasterTransact@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    117c <NvMemWaitReady+0x5c>
jmp    118b <NvMemWaitReady+0x6b>
mov    $0x1,%edi
call   1030 <Delay@plt>
jmp    112f <NvMemWaitReady+0xf>
mov    -0x8(%rbp),%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NvMemWaitReady>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffed,%ebx
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x57,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x1,%r8d
xor    %r9d,%r9d
call   1040 <TwMasterTransact@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    116f <NvMemWaitReady+0x4f>
mov    $0x1,%edi
call   1030 <Delay@plt>
inc    %ebx
jne    1140 <NvMemWaitReady+0x20>
xor    %eax,%eax
cmp    $0xffffffff,%ebp
sete   %al
neg    %eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @NvMemWaitReady() {
%1 = alloca i8
%2 = alloca i32
store i32 20, i32* %2
br label %3
3: ; preds = %12, %0
%4 = load i32, i32* %2
%5 = add nsw i32 %4, -1
store i32 %5, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = call i32 @TwMasterTransact(i32 87, i32 0, i32 0, i8* %1, i32 1, i32 0)
%9 = icmp eq i32 %8, -1
br label %10
10: ; preds = %7, %3
%11 = phi i1 [ false, %3 ], [ %9, %7 ]
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = call i32 @Delay(i32 1)
br label %3
14: ; preds = %10
%15 = load i32, i32* %2
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 0, i32 -1
ret i32 %18
}

LLVM IR (-O2):
define i32 @NvMemWaitReady() {
%1 = alloca i8
br label %2
2: ; preds = %0, %6
%3 = phi i32 [ 19, %0 ], [ %8, %6 ]
%4 = call i32 @TwMasterTransact(i32 87, i32 0, i32 0, i8* %1, i32 1, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = call i32 @Delay(i32 1)
%8 = add nsw i32 %3, -1
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %2
10: ; preds = %6, %2
%11 = sext i1 %5 to i32
ret i32 %11
}