#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*/ printf(char *, int, int, int, int);
int principal_diagonal_prod(int num[20][20], int i, int j) {
  if (i > 16 || j > 16)
    return -1;
  printf("%d:%d->%d:%d", i, j, i + 3, j + 3);
  return num[i][j] * num[i + 1][j + 1] * num[i + 2][j + 2] * num[i + 3][j + 3];
}


x86 assembly (clang, -O0):
<principal_diagonal_prod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x10,-0x14(%rbp)
jg     1136 <principal_diagonal_prod+0x26>
cmpl   $0x10,-0x18(%rbp)
jle    1142 <principal_diagonal_prod+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11de <principal_diagonal_prod+0xce>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
add    $0x3,%ecx
mov    -0x18(%rbp),%r8d
add    $0x3,%r8d
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x50,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
imul   $0x50,%rdx,%rdx
add    %rdx,%rcx
mov    -0x18(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
imul   (%rcx,%rdx,4),%eax
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
add    $0x2,%edx
movslq %edx,%rdx
imul   $0x50,%rdx,%rdx
add    %rdx,%rcx
mov    -0x18(%rbp),%edx
add    $0x2,%edx
movslq %edx,%rdx
imul   (%rcx,%rdx,4),%eax
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
add    $0x3,%edx
movslq %edx,%rdx
imul   $0x50,%rdx,%rdx
add    %rdx,%rcx
mov    -0x18(%rbp),%edx
add    $0x3,%edx
movslq %edx,%rdx
imul   (%rcx,%rdx,4),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<principal_diagonal_prod>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%eax
cmp    $0x10,%esi
jg     1198 <principal_diagonal_prod+0x88>
mov    %edx,%ebp
cmp    $0x10,%edx
jg     1198 <principal_diagonal_prod+0x88>
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x3(%rbx),%r15d
lea    0x3(%rbp),%r8d
lea    0xec4(%rip),%rdi
mov    %ebp,%edx
mov    %r15d,%ecx
call   1030 <printf@plt>
movslq %ebx,%rax
movslq %ebp,%rcx
lea    (%rax,%rax,4),%rdx
shl    $0x4,%rdx
add    %r14,%rdx
lea    0x1(%rbx),%eax
cltq
lea    (%rax,%rax,4),%rax
shl    $0x4,%rax
add    %r14,%rax
mov    0x4(%rax,%rcx,4),%eax
imul   (%rdx,%rcx,4),%eax
add    $0x2,%ebx
movslq %ebx,%rdx
lea    (%rdx,%rdx,4),%rdx
shl    $0x4,%rdx
add    %r14,%rdx
imul   0x8(%rdx,%rcx,4),%eax
movslq %r15d,%rdx
lea    (%rdx,%rdx,4),%rdx
shl    $0x4,%rdx
add    %r14,%rdx
imul   0xc(%rdx,%rcx,4),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%d:%d->%d:%d\00"
define i32 @principal_diagonal_prod([20 x i32]* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca [20 x i32]*
%6 = alloca i32
%7 = alloca i32
store [20 x i32]* %0, [20 x i32]** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %6
%9 = icmp sgt i32 %8, 16
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 16
br i1 %12, label %13, label %14
13: ; preds = %10, %3
store i32 -1, i32* %4
br label %63
14: ; preds = %10
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 3
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 3
%21 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16, i32 %18, i32 %20)
%22 = load [20 x i32]*, [20 x i32]** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [20 x i32], [20 x i32]* %22, i64 %24
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [20 x i32], [20 x i32]* %25, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = load [20 x i32]*, [20 x i32]** %5
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [20 x i32], [20 x i32]* %30, i64 %33
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [20 x i32], [20 x i32]* %34, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = mul nsw i32 %29, %39
%41 = load [20 x i32]*, [20 x i32]** %5
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [20 x i32], [20 x i32]* %41, i64 %44
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 2
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [20 x i32], [20 x i32]* %45, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = mul nsw i32 %40, %50
%52 = load [20 x i32]*, [20 x i32]** %5
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 3
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [20 x i32], [20 x i32]* %52, i64 %55
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 3
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [20 x i32], [20 x i32]* %56, i64 0, i64 %59
%61 = load i32, i32* %60
%62 = mul nsw i32 %51, %61
store i32 %62, i32* %4
br label %63
63: ; preds = %14, %13
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
@.str = [13 x i8] c"%d:%d->%d:%d\00"
define i32 @principal_diagonal_prod([20 x i32]* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 16
%5 = icmp sgt i32 %2, 16
%6 = or i1 %4, %5
br i1 %6, label %34, label %7
7: ; preds = %3
%8 = add nsw i32 %1, 3
%9 = add nsw i32 %2, 3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2, i32 %8, i32 %9)
%11 = sext i32 %1 to i64
%12 = sext i32 %2 to i64
%13 = getelementptr inbounds [20 x i32], [20 x i32]* %0, i64 %11, i64 %12
%14 = load i32, i32* %13
%15 = add nsw i32 %1, 1
%16 = sext i32 %15 to i64
%17 = add nsw i32 %2, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [20 x i32], [20 x i32]* %0, i64 %16, i64 %18
%20 = load i32, i32* %19
%21 = mul nsw i32 %20, %14
%22 = add nsw i32 %1, 2
%23 = sext i32 %22 to i64
%24 = add nsw i32 %2, 2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [20 x i32], [20 x i32]* %0, i64 %23, i64 %25
%27 = load i32, i32* %26
%28 = mul nsw i32 %21, %27
%29 = sext i32 %8 to i64
%30 = sext i32 %9 to i64
%31 = getelementptr inbounds [20 x i32], [20 x i32]* %0, i64 %29, i64 %30
%32 = load i32, i32* %31
%33 = mul nsw i32 %28, %32
br label %34
34: ; preds = %3, %7
%35 = phi i32 [ %33, %7 ], [ -1, %3 ]
ret i32 %35
}