#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*/ PEX_8111Read(void *, int, int *);
int /*<<< orphan*/ printf(char *);
int EE_WaitIdle(void *info) {
  int eeCtl, ii;
  for (ii = 0; ii < 1000; ii++) {
    PEX_8111Read(info, 0x1004, &eeCtl);
    if ((eeCtl & (1 << 19)) == 0)
      return (eeCtl);
  }
  printf("ERROR: EEPROM Busy timeout!\n");
  return (1 << 19);
}


x86 assembly (clang, -O0):
<EE_WaitIdle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3e8,-0x18(%rbp)
jge    1181 <EE_WaitIdle+0x61>
mov    -0x10(%rbp),%rdi
mov    $0x1004,%esi
lea    -0x14(%rbp),%rdx
call   1040 <PEX_8111Read@plt>
mov    -0x14(%rbp),%eax
and    $0x80000,%eax
cmp    $0x0,%eax
jne    116e <EE_WaitIdle+0x4e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <EE_WaitIdle+0x74>
jmp    1173 <EE_WaitIdle+0x53>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1133 <EE_WaitIdle+0x13>
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
movl   $0x80000,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EE_WaitIdle>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x3e8,%ebp
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x1004,%esi
mov    %r14,%rdx
call   1040 <PEX_8111Read@plt>
mov    0xc(%rsp),%eax
test   $0x80000,%eax
je     1171 <EE_WaitIdle+0x51>
add    $0xffffffff,%ebp
jne    1140 <EE_WaitIdle+0x20>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    $0x80000,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"ERROR: EEPROM Busy timeout!\0A\00"
define i32 @EE_WaitIdle(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
br label %6
6: ; preds = %18, %1
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 1000
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = load i8*, i8** %3
%11 = call i32 @PEX_8111Read(i8* %10, i32 4100, i32* %4)
%12 = load i32, i32* %4
%13 = and i32 %12, 524288
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = load i32, i32* %4
store i32 %16, i32* %2
br label %23
17: ; preds = %9
br label %18
18: ; preds = %17
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %6
21: ; preds = %6
%22 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 524288, i32* %2
br label %23
23: ; preds = %21, %15
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@str = [28 x i8] c"ERROR: EEPROM Busy timeout!\00"
define i32 @EE_WaitIdle(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %7
4: ; preds = %7
%5 = add nuw nsw i32 %8, 1
%6 = icmp eq i32 %5, 1000
br i1 %6, label %13, label %7
7: ; preds = %1, %4
%8 = phi i32 [ 0, %1 ], [ %5, %4 ]
%9 = call i32 @PEX_8111Read(i8* %0, i32 4100, i32* %2)
%10 = load i32, i32* %2
%11 = and i32 %10, 524288
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %4
13: ; preds = %4
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %7, %13
%16 = phi i32 [ 524288, %13 ], [ %10, %7 ]
ret i32 %16
}