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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  int i;
  int max_sum = 0;
  int current_sum = 0;
  int array[] = {-1, 2, 5, -6, 9};
  for (i = 0; i < (sizeof(array) / sizeof(int)); ++i) {
    current_sum = current_sum + array[i];
    if (current_sum < 0)
      current_sum = 0;
    if (current_sum > max_sum)
      max_sum = current_sum;
  }
  printf("MAX CONT. SUM OF SUBARRAY :%d\n", max_sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0xecc(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec9(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xec7(%rip),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
cmp    $0x5,%rax
jae    11a5 <main+0x95>
mov    -0x10(%rbp),%eax
movslq -0x8(%rbp),%rcx
add    -0x30(%rbp,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1180 <main+0x70>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1192 <main+0x82>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1197 <main+0x87>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1153 <main+0x43>
mov    -0xc(%rbp),%esi
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@__const.main.array = [5 x i32] [i32 -1, i32 2, i32 5, i32 -6, i32 9]
@.str = [31 x i8] c"MAX CONT. SUM OF SUBARRAY :%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [5 x i32]
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%6 = bitcast [5 x i32]* %5 to i8*
store i32 0, i32* %2
br label %7
7: ; preds = %28, %0
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = icmp ult i64 %9, 5
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [5 x i32], [5 x i32]* %5, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = add nsw i32 %12, %16
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %11
store i32 0, i32* %4
br label %21
21: ; preds = %20, %11
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32, i32* %4
store i32 %26, i32* %3
br label %27
27: ; preds = %25, %21
br label %28
28: ; preds = %27
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
br label %7
31: ; preds = %7
%32 = load i32, i32* %3
%33 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"MAX CONT. SUM OF SUBARRAY :%d\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 10)
ret i32 0
}