#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 inb(int);
int wait_for_ec_status(unsigned char status, int is_set) {
  int i;
  for (i = 0; i < 500; i += 1) {
    unsigned char value = inb(0x66);
    if (is_set) {
      value = ~value;
    }
    if ((status & value) == 0) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<wait_for_ec_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x1f4,-0x10(%rbp)
jge    1188 <wait_for_ec_status+0x78>
mov    $0x66,%edi
call   1030 <inb@plt>
mov    %al,-0x11(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1156 <wait_for_ec_status+0x46>
movzbl -0x11(%rbp),%eax
xor    $0xffffffff,%eax
mov    %al,-0x11(%rbp)
movzbl -0x5(%rbp),%eax
movzbl -0x11(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    1175 <wait_for_ec_status+0x65>
movl   $0x1,-0x4(%rbp)
jmp    118f <wait_for_ec_status+0x7f>
jmp    117a <wait_for_ec_status+0x6a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1128 <wait_for_ec_status+0x18>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_ec_status>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
neg    %esi
sbb    %ebp,%ebp
mov    $0x1f4,%ebx
mov    $0x66,%edi
call   1030 <inb@plt>
xor    %bpl,%al
test   %r14b,%al
je     113b <wait_for_ec_status+0x2b>
add    $0xffffffff,%ebx
jne    1120 <wait_for_ec_status+0x10>
xor    %eax,%eax
jmp    1140 <wait_for_ec_status+0x30>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @wait_for_ec_status(i8 zeroext %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8 %0, i8* %4
store i32 %1, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %29, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 500
br i1 %10, label %11, label %32
11: ; preds = %8
%12 = call zeroext i8 @inb(i32 102)
store i8 %12, i8* %7
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8, i8* %7
%17 = zext i8 %16 to i32
%18 = xor i32 %17, -1
%19 = trunc i32 %18 to i8
store i8 %19, i8* %7
br label %20
20: ; preds = %15, %11
%21 = load i8, i8* %4
%22 = zext i8 %21 to i32
%23 = load i8, i8* %7
%24 = zext i8 %23 to i32
%25 = and i32 %22, %24
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %20
store i32 1, i32* %3
br label %33
28: ; preds = %20
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %8
32: ; preds = %8
store i32 0, i32* %3
br label %33
33: ; preds = %32, %27
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @wait_for_ec_status(i8 zeroext %0, i32 %1) {
%3 = icmp ne i32 %1, 0
%4 = sext i1 %3 to i8
br label %8
5: ; preds = %8
%6 = add nuw nsw i32 %9, 1
%7 = icmp eq i32 %6, 500
br i1 %7, label %14, label %8
8: ; preds = %2, %5
%9 = phi i32 [ 0, %2 ], [ %6, %5 ]
%10 = tail call zeroext i8 @inb(i32 102)
%11 = xor i8 %10, %4
%12 = and i8 %11, %0
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %5
14: ; preds = %5, %8
%15 = phi i32 [ 1, %8 ], [ 0, %5 ]
ret i32 %15
}