#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_subarray_better(int *, int, int);
int max_subarray_brute(int *, int, int);
int max_subarray_optimal(int *, int, int);
int test_negative() {
  int array[] = {-10, 9,   15, 12, -11, 4,  -2,  6,   -7, 12, -17, 3,  21,
                 12,  -18, 16, 5,  13,  -9, -11, -12, 17, 5,  12,  -25};
  return 112 == max_subarray_brute(array, 5, 5) &&
         112 == max_subarray_better(array, 5, 5) &&
         112 == max_subarray_optimal(array, 5, 5);
}


x86 assembly (clang, -O0):
<test_negative>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x70(%rbp),%rdi
lea    0xeaa(%rip),%rsi
mov    $0x64,%edx
call   1040 <memcpy@plt>
lea    -0x70(%rbp),%rdi
mov    $0x5,%edx
mov    %edx,%esi
call   1030 <max_subarray_brute@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x70,%ecx
cmp    %edx,%ecx
mov    %al,-0x71(%rbp)
jne    11c7 <test_negative+0x87>
lea    -0x70(%rbp),%rdi
mov    $0x5,%edx
mov    %edx,%esi
call   1050 <max_subarray_better@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x70,%ecx
cmp    %edx,%ecx
mov    %al,-0x71(%rbp)
jne    11c7 <test_negative+0x87>
lea    -0x70(%rbp),%rdi
mov    $0x5,%edx
mov    %edx,%esi
call   1060 <max_subarray_optimal@plt>
mov    %eax,%ecx
mov    $0x70,%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_negative>:
push   %rbx
sub    $0x70,%rsp
mov    0xf25(%rip),%eax
mov    %eax,0x60(%rsp)
movaps 0xf0a(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xeee(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe7e(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x5,%esi
mov    $0x5,%edx
call   1030 <max_subarray_brute@plt>
xor    %ebx,%ebx
cmp    $0x70,%eax
jne    11d0 <test_negative+0xa0>
mov    %rsp,%rdi
mov    $0x5,%esi
mov    $0x5,%edx
call   1040 <max_subarray_better@plt>
cmp    $0x70,%eax
jne    11d0 <test_negative+0xa0>
mov    %rsp,%rdi
mov    $0x5,%esi
mov    $0x5,%edx
call   1050 <max_subarray_optimal@plt>
xor    %ebx,%ebx
cmp    $0x70,%eax
sete   %bl
mov    %ebx,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_negative.array = [25 x i32] [i32 -10, i32 9, i32 15, i32 12, i32 -11, i32 4, i32 -2, i32 6, i32 -7, i32 12, i32 -17, i32 3, i32 21, i32 12, i32 -18, i32 16, i32 5, i32 13, i32 -9, i32 -11, i32 -12, i32 17, i32 5, i32 12, i32 -25]
define i32 @test_negative() {
%1 = alloca [25 x i32]
%2 = bitcast [25 x i32]* %1 to i8*
%3 = getelementptr inbounds [25 x i32], [25 x i32]* %1, i64 0, i64 0
%4 = call i32 @max_subarray_brute(i32* %3, i32 5, i32 5)
%5 = icmp eq i32 112, %4
br i1 %5, label %6, label %14
6: ; preds = %0
%7 = getelementptr inbounds [25 x i32], [25 x i32]* %1, i64 0, i64 0
%8 = call i32 @max_subarray_better(i32* %7, i32 5, i32 5)
%9 = icmp eq i32 112, %8
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = getelementptr inbounds [25 x i32], [25 x i32]* %1, i64 0, i64 0
%12 = call i32 @max_subarray_optimal(i32* %11, i32 5, i32 5)
%13 = icmp eq i32 112, %12
br label %14
14: ; preds = %10, %6, %0
%15 = phi i1 [ false, %6 ], [ false, %0 ], [ %13, %10 ]
%16 = zext i1 %15 to i32
ret i32 %16
}

LLVM IR (-O2):
@__const.test_negative.array = [25 x i32] [i32 -10, i32 9, i32 15, i32 12, i32 -11, i32 4, i32 -2, i32 6, i32 -7, i32 12, i32 -17, i32 3, i32 21, i32 12, i32 -18, i32 16, i32 5, i32 13, i32 -9, i32 -11, i32 -12, i32 17, i32 5, i32 12, i32 -25]
define i32 @test_negative() {
%1 = alloca [25 x i32]
%2 = bitcast [25 x i32]* %1 to i8*
%3 = getelementptr inbounds [25 x i32], [25 x i32]* %1, i64 0, i64 0
%4 = call i32 @max_subarray_brute(i32* %3, i32 5, i32 5)
%5 = icmp eq i32 %4, 112
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = call i32 @max_subarray_better(i32* %3, i32 5, i32 5)
%8 = icmp eq i32 %7, 112
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = call i32 @max_subarray_optimal(i32* %3, i32 5, i32 5)
%11 = icmp eq i32 %10, 112
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %9, %6, %0
%14 = phi i32 [ 0, %6 ], [ 0, %0 ], [ %12, %9 ]
ret i32 %14
}