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

; 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.SearchResult = type { double, double, i32, i32 }
%struct.Board = type { i32, i32, i32, i32, [1024 x i32], [1024 x i8], [1024 x i8], i8 }

@stderr = external global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [25 x i8], align 1
@show_probability.solver_result = external hidden global %struct.SearchResult, align 8
@show_probability.p_a = external hidden global [1024 x double], align 16
@show_probability.board = external hidden global %struct.Board, align 4
@.str.11 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1

; 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

declare i32 @printf(ptr noundef, ...) #1

declare void @get_solver_result(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare void @get_solver_result_basic(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @parse_board(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @show_probability(ptr noundef %0) #4 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  call void @parse_board(ptr noundef @show_probability.board, ptr noundef %6)
  %7 = load i32, ptr getelementptr inbounds (%struct.Board, ptr @show_probability.board, i32 0, i32 3), align 4, !tbaa !9
  %8 = load i32, ptr getelementptr inbounds (%struct.Board, ptr @show_probability.board, i32 0, i32 2), align 4, !tbaa !13
  %9 = icmp eq i32 %7, %8
  br i1 %9, label %10, label %13

10:                                               ; preds = %1
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef @.str.7) #5
  call void @exit(i32 noundef 1) #6
  unreachable

13:                                               ; preds = %1
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  call void @get_solver_result(ptr noundef @show_probability.board, ptr noundef %14, ptr noundef @show_probability.solver_result, ptr noundef @show_probability.p_a)
  %15 = load i32, ptr getelementptr inbounds (%struct.SearchResult, ptr @show_probability.solver_result, i32 0, i32 3), align 4, !tbaa !14
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %19

17:                                               ; preds = %13
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  call void @get_solver_result_basic(ptr noundef @show_probability.board, ptr noundef %18, ptr noundef @show_probability.solver_result, ptr noundef @show_probability.p_a)
  br label %19

19:                                               ; preds = %17, %13
  %20 = load i32, ptr getelementptr inbounds (%struct.SearchResult, ptr @show_probability.solver_result, i32 0, i32 3), align 4, !tbaa !14
  %21 = icmp eq i32 %20, 3
  br i1 %21, label %22, label %25

22:                                               ; preds = %19
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.8) #5
  call void @exit(i32 noundef 1) #6
  unreachable

25:                                               ; preds = %19
  %26 = load i32, ptr getelementptr inbounds (%struct.SearchResult, ptr @show_probability.solver_result, i32 0, i32 3), align 4, !tbaa !14
  %27 = icmp eq i32 %26, 2
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str.9) #5
  call void @exit(i32 noundef 1) #6
  unreachable

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !17
  br label %32

32:                                               ; preds = %71, %31
  %33 = load i32, ptr %3, align 4, !tbaa !17
  %34 = load i32, ptr getelementptr inbounds (%struct.Board, ptr @show_probability.board, i32 0, i32 1), align 4, !tbaa !18
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %74

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !17
  br label %38

38:                                               ; preds = %66, %37
  %39 = load i32, ptr %5, align 4, !tbaa !17
  %40 = load i32, ptr @show_probability.board, align 4, !tbaa !19
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %69

43:                                               ; preds = %38
  %44 = load i32, ptr %3, align 4, !tbaa !17
  %45 = load i32, ptr @show_probability.board, align 4, !tbaa !19
  %46 = mul nsw i32 %44, %45
  %47 = load i32, ptr %5, align 4, !tbaa !17
  %48 = add nsw i32 %46, %47
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1024 x i8], ptr getelementptr inbounds (%struct.Board, ptr @show_probability.board, i32 0, i32 5), i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !20, !range !21, !noundef !22
  %52 = trunc i8 %51 to i1
  br i1 %52, label %53, label %55

53:                                               ; preds = %43
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  br label %65

55:                                               ; preds = %43
  %56 = load i32, ptr %3, align 4, !tbaa !17
  %57 = load i32, ptr @show_probability.board, align 4, !tbaa !19
  %58 = mul nsw i32 %56, %57
  %59 = load i32, ptr %5, align 4, !tbaa !17
  %60 = add nsw i32 %58, %59
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [1024 x double], ptr @show_probability.p_a, i64 0, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !23
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.12, double noundef %63)
  br label %65

65:                                               ; preds = %55, %53
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %5, align 4, !tbaa !17
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %5, align 4, !tbaa !17
  br label %38, !llvm.loop !24

69:                                               ; preds = %42
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.13)
  br label %71

71:                                               ; preds = %69
  %72 = load i32, ptr %3, align 4, !tbaa !17
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %3, align 4, !tbaa !17
  br label %32, !llvm.loop !26

74:                                               ; preds = %36
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind "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 = { noreturn nounwind "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 #4 = { 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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!15, !11, i64 20}
!15 = !{!"SearchResult", !16, i64 0, !16, i64 8, !11, i64 16, !11, i64 20}
!16 = !{!"double", !7, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !11, i64 4}
!19 = !{!10, !11, i64 0}
!20 = !{!12, !12, i64 0}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!16, !16, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}


; 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.SearchResult = type { double, double, i32, i32 }
%struct.Board = type { i32, i32, i32, i32, [1024 x i32], [1024 x i8], [1024 x i8], i8 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [25 x i8], align 1
@show_probability.solver_result = external hidden global %struct.SearchResult, align 8
@show_probability.p_a = external hidden global [1024 x double], align 16
@show_probability.board = external hidden global %struct.Board, align 4
@.str.11 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @parse_board(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @show_probability(ptr noundef %0) local_unnamed_addr #3 {
  tail call void @parse_board(ptr noundef nonnull @show_probability.board, ptr noundef %0)
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @show_probability.board, i64 12), align 4, !tbaa !5
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @show_probability.board, i64 8), align 4, !tbaa !11
  %4 = icmp eq i32 %2, %3
  br i1 %4, label %5, label %8

5:                                                ; preds = %1
  %6 = load ptr, ptr @stderr, align 8, !tbaa !12
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.7) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

8:                                                ; preds = %1
  tail call void @get_solver_result(ptr noundef nonnull @show_probability.board, ptr noundef %0, ptr noundef nonnull @show_probability.solver_result, ptr noundef nonnull @show_probability.p_a) #6
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @show_probability.solver_result, i64 20), align 4, !tbaa !14
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %12

11:                                               ; preds = %8
  tail call void @get_solver_result_basic(ptr noundef nonnull @show_probability.board, ptr noundef %0, ptr noundef nonnull @show_probability.solver_result, ptr noundef nonnull @show_probability.p_a) #6
  %.pr = load i32, ptr getelementptr inbounds (i8, ptr @show_probability.solver_result, i64 20), align 4, !tbaa !14
  br label %12

12:                                               ; preds = %11, %8
  %13 = phi i32 [ %.pr, %11 ], [ %9, %8 ]
  switch i32 %13, label %.preheader13 [
    i32 3, label %16
    i32 2, label %19
  ]

.preheader13:                                     ; preds = %12
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @show_probability.board, i64 4), align 4, !tbaa !17
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.preheader, label %._crit_edge16

16:                                               ; preds = %12
  %17 = load ptr, ptr @stderr, align 8, !tbaa !12
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.8) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

19:                                               ; preds = %12
  %20 = load ptr, ptr @stderr, align 8, !tbaa !12
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str.9) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

.preheader:                                       ; preds = %.preheader13, %._crit_edge
  %.01015 = phi i32 [ %25, %._crit_edge ], [ 0, %.preheader13 ]
  %22 = load i32, ptr @show_probability.board, align 4, !tbaa !18
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph, label %._crit_edge

._crit_edge16:                                    ; preds = %._crit_edge, %.preheader13
  ret void

._crit_edge:                                      ; preds = %41, %.preheader
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13)
  %25 = add nuw nsw i32 %.01015, 1
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @show_probability.board, i64 4), align 4, !tbaa !17
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %.preheader, label %._crit_edge16, !llvm.loop !19

.lr.ph:                                           ; preds = %.preheader, %41
  %28 = phi i32 [ %43, %41 ], [ %22, %.preheader ]
  %.014 = phi i32 [ %42, %41 ], [ 0, %.preheader ]
  %29 = mul nsw i32 %28, %.01015
  %30 = add nsw i32 %29, %.014
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1024 x i8], ptr getelementptr inbounds (i8, ptr @show_probability.board, i64 4112), i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !21, !range !22, !noundef !23
  %34 = trunc nuw i8 %33 to i1
  br i1 %34, label %35, label %37

35:                                               ; preds = %.lr.ph
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  br label %41

37:                                               ; preds = %.lr.ph
  %38 = getelementptr inbounds [1024 x double], ptr @show_probability.p_a, i64 0, i64 %31
  %39 = load double, ptr %38, align 8, !tbaa !24
  %40 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12, double noundef %39)
  br label %41

41:                                               ; preds = %35, %37
  %42 = add nuw nsw i32 %.014, 1
  %43 = load i32, ptr @show_probability.board, align 4, !tbaa !18
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %.lr.ph, label %._crit_edge, !llvm.loop !25
}

attributes #0 = { nofree nounwind "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 = { noreturn nounwind "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 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 #4 = { cold nounwind }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!15, !7, i64 20}
!15 = !{!"SearchResult", !16, i64 0, !16, i64 8, !7, i64 16, !7, i64 20}
!16 = !{!"double", !8, i64 0}
!17 = !{!6, !7, i64 4}
!18 = !{!6, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!10, !10, i64 0}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!16, !16, i64 0}
!25 = distinct !{!25, !20}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass