; 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 }

@cursor_x2 = external dso_local global i32, align 4
@cursor_y2 = external dso_local global i32, align 4

; 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 @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 void @transform_to_board(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @is_tile_selection_accepted(ptr noundef byval(%struct.Game) align 8 %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [64 x [64 x i32]], align 16
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %11 = load i32, ptr @cursor_x2, align 4, !tbaa !5
  store i32 %11, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %12 = load i32, ptr @cursor_y2, align 4, !tbaa !5
  store i32 %12, ptr %4, align 4, !tbaa !5
  call void @transform_to_board(ptr noundef %3, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %13 = getelementptr inbounds %struct.Game, ptr %0, i32 0, i32 1
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [8 x [8 x i16]], ptr %13, i64 0, i64 %15
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [8 x i16], ptr %16, i64 0, i64 %18
  %20 = load i16, ptr %19, align 2, !tbaa !9
  %21 = sext i16 %20 to i32
  %22 = call i32 @get_piece_owner(i32 noundef %21)
  store i32 %22, ptr %5, align 4, !tbaa !5
  %23 = getelementptr inbounds %struct.Game, ptr %0, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = and i32 %24, 1
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %1
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 2
  br i1 %29, label %38, label %30

30:                                               ; preds = %27, %1
  %31 = getelementptr inbounds %struct.Game, ptr %0, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = and i32 %32, 2
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %39

35:                                               ; preds = %30
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %39

38:                                               ; preds = %35, %27
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %76

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

50:                                               ; preds = %69, %39
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = icmp slt i32 %51, 64
  br i1 %52, label %54, label %53

53:                                               ; preds = %50
  store i32 2, ptr %6, align 4
  br label %72

54:                                               ; preds = %50
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = icmp ne i32 %55, %56
  br i1 %57, label %58, label %68

58:                                               ; preds = %54
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [64 x [64 x i32]], ptr %7, i64 0, i64 %60
  %62 = load i32, ptr %10, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [64 x i32], ptr %61, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %58
  store i8 1, ptr %9, align 1, !tbaa !13
  store i32 2, ptr %6, align 4
  br label %72

68:                                               ; preds = %58, %54
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %10, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %10, align 4, !tbaa !5
  br label %50, !llvm.loop !15

72:                                               ; preds = %67, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %73

73:                                               ; preds = %72
  %74 = load i8, ptr %9, align 1, !tbaa !13, !range !17, !noundef !18
  %75 = trunc i8 %74 to i1
  store i1 %75, ptr %2, align 1
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 16384, ptr %7) #3
  br label %76

76:                                               ; preds = %73, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %77 = load i1, ptr %2, align 1
  ret i1 %77
}

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 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{i8 0, i8 2}
!18 = !{}


; 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 }

@cursor_x2 = external dso_local local_unnamed_addr global i32, align 4
@cursor_y2 = external dso_local local_unnamed_addr global i32, align 4

; 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 @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 void @transform_to_board(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @is_tile_selection_accepted(ptr noundef byval(%struct.Game) align 8 %0) local_unnamed_addr #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca [64 x [64 x i32]], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %5 = load i32, ptr @cursor_x2, align 4, !tbaa !5
  store i32 %5, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %6 = load i32, ptr @cursor_y2, align 4, !tbaa !5
  store i32 %6, ptr %3, align 4, !tbaa !5
  call void @transform_to_board(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [8 x [8 x i16]], ptr %7, i64 0, i64 %9, i64 %11
  %13 = load i16, ptr %12, align 2, !tbaa !9
  %14 = sext i16 %13 to i32
  %15 = call i32 @get_piece_owner(i32 noundef %14)
  %16 = getelementptr inbounds i8, ptr %0, i64 132
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = and i32 %17, 1
  %19 = icmp ne i32 %18, 0
  %20 = icmp eq i32 %15, 2
  %or.cond = select i1 %19, i1 %20, i1 false
  br i1 %or.cond, label %45, label %21

21:                                               ; preds = %1
  %22 = and i32 %17, 2
  %23 = icmp ne i32 %22, 0
  %24 = icmp eq i32 %15, 1
  %or.cond3 = select i1 %23, i1 %24, i1 false
  br i1 %or.cond3, label %45, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 16384, ptr nonnull %4) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16384) %4, i8 0, i64 16384, i1 false)
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !5
  call void @fill_adjacency_matrix(ptr noundef nonnull %7, i32 noundef %17, i32 noundef %26, i32 noundef %27, ptr noundef nonnull %4)
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = call i32 @transform_to_adj(i32 noundef %28, i32 noundef %29)
  %31 = sext i32 %30 to i64
  %32 = zext i32 %30 to i64
  br label %33

33:                                               ; preds = %42, %25
  %indvars.iv = phi i64 [ 0, %25 ], [ %indvars.iv.next.1, %42 ]
  %34 = phi i1 [ true, %25 ], [ %43, %42 ]
  %.not = icmp eq i64 %indvars.iv, %32
  br i1 %.not, label %38, label %35

35:                                               ; preds = %33
  %36 = getelementptr inbounds [64 x [64 x i32]], ptr %4, i64 0, i64 %31, i64 %indvars.iv
  %37 = load i32, ptr %36, align 8, !tbaa !5
  %.not15 = icmp eq i32 %37, 0
  br i1 %.not15, label %38, label %44

38:                                               ; preds = %33, %35
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %.not.1 = icmp eq i64 %indvars.iv.next, %32
  br i1 %.not.1, label %42, label %39

39:                                               ; preds = %38
  %40 = getelementptr inbounds [64 x [64 x i32]], ptr %4, i64 0, i64 %31, i64 %indvars.iv.next
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %.not15.1 = icmp eq i32 %41, 0
  br i1 %.not15.1, label %42, label %44

42:                                               ; preds = %39, %38
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %43 = icmp ult i64 %indvars.iv.next, 63
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 64
  br i1 %exitcond.not.1, label %44, label %33, !llvm.loop !13

44:                                               ; preds = %42, %39, %35
  %.lcssa = phi i1 [ %34, %35 ], [ true, %39 ], [ %43, %42 ]
  call void @llvm.lifetime.end.p0(i64 16384, ptr nonnull %4) #3
  br label %45

45:                                               ; preds = %1, %21, %44
  %.013 = phi i1 [ %.lcssa, %44 ], [ false, %21 ], [ false, %1 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  ret i1 %.013
}

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 = !{!"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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass