#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, currentDensity = currentSum / l,
      maxDensity = currentDensity;
  int start = 0;
  for (int i = l; i < size; ++i) {
    if (currentSum < 0) {
      currentSum = currentSum - a[i - l] + a[i];
      start = i - l;
    } else
      currentSum += a[i];
    currentDensity = currentSum / (i - start + 1);
    if (currentDensity > maxDensity) {
      maxDensity = currentDensity;
    }
  }
  printf("Maximum Density of Subsequence of length > %d is %d\n", l, maxSum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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    -0x58(%rbp),%eax
cltd
idivl  -0x4c(%rbp)
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    %eax,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1243 <main+0x123>
cmpl   $0x0,-0x58(%rbp)
jge    11fe <main+0xde>
mov    -0x58(%rbp),%eax
mov    -0x68(%rbp),%ecx
sub    -0x4c(%rbp),%ecx
movslq %ecx,%rcx
sub    -0x40(%rbp,%rcx,4),%eax
movslq -0x68(%rbp),%rcx
add    -0x40(%rbp,%rcx,4),%eax
mov    %eax,-0x58(%rbp)
mov    -0x68(%rbp),%eax
sub    -0x4c(%rbp),%eax
mov    %eax,-0x64(%rbp)
jmp    120c <main+0xec>
movslq -0x68(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    -0x68(%rbp),%ecx
sub    -0x64(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x60(%rbp),%eax
jle    1230 <main+0x110>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x60(%rbp)
jmp    1235 <main+0x115>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11bf <main+0x9f>
mov    -0x4c(%rbp),%esi
mov    -0x48(%rbp),%edx
lea    0xdd4(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
mov    $0x2,%esi
mov    $0x5,%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 = [53 x i8] c"Maximum Density of Subsequence 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
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = 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 %18
18: ; preds = %29, %2
%19 = load i32, i32* %11
%20 = load i32, i32* %9
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %10
%28 = add nsw i32 %27, %26
store i32 %28, i32* %10
br label %29
29: ; preds = %22
%30 = load i32, i32* %11
%31 = add nsw i32 %30, 1
store i32 %31, i32* %11
br label %18
32: ; preds = %18
%33 = load i32, i32* %10
store i32 %33, i32* %8
%34 = load i32, i32* %10
store i32 %34, i32* %12
%35 = load i32, i32* %12
%36 = load i32, i32* %9
%37 = sdiv i32 %35, %36
store i32 %37, i32* %13
%38 = load i32, i32* %13
store i32 %38, i32* %14
store i32 0, i32* %15
%39 = load i32, i32* %9
store i32 %39, i32* %16
br label %40
40: ; preds = %84, %32
%41 = load i32, i32* %16
%42 = load i32, i32* %7
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %87
44: ; preds = %40
%45 = load i32, i32* %12
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %64
47: ; preds = %44
%48 = load i32, i32* %12
%49 = load i32, i32* %16
%50 = load i32, i32* %9
%51 = sub nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = sub nsw i32 %48, %54
%56 = load i32, i32* %16
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = add nsw i32 %55, %59
store i32 %60, i32* %12
%61 = load i32, i32* %16
%62 = load i32, i32* %9
%63 = sub nsw i32 %61, %62
store i32 %63, i32* %15
br label %71
64: ; preds = %44
%65 = load i32, i32* %16
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %66
%68 = load i32, i32* %67
%69 = load i32, i32* %12
%70 = add nsw i32 %69, %68
store i32 %70, i32* %12
br label %71
71: ; preds = %64, %47
%72 = load i32, i32* %12
%73 = load i32, i32* %16
%74 = load i32, i32* %15
%75 = sub nsw i32 %73, %74
%76 = add nsw i32 %75, 1
%77 = sdiv i32 %72, %76
store i32 %77, i32* %13
%78 = load i32, i32* %13
%79 = load i32, i32* %14
%80 = icmp sgt i32 %78, %79
br i1 %80, label %81, label %83
81: ; preds = %71
%82 = load i32, i32* %13
store i32 %82, i32* %14
br label %83
83: ; preds = %81, %71
br label %84
84: ; preds = %83
%85 = load i32, i32* %16
%86 = add nsw i32 %85, 1
store i32 %86, i32* %16
br label %40
87: ; preds = %40
%88 = load i32, i32* %9
%89 = load i32, i32* %8
%90 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %88, i32 %89)
ret i32 0
}

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