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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  int i, begin = 0, end = 0;
  int data[] = {1, -2, 3, -1, 7};
  int sum = 0;
  int max = data[0];
  for (i = 0; i < sizeof(data) / sizeof(data[0]); i++) {
    sum += data[i];
    if (sum >= max) {
      max = sum;
      end = i;
    }
    if (sum < 0) {
      begin = i + 1;
      sum = 0;
    }
  }
  printf("%d\n", max);
  printf("begin:%d\nend:%d", begin + 1, end + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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,-0x34(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
cmp    $0x5,%rax
jae    11c1 <main+0xb1>
movslq -0x8(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jl     1194 <main+0x84>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11ae <main+0x9e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x34(%rbp)
jmp    11b3 <main+0xa3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1160 <main+0x50>
mov    -0x38(%rbp),%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@__const.main.data = [5 x i32] [i32 1, i32 -2, i32 3, i32 -1, i32 7]
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [16 x i8] c"begin:%d\0Aend:%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [5 x i32]
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%8 = bitcast [5 x i32]* %5 to i8*
store i32 0, i32* %6
%9 = getelementptr inbounds [5 x i32], [5 x i32]* %5, i64 0, i64 0
%10 = load i32, i32* %9
store i32 %10, i32* %7
store i32 0, i32* %2
br label %11
11: ; preds = %35, %0
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = icmp ult i64 %13, 5
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [5 x i32], [5 x i32]* %5, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %6
%21 = add nsw i32 %20, %19
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = icmp sge i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = load i32, i32* %6
store i32 %26, i32* %7
%27 = load i32, i32* %2
store i32 %27, i32* %4
br label %28
28: ; preds = %25, %15
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
store i32 0, i32* %6
br label %34
34: ; preds = %31, %28
br label %35
35: ; preds = %34
%36 = load i32, i32* %2
%37 = add nsw i32 %36, 1
store i32 %37, i32* %2
br label %11
38: ; preds = %11
%39 = load i32, i32* %7
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
%45 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [16 x i8] c"begin:%d\0Aend:%d\00"
define i32 @main() {
%1 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 9)
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 5)
ret i32 0
}