#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 islandPerimeter(int **, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int grid[4][4] = {{0, 1, 0, 0}, {1, 1, 1, 0}, {0, 1, 0, 0}, {1, 1, 0, 0}};
  int *p[4];
  int i, j;
  p[0] = grid[0];
  p[1] = grid[1];
  p[2] = grid[2];
  p[3] = grid[3];
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      printf("%d ", grid[i][j]);
    }
    printf("\n");
  }
  printf("perimeter = %d\n", islandPerimeter(p, 4, 4));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xeac(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x50(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x68(%rbp)
lea    -0x50(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x60(%rbp)
lea    -0x50(%rbp),%rax
add    $0x30,%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x74(%rbp)
cmpl   $0x4,-0x74(%rbp)
jge    11fa <main+0xca>
movl   $0x0,-0x78(%rbp)
cmpl   $0x4,-0x78(%rbp)
jge    11de <main+0xae>
movslq -0x74(%rbp),%rcx
lea    -0x50(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x78(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    11a2 <main+0x72>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1191 <main+0x61>
lea    -0x70(%rbp),%rdi
mov    $0x4,%edx
mov    %edx,%esi
call   1050 <islandPerimeter@plt>
mov    %eax,%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
movaps 0xef4(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xed8(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xea0(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x30(%rsp),%rax
lea    0x20(%rsp),%rcx
lea    0x10(%rsp),%rdx
mov    %rsp,%rsi
mov    %rsi,0x40(%rsp)
mov    %rdx,0x48(%rsp)
mov    %rcx,0x50(%rsp)
mov    %rax,0x58(%rsp)
lea    0xeaf(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x28(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x30(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x34(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x38(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x3c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x40(%rsp),%rdi
mov    $0x4,%esi
mov    $0x4,%edx
call   1050 <islandPerimeter@plt>
lea    0xd92(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.grid = [4 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 0, i32 0], [4 x i32] [i32 1, i32 1, i32 1, i32 0], [4 x i32] [i32 0, i32 1, i32 0, i32 0], [4 x i32] [i32 1, i32 1, i32 0, i32 0]]
@.str = [4 x i8] c"%d \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [16 x i8] c"perimeter = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x [4 x i32]]
%7 = alloca [4 x i32*]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [4 x [4 x i32]]* %6 to i8*
%11 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %6, i64 0, i64 0
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%13 = getelementptr inbounds [4 x i32*], [4 x i32*]* %7, i64 0, i64 0
store i32* %12, i32** %13
%14 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %6, i64 0, i64 1
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %14, i64 0, i64 0
%16 = getelementptr inbounds [4 x i32*], [4 x i32*]* %7, i64 0, i64 1
store i32* %15, i32** %16
%17 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %6, i64 0, i64 2
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %17, i64 0, i64 0
%19 = getelementptr inbounds [4 x i32*], [4 x i32*]* %7, i64 0, i64 2
store i32* %18, i32** %19
%20 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %6, i64 0, i64 3
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 0
%22 = getelementptr inbounds [4 x i32*], [4 x i32*]* %7, i64 0, i64 3
store i32* %21, i32** %22
store i32 0, i32* %8
br label %23
23: ; preds = %44, %2
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %47
26: ; preds = %23
store i32 0, i32* %9
br label %27
27: ; preds = %39, %26
%28 = load i32, i32* %9
%29 = icmp slt i32 %28, 4
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %6, i64 0, i64 %32
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [4 x i32], [4 x i32]* %33, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %30
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %27
42: ; preds = %27
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %42
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %23
47: ; preds = %23
%48 = getelementptr inbounds [4 x i32*], [4 x i32*]* %7, i64 0, i64 0
%49 = call i32 @islandPerimeter(i32** %48, i32 4, i32 4)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %49)
ret i32 0
}

LLVM IR (-O2):
@__const.main.grid = [4 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 0, i32 0], [4 x i32] [i32 1, i32 1, i32 1, i32 0], [4 x i32] [i32 0, i32 1, i32 0, i32 0], [4 x i32] [i32 1, i32 1, i32 0, i32 0]]
@.str = [4 x i8] c"%d \00"
@.str.2 = [16 x i8] c"perimeter = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x [4 x i32]]
%4 = alloca [4 x i32*]
%5 = bitcast [4 x [4 x i32]]* %3 to i8*
%6 = bitcast [4 x i32*]* %4 to i8*
%7 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 0, i64 0
%8 = getelementptr inbounds [4 x i32*], [4 x i32*]* %4, i64 0, i64 0
store i32* %7, i32** %8
%9 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 1, i64 0
%10 = getelementptr inbounds [4 x i32*], [4 x i32*]* %4, i64 0, i64 1
store i32* %9, i32** %10
%11 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 2, i64 0
%12 = getelementptr inbounds [4 x i32*], [4 x i32*]* %4, i64 0, i64 2
store i32* %11, i32** %12
%13 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 3, i64 0
%14 = getelementptr inbounds [4 x i32*], [4 x i32*]* %4, i64 0, i64 3
store i32* %13, i32** %14
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 0)
%16 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 0, i64 2
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 0, i64 3
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = call i32 @putchar(i32 10)
%26 = load i32, i32* %9
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 1, i64 1
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 1, i64 2
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 1, i64 3
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = call i32 @putchar(i32 10)
%38 = load i32, i32* %11
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 2, i64 1
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 2, i64 2
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 2, i64 3
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = call i32 @putchar(i32 10)
%50 = load i32, i32* %13
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %50)
%52 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 3, i64 1
%53 = load i32, i32* %52
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 3, i64 2
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 3, i64 3
%59 = load i32, i32* %58
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %59)
%61 = call i32 @putchar(i32 10)
%62 = call i32 @islandPerimeter(i32** %8, i32 4, i32 4)
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %62)
ret i32 0
}