; 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 zeroext i1 @is_white_tile(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @get_tile_colour_pair(ptr noundef byval(%struct.Game) align 8 %0, i32 noundef %1, i32 noundef %2, i1 noundef zeroext %3, i32 noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %12 = zext i1 %3 to i8
  store i8 %12, ptr %8, align 1, !tbaa !9
  store i32 %4, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %13 = load i8, ptr %8, align 1, !tbaa !9, !range !11, !noundef !12
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %20

15:                                               ; preds = %5
  %16 = load i32, ptr %9, align 4, !tbaa !5
  %17 = icmp eq i32 %16, 1
  %18 = zext i1 %17 to i64
  %19 = select i1 %17, i32 8, i32 16
  store i32 %19, ptr %10, align 4, !tbaa !5
  br label %26

20:                                               ; preds = %5
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = call zeroext i1 @is_white_tile(i32 noundef %21, i32 noundef %22)
  %24 = zext i1 %23 to i64
  %25 = select i1 %23, i32 2, i32 4
  store i32 %25, ptr %10, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %20, %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %27 = getelementptr inbounds %struct.Game, ptr %0, i32 0, i32 1
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [8 x [8 x i16]], ptr %27, i64 0, i64 %29
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [8 x i16], ptr %30, i64 0, i64 %32
  %34 = load i16, ptr %33, align 2, !tbaa !13
  %35 = sext i16 %34 to i32
  %36 = call i32 @get_piece_owner(i32 noundef %35)
  store i32 %36, ptr %11, align 4, !tbaa !5
  %37 = load i32, ptr %11, align 4, !tbaa !5
  %38 = icmp eq i32 %37, -1
  br i1 %38, label %39, label %46

39:                                               ; preds = %26
  %40 = getelementptr inbounds %struct.Game, ptr %0, i32 0, i32 2
  %41 = load i32, ptr %40, align 4, !tbaa !15
  %42 = and i32 %41, 1
  %43 = icmp ne i32 %42, 0
  %44 = zext i1 %43 to i64
  %45 = select i1 %43, i32 1, i32 2
  store i32 %45, ptr %11, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %39, %26
  %47 = load i32, ptr %11, align 4, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !5
  %49 = or i32 %47, %48
  %50 = shl i32 %49, 8
  %51 = and i32 %50, 65280
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  ret i32 %51
}

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 = { 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 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !6, i64 132}
!16 = !{!"", !6, i64 0, !7, i64 4, !6, i64 132, !6, i64 136, !6, i64 140}


; 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: nounwind uwtable
declare dso_local i32 @get_piece_owner(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @is_white_tile(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 65281) i32 @get_tile_colour_pair(ptr nocapture noundef readonly byval(%struct.Game) align 8 %0, i32 noundef %1, i32 noundef %2, i1 noundef zeroext %3, i32 noundef %4) local_unnamed_addr #0 {
  br i1 %3, label %6, label %9

6:                                                ; preds = %5
  %7 = icmp eq i32 %4, 1
  %8 = select i1 %7, i32 8, i32 16
  br label %12

9:                                                ; preds = %5
  %10 = tail call zeroext i1 @is_white_tile(i32 noundef %1, i32 noundef %2)
  %11 = select i1 %10, i32 2, i32 4
  br label %12

12:                                               ; preds = %9, %6
  %.09 = phi i32 [ %8, %6 ], [ %11, %9 ]
  %13 = getelementptr inbounds i8, ptr %0, i64 4
  %14 = sext i32 %2 to i64
  %15 = sext i32 %1 to i64
  %16 = getelementptr inbounds [8 x [8 x i16]], ptr %13, i64 0, i64 %14, i64 %15
  %17 = load i16, ptr %16, align 2, !tbaa !5
  %18 = sext i16 %17 to i32
  %19 = tail call i32 @get_piece_owner(i32 noundef %18)
  %20 = icmp eq i32 %19, -1
  %21 = getelementptr inbounds i8, ptr %0, i64 132
  %22 = load i32, ptr %21, align 4
  %23 = and i32 %22, 1
  %.not = icmp eq i32 %23, 0
  %24 = select i1 %.not, i32 2, i32 1
  %.0 = select i1 %20, i32 %24, i32 %19
  %25 = or i32 %.0, %.09
  %26 = shl i32 %25, 8
  %27 = and i32 %26, 65280
  ret i32 %27
}

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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass