#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__ A1_or_A2_in_C(int **, int **, int **, int, int, double, int *, int *,
                         int *);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc_or_die(int);
int /*<<< orphan*/ populate_bonds(int **, int **, int, int, double);
double P_A1_or_A2_in_C(int **site_marks, int **vbonds, int **hbonds, int M,
                       int N, double p, int reps, int A1[2], int A2[2]) {
  int k;
  int num_A1_or_A2_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_A1_or_A2_in_C += A1_or_A2_in_C(site_marks, vbonds, hbonds, M, N, p, A1,
                                       A2, cluster_sizes);
  }
  free(cluster_sizes);
  return (double)num_A1_or_A2_in_C / (double)reps;
}


x86 assembly (clang, -O0):
<P_A1_or_A2_in_C>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x18(%rbp),%rax
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    1206 <P_A1_or_A2_in_C+0xc6>
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    0x18(%rbp),%r10
mov    -0x40(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <A1_or_A2_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    1195 <P_A1_or_A2_in_C+0x55>
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_A1_or_A2_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    11f5 <P_A1_or_A2_in_C+0xb5>
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    0x20(%rsp),%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %ebx,%ecx
mov    %r15d,%r8d
movsd  0x8(%rsp),%xmm0
mov    0x60(%rsp),%r9
push   0x18(%rsp)
push   0x70(%rsp)
call   1060 <A1_or_A2_in_C@plt>
add    $0x10,%rsp
add    %eax,%r14d
add    $0xffffffff,%r12d
jne    1190 <P_A1_or_A2_in_C+0x50>
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x14(%rsp),%r12d
mov    0x18(%rsp),%rax
jmp    11ff <P_A1_or_A2_in_C+0xbf>
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_A1_or_A2_in_C(i32** %0, i32** %1, i32** %2, i32 %3, i32 %4, double %5, i32 %6, i32* %7, i32* %8) {
%10 = alloca i32**
%11 = alloca i32**
%12 = alloca i32**
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32*
store i32** %0, i32*** %10
store i32** %1, i32*** %11
store i32** %2, i32*** %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store double %5, double* %15
store i32 %6, i32* %16
store i32* %7, i32** %17
store i32* %8, i32** %18
store i32 0, i32* %20
%22 = load i32, i32* %13
%23 = sext i32 %22 to i64
%24 = mul i64 4, %23
%25 = load i32, i32* %14
%26 = sext i32 %25 to i64
%27 = mul i64 %24, %26
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc_or_die(i32 %28)
%30 = inttoptr i64 %29 to i32*
store i32* %30, i32** %21
store i32 0, i32* %19
br label %31
31: ; preds = %56, %9
%32 = load i32, i32* %19
%33 = load i32, i32* %16
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %59
35: ; preds = %31
%36 = load i32**, i32*** %11
%37 = load i32**, i32*** %12
%38 = load i32, i32* %13
%39 = load i32, i32* %14
%40 = load double, double* %15
%41 = call i32 @populate_bonds(i32** %36, i32** %37, i32 %38, i32 %39, double %40)
%42 = load i32**, i32*** %10
%43 = load i32**, i32*** %11
%44 = load i32**, i32*** %12
%45 = load i32, i32* %13
%46 = load i32, i32* %14
%47 = load double, double* %15
%48 = load i32*, i32** %17
%49 = load i32*, i32** %18
%50 = load i32*, i32** %21
%51 = call i64 @A1_or_A2_in_C(i32** %42, i32** %43, i32** %44, i32 %45, i32 %46, double %47, i32* %48, i32* %49, i32* %50)
%52 = load i32, i32* %20
%53 = sext i32 %52 to i64
%54 = add nsw i64 %53, %51
%55 = trunc i64 %54 to i32
store i32 %55, i32* %20
br label %56
56: ; preds = %35
%57 = load i32, i32* %19
%58 = add nsw i32 %57, 1
store i32 %58, i32* %19
br label %31
59: ; preds = %31
%60 = load i32*, i32** %21
%61 = call i32 @free(i32* %60)
%62 = load i32, i32* %20
%63 = sitofp i32 %62 to double
%64 = load i32, i32* %16
%65 = sitofp i32 %64 to double
%66 = fdiv double %63, %65
ret double %66
}

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