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

/* Variables and functions */
scalar_t__ run_one(struct runq *);
unsigned int runq_dispatch(struct runq *r, unsigned int limit) {
  int count = 0;
  while (!limit || (count < limit)) {
    if (run_one(r) <= 0)
      break;
    count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<runq_dispatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x11(%rbp)
je     1141 <runq_dispatch+0x31>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
setb   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1151 <runq_dispatch+0x41>
jmp    1177 <runq_dispatch+0x67>
mov    -0x8(%rbp),%rdi
call   1030 <run_one@plt>
cmp    $0x0,%rax
jg     1169 <runq_dispatch+0x59>
jmp    1177 <runq_dispatch+0x67>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <runq_dispatch+0x16>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runq_dispatch>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <run_one@plt>
test   %rax,%rax
jle    1138 <runq_dispatch+0x28>
add    $0x1,%ebx
test   %ebp,%ebp
je     1120 <runq_dispatch+0x10>
cmp    %ebp,%ebx
jb     1120 <runq_dispatch+0x10>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.runq = type { i32 }
define i32 @runq_dispatch(%struct.runq* %0, i32 %1) {
%3 = alloca %struct.runq*
%4 = alloca i32
%5 = alloca i32
store %struct.runq* %0, %struct.runq** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %20, %2
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp ult i32 %10, %11
br label %13
13: ; preds = %9, %6
%14 = phi i1 [ true, %6 ], [ %12, %9 ]
br i1 %14, label %15, label %23
15: ; preds = %13
%16 = load %struct.runq*, %struct.runq** %3
%17 = call i64 @run_one(%struct.runq* %16)
%18 = icmp sle i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %23
20: ; preds = %15
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %6
23: ; preds = %19, %13
%24 = load i32, i32* %5
ret i32 %24
}

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