#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 max_sum(int *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int size, i, k, max;
  scanf("%d", &size);
  int a[size];
  for (i = 0; i < size; i++)
    scanf("%d", &a[i]);
  max = a[0];
  for (i = 0; i < size; i++) {
    if (a[i] > max)
      max = a[i];
    if (a[i] >= 0) {
      break;
    }
  }
  if (max >= 0) {
    k = max_sum(a, size);
    printf("Maximum sum of sub-array %d", k);
  } else {
    printf("%d", max);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed3(%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    11b2 <main+0x82>
mov    -0x30(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7a(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117d <main+0x4d>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121a <main+0xea>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
jle    11f0 <main+0xc0>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jl     1207 <main+0xd7>
jmp    121a <main+0xea>
jmp    120c <main+0xdc>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c2 <main+0x92>
cmpl   $0x0,-0x14(%rbp)
jl     1247 <main+0x117>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <max_sum@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xdc3(%rip),%rdi
call   1040 <printf@plt>
jmp    1256 <main+0x126>
mov    -0x14(%rbp),%esi
lea    0xdc8(%rip),%rdi
call   1040 <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    0xed4(%rip),%r15
lea    -0x2c(%rbp),%rsi
mov    %r15,%rdi
call   1050 <scanf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
xor    %r13d,%r13d
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%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    %eax,%esi
mov    (%r14),%eax
test   %esi,%esi
jle    11da <main+0xaa>
test   %eax,%eax
jns    11da <main+0xaa>
cmp    $0x1,%esi
je     11da <main+0xaa>
mov    $0x2,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    -0x4(%r14,%rcx,4),%edx
cmp    %eax,%edx
cmovg  %edx,%eax
test   %edx,%edx
jns    11da <main+0xaa>
lea    0x1(%rcx),%rdx
cmp    %rsi,%rcx
mov    %rdx,%rcx
jb     11c0 <main+0x90>
test   %eax,%eax
js     11ef <main+0xbf>
mov    %r14,%rdi
call   1030 <max_sum@plt>
lea    0xe13(%rip),%rdi
jmp    11f6 <main+0xc6>
lea    0xe23(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r12,%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"
@.str.1 = [28 x i8] c"Maximum sum of sub-array %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
%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* %5
store i32 0, i32* %3
br label %28
28: ; preds = %52, %25
%29 = load i32, i32* %3
%30 = load i32, i32* %2
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %55
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 = icmp sgt i32 %36, %37
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %12, i64 %41
%43 = load i32, i32* %42
store i32 %43, i32* %5
br label %44
44: ; preds = %39, %32
%45 = load i32, i32* %3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %12, i64 %46
%48 = load i32, i32* %47
%49 = icmp sge i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %44
br label %55
51: ; preds = %44
br label %52
52: ; preds = %51
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %28
55: ; preds = %50, %28
%56 = load i32, i32* %5
%57 = icmp sge i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i32, i32* %2
%60 = call i32 @max_sum(i32* %12, i32 %59)
store i32 %60, i32* %4
%61 = load i32, i32* %4
%62 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %61)
br label %66
63: ; preds = %55
%64 = load i32, i32* %5
%65 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %63, %58
store i32 0, i32* %1
%67 = load i8*, i8** %6
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [28 x i8] c"Maximum sum of sub-array %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, 0
br i1 %20, label %21, label %37
21: ; preds = %18
%22 = zext i32 %15 to i64
%23 = icmp slt i32 %19, 0
%24 = icmp ne i32 %15, 1
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %26, label %37
26: ; preds = %21, %26
%27 = phi i64 [ %34, %26 ], [ 1, %21 ]
%28 = phi i32 [ %32, %26 ], [ %19, %21 ]
%29 = getelementptr inbounds i32, i32* %7, i64 %27
%30 = load i32, i32* %29
%31 = icmp sgt i32 %30, %28
%32 = select i1 %31, i32 %30, i32 %28
%33 = icmp slt i32 %30, 0
%34 = add nuw nsw i64 %27, 1
%35 = icmp ult i64 %34, %22
%36 = select i1 %33, i1 %35, i1 false
br i1 %36, label %26, label %37
37: ; preds = %26, %21, %18
%38 = phi i32 [ %19, %18 ], [ %19, %21 ], [ %32, %26 ]
%39 = icmp sgt i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 @max_sum(i32* %7, i32 %15)
%42 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %45
43: ; preds = %37
%44 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %38)
br label %45
45: ; preds = %43, %40
ret i32 0
}