#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 aleatW(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, frac;
  struct stat sdata;
  FILE *ifile, *ofile;
  unsigned char *buff;
  if (argc < 5) {
    fprintf(
        stderr,
        "\nUsage: %s <intsfile> <fraction [2,4,6...]> <number> <intervals "
        "file>\n\n"
        "  randomly extracts <number> intervals of length <length> from "
        "<intsfile>.\n"
        "  randomly extracts, from <file>, <number> intervals of integers "
        "whose length\n"
        "  is (sizeof<intsfile> / <fraction>) uints.\n"
        "  The output file, <intervals file> has a first line of the form:\n"
        "    # number=<number> length=<width> file=<intsfile>\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 / sizeof(unsigned int);
  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);
  }
  frac = m;
  m = n / m;
  fprintf(stderr, "\n The interval-width was set to %u, fraction is= %u\n", m,
          frac);
  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=%lu numwords=%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 = aleatW(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   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <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    0xfad(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
lea    0xfa9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movslq -0x28(%rbp),%rax
shr    $0x2,%rax
mov    %eax,-0x14(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xf87(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1287 <main+0xf7>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    12ab <main+0x11b>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xf6a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,-0x18(%rbp)
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xf67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    1313 <main+0x183>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
lea    0xf6b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf74(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    137f <main+0x1ef>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xf4a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
mov    0x2c73(%rip),%rax
mov    (%rax),%edx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    13da <main+0x24a>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xf17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2c29(%rip),%rax
mov    (%rax),%edi
mov    0x2c18(%rip),%rax
mov    (%rax),%edx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1441 <main+0x2b1>
mov    0x2be1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xed1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2bc2(%rip),%rax
mov    (%rax),%edi
mov    0x2bb1(%rip),%rax
mov    (%rax),%edx
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xea4(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    14b6 <main+0x326>
mov    0x2b6c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2b4d(%rip),%rax
mov    (%rax),%edi
mov    0x2b3c(%rip),%rax
mov    (%rax),%edx
lea    0xd2f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <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    0xe56(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmp    $0x0,%rax
jg     152b <main+0x39b>
mov    0x2af7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2ad8(%rip),%rax
mov    (%rax),%edi
mov    0x2ac7(%rip),%rax
mov    (%rax),%edx
lea    0xcba(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    15d5 <main+0x445>
mov    -0x14(%rbp),%edi
sub    -0x18(%rbp),%edi
add    $0x1,%edi
call   10b0 <aleatW@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    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmp    $0x0,%rax
jg     15c2 <main+0x432>
mov    0x2a60(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2a41(%rip),%rax
mov    (%rax),%edi
mov    0x2a30(%rip),%rax
mov    (%rax),%edx
lea    0xc23(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    15c7 <main+0x437>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1532 <main+0x3a2>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1631 <main+0x4a1>
mov    0x29f1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xd49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x29d2(%rip),%rax
mov    (%rax),%edi
mov    0x29c1(%rip),%rax
mov    (%rax),%edx
lea    0xbb4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x29a8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <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   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x8(%r14),%rdi
mov    %rsp,%rsi
call   1060 <stat@plt>
test   %rax,%rax
jne    1256 <main+0xc6>
mov    (%rsp),%r15d
sar    $0x2,%r15d
mov    0x2df9(%rip),%r13
mov    0x0(%r13),%edi
lea    0xfef(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x10(%r14),%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jle    1285 <main+0xf5>
mov    %eax,%ecx
cmp    %r15d,%eax
jg     1285 <main+0xf5>
mov    %r15d,%eax
cltd
idiv   %ecx
mov    %eax,%r12d
mov    0x0(%r13),%edi
lea    0x1014(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x18(%r14),%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jg     12a4 <main+0x114>
mov    0x0(%r13),%edi
lea    0x1028(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d83(%rip),%rbx
mov    (%rbx),%edi
mov    0x8(%r14),%rdx
lea    0xf4e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
mov    0x2d5e(%rip),%rax
mov    (%rax),%edx
lea    0xf51(%rip),%rsi
jmp    1293 <main+0x103>
mov    0x0(%r13),%edi
lea    0xf74(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %eax,%ebp
mov    0x8(%r14),%rdi
lea    0xfe5(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    12cf <main+0x13f>
mov    0x0(%r13),%edi
mov    0x8(%r14),%rdx
lea    0xfce(%rip),%rsi
jmp    1380 <main+0x1f0>
mov    %rax,%rbx
mov    %r15d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
jne    12f9 <main+0x169>
mov    0x0(%r13),%edi
lea    0xfd6(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1387 <main+0x1f7>
mov    %rax,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    133f <main+0x1af>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x20(%r14),%rdi
lea    0xfd9(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    1350 <main+0x1c0>
mov    0x0(%r13),%edi
mov    0x20(%r14),%rdx
lea    0xfc2(%rip),%rsi
jmp    1380 <main+0x1f0>
mov    0x0(%r13),%edi
mov    0x8(%r14),%rdx
lea    0xf93(%rip),%rsi
jmp    1380 <main+0x1f0>
mov    %rax,%rbx
mov    0x8(%r14),%r8
lea    0xfc9(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %rax,%rax
jg     1390 <main+0x200>
mov    0x0(%r13),%edi
mov    0x20(%r14),%rdx
lea    0xfc9(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%r13),%edi
jmp    1273 <main+0xe3>
sub    %r12d,%r15d
add    $0x1,%r15d
add    $0xffffffff,%r12d
lea    0xfc4(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15d,%edi
call   10b0 <aleatW@plt>
lea    (%r12,%rax,1),%ecx
mov    %ebx,%edi
mov    %r13,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %rax,%rax
jle    13fa <main+0x26a>
add    $0xffffffff,%ebp
jne    13b0 <main+0x220>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2bfd(%rip),%rbx
mov    (%rbx),%edi
mov    0x20(%r14),%rdx
test   %rax,%rax
jne    1407 <main+0x277>
lea    0xf78(%rip),%rsi
jmp    11b6 <main+0x26>
mov    0x2bdf(%rip),%rbx
mov    (%rbx),%edi
mov    0x20(%r14),%rdx
lea    0xf3b(%rip),%rsi
jmp    126a <main+0xda>

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

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