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

/* Variables and functions */
scalar_t__ get_data_buffer_status(int, int /*<<< orphan*/ *, scalar_t__ *,
                                  int /*<<< orphan*/ *);
int /*<<< orphan*/ usleep(int);
int kvss905c_data_buffer_wait(int fd, uint8_t *requestsense) {
  uint32_t length;
  uint8_t window_id;
  for (;;) {
    if (get_data_buffer_status(fd, &window_id, &length, requestsense)) {
      return 1;
    }
    if (length)
      break;
    usleep(5000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<kvss905c_data_buffer_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rcx
lea    -0x1c(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <get_data_buffer_status@plt>
cmp    $0x0,%rax
je     1159 <kvss905c_data_buffer_wait+0x39>
movl   $0x1,-0x4(%rbp)
jmp    117f <kvss905c_data_buffer_wait+0x5f>
cmpq   $0x0,-0x18(%rbp)
je     1169 <kvss905c_data_buffer_wait+0x49>
jmp    1178 <kvss905c_data_buffer_wait+0x58>
mov    $0x1388,%edi
call   1040 <usleep@plt>
jmp    112f <kvss905c_data_buffer_wait+0xf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kvss905c_data_buffer_wait>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rcx
call   1030 <get_data_buffer_status@plt>
mov    $0x1,%r14d
test   %rax,%rax
jne    118c <kvss905c_data_buffer_wait+0x6c>
lea    0x4(%rsp),%r15
lea    0x8(%rsp),%r12
nopl   0x0(%rax,%rax,1)
cmpq   $0x0,0x8(%rsp)
jne    1189 <kvss905c_data_buffer_wait+0x69>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1030 <get_data_buffer_status@plt>
test   %rax,%rax
je     1160 <kvss905c_data_buffer_wait+0x40>
jmp    118c <kvss905c_data_buffer_wait+0x6c>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @kvss905c_data_buffer_wait(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
br label %8
8: ; preds = %18, %2
%9 = load i32, i32* %4
%10 = load i32*, i32** %5
%11 = call i64 @get_data_buffer_status(i32 %9, i32* %7, i64* %6, i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8
store i32 1, i32* %3
br label %21
14: ; preds = %8
%15 = load i64, i64* %6
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
br label %20
18: ; preds = %14
%19 = call i32 @usleep(i32 5000)
br label %8
20: ; preds = %17
store i32 0, i32* %3
br label %21
21: ; preds = %20, %13
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
define i32 @kvss905c_data_buffer_wait(i32 %0, i32* %1) {
%3 = alloca i64
%4 = alloca i32
%5 = bitcast i64* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i64 @get_data_buffer_status(i32 %0, i32* %4, i64* %3, i32* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %2, %12
%10 = load i64, i64* %3
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = call i32 @usleep(i32 5000)
%14 = call i64 @get_data_buffer_status(i32 %0, i32* %4, i64* %3, i32* %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %9, label %16
16: ; preds = %12, %9, %2
%17 = phi i32 [ 1, %2 ], [ 0, %9 ], [ 1, %12 ]
ret i32 %17
}