#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 vnic_rq {
  int dummy;
};

/* Variables and functions */
int stub1(struct vnic_rq *);
scalar_t__ vnic_rq_desc_avail(struct vnic_rq *);
int vnic_rq_fill_count(struct vnic_rq *rq, int (*buf_fill)(struct vnic_rq *rq),
                       unsigned int count) {
  int err;
  while ((vnic_rq_desc_avail(rq) > 0) && (count--)) {
    err = (*buf_fill)(rq);
    if (err)
      return err;
  }
  return 0;
}


x86 assembly (clang, -O0):
<vnic_rq_fill_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <vnic_rq_desc_avail@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jle    1152 <vnic_rq_fill_count+0x42>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1162 <vnic_rq_fill_count+0x52>
jmp    1189 <vnic_rq_fill_count+0x79>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rdi
call   *%rax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1184 <vnic_rq_fill_count+0x74>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1190 <vnic_rq_fill_count+0x80>
jmp    1123 <vnic_rq_fill_count+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vnic_rq_fill_count>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
nopl   (%rax)
mov    %r15,%rdi
call   1030 <vnic_rq_desc_avail@plt>
mov    %rax,%rcx
sub    $0x1,%ebx
setb   %dl
xor    %eax,%eax
test   %rcx,%rcx
jle    1146 <vnic_rq_fill_count+0x36>
test   %dl,%dl
jne    1146 <vnic_rq_fill_count+0x36>
mov    %r15,%rdi
call   *%r14
test   %eax,%eax
je     1120 <vnic_rq_fill_count+0x10>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.vnic_rq = type { i32 }
define i32 @vnic_rq_fill_count(%struct.vnic_rq* %0, i32 (%struct.vnic_rq*)* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.vnic_rq*
%6 = alloca i32 (%struct.vnic_rq*)*
%7 = alloca i32
%8 = alloca i32
store %struct.vnic_rq* %0, %struct.vnic_rq** %5
store i32 (%struct.vnic_rq*)* %1, i32 (%struct.vnic_rq*)** %6
store i32 %2, i32* %7
br label %9
9: ; preds = %27, %3
%10 = load %struct.vnic_rq*, %struct.vnic_rq** %5
%11 = call i64 @vnic_rq_desc_avail(%struct.vnic_rq* %10)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* %7
%15 = add i32 %14, -1
store i32 %15, i32* %7
%16 = icmp ne i32 %14, 0
br label %17
17: ; preds = %13, %9
%18 = phi i1 [ false, %9 ], [ %16, %13 ]
br i1 %18, label %19, label %28
19: ; preds = %17
%20 = load i32 (%struct.vnic_rq*)*, i32 (%struct.vnic_rq*)** %6
%21 = load %struct.vnic_rq*, %struct.vnic_rq** %5
%22 = call i32 %20(%struct.vnic_rq* %21)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i32, i32* %8
store i32 %26, i32* %4
br label %29
27: ; preds = %19
br label %9
28: ; preds = %17
store i32 0, i32* %4
br label %29
29: ; preds = %28, %25
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
%struct.vnic_rq = type { i32 }
define i32 @vnic_rq_fill_count(%struct.vnic_rq* %0, i32 (%struct.vnic_rq*)* nocapture %1, i32 %2) {
br label %4
4: ; preds = %10, %3
%5 = phi i32 [ %2, %3 ], [ %11, %10 ]
%6 = tail call i64 @vnic_rq_desc_avail(%struct.vnic_rq* %0)
%7 = icmp slt i64 %6, 1
%8 = icmp eq i32 %5, 0
%9 = select i1 %7, i1 true, i1 %8
br i1 %9, label %14, label %10
10: ; preds = %4
%11 = add i32 %5, -1
%12 = tail call i32 %1(%struct.vnic_rq* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %4, label %14
14: ; preds = %4, %10
%15 = phi i32 [ %12, %10 ], [ 0, %4 ]
ret i32 %15
}