#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 scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ fetchpage(int, scalar_t__);
scalar_t__ random();
void workloop(int fd, off_t min, off_t max) {
  off_t offs;
  max -= 4096;
  if (max < 0)
    errx(1, "file should be at least 4k");
  offs = random() % (max - min) + min;
  fetchpage(fd, offs);
}


x86 assembly (clang, -O0):
<workloop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x1000,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    116d <workloop+0x3d>
mov    $0x1,%edi
lea    0xe98(%rip),%rsi
call   1040 <errx@plt>
mov    $0x0,%al
call   1050 <random@plt>
mov    -0x18(%rbp),%rcx
sub    -0x10(%rbp),%rcx
cqto
idiv   %rcx
add    -0x10(%rbp),%rdx
mov    %rdx,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <fetchpage@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<workloop>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %edi,%r14d
cmp    $0xfff,%rdx
jg     1157 <workloop+0x27>
lea    0xeb3(%rip),%rsi
mov    $0x1,%edi
call   1040 <errx@plt>
xor    %eax,%eax
call   1050 <random@plt>
sub    %rbx,%rbp
add    $0xfffffffffffff000,%rbp
mov    %rax,%rcx
or     %rbp,%rcx
shr    $0x20,%rcx
je     117b <workloop+0x4b>
cqto
idiv   %rbp
jmp    117f <workloop+0x4f>
xor    %edx,%edx
div    %ebp
add    %rbx,%rdx
mov    %r14d,%edi
mov    %rdx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fetchpage@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"file should be at least 4k\00"
define void @workloop(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 %0, i32* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = sub nsw i64 %8, 4096
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @errx(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
%15 = call i64 (...) @random()
%16 = load i64, i64* %6
%17 = load i64, i64* %5
%18 = sub nsw i64 %16, %17
%19 = srem i64 %15, %18
%20 = load i64, i64* %5
%21 = add nsw i64 %19, %20
store i64 %21, i64* %7
%22 = load i32, i32* %4
%23 = load i64, i64* %7
%24 = call i32 @fetchpage(i32 %22, i64 %23)
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"file should be at least 4k\00"
define void @workloop(i32 %0, i64 %1, i64 %2) {
%4 = icmp slt i64 %2, 4096
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = tail call i64 (...) @random()
%9 = sub i64 -4096, %1
%10 = add i64 %9, %2
%11 = srem i64 %8, %10
%12 = add nsw i64 %11, %1
%13 = tail call i32 @fetchpage(i32 %0, i64 %12)
ret void
}