#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*/ assert(int);
unsigned long long largestProductDiagonallyDownUp(int **);
unsigned long long largestProductDiagonallyUpDown(int **);
unsigned long long largestProductHorizontallyAndVertically(int **);
int /*<<< orphan*/ printf(char *, unsigned long long);
int main() {
  int grid[20][20] = {
      {8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8},
      {49, 49, 99, 40, 17, 81, 18, 57, 60, 87,
       17, 40, 98, 43, 69, 48, 04, 56, 62, 0},
      {81, 49, 31, 73, 55, 79, 14, 29, 93, 71,
       40, 67, 53, 88, 30, 3,  49, 13, 36, 65},
      {52, 70, 95, 23, 4,  60, 11, 42, 69, 24,
       68, 56, 1,  32, 56, 71, 37, 2,  36, 91},
      {22, 31, 16, 71, 51, 67, 63, 89, 41, 92,
       36, 54, 22, 40, 40, 28, 66, 33, 13, 80},
      {24, 47, 32, 60, 99, 3,  45, 2,  44, 75,
       33, 53, 78, 36, 84, 20, 35, 17, 12, 50},
      {32, 98, 81, 28, 64, 23, 67, 10, 26, 38,
       40, 67, 59, 54, 70, 66, 18, 38, 64, 70},
      {67, 26, 20, 68, 2,  62, 12, 20, 95, 63,
       94, 39, 63, 8,  40, 91, 66, 49, 94, 21},
      {24, 55, 58, 5,  66, 73, 99, 26, 97, 17,
       78, 78, 96, 83, 14, 88, 34, 89, 63, 72},
      {21, 36, 23, 9,  75, 0,  76, 44, 20, 45,
       35, 14, 0,  61, 33, 97, 34, 31, 33, 95},
      {78, 17, 53, 28, 22, 75, 31, 67, 15, 94,
       3,  80, 4,  62, 16, 14, 9,  53, 56, 92},
      {16, 39, 5, 42, 96, 35, 31, 47, 55, 58,
       88, 24, 0, 17, 54, 24, 36, 29, 85, 57},
      {86, 56, 0,  48, 35, 71, 89, 7,  5,  44,
       44, 37, 44, 60, 21, 58, 51, 54, 17, 58},
      {19, 80, 81, 68, 5,  94, 47, 69, 28, 73,
       92, 13, 86, 52, 17, 77, 4,  89, 55, 40},
      {4,  52, 8,  83, 97, 35, 99, 16, 7,  97,
       57, 32, 16, 26, 26, 79, 33, 27, 98, 66},
      {88, 36, 68, 87, 57, 62, 20, 72, 3,  46,
       33, 67, 46, 55, 12, 32, 63, 93, 53, 69},
      {4,  42, 16, 73, 38, 25, 39, 11, 24, 94,
       72, 18, 8,  46, 29, 32, 40, 62, 76, 36},
      {20, 69, 36, 41, 72, 30, 23, 88, 34, 62,
       99, 69, 82, 67, 59, 85, 74, 4,  36, 16},
      {20, 73, 35, 29, 78, 31, 90, 1,  74, 31,
       49, 71, 48, 86, 81, 16, 23, 57, 5,  54},
      {1,  70, 54, 71, 83, 51, 54, 69, 16, 92,
       33, 48, 61, 43, 52, 1,  89, 19, 67, 48}};
  unsigned long long largestProductHorizontalAndVertical =
      largestProductHorizontallyAndVertically(grid);
  unsigned long long largestProductDiagonalClockwise =
      largestProductDiagonallyUpDown(grid);
  unsigned long long largestProductDiagonalAntiClockwise =
      largestProductDiagonallyDownUp(grid);
  unsigned long long largest =
      ((largestProductHorizontalAndVertical > largestProductDiagonalClockwise
            ? largestProductHorizontalAndVertical
            : largestProductDiagonalClockwise) >
               largestProductDiagonalAntiClockwise
           ? (largestProductHorizontalAndVertical >
                      largestProductDiagonalClockwise
                  ? largestProductHorizontalAndVertical
                  : largestProductDiagonalClockwise)
           : largestProductDiagonalAntiClockwise);
  printf("Largest Product: %llu", largest);
  assert(70600674 == largest);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x690,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x650(%rbp),%rdi
lea    0xe80(%rip),%rsi
mov    $0x640,%edx
call   1060 <memcpy@plt>
lea    -0x650(%rbp),%rdi
call   1030 <largestProductHorizontallyAndVertically@plt>
mov    %rax,-0x658(%rbp)
lea    -0x650(%rbp),%rdi
call   1070 <largestProductDiagonallyUpDown@plt>
mov    %rax,-0x660(%rbp)
lea    -0x650(%rbp),%rdi
call   1080 <largestProductDiagonallyDownUp@plt>
mov    %rax,-0x668(%rbp)
mov    -0x658(%rbp),%rax
cmp    -0x660(%rbp),%rax
jbe    11ea <main+0x8a>
mov    -0x658(%rbp),%rax
mov    %rax,-0x678(%rbp)
jmp    11f8 <main+0x98>
mov    -0x660(%rbp),%rax
mov    %rax,-0x678(%rbp)
mov    -0x678(%rbp),%rax
cmp    -0x668(%rbp),%rax
jbe    1254 <main+0xf4>
mov    -0x658(%rbp),%rax
cmp    -0x660(%rbp),%rax
jbe    1233 <main+0xd3>
mov    -0x658(%rbp),%rax
mov    %rax,-0x680(%rbp)
jmp    1241 <main+0xe1>
mov    -0x660(%rbp),%rax
mov    %rax,-0x680(%rbp)
mov    -0x680(%rbp),%rax
mov    %rax,-0x688(%rbp)
jmp    1262 <main+0x102>
mov    -0x668(%rbp),%rax
mov    %rax,-0x688(%rbp)
mov    -0x688(%rbp),%rax
mov    %rax,-0x670(%rbp)
mov    -0x670(%rbp),%rsi
lea    0x13c2(%rip),%rdi
call   1040 <printf@plt>
mov    $0x43547e2,%eax
cmp    -0x670(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x690,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x640,%rsp
lea    0xe8d(%rip),%rsi
mov    %rsp,%r14
mov    $0x640,%edx
mov    %r14,%rdi
call   1060 <memcpy@plt>
mov    %r14,%rdi
call   1030 <largestProductHorizontallyAndVertically@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <largestProductDiagonallyUpDown@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1080 <largestProductDiagonallyDownUp@plt>
cmp    %rbx,%r15
cmova  %r15,%rbx
cmp    %rax,%rbx
cmovbe %rax,%rbx
lea    0x148a(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %edi,%edi
cmp    $0x43547e2,%rbx
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x640,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.grid = [20 x [20 x i32]] [[20 x i32] [i32 8, i32 2, i32 22, i32 97, i32 38, i32 15, i32 0, i32 40, i32 0, i32 75, i32 4, i32 5, i32 7, i32 78, i32 52, i32 12, i32 50, i32 77, i32 91, i32 8], [20 x i32] [i32 49, i32 49, i32 99, i32 40, i32 17, i32 81, i32 18, i32 57, i32 60, i32 87, i32 17, i32 40, i32 98, i32 43, i32 69, i32 48, i32 4, i32 56, i32 62, i32 0], [20 x i32] [i32 81, i32 49, i32 31, i32 73, i32 55, i32 79, i32 14, i32 29, i32 93, i32 71, i32 40, i32 67, i32 53, i32 88, i32 30, i32 3, i32 49, i32 13, i32 36, i32 65], [20 x i32] [i32 52, i32 70, i32 95, i32 23, i32 4, i32 60, i32 11, i32 42, i32 69, i32 24, i32 68, i32 56, i32 1, i32 32, i32 56, i32 71, i32 37, i32 2, i32 36, i32 91], [20 x i32] [i32 22, i32 31, i32 16, i32 71, i32 51, i32 67, i32 63, i32 89, i32 41, i32 92, i32 36, i32 54, i32 22, i32 40, i32 40, i32 28, i32 66, i32 33, i32 13, i32 80], [20 x i32] [i32 24, i32 47, i32 32, i32 60, i32 99, i32 3, i32 45, i32 2, i32 44, i32 75, i32 33, i32 53, i32 78, i32 36, i32 84, i32 20, i32 35, i32 17, i32 12, i32 50], [20 x i32] [i32 32, i32 98, i32 81, i32 28, i32 64, i32 23, i32 67, i32 10, i32 26, i32 38, i32 40, i32 67, i32 59, i32 54, i32 70, i32 66, i32 18, i32 38, i32 64, i32 70], [20 x i32] [i32 67, i32 26, i32 20, i32 68, i32 2, i32 62, i32 12, i32 20, i32 95, i32 63, i32 94, i32 39, i32 63, i32 8, i32 40, i32 91, i32 66, i32 49, i32 94, i32 21], [20 x i32] [i32 24, i32 55, i32 58, i32 5, i32 66, i32 73, i32 99, i32 26, i32 97, i32 17, i32 78, i32 78, i32 96, i32 83, i32 14, i32 88, i32 34, i32 89, i32 63, i32 72], [20 x i32] [i32 21, i32 36, i32 23, i32 9, i32 75, i32 0, i32 76, i32 44, i32 20, i32 45, i32 35, i32 14, i32 0, i32 61, i32 33, i32 97, i32 34, i32 31, i32 33, i32 95], [20 x i32] [i32 78, i32 17, i32 53, i32 28, i32 22, i32 75, i32 31, i32 67, i32 15, i32 94, i32 3, i32 80, i32 4, i32 62, i32 16, i32 14, i32 9, i32 53, i32 56, i32 92], [20 x i32] [i32 16, i32 39, i32 5, i32 42, i32 96, i32 35, i32 31, i32 47, i32 55, i32 58, i32 88, i32 24, i32 0, i32 17, i32 54, i32 24, i32 36, i32 29, i32 85, i32 57], [20 x i32] [i32 86, i32 56, i32 0, i32 48, i32 35, i32 71, i32 89, i32 7, i32 5, i32 44, i32 44, i32 37, i32 44, i32 60, i32 21, i32 58, i32 51, i32 54, i32 17, i32 58], [20 x i32] [i32 19, i32 80, i32 81, i32 68, i32 5, i32 94, i32 47, i32 69, i32 28, i32 73, i32 92, i32 13, i32 86, i32 52, i32 17, i32 77, i32 4, i32 89, i32 55, i32 40], [20 x i32] [i32 4, i32 52, i32 8, i32 83, i32 97, i32 35, i32 99, i32 16, i32 7, i32 97, i32 57, i32 32, i32 16, i32 26, i32 26, i32 79, i32 33, i32 27, i32 98, i32 66], [20 x i32] [i32 88, i32 36, i32 68, i32 87, i32 57, i32 62, i32 20, i32 72, i32 3, i32 46, i32 33, i32 67, i32 46, i32 55, i32 12, i32 32, i32 63, i32 93, i32 53, i32 69], [20 x i32] [i32 4, i32 42, i32 16, i32 73, i32 38, i32 25, i32 39, i32 11, i32 24, i32 94, i32 72, i32 18, i32 8, i32 46, i32 29, i32 32, i32 40, i32 62, i32 76, i32 36], [20 x i32] [i32 20, i32 69, i32 36, i32 41, i32 72, i32 30, i32 23, i32 88, i32 34, i32 62, i32 99, i32 69, i32 82, i32 67, i32 59, i32 85, i32 74, i32 4, i32 36, i32 16], [20 x i32] [i32 20, i32 73, i32 35, i32 29, i32 78, i32 31, i32 90, i32 1, i32 74, i32 31, i32 49, i32 71, i32 48, i32 86, i32 81, i32 16, i32 23, i32 57, i32 5, i32 54], [20 x i32] [i32 1, i32 70, i32 54, i32 71, i32 83, i32 51, i32 54, i32 69, i32 16, i32 92, i32 33, i32 48, i32 61, i32 43, i32 52, i32 1, i32 89, i32 19, i32 67, i32 48]]
@.str = [22 x i8] c"Largest Product: %llu\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x [20 x i32]]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = bitcast [20 x [20 x i32]]* %2 to i8*
%8 = getelementptr inbounds [20 x [20 x i32]], [20 x [20 x i32]]* %2, i64 0, i64 0
%9 = bitcast [20 x i32]* %8 to i32**
%10 = call i64 @largestProductHorizontallyAndVertically(i32** %9)
store i64 %10, i64* %3
%11 = getelementptr inbounds [20 x [20 x i32]], [20 x [20 x i32]]* %2, i64 0, i64 0
%12 = bitcast [20 x i32]* %11 to i32**
%13 = call i64 @largestProductDiagonallyUpDown(i32** %12)
store i64 %13, i64* %4
%14 = getelementptr inbounds [20 x [20 x i32]], [20 x [20 x i32]]* %2, i64 0, i64 0
%15 = bitcast [20 x i32]* %14 to i32**
%16 = call i64 @largestProductDiagonallyDownUp(i32** %15)
store i64 %16, i64* %5
%17 = load i64, i64* %3
%18 = load i64, i64* %4
%19 = icmp ugt i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = load i64, i64* %3
br label %24
22: ; preds = %0
%23 = load i64, i64* %4
br label %24
24: ; preds = %22, %20
%25 = phi i64 [ %21, %20 ], [ %23, %22 ]
%26 = load i64, i64* %5
%27 = icmp ugt i64 %25, %26
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = load i64, i64* %3
%30 = load i64, i64* %4
%31 = icmp ugt i64 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = load i64, i64* %3
br label %36
34: ; preds = %28
%35 = load i64, i64* %4
br label %36
36: ; preds = %34, %32
%37 = phi i64 [ %33, %32 ], [ %35, %34 ]
br label %40
38: ; preds = %24
%39 = load i64, i64* %5
br label %40
40: ; preds = %38, %36
%41 = phi i64 [ %37, %36 ], [ %39, %38 ]
store i64 %41, i64* %6
%42 = load i64, i64* %6
%43 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %42)
%44 = load i64, i64* %6
%45 = icmp eq i64 70600674, %44
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
ret i32 0
}

LLVM IR (-O2):
@__const.main.grid = [20 x [20 x i32]] [[20 x i32] [i32 8, i32 2, i32 22, i32 97, i32 38, i32 15, i32 0, i32 40, i32 0, i32 75, i32 4, i32 5, i32 7, i32 78, i32 52, i32 12, i32 50, i32 77, i32 91, i32 8], [20 x i32] [i32 49, i32 49, i32 99, i32 40, i32 17, i32 81, i32 18, i32 57, i32 60, i32 87, i32 17, i32 40, i32 98, i32 43, i32 69, i32 48, i32 4, i32 56, i32 62, i32 0], [20 x i32] [i32 81, i32 49, i32 31, i32 73, i32 55, i32 79, i32 14, i32 29, i32 93, i32 71, i32 40, i32 67, i32 53, i32 88, i32 30, i32 3, i32 49, i32 13, i32 36, i32 65], [20 x i32] [i32 52, i32 70, i32 95, i32 23, i32 4, i32 60, i32 11, i32 42, i32 69, i32 24, i32 68, i32 56, i32 1, i32 32, i32 56, i32 71, i32 37, i32 2, i32 36, i32 91], [20 x i32] [i32 22, i32 31, i32 16, i32 71, i32 51, i32 67, i32 63, i32 89, i32 41, i32 92, i32 36, i32 54, i32 22, i32 40, i32 40, i32 28, i32 66, i32 33, i32 13, i32 80], [20 x i32] [i32 24, i32 47, i32 32, i32 60, i32 99, i32 3, i32 45, i32 2, i32 44, i32 75, i32 33, i32 53, i32 78, i32 36, i32 84, i32 20, i32 35, i32 17, i32 12, i32 50], [20 x i32] [i32 32, i32 98, i32 81, i32 28, i32 64, i32 23, i32 67, i32 10, i32 26, i32 38, i32 40, i32 67, i32 59, i32 54, i32 70, i32 66, i32 18, i32 38, i32 64, i32 70], [20 x i32] [i32 67, i32 26, i32 20, i32 68, i32 2, i32 62, i32 12, i32 20, i32 95, i32 63, i32 94, i32 39, i32 63, i32 8, i32 40, i32 91, i32 66, i32 49, i32 94, i32 21], [20 x i32] [i32 24, i32 55, i32 58, i32 5, i32 66, i32 73, i32 99, i32 26, i32 97, i32 17, i32 78, i32 78, i32 96, i32 83, i32 14, i32 88, i32 34, i32 89, i32 63, i32 72], [20 x i32] [i32 21, i32 36, i32 23, i32 9, i32 75, i32 0, i32 76, i32 44, i32 20, i32 45, i32 35, i32 14, i32 0, i32 61, i32 33, i32 97, i32 34, i32 31, i32 33, i32 95], [20 x i32] [i32 78, i32 17, i32 53, i32 28, i32 22, i32 75, i32 31, i32 67, i32 15, i32 94, i32 3, i32 80, i32 4, i32 62, i32 16, i32 14, i32 9, i32 53, i32 56, i32 92], [20 x i32] [i32 16, i32 39, i32 5, i32 42, i32 96, i32 35, i32 31, i32 47, i32 55, i32 58, i32 88, i32 24, i32 0, i32 17, i32 54, i32 24, i32 36, i32 29, i32 85, i32 57], [20 x i32] [i32 86, i32 56, i32 0, i32 48, i32 35, i32 71, i32 89, i32 7, i32 5, i32 44, i32 44, i32 37, i32 44, i32 60, i32 21, i32 58, i32 51, i32 54, i32 17, i32 58], [20 x i32] [i32 19, i32 80, i32 81, i32 68, i32 5, i32 94, i32 47, i32 69, i32 28, i32 73, i32 92, i32 13, i32 86, i32 52, i32 17, i32 77, i32 4, i32 89, i32 55, i32 40], [20 x i32] [i32 4, i32 52, i32 8, i32 83, i32 97, i32 35, i32 99, i32 16, i32 7, i32 97, i32 57, i32 32, i32 16, i32 26, i32 26, i32 79, i32 33, i32 27, i32 98, i32 66], [20 x i32] [i32 88, i32 36, i32 68, i32 87, i32 57, i32 62, i32 20, i32 72, i32 3, i32 46, i32 33, i32 67, i32 46, i32 55, i32 12, i32 32, i32 63, i32 93, i32 53, i32 69], [20 x i32] [i32 4, i32 42, i32 16, i32 73, i32 38, i32 25, i32 39, i32 11, i32 24, i32 94, i32 72, i32 18, i32 8, i32 46, i32 29, i32 32, i32 40, i32 62, i32 76, i32 36], [20 x i32] [i32 20, i32 69, i32 36, i32 41, i32 72, i32 30, i32 23, i32 88, i32 34, i32 62, i32 99, i32 69, i32 82, i32 67, i32 59, i32 85, i32 74, i32 4, i32 36, i32 16], [20 x i32] [i32 20, i32 73, i32 35, i32 29, i32 78, i32 31, i32 90, i32 1, i32 74, i32 31, i32 49, i32 71, i32 48, i32 86, i32 81, i32 16, i32 23, i32 57, i32 5, i32 54], [20 x i32] [i32 1, i32 70, i32 54, i32 71, i32 83, i32 51, i32 54, i32 69, i32 16, i32 92, i32 33, i32 48, i32 61, i32 43, i32 52, i32 1, i32 89, i32 19, i32 67, i32 48]]
@.str = [22 x i8] c"Largest Product: %llu\00"
define i32 @main() {
%1 = alloca [20 x [20 x i32]]
%2 = bitcast [20 x [20 x i32]]* %1 to i8*
%3 = bitcast [20 x [20 x i32]]* %1 to i32**
%4 = call i64 @largestProductHorizontallyAndVertically(i32** %3)
%5 = call i64 @largestProductDiagonallyUpDown(i32** %3)
%6 = call i64 @largestProductDiagonallyDownUp(i32** %3)
%7 = icmp ugt i64 %4, %5
%8 = select i1 %7, i64 %4, i64 %5
%9 = icmp ugt i64 %8, %6
%10 = select i1 %9, i64 %8, i64 %6
%11 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = icmp eq i64 %10, 70600674
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
ret i32 0
}