#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;
  int currentSum = sumL;
  for (int i = l; i < size; ++i) {
    if (currentSum < 0) {
      currentSum = currentSum - a[i - l] + a[i];
    } else
      currentSum += a[i];
    if (currentSum > maxSum) {
      maxSum = currentSum;
    }
  }
  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    -0x50(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1211 <main+0xf1>
cmpl   $0x0,-0x58(%rbp)
jge    11de <main+0xbe>
mov    -0x58(%rbp),%eax
mov    -0x5c(%rbp),%ecx
sub    -0x4c(%rbp),%ecx
movslq %ecx,%rcx
sub    -0x40(%rbp,%rcx,4),%eax
movslq -0x5c(%rbp),%rcx
add    -0x40(%rbp,%rcx,4),%eax
mov    %eax,-0x58(%rbp)
jmp    11ec <main+0xcc>
movslq -0x5c(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x48(%rbp),%eax
jle    11fe <main+0xde>
mov    -0x58(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    1203 <main+0xe3>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11a8 <main+0x88>
mov    -0x4c(%rbp),%esi
mov    -0x48(%rbp),%edx
lea    0xe06(%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    $0x11,%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 = [34 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
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = 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 %15
15: ; preds = %26, %2
%16 = load i32, i32* %11
%17 = load i32, i32* %9
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = load i32, i32* %10
%25 = add nsw i32 %24, %23
store i32 %25, i32* %10
br label %26
26: ; preds = %19
%27 = load i32, i32* %11
%28 = add nsw i32 %27, 1
store i32 %28, i32* %11
br label %15
29: ; preds = %15
%30 = load i32, i32* %10
store i32 %30, i32* %8
%31 = load i32, i32* %10
store i32 %31, i32* %12
%32 = load i32, i32* %9
store i32 %32, i32* %13
br label %33
33: ; preds = %68, %29
%34 = load i32, i32* %13
%35 = load i32, i32* %7
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %71
37: ; preds = %33
%38 = load i32, i32* %12
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %54
40: ; preds = %37
%41 = load i32, i32* %12
%42 = load i32, i32* %13
%43 = load i32, i32* %9
%44 = sub nsw i32 %42, %43
%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 = sub nsw i32 %41, %47
%49 = load i32, i32* %13
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = add nsw i32 %48, %52
store i32 %53, i32* %12
br label %61
54: ; preds = %37
%55 = load i32, i32* %13
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = load i32, i32* %12
%60 = add nsw i32 %59, %58
store i32 %60, i32* %12
br label %61
61: ; preds = %54, %40
%62 = load i32, i32* %12
%63 = load i32, i32* %8
%64 = icmp sgt i32 %62, %63
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = load i32, i32* %12
store i32 %66, i32* %8
br label %67
67: ; preds = %65, %61
br label %68
68: ; preds = %67
%69 = load i32, i32* %13
%70 = add nsw i32 %69, 1
store i32 %70, i32* %13
br label %33
71: ; preds = %33
%72 = load i32, i32* %9
%73 = load i32, i32* %8
%74 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %72, i32 %73)
ret i32 0
}

LLVM IR (-O2):
@.str = [34 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 ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 2, i32 17)
ret i32 0
}