#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 */
int FindMax(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i, MAX = 0, maxVal = 0;
  scanf("%d", &n);
  int arr[n];
  for (i = 0; i < n; i++)
    scanf("%d", &arr[i]);
  maxVal = MAX = arr[0];
  for (i = 1; i < n; i++) {
    maxVal = FindMax(arr[i], maxVal + arr[i]);
    MAX = FindMax(MAX, maxVal);
  }
  printf("%d", MAX);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeac(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c0 <main+0x90>
mov    -0x30(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe53(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118b <main+0x5b>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    %eax,-0x14(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1218 <main+0xe8>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x14(%rbp),%esi
movslq -0xc(%rbp),%rcx
add    (%rax,%rcx,4),%esi
call   1040 <FindMax@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <FindMax@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d3 <main+0xa3>
mov    -0x10(%rbp),%esi
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebb(%rip),%r14
lea    -0x2c(%rbp),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
xor    %r13d,%r13d
mov    %r12,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     1180 <main+0x50>
mov    (%r12),%ebx
cmp    $0x2,%eax
jl     11db <main+0xab>
mov    $0x1,%r13d
mov    %ebx,%r14d
xchg   %ax,%ax
mov    (%r12,%r13,4),%edi
add    %edi,%ebx
mov    %ebx,%esi
call   1040 <FindMax@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %eax,%esi
call   1040 <FindMax@plt>
mov    %eax,%r14d
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
cmp    %rax,%r13
jl     11b0 <main+0x80>
jmp    11de <main+0xae>
mov    %ebx,%r14d
lea    0xe1b(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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