#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, frac;
  struct stat sdata;
  FILE *ifile, *ofile;
  unsigned char *buff;
  if (argc < 5) {
    fprintf(
        stderr,
        "\nUsage: %s <file> <fraction [2,4,6...]> <number> <intervals file>\n\n"
        "  randomly extracts, from <file>, <number> intervals whose length is "
        "(sizeof<file> / <fraction>) chars.\n"
        "  The output file, <intervals file> has a first line of the form:\n"
        "    # number=<number> length=<width> 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: <fraction> 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=%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    0xf48(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
lea    0xf44(%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    0xf27(%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    0xf0a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,-0x18(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xf0b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    130e <main+0x17e>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
lea    0xf0f(%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    0xf19(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    137a <main+0x1ea>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xeef(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
mov    0x2c78(%rip),%rax
mov    (%rax),%edx
lea    0xe06(%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    13d5 <main+0x245>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xebc(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c2e(%rip),%rax
mov    (%rax),%edi
mov    0x2c1d(%rip),%rax
mov    (%rax),%edx
lea    0xdab(%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     143c <main+0x2ac>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
mov    0x2bb6(%rip),%rax
mov    (%rax),%edx
lea    0xd44(%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    0xe49(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    14b1 <main+0x321>
mov    0x2b71(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2b52(%rip),%rax
mov    (%rax),%edi
mov    0x2b41(%rip),%rax
mov    (%rax),%edx
lea    0xccf(%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    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmp    $0x0,%rax
jg     1526 <main+0x396>
mov    0x2afc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2add(%rip),%rax
mov    (%rax),%edi
mov    0x2acc(%rip),%rax
mov    (%rax),%edx
lea    0xc5a(%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    15d0 <main+0x440>
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    0xda0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmp    $0x0,%rax
jg     15bd <main+0x42d>
mov    0x2a65(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2a46(%rip),%rax
mov    (%rax),%edi
mov    0x2a35(%rip),%rax
mov    (%rax),%edx
lea    0xbc3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    15c2 <main+0x432>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    152d <main+0x39d>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     162c <main+0x49c>
mov    0x29f6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xceb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x29d7(%rip),%rax
mov    (%rax),%edi
mov    0x29c6(%rip),%rax
mov    (%rax),%edx
lea    0xb54(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x29ad(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xcc6(%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    1252 <main+0xc2>
mov    (%rsp),%r15d
mov    0x2dfd(%rip),%r13
mov    0x0(%r13),%edi
lea    0xf8e(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x10(%r14),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
jle    1281 <main+0xf1>
mov    %eax,%ecx
cmp    %r15d,%eax
jg     1281 <main+0xf1>
mov    %r15d,%eax
cltd
idiv   %ecx
mov    %eax,%r12d
mov    0x0(%r13),%edi
lea    0xfb7(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x18(%r14),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
jg     12a0 <main+0x110>
mov    0x0(%r13),%edi
lea    0xfcb(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d87(%rip),%rbx
mov    (%rbx),%edi
mov    0x8(%r14),%rdx
lea    0xeed(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
mov    0x2d62(%rip),%rax
mov    (%rax),%edx
lea    0xef0(%rip),%rsi
jmp    128f <main+0xff>
mov    0x0(%r13),%edi
lea    0xf13(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%ebp
mov    0x8(%r14),%rdi
lea    0xf89(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    12cb <main+0x13b>
mov    0x0(%r13),%edi
mov    0x8(%r14),%rdx
lea    0xf72(%rip),%rsi
jmp    137c <main+0x1ec>
mov    %rax,%rbx
mov    %r15d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
jne    12f5 <main+0x165>
mov    0x0(%r13),%edi
lea    0xf7a(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1383 <main+0x1f3>
mov    %rax,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    133b <main+0x1ab>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x20(%r14),%rdi
lea    0xf7d(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    134c <main+0x1bc>
mov    0x0(%r13),%edi
mov    0x20(%r14),%rdx
lea    0xf66(%rip),%rsi
jmp    137c <main+0x1ec>
mov    0x0(%r13),%edi
mov    0x8(%r14),%rdx
lea    0xf37(%rip),%rsi
jmp    137c <main+0x1ec>
mov    %rax,%rbx
mov    0x8(%r14),%r8
lea    0xf6d(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %rax,%rax
jg     138c <main+0x1fc>
mov    0x0(%r13),%edi
mov    0x20(%r14),%rdx
lea    0xf6a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%r13),%edi
jmp    126f <main+0xdf>
sub    %r12d,%r15d
add    $0x1,%r15d
add    $0xffffffff,%r12d
lea    0xf65(%rip),%r13
xchg   %ax,%ax
mov    %r15d,%edi
call   1030 <aleat@plt>
lea    (%r12,%rax,1),%ecx
mov    %ebx,%edi
mov    %r13,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %rax,%rax
jle    13ea <main+0x25a>
add    $0xffffffff,%ebp
jne    13a0 <main+0x210>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2c0d(%rip),%rbx
mov    (%rbx),%edi
mov    0x20(%r14),%rdx
test   %rax,%rax
jne    13f7 <main+0x267>
lea    0xf25(%rip),%rsi
jmp    11b6 <main+0x26>
mov    0x2bef(%rip),%rbx
mov    (%rbx),%edi
mov    0x20(%r14),%rdx
lea    0xee8(%rip),%rsi
jmp    1266 <main+0xd6>

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

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