#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 /*<<< orphan*/ free(int *);
int /*<<< orphan*/ get_cluster_sizes(int **, int, int, int, int *, int *);
scalar_t__ malloc_or_die(int);
int /*<<< orphan*/ mark_cluster_numbers(int **, int **, int **, int, int,
                                        int *);
int /*<<< orphan*/ populate_bonds(int **, int **, int, int, double);
double get_mean_finite_C0_size(int **site_marks, int **vbonds, int **hbonds,
                               int M, int N, double p, int reps, int A1[2]) {
  int num_clusters;
  int *cluster_sizes;
  double mean_finite_C0_size = 0.0;
  int A_cluster_size;
  int rep;
  int num_finite = 0;
  int A_clno;
  int largest_clno;
  for (rep = 0; rep < reps; rep++) {
    populate_bonds(vbonds, hbonds, M, N, p);
    mark_cluster_numbers(site_marks, vbonds, hbonds, M, N, &num_clusters);
    cluster_sizes = (int *)malloc_or_die(sizeof(int) * num_clusters);
    get_cluster_sizes(site_marks, M, N, num_clusters, cluster_sizes,
                      &largest_clno);
    A_clno = site_marks[A1[0]][A1[1]];
    A_cluster_size = cluster_sizes[A_clno];
    if (A_clno != largest_clno) {
      mean_finite_C0_size += A_cluster_size;
      num_finite++;
    }
    free(cluster_sizes);
  }
  if (num_finite == 0)
    mean_finite_C0_size = 0.0;
  else
    mean_finite_C0_size /= num_finite;
  return mean_finite_C0_size;
}


