#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,
        "\nUsage: %s <file> <length> <number> <intervals file>\n\n"
        "  randomly extracts <number> intervals of length <length> chars 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\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;
  fprintf(stderr, "\n max value to be generated is %i\n", n);
  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(1);
}


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    0xf21(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
lea    0xf1d(%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    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xf00(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1282 <main+0xf2>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    12a6 <main+0x116>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xee3(%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    12e1 <main+0x151>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xedc(%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    0xee5(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    134d <main+0x1bd>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xebb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
mov    0x2ca5(%rip),%rax
mov    (%rax),%edx
lea    0xe0c(%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    13a8 <main+0x218>
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
mov    0x2c4a(%rip),%rax
mov    (%rax),%edx
lea    0xdb1(%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     140f <main+0x27f>
mov    0x2c13(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
mov    0x2be3(%rip),%rax
mov    (%rax),%edx
lea    0xd4a(%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    0xe15(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1484 <main+0x2f4>
mov    0x2b9e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2b7f(%rip),%rax
mov    (%rax),%edi
mov    0x2b6e(%rip),%rax
mov    (%rax),%edx
lea    0xcd5(%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    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmp    $0x0,%rax
jg     14f9 <main+0x369>
mov    0x2b29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xdbd(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2b0a(%rip),%rax
mov    (%rax),%edi
mov    0x2af9(%rip),%rax
mov    (%rax),%edx
lea    0xc60(%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    15a3 <main+0x413>
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    0xd6c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmp    $0x0,%rax
jg     1590 <main+0x400>
mov    0x2a92(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xd26(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2a73(%rip),%rax
mov    (%rax),%edi
mov    0x2a62(%rip),%rax
mov    (%rax),%edx
lea    0xbc9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1595 <main+0x405>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1500 <main+0x370>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     15ff <main+0x46f>
mov    0x2a23(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xcb7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2a04(%rip),%rax
mov    (%rax),%edi
mov    0x29f3(%rip),%rax
mov    (%rax),%edx
lea    0xb5a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x29da(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xc92(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%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    1237 <main+0xa7>
mov    (%rsp),%r12d
mov    0x2dfd(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xf68(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x10(%r14),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
jle    1266 <main+0xd6>
mov    %eax,%r15d
mov    %r12d,%r13d
sub    %eax,%r13d
jl     1266 <main+0xd6>
mov    0x18(%r14),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
jg     1284 <main+0xf4>
mov    0x0(%rbp),%edi
lea    0xf86(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2da2(%rip),%rbx
mov    (%rbx),%edi
mov    0x8(%r14),%rdx
lea    0xee1(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
lea    0xee4(%rip),%rsi
jmp    1273 <main+0xe3>
mov    0x0(%rbp),%edi
lea    0xf08(%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    0xf44(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    12b1 <main+0x121>
mov    0x2d3e(%rip),%rbx
mov    (%rbx),%edi
mov    0x8(%r14),%rdx
lea    0xf28(%rip),%rsi
jmp    124b <main+0xbb>
mov    %rax,%rbp
mov    %r12d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
jne    12e0 <main+0x150>
mov    0x2d18(%rip),%rbx
mov    (%rbx),%edi
lea    0xf2e(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1252 <main+0xc2>
mov    %rax,%rdi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    132e <main+0x19e>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    0x20(%r14),%rdi
lea    0xf31(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    1347 <main+0x1b7>
mov    0x2cc4(%rip),%rbx
mov    (%rbx),%edi
mov    0x20(%r14),%rdx
lea    0xf15(%rip),%rsi
jmp    124b <main+0xbb>
mov    0x2cab(%rip),%rbx
mov    (%rbx),%edi
mov    0x8(%r14),%rdx
lea    0xede(%rip),%rsi
jmp    124b <main+0xbb>
mov    %rax,%rbp
mov    0x8(%r14),%r8
lea    0xf11(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %rax,%rax
jg     1381 <main+0x1f1>
mov    0x2c71(%rip),%rbx
mov    (%rbx),%edi
mov    0x20(%r14),%rdx
lea    0xf09(%rip),%rsi
jmp    124b <main+0xbb>
add    $0x1,%r13d
add    $0xffffffff,%r15d
lea    0xf12(%rip),%r12
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    1368 <main+0x1d8>
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    1375 <main+0x1e5>
lea    0xed4(%rip),%rsi
jmp    11b6 <main+0x26>

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

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