#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 INT_MIN;
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char const *argv[]) {
  int a[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
  int size = sizeof(a) / sizeof(a[0]);
  int maxSum = INT_MIN, length;
  int sum = 0, i = 0;
  for (int j = 0; j < size; ++j) {
    sum = sum + a[j];
    if (sum > maxSum)
      maxSum = sum;
    if (sum < 0) {
      i = j + 1;
      sum = 0;
    }
  }
  printf("The maxSum is %d\n", 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)
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11cc <main+0xac>
mov    -0x50(%rbp),%eax
movslq -0x58(%rbp),%rcx
add    -0x40(%rbp,%rcx,4),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x48(%rbp),%eax
jle    119f <main+0x7f>
mov    -0x50(%rbp),%eax
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x50(%rbp)
jge    11b9 <main+0x99>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x50(%rbp)
jmp    11be <main+0x9e>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1173 <main+0x53>
mov    -0x48(%rbp),%esi
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ed0(%rip),%rax
mov    (%rax),%eax
test   %eax,%eax
mov    $0x1,%ecx
cmovg  %eax,%ecx
cmp    $0x6,%eax
mov    $0x5,%eax
cmovge %ecx,%eax
mov    $0x5,%edx
cmp    $0x5,%ecx
cmovb  %edx,%eax
cmp    $0x7,%eax
mov    $0x6,%esi
cmovae %eax,%esi
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@__const.main.a = [9 x i32] [i32 -2, i32 1, i32 -3, i32 4, i32 -1, i32 2, i32 1, i32 -5, i32 4]
@INT_MIN = global i32 0
@.str = [18 x i8] c"The maxSum 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
%14 = load i32, i32* @INT_MIN
store i32 %14, i32* %8
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %15
15: ; preds = %38, %2
%16 = load i32, i32* %12
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %41
19: ; preds = %15
%20 = load i32, i32* %10
%21 = load i32, i32* %12
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %20, %24
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = load i32, i32* %8
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %19
%30 = load i32, i32* %10
store i32 %30, i32* %8
br label %31
31: ; preds = %29, %19
%32 = load i32, i32* %10
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %12
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
store i32 0, i32* %10
br label %37
37: ; preds = %34, %31
br label %38
38: ; preds = %37
%39 = load i32, i32* %12
%40 = add nsw i32 %39, 1
store i32 %40, i32* %12
br label %15
41: ; preds = %15
%42 = load i32, i32* %8
%43 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %42)
ret i32 0
}

LLVM IR (-O2):
@INT_MIN = global i32 0
@.str = [18 x i8] c"The maxSum is %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @INT_MIN
%4 = icmp sgt i32 %3, 1
%5 = select i1 %4, i32 %3, i32 1
%6 = icmp ugt i32 %5, 4
%7 = icmp sgt i32 %3, 5
%8 = select i1 %6, i1 %7, i1 false
%9 = select i1 %8, i32 %5, i32 5
%10 = icmp ugt i32 %9, 6
%11 = select i1 %10, i32 %9, i32 6
%12 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i32 0
}