; LLVM IR from totte174/minesolve :: src (probability)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.EquationSet = type { [1024 x %struct.Equation], i32, [192 x i32], [192 x i32], i32, %struct.Mask, %struct.Mask }
%struct.Equation = type { %struct.Mask, i32 }
%struct.Mask = type { [3 x i64] }
%struct.Edge = type { [192 x i32], i32, [192 x i32], [192 x i32], i32, i32, [192 x i32], i32 }
%struct.ProbabilityMap = type { double, [192 x double], [192 x double], double }
%struct.Board = type { i32, i32, i32, i32, [1024 x i32], [1024 x i8], [1024 x i8], i8 }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @get_pmap_basic(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.EquationSet, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 34360, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call i32 @get_equation_set(ptr noundef %15, ptr noundef %16, ptr noundef %8, ptr noundef %17)
  store i32 %18, ptr %9, align 4, !tbaa !9
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %3
  %22 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %22, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %92

23:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %41, %23
  %25 = load i32, ptr %12, align 4, !tbaa !9
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Edge, ptr %26, i32 0, i32 7
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = icmp slt i32 %25, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %24
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %44

31:                                               ; preds = %24
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ProbabilityMap, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %12, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [192 x double], ptr %33, i64 0, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = fptosi double %37 to i32
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = add nsw i32 %39, %38
  store i32 %40, ptr %11, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %31
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %12, align 4, !tbaa !9
  br label %24, !llvm.loop !15

44:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store double 0.000000e+00, ptr %13, align 8, !tbaa !13
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Board, ptr %45, i32 0, i32 3
  %47 = load i32, ptr %46, align 4, !tbaa !17
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Edge, ptr %48, i32 0, i32 7
  %50 = load i32, ptr %49, align 4, !tbaa !11
  %51 = sub nsw i32 %47, %50
  %52 = icmp sgt i32 %51, 0
  br i1 %52, label %53, label %69

53:                                               ; preds = %44
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Board, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 4, !tbaa !20
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = sub nsw i32 %56, %57
  %59 = sitofp i32 %58 to double
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Board, ptr %60, i32 0, i32 3
  %62 = load i32, ptr %61, align 4, !tbaa !17
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Edge, ptr %63, i32 0, i32 7
  %65 = load i32, ptr %64, align 4, !tbaa !11
  %66 = sub nsw i32 %62, %65
  %67 = sitofp i32 %66 to double
  %68 = fdiv double %59, %67
  store double %68, ptr %13, align 8, !tbaa !13
  br label %69

69:                                               ; preds = %53, %44
  %70 = load double, ptr %13, align 8, !tbaa !13
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.ProbabilityMap, ptr %71, i32 0, i32 3
  store double %70, ptr %72, align 8, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %73

73:                                               ; preds = %87, %69
  %74 = load i32, ptr %14, align 4, !tbaa !9
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.Edge, ptr %75, i32 0, i32 1
  %77 = load i32, ptr %76, align 4, !tbaa !23
  %78 = icmp slt i32 %74, %77
  br i1 %78, label %80, label %79

79:                                               ; preds = %73
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %90

80:                                               ; preds = %73
  %81 = load double, ptr %13, align 8, !tbaa !13
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.ProbabilityMap, ptr %82, i32 0, i32 1
  %84 = load i32, ptr %14, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [192 x double], ptr %83, i64 0, i64 %85
  store double %81, ptr %86, align 8, !tbaa !13
  br label %87

87:                                               ; preds = %80
  %88 = load i32, ptr %14, align 4, !tbaa !9
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %14, align 4, !tbaa !9
  br label %73, !llvm.loop !24

90:                                               ; preds = %79
  %91 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %91, ptr %4, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %92

92:                                               ; preds = %90, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 34360, ptr %8) #3
  %93 = load i32, ptr %4, align 4
  ret i32 %93
}

declare i32 @get_equation_set(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 3084}
!12 = !{!"Edge", !7, i64 0, !10, i64 768, !7, i64 772, !7, i64 1540, !10, i64 2308, !10, i64 2312, !7, i64 2316, !10, i64 3084}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !10, i64 12}
!18 = !{!"Board", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 4112, !7, i64 5136, !19, i64 6160}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!18, !10, i64 8}
!21 = !{!22, !14, i64 3080}
!22 = !{!"ProbabilityMap", !14, i64 0, !7, i64 8, !7, i64 1544, !14, i64 3080}
!23 = !{!12, !10, i64 768}
!24 = distinct !{!24, !16}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.EquationSet = type { [1024 x %struct.Equation], i32, [192 x i32], [192 x i32], i32, %struct.Mask, %struct.Mask }
%struct.Equation = type { %struct.Mask, i32 }
%struct.Mask = type { [3 x i64] }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @get_pmap_basic(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.EquationSet, align 8
  call void @llvm.lifetime.start.p0(i64 34360, ptr nonnull %4) #4
  %5 = call i32 @get_equation_set(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %4, ptr noundef %2) #4
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %3
  %6 = getelementptr inbounds i8, ptr %1, i64 3084
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %2, i64 1544
  %wide.trip.count = zext nneg i32 %7 to i64
  %min.iters.check = icmp ult i32 %7, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %.02832.ph = phi i32 [ 0, %.lr.ph ], [ %17, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i32> [ zeroinitializer, %vector.ph ], [ %14, %vector.body ]
  %vec.phi44 = phi <2 x i32> [ zeroinitializer, %vector.ph ], [ %15, %vector.body ]
  %10 = getelementptr inbounds [192 x double], ptr %9, i64 0, i64 %index
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %wide.load = load <2 x double>, ptr %10, align 8, !tbaa !10
  %wide.load45 = load <2 x double>, ptr %11, align 8, !tbaa !10
  %12 = fptosi <2 x double> %wide.load to <2 x i32>
  %13 = fptosi <2 x double> %wide.load45 to <2 x i32>
  %14 = add <2 x i32> %vec.phi, %12
  %15 = add <2 x i32> %vec.phi44, %13
  %index.next = add nuw i64 %index, 4
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !12

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i32> %15, %14
  %17 = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %.preheader
  %.028.lcssa = phi i32 [ 0, %.preheader ], [ %17, %middle.block ], [ %25, %scalar.ph ]
  %18 = getelementptr inbounds i8, ptr %0, i64 12
  %19 = load i32, ptr %18, align 4, !tbaa !16
  %20 = sub nsw i32 %19, %7
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %26, label %33

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %.02832 = phi i32 [ %25, %scalar.ph ], [ %.02832.ph, %scalar.ph.preheader ]
  %22 = getelementptr inbounds [192 x double], ptr %9, i64 0, i64 %indvars.iv
  %23 = load double, ptr %22, align 8, !tbaa !10
  %24 = fptosi double %23 to i32
  %25 = add nsw i32 %.02832, %24
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !19

26:                                               ; preds = %._crit_edge
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = load i32, ptr %27, align 4, !tbaa !20
  %29 = sub nsw i32 %28, %.028.lcssa
  %30 = sitofp i32 %29 to double
  %31 = uitofp nneg i32 %20 to double
  %32 = fdiv double %30, %31
  br label %33

33:                                               ; preds = %26, %._crit_edge
  %.026 = phi double [ %32, %26 ], [ 0.000000e+00, %._crit_edge ]
  %34 = getelementptr inbounds i8, ptr %2, i64 3080
  store double %.026, ptr %34, align 8, !tbaa !21
  %35 = getelementptr inbounds i8, ptr %1, i64 768
  %36 = load i32, ptr %35, align 4, !tbaa !23
  %37 = icmp sgt i32 %36, 0
  br i1 %37, label %.lr.ph37, label %.loopexit

.lr.ph37:                                         ; preds = %33
  %38 = getelementptr inbounds i8, ptr %2, i64 8
  %wide.trip.count42 = zext nneg i32 %36 to i64
  %min.iters.check48 = icmp ult i32 %36, 4
  br i1 %min.iters.check48, label %scalar.ph47.preheader, label %vector.ph49

vector.ph49:                                      ; preds = %.lr.ph37
  %n.vec51 = and i64 %wide.trip.count42, 2147483644
  %broadcast.splatinsert = insertelement <2 x double> poison, double %.026, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body53

vector.body53:                                    ; preds = %vector.body53, %vector.ph49
  %index54 = phi i64 [ 0, %vector.ph49 ], [ %index.next55, %vector.body53 ]
  %39 = getelementptr inbounds [192 x double], ptr %38, i64 0, i64 %index54
  %40 = getelementptr inbounds i8, ptr %39, i64 16
  store <2 x double> %broadcast.splat, ptr %39, align 8, !tbaa !10
  store <2 x double> %broadcast.splat, ptr %40, align 8, !tbaa !10
  %index.next55 = add nuw i64 %index54, 4
  %41 = icmp eq i64 %index.next55, %n.vec51
  br i1 %41, label %middle.block46, label %vector.body53, !llvm.loop !24

middle.block46:                                   ; preds = %vector.body53
  %cmp.n56 = icmp eq i64 %n.vec51, %wide.trip.count42
  br i1 %cmp.n56, label %.loopexit, label %scalar.ph47.preheader

scalar.ph47.preheader:                            ; preds = %middle.block46, %.lr.ph37
  %indvars.iv39.ph = phi i64 [ 0, %.lr.ph37 ], [ %n.vec51, %middle.block46 ]
  br label %scalar.ph47

scalar.ph47:                                      ; preds = %scalar.ph47.preheader, %scalar.ph47
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %scalar.ph47 ], [ %indvars.iv39.ph, %scalar.ph47.preheader ]
  %42 = getelementptr inbounds [192 x double], ptr %38, i64 0, i64 %indvars.iv39
  store double %.026, ptr %42, align 8, !tbaa !10
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next40, %wide.trip.count42
  br i1 %exitcond43.not, label %.loopexit, label %scalar.ph47, !llvm.loop !25

.loopexit:                                        ; preds = %scalar.ph47, %middle.block46, %33, %3
  call void @llvm.lifetime.end.p0(i64 34360, ptr nonnull %4) #4
  ret i32 %5
}

declare i32 @get_equation_set(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v2i32(<2 x i32>) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !9, i64 3084}
!6 = !{!"Edge", !7, i64 0, !9, i64 768, !7, i64 772, !7, i64 1540, !9, i64 2308, !9, i64 2312, !7, i64 2316, !9, i64 3084}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !7, i64 0}
!12 = distinct !{!12, !13, !14, !15}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = !{!17, !9, i64 12}
!17 = !{!"Board", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !7, i64 16, !7, i64 4112, !7, i64 5136, !18, i64 6160}
!18 = !{!"_Bool", !7, i64 0}
!19 = distinct !{!19, !13, !15, !14}
!20 = !{!17, !9, i64 8}
!21 = !{!22, !11, i64 3080}
!22 = !{!"ProbabilityMap", !11, i64 0, !7, i64 8, !7, i64 1544, !11, i64 3080}
!23 = !{!6, !9, i64 768}
!24 = distinct !{!24, !13, !14, !15}
!25 = distinct !{!25, !13, !15, !14}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass