; 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
define dso_local void @update_castling_flags(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  store i8 0, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #2
  store i8 0, ptr %10, align 1, !tbaa !11
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = and i32 %13, 32
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %26

16:                                               ; preds = %4
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  store i8 1, ptr %10, align 1, !tbaa !11
  br label %25

20:                                               ; preds = %16
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 7
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i8 1, ptr %9, align 1, !tbaa !11
  br label %24

24:                                               ; preds = %23, %20
  br label %25

25:                                               ; preds = %24, %19
  br label %32

26:                                               ; preds = %4
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = and i32 %27, 128
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %26
  store i8 1, ptr %9, align 1, !tbaa !11
  store i8 1, ptr %10, align 1, !tbaa !11
  br label %31

31:                                               ; preds = %30, %26
  br label %32

32:                                               ; preds = %31, %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = icmp eq i32 %33, 1
  %35 = zext i1 %34 to i64
  %36 = select i1 %34, i32 64, i32 256
  store i32 %36, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = icmp eq i32 %37, 1
  %39 = zext i1 %38 to i64
  %40 = select i1 %38, i32 128, i32 512
  store i32 %40, ptr %12, align 4, !tbaa !9
  %41 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %42 = trunc i8 %41 to i1
  br i1 %42, label %43, label %56

43:                                               ; preds = %32
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Game, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %45, align 4, !tbaa !15
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = and i32 %46, %47
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %56

50:                                               ; preds = %43
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Game, ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 4, !tbaa !15
  %55 = xor i32 %54, %51
  store i32 %55, ptr %53, align 4, !tbaa !15
  br label %56

56:                                               ; preds = %50, %43, %32
  %57 = load i8, ptr %10, align 1, !tbaa !11, !range !13, !noundef !14
  %58 = trunc i8 %57 to i1
  br i1 %58, label %59, label %72

59:                                               ; preds = %56
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Game, ptr %60, i32 0, i32 2
  %62 = load i32, ptr %61, align 4, !tbaa !15
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = and i32 %62, %63
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %72

66:                                               ; preds = %59
  %67 = load i32, ptr %12, align 4, !tbaa !9
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Game, ptr %68, i32 0, i32 2
  %70 = load i32, ptr %69, align 4, !tbaa !15
  %71 = xor i32 %70, %67
  store i32 %71, ptr %69, align 4, !tbaa !15
  br label %72

72:                                               ; preds = %66, %59, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  ret void
}

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @update_castling_flags(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = and i32 %2, 32
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %9, label %6

6:                                                ; preds = %4
  switch i32 %3, label %.thread28 [
    i32 0, label %.thread.thread
    i32 7, label %.thread31
  ]

.thread.thread:                                   ; preds = %6
  %7 = icmp eq i32 %1, 1
  %8 = select i1 %7, i32 128, i32 512
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 132
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  br label %.thread37

9:                                                ; preds = %4
  %10 = and i32 %2, 128
  %.not17.not = icmp eq i32 %10, 0
  %11 = icmp eq i32 %1, 1
  %12 = select i1 %11, i32 64, i32 256
  %13 = select i1 %11, i32 128, i32 512
  br i1 %.not17.not, label %.thread28, label %14

14:                                               ; preds = %9
  %15 = getelementptr inbounds i8, ptr %0, i64 132
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = and i32 %16, %12
  %.not18 = icmp eq i32 %17, 0
  br i1 %.not18, label %.thread37, label %24

.thread31:                                        ; preds = %6
  %18 = icmp eq i32 %1, 1
  %19 = select i1 %18, i32 64, i32 256
  %20 = getelementptr inbounds i8, ptr %0, i64 132
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = and i32 %21, %19
  %.not1833 = icmp eq i32 %22, 0
  br i1 %.not1833, label %.thread28, label %.thread35

.thread35:                                        ; preds = %.thread31
  %23 = xor i32 %21, %19
  store i32 %23, ptr %20, align 4, !tbaa !5
  br label %.thread28

24:                                               ; preds = %14
  %25 = xor i32 %16, %12
  store i32 %25, ptr %15, align 4, !tbaa !5
  br label %.thread37

.thread37:                                        ; preds = %14, %24, %.thread.thread
  %26 = phi i32 [ %25, %24 ], [ %.pre, %.thread.thread ], [ %16, %14 ]
  %27 = phi i32 [ %13, %24 ], [ %8, %.thread.thread ], [ %13, %14 ]
  %28 = and i32 %26, %27
  %.not19 = icmp eq i32 %28, 0
  br i1 %.not19, label %.thread28, label %29

29:                                               ; preds = %.thread37
  %30 = getelementptr inbounds i8, ptr %0, i64 132
  %31 = xor i32 %26, %27
  store i32 %31, ptr %30, align 4, !tbaa !5
  br label %.thread28

.thread28:                                        ; preds = %6, %.thread31, %.thread35, %9, %29, %.thread37
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !7, i64 132}
!6 = !{!"", !7, i64 0, !8, i64 4, !7, i64 132, !7, i64 136, !7, i64 140}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass