#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 /*<<< orphan*/ printf(char *, int);
int main(void) {
  int a[5] = {-9, 10, -11, 12, -15};
  int len = 5;
  int previousMax = a[0], currentMax = a[0], i;
  for (i = 1; i < len; i++) {
    if (currentMax + a[i] > currentMax) {
      currentMax = currentMax + a[i];
      if (a[i] > currentMax) {
        currentMax = a[i];
      }
    } else {
      if (previousMax < currentMax) {
        previousMax = currentMax;
      }
      currentMax = a[i];
    }
  }
  if (previousMax < currentMax) {
    previousMax = currentMax;
  }
  printf("previousmax: %d", previousMax);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xed5(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x5,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11d7 <main+0xc7>
mov    -0x2c(%rbp),%eax
movslq -0x30(%rbp),%rcx
add    -0x20(%rbp,%rcx,4),%eax
cmp    -0x2c(%rbp),%eax
jle    11a7 <main+0x97>
mov    -0x2c(%rbp),%eax
movslq -0x30(%rbp),%rcx
add    -0x20(%rbp,%rcx,4),%eax
mov    %eax,-0x2c(%rbp)
movslq -0x30(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
cmp    -0x2c(%rbp),%eax
jle    11a2 <main+0x92>
movslq -0x30(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
mov    %eax,-0x2c(%rbp)
jmp    11c4 <main+0xb4>
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11b9 <main+0xa9>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
movslq -0x30(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
mov    %eax,-0x2c(%rbp)
jmp    11c9 <main+0xb9>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1158 <main+0x48>
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11e9 <main+0xd9>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
@.str = [16 x i8] c"previousmax: %d\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 12)
ret i32 1
}