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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char const *argv[]) {
  int a[] = {0, 5, -3, -1, 2, -4, 1, 7, 8};
  int size = sizeof(a) / sizeof(a[0]);
  int maxSum = 0, l = 2, sumL = 0;
  for (int i = 0; i < l; ++i) {
    sumL += a[i];
  }
  maxSum = sumL;
  for (int i = l; i < size; ++i) {
    sumL = sumL - a[i - l] + a[i];
    if (sumL > maxSum) {
      maxSum = sumL;
    }
  }
  printf("Maximum sum of length %d is %d\n", l, maxSum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xebf(%rip),%rsi
mov    $0x24,%edx
call   1040 <memcpy@plt>
movl   $0x9,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x2,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    1196 <main+0x76>
movslq -0x54(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
add    -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    116e <main+0x4e>
mov    -0x50(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11ee <main+0xce>
mov    -0x50(%rbp),%eax
mov    -0x58(%rbp),%ecx
sub    -0x4c(%rbp),%ecx
movslq %ecx,%rcx
sub    -0x40(%rbp,%rcx,4),%eax
movslq -0x58(%rbp),%rcx
add    -0x40(%rbp,%rcx,4),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x48(%rbp),%eax
jle    11db <main+0xbb>
mov    -0x50(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    11e0 <main+0xc0>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11a2 <main+0x82>
mov    -0x4c(%rbp),%esi
mov    -0x48(%rbp),%edx
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
mov    $0x2,%esi
mov    $0xf,%edx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@__const.main.a = [9 x i32] [i32 0, i32 5, i32 -3, i32 -1, i32 2, i32 -4, i32 1, i32 7, i32 8]
@.str = [32 x i8] c"Maximum sum of length %d is %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [9 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [9 x i32]* %6 to i8*
store i32 9, i32* %7
store i32 0, i32* %8
store i32 2, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %14
14: ; preds = %25, %2
%15 = load i32, i32* %11
%16 = load i32, i32* %9
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = load i32, i32* %11
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = load i32, i32* %10
%24 = add nsw i32 %23, %22
store i32 %24, i32* %10
br label %25
25: ; preds = %18
%26 = load i32, i32* %11
%27 = add nsw i32 %26, 1
store i32 %27, i32* %11
br label %14
28: ; preds = %14
%29 = load i32, i32* %10
store i32 %29, i32* %8
%30 = load i32, i32* %9
store i32 %30, i32* %12
br label %31
31: ; preds = %55, %28
%32 = load i32, i32* %12
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %58
35: ; preds = %31
%36 = load i32, i32* %10
%37 = load i32, i32* %12
%38 = load i32, i32* %9
%39 = sub nsw i32 %37, %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = sub nsw i32 %36, %42
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = add nsw i32 %43, %47
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = load i32, i32* %8
%51 = icmp sgt i32 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %35
%53 = load i32, i32* %10
store i32 %53, i32* %8
br label %54
54: ; preds = %52, %35
br label %55
55: ; preds = %54
%56 = load i32, i32* %12
%57 = add nsw i32 %56, 1
store i32 %57, i32* %12
br label %31
58: ; preds = %31
%59 = load i32, i32* %9
%60 = load i32, i32* %8
%61 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %59, i32 %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Maximum sum of length %d is %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 2, i32 15)
ret i32 0
}