#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;
  for (int i = 0; i < size; ++i) {
    int sum = 0;
    for (int j = i; j < size; ++j) {
      sum += a[j];
      if (sum > maxSum)
        maxSum = sum;
    }
  }
  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)
mov    -0x50(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11d0 <main+0xb0>
movl   $0x0,-0x54(%rbp)
mov    -0x50(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11bd <main+0x9d>
movslq -0x58(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x48(%rbp),%eax
jle    11aa <main+0x8a>
mov    -0x54(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    11af <main+0x8f>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    117e <main+0x5e>
jmp    11c2 <main+0xa2>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1165 <main+0x45>
mov    -0x48(%rbp),%esi
lea    0xe4a(%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    $0xffffffff,%ecx
cmovns %eax,%ecx
cmp    $0x2,%eax
mov    $0x1,%eax
cmovge %ecx,%eax
mov    $0x1,%edx
test   %ecx,%ecx
cmovle %edx,%eax
cmp    $0x3,%eax
mov    $0x2,%ecx
cmovae %eax,%ecx
cmp    $0x5,%eax
mov    $0x4,%eax
cmovae %ecx,%eax
mov    $0x4,%edx
cmp    $0x4,%ecx
cmovb  %edx,%eax
cmp    $0x7,%eax
mov    $0x6,%esi
cmovae %eax,%esi
cmp    $0x5,%esi
cmovl  %edx,%esi
lea    0xe8e(%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
br label %15
15: ; preds = %42, %2
%16 = load i32, i32* %10
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %45
19: ; preds = %15
store i32 0, i32* %11
%20 = load i32, i32* %10
store i32 %20, i32* %12
br label %21
21: ; preds = %38, %19
%22 = load i32, i32* %12
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %41
25: ; preds = %21
%26 = load i32, i32* %12
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = load i32, i32* %11
%31 = add nsw i32 %30, %29
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = load i32, i32* %8
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %25
%36 = load i32, i32* %11
store i32 %36, i32* %8
br label %37
37: ; preds = %35, %25
br label %38
38: ; preds = %37
%39 = load i32, i32* %12
%40 = add nsw i32 %39, 1
store i32 %40, i32* %12
br label %21
41: ; preds = %21
br label %42
42: ; preds = %41
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %15
45: ; preds = %15
%46 = load i32, i32* %8
%47 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %46)
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 sgt i32 %5, 0
%7 = icmp sgt i32 %3, 1
%8 = select i1 %6, i1 %7, i1 false
%9 = select i1 %8, i32 %5, i32 1
%10 = icmp ugt i32 %9, 2
%11 = select i1 %10, i32 %9, i32 2
%12 = icmp ugt i32 %11, 3
%13 = icmp ugt i32 %9, 4
%14 = select i1 %12, i1 %13, i1 false
%15 = select i1 %14, i32 %11, i32 4
%16 = icmp ugt i32 %15, 6
%17 = select i1 %16, i32 %15, i32 6
%18 = call i32 @llvm.smax.i32(i32 %17, i32 4)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %18)
ret i32 0
}