#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 */
typedef int /*<<< orphan*/ gzFile;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(double *);
int fwrite(double *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ getGz(char const *, char *);
int /*<<< orphan*/ gzclose(int /*<<< orphan*/);
int gzread(int /*<<< orphan*/, double *, int);
double *malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  if (argc != 5) {
    fprintf(stderr,
            "\nProgram extract ranges from output of msToGlf\n./splitgl "
            "file.glf.gz nindTotal firstInd lastInd\n");
    fprintf(stderr, "\nTo extract first the GLS for the first 10 samples in an "
                    "glf.gz that contains 25 samples\n");
    fprintf(stderr, "./splitgl file.glf.gz 25 10\n");
    return 0;
  }
  const char *fname = argv[1];
  int tot = atoi(argv[2]);
  int first = atoi(argv[3]);
  int last = atoi(argv[4]);
  first--;
  last--;
  fprintf(stderr, "fname:%s tot:%d first:%d last:%d\n", fname, tot, first,
          last);
  gzFile gz = getGz(fname, "r");
  double *lk = malloc(sizeof(double) * 10 * tot);
  int nsites = 0;
  while (1) {
    int br = gzread(gz, lk, 10 * sizeof(double) * tot);
    nsites++;
    if (br == 0)
      break;
    assert(br == 10 * sizeof(double) * tot);
    int beg = 10 * first;
    int nDoubles = (last - first + 1) * 10;
    br = fwrite(lk + beg, sizeof(double), nDoubles, stdout);
    if (br != nDoubles) {
      fprintf(stderr, "Problem writing full chunk\n");
      return 0;
    }
  }
  fprintf(stderr, "nsites:%d processed\n", nsites);
  free(lk);
  gzclose(gz);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     1201 <main+0x71>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xecd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    138c <main+0x1fc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1050 <getGz@plt>
mov    %eax,-0x28(%rbp)
movslq -0x1c(%rbp),%rax
imul   $0x50,%rax,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x30(%rbp),%rsi
movslq -0x1c(%rbp),%rax
imul   $0x50,%rax,%rax
mov    %eax,%edx
call   1070 <gzread@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    12d3 <main+0x143>
jmp    1361 <main+0x1d1>
movslq -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x50,%rcx,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
imul   $0xa,-0x20(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x24(%rbp),%eax
sub    -0x20(%rbp),%eax
add    $0x1,%eax
imul   $0xa,%eax,%eax
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x40(%rbp),%edx
mov    0x2cba(%rip),%rax
mov    (%rax),%ecx
mov    $0x8,%esi
call   10b0 <fwrite@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x40(%rbp),%eax
je     135c <main+0x1cc>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    138c <main+0x1fc>
jmp    12a2 <main+0x112>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%edi
call   1030 <gzclose@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x5,%edi
jne    1293 <main+0x103>
mov    %rsi,%rbx
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r15d
mov    0x18(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
mov    0x20(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebx
lea    -0x1(%rbp),%r12d
add    $0xffffffff,%ebx
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xef4(%rip),%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xefc(%rip),%rsi
mov    %r14,%rdi
call   1050 <getGz@plt>
mov    %eax,%r14d
movslq %r15d,%rax
shl    $0x4,%rax
lea    (%rax,%rax,4),%r13
mov    %r13d,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
lea    -0x2(%rbp,%rbp,1),%eax
lea    (%rax,%rax,4),%eax
sub    %r12d,%ebx
lea    (%rbx,%rbx,4),%ecx
lea    (%rcx,%rcx,1),%ebp
add    $0xa,%ebp
cltq
lea    (%r15,%rax,8),%r12
mov    $0x1,%ebx
nopl   (%rax)
mov    %r14d,%edi
mov    %r15,%rsi
mov    %r13d,%edx
call   1070 <gzread@plt>
test   %eax,%eax
je     12cc <main+0x13c>
cltq
xor    %edi,%edi
cmp    %rax,%r13
sete   %dil
call   1060 <assert@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%ecx
mov    %r12,%rdi
mov    $0x8,%esi
mov    %ebp,%edx
call   10b0 <fwrite@plt>
add    $0x1,%ebx
cmp    %ebp,%eax
je     1240 <main+0xb0>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
jmp    12c3 <main+0x133>
mov    0x2d46(%rip),%rbx
mov    (%rbx),%edi
lea    0xd5d(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdae(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdf8(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12f5 <main+0x165>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r14d,%edi
call   1030 <gzclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [97 x i8] c"\0AProgram extract ranges from output of msToGlf\0A./splitgl file.glf.gz nindTotal firstInd lastInd\0A\00"
@.str.1 = [90 x i8] c"\0ATo extract first the GLS for the first 10 samples in an glf.gz that contains 25 samples\0A\00"
@.str.2 = [29 x i8] c"./splitgl file.glf.gz 25 10\0A\00"
@.str.3 = [34 x i8] c"fname:%s tot:%d first:%d last:%d\0A\00"
@.str.4 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.5 = [28 x i8] c"Problem writing full chunk\0A\00"
@.str.6 = [21 x i8] c"nsites:%d processed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double*
%12 = alloca i32
%13 = alloca i32
%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 ne i32 %16, 5
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %109
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %7
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %8
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 4
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %9
%41 = load i32, i32* %8
%42 = add nsw i32 %41, -1
store i32 %42, i32* %8
%43 = load i32, i32* %9
%44 = add nsw i32 %43, -1
store i32 %44, i32* %9
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %6
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = load i32, i32* %9
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %46, i32 %47, i32 %48, i32 %49)
%51 = load i8*, i8** %6
%52 = call i32 @getGz(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 %52, i32* %10
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = mul i64 80, %54
%56 = trunc i64 %55 to i32
%57 = call double* @malloc(i32 %56)
store double* %57, double** %11
store i32 0, i32* %12
br label %58
58: ; preds = %25, %100
%59 = load i32, i32* %10
%60 = load double*, double** %11
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = mul i64 80, %62
%64 = trunc i64 %63 to i32
%65 = call i32 @gzread(i32 %59, double* %60, i32 %64)
store i32 %65, i32* %13
%66 = load i32, i32* %12
%67 = add nsw i32 %66, 1
store i32 %67, i32* %12
%68 = load i32, i32* %13
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %58
br label %101
71: ; preds = %58
%72 = load i32, i32* %13
%73 = sext i32 %72 to i64
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = mul i64 80, %75
%77 = icmp eq i64 %73, %76
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = load i32, i32* %8
%81 = mul nsw i32 10, %80
store i32 %81, i32* %14
%82 = load i32, i32* %9
%83 = load i32, i32* %8
%84 = sub nsw i32 %82, %83
%85 = add nsw i32 %84, 1
%86 = mul nsw i32 %85, 10
store i32 %86, i32* %15
%87 = load double*, double** %11
%88 = load i32, i32* %14
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds double, double* %87, i64 %89
%91 = load i32, i32* %15
%92 = load i32, i32* @stdout
%93 = call i32 @fwrite(double* %90, i32 8, i32 %91, i32 %92)
store i32 %93, i32* %13
%94 = load i32, i32* %13
%95 = load i32, i32* %15
%96 = icmp ne i32 %94, %95
br i1 %96, label %97, label %100
97: ; preds = %71
%98 = load i32, i32* @stderr
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %109
100: ; preds = %71
br label %58
101: ; preds = %70
%102 = load i32, i32* @stderr
%103 = load i32, i32* %12
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %103)
%105 = load double*, double** %11
%106 = call i32 @free(double* %105)
%107 = load i32, i32* %10
%108 = call i32 @gzclose(i32 %107)
br label %109
109: ; preds = %101, %97, %18
%110 = load i32, i32* %3
ret i32 %110
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [97 x i8] c"\0AProgram extract ranges from output of msToGlf\0A./splitgl file.glf.gz nindTotal firstInd lastInd\0A\00"
@.str.1 = [90 x i8] c"\0ATo extract first the GLS for the first 10 samples in an glf.gz that contains 25 samples\0A\00"
@.str.2 = [29 x i8] c"./splitgl file.glf.gz 25 10\0A\00"
@.str.3 = [34 x i8] c"fname:%s tot:%d first:%d last:%d\0A\00"
@.str.4 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.5 = [28 x i8] c"Problem writing full chunk\0A\00"
@.str.6 = [21 x i8] c"nsites:%d processed\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %59
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 4
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = add nsw i32 %19, -1
%24 = add nsw i32 %22, -1
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %13, i32 %16, i32 %23, i32 %24)
%27 = tail call i32 @getGz(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%28 = sext i32 %16 to i64
%29 = mul nsw i64 %28, 80
%30 = trunc i64 %29 to i32
%31 = tail call double* @malloc(i32 %30)
%32 = mul nsw i32 %23, 10
%33 = sub nsw i32 %24, %23
%34 = mul i32 %33, 10
%35 = add i32 %34, 10
%36 = sext i32 %32 to i64
%37 = getelementptr inbounds double, double* %31, i64 %36
br label %38
38: ; preds = %43, %11
%39 = phi i32 [ 0, %11 ], [ %41, %43 ]
%40 = tail call i32 @gzread(i32 %27, double* %31, i32 %30)
%41 = add nuw nsw i32 %39, 1
%42 = icmp eq i32 %40, 0
br i1 %42, label %54, label %43
43: ; preds = %38
%44 = sext i32 %40 to i64
%45 = icmp eq i64 %29, %44
%46 = zext i1 %45 to i32
%47 = tail call i32 @assert(i32 %46)
%48 = load i32, i32* @stdout
%49 = tail call i32 @fwrite(double* %37, i32 8, i32 %35, i32 %48)
%50 = icmp eq i32 %49, %35
br i1 %50, label %38, label %51
51: ; preds = %43
%52 = load i32, i32* @stderr
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %59
54: ; preds = %38
%55 = load i32, i32* @stderr
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %41)
%57 = tail call i32 @free(double* %31)
%58 = tail call i32 @gzclose(i32 %27)
br label %59
59: ; preds = %51, %54, %4
ret i32 0
}