int next_pages_per_loop(const int color, const int pages) {
  int pages_next_loop;
  if (color == -1) {
    pages_next_loop = ((pages) < (4096) ? (pages) : (4096));
    pages_next_loop = ((pages_next_loop) > (256) ? (pages_next_loop) : (256));
  } else {
    if (pages < 512 / 4) {
      pages_next_loop = 0;
    } else {
      pages_next_loop = 512;
    }
  }
  return pages_next_loop;
}


x86 assembly (clang, -O0):
<next_pages_per_loop>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    116f <next_pages_per_loop+0x6f>
cmpl   $0x1000,-0x8(%rbp)
jge    112c <next_pages_per_loop+0x2c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1139 <next_pages_per_loop+0x39>
mov    $0x1000,%eax
mov    %eax,-0x10(%rbp)
jmp    1139 <next_pages_per_loop+0x39>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x100,-0xc(%rbp)
jle    1157 <next_pages_per_loop+0x57>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <next_pages_per_loop+0x64>
mov    $0x100,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <next_pages_per_loop+0x64>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <next_pages_per_loop+0x94>
cmpl   $0x80,-0x8(%rbp)
jge    1188 <next_pages_per_loop+0x88>
movl   $0x0,-0xc(%rbp)
jmp    118f <next_pages_per_loop+0x8f>
movl   $0x200,-0xc(%rbp)
jmp    1194 <next_pages_per_loop+0x94>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_pages_per_loop>:
cmp    $0xffffffff,%edi
je     1111 <next_pages_per_loop+0x11>
xor    %eax,%eax
cmp    $0x7f,%esi
setg   %al
shl    $0x9,%eax
ret
cmp    $0x1000,%esi
mov    $0x1000,%ecx
cmovl  %esi,%ecx
cmp    $0x101,%ecx
mov    $0x100,%eax
cmovge %ecx,%eax
ret

LLVM IR (-O0):
define i32 @next_pages_per_loop(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %23
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 4096
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = load i32, i32* %4
br label %14
13: ; preds = %8
br label %14
14: ; preds = %13, %11
%15 = phi i32 [ %12, %11 ], [ 4096, %13 ]
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 256
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i32, i32* %5
br label %21
20: ; preds = %14
br label %21
21: ; preds = %20, %18
%22 = phi i32 [ %19, %18 ], [ 256, %20 ]
store i32 %22, i32* %5
br label %29
23: ; preds = %2
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 128
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 0, i32* %5
br label %28
27: ; preds = %23
store i32 512, i32* %5
br label %28
28: ; preds = %27, %26
br label %29
29: ; preds = %28, %21
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
define i32 @next_pages_per_loop(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, -1
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = icmp slt i32 %1, 4096
%6 = select i1 %5, i32 %1, i32 4096
%7 = icmp sgt i32 %6, 256
%8 = select i1 %7, i32 %6, i32 256
br label %12
9: ; preds = %2
%10 = icmp slt i32 %1, 128
%11 = select i1 %10, i32 0, i32 512
br label %12
12: ; preds = %9, %4
%13 = phi i32 [ %8, %4 ], [ %11, %9 ]
ret i32 %13
}