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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ printf(char *, long long);
scalar_t__ scanf(char *, long long *);
int main() {
  long long N, i;
  long long thissum, sum, tmp;
  while (scanf("%lld", &N) != EOF) {
    scanf("%lld", &tmp);
    thissum = sum = tmp;
    for (i = 1; i < N; ++i) {
      scanf("%lld", &tmp);
      if (sum > 0)
        sum += tmp;
      else
        sum = tmp;
      if (thissum < sum)
        thissum = sum;
    }
    printf("%lld\n", thissum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    0x2ea2(%rip),%rcx
cmp    (%rcx),%rax
je     11f6 <main+0xd6>
lea    0xeaa(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11e1 <main+0xc1>
lea    0xe78(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <scanf@plt>
cmpq   $0x0,-0x28(%rbp)
jle    11ad <main+0x8d>
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11b5 <main+0x95>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    11cb <main+0xab>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11d0 <main+0xb0>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1173 <main+0x53>
mov    -0x20(%rbp),%rsi
lea    0xe19(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x2ea2(%rip),%rcx
cmp    (%rcx),%rax
jne    115c <main+0x3c>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe9d(%rip),%r13
lea    0x10(%rsp),%r14
xor    %ebp,%ebp
jmp    119b <main+0x7b>
nopl   0x0(%rax)
mov    %rbx,%r15
lea    0xe8b(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%rax
je     114b <main+0x2b>
mov    %r13,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
mov    0x10(%rsp),%rbx
cmpq   $0x2,0x8(%rsp)
jl     1170 <main+0x50>
mov    $0x1,%r12d
mov    %rbx,%r15
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
test   %rbx,%rbx
cmovs  %rbp,%rbx
add    0x10(%rsp),%rbx
cmp    %rbx,%r15
cmovl  %rbx,%r15
add    $0x1,%r12
cmp    0x8(%rsp),%r12
jl     11c0 <main+0xa0>
jmp    1173 <main+0x53>

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

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
@EOF = global i64 0
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
%4 = bitcast i64* %2 to i8*
%5 = call i64 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%6 = load i64, i64* @EOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %33, label %8
8: ; preds = %0, %27
%9 = call i64 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
%10 = load i64, i64* %2
%11 = load i64, i64* %1
%12 = icmp sgt i64 %11, 1
br i1 %12, label %13, label %27
13: ; preds = %8, %13
%14 = phi i64 [ %21, %13 ], [ %10, %8 ]
%15 = phi i64 [ %23, %13 ], [ %10, %8 ]
%16 = phi i64 [ %24, %13 ], [ 1, %8 ]
%17 = call i64 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
%18 = icmp sgt i64 %14, 0
%19 = load i64, i64* %2
%20 = select i1 %18, i64 %14, i64 0
%21 = add nsw i64 %19, %20
%22 = icmp slt i64 %15, %21
%23 = select i1 %22, i64 %21, i64 %15
%24 = add nuw nsw i64 %16, 1
%25 = load i64, i64* %1
%26 = icmp slt i64 %24, %25
br i1 %26, label %13, label %27
27: ; preds = %13, %8
%28 = phi i64 [ %10, %8 ], [ %23, %13 ]
%29 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %28)
%30 = call i64 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%31 = load i64, i64* @EOF
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %8
33: ; preds = %27, %0
ret i32 0
}