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

/* Variables and functions */
int fread(int *, int, int, int /*<<< orphan*/ *);
int read_number(FILE *in, int min, int max) {
  int span = max - min + 1;
  int fits = 256 / span;
  while (1) {
    uint8_t b;
    if (fread(&b, 1, 1, in) != 1) {
      return 0;
    }
    if (b >= fits * span) {
      continue;
    } else {
      return min + (b % span);
    }
  }
}


x86 assembly (clang, -O0):
<read_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x100,%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1163 <read_number+0x53>
movl   $0x0,-0x4(%rbp)
jmp    118f <read_number+0x7f>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jl     117a <read_number+0x6a>
jmp    113a <read_number+0x2a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    -0x28(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_number>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    119f <read_number+0x8f>
sub    %r14d,%r15d
add    $0x1,%r15d
mov    $0x100,%ebp
mov    $0x100,%eax
xor    %edx,%edx
idiv   %r15d
sub    %edx,%ebp
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0xc(%rsp),%eax
cmp    %ebp,%eax
jl     1196 <read_number+0x86>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1170 <read_number+0x60>
xor    %eax,%eax
jmp    119f <read_number+0x8f>
cltd
idiv   %r15d
mov    %edx,%eax
add    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_number(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = sub nsw i32 %11, %12
%14 = add nsw i32 %13, 1
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = sdiv i32 256, %15
store i32 %16, i32* %9
br label %17
17: ; preds = %3, %28
%18 = load i32*, i32** %5
%19 = call i32 @fread(i32* %10, i32 1, i32 1, i32* %18)
%20 = icmp ne i32 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 0, i32* %4
br label %35
22: ; preds = %17
%23 = load i32, i32* %10
%24 = load i32, i32* %9
%25 = load i32, i32* %8
%26 = mul nsw i32 %24, %25
%27 = icmp sge i32 %23, %26
br i1 %27, label %28, label %29
28: ; preds = %22
br label %17
29: ; preds = %22
%30 = load i32, i32* %6
%31 = load i32, i32* %10
%32 = load i32, i32* %8
%33 = srem i32 %31, %32
%34 = add nsw i32 %30, %33
store i32 %34, i32* %4
br label %35
35: ; preds = %29, %21
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @read_number(i32* nocapture %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = sub nsw i32 %2, %1
%6 = add nsw i32 %5, 1
%7 = bitcast i32* %4 to i8*
%8 = call i32 @fread(i32* %4, i32 1, i32 1, i32* %0)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %22
10: ; preds = %3
%11 = srem i32 256, %6
%12 = sub nuw nsw i32 256, %11
br label %13
13: ; preds = %10, %19
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, %12
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = srem i32 %14, %6
%18 = add nsw i32 %17, %1
br label %22
19: ; preds = %13
%20 = call i32 @fread(i32* %4, i32 1, i32 1, i32* %0)
%21 = icmp eq i32 %20, 1
br i1 %21, label %13, label %22
22: ; preds = %19, %3, %16
%23 = phi i32 [ %18, %16 ], [ 0, %3 ], [ 0, %19 ]
ret i32 %23
}