#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 */
scalar_t__ calloc(int, int);
int islandPerimeter(int **, int, int);
char *whenTest2_ShouldReturn8() {
  int **array;
  int columns = 4;
  int rows = 2;
  int expected = 8;
  int i = 0;
  array = (int **)calloc(rows, sizeof(int *));
  for (i = 0; i < rows; i++) {
    array[i] = (int *)calloc(columns, sizeof(int));
  }
  array[0][0] = 0;
  array[0][1] = 1;
  array[0][2] = 0;
  array[0][3] = 0;
  array[1][0] = 1;
  array[1][1] = 1;
  array[1][2] = 0;
  array[1][3] = 0;
  int result = islandPerimeter(array, rows, columns);
  do {
    if (!(expected == result))
      return "Error, perimeter is wrong";
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<whenTest2_ShouldReturn8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x4,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
movl   $0x8,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1192 <whenTest2_ShouldReturn8+0x72>
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115c <whenTest2_ShouldReturn8+0x3c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x1,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x0,0xc(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x1,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x0,0xc(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <islandPerimeter@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     1232 <whenTest2_ShouldReturn8+0x112>
lea    0xdd7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123f <whenTest2_ShouldReturn8+0x11f>
jmp    1237 <whenTest2_ShouldReturn8+0x117>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<whenTest2_ShouldReturn8>:
push   %rbx
mov    $0x2,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rbx
mov    $0x4,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,(%rbx)
mov    $0x4,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,0x8(%rbx)
mov    (%rbx),%rcx
movaps 0xe9e(%rip),%xmm0
movups %xmm0,(%rcx)
movaps 0xea4(%rip),%xmm0
movups %xmm0,(%rax)
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x4,%edx
call   1040 <islandPerimeter@plt>
xor    %ecx,%ecx
cmp    $0x8,%eax
lea    0xe93(%rip),%rax
cmovne %rax,%rcx
mov    %rcx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [26 x i8] c"Error, perimeter is wrong\00"
define i8* @whenTest2_ShouldReturn8() {
%1 = tail call i64 @calloc(i32 2, i32 8)
%2 = inttoptr i64 %1 to i32**
%3 = tail call i64 @calloc(i32 4, i32 4)
%4 = inttoptr i64 %3 to i32*
store i32* %4, i32** %2
%5 = tail call i64 @calloc(i32 4, i32 4)
%6 = inttoptr i64 %5 to i32*
%7 = getelementptr inbounds i32*, i32** %2, i64 1
store i32* %6, i32** %7
%8 = inttoptr i64 %1 to <4 x i32>**
%9 = load <4 x i32>*, <4 x i32>** %8
store <4 x i32> <i32 0, i32 1, i32 0, i32 0>, <4 x i32>* %9
%10 = inttoptr i64 %5 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 0, i32 0>, <4 x i32>* %10
%11 = tail call i32 @islandPerimeter(i32** %2, i32 2, i32 4)
%12 = icmp eq i32 %11, 8
%13 = select i1 %12, i8* null, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0)
ret i8* %13
}