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

/* Variables and functions */
int INT_MIN;
int /*<<< orphan*/ printf(char *, int);
int main() {
  int v[] = {-2, -3, 4, -1, -2, 1, 5, -3};
  int currentMax = 0, globalMax = INT_MIN;
  int size = sizeof(v) / sizeof(v[0]);
  for (int i = 0; i < size; i++) {
    currentMax += v[i];
    globalMax = globalMax < currentMax ? currentMax : globalMax;
    if (currentMax < 0) {
      currentMax = 0;
    }
  }
  printf("Max sum is %d\n", globalMax);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xed4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed1(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
movl   $0x8,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    11cd <main+0xbd>
movslq -0x40(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    119d <main+0x8d>
mov    -0x34(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    11a3 <main+0x93>
mov    -0x38(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11ba <main+0xaa>
movl   $0x0,-0x34(%rbp)
jmp    11bf <main+0xaf>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    116c <main+0x5c>
mov    -0x38(%rbp),%esi
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ed0(%rip),%rax
mov    (%rax),%eax
cmp    $0x8,%eax
mov    $0x7,%esi
cmovge %eax,%esi
lea    0xed4(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@INT_MIN = global i32 0
@.str = [15 x i8] c"Max sum is %d\0A\00"
define i32 @main() {
%1 = load i32, i32* @INT_MIN
%2 = icmp sgt i32 %1, 7
%3 = select i1 %2, i32 %1, i32 7
%4 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3)
ret i32 0
}