#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, 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, maxStartIndex = 0, maxEndIndex = 0, currentMaxSum = 0;
  for (int i = 0; i < size; ++i) {
    currentMaxSum += a[i];
    if (currentMaxSum > maxSum) {
      maxSum = currentMaxSum;
      maxEndIndex = i;
    }
    if (currentMaxSum < 0) {
      maxStartIndex = i + 1;
      currentMaxSum = 0;
    }
  }
  printf("The maxSum is %d, maxStartIndex is %d, maxEndIndex is %d \n", maxSum,
         maxStartIndex, maxEndIndex);
  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,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11d9 <main+0xb9>
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    11ac <main+0x8c>
mov    -0x54(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    11c6 <main+0xa6>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
movl   $0x0,-0x54(%rbp)
jmp    11cb <main+0xab>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    117a <main+0x5a>
mov    -0x48(%rbp),%esi
mov    -0x4c(%rbp),%edx
mov    -0x50(%rbp),%ecx
lea    0xe3b(%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
xor    %edx,%edx
test   %eax,%eax
setle  %dl
cmp    $0x4,%eax
mov    $0x4,%esi
cmovge %eax,%esi
mov    $0x3,%ecx
cmovl  %ecx,%edx
cmp    $0x5,%esi
setb   %dil
mov    $0x5,%ecx
cmovae %edx,%ecx
cmp    $0x6,%eax
setl   %al
or     %dil,%al
mov    $0x6,%eax
cmovne %eax,%esi
cmovne %eax,%ecx
lea    0xea2(%rip),%rdi
mov    $0x3,%edx
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 = [59 x i8] c"The maxSum is %d, maxStartIndex is %d, maxEndIndex 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* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %15
15: ; preds = %39, %2
%16 = load i32, i32* %12
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %42
19: ; preds = %15
%20 = load i32, i32* %12
%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* %11
%25 = add nsw i32 %24, %23
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = load i32, i32* %8
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %19
%30 = load i32, i32* %11
store i32 %30, i32* %8
%31 = load i32, i32* %12
store i32 %31, i32* %10
br label %32
32: ; preds = %29, %19
%33 = load i32, i32* %11
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* %12
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
store i32 0, i32* %11
br label %38
38: ; preds = %35, %32
br label %39
39: ; preds = %38
%40 = load i32, i32* %12
%41 = add nsw i32 %40, 1
store i32 %41, i32* %12
br label %15
42: ; preds = %15
%43 = load i32, i32* %8
%44 = load i32, i32* %9
%45 = load i32, i32* %10
%46 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %43, i32 %44, i32 %45)
ret i32 0
}

LLVM IR (-O2):
@INT_MIN = global i32 0
@.str = [59 x i8] c"The maxSum is %d, maxStartIndex is %d, maxEndIndex is %d \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @INT_MIN
%4 = icmp slt i32 %3, 1
%5 = zext i1 %4 to i32
%6 = icmp slt i32 %3, 4
%7 = select i1 %6, i32 4, i32 %3
%8 = select i1 %6, i32 3, i32 %5
%9 = icmp ult i32 %7, 5
%10 = select i1 %9, i32 5, i32 %8
%11 = icmp slt i32 %3, 6
%12 = select i1 %9, i1 true, i1 %11
%13 = select i1 %12, i32 6, i32 %7
%14 = select i1 %12, i32 6, i32 %10
%15 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %13, i32 3, i32 %14)
ret i32 0
}