#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*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ fwrite(float *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scan_line(int /*<<< orphan*/ *, float *, int);
int main(int argc, char *argv[]) {
  FILE *ftext;
  FILE *ffloat;
  int st, en;
  float *buf;
  long lines;
  if (argc != 5) {
    printf("usage: extract TextFile FloatFile start end\n");
    exit(0);
  }
  ftext = fopen(argv[1], "rt");
  if (ftext == NULL) {
    printf("Error opening text file: %s\n", argv[1]);
    exit(1);
  }
  ffloat = fopen(argv[2], "wb");
  if (ffloat == NULL) {
    printf("Error opening float file: %s\n", argv[2]);
    exit(1);
  }
  st = atoi(argv[3]);
  en = atoi(argv[4]);
  buf = (float *)malloc(en * sizeof(float));
  if (buf == NULL) {
    printf("Error in malloc()\n");
    exit(1);
  }
  lines = 0;
  while (!feof(ftext)) {
    scan_line(ftext, buf, en);
    fwrite(&buf[st - 1], sizeof(float), en - st + 1, ffloat);
    printf("\r%ld lines", lines++);
  }
  printf("\n");
  free(buf);
  fclose(ftext);
  fclose(ffloat);
  return 0;
}


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     11d5 <main+0x35>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe49(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1218 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe26(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    125b <main+0xbb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x28(%rbp)
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12b1 <main+0x111>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12d7 <main+0x137>
jmp    1333 <main+0x193>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1040 <scan_line@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%edx
sub    -0x24(%rbp),%edx
add    $0x1,%edx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   10c0 <fwrite@plt>
mov    -0x38(%rbp),%rsi
mov    %rsi,%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12b9 <main+0x119>
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x5,%edi
jne    12f1 <main+0x131>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe1b(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1304 <main+0x144>
mov    %rax,%r13
mov    0x10(%r14),%rdi
lea    0xe1f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1311 <main+0x151>
mov    %rax,%rbp
mov    0x18(%r14),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
mov    0x20(%r14),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r12d
lea    0x0(,%r12,4),%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     132d <main+0x16d>
mov    %rax,%rbx
mov    %r13,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    12be <main+0xfe>
movslq %r15d,%rax
lea    (%rbx,%rax,4),%rcx
add    $0xfffffffffffffffc,%rcx
mov    %rcx,0x10(%rsp)
mov    %r12d,%ecx
sub    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0xc(%rsp)
xor    %r14d,%r14d
xchg   %ax,%ax
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1060 <scan_line@plt>
mov    0x10(%rsp),%rdi
mov    $0x4,%esi
mov    0xc(%rsp),%edx
mov    %rbp,%rcx
call   10e0 <fwrite@plt>
mov    %r12,%r15
lea    0x1(%r14),%r12
lea    0xd9f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r13,%rdi
call   1090 <feof@plt>
mov    %r12,%r14
mov    %r15,%r12
test   %eax,%eax
je     1270 <main+0xb0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1070 <fclose@plt>
mov    %rbp,%rdi
call   1070 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd66(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x8(%r14),%rsi
lea    0xcf4(%rip),%rdi
jmp    131c <main+0x15c>
mov    0x10(%r14),%rsi
lea    0xd07(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd18(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"usage: extract TextFile FloatFile start end\0A\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [29 x i8] c"Error opening text file: %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [30 x i8] c"Error opening float file: %s\0A\00"
@.str.5 = [19 x i8] c"Error in malloc()\0A\00"
@.str.6 = [11 x i8] c"\0D%ld lines\00"
@.str.7 = [2 x i8] c"\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 float*
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 5
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %7
%35 = load i32*, i32** %7
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %43
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %30
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 3
%46 = load i8*, i8** %45
%47 = call i32 @atoi(i8* %46)
store i32 %47, i32* %8
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 4
%50 = load i8*, i8** %49
%51 = call i32 @atoi(i8* %50)
store i32 %51, i32* %9
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 4
%55 = trunc i64 %54 to i32
%56 = call i64 @malloc(i32 %55)
%57 = inttoptr i64 %56 to float*
store float* %57, float** %10
%58 = load float*, float** %10
%59 = icmp eq float* %58, null
br i1 %59, label %60, label %63
60: ; preds = %43
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %43
store i64 0, i64* %11
br label %64
64: ; preds = %69, %63
%65 = load i32*, i32** %6
%66 = call i32 @feof(i32* %65)
%67 = icmp ne i32 %66, 0
%68 = xor i1 %67, true
br i1 %68, label %69, label %88
69: ; preds = %64
%70 = load i32*, i32** %6
%71 = load float*, float** %10
%72 = load i32, i32* %9
%73 = call i32 @scan_line(i32* %70, float* %71, i32 %72)
%74 = load float*, float** %10
%75 = load i32, i32* %8
%76 = sub nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds float, float* %74, i64 %77
%79 = load i32, i32* %9
%80 = load i32, i32* %8
%81 = sub nsw i32 %79, %80
%82 = add nsw i32 %81, 1
%83 = load i32*, i32** %7
%84 = call i32 @fwrite(float* %78, i32 4, i32 %82, i32* %83)
%85 = load i64, i64* %11
%86 = add nsw i64 %85, 1
store i64 %86, i64* %11
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i64 %85)
br label %64
88: ; preds = %64
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%90 = load float*, float** %10
%91 = call i32 @free(float* %90)
%92 = load i32*, i32** %6
%93 = call i32 @fclose(i32* %92)
%94 = load i32*, i32** %7
%95 = call i32 @fclose(i32* %94)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [29 x i8] c"Error opening text file: %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [30 x i8] c"Error opening float file: %s\0A\00"
@.str.6 = [11 x i8] c"\0D%ld lines\00"
@str = [18 x i8] c"Error in malloc()\00"
@str.8 = [44 x i8] c"usage: extract TextFile FloatFile start end\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.8, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i8*, i8** %8
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %7
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i8*, i8** %17
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %16
%26 = getelementptr inbounds i8*, i8** %1, i64 3
%27 = load i8*, i8** %26
%28 = tail call i32 @atoi(i8* %27)
%29 = getelementptr inbounds i8*, i8** %1, i64 4
%30 = load i8*, i8** %29
%31 = tail call i32 @atoi(i8* %30)
%32 = shl i32 %31, 2
%33 = tail call i64 @malloc(i32 %32)
%34 = inttoptr i64 %33 to float*
%35 = icmp eq i64 %33, 0
br i1 %35, label %45, label %36
36: ; preds = %25
%37 = tail call i32 @feof(i32* %10)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %56
39: ; preds = %36
%40 = add nsw i32 %28, -1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds float, float* %34, i64 %41
%43 = sub i32 1, %28
%44 = add i32 %43, %31
br label %48
45: ; preds = %25
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%47 = tail call i32 @exit(i32 1)
unreachable
48: ; preds = %39, %48
%49 = phi i64 [ 0, %39 ], [ %52, %48 ]
%50 = tail call i32 @scan_line(i32* %10, float* %34, i32 %31)
%51 = tail call i32 @fwrite(float* %42, i32 4, i32 %44, i32* %19)
%52 = add nuw nsw i64 %49, 1
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i64 %49)
%54 = tail call i32 @feof(i32* %10)
%55 = icmp eq i32 %54, 0
br i1 %55, label %48, label %56
56: ; preds = %48, %36
%57 = tail call i32 @putchar(i32 10)
%58 = tail call i32 @free(float* %34)
%59 = tail call i32 @fclose(i32* %10)
%60 = tail call i32 @fclose(i32* %19)
ret i32 0
}