#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*/ populate_bonds(int **, int **, int, int, double);
int /*<<< orphan*/ print_lattice(int **, int **, int **, int, int, int *,
                                 int *);
int /*<<< orphan*/ set_A1_A2(int *, int *, int, int);
int sscanf(char *, char *, ...);
int /*<<< orphan*/ usage(char *, char *, int);
void test_print_lattice(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];
  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);
  free_matrix(vbonds, M, N);
  free_matrix(hbonds, M, N);
  free_matrix(site_marks, M, N);
}


x86 assembly (clang, -O0):
<test_print_lattice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x12,-0x14(%rbp)
movl   $0x12,-0x18(%rbp)
movsd  0xe6b(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    129b <test_print_lattice+0x12b>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe48(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    11d9 <test_print_lattice+0x69>
jmp    1288 <test_print_lattice+0x118>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe22(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    1205 <test_print_lattice+0x95>
jmp    1283 <test_print_lattice+0x113>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdf5(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    1237 <test_print_lattice+0xc7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    127e <test_print_lattice+0x10e>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdc9(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    1263 <test_print_lattice+0xf3>
jmp    1279 <test_print_lattice+0x109>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %edx,%edx
call   1090 <usage@plt>
jmp    127e <test_print_lattice+0x10e>
jmp    1283 <test_print_lattice+0x113>
jmp    1288 <test_print_lattice+0x118>
jmp    128d <test_print_lattice+0x11d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a1 <test_print_lattice+0x31>
cmpl   $0x3,-0x14(%rbp)
jl     12af <test_print_lattice+0x13f>
cmpl   $0x3,-0x18(%rbp)
jge    12c8 <test_print_lattice+0x158>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x1,%edx
call   1090 <usage@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1070 <allocate_matrix@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1070 <allocate_matrix@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x2e,%edx
call   1070 <allocate_matrix@plt>
mov    %rax,-0x40(%rbp)
lea    -0x48(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1050 <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   1060 <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>
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    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_print_lattice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%eax
movl   $0x12,0xc(%rsp)
movl   $0x12,0x8(%rsp)
movabs $0x3fe3333333333333,%rcx
33 e3 3f
mov    %rcx,0x10(%rsp)
mov    $0x12,%esi
mov    $0x12,%edi
cmp    $0x3,%eax
jl     1267 <test_print_lattice+0xf7>
mov    %eax,%ebp
mov    $0x2,%r12d
lea    0xe3c(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r13
jmp    11e9 <test_print_lattice+0x79>
mov    0xc(%rsp),%eax
mov    %eax,0x8(%rsp)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r12,%rbp
je     125f <test_print_lattice+0xef>
mov    (%rbx,%r12,8),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     11e0 <test_print_lattice+0x70>
mov    (%rbx,%r12,8),%rdi
lea    0xdfc(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     11e0 <test_print_lattice+0x70>
mov    (%rbx,%r12,8),%rdi
lea    0xde1(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     11d0 <test_print_lattice+0x60>
mov    (%rbx,%r12,8),%rdi
lea    0xdcd(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     11e0 <test_print_lattice+0x70>
mov    (%rbx),%rdi
mov    0x8(%rbx),%rsi
xor    %edx,%edx
call   1090 <usage@plt>
jmp    11e0 <test_print_lattice+0x70>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
cmp    $0x3,%edi
jl     1271 <test_print_lattice+0x101>
cmp    $0x2,%esi
jg     128a <test_print_lattice+0x11a>
mov    (%rbx),%rdi
mov    0x8(%rbx),%rsi
mov    $0x1,%edx
call   1090 <usage@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
xor    %edx,%edx
call   1070 <allocate_matrix@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
xor    %edx,%edx
call   1070 <allocate_matrix@plt>
mov    %rax,%rbp
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    $0x2e,%edx
call   1070 <allocate_matrix@plt>
mov    %rax,%r14
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
lea    0x20(%rsp),%r15
lea    0x18(%rsp),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <set_A1_A2@plt>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <populate_bonds@plt>
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    %r12,(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r15,%r9
call   1040 <print_lattice@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
call   1030 <free_matrix@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %rbp,%rdi
call   1030 <free_matrix@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %r14,%rdi
call   1030 <free_matrix@plt>
add    $0x28,%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"
define void @test_print_lattice(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]
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 %14
14: ; preds = %67, %2
%15 = load i32, i32* %8
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %70
18: ; preds = %14
%19 = load i8**, i8*** %4
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = call i32 (i8*, i8*, ...) @sscanf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %5)
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %18
br label %66
27: ; preds = %18
%28 = load i8**, i8*** %4
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 (i8*, i8*, ...) @sscanf(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %36
35: ; preds = %27
br label %65
36: ; preds = %27
%37 = load i8**, i8*** %4
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 (i8*, i8*, ...) @sscanf(i8* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = load i32, i32* %5
store i32 %45, i32* %6
br label %64
46: ; preds = %36
%47 = load i8**, i8*** %4
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 (i8*, i8*, ...) @sscanf(i8* %51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double* %7)
%53 = icmp eq i32 %52, 1
br i1 %53, label %54, label %55
54: ; preds = %46
br label %63
55: ; preds = %46
%56 = load i8**, i8*** %4
%57 = getelementptr inbounds i8*, i8** %56, i64 0
%58 = load i8*, i8** %57
%59 = load i8**, i8*** %4
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = call i32 @usage(i8* %58, i8* %61, i32 0)
br label %63
63: ; preds = %55, %54
br label %64
64: ; preds = %63, %44
br label %65
65: ; preds = %64, %35
br label %66
66: ; preds = %65, %26
br label %67
67: ; preds = %66
%68 = load i32, i32* %8
%69 = add nsw i32 %68, 1
store i32 %69, i32* %8
br label %14
70: ; preds = %14
%71 = load i32, i32* %5
%72 = icmp slt i32 %71, 3
br i1 %72, label %76, label %73
73: ; preds = %70
%74 = load i32, i32* %6
%75 = icmp slt i32 %74, 3
br i1 %75, label %76, label %84
76: ; preds = %73, %70
%77 = load i8**, i8*** %4
%78 = getelementptr inbounds i8*, i8** %77, i64 0
%79 = load i8*, i8** %78
%80 = load i8**, i8*** %4
%81 = getelementptr inbounds i8*, i8** %80, i64 1
%82 = load i8*, i8** %81
%83 = call i32 @usage(i8* %79, i8* %82, i32 1)
br label %84
84: ; preds = %76, %73
%85 = load i32, i32* %5
%86 = load i32, i32* %6
%87 = call i32** @allocate_matrix(i32 %85, i32 %86, i8 signext 0)
store i32** %87, i32*** %9
%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*** %10
%91 = load i32, i32* %5
%92 = load i32, i32* %6
%93 = call i32** @allocate_matrix(i32 %91, i32 %92, i8 signext 46)
store i32** %93, i32*** %11
%94 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%95 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%96 = load i32, i32* %5
%97 = load i32, i32* %6
%98 = call i32 @set_A1_A2(i32* %94, i32* %95, i32 %96, i32 %97)
%99 = load i32**, i32*** %9
%100 = load i32**, i32*** %10
%101 = load i32, i32* %5
%102 = load i32, i32* %6
%103 = load double, double* %7
%104 = call i32 @populate_bonds(i32** %99, i32** %100, i32 %101, i32 %102, double %103)
%105 = load i32**, i32*** %11
%106 = load i32**, i32*** %9
%107 = load i32**, i32*** %10
%108 = load i32, i32* %5
%109 = load i32, i32* %6
%110 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%111 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%112 = call i32 @print_lattice(i32** %105, i32** %106, i32** %107, i32 %108, i32 %109, i32* %110, i32* %111)
%113 = load i32**, i32*** %9
%114 = load i32, i32* %5
%115 = load i32, i32* %6
%116 = call i32 @free_matrix(i32** %113, i32 %114, i32 %115)
%117 = load i32**, i32*** %10
%118 = load i32, i32* %5
%119 = load i32, i32* %6
%120 = call i32 @free_matrix(i32** %117, i32 %118, i32 %119)
%121 = load i32**, i32*** %11
%122 = load i32, i32* %5
%123 = load i32, i32* %6
%124 = call i32 @free_matrix(i32** %121, i32 %122, i32 %123)
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"
define void @test_print_lattice(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 = bitcast i32* %3 to i8*
store i32 18, i32* %3
%9 = bitcast i32* %4 to i8*
store i32 18, i32* %4
%10 = bitcast double* %5 to i8*
store double 6.000000e-01, double* %5
%11 = bitcast [2 x i32]* %6 to i8*
%12 = bitcast [2 x i32]* %7 to i8*
%13 = icmp sgt i32 %0, 2
br i1 %13, label %14, label %47
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = zext i32 %0 to i64
br label %17
17: ; preds = %14, %41
%18 = phi i64 [ 2, %14 ], [ %42, %41 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 (i8*, i8*, ...) @sscanf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3)
%22 = icmp eq i32 %21, 1
br i1 %22, label %41, label %23
23: ; preds = %17
%24 = load i8*, i8** %19
%25 = call i32 (i8*, i8*, ...) @sscanf(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%26 = icmp eq i32 %25, 1
br i1 %26, label %41, label %27
27: ; preds = %23
%28 = load i8*, i8** %19
%29 = call i32 (i8*, i8*, ...) @sscanf(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i32, i32* %3
store i32 %32, i32* %4
br label %41
33: ; preds = %27
%34 = load i8*, i8** %19
%35 = call i32 (i8*, i8*, ...) @sscanf(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double* %5)
%36 = icmp eq i32 %35, 1
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i8*, i8** %1
%39 = load i8*, i8** %15
%40 = call i32 @usage(i8* %38, i8* %39, i32 0)
br label %41
41: ; preds = %17, %31, %33, %37, %23
%42 = add nuw nsw i64 %18, 1
%43 = icmp eq i64 %42, %16
br i1 %43, label %44, label %17
44: ; preds = %41
%45 = load i32, i32* %3
%46 = load i32, i32* %4
br label %47
47: ; preds = %44, %2
%48 = phi i32 [ %46, %44 ], [ 18, %2 ]
%49 = phi i32 [ %45, %44 ], [ 18, %2 ]
%50 = icmp slt i32 %49, 3
%51 = icmp slt i32 %48, 3
%52 = select i1 %50, i1 true, i1 %51
br i1 %52, label %53, label %60
53: ; preds = %47
%54 = load i8*, i8** %1
%55 = getelementptr inbounds i8*, i8** %1, i64 1
%56 = load i8*, i8** %55
%57 = call i32 @usage(i8* %54, i8* %56, i32 1)
%58 = load i32, i32* %3
%59 = load i32, i32* %4
br label %60
60: ; preds = %47, %53
%61 = phi i32 [ %48, %47 ], [ %59, %53 ]
%62 = phi i32 [ %49, %47 ], [ %58, %53 ]
%63 = call i32** @allocate_matrix(i32 %62, i32 %61, i8 signext 0)
%64 = load i32, i32* %3
%65 = load i32, i32* %4
%66 = call i32** @allocate_matrix(i32 %64, i32 %65, i8 signext 0)
%67 = load i32, i32* %3
%68 = load i32, i32* %4
%69 = call i32** @allocate_matrix(i32 %67, i32 %68, i8 signext 46)
%70 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%72 = load i32, i32* %3
%73 = load i32, i32* %4
%74 = call i32 @set_A1_A2(i32* %70, i32* %71, i32 %72, i32 %73)
%75 = load i32, i32* %3
%76 = load i32, i32* %4
%77 = load double, double* %5
%78 = call i32 @populate_bonds(i32** %63, i32** %66, i32 %75, i32 %76, double %77)
%79 = load i32, i32* %3
%80 = load i32, i32* %4
%81 = call i32 @print_lattice(i32** %69, i32** %63, i32** %66, i32 %79, i32 %80, i32* %70, i32* %71)
%82 = load i32, i32* %3
%83 = load i32, i32* %4
%84 = call i32 @free_matrix(i32** %63, i32 %82, i32 %83)
%85 = load i32, i32* %3
%86 = load i32, i32* %4
%87 = call i32 @free_matrix(i32** %66, i32 %85, i32 %86)
%88 = load i32, i32* %3
%89 = load i32, i32* %4
%90 = call i32 @free_matrix(i32** %69, i32 %88, i32 %89)
ret void
}