x86 assembly (clang, -O0):
<get_mean_finite_C0_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1261 <get_mean_finite_C0_size+0x111>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
movsd  -0x28(%rbp),%xmm0
call   1050 <populate_bonds@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    -0x30(%rbp),%r9
call   1040 <mark_cluster_numbers@plt>
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc_or_die@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x38(%rbp),%r8
lea    -0x54(%rbp),%r9
call   1070 <get_cluster_sizes@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    0x10(%rbp),%rcx
movslq 0x4(%rcx),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x44(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x54(%rbp),%eax
je     124a <get_mean_finite_C0_size+0xfa>
cvtsi2sdl -0x44(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    118e <get_mean_finite_C0_size+0x3e>
cmpl   $0x0,-0x4c(%rbp)
jne    1278 <get_mean_finite_C0_size+0x128>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    128b <get_mean_finite_C0_size+0x13b>
cvtsi2sdl -0x4c(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mean_finite_C0_size>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movsd  %xmm0,0x40(%rsp)
mov    %r8d,0x1c(%rsp)
mov    %ecx,0x18(%rsp)
mov    %rdx,0x38(%rsp)
mov    %rsi,0x30(%rsp)
mov    %rdi,0x28(%rsp)
test   %r9d,%r9d
jle    1298 <get_mean_finite_C0_size+0x148>
movl   $0x0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    0x30(%rsp),%rbx
mov    0x38(%rsp),%rbp
mov    0x18(%rsp),%r12d
mov    0x1c(%rsp),%r13d
mov    0x28(%rsp),%r14
jmp    11d7 <get_mean_finite_C0_size+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%r9d
add    $0xffffffff,%r9d
je     1279 <get_mean_finite_C0_size+0x129>
mov    %r9d,0x20(%rsp)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
mov    %r13d,%ecx
movsd  0x40(%rsp),%xmm0
call   1050 <populate_bonds@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r12d,%ecx
mov    %r13d,%r8d
lea    0xc(%rsp),%r9
call   1040 <mark_cluster_numbers@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc_or_die@plt>
mov    %rax,%r15
mov    0xc(%rsp),%ecx
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %rax,%r8
lea    0x24(%rsp),%r9
call   1070 <get_cluster_sizes@plt>
mov    0x80(%rsp),%rcx
movslq (%rcx),%rax
mov    (%r14,%rax,8),%rax
movslq 0x4(%rcx),%rcx
movslq (%rax,%rcx,4),%rax
cmp    0x24(%rsp),%eax
je     11c0 <get_mean_finite_C0_size+0x70>
xorps  %xmm0,%xmm0
cvtsi2sdl (%r15,%rax,4),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
addl   $0x1,0x8(%rsp)
jmp    11c0 <get_mean_finite_C0_size+0x70>
mov    0x8(%rsp),%eax
test   %eax,%eax
je     1298 <get_mean_finite_C0_size+0x148>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    129c <get_mean_finite_C0_size+0x14c>
xorpd  %xmm0,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @get_mean_finite_C0_size(i32** %0, i32** %1, i32** %2, i32 %3, i32 %4, double %5, i32 %6, i32* %7) {
%9 = alloca i32**
%10 = alloca i32**
%11 = alloca i32**
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca i32
%16 = alloca i32*
%17 = alloca i32
%18 = alloca i32*
%19 = alloca double
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
store i32** %0, i32*** %9
store i32** %1, i32*** %10
store i32** %2, i32*** %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store double %5, double* %14
store i32 %6, i32* %15
store i32* %7, i32** %16
store double 0.000000e+00, double* %19
store i32 0, i32* %22
store i32 0, i32* %21
br label %25
25: ; preds = %85, %8
%26 = load i32, i32* %21
%27 = load i32, i32* %15
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %88
29: ; preds = %25
%30 = load i32**, i32*** %10
%31 = load i32**, i32*** %11
%32 = load i32, i32* %12
%33 = load i32, i32* %13
%34 = load double, double* %14
%35 = call i32 @populate_bonds(i32** %30, i32** %31, i32 %32, i32 %33, double %34)
%36 = load i32**, i32*** %9
%37 = load i32**, i32*** %10
%38 = load i32**, i32*** %11
%39 = load i32, i32* %12
%40 = load i32, i32* %13
%41 = call i32 @mark_cluster_numbers(i32** %36, i32** %37, i32** %38, i32 %39, i32 %40, i32* %17)
%42 = load i32, i32* %17
%43 = sext i32 %42 to i64
%44 = mul i64 4, %43
%45 = trunc i64 %44 to i32
%46 = call i64 @malloc_or_die(i32 %45)
%47 = inttoptr i64 %46 to i32*
store i32* %47, i32** %18
%48 = load i32**, i32*** %9
%49 = load i32, i32* %12
%50 = load i32, i32* %13
%51 = load i32, i32* %17
%52 = load i32*, i32** %18
%53 = call i32 @get_cluster_sizes(i32** %48, i32 %49, i32 %50, i32 %51, i32* %52, i32* %24)
%54 = load i32**, i32*** %9
%55 = load i32*, i32** %16
%56 = getelementptr inbounds i32, i32* %55, i64 0
%57 = load i32, i32* %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32*, i32** %54, i64 %58
%60 = load i32*, i32** %59
%61 = load i32*, i32** %16
%62 = getelementptr inbounds i32, i32* %61, i64 1
%63 = load i32, i32* %62
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %60, i64 %64
%66 = load i32, i32* %65
store i32 %66, i32* %23
%67 = load i32*, i32** %18
%68 = load i32, i32* %23
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
%71 = load i32, i32* %70
store i32 %71, i32* %20
%72 = load i32, i32* %23
%73 = load i32, i32* %24
%74 = icmp ne i32 %72, %73
br i1 %74, label %75, label %82
75: ; preds = %29
%76 = load i32, i32* %20
%77 = sitofp i32 %76 to double
%78 = load double, double* %19
%79 = fadd double %78, %77
store double %79, double* %19
%80 = load i32, i32* %22
%81 = add nsw i32 %80, 1
store i32 %81, i32* %22
br label %82
82: ; preds = %75, %29
%83 = load i32*, i32** %18
%84 = call i32 @free(i32* %83)
br label %85
85: ; preds = %82
%86 = load i32, i32* %21
%87 = add nsw i32 %86, 1
store i32 %87, i32* %21
br label %25
88: ; preds = %25
%89 = load i32, i32* %22
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %92
91: ; preds = %88
store double 0.000000e+00, double* %19
br label %97
92: ; preds = %88
%93 = load i32, i32* %22
%94 = sitofp i32 %93 to double
%95 = load double, double* %19
%96 = fdiv double %95, %94
store double %96, double* %19
br label %97
97: ; preds = %92, %91
%98 = load double, double* %19
ret double %98
}

LLVM IR (-O2):
define double @get_mean_finite_C0_size(i32** %0, i32** %1, i32** %2, i32 %3, i32 %4, double %5, i32 %6, i32* nocapture %7) {
%9 = alloca i32
%10 = alloca i32
%11 = bitcast i32* %9 to i8*
%12 = bitcast i32* %10 to i8*
%13 = icmp sgt i32 %6, 0
br i1 %13, label %14, label %56
14: ; preds = %8
%15 = getelementptr inbounds i32, i32* %7, i64 1
br label %16
16: ; preds = %14, %45
%17 = phi double [ 0.000000e+00, %14 ], [ %47, %45 ]
%18 = phi i32 [ 0, %14 ], [ %46, %45 ]
%19 = phi i32 [ 0, %14 ], [ %49, %45 ]
%20 = call i32 @populate_bonds(i32** %1, i32** %2, i32 %3, i32 %4, double %5)
%21 = call i32 @mark_cluster_numbers(i32** %0, i32** %1, i32** %2, i32 %3, i32 %4, i32* %9)
%22 = load i32, i32* %9
%23 = shl i32 %22, 2
%24 = call i64 @malloc_or_die(i32 %23)
%25 = inttoptr i64 %24 to i32*
%26 = load i32, i32* %9
%27 = call i32 @get_cluster_sizes(i32** %0, i32 %3, i32 %4, i32 %26, i32* %25, i32* %10)
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32*, i32** %0, i64 %29
%31 = load i32*, i32** %30
%32 = load i32, i32* %15
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = load i32, i32* %10
%37 = icmp eq i32 %35, %36
br i1 %37, label %45, label %38
38: ; preds = %16
%39 = sext i32 %35 to i64
%40 = getelementptr inbounds i32, i32* %25, i64 %39
%41 = load i32, i32* %40
%42 = sitofp i32 %41 to double
%43 = fadd double %17, %42
%44 = add nsw i32 %18, 1
br label %45
45: ; preds = %38, %16
%46 = phi i32 [ %44, %38 ], [ %18, %16 ]
%47 = phi double [ %43, %38 ], [ %17, %16 ]
%48 = call i32 @free(i32* %25)
%49 = add nuw nsw i32 %19, 1
%50 = icmp eq i32 %49, %6
br i1 %50, label %51, label %16
51: ; preds = %45
%52 = icmp eq i32 %46, 0
br i1 %52, label %56, label %53
53: ; preds = %51
%54 = sitofp i32 %46 to double
%55 = fdiv double %47, %54
br label %56
56: ; preds = %8, %51, %53
%57 = phi double [ %55, %53 ], [ 0.000000e+00, %51 ], [ 0.000000e+00, %8 ]
ret double %57
}