#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 **allocate_matrix(int, int, char);
int /*<<< orphan*/ free_matrix(int **, int, int);
int /*<<< orphan*/ get_bonded_neighbors(int **, int **, int, int, int *, int **,
                                        int *);
int /*<<< orphan*/ populate_bonds(int **, int **, int, int, double);
int /*<<< orphan*/ print_lattice(int **, int **, int **, int, int, int *,
                                 int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ set_A1_A2(int *, int *, int, int);
int sscanf(char *, char *, ...);
int /*<<< orphan*/ usage(char *, char *, int);
void test_get_bonded_neighbors(int argc, char **argv) {
  int M = 18;
  int N = 18;
  double p = 0.6;
  int argi;
  int **vbonds;
  int **hbonds;
  int **site_marks;
  int A1[2];
  int A2[2];
  int neighbors[4][2];
  int numnei;
  int k;
  for (argi = 2; argi < argc; argi++) {
    if (sscanf(argv[argi], "M=%d", &M) == 1)
      ;
    else if (sscanf(argv[argi], "N=%d", &N) == 1)
      ;
    else if (sscanf(argv[argi], "MN=%d", &M) == 1)
      N = M;
    else if (sscanf(argv[argi], "p=%lf", &p) == 1)
      ;
    else
      usage(argv[0], argv[1], 0);
  }
  if ((M < 3) || (N < 3))
    usage(argv[0], argv[1], 1);
  vbonds = allocate_matrix(M, N, 0);
  hbonds = allocate_matrix(M, N, 0);
  site_marks = allocate_matrix(M, N, '.');
  set_A1_A2(A1, A2, M, N);
  populate_bonds(vbonds, hbonds, M, N, p);
  print_lattice(site_marks, vbonds, hbonds, M, N, A1, A2);
  printf("\n");
  get_bonded_neighbors(vbonds, hbonds, M, N, A1, neighbors, &numnei);
  printf("Bonded neighbors of A1 at (%d, %d):\n", A1[0], A1[1]);
  if (numnei == 0)
    printf("(none)\n");
  for (k = 0; k < numnei; k++) {
    printf("  ( %3d, %3d )\n", neighbors[k][0], neighbors[k][1]);
  }
  free_matrix(vbonds, M, N);
  free_matrix(hbonds, M, N);
  free_matrix(site_marks, M, N);
}


x86 assembly (clang, -O0):
<test_get_bonded_neighbors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x12,-0x14(%rbp)
movl   $0x12,-0x18(%rbp)
movsd  0xe48(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12be <test_get_bonded_neighbors+0x12e>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe25(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
cmp    $0x1,%eax
jne    11fc <test_get_bonded_neighbors+0x6c>
jmp    12ab <test_get_bonded_neighbors+0x11b>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdff(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
cmp    $0x1,%eax
jne    1228 <test_get_bonded_neighbors+0x98>
jmp    12a6 <test_get_bonded_neighbors+0x116>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdd2(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
cmp    $0x1,%eax
jne    125a <test_get_bonded_neighbors+0xca>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    12a1 <test_get_bonded_neighbors+0x111>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xda6(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
cmp    $0x1,%eax
jne    1286 <test_get_bonded_neighbors+0xf6>
jmp    129c <test_get_bonded_neighbors+0x10c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %edx,%edx
call   10b0 <usage@plt>
jmp    12a1 <test_get_bonded_neighbors+0x111>
jmp    12a6 <test_get_bonded_neighbors+0x116>
jmp    12ab <test_get_bonded_neighbors+0x11b>
jmp    12b0 <test_get_bonded_neighbors+0x120>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c4 <test_get_bonded_neighbors+0x34>
cmpl   $0x3,-0x14(%rbp)
jl     12d2 <test_get_bonded_neighbors+0x142>
cmpl   $0x3,-0x18(%rbp)
jge    12eb <test_get_bonded_neighbors+0x15b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x1,%edx
call   10b0 <usage@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1090 <allocate_matrix@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1090 <allocate_matrix@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x2e,%edx
call   1090 <allocate_matrix@plt>
mov    %rax,-0x40(%rbp)
lea    -0x48(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1060 <set_A1_A2@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
movsd  -0x20(%rbp),%xmm0
call   1080 <populate_bonds@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    -0x48(%rbp),%r9
lea    -0x50(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <print_lattice@plt>
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    -0x48(%rbp),%r8
lea    -0x70(%rbp),%r9
lea    -0x74(%rbp),%rax
mov    %rax,(%rsp)
call   1050 <get_bonded_neighbors@plt>
mov    -0x48(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    0xc6b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x74(%rbp)
jne    13cd <test_get_bonded_neighbors+0x23d>
lea    0xc78(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    140c <test_get_bonded_neighbors+0x27c>
movslq -0x78(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%esi
movslq -0x78(%rbp),%rax
mov    -0x6c(%rbp,%rax,8),%edx
lea    0xc4f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    13d4 <test_get_bonded_neighbors+0x244>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <free_matrix@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <free_matrix@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <free_matrix@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_get_bonded_neighbors>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    %edi,%eax
movl   $0x12,0x10(%rsp)
movl   $0x12,0xc(%rsp)
movabs $0x3fe3333333333333,%rcx
33 e3 3f
mov    %rcx,0x18(%rsp)
mov    $0x12,%esi
mov    $0x12,%edi
cmp    $0x3,%eax
jl     12a7 <test_get_bonded_neighbors+0xf7>
mov    %eax,%ebp
mov    $0x2,%r12d
lea    0xdfc(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r13
jmp    1229 <test_get_bonded_neighbors+0x79>
mov    0x10(%rsp),%eax
mov    %eax,0xc(%rsp)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r12,%rbp
je     129f <test_get_bonded_neighbors+0xef>
mov    (%rbx,%r12,8),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10c0 <sscanf@plt>
cmp    $0x1,%eax
je     1220 <test_get_bonded_neighbors+0x70>
mov    (%rbx,%r12,8),%rdi
lea    0xdbc(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   10c0 <sscanf@plt>
cmp    $0x1,%eax
je     1220 <test_get_bonded_neighbors+0x70>
mov    (%rbx,%r12,8),%rdi
lea    0xda1(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10c0 <sscanf@plt>
cmp    $0x1,%eax
je     1210 <test_get_bonded_neighbors+0x60>
mov    (%rbx,%r12,8),%rdi
lea    0xd8d(%rip),%rsi
lea    0x18(%rsp),%rdx
xor    %eax,%eax
call   10c0 <sscanf@plt>
cmp    $0x1,%eax
je     1220 <test_get_bonded_neighbors+0x70>
mov    (%rbx),%rdi
mov    0x8(%rbx),%rsi
xor    %edx,%edx
call   10d0 <usage@plt>
jmp    1220 <test_get_bonded_neighbors+0x70>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
cmp    $0x3,%edi
jl     12b1 <test_get_bonded_neighbors+0x101>
cmp    $0x2,%esi
jg     12ca <test_get_bonded_neighbors+0x11a>
mov    (%rbx),%rdi
mov    0x8(%rbx),%rsi
mov    $0x1,%edx
call   10d0 <usage@plt>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
xor    %edx,%edx
call   10b0 <allocate_matrix@plt>
mov    %rax,%r14
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
xor    %edx,%edx
call   10b0 <allocate_matrix@plt>
mov    %rax,%r13
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
mov    $0x2e,%edx
call   10b0 <allocate_matrix@plt>
mov    %rax,%r15
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0x20(%rsp),%r12
lea    0x28(%rsp),%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
call   1080 <set_A1_A2@plt>
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
movsd  0x18(%rsp),%xmm0
mov    %r14,%rdi
mov    %r13,%rsi
call   10a0 <populate_bonds@plt>
mov    0x10(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    %rbp,(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
mov    %r12,%r9
call   1060 <print_lattice@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0x14(%rsp),%rax
mov    %rax,(%rsp)
lea    0x30(%rsp),%r9
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12,%r8
call   1070 <get_bonded_neighbors@plt>
mov    0x20(%rsp),%esi
mov    0x24(%rsp),%edx
lea    0xc85(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x14(%rsp),%eax
test   %eax,%eax
je     13a1 <test_get_bonded_neighbors+0x1f1>
test   %eax,%eax
jg     13b5 <test_get_bonded_neighbors+0x205>
jmp    13e0 <test_get_bonded_neighbors+0x230>
lea    0xc9e(%rip),%rdi
call   1040 <puts@plt>
mov    0x14(%rsp),%eax
test   %eax,%eax
jle    13e0 <test_get_bonded_neighbors+0x230>
lea    0xc7a(%rip),%rbp
xor    %ebx,%ebx
xchg   %ax,%ax
mov    0x30(%rsp,%rbx,8),%esi
mov    0x34(%rsp,%rbx,8),%edx
mov    %rbp,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
add    $0x1,%rbx
movslq 0x14(%rsp),%rax
cmp    %rax,%rbx
jl     13c0 <test_get_bonded_neighbors+0x210>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %r14,%rdi
call   1050 <free_matrix@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %r13,%rdi
call   1050 <free_matrix@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %r15,%rdi
call   1050 <free_matrix@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"M=%d\00"
@.str.1 = [5 x i8] c"N=%d\00"
@.str.2 = [6 x i8] c"MN=%d\00"
@.str.3 = [6 x i8] c"p=%lf\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [37 x i8] c"Bonded neighbors of A1 at (%d, %d):\0A\00"
@.str.6 = [8 x i8] c"(none)\0A\00"
@.str.7 = [16 x i8] c" ( %3d, %3d )\0A\00"
define void @test_get_bonded_neighbors(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32**
%10 = alloca i32**
%11 = alloca i32**
%12 = alloca [2 x i32]
%13 = alloca [2 x i32]
%14 = alloca [4 x [2 x i32]]
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 18, i32* %5
store i32 18, i32* %6
store double 6.000000e-01, double* %7
store i32 2, i32* %8
br label %17
17: ; preds = %70, %2
%18 = load i32, i32* %8
%19 = load i32, i32* %3
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %73
21: ; preds = %17
%22 = load i8**, i8*** %4
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 (i8*, i8*, ...) @sscanf(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %5)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %21
br label %69
30: ; preds = %21
%31 = load i8**, i8*** %4
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 (i8*, i8*, ...) @sscanf(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %39
38: ; preds = %30
br label %68
39: ; preds = %30
%40 = load i8**, i8*** %4
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 (i8*, i8*, ...) @sscanf(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %49
47: ; preds = %39
%48 = load i32, i32* %5
store i32 %48, i32* %6
br label %67
49: ; preds = %39
%50 = load i8**, i8*** %4
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 (i8*, i8*, ...) @sscanf(i8* %54, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double* %7)
%56 = icmp eq i32 %55, 1
br i1 %56, label %57, label %58
57: ; preds = %49
br label %66
58: ; preds = %49
%59 = load i8**, i8*** %4
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = load i8**, i8*** %4
%63 = getelementptr inbounds i8*, i8** %62, i64 1
%64 = load i8*, i8** %63
%65 = call i32 @usage(i8* %61, i8* %64, i32 0)
br label %66
66: ; preds = %58, %57
br label %67
67: ; preds = %66, %47
br label %68
68: ; preds = %67, %38
br label %69
69: ; preds = %68, %29
br label %70
70: ; preds = %69
%71 = load i32, i32* %8
%72 = add nsw i32 %71, 1
store i32 %72, i32* %8
br label %17
73: ; preds = %17
%74 = load i32, i32* %5
%75 = icmp slt i32 %74, 3
br i1 %75, label %79, label %76
76: ; preds = %73
%77 = load i32, i32* %6
%78 = icmp slt i32 %77, 3
br i1 %78, label %79, label %87
79: ; preds = %76, %73
%80 = load i8**, i8*** %4
%81 = getelementptr inbounds i8*, i8** %80, i64 0
%82 = load i8*, i8** %81
%83 = load i8**, i8*** %4
%84 = getelementptr inbounds i8*, i8** %83, i64 1
%85 = load i8*, i8** %84
%86 = call i32 @usage(i8* %82, i8* %85, i32 1)
br label %87
87: ; preds = %79, %76
%88 = load i32, i32* %5
%89 = load i32, i32* %6
%90 = call i32** @allocate_matrix(i32 %88, i32 %89, i8 signext 0)
store i32** %90, i32*** %9
%91 = load i32, i32* %5
%92 = load i32, i32* %6
%93 = call i32** @allocate_matrix(i32 %91, i32 %92, i8 signext 0)
store i32** %93, i32*** %10
%94 = load i32, i32* %5
%95 = load i32, i32* %6
%96 = call i32** @allocate_matrix(i32 %94, i32 %95, i8 signext 46)
store i32** %96, i32*** %11
%97 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%98 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%99 = load i32, i32* %5
%100 = load i32, i32* %6
%101 = call i32 @set_A1_A2(i32* %97, i32* %98, i32 %99, i32 %100)
%102 = load i32**, i32*** %9
%103 = load i32**, i32*** %10
%104 = load i32, i32* %5
%105 = load i32, i32* %6
%106 = load double, double* %7
%107 = call i32 @populate_bonds(i32** %102, i32** %103, i32 %104, i32 %105, double %106)
%108 = load i32**, i32*** %11
%109 = load i32**, i32*** %9
%110 = load i32**, i32*** %10
%111 = load i32, i32* %5
%112 = load i32, i32* %6
%113 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%114 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%115 = call i32 @print_lattice(i32** %108, i32** %109, i32** %110, i32 %111, i32 %112, i32* %113, i32* %114)
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%117 = load i32**, i32*** %9
%118 = load i32**, i32*** %10
%119 = load i32, i32* %5
%120 = load i32, i32* %6
%121 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%122 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %14, i64 0, i64 0
%123 = bitcast [2 x i32]* %122 to i32**
%124 = call i32 @get_bonded_neighbors(i32** %117, i32** %118, i32 %119, i32 %120, i32* %121, i32** %123, i32* %15)
%125 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%126 = load i32, i32* %125
%127 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%128 = load i32, i32* %127
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %126, i32 %128)
%130 = load i32, i32* %15
%131 = icmp eq i32 %130, 0
br i1 %131, label %132, label %134
132: ; preds = %87
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %134
134: ; preds = %132, %87
store i32 0, i32* %16
br label %135
135: ; preds = %151, %134
%136 = load i32, i32* %16
%137 = load i32, i32* %15
%138 = icmp slt i32 %136, %137
br i1 %138, label %139, label %154
139: ; preds = %135
%140 = load i32, i32* %16
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %14, i64 0, i64 %141
%143 = getelementptr inbounds [2 x i32], [2 x i32]* %142, i64 0, i64 0
%144 = load i32, i32* %143
%145 = load i32, i32* %16
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %14, i64 0, i64 %146
%148 = getelementptr inbounds [2 x i32], [2 x i32]* %147, i64 0, i64 1
%149 = load i32, i32* %148
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 %144, i32 %149)
br label %151
151: ; preds = %139
%152 = load i32, i32* %16
%153 = add nsw i32 %152, 1
store i32 %153, i32* %16
br label %135
154: ; preds = %135
%155 = load i32**, i32*** %9
%156 = load i32, i32* %5
%157 = load i32, i32* %6
%158 = call i32 @free_matrix(i32** %155, i32 %156, i32 %157)
%159 = load i32**, i32*** %10
%160 = load i32, i32* %5
%161 = load i32, i32* %6
%162 = call i32 @free_matrix(i32** %159, i32 %160, i32 %161)
%163 = load i32**, i32*** %11
%164 = load i32, i32* %5
%165 = load i32, i32* %6
%166 = call i32 @free_matrix(i32** %163, i32 %164, i32 %165)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"M=%d\00"
@.str.1 = [5 x i8] c"N=%d\00"
@.str.2 = [6 x i8] c"MN=%d\00"
@.str.3 = [6 x i8] c"p=%lf\00"
@.str.5 = [37 x i8] c"Bonded neighbors of A1 at (%d, %d):\0A\00"
@.str.7 = [16 x i8] c" ( %3d, %3d )\0A\00"
@str = [7 x i8] c"(none)\00"
define void @test_get_bonded_neighbors(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca [4 x [2 x i32]]
%9 = alloca i32
%10 = bitcast i32* %3 to i8*
store i32 18, i32* %3
%11 = bitcast i32* %4 to i8*
store i32 18, i32* %4
%12 = bitcast double* %5 to i8*
store double 6.000000e-01, double* %5
%13 = bitcast [2 x i32]* %6 to i8*
%14 = bitcast [2 x i32]* %7 to i8*
%15 = bitcast [4 x [2 x i32]]* %8 to i8*
%16 = bitcast i32* %9 to i8*
%17 = icmp sgt i32 %0, 2
br i1 %17, label %18, label %51
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = zext i32 %0 to i64
br label %21
21: ; preds = %18, %45
%22 = phi i64 [ 2, %18 ], [ %46, %45 ]
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 (i8*, i8*, ...) @sscanf(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3)
%26 = icmp eq i32 %25, 1
br i1 %26, label %45, label %27
27: ; preds = %21
%28 = load i8*, i8** %23
%29 = call i32 (i8*, i8*, ...) @sscanf(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%30 = icmp eq i32 %29, 1
br i1 %30, label %45, label %31
31: ; preds = %27
%32 = load i8*, i8** %23
%33 = call i32 (i8*, i8*, ...) @sscanf(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = load i32, i32* %3
store i32 %36, i32* %4
br label %45
37: ; preds = %31
%38 = load i8*, i8** %23
%39 = call i32 (i8*, i8*, ...) @sscanf(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double* %5)
%40 = icmp eq i32 %39, 1
br i1 %40, label %45, label %41
41: ; preds = %37
%42 = load i8*, i8** %1
%43 = load i8*, i8** %19
%44 = call i32 @usage(i8* %42, i8* %43, i32 0)
br label %45
45: ; preds = %21, %35, %37, %41, %27
%46 = add nuw nsw i64 %22, 1
%47 = icmp eq i64 %46, %20
br i1 %47, label %48, label %21
48: ; preds = %45
%49 = load i32, i32* %3
%50 = load i32, i32* %4
br label %51
51: ; preds = %48, %2
%52 = phi i32 [ %50, %48 ], [ 18, %2 ]
%53 = phi i32 [ %49, %48 ], [ 18, %2 ]
%54 = icmp slt i32 %53, 3
%55 = icmp slt i32 %52, 3
%56 = select i1 %54, i1 true, i1 %55
br i1 %56, label %57, label %64
57: ; preds = %51
%58 = load i8*, i8** %1
%59 = getelementptr inbounds i8*, i8** %1, i64 1
%60 = load i8*, i8** %59
%61 = call i32 @usage(i8* %58, i8* %60, i32 1)
%62 = load i32, i32* %3
%63 = load i32, i32* %4
br label %64
64: ; preds = %51, %57
%65 = phi i32 [ %52, %51 ], [ %63, %57 ]
%66 = phi i32 [ %53, %51 ], [ %62, %57 ]
%67 = call i32** @allocate_matrix(i32 %66, i32 %65, i8 signext 0)
%68 = load i32, i32* %3
%69 = load i32, i32* %4
%70 = call i32** @allocate_matrix(i32 %68, i32 %69, i8 signext 0)
%71 = load i32, i32* %3
%72 = load i32, i32* %4
%73 = call i32** @allocate_matrix(i32 %71, i32 %72, i8 signext 46)
%74 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%76 = load i32, i32* %3
%77 = load i32, i32* %4
%78 = call i32 @set_A1_A2(i32* %74, i32* %75, i32 %76, i32 %77)
%79 = load i32, i32* %3
%80 = load i32, i32* %4
%81 = load double, double* %5
%82 = call i32 @populate_bonds(i32** %67, i32** %70, i32 %79, i32 %80, double %81)
%83 = load i32, i32* %3
%84 = load i32, i32* %4
%85 = call i32 @print_lattice(i32** %73, i32** %67, i32** %70, i32 %83, i32 %84, i32* %74, i32* %75)
%86 = call i32 @putchar(i32 10)
%87 = load i32, i32* %3
%88 = load i32, i32* %4
%89 = bitcast [4 x [2 x i32]]* %8 to i32**
%90 = call i32 @get_bonded_neighbors(i32** %67, i32** %70, i32 %87, i32 %88, i32* %74, i32** %89, i32* %9)
%91 = load i32, i32* %74
%92 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%93 = load i32, i32* %92
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %91, i32 %93)
%95 = load i32, i32* %9
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %64
%98 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%99 = load i32, i32* %9
br label %100
100: ; preds = %97, %64
%101 = phi i32 [ %99, %97 ], [ %95, %64 ]
%102 = icmp sgt i32 %101, 0
br i1 %102, label %103, label %114
103: ; preds = %100, %103
%104 = phi i64 [ %110, %103 ], [ 0, %100 ]
%105 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %8, i64 0, i64 %104, i64 0
%106 = load i32, i32* %105
%107 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %8, i64 0, i64 %104, i64 1
%108 = load i32, i32* %107
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 %106, i32 %108)
%110 = add nuw nsw i64 %104, 1
%111 = load i32, i32* %9
%112 = sext i32 %111 to i64
%113 = icmp slt i64 %110, %112
br i1 %113, label %103, label %114
114: ; preds = %103, %100
%115 = load i32, i32* %3
%116 = load i32, i32* %4
%117 = call i32 @free_matrix(i32** %67, i32 %115, i32 %116)
%118 = load i32, i32* %3
%119 = load i32, i32* %4
%120 = call i32 @free_matrix(i32** %70, i32 %118, i32 %119)
%121 = load i32, i32* %3
%122 = load i32, i32* %4
%123 = call i32 @free_matrix(i32** %73, i32 %121, i32 %122)
ret void
}