#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 */

/* Variables and functions */
int /*<<< orphan*/ fatal(char *);
int lenchars_file(char *);
scalar_t__ readchars_file(char *, int, int *);
int *readtokens_file(char *fn, int fA, int fB, int *N) {
  int nbytes = lenchars_file(fn);
  int nframes = nbytes / sizeof(int);
  if (fA == -1)
    fA = 0;
  if (fA >= nframes) {
    fatal("ERROR: fA is larger than total number of frames\n");
  }
  if (fB == -1)
    fB = nframes - 1;
  if (fB < fA) {
    fatal("ERROR: fB is less than fA\n");
  }
  *N = fB - fA + 1;
  int nbytesread = (*N) * sizeof(int);
  return (int *)readchars_file(fn, fA * sizeof(int), &nbytesread);
}


x86 assembly (clang, -O0):
<readtokens_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <lenchars_file@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shr    $0x2,%rax
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    116e <readtokens_file+0x3e>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x20(%rbp),%eax
jl     1186 <readtokens_file+0x56>
lea    0xe7f(%rip),%rdi
call   1050 <fatal@plt>
cmpl   $0xffffffff,-0x10(%rbp)
jne    1199 <readtokens_file+0x69>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <readtokens_file+0x81>
lea    0xe85(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
lea    -0x24(%rbp),%rdx
call   1030 <readchars_file@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readtokens_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r12d
mov    %esi,%r13d
mov    %rdi,%r15
call   1040 <lenchars_file@plt>
mov    %eax,%ebx
sar    $0x2,%ebx
xor    %ebp,%ebp
cmp    $0xffffffff,%r13d
cmovne %r13d,%ebp
cmp    %ebx,%ebp
jl     116b <readtokens_file+0x3b>
lea    0xe9a(%rip),%rdi
call   1050 <fatal@plt>
add    $0xffffffff,%ebx
cmp    $0xffffffff,%r12d
cmovne %r12d,%ebx
sub    %ebp,%ebx
jge    1186 <readtokens_file+0x56>
lea    0xeb0(%rip),%rdi
call   1050 <fatal@plt>
lea    0x1(%rbx),%eax
mov    %eax,(%r14)
lea    0x4(,%rbx,4),%eax
mov    %eax,0x4(%rsp)
shl    $0x2,%ebp
lea    0x4(%rsp),%rdx
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <readchars_file@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"ERROR: fA is larger than total number of frames\0A\00"
@.str.1 = [27 x i8] c"ERROR: fB is less than fA\0A\00"
define i32* @readtokens_file(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%12 = load i8*, i8** %5
%13 = call i32 @lenchars_file(i8* %12)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = sext i32 %14 to i64
%16 = udiv i64 %15, 4
%17 = trunc i64 %16 to i32
store i32 %17, i32* %10
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 0, i32* %6
br label %21
21: ; preds = %20, %4
%22 = load i32, i32* %6
%23 = load i32, i32* %10
%24 = icmp sge i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @fatal(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %10
%32 = sub nsw i32 %31, 1
store i32 %32, i32* %7
br label %33
33: ; preds = %30, %27
%34 = load i32, i32* %7
%35 = load i32, i32* %6
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
%40 = load i32, i32* %7
%41 = load i32, i32* %6
%42 = sub nsw i32 %40, %41
%43 = add nsw i32 %42, 1
%44 = load i32*, i32** %8
store i32 %43, i32* %44
%45 = load i32*, i32** %8
%46 = load i32, i32* %45
%47 = sext i32 %46 to i64
%48 = mul i64 %47, 4
%49 = trunc i64 %48 to i32
store i32 %49, i32* %11
%50 = load i8*, i8** %5
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = mul i64 %52, 4
%54 = trunc i64 %53 to i32
%55 = call i64 @readchars_file(i8* %50, i32 %54, i32* %11)
%56 = inttoptr i64 %55 to i32*
ret i32* %56
}

LLVM IR (-O2):
@.str = [49 x i8] c"ERROR: fA is larger than total number of frames\0A\00"
@.str.1 = [27 x i8] c"ERROR: fB is less than fA\0A\00"
define i32* @readtokens_file(i8* %0, i32 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = tail call i32 @lenchars_file(i8* %0)
%7 = ashr i32 %6, 2
%8 = icmp eq i32 %1, -1
%9 = select i1 %8, i32 0, i32 %1
%10 = icmp slt i32 %9, %7
br i1 %10, label %13, label %11
11: ; preds = %4
%12 = tail call i32 @fatal(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %4
%14 = icmp eq i32 %2, -1
%15 = add nsw i32 %7, -1
%16 = select i1 %14, i32 %15, i32 %2
%17 = icmp slt i32 %16, %9
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = sub nsw i32 %16, %9
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%23 = bitcast i32* %5 to i8*
%24 = shl i32 %22, 2
store i32 %24, i32* %5
%25 = shl i32 %9, 2
%26 = call i64 @readchars_file(i8* %0, i32 %25, i32* %5)
%27 = inttoptr i64 %26 to i32*
ret i32* %27
}