#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 */
struct c2interface {
  int dummy;
};

/* Variables and functions */
int EIO;
int c2_read_ar(struct c2interface *, unsigned char *);
int /*<<< orphan*/ usleep(int);
int c2_poll_in_busy(struct c2interface *c2if) {
  unsigned char addr;
  int ret, timeout = 20;
  do {
    ret = (c2_read_ar(c2if, &addr));
    if (ret < 0)
      return -EIO;
    if (!(addr & 0x02))
      break;
    usleep(1);
  } while (--timeout > 0);
  if (timeout == 0)
    return -EIO;
  return 0;
}


x86 assembly (clang, -O0):
<c2_poll_in_busy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x14,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x11(%rbp),%rsi
call   1030 <c2_read_ar@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1160 <c2_poll_in_busy+0x40>
xor    %eax,%eax
mov    0x2e8a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b5 <c2_poll_in_busy+0x95>
movzbl -0x11(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    1175 <c2_poll_in_busy+0x55>
jmp    1191 <c2_poll_in_busy+0x71>
mov    $0x1,%edi
call   1040 <usleep@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jg     1133 <c2_poll_in_busy+0x13>
cmpl   $0x0,-0x1c(%rbp)
jne    11ae <c2_poll_in_busy+0x8e>
xor    %eax,%eax
mov    0x2e3c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b5 <c2_poll_in_busy+0x95>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c2_poll_in_busy>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x15,%ebp
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <c2_read_ar@plt>
test   %eax,%eax
js     1168 <c2_poll_in_busy+0x48>
testb  $0x2,0xf(%rsp)
je     1175 <c2_poll_in_busy+0x55>
mov    $0x1,%edi
call   1040 <usleep@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1140 <c2_poll_in_busy+0x20>
mov    0x2e71(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    1177 <c2_poll_in_busy+0x57>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.c2interface = type { i32 }
@EIO = global i32 0
define i32 @c2_poll_in_busy(%struct.c2interface* %0) {
%2 = alloca i32
%3 = alloca %struct.c2interface*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store %struct.c2interface* %0, %struct.c2interface** %3
store i32 20, i32* %6
br label %7
7: ; preds = %23, %1
%8 = load %struct.c2interface*, %struct.c2interface** %3
%9 = call i32 @c2_read_ar(%struct.c2interface* %8, i8* %4)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* @EIO
%14 = sub nsw i32 0, %13
store i32 %14, i32* %2
br label %34
15: ; preds = %7
%16 = load i8, i8* %4
%17 = zext i8 %16 to i32
%18 = and i32 %17, 2
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %15
br label %27
21: ; preds = %15
%22 = call i32 @usleep(i32 1)
br label %23
23: ; preds = %21
%24 = load i32, i32* %6
%25 = add nsw i32 %24, -1
store i32 %25, i32* %6
%26 = icmp sgt i32 %25, 0
br i1 %26, label %7, label %27
27: ; preds = %23, %20
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @EIO
%32 = sub nsw i32 0, %31
store i32 %32, i32* %2
br label %34
33: ; preds = %27
store i32 0, i32* %2
br label %34
34: ; preds = %33, %30, %12
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
%struct.c2interface = type { i32 }
@EIO = global i32 0
define i32 @c2_poll_in_busy(%struct.c2interface* %0) {
%2 = alloca i8
br label %3
3: ; preds = %14, %1
%4 = phi i32 [ 20, %1 ], [ %16, %14 ]
%5 = call i32 @c2_read_ar(%struct.c2interface* %0, i8* %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @EIO
%9 = sub nsw i32 0, %8
br label %21
10: ; preds = %3
%11 = load i8, i8* %2
%12 = and i8 %11, 2
%13 = icmp eq i8 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = call i32 @usleep(i32 1)
%16 = add nsw i32 %4, -1
%17 = icmp ugt i32 %4, 1
br i1 %17, label %3, label %18
18: ; preds = %14
%19 = load i32, i32* @EIO
%20 = sub nsw i32 0, %19
br label %21
21: ; preds = %10, %18, %7
%22 = phi i32 [ %9, %7 ], [ %20, %18 ], [ 0, %10 ]
ret i32 %22
}