; LLVM IR from SoloGameDevGitHub/AIEngine :: AdversarialSearch/Minimax/TicTacToeMinimax.ll (ZN16TicTacToeMinimax8getStateEi)

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

@_ZL11winnerMasks = external hidden constant [8 x i32], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN16TicTacToeMinimax8getStateEi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store ptr @_ZL11winnerMasks, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store ptr @_ZL11winnerMasks, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store ptr getelementptr inbounds (i32, ptr @_ZL11winnerMasks, i64 8), ptr %6, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %47, %1
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !9
  %13 = icmp ne ptr %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %7, align 4
  br label %50

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %17, ptr %8, align 4, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr %8, align 4, !tbaa !5
  %20 = and i32 %18, %19
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = icmp eq i32 %20, %21
  br i1 %22, label %23, label %43

23:                                               ; preds = %15
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = ashr i32 %24, 1
  store i32 %25, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = xor i32 %26, %27
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = and i32 %28, %29
  store i32 %30, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %23
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %40

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

38:                                               ; preds = %34
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %40

39:                                               ; preds = %34
  store i32 0, ptr %7, align 4
  br label %40

40:                                               ; preds = %39, %38, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %41 = load i32, ptr %7, align 4
  switch i32 %41, label %44 [
    i32 0, label %42
  ]

42:                                               ; preds = %40
  br label %43

43:                                               ; preds = %42, %15
  store i32 0, ptr %7, align 4
  br label %44

44:                                               ; preds = %43, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %45 = load i32, ptr %7, align 4
  switch i32 %45, label %50 [
    i32 0, label %46
  ]

46:                                               ; preds = %44
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = getelementptr inbounds i32, ptr %48, i32 1
  store ptr %49, ptr %5, align 8, !tbaa !9
  br label %10

50:                                               ; preds = %44, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %51 = load i32, ptr %7, align 4
  switch i32 %51, label %60 [
    i32 2, label %52
    i32 1, label %58
  ]

52:                                               ; preds = %50
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = and i32 %53, 174762
  %55 = icmp eq i32 %54, 174762
  br i1 %55, label %56, label %57

56:                                               ; preds = %52
  store i32 0, ptr %2, align 4
  br label %58

57:                                               ; preds = %52
  store i32 2, ptr %2, align 4
  br label %58

58:                                               ; preds = %57, %56, %50
  %59 = load i32, ptr %2, align 4
  ret i32 %59

60:                                               ; preds = %50
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@_ZL11winnerMasks = external hidden local_unnamed_addr constant [8 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i32 @_ZN16TicTacToeMinimax8getStateEi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = xor i32 %0, -1
  %3 = load i32, ptr @_ZL11winnerMasks, align 16, !tbaa !5
  %4 = and i32 %3, %0
  %5 = icmp eq i32 %4, %3
  br i1 %5, label %6, label %.thread

6:                                                ; preds = %1
  %7 = ashr i32 %3, 1
  %8 = and i32 %7, %2
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %.thread29.thread, label %10

10:                                               ; preds = %6
  %.not32 = icmp eq i32 %8, %7
  br i1 %.not32, label %.thread29.thread, label %.thread

.thread:                                          ; preds = %1, %10
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL11winnerMasks, i64 4), align 4, !tbaa !5
  %12 = and i32 %11, %0
  %13 = icmp eq i32 %12, %11
  br i1 %13, label %14, label %.thread.1

14:                                               ; preds = %.thread
  %15 = ashr i32 %11, 1
  %16 = and i32 %15, %2
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %.thread29.thread, label %18

18:                                               ; preds = %14
  %.not32.1 = icmp eq i32 %16, %15
  br i1 %.not32.1, label %.thread29.thread, label %.thread.1

.thread.1:                                        ; preds = %18, %.thread
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL11winnerMasks, i64 8), align 8, !tbaa !5
  %20 = and i32 %19, %0
  %21 = icmp eq i32 %20, %19
  br i1 %21, label %22, label %.thread.2

22:                                               ; preds = %.thread.1
  %23 = ashr i32 %19, 1
  %24 = and i32 %23, %2
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %.thread29.thread, label %26

26:                                               ; preds = %22
  %.not32.2 = icmp eq i32 %24, %23
  br i1 %.not32.2, label %.thread29.thread, label %.thread.2

.thread.2:                                        ; preds = %26, %.thread.1
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL11winnerMasks, i64 12), align 4, !tbaa !5
  %28 = and i32 %27, %0
  %29 = icmp eq i32 %28, %27
  br i1 %29, label %30, label %.thread.3

30:                                               ; preds = %.thread.2
  %31 = ashr i32 %27, 1
  %32 = and i32 %31, %2
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %.thread29.thread, label %34

34:                                               ; preds = %30
  %.not32.3 = icmp eq i32 %32, %31
  br i1 %.not32.3, label %.thread29.thread, label %.thread.3

.thread.3:                                        ; preds = %34, %.thread.2
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL11winnerMasks, i64 16), align 16, !tbaa !5
  %36 = and i32 %35, %0
  %37 = icmp eq i32 %36, %35
  br i1 %37, label %38, label %.thread.4

38:                                               ; preds = %.thread.3
  %39 = ashr i32 %35, 1
  %40 = and i32 %39, %2
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %.thread29.thread, label %42

42:                                               ; preds = %38
  %.not32.4 = icmp eq i32 %40, %39
  br i1 %.not32.4, label %.thread29.thread, label %.thread.4

.thread.4:                                        ; preds = %42, %.thread.3
  %43 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL11winnerMasks, i64 20), align 4, !tbaa !5
  %44 = and i32 %43, %0
  %45 = icmp eq i32 %44, %43
  br i1 %45, label %46, label %.thread.5

46:                                               ; preds = %.thread.4
  %47 = ashr i32 %43, 1
  %48 = and i32 %47, %2
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %.thread29.thread, label %50

50:                                               ; preds = %46
  %.not32.5 = icmp eq i32 %48, %47
  br i1 %.not32.5, label %.thread29.thread, label %.thread.5

.thread.5:                                        ; preds = %50, %.thread.4
  %51 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL11winnerMasks, i64 24), align 8, !tbaa !5
  %52 = and i32 %51, %0
  %53 = icmp eq i32 %52, %51
  br i1 %53, label %54, label %.thread.6

54:                                               ; preds = %.thread.5
  %55 = ashr i32 %51, 1
  %56 = and i32 %55, %2
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %.thread29.thread, label %58

58:                                               ; preds = %54
  %.not32.6 = icmp eq i32 %56, %55
  br i1 %.not32.6, label %.thread29.thread, label %.thread.6

.thread.6:                                        ; preds = %58, %.thread.5
  %59 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL11winnerMasks, i64 28), align 4, !tbaa !5
  %60 = and i32 %59, %0
  %61 = icmp eq i32 %60, %59
  br i1 %61, label %62, label %67

62:                                               ; preds = %.thread.6
  %63 = ashr i32 %59, 1
  %64 = and i32 %63, %2
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %.thread29.thread, label %66

66:                                               ; preds = %62
  %.not32.7 = icmp eq i32 %64, %63
  br i1 %.not32.7, label %.thread29.thread, label %67

67:                                               ; preds = %66, %.thread.6
  %68 = and i32 %0, 174762
  %69 = icmp eq i32 %68, 174762
  %.25 = select i1 %69, i32 0, i32 2
  br label %.thread29.thread

.thread29.thread:                                 ; preds = %66, %62, %58, %54, %50, %46, %42, %38, %34, %30, %26, %22, %18, %14, %10, %6, %67
  %70 = phi i32 [ %.25, %67 ], [ -1, %66 ], [ 1, %62 ], [ -1, %58 ], [ 1, %54 ], [ -1, %50 ], [ 1, %46 ], [ -1, %42 ], [ 1, %38 ], [ -1, %34 ], [ 1, %30 ], [ -1, %26 ], [ 1, %22 ], [ -1, %18 ], [ 1, %14 ], [ -1, %10 ], [ 1, %6 ]
  ret i32 %70
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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