#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 sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int max_length(const char *filename, int window) {
  FILE *fp;
  char line[32];
  int i, loc, max;
  if ((fp = fopen(filename, "r")) == NULL) {
    fprintf(stderr, "file open error\n");
    exit(1);
  }
  max = 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)
      max = loc;
  }
  return max + 1;
}


x86 assembly (clang, -O0):
<max_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119c <max_length+0x4c>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x4c(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x20,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     1227 <max_length+0xd7>
lea    -0x40(%rbp),%rdi
lea    0xe49(%rip),%rsi
lea    -0x44(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11fb <max_length+0xab>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cvtsi2ssl -0x44(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jle    1222 <max_length+0xd2>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    11a3 <max_length+0x53>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<max_length>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %esi,%ebx
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1228 <max_length+0xd8>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
mov    %rax,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     11f5 <max_length+0xa5>
cvtsi2ss %ebx,%xmm0
movss  %xmm0,0x8(%rsp)
xor    %ebp,%ebp
lea    0xe73(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1209 <max_length+0xb9>
xorps  %xmm0,%xmm0
cvtsi2ssl 0xc(%rsp),%xmm0
divss  0x8(%rsp),%xmm0
cvttss2si %xmm0,%eax
cmp    %eax,%ebp
cmovl  %eax,%ebp
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %r15,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
jne    11b0 <max_length+0x60>
add    $0x1,%ebp
jmp    11fa <max_length+0xaa>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
jmp    1219 <max_length+0xc9>

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"
define i32 @max_length(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [32 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
store i32 0, i32* %9
br label %18
18: ; preds = %43, %17
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i32* @fgets(i8* %19, i32 32, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %44
23: ; preds = %18
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%25 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
%32 = load i32, i32* %7
%33 = sitofp i32 %32 to float
%34 = load i32, i32* %4
%35 = sitofp i32 %34 to float
%36 = fdiv float %33, %35
%37 = fptosi float %36 to i32
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = icmp sgt i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %31
%42 = load i32, i32* %8
store i32 %42, i32* %9
br label %43
43: ; preds = %41, %31
br label %18
44: ; preds = %18
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
ret i32 %46
}

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"
define i32 @max_length(i8* nocapture %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = call i32* @fgets(i8* %5, i32 32, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %37, label %12
12: ; preds = %9
%13 = sitofp i32 %1 to float
br label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %12, %26
%19 = phi i32 [ 0, %12 ], [ %32, %26 ]
%20 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%21 = icmp eq i32 %20, 1
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = load i32, i32* %4
%28 = sitofp i32 %27 to float
%29 = fdiv float %28, %13
%30 = fptosi float %29 to i32
%31 = icmp slt i32 %19, %30
%32 = select i1 %31, i32 %30, i32 %19
%33 = call i32* @fgets(i8* %5, i32 32, i32* %7)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %18
35: ; preds = %26
%36 = add i32 %32, 1
br label %37
37: ; preds = %35, %9
%38 = phi i32 [ 1, %9 ], [ %36, %35 ]
ret i32 %38
}