#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 */
typedef scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ am_hal_flash_delay(int);
uint32_t am_util_wait_status_change(uint32_t ui32Iterations,
                                    uint32_t ui32Address, uint32_t ui32Mask,
                                    uint32_t ui32Value) {
  for (uint32_t i = 0; i < ui32Iterations; i++) {
    if (((*(volatile uint32_t *)ui32Address) & ui32Mask) == ui32Value) {
      return 1;
    }
    am_hal_flash_delay(16);
  }
  return 0;
}


x86 assembly (clang, -O0):
<am_util_wait_status_change>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    117b <am_util_wait_status_change+0x6b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
and    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1160 <am_util_wait_status_change+0x50>
movq   $0x1,-0x8(%rbp)
jmp    1183 <am_util_wait_status_change+0x73>
mov    $0x10,%edi
call   1030 <am_hal_flash_delay@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1130 <am_util_wait_status_change+0x20>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<am_util_wait_status_change>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
jle    116c <am_util_wait_status_change+0x5c>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    (%rsi),%rcx
and    %rdx,%rcx
mov    $0x1,%eax
cmp    %r14,%rcx
je     116e <am_util_wait_status_change+0x5e>
mov    %rdi,%r13
mov    $0x1,%eax
nop
mov    %rax,%rbx
mov    $0x10,%edi
call   1030 <am_hal_flash_delay@plt>
cmp    %rbx,%r13
je     1162 <am_util_wait_status_change+0x52>
mov    (%r12),%rcx
and    %r15,%rcx
lea    0x1(%rbx),%rax
cmp    %r14,%rcx
jne    1140 <am_util_wait_status_change+0x30>
xor    %eax,%eax
cmp    %r13,%rbx
setl   %al
jmp    116e <am_util_wait_status_change+0x5e>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @am_util_wait_status_change(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i64 0, i64* %10
br label %11
11: ; preds = %26, %4
%12 = load i64, i64* %10
%13 = load i64, i64* %6
%14 = icmp slt i64 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = load i64, i64* %7
%17 = inttoptr i64 %16 to i64*
%18 = load volatile i64, i64* %17
%19 = load i64, i64* %8
%20 = and i64 %18, %19
%21 = load i64, i64* %9
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %15
store i64 1, i64* %5
br label %30
24: ; preds = %15
%25 = call i32 @am_hal_flash_delay(i32 16)
br label %26
26: ; preds = %24
%27 = load i64, i64* %10
%28 = add nsw i64 %27, 1
store i64 %28, i64* %10
br label %11
29: ; preds = %11
store i64 0, i64* %5
br label %30
30: ; preds = %29, %23
%31 = load i64, i64* %5
ret i64 %31
}

LLVM IR (-O2):
define i64 @am_util_wait_status_change(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = inttoptr i64 %1 to i64*
%6 = icmp sgt i64 %0, 0
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = load volatile i64, i64* %5
%9 = and i64 %8, %2
%10 = icmp eq i64 %9, %3
br i1 %10, label %23, label %15
11: ; preds = %15
%12 = load volatile i64, i64* %5
%13 = and i64 %12, %2
%14 = icmp eq i64 %13, %3
br i1 %14, label %20, label %15
15: ; preds = %7, %11
%16 = phi i64 [ %18, %11 ], [ 0, %7 ]
%17 = tail call i32 @am_hal_flash_delay(i32 16)
%18 = add nuw nsw i64 %16, 1
%19 = icmp eq i64 %18, %0
br i1 %19, label %20, label %11
20: ; preds = %15, %11
%21 = icmp slt i64 %18, %0
%22 = zext i1 %21 to i64
br label %23
23: ; preds = %20, %7, %4
%24 = phi i64 [ 0, %4 ], [ 1, %7 ], [ %22, %20 ]
ret i64 %24
}