#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 stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int aleat(int);
int atoi(char *);
int errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/, char *, ...);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
main(int argc, char **argv) {
  int n, m, J, t;
  struct stat sdata;
  FILE *ifile, *ofile;
  unsigned char *buff;
  if (argc < 5) {
    fprintf(
        stderr,
        "Usage: %s <file> <length> <number> <intervals file>\n"
        "  randomly extracts <number> intervals of length <length> from "
        "<file>.\n"
        "  The output file, <intervals file> has a first line of the form:\n"
        "    # number=<number> length=<length> file=<file>\n"
        "  and then <number> lines of the form <from>,<to>.\n",
        argv[0]);
    exit(1);
  }
  if (stat(argv[1], &sdata) != 0) {
    fprintf(stderr, "Error: cannot stat file %s\n", argv[1]);
    fprintf(stderr, " errno = %i\n", errno);
    exit(1);
  }
  n = sdata.st_size;
  m = atoi(argv[2]);
  if ((m <= 0) || (m > n)) {
    fprintf(stderr,
            "Error: length must be >= 1 and <= file length"
            " (%i)\n",
            n);
    exit(1);
  }
  J = atoi(argv[3]);
  if (J < 1) {
    fprintf(stderr, "Error: number of intervals must be >= 1\n");
    exit(1);
  }
  ifile = fopen(argv[1], "r");
  if (ifile == NULL) {
    fprintf(stderr, "Error: cannot open file %s for reading\n", argv[1]);
    fprintf(stderr, " errno = %i\n", errno);
    exit(1);
  }
  buff = (unsigned char *)malloc(n);
  if (buff == NULL) {
    fprintf(stderr, "Error: cannot allocate %i bytes\n", n);
    fprintf(stderr, " errno = %i\n", errno);
    exit(1);
  }
  if (fread(buff, n, 1, ifile) != 1) {
    fprintf(stderr, "Error: cannot read file %s\n", argv[1]);
    fprintf(stderr, " errno = %i\n", errno);
    exit(1);
  }
  fclose(ifile);
  ofile = fopen(argv[4], "w");
  if (ofile == NULL) {
    fprintf(stderr, "Error: cannot open file %s for writing\n", argv[4]);
    fprintf(stderr, " errno = %i\n", errno);
    exit(1);
  }
  if (fprintf(ofile, "# number=%i length=%i file=%s\n", J, m, argv[1]) <= 0) {
    fprintf(stderr, "Error: cannot write file %s\n", argv[4]);
    fprintf(stderr, " errno = %i\n", errno);
    exit(1);
  }
  for (t = 0; t < J; t++) {
    int j, l;
    j = aleat(n - m + 1);
    if (fprintf(ofile, "%i,%i\n", j, j + m - 1) <= 0) {
      fprintf(stderr, "Error: cannot write file %s\n", argv[4]);
      fprintf(stderr, " errno = %i\n", errno);
      exit(1);
    }
  }
  if (fclose(ofile) != 0) {
    fprintf(stderr, "Error: cannot write file %s\n", argv[4]);
    fprintf(stderr, " errno = %i\n", errno);
    exit(1);
  }
  fprintf(stderr, "File %s successfully generated\n", argv[4]);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11d8 <main+0x48>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
je     123c <main+0xac>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xf18(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
lea    0xf14(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1268 <main+0xd8>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    128c <main+0xfc>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xed1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    12c7 <main+0x137>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xeca(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xed3(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1333 <main+0x1a3>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xea9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
mov    0x2cbf(%rip),%rax
mov    (%rax),%edx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    138e <main+0x1fe>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
mov    0x2c64(%rip),%rax
mov    (%rax),%edx
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     13f5 <main+0x265>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c0e(%rip),%rax
mov    (%rax),%edi
mov    0x2bfd(%rip),%rax
mov    (%rax),%edx
lea    0xd5b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xe03(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    146a <main+0x2da>
mov    0x2bb8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2b99(%rip),%rax
mov    (%rax),%edi
mov    0x2b88(%rip),%rax
mov    (%rax),%edx
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x38(%rbp),%rax
mov    %eax,%edi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmp    $0x0,%rax
jg     14df <main+0x34f>
mov    0x2b43(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xdab(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2b24(%rip),%rax
mov    (%rax),%edi
mov    0x2b13(%rip),%rax
mov    (%rax),%edx
lea    0xc71(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1589 <main+0x3f9>
mov    -0x14(%rbp),%edi
sub    -0x18(%rbp),%edi
add    $0x1,%edi
call   1030 <aleat@plt>
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rax
mov    %eax,%edi
mov    -0x44(%rbp),%edx
mov    -0x44(%rbp),%ecx
add    -0x18(%rbp),%ecx
sub    $0x1,%ecx
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmp    $0x0,%rax
jg     1576 <main+0x3e6>
mov    0x2aac(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xd14(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2a8d(%rip),%rax
mov    (%rax),%edi
mov    0x2a7c(%rip),%rax
mov    (%rax),%edx
lea    0xbda(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    157b <main+0x3eb>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    14e6 <main+0x356>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     15e5 <main+0x455>
mov    0x2a3d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xca5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2a1e(%rip),%rax
mov    (%rax),%edi
mov    0x2a0d(%rip),%rax
mov    (%rax),%edx
lea    0xb6b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x29f4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xc80(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x4,%edi
jg     11c7 <main+0x37>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe4a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x8(%r14),%rdi
mov    %rsp,%rsi
call   1070 <stat@plt>
test   %rax,%rax
jne    1222 <main+0x92>
mov    (%rsp),%r12d
mov    0x10(%r14),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
jle    1251 <main+0xc1>
mov    %eax,%r15d
mov    %r12d,%r13d
sub    %eax,%r13d
jl     1251 <main+0xc1>
mov    0x18(%r14),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
jg     1275 <main+0xe5>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xf6f(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2db7(%rip),%rbx
mov    (%rbx),%edi
mov    0x8(%r14),%rdx
lea    0xeed(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
lea    0xef0(%rip),%rsi
jmp    1264 <main+0xd4>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xeeb(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%ebx
mov    0x8(%r14),%rdi
lea    0xf27(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    12a2 <main+0x112>
mov    0x2d4d(%rip),%rbx
mov    (%rbx),%edi
mov    0x8(%r14),%rdx
lea    0xf0b(%rip),%rsi
jmp    1236 <main+0xa6>
mov    %rax,%rbp
mov    %r12d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
jne    12d1 <main+0x141>
mov    0x2d27(%rip),%rbx
mov    (%rbx),%edi
lea    0xf11(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    123d <main+0xad>
mov    %rax,%rdi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    131f <main+0x18f>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    0x20(%r14),%rdi
lea    0xf14(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    1338 <main+0x1a8>
mov    0x2cd3(%rip),%rbx
mov    (%rbx),%edi
mov    0x20(%r14),%rdx
lea    0xef8(%rip),%rsi
jmp    1236 <main+0xa6>
mov    0x2cba(%rip),%rbx
mov    (%rbx),%edi
mov    0x8(%r14),%rdx
lea    0xec1(%rip),%rsi
jmp    1236 <main+0xa6>
mov    %rax,%rbp
mov    0x8(%r14),%r8
lea    0xef4(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %rax,%rax
jg     1372 <main+0x1e2>
mov    0x2c80(%rip),%rbx
mov    (%rbx),%edi
mov    0x20(%r14),%rdx
lea    0xeec(%rip),%rsi
jmp    1236 <main+0xa6>
add    $0x1,%r13d
add    $0xffffffff,%r15d
lea    0xef5(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13d,%edi
call   1030 <aleat@plt>
lea    (%r15,%rax,1),%ecx
mov    %ebp,%edi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %rax,%rax
jle    1359 <main+0x1c9>
add    $0xffffffff,%ebx
jne    1390 <main+0x200>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    0x2c1d(%rip),%rbx
mov    (%rbx),%edi
mov    0x20(%r14),%rdx
test   %rax,%rax
jne    1366 <main+0x1d6>
lea    0xea8(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [291 x i8] c"Usage: %s <file> <length> <number> <intervals file>\0A randomly extracts <number> intervals of length <length> from <file>.\0A The output file, <intervals file> has a first line of the form:\0A # number=<number> length=<length> file=<file>\0A and then <number> lines of the form <from>,<to>.\0A\00"
@.str.1 = [28 x i8] c"Error: cannot stat file %s\0A\00"
@.str.2 = [13 x i8] c" errno = %i\0A\00"
@errno = global i32 0
@.str.3 = [52 x i8] c"Error: length must be >= 1 and <= file length (%i)\0A\00"
@.str.4 = [41 x i8] c"Error: number of intervals must be >= 1\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [40 x i8] c"Error: cannot open file %s for reading\0A\00"
@.str.7 = [33 x i8] c"Error: cannot allocate %i bytes\0A\00"
@.str.8 = [28 x i8] c"Error: cannot read file %s\0A\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [40 x i8] c"Error: cannot open file %s for writing\0A\00"
@.str.11 = [31 x i8] c"# number=%i length=%i file=%s\0A\00"
@.str.12 = [29 x i8] c"Error: cannot write file %s\0A\00"
@.str.13 = [7 x i8] c"%i,%i\0A\00"
@.str.14 = [32 x i8] c"File %s successfully generated\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.stat
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 5
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i64 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([291 x i8], [291 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @stat(i8* %28, %struct.stat* %10)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i64 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %25
%42 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%43 = load i32, i32* %42
store i32 %43, i32* %6
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @atoi(i8* %46)
store i32 %47, i32* %7
%48 = load i32, i32* %7
%49 = icmp sle i32 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %41
%51 = load i32, i32* %7
%52 = load i32, i32* %6
%53 = icmp sgt i32 %51, %52
br i1 %53, label %54, label %59
54: ; preds = %50, %41
%55 = load i32, i32* @stderr
%56 = load i32, i32* %6
%57 = call i64 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %50
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 3
%62 = load i8*, i8** %61
%63 = call i32 @atoi(i8* %62)
store i32 %63, i32* %8
%64 = load i32, i32* %8
%65 = icmp slt i32 %64, 1
br i1 %65, label %66, label %70
66: ; preds = %59
%67 = load i32, i32* @stderr
%68 = call i64 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %59
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = call i32* @fopen(i8* %73, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %74, i32** %11
%75 = load i32*, i32** %11
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %87
77: ; preds = %70
%78 = load i32, i32* @stderr
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i64 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %81)
%83 = load i32, i32* @stderr
%84 = load i32, i32* @errno
%85 = call i64 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %84)
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %70
%88 = load i32, i32* %6
%89 = call i64 @malloc(i32 %88)
%90 = inttoptr i64 %89 to i8*
store i8* %90, i8** %13
%91 = load i8*, i8** %13
%92 = icmp eq i8* %91, null
br i1 %92, label %93, label %101
93: ; preds = %87
%94 = load i32, i32* @stderr
%95 = load i32, i32* %6
%96 = call i64 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %95)
%97 = load i32, i32* @stderr
%98 = load i32, i32* @errno
%99 = call i64 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %98)
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %87
%102 = load i8*, i8** %13
%103 = load i32, i32* %6
%104 = load i32*, i32** %11
%105 = call i32 @fread(i8* %102, i32 %103, i32 1, i32* %104)
%106 = icmp ne i32 %105, 1
br i1 %106, label %107, label %117
107: ; preds = %101
%108 = load i32, i32* @stderr
%109 = load i8**, i8*** %5
%110 = getelementptr inbounds i8*, i8** %109, i64 1
%111 = load i8*, i8** %110
%112 = call i64 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %111)
%113 = load i32, i32* @stderr
%114 = load i32, i32* @errno
%115 = call i64 (i32, i8*, ...) @fprintf(i32 %113, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %114)
%116 = call i32 @exit(i32 1)
unreachable
117: ; preds = %101
%118 = load i32*, i32** %11
%119 = call i64 @fclose(i32* %118)
%120 = load i8**, i8*** %5
%121 = getelementptr inbounds i8*, i8** %120, i64 4
%122 = load i8*, i8** %121
%123 = call i32* @fopen(i8* %122, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %123, i32** %12
%124 = load i32*, i32** %12
%125 = icmp eq i32* %124, null
br i1 %125, label %126, label %136
126: ; preds = %117
%127 = load i32, i32* @stderr
%128 = load i8**, i8*** %5
%129 = getelementptr inbounds i8*, i8** %128, i64 4
%130 = load i8*, i8** %129
%131 = call i64 (i32, i8*, ...) @fprintf(i32 %127, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0), i8* %130)
%132 = load i32, i32* @stderr
%133 = load i32, i32* @errno
%134 = call i64 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %133)
%135 = call i32 @exit(i32 1)
unreachable
136: ; preds = %117
%137 = load i32*, i32** %12
%138 = ptrtoint i32* %137 to i32
%139 = load i32, i32* %8
%140 = load i32, i32* %7
%141 = load i8**, i8*** %5
%142 = getelementptr inbounds i8*, i8** %141, i64 1
%143 = load i8*, i8** %142
%144 = call i64 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0), i32 %139, i32 %140, i8* %143)
%145 = icmp sle i64 %144, 0
br i1 %145, label %146, label %156
146: ; preds = %136
%147 = load i32, i32* @stderr
%148 = load i8**, i8*** %5
%149 = getelementptr inbounds i8*, i8** %148, i64 4
%150 = load i8*, i8** %149
%151 = call i64 (i32, i8*, ...) @fprintf(i32 %147, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0), i8* %150)
%152 = load i32, i32* @stderr
%153 = load i32, i32* @errno
%154 = call i64 (i32, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %153)
%155 = call i32 @exit(i32 1)
unreachable
156: ; preds = %136
store i32 0, i32* %9
br label %157
157: ; preds = %187, %156
%158 = load i32, i32* %9
%159 = load i32, i32* %8
%160 = icmp slt i32 %158, %159
br i1 %160, label %161, label %190
161: ; preds = %157
%162 = load i32, i32* %6
%163 = load i32, i32* %7
%164 = sub nsw i32 %162, %163
%165 = add nsw i32 %164, 1
%166 = call i32 @aleat(i32 %165)
store i32 %166, i32* %14
%167 = load i32*, i32** %12
%168 = ptrtoint i32* %167 to i32
%169 = load i32, i32* %14
%170 = load i32, i32* %14
%171 = load i32, i32* %7
%172 = add nsw i32 %170, %171
%173 = sub nsw i32 %172, 1
%174 = call i64 (i32, i8*, ...) @fprintf(i32 %168, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 %169, i32 %173)
%175 = icmp sle i64 %174, 0
br i1 %175, label %176, label %186
176: ; preds = %161
%177 = load i32, i32* @stderr
%178 = load i8**, i8*** %5
%179 = getelementptr inbounds i8*, i8** %178, i64 4
%180 = load i8*, i8** %179
%181 = call i64 (i32, i8*, ...) @fprintf(i32 %177, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0), i8* %180)
%182 = load i32, i32* @stderr
%183 = load i32, i32* @errno
%184 = call i64 (i32, i8*, ...) @fprintf(i32 %182, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %183)
%185 = call i32 @exit(i32 1)
unreachable
186: ; preds = %161
br label %187
187: ; preds = %186
%188 = load i32, i32* %9
%189 = add nsw i32 %188, 1
store i32 %189, i32* %9
br label %157
190: ; preds = %157
%191 = load i32*, i32** %12
%192 = call i64 @fclose(i32* %191)
%193 = icmp ne i64 %192, 0
br i1 %193, label %194, label %204
194: ; preds = %190
%195 = load i32, i32* @stderr
%196 = load i8**, i8*** %5
%197 = getelementptr inbounds i8*, i8** %196, i64 4
%198 = load i8*, i8** %197
%199 = call i64 (i32, i8*, ...) @fprintf(i32 %195, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0), i8* %198)
%200 = load i32, i32* @stderr
%201 = load i32, i32* @errno
%202 = call i64 (i32, i8*, ...) @fprintf(i32 %200, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %201)
%203 = call i32 @exit(i32 1)
unreachable
204: ; preds = %190
%205 = load i32, i32* @stderr
%206 = load i8**, i8*** %5
%207 = getelementptr inbounds i8*, i8** %206, i64 4
%208 = load i8*, i8** %207
%209 = call i64 (i32, i8*, ...) @fprintf(i32 %205, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.14, i64 0, i64 0), i8* %208)
%210 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [291 x i8] c"Usage: %s <file> <length> <number> <intervals file>\0A randomly extracts <number> intervals of length <length> from <file>.\0A The output file, <intervals file> has a first line of the form:\0A # number=<number> length=<length> file=<file>\0A and then <number> lines of the form <from>,<to>.\0A\00"
@.str.1 = [28 x i8] c"Error: cannot stat file %s\0A\00"
@.str.2 = [13 x i8] c" errno = %i\0A\00"
@errno = global i32 0
@.str.3 = [52 x i8] c"Error: length must be >= 1 and <= file length (%i)\0A\00"
@.str.4 = [41 x i8] c"Error: number of intervals must be >= 1\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [40 x i8] c"Error: cannot open file %s for reading\0A\00"
@.str.7 = [33 x i8] c"Error: cannot allocate %i bytes\0A\00"
@.str.8 = [28 x i8] c"Error: cannot read file %s\0A\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [40 x i8] c"Error: cannot open file %s for writing\0A\00"
@.str.11 = [31 x i8] c"# number=%i length=%i file=%s\0A\00"
@.str.12 = [29 x i8] c"Error: cannot write file %s\0A\00"
@.str.13 = [7 x i8] c"%i,%i\0A\00"
@.str.14 = [32 x i8] c"File %s successfully generated\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp slt i32 %0, 5
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i64 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([291 x i8], [291 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @stat(i8* %13, %struct.stat* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = call i64 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i64 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %11
%25 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
%30 = icmp slt i32 %29, 1
%31 = icmp slt i32 %26, %29
%32 = select i1 %30, i1 true, i1 %31
br i1 %32, label %33, label %37
33: ; preds = %24
%34 = load i32, i32* @stderr
%35 = call i64 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %24
%38 = getelementptr inbounds i8*, i8** %1, i64 3
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
%41 = icmp slt i32 %40, 1
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = call i64 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %37
%47 = load i8*, i8** %12
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %58
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = load i8*, i8** %12
%53 = call i64 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %52)
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i64 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %46
%59 = call i64 @malloc(i32 %26)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %68
61: ; preds = %58
%62 = load i32, i32* @stderr
%63 = call i64 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %26)
%64 = load i32, i32* @stderr
%65 = load i32, i32* @errno
%66 = call i64 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %65)
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %58
%69 = inttoptr i64 %59 to i8*
%70 = call i32 @fread(i8* %69, i32 %26, i32 1, i32* %48)
%71 = icmp eq i32 %70, 1
br i1 %71, label %80, label %72
72: ; preds = %68
%73 = load i32, i32* @stderr
%74 = load i8*, i8** %12
%75 = call i64 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %74)
%76 = load i32, i32* @stderr
%77 = load i32, i32* @errno
%78 = call i64 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %77)
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %68
%81 = call i64 @fclose(i32* %48)
%82 = getelementptr inbounds i8*, i8** %1, i64 4
%83 = load i8*, i8** %82
%84 = call i32* @fopen(i8* %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%85 = icmp eq i32* %84, null
br i1 %85, label %86, label %94
86: ; preds = %80
%87 = load i32, i32* @stderr
%88 = load i8*, i8** %82
%89 = call i64 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0), i8* %88)
%90 = load i32, i32* @stderr
%91 = load i32, i32* @errno
%92 = call i64 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %91)
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %80
%95 = ptrtoint i32* %84 to i64
%96 = trunc i64 %95 to i32
%97 = load i8*, i8** %12
%98 = call i64 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0), i32 %40, i32 %29, i8* %97)
%99 = icmp slt i64 %98, 1
br i1 %99, label %104, label %100
100: ; preds = %94
%101 = add i32 %26, 1
%102 = sub i32 %101, %29
%103 = add nsw i32 %29, -1
br label %114
104: ; preds = %94
%105 = load i32, i32* @stderr
%106 = load i8*, i8** %82
%107 = call i64 (i32, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0), i8* %106)
%108 = load i32, i32* @stderr
%109 = load i32, i32* @errno
%110 = call i64 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %109)
%111 = call i32 @exit(i32 1)
unreachable
112: ; preds = %114
%113 = icmp eq i32 %120, %40
br i1 %113, label %129, label %114
114: ; preds = %100, %112
%115 = phi i32 [ 0, %100 ], [ %120, %112 ]
%116 = call i32 @aleat(i32 %102)
%117 = add i32 %103, %116
%118 = call i64 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 %116, i32 %117)
%119 = icmp slt i64 %118, 1
%120 = add nuw nsw i32 %115, 1
br i1 %119, label %121, label %112
121: ; preds = %114
%122 = load i32, i32* @stderr
%123 = load i8*, i8** %82
%124 = call i64 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0), i8* %123)
%125 = load i32, i32* @stderr
%126 = load i32, i32* @errno
%127 = call i64 (i32, i8*, ...) @fprintf(i32 %125, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %126)
%128 = call i32 @exit(i32 1)
unreachable
129: ; preds = %112
%130 = call i64 @fclose(i32* %84)
%131 = icmp eq i64 %130, 0
%132 = load i32, i32* @stderr
%133 = load i8*, i8** %82
br i1 %131, label %140, label %134
134: ; preds = %129
%135 = call i64 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0), i8* %133)
%136 = load i32, i32* @stderr
%137 = load i32, i32* @errno
%138 = call i64 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %137)
%139 = call i32 @exit(i32 1)
unreachable
140: ; preds = %129
%141 = call i64 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.14, i64 0, i64 0), i8* %133)
%142 = call i32 @exit(i32 0)
unreachable
}