#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 get_col_prod(int, int);
int get_diag_down_prod(int, int);
int get_diag_up_prod(int, int);
int get_row_prod(int, int);
int /*<<< orphan*/ printf(char *, int, int, int);
int problem11(void) {
  int largest = 0;
  int i, j, temp;
  for (i = 0; i < 20 - 3; i++) {
    for (j = 0; j < 20 - 3; j++) {
      if ((temp = get_row_prod(i, j)) > largest)
        largest = temp;
      if ((temp = get_col_prod(i, j)) > largest)
        largest = temp;
      if ((temp = get_diag_up_prod(i, j)) > largest)
        largest = temp;
      if ((temp = get_diag_down_prod(i, j)) > largest)
        largest = temp;
    }
  }
  printf("The greatest product of four adjacent numbers int the same direction "
         "in the %dx%d grid is %d\n",
         20, 20, largest);
  return 0;
}


x86 assembly (clang, -O0):
<problem11>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x11,-0x8(%rbp)
jge    121b <problem11+0xcb>
movl   $0x0,-0xc(%rbp)
cmpl   $0x11,-0xc(%rbp)
jge    1208 <problem11+0xb8>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1070 <get_row_prod@plt>
mov    %eax,-0x10(%rbp)
cmp    -0x4(%rbp),%eax
jle    119e <problem11+0x4e>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <get_col_prod@plt>
mov    %eax,-0x10(%rbp)
cmp    -0x4(%rbp),%eax
jle    11bb <problem11+0x6b>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <get_diag_up_prod@plt>
mov    %eax,-0x10(%rbp)
cmp    -0x4(%rbp),%eax
jle    11d8 <problem11+0x88>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <get_diag_down_prod@plt>
mov    %eax,-0x10(%rbp)
cmp    -0x4(%rbp),%eax
jle    11f5 <problem11+0xa5>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fa <problem11+0xaa>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1177 <problem11+0x27>
jmp    120d <problem11+0xbd>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1166 <problem11+0x16>
mov    -0x4(%rbp),%ecx
lea    0xddb(%rip),%rdi
mov    $0x14,%edx
mov    %edx,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<problem11>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    116a <problem11+0x1a>
nop
add    $0x1,%r14d
cmp    $0x11,%r14d
je     11ca <problem11+0x7a>
xor    %ebp,%ebp
jmp    1178 <problem11+0x28>
xchg   %ax,%ax
add    $0x1,%ebp
cmp    $0x11,%ebp
je     1160 <problem11+0x10>
mov    %r14d,%edi
mov    %ebp,%esi
call   1070 <get_row_prod@plt>
mov    %eax,%ebx
cmp    %r15d,%eax
jg     118c <problem11+0x3c>
mov    %r15d,%ebx
mov    %r14d,%edi
mov    %ebp,%esi
call   1040 <get_col_prod@plt>
mov    %eax,%r15d
cmp    %ebx,%eax
jg     11a0 <problem11+0x50>
mov    %ebx,%r15d
mov    %r14d,%edi
mov    %ebp,%esi
call   1060 <get_diag_up_prod@plt>
mov    %eax,%ebx
cmp    %r15d,%eax
jg     11b4 <problem11+0x64>
mov    %r15d,%ebx
mov    %r14d,%edi
mov    %ebp,%esi
call   1030 <get_diag_down_prod@plt>
mov    %eax,%r15d
cmp    %ebx,%eax
jg     1170 <problem11+0x20>
mov    %ebx,%r15d
jmp    1170 <problem11+0x20>
lea    0xe2f(%rip),%rdi
mov    $0x14,%esi
mov    $0x14,%edx
mov    %r15d,%ecx
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [94 x i8] c"The greatest product of four adjacent numbers int the same direction in the %dx%d grid is %d\0A\00"
define i32 @problem11() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %49, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 17
br i1 %7, label %8, label %52
8: ; preds = %5
store i32 0, i32* %3
br label %9
9: ; preds = %45, %8
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 17
br i1 %11, label %12, label %48
12: ; preds = %9
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = call i32 @get_row_prod(i32 %13, i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %1
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = load i32, i32* %4
store i32 %19, i32* %1
br label %20
20: ; preds = %18, %12
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = call i32 @get_col_prod(i32 %21, i32 %22)
store i32 %23, i32* %4
%24 = load i32, i32* %1
%25 = icmp sgt i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = load i32, i32* %4
store i32 %27, i32* %1
br label %28
28: ; preds = %26, %20
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = call i32 @get_diag_up_prod(i32 %29, i32 %30)
store i32 %31, i32* %4
%32 = load i32, i32* %1
%33 = icmp sgt i32 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = load i32, i32* %4
store i32 %35, i32* %1
br label %36
36: ; preds = %34, %28
%37 = load i32, i32* %2
%38 = load i32, i32* %3
%39 = call i32 @get_diag_down_prod(i32 %37, i32 %38)
store i32 %39, i32* %4
%40 = load i32, i32* %1
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = load i32, i32* %4
store i32 %43, i32* %1
br label %44
44: ; preds = %42, %36
br label %45
45: ; preds = %44
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
br label %9
48: ; preds = %9
br label %49
49: ; preds = %48
%50 = load i32, i32* %2
%51 = add nsw i32 %50, 1
store i32 %51, i32* %2
br label %5
52: ; preds = %5
%53 = load i32, i32* %1
%54 = call i32 @printf(i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str, i64 0, i64 0), i32 20, i32 20, i32 %53)
ret i32 0
}

LLVM IR (-O2):
@.str = [94 x i8] c"The greatest product of four adjacent numbers int the same direction in the %dx%d grid is %d\0A\00"
define i32 @problem11() {
br label %1
1: ; preds = %0, %21
%2 = phi i32 [ 0, %0 ], [ %22, %21 ]
%3 = phi i32 [ 0, %0 ], [ %18, %21 ]
br label %4
4: ; preds = %1, %4
%5 = phi i32 [ 0, %1 ], [ %19, %4 ]
%6 = phi i32 [ %3, %1 ], [ %18, %4 ]
%7 = tail call i32 @get_row_prod(i32 %2, i32 %5)
%8 = icmp sgt i32 %7, %6
%9 = select i1 %8, i32 %7, i32 %6
%10 = tail call i32 @get_col_prod(i32 %2, i32 %5)
%11 = icmp sgt i32 %10, %9
%12 = select i1 %11, i32 %10, i32 %9
%13 = tail call i32 @get_diag_up_prod(i32 %2, i32 %5)
%14 = icmp sgt i32 %13, %12
%15 = select i1 %14, i32 %13, i32 %12
%16 = tail call i32 @get_diag_down_prod(i32 %2, i32 %5)
%17 = icmp sgt i32 %16, %15
%18 = select i1 %17, i32 %16, i32 %15
%19 = add nuw nsw i32 %5, 1
%20 = icmp eq i32 %19, 17
br i1 %20, label %21, label %4
21: ; preds = %4
%22 = add nuw nsw i32 %2, 1
%23 = icmp eq i32 %22, 17
br i1 %23, label %24, label %1
24: ; preds = %21
%25 = tail call i32 @printf(i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str, i64 0, i64 0), i32 20, i32 20, i32 %18)
ret i32 0
}