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

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_piece_type(i32 noundef) #0

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @fill_adjacency_matrix(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = load i32, ptr %9, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [8 x i16], ptr %11, i64 %13
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [8 x i16], ptr %14, i64 0, i64 %16
  %18 = load i16, ptr %17, align 2, !tbaa !11
  %19 = sext i16 %18 to i32
  %20 = call i32 @get_piece_type(i32 noundef %19)
  switch i32 %20, label %65 [
    i32 4, label %21
    i32 8, label %27
    i32 16, label %32
    i32 32, label %37
    i32 64, label %42
    i32 128, label %51
  ]

21:                                               ; preds = %5
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = load i32, ptr %9, align 4, !tbaa !9
  call void @add_pawn_like_edges(ptr noundef %22, ptr noundef %23, i32 noundef %24, i32 noundef %25, i32 noundef %26)
  br label %65

27:                                               ; preds = %5
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load i32, ptr %9, align 4, !tbaa !9
  call void @add_knight_like_edges(ptr noundef %28, ptr noundef %29, i32 noundef %30, i32 noundef %31)
  br label %65

32:                                               ; preds = %5
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = load i32, ptr %9, align 4, !tbaa !9
  call void @add_diag_edges(ptr noundef %33, ptr noundef %34, i32 noundef %35, i32 noundef %36, i32 noundef -1)
  br label %65

37:                                               ; preds = %5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = load i32, ptr %9, align 4, !tbaa !9
  call void @add_straight_edges(ptr noundef %38, ptr noundef %39, i32 noundef %40, i32 noundef %41, i32 noundef -1)
  br label %65

42:                                               ; preds = %5
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = load i32, ptr %9, align 4, !tbaa !9
  call void @add_straight_edges(ptr noundef %43, ptr noundef %44, i32 noundef %45, i32 noundef %46, i32 noundef -1)
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = load i32, ptr %9, align 4, !tbaa !9
  call void @add_diag_edges(ptr noundef %47, ptr noundef %48, i32 noundef %49, i32 noundef %50, i32 noundef -1)
  br label %65

51:                                               ; preds = %5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = load i32, ptr %9, align 4, !tbaa !9
  call void @add_straight_edges(ptr noundef %52, ptr noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef 1)
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = load i32, ptr %9, align 4, !tbaa !9
  call void @add_diag_edges(ptr noundef %56, ptr noundef %57, i32 noundef %58, i32 noundef %59, i32 noundef 1)
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = load i32, ptr %9, align 4, !tbaa !9
  call void @add_castling_edges(ptr noundef %60, ptr noundef %61, i32 noundef %62, i32 noundef %63, i32 noundef %64)
  br label %65

65:                                               ; preds = %51, %42, %37, %32, %27, %21, %5
  ret void
}

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

!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, !12, i64 0}
!12 = !{!"short", !7, i64 0}


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_piece_type(i32 noundef) local_unnamed_addr #0

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @fill_adjacency_matrix(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = sext i32 %3 to i64
  %7 = sext i32 %2 to i64
  %8 = getelementptr inbounds [8 x i16], ptr %0, i64 %6, i64 %7
  %9 = load i16, ptr %8, align 2, !tbaa !5
  %10 = sext i16 %9 to i32
  %11 = tail call i32 @get_piece_type(i32 noundef %10)
  switch i32 %11, label %18 [
    i32 4, label %12
    i32 8, label %13
    i32 16, label %14
    i32 32, label %15
    i32 64, label %16
    i32 128, label %17
  ]

12:                                               ; preds = %5
  tail call void @add_pawn_like_edges(ptr noundef %4, ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  br label %18

13:                                               ; preds = %5
  tail call void @add_knight_like_edges(ptr noundef %4, ptr noundef nonnull %0, i32 noundef %2, i32 noundef %3)
  br label %18

14:                                               ; preds = %5
  tail call void @add_diag_edges(ptr noundef %4, ptr noundef nonnull %0, i32 noundef %2, i32 noundef %3, i32 noundef -1)
  br label %18

15:                                               ; preds = %5
  tail call void @add_straight_edges(ptr noundef %4, ptr noundef nonnull %0, i32 noundef %2, i32 noundef %3, i32 noundef -1)
  br label %18

16:                                               ; preds = %5
  tail call void @add_straight_edges(ptr noundef %4, ptr noundef nonnull %0, i32 noundef %2, i32 noundef %3, i32 noundef -1)
  tail call void @add_diag_edges(ptr noundef %4, ptr noundef nonnull %0, i32 noundef %2, i32 noundef %3, i32 noundef -1)
  br label %18

17:                                               ; preds = %5
  tail call void @add_straight_edges(ptr noundef %4, ptr noundef nonnull %0, i32 noundef %2, i32 noundef %3, i32 noundef 1)
  tail call void @add_diag_edges(ptr noundef %4, ptr noundef nonnull %0, i32 noundef %2, i32 noundef %3, i32 noundef 1)
  tail call void @add_castling_edges(ptr noundef %4, ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  br label %18

18:                                               ; preds = %17, %16, %15, %14, %13, %12, %5
  ret void
}

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass