#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__ A_in_C(int **, int **, int **, int, int, double, int *, int *);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc_or_die(int);
int /*<<< orphan*/ populate_bonds(int **, int **, int, int, double);
double P_A_in_C(int **site_marks, int **vbonds, int **hbonds, int M, int N,
                double p, int reps, int A[2]) {
  int k;
  int num_A_in_C = 0;
  int *cluster_sizes = (int *)malloc_or_die(sizeof(int) * M * N);
  for (k = 0; k < reps; k++) {
    populate_bonds(vbonds, hbonds, M, N, p);
    num_A_in_C += A_in_C(site_marks, vbonds, hbonds, M, N, p, A, cluster_sizes);
  }
  free(cluster_sizes);
  return (double)num_A_in_C / (double)reps;
}


x86 assembly (clang, -O0):
<P_A_in_C>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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)
movl   $0x0,-0x34(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
movslq -0x20(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1050 <malloc_or_die@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11f9 <P_A_in_C+0xb9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
movsd  -0x28(%rbp),%xmm0
call   1040 <populate_bonds@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
movsd  -0x28(%rbp),%xmm0
mov    0x10(%rbp),%r9
mov    -0x40(%rbp),%rax
mov    %rax,(%rsp)
call   1060 <A_in_C@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1191 <P_A_in_C+0x51>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cvtsi2sdl -0x34(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<P_A_in_C>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r12d
movsd  %xmm0,0x8(%rsp)
mov    %r8d,%r15d
mov    %ecx,%ebx
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %ecx,%edi
imul   %r8d,%edi
shl    $0x2,%edi
call   1050 <malloc_or_die@plt>
test   %r12d,%r12d
jle    11f2 <P_A_in_C+0xb2>
mov    %r14,0x20(%rsp)
xor    %r14d,%r14d
mov    %r12d,0x14(%rsp)
mov    %rax,0x18(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
mov    %r15d,%ecx
movsd  0x8(%rsp),%xmm0
call   1040 <populate_bonds@plt>
mov    0x18(%rsp),%rax
mov    %rax,(%rsp)
mov    0x20(%rsp),%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %ebx,%ecx
mov    %r15d,%r8d
movsd  0x8(%rsp),%xmm0
mov    0x60(%rsp),%r9
call   1060 <A_in_C@plt>
add    %eax,%r14d
add    $0xffffffff,%r12d
jne    1190 <P_A_in_C+0x50>
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x14(%rsp),%r12d
mov    0x18(%rsp),%rax
jmp    11fc <P_A_in_C+0xbc>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rax,%rdi
call   1030 <free@plt>
cvtsi2sd %r12d,%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @P_A_in_C(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 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 i32 0, i32* %18
%20 = load i32, i32* %12
%21 = sext i32 %20 to i64
%22 = mul i64 4, %21
%23 = load i32, i32* %13
%24 = sext i32 %23 to i64
%25 = mul i64 %22, %24
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc_or_die(i32 %26)
%28 = inttoptr i64 %27 to i32*
store i32* %28, i32** %19
store i32 0, i32* %17
br label %29
29: ; preds = %53, %8
%30 = load i32, i32* %17
%31 = load i32, i32* %15
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %56
33: ; preds = %29
%34 = load i32**, i32*** %10
%35 = load i32**, i32*** %11
%36 = load i32, i32* %12
%37 = load i32, i32* %13
%38 = load double, double* %14
%39 = call i32 @populate_bonds(i32** %34, i32** %35, i32 %36, i32 %37, double %38)
%40 = load i32**, i32*** %9
%41 = load i32**, i32*** %10
%42 = load i32**, i32*** %11
%43 = load i32, i32* %12
%44 = load i32, i32* %13
%45 = load double, double* %14
%46 = load i32*, i32** %16
%47 = load i32*, i32** %19
%48 = call i64 @A_in_C(i32** %40, i32** %41, i32** %42, i32 %43, i32 %44, double %45, i32* %46, i32* %47)
%49 = load i32, i32* %18
%50 = sext i32 %49 to i64
%51 = add nsw i64 %50, %48
%52 = trunc i64 %51 to i32
store i32 %52, i32* %18
br label %53
53: ; preds = %33
%54 = load i32, i32* %17
%55 = add nsw i32 %54, 1
store i32 %55, i32* %17
br label %29
56: ; preds = %29
%57 = load i32*, i32** %19
%58 = call i32 @free(i32* %57)
%59 = load i32, i32* %18
%60 = sitofp i32 %59 to double
%61 = load i32, i32* %15
%62 = sitofp i32 %61 to double
%63 = fdiv double %60, %62
ret double %63
}

LLVM IR (-O2):
define double @P_A_in_C(i32** %0, i32** %1, i32** %2, i32 %3, i32 %4, double %5, i32 %6, i32* %7) {
%9 = shl i32 %3, 2
%10 = mul i32 %9, %4
%11 = tail call i64 @malloc_or_die(i32 %10)
%12 = inttoptr i64 %11 to i32*
%13 = icmp sgt i32 %6, 0
br i1 %13, label %14, label %25
14: ; preds = %8, %14
%15 = phi i32 [ %21, %14 ], [ 0, %8 ]
%16 = phi i32 [ %20, %14 ], [ 0, %8 ]
%17 = tail call i32 @populate_bonds(i32** %1, i32** %2, i32 %3, i32 %4, double %5)
%18 = tail call i64 @A_in_C(i32** %0, i32** %1, i32** %2, i32 %3, i32 %4, double %5, i32* %7, i32* %12)
%19 = trunc i64 %18 to i32
%20 = add i32 %16, %19
%21 = add nuw nsw i32 %15, 1
%22 = icmp eq i32 %21, %6
br i1 %22, label %23, label %14
23: ; preds = %14
%24 = sitofp i32 %20 to double
br label %25
25: ; preds = %23, %8
%26 = phi double [ 0.000000e+00, %8 ], [ %24, %23 ]
%27 = tail call i32 @free(i32* %12)
%28 = sitofp i32 %6 to double
%29 = fdiv double %26, %28
ret double %29
}