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

/* Variables and functions */
int /*<<< orphan*/ kadane(int *, int *, int *, int *);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
void findmaxrect(int a[][5], int *startcol, int *endcol, int *startrow,
                 int *endrow, int *maxsum) {
  *maxsum = 0;
  int temp[5];
  int start, end, right, sum;
  for (int left = 0; left < 5; left++) {
    memset(temp, 0, sizeof(temp));
    for (right = left; right < 5; right++) {
      for (int i = 0; i < 5; i++) {
        temp[i] += a[i][right];
      }
      kadane(temp, &sum, &start, &end);
      if (sum > *maxsum) {
        *maxsum = sum;
        *startcol = left;
        *endcol = right;
        *startrow = start;
        *endrow = end;
      }
    }
  }
}


x86 assembly (clang, -O0):
<findmaxrect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x64(%rbp)
cmpl   $0x5,-0x64(%rbp)
jge    1233 <findmaxrect+0x113>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    -0x64(%rbp),%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x5,-0x5c(%rbp)
jge    1220 <findmaxrect+0x100>
movl   $0x0,-0x68(%rbp)
cmpl   $0x5,-0x68(%rbp)
jge    11bc <findmaxrect+0x9c>
mov    -0x8(%rbp),%rax
movslq -0x68(%rbp),%rcx
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
movslq -0x68(%rbp),%rax
add    -0x50(%rbp,%rax,4),%ecx
mov    %ecx,-0x50(%rbp,%rax,4)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1182 <findmaxrect+0x62>
lea    -0x50(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x54(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1040 <kadane@plt>
mov    -0x60(%rbp),%eax
mov    -0x30(%rbp),%rcx
cmp    (%rcx),%eax
jle    120d <findmaxrect+0xed>
mov    -0x60(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x64(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x5c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x54(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    1212 <findmaxrect+0xf2>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1171 <findmaxrect+0x51>
jmp    1225 <findmaxrect+0x105>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1151 <findmaxrect+0x31>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findmaxrect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,%rbx
mov    %r8,0x40(%rsp)
mov    %rcx,0x38(%rsp)
mov    %rdx,0x30(%rsp)
mov    %rsi,0x28(%rsp)
mov    %rdi,%rbp
movl   $0x0,(%r9)
xor    %r14d,%r14d
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
jmp    116e <findmaxrect+0x4e>
xchg   %ax,%ax
add    $0x1,%r14
cmp    $0x5,%r14
je     1221 <findmaxrect+0x101>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    %r14,%r15
jmp    119a <findmaxrect+0x7a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r15
cmp    $0x5,%r15
je     1160 <findmaxrect+0x40>
movd   0x3c(%rbp,%r15,4),%xmm0
movd   0x28(%rbp,%r15,4),%xmm1
punpckldq %xmm0,%xmm1
movd   0x14(%rbp,%r15,4),%xmm0
movd   0x0(%rbp,%r15,4),%xmm2
punpckldq %xmm0,%xmm2
punpcklqdq %xmm1,%xmm2
paddd  0x10(%rsp),%xmm2
movdqa %xmm2,0x10(%rsp)
mov    0x50(%rbp,%r15,4),%eax
add    %eax,0x20(%rsp)
lea    0x10(%rsp),%rdi
lea    0x4(%rsp),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <kadane@plt>
mov    0x4(%rsp),%eax
cmp    (%rbx),%eax
jle    1190 <findmaxrect+0x70>
mov    %eax,(%rbx)
mov    0x28(%rsp),%rax
mov    %r14d,(%rax)
mov    0x30(%rsp),%rax
mov    %r15d,(%rax)
mov    0xc(%rsp),%eax
mov    0x38(%rsp),%rcx
mov    %eax,(%rcx)
mov    0x8(%rsp),%eax
mov    0x40(%rsp),%rcx
mov    %eax,(%rcx)
jmp    1190 <findmaxrect+0x70>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @findmaxrect([5 x i32]* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca [5 x i32]*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca [5 x i32]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store [5 x i32]* %0, [5 x i32]** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%20 = load i32*, i32** %12
store i32 0, i32* %20
store i32 0, i32* %18
br label %21
21: ; preds = %75, %6
%22 = load i32, i32* %18
%23 = icmp slt i32 %22, 5
br i1 %23, label %24, label %78
24: ; preds = %21
%25 = getelementptr inbounds [5 x i32], [5 x i32]* %13, i64 0, i64 0
%26 = call i32 @memset(i32* %25, i32 0, i32 20)
%27 = load i32, i32* %18
store i32 %27, i32* %16
br label %28
28: ; preds = %71, %24
%29 = load i32, i32* %16
%30 = icmp slt i32 %29, 5
br i1 %30, label %31, label %74
31: ; preds = %28
store i32 0, i32* %19
br label %32
32: ; preds = %49, %31
%33 = load i32, i32* %19
%34 = icmp slt i32 %33, 5
br i1 %34, label %35, label %52
35: ; preds = %32
%36 = load [5 x i32]*, [5 x i32]** %7
%37 = load i32, i32* %19
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [5 x i32], [5 x i32]* %36, i64 %38
%40 = load i32, i32* %16
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [5 x i32], [5 x i32]* %39, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = load i32, i32* %19
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [5 x i32], [5 x i32]* %13, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = add nsw i32 %47, %43
store i32 %48, i32* %46
br label %49
49: ; preds = %35
%50 = load i32, i32* %19
%51 = add nsw i32 %50, 1
store i32 %51, i32* %19
br label %32
52: ; preds = %32
%53 = getelementptr inbounds [5 x i32], [5 x i32]* %13, i64 0, i64 0
%54 = call i32 @kadane(i32* %53, i32* %17, i32* %14, i32* %15)
%55 = load i32, i32* %17
%56 = load i32*, i32** %12
%57 = load i32, i32* %56
%58 = icmp sgt i32 %55, %57
br i1 %58, label %59, label %70
59: ; preds = %52
%60 = load i32, i32* %17
%61 = load i32*, i32** %12
store i32 %60, i32* %61
%62 = load i32, i32* %18
%63 = load i32*, i32** %8
store i32 %62, i32* %63
%64 = load i32, i32* %16
%65 = load i32*, i32** %9
store i32 %64, i32* %65
%66 = load i32, i32* %14
%67 = load i32*, i32** %10
store i32 %66, i32* %67
%68 = load i32, i32* %15
%69 = load i32*, i32** %11
store i32 %68, i32* %69
br label %70
70: ; preds = %59, %52
br label %71
71: ; preds = %70
%72 = load i32, i32* %16
%73 = add nsw i32 %72, 1
store i32 %73, i32* %16
br label %28
74: ; preds = %28
br label %75
75: ; preds = %74
%76 = load i32, i32* %18
%77 = add nsw i32 %76, 1
store i32 %77, i32* %18
br label %21
78: ; preds = %21
ret void
}

LLVM IR (-O2):
define void @findmaxrect([5 x i32]* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i32* nocapture %5) {
%7 = alloca [5 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %5
%11 = bitcast [5 x i32]* %7 to i8*
%12 = bitcast i32* %8 to i8*
%13 = bitcast i32* %9 to i8*
%14 = bitcast i32* %10 to i8*
%15 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
%16 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 4
%17 = bitcast [5 x i32]* %7 to <4 x i32>*
%18 = bitcast [5 x i32]* %7 to <4 x i32>*
br label %20
19: ; preds = %55
ret void
20: ; preds = %55, %6
%21 = phi i64 [ 0, %6 ], [ %56, %55 ]
%22 = trunc i64 %21 to i32
%23 = call i32 @memset(i32* %15, i32 0, i32 20)
br label %24
24: ; preds = %20, %52
%25 = phi i64 [ %21, %20 ], [ %53, %52 ]
%26 = getelementptr inbounds [5 x i32], [5 x i32]* %0, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = getelementptr inbounds [5 x i32], [5 x i32]* %0, i64 1, i64 %25
%29 = load i32, i32* %28
%30 = getelementptr inbounds [5 x i32], [5 x i32]* %0, i64 2, i64 %25
%31 = load i32, i32* %30
%32 = getelementptr inbounds [5 x i32], [5 x i32]* %0, i64 3, i64 %25
%33 = load i32, i32* %32
%34 = load <4 x i32>, <4 x i32>* %17
%35 = insertelement <4 x i32> poison, i32 %27, i64 0
%36 = insertelement <4 x i32> %35, i32 %29, i64 1
%37 = insertelement <4 x i32> %36, i32 %31, i64 2
%38 = insertelement <4 x i32> %37, i32 %33, i64 3
%39 = add nsw <4 x i32> %34, %38
store <4 x i32> %39, <4 x i32>* %18
%40 = getelementptr inbounds [5 x i32], [5 x i32]* %0, i64 4, i64 %25
%41 = load i32, i32* %40
%42 = load i32, i32* %16
%43 = add nsw i32 %42, %41
store i32 %43, i32* %16
%44 = call i32 @kadane(i32* %15, i32* %10, i32* %8, i32* %9)
%45 = load i32, i32* %10
%46 = load i32, i32* %5
%47 = icmp sgt i32 %45, %46
br i1 %47, label %48, label %52
48: ; preds = %24
store i32 %45, i32* %5
store i32 %22, i32* %1
%49 = trunc i64 %25 to i32
store i32 %49, i32* %2
%50 = load i32, i32* %8
store i32 %50, i32* %3
%51 = load i32, i32* %9
store i32 %51, i32* %4
br label %52
52: ; preds = %24, %48
%53 = add nuw nsw i64 %25, 1
%54 = icmp eq i64 %53, 5
br i1 %54, label %55, label %24
55: ; preds = %52
%56 = add nuw nsw i64 %21, 1
%57 = icmp eq i64 %56, 5
br i1 %57, label %19, label %20
}