#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 largest1BorderedSquare(int **, int, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int grid[3][3] = {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}};
  int **p = (int **)malloc(sizeof(int *) * 3);
  p[0] = grid[0];
  p[1] = grid[1];
  p[2] = grid[2];
  int size = 3;
  int len = largest1BorderedSquare(p, 3, &size);
  printf("len %d\n", len);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x30(%rbp),%rcx
add    $0xc,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x8(%rax)
lea    -0x30(%rbp),%rcx
add    $0x18,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x10(%rax)
movl   $0x3,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x3,%esi
lea    -0x3c(%rbp),%rdx
call   1030 <largest1BorderedSquare@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%esi
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
mov    0xee6(%rip),%eax
mov    %eax,0x30(%rsp)
movaps 0xecb(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeaf(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    $0x18,%edi
call   1050 <malloc@plt>
lea    0x10(%rsp),%rcx
mov    %rcx,(%rax)
lea    0x1c(%rsp),%rcx
mov    %rcx,0x8(%rax)
lea    0x28(%rsp),%rcx
mov    %rcx,0x10(%rax)
movl   $0x3,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
mov    $0x3,%esi
call   1030 <largest1BorderedSquare@plt>
lea    0xe89(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@__const.main.grid = [3 x [3 x i32]] [[3 x i32] [i32 1, i32 1, i32 1], [3 x i32] [i32 1, i32 0, i32 1], [3 x i32] [i32 1, i32 1, i32 1]]
@.str = [8 x i8] c"len %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x [3 x i32]]
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [3 x [3 x i32]]* %2 to i8*
%7 = call i64 @malloc(i32 24)
%8 = inttoptr i64 %7 to i32**
store i32** %8, i32*** %3
%9 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 0
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
%11 = load i32**, i32*** %3
%12 = getelementptr inbounds i32*, i32** %11, i64 0
store i32* %10, i32** %12
%13 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 1
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 0
%15 = load i32**, i32*** %3
%16 = getelementptr inbounds i32*, i32** %15, i64 1
store i32* %14, i32** %16
%17 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 2
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 0
%19 = load i32**, i32*** %3
%20 = getelementptr inbounds i32*, i32** %19, i64 2
store i32* %18, i32** %20
store i32 3, i32* %4
%21 = load i32**, i32*** %3
%22 = call i32 @largest1BorderedSquare(i32** %21, i32 3, i32* %4)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %23)
ret i32 0
}

LLVM IR (-O2):
@__const.main.grid = [3 x [3 x i32]] [[3 x i32] [i32 1, i32 1, i32 1], [3 x i32] [i32 1, i32 0, i32 1], [3 x i32] [i32 1, i32 1, i32 1]]
@.str = [8 x i8] c"len %d\0A\00"
define i32 @main() {
%1 = alloca [3 x [3 x i32]]
%2 = alloca i32
%3 = bitcast [3 x [3 x i32]]* %1 to i8*
%4 = tail call i64 @malloc(i32 24)
%5 = inttoptr i64 %4 to i32**
%6 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i64 0, i64 0, i64 0
store i32* %6, i32** %5
%7 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i64 0, i64 1, i64 0
%8 = getelementptr inbounds i32*, i32** %5, i64 1
store i32* %7, i32** %8
%9 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i64 0, i64 2, i64 0
%10 = getelementptr inbounds i32*, i32** %5, i64 2
store i32* %9, i32** %10
%11 = bitcast i32* %2 to i8*
store i32 3, i32* %2
%12 = call i32 @largest1BorderedSquare(i32** %5, i32 3, i32* %2)
%13 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %12)
ret i32 0
}