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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int *malloc(int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int *read_sequence(const char *filename, int window, int max) {
  FILE *fp;
  int i;
  char line[32];
  double loc;
  int *seq;
  if ((fp = fopen(filename, "r")) == NULL) {
    fprintf(stderr, "file open error\n");
    exit(1);
  }
  seq = malloc(max * sizeof(int));
  for (i = 0; i < max; i++)
    seq[i] = 0;
  while (fgets(line, sizeof(line), fp) != NULL) {
    if (sscanf(line, "%d", &i) != 1) {
      fprintf(stderr, "file read error\n");
      exit(1);
    }
    loc = (float)i / (float)window;
    if (loc >= max) {
      fprintf(stderr, "maximum length exceeded\n");
    }
    seq[(int)loc]++;
  }
  return seq;
}


x86 assembly (clang, -O0):
<read_sequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11af <read_sequence+0x4f>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11f2 <read_sequence+0x92>
mov    -0x50(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c9 <read_sequence+0x69>
jmp    11f7 <read_sequence+0x97>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x20,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     12a9 <read_sequence+0x149>
lea    -0x40(%rbp),%rdi
lea    0xdf5(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     124f <read_sequence+0xef>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cvtsi2ssl -0x1c(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     128f <read_sequence+0x12f>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x50(%rbp),%rax
cvttsd2si -0x48(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    11f7 <read_sequence+0x97>
mov    -0x50(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_sequence>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,%r15d
mov    %esi,%ebp
lea    0xe76(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12c0 <read_sequence+0x150>
mov    %rax,%r14
lea    0x0(,%r15,4),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %r15d,%r15d
jle    11c6 <read_sequence+0x56>
mov    %r15d,%edx
shl    $0x2,%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    %r15d,%eax
jmp    11c8 <read_sequence+0x58>
xor    %eax,%eax
mov    %eax,0xc(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     128f <read_sequence+0x11f>
cvtsi2ss %ebp,%xmm0
movss  %xmm0,0x14(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
movsd  %xmm0,0x18(%rsp)
lea    0xe0d(%rip),%r15
lea    0x20(%rsp),%rbp
lea    0xc(%rsp),%r12
lea    0xe10(%rip),%r13
jmp    123f <read_sequence+0xcf>
nopl   0x0(%rax)
cvttss2si %xmm1,%eax
cltq
addl   $0x1,(%rbx,%rax,4)
mov    %rbp,%rdi
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     128f <read_sequence+0x11f>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    12a1 <read_sequence+0x131>
xorps  %xmm1,%xmm1
cvtsi2ssl 0xc(%rsp),%xmm1
divss  0x14(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
ucomisd 0x18(%rsp),%xmm0
jb     1220 <read_sequence+0xb0>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
movss  %xmm1,0x10(%rsp)
call   1050 <fprintf@plt>
movss  0x10(%rsp),%xmm1
jmp    1220 <read_sequence+0xb0>
mov    %rbx,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xd32(%rip),%rsi
jmp    12b1 <read_sequence+0x141>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"file open error\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [17 x i8] c"file read error\0A\00"
@.str.4 = [25 x i8] c"maximum length exceeded\0A\00"
define i32* @read_sequence(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [32 x i8]
%10 = alloca double
%11 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %3
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 4
%23 = trunc i64 %22 to i32
%24 = call i32* @malloc(i32 %23)
store i32* %24, i32** %11
store i32 0, i32* %8
br label %25
25: ; preds = %34, %19
%26 = load i32, i32* %8
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = load i32*, i32** %11
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
store i32 0, i32* %33
br label %34
34: ; preds = %29
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %25
37: ; preds = %25
br label %38
38: ; preds = %65, %37
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%40 = load i32*, i32** %7
%41 = call i32* @fgets(i8* %39, i32 32, i32* %40)
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %73
43: ; preds = %38
%44 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%45 = call i32 @sscanf(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%46 = icmp ne i32 %45, 1
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %43
%52 = load i32, i32* %8
%53 = sitofp i32 %52 to float
%54 = load i32, i32* %5
%55 = sitofp i32 %54 to float
%56 = fdiv float %53, %55
%57 = fpext float %56 to double
store double %57, double* %10
%58 = load double, double* %10
%59 = load i32, i32* %6
%60 = sitofp i32 %59 to double
%61 = fcmp oge double %58, %60
br i1 %61, label %62, label %65
62: ; preds = %51
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %65
65: ; preds = %62, %51
%66 = load i32*, i32** %11
%67 = load double, double* %10
%68 = fptosi double %67 to i32
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %66, i64 %69
%71 = load i32, i32* %70
%72 = add nsw i32 %71, 1
store i32 %72, i32* %70
br label %38
73: ; preds = %38
%74 = load i32*, i32** %11
ret i32* %74
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"file open error\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [17 x i8] c"file read error\0A\00"
@.str.4 = [25 x i8] c"maximum length exceeded\0A\00"
define noalias i32* @read_sequence(i8* nocapture %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca [32 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %3
%15 = shl i32 %2, 2
%16 = tail call i32* @malloc(i32 %15)
%17 = icmp sgt i32 %2, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = bitcast i32* %16 to i8*
%20 = zext i32 %2 to i64
%21 = shl nuw nsw i64 %20, 2
br label %22
22: ; preds = %18, %14
%23 = phi i32 [ 0, %14 ], [ %2, %18 ]
store i32 %23, i32* %4
%24 = call i32* @fgets(i8* %7, i32 32, i32* %8)
%25 = icmp eq i32* %24, null
br i1 %25, label %53, label %26
26: ; preds = %22
%27 = sitofp i32 %1 to float
%28 = sitofp i32 %2 to double
br label %29
29: ; preds = %26, %45
%30 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%31 = icmp eq i32 %30, 1
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %29
%37 = load i32, i32* %4
%38 = sitofp i32 %37 to float
%39 = fdiv float %38, %27
%40 = fpext float %39 to double
%41 = fcmp ult double %40, %28
br i1 %41, label %45, label %42
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %42, %36
%46 = fptosi float %39 to i32
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %16, i64 %47
%49 = load i32, i32* %48
%50 = add nsw i32 %49, 1
store i32 %50, i32* %48
%51 = call i32* @fgets(i8* %7, i32 32, i32* %8)
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %29
53: ; preds = %45, %22
ret i32* %16
}