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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, int, int);
int main() {
  int x[] = {-1, 2, -5, 6, 1, 4, -2, 3}, start_index = -1, end_index = -1, i,
      sum, max;
  sum = max = x[0];
  for (i = 1; i < sizeof(x) / sizeof(int); i++) {
    if (sum + x[i] > x[i]) {
      sum += x[i];
    } else {
      sum = x[i];
      start_index = i;
    }
    if (x[i] > 0) {
      max = sum;
      end_index = i;
    }
  }
  printf("maximum sum: %i  start_index: %i  end_index: %i", sum, start_index,
         end_index);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xed4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed1(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0x34(%rbp)
movl   $0xffffffff,-0x38(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    %eax,-0x40(%rbp)
movl   $0x1,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmp    $0x8,%rax
jae    11e2 <main+0xd2>
mov    -0x40(%rbp),%eax
movslq -0x3c(%rbp),%rcx
add    -0x30(%rbp,%rcx,4),%eax
movslq -0x3c(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jle    11a3 <main+0x93>
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    11b4 <main+0xa4>
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x34(%rbp)
movslq -0x3c(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,4)
jle    11cf <main+0xbf>
mov    -0x40(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    11d4 <main+0xc4>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1169 <main+0x59>
mov    -0x40(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@__const.main.x = [8 x i32] [i32 -1, i32 2, i32 -5, i32 6, i32 1, i32 4, i32 -2, i32 3]
@.str = [48 x i8] c"maximum sum: %i start_index: %i end_index: %i\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [8 x i32]* %2 to i8*
store i32 -1, i32* %3
store i32 -1, i32* %4
%9 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%10 = load i32, i32* %9
store i32 %10, i32* %7
store i32 %10, i32* %6
store i32 1, i32* %5
br label %11
11: ; preds = %50, %0
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = icmp ult i64 %13, 8
br i1 %14, label %15, label %53
15: ; preds = %11
%16 = load i32, i32* %6
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = add nsw i32 %16, %20
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = icmp sgt i32 %21, %25
br i1 %26, label %27, label %34
27: ; preds = %15
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = load i32, i32* %6
%33 = add nsw i32 %32, %31
store i32 %33, i32* %6
br label %40
34: ; preds = %15
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %36
%38 = load i32, i32* %37
store i32 %38, i32* %6
%39 = load i32, i32* %5
store i32 %39, i32* %3
br label %40
40: ; preds = %34, %27
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load i32, i32* %6
store i32 %47, i32* %7
%48 = load i32, i32* %5
store i32 %48, i32* %4
br label %49
49: ; preds = %46, %40
br label %50
50: ; preds = %49
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %11
53: ; preds = %11
%54 = load i32, i32* %6
%55 = load i32, i32* %3
%56 = load i32, i32* %4
%57 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %54, i32 %55, i32 %56)
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):
@.str = [48 x i8] c"maximum sum: %i start_index: %i end_index: %i\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 12, i32 3, i32 7)
ret i32 0
}