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

; 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.SolverSearchState = type { i32, [8 x i32], [8 x i32] }
%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 }
%struct.Arguments = type { [2048 x i8], i32, i32, i32, i32, i32, i32, i8, i8, i8, i8 }

@get_solver_result.state = external hidden global %struct.SolverSearchState, align 4
@get_solver_result.edge = external hidden global %struct.Edge, align 4
@get_solver_result.pmap = external hidden global %struct.ProbabilityMap, align 8

; 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
declare dso_local void @tree_search(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @get_solver_result(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = 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
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Board, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Board, ptr %17, i32 0, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = sub nsw i32 %16, %19
  store i32 %20, ptr %9, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Board, ptr %21, i32 0, i32 3
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Board, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Board, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !16
  %30 = mul nsw i32 %26, %29
  %31 = icmp eq i32 %23, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %4
  store i32 1, ptr %10, align 4, !tbaa !14
  br label %48

33:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Arguments, ptr %34, i32 0, i32 6
  %36 = load i32, ptr %35, align 4, !tbaa !17
  store i32 %36, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %37 = load i32, ptr %9, align 4, !tbaa !14
  store i32 %37, ptr %12, align 4, !tbaa !14
  %38 = load i32, ptr %11, align 4, !tbaa !14
  %39 = load i32, ptr %12, align 4, !tbaa !14
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %33
  %42 = load i32, ptr %11, align 4, !tbaa !14
  br label %45

43:                                               ; preds = %33
  %44 = load i32, ptr %12, align 4, !tbaa !14
  br label %45

45:                                               ; preds = %43, %41
  %46 = phi i32 [ %42, %41 ], [ %44, %43 ]
  store i32 %46, ptr %13, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %47 = load i32, ptr %13, align 4, !tbaa !14
  store i32 %47, ptr %10, align 4, !tbaa !14
  br label %48

48:                                               ; preds = %45, %32
  store i32 0, ptr @get_solver_result.state, align 4, !tbaa !19
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %10, align 4, !tbaa !14
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  call void @tree_search(ptr noundef %49, ptr noundef @get_solver_result.state, i32 noundef %50, ptr noundef %51, ptr noundef @get_solver_result.edge, ptr noundef @get_solver_result.pmap)
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %57

54:                                               ; preds = %48
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  call void @pmap_to_board(ptr noundef %55, ptr noundef @get_solver_result.edge, ptr noundef @get_solver_result.pmap, ptr noundef %56)
  br label %57

57:                                               ; preds = %54, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

declare void @pmap_to_board(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, !11, i64 12}
!10 = !{!"Board", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !7, i64 16, !7, i64 4112, !7, i64 5136, !12, i64 6160}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 0}
!16 = !{!10, !11, i64 4}
!17 = !{!18, !11, i64 2068}
!18 = !{!"Arguments", !7, i64 0, !11, i64 2048, !11, i64 2052, !11, i64 2056, !11, i64 2060, !11, i64 2064, !11, i64 2068, !12, i64 2072, !12, i64 2073, !12, i64 2074, !12, i64 2075}
!19 = !{!20, !11, i64 0}
!20 = !{!"SolverSearchState", !11, i64 0, !7, i64 4, !7, i64 36}


; 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.SolverSearchState = type { i32, [8 x i32], [8 x i32] }
%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 }

@get_solver_result.state = external hidden global %struct.SolverSearchState, align 4
@get_solver_result.edge = external hidden global %struct.Edge, align 4
@get_solver_result.pmap = external hidden global %struct.ProbabilityMap, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @tree_search(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @get_solver_result(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = load i32, ptr %0, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %10 = mul nsw i32 %9, %7
  %11 = icmp eq i32 %6, %10
  br i1 %11, label %19, label %12

12:                                               ; preds = %4
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = sub nsw i32 %6, %14
  %16 = getelementptr inbounds i8, ptr %1, i64 2068
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = tail call i32 @llvm.smin.i32(i32 %17, i32 %15)
  br label %19

19:                                               ; preds = %4, %12
  %.0 = phi i32 [ %18, %12 ], [ 1, %4 ]
  store i32 0, ptr @get_solver_result.state, align 4, !tbaa !16
  tail call void @tree_search(ptr noundef nonnull %0, ptr noundef nonnull @get_solver_result.state, i32 noundef %.0, ptr noundef %2, ptr noundef nonnull @get_solver_result.edge, ptr noundef nonnull @get_solver_result.pmap)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %21, label %20

20:                                               ; preds = %19
  tail call void @pmap_to_board(ptr noundef nonnull %0, ptr noundef nonnull @get_solver_result.edge, ptr noundef nonnull @get_solver_result.pmap, ptr noundef nonnull %3) #3
  br label %21

21:                                               ; preds = %20, %19
  ret void
}

declare void @pmap_to_board(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

attributes #0 = { 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 #1 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 12}
!6 = !{!"Board", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !8, i64 4112, !8, i64 5136, !10, i64 6160}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !7, i64 8}
!14 = !{!15, !7, i64 2068}
!15 = !{!"Arguments", !8, i64 0, !7, i64 2048, !7, i64 2052, !7, i64 2056, !7, i64 2060, !7, i64 2064, !7, i64 2068, !10, i64 2072, !10, i64 2073, !10, i64 2074, !10, i64 2075}
!16 = !{!17, !7, i64 0}
!17 = !{!"SolverSearchState", !7, i64 0, !8, i64 4, !8, i64 36}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass