; LLVM IR from AlgoGenesis/C :: Backtracking Algorithms/Chess-In-Terminal/src (main)

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

; 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 i32 @get_piece_owner(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @transform_to_adj(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @transform_from_adj(i32 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @has_path(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @fill_adjacency_matrix(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @is_in_check(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @make_game(ptr dead_on_unwind noalias writable sret(%struct.Game) align 4) #1

; Function Attrs: nounwind uwtable
declare dso_local void @copy_game(ptr noundef byval(%struct.Game) align 8, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @_make_move(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @is_in_mate(ptr noundef byval(%struct.Game) align 8 %0, i32 noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca [64 x [64 x i32]], align 16
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.Game, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %1, ptr %4, align 4, !tbaa !5
  %14 = getelementptr inbounds %struct.Game, ptr %0, i32 0, i32 1
  %15 = getelementptr inbounds [8 x [8 x i16]], ptr %14, i64 0, i64 0
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = call zeroext i1 @is_in_check(ptr noundef %15, i32 noundef %16)
  br i1 %17, label %19, label %18

18:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %106

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

20:                                               ; preds = %100, %19
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = icmp slt i32 %21, 8
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 2, ptr %6, align 4
  br label %103

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

25:                                               ; preds = %94, %24
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 8
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 5, ptr %6, align 4
  br label %97

29:                                               ; preds = %25
  %30 = getelementptr inbounds %struct.Game, ptr %0, i32 0, i32 1
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [8 x [8 x i16]], ptr %30, i64 0, i64 %32
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [8 x i16], ptr %33, i64 0, i64 %35
  %37 = load i16, ptr %36, align 2, !tbaa !9
  %38 = sext i16 %37 to i32
  %39 = call i32 @get_piece_owner(i32 noundef %38)
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = icmp ne i32 %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %29
  br label %94

43:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 16384, ptr %8) #3
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 16384, i1 false)
  %44 = getelementptr inbounds %struct.Game, ptr %0, i32 0, i32 1
  %45 = getelementptr inbounds [8 x [8 x i16]], ptr %44, i64 0, i64 0
  %46 = getelementptr inbounds %struct.Game, ptr %0, i32 0, i32 2
  %47 = load i32, ptr %46, align 4, !tbaa !11
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = getelementptr inbounds [64 x [64 x i32]], ptr %8, i64 0, i64 0
  call void @fill_adjacency_matrix(ptr noundef %45, i32 noundef %47, i32 noundef %48, i32 noundef %49, ptr noundef %50)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = call i32 @transform_to_adj(i32 noundef %51, i32 noundef %52)
  store i32 %53, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %85, %43
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = icmp slt i32 %55, 64
  br i1 %56, label %58, label %57

57:                                               ; preds = %54
  store i32 8, ptr %6, align 4
  br label %88

58:                                               ; preds = %54
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = icmp ne i32 %59, %60
  br i1 %61, label %62, label %84

62:                                               ; preds = %58
  %63 = getelementptr inbounds [64 x [64 x i32]], ptr %8, i64 0, i64 0
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = call i32 @has_path(ptr noundef %63, i32 noundef %64, i32 noundef %65)
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %84

68:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 144, ptr %11) #3
  call void @make_game(ptr dead_on_unwind writable sret(%struct.Game) align 4 %11)
  call void @copy_game(ptr noundef byval(%struct.Game) align 8 %0, ptr noundef %11)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %69 = load i32, ptr %10, align 4, !tbaa !5
  call void @transform_from_adj(i32 noundef %69, ptr noundef %12, ptr noundef %13)
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = load i32, ptr %7, align 4, !tbaa !5
  %72 = load i32, ptr %12, align 4, !tbaa !5
  %73 = load i32, ptr %13, align 4, !tbaa !5
  %74 = call i32 @_make_move(ptr noundef %11, i32 noundef %70, i32 noundef %71, i32 noundef %72, i32 noundef %73)
  %75 = getelementptr inbounds %struct.Game, ptr %11, i32 0, i32 1
  %76 = getelementptr inbounds [8 x [8 x i16]], ptr %75, i64 0, i64 0
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = call zeroext i1 @is_in_check(ptr noundef %76, i32 noundef %77)
  br i1 %78, label %80, label %79

79:                                               ; preds = %68
  store i1 false, ptr %3, align 1
  store i32 1, ptr %6, align 4
  br label %81

80:                                               ; preds = %68
  store i32 0, ptr %6, align 4
  br label %81

81:                                               ; preds = %80, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 144, ptr %11) #3
  %82 = load i32, ptr %6, align 4
  switch i32 %82, label %88 [
    i32 0, label %83
  ]

83:                                               ; preds = %81
  br label %84

84:                                               ; preds = %83, %62, %58
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %10, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %10, align 4, !tbaa !5
  br label %54, !llvm.loop !13

88:                                               ; preds = %81, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %89 = load i32, ptr %6, align 4
  switch i32 %89, label %91 [
    i32 8, label %90
  ]

90:                                               ; preds = %88
  store i32 0, ptr %6, align 4
  br label %91

91:                                               ; preds = %90, %88
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 16384, ptr %8) #3
  %92 = load i32, ptr %6, align 4
  switch i32 %92, label %97 [
    i32 0, label %93
  ]

93:                                               ; preds = %91
  br label %94

94:                                               ; preds = %93, %42
  %95 = load i32, ptr %7, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %7, align 4, !tbaa !5
  br label %25, !llvm.loop !15

97:                                               ; preds = %91, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %98 = load i32, ptr %6, align 4
  switch i32 %98, label %103 [
    i32 5, label %99
  ]

99:                                               ; preds = %97
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %5, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %5, align 4, !tbaa !5
  br label %20, !llvm.loop !16

103:                                              ; preds = %97, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %104 = load i32, ptr %6, align 4
  switch i32 %104, label %108 [
    i32 2, label %105
    i32 1, label %106
  ]

105:                                              ; preds = %103
  store i1 true, ptr %3, align 1
  br label %106

106:                                              ; preds = %105, %103, %18
  %107 = load i1, ptr %3, align 1
  ret i1 %107

108:                                              ; preds = %103
  unreachable
}

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 132}
!12 = !{!"", !6, i64 0, !7, i64 4, !6, i64 132, !6, i64 136, !6, i64 140}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

; 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
declare dso_local i32 @get_piece_owner(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @transform_to_adj(i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @has_path(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @is_in_check(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @make_game(ptr dead_on_unwind noalias writable sret(%struct.Game) align 4) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @copy_game(ptr noundef byval(%struct.Game) align 8, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @_make_move(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @is_in_mate(ptr noundef byval(%struct.Game) align 8 %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca [64 x [64 x i32]], align 16
  %4 = alloca %struct.Game, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = call zeroext i1 @is_in_check(ptr noundef nonnull %7, i32 noundef %1)
  br i1 %8, label %.preheader45, label %.loopexit

.preheader45:                                     ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 132
  %10 = getelementptr inbounds i8, ptr %4, i64 4
  br label %.preheader

.preheader:                                       ; preds = %.preheader45, %33
  %indvars.iv52 = phi i64 [ 0, %.preheader45 ], [ %indvars.iv.next53, %33 ]
  %11 = trunc nuw nsw i64 %indvars.iv52 to i32
  br label %12

12:                                               ; preds = %.preheader, %31
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %31 ]
  %13 = getelementptr inbounds [8 x [8 x i16]], ptr %7, i64 0, i64 %indvars.iv, i64 %indvars.iv52
  %14 = load i16, ptr %13, align 2, !tbaa !5
  %15 = sext i16 %14 to i32
  %16 = call i32 @get_piece_owner(i32 noundef %15)
  %.not = icmp eq i32 %16, %1
  br i1 %.not, label %17, label %31

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 16384, ptr nonnull %3) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16384) %3, i8 0, i64 16384, i1 false)
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = trunc nuw nsw i64 %indvars.iv to i32
  call void @fill_adjacency_matrix(ptr noundef nonnull %7, i32 noundef %18, i32 noundef %11, i32 noundef %19, ptr noundef nonnull %3)
  %20 = call i32 @transform_to_adj(i32 noundef %11, i32 noundef %19)
  br label %21

.thread:                                          ; preds = %29
  call void @llvm.lifetime.end.p0(i64 16384, ptr nonnull %3) #3
  br label %31

21:                                               ; preds = %17, %29
  %.047 = phi i32 [ 0, %17 ], [ %30, %29 ]
  %.not39 = icmp eq i32 %20, %.047
  br i1 %.not39, label %29, label %22

22:                                               ; preds = %21
  %23 = call i32 @has_path(ptr noundef nonnull %3, i32 noundef %20, i32 noundef %.047)
  %.not40 = icmp eq i32 %23, 0
  br i1 %.not40, label %29, label %24

24:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %4) #3
  call void @make_game(ptr dead_on_unwind nonnull writable sret(%struct.Game) align 4 %4)
  call void @copy_game(ptr noundef nonnull byval(%struct.Game) align 8 %0, ptr noundef nonnull %4)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  call void @transform_from_adj(i32 noundef %.047, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %25 = load i32, ptr %5, align 4, !tbaa !12
  %26 = load i32, ptr %6, align 4, !tbaa !12
  %27 = call i32 @_make_move(ptr noundef nonnull %4, i32 noundef %11, i32 noundef %19, i32 noundef %25, i32 noundef %26)
  %28 = call zeroext i1 @is_in_check(ptr noundef nonnull %10, i32 noundef %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %4) #3
  br i1 %28, label %29, label %32

29:                                               ; preds = %21, %22, %24
  %30 = add nuw nsw i32 %.047, 1
  %exitcond = icmp eq i32 %30, 64
  br i1 %exitcond, label %.thread, label %21, !llvm.loop !13

31:                                               ; preds = %.thread, %12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond51.not = icmp eq i64 %indvars.iv.next, 8
  br i1 %exitcond51.not, label %33, label %12, !llvm.loop !15

32:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 16384, ptr nonnull %3) #3
  br label %.loopexit

33:                                               ; preds = %31
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %exitcond55 = icmp eq i64 %indvars.iv.next53, 8
  br i1 %exitcond55, label %.loopexit, label %.preheader, !llvm.loop !16

.loopexit:                                        ; preds = %33, %32, %2
  %.9 = phi i1 [ false, %2 ], [ false, %32 ], [ true, %33 ]
  ret i1 %.9
}

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 132}
!10 = !{!"", !11, i64 0, !7, i64 4, !11, i64 132, !11, i64 136, !11, i64 140}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass