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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

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

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

8:                                                ; preds = %29, %1
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 262144
  br i1 %10, label %11, label %32

11:                                               ; preds = %8
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = and i32 %12, %13
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %29

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = or i32 %17, %18
  store i32 %19, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %20, i32 noundef -2147483648, i32 noundef 2147483647, i32 noundef 1)
  store i32 %21, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp sgt i32 %22, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %16
  %26 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %26, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %27, ptr %3, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %25, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %29

29:                                               ; preds = %28, %11
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = shl i32 %30, 2
  store i32 %31, ptr %5, align 4, !tbaa !5
  br label %8, !llvm.loop !9

32:                                               ; preds = %8
  %33 = load i32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %33
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN16TicTacToeMinimax18predictMaxDecisionEi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = and i32 %0, 3
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %4, label %7

4:                                                ; preds = %1
  %5 = or disjoint i32 %0, 3
  %6 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %5, i32 noundef -2147483648, i32 noundef 2147483647, i32 noundef 1)
  %.not = icmp eq i32 %6, -2147483648
  %spec.select17 = select i1 %.not, i32 0, i32 %5
  br label %7

7:                                                ; preds = %4, %1
  %.214 = phi i32 [ %6, %4 ], [ -2147483648, %1 ]
  %.2 = phi i32 [ %spec.select17, %4 ], [ 0, %1 ]
  %8 = and i32 %0, 12
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %14

10:                                               ; preds = %7
  %11 = or disjoint i32 %0, 12
  %12 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %11, i32 noundef -2147483648, i32 noundef 2147483647, i32 noundef 1)
  %13 = icmp sgt i32 %12, %.214
  %spec.select.1 = tail call i32 @llvm.smax.i32(i32 %12, i32 %.214)
  %spec.select17.1 = select i1 %13, i32 %11, i32 %.2
  br label %14

14:                                               ; preds = %10, %7
  %.214.1 = phi i32 [ %spec.select.1, %10 ], [ %.214, %7 ]
  %.2.1 = phi i32 [ %spec.select17.1, %10 ], [ %.2, %7 ]
  %15 = and i32 %0, 48
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %21

17:                                               ; preds = %14
  %18 = or disjoint i32 %0, 48
  %19 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %18, i32 noundef -2147483648, i32 noundef 2147483647, i32 noundef 1)
  %20 = icmp sgt i32 %19, %.214.1
  %spec.select.2 = tail call i32 @llvm.smax.i32(i32 %19, i32 %.214.1)
  %spec.select17.2 = select i1 %20, i32 %18, i32 %.2.1
  br label %21

21:                                               ; preds = %17, %14
  %.214.2 = phi i32 [ %spec.select.2, %17 ], [ %.214.1, %14 ]
  %.2.2 = phi i32 [ %spec.select17.2, %17 ], [ %.2.1, %14 ]
  %22 = and i32 %0, 192
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %28

24:                                               ; preds = %21
  %25 = or disjoint i32 %0, 192
  %26 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %25, i32 noundef -2147483648, i32 noundef 2147483647, i32 noundef 1)
  %27 = icmp sgt i32 %26, %.214.2
  %spec.select.3 = tail call i32 @llvm.smax.i32(i32 %26, i32 %.214.2)
  %spec.select17.3 = select i1 %27, i32 %25, i32 %.2.2
  br label %28

28:                                               ; preds = %24, %21
  %.214.3 = phi i32 [ %spec.select.3, %24 ], [ %.214.2, %21 ]
  %.2.3 = phi i32 [ %spec.select17.3, %24 ], [ %.2.2, %21 ]
  %29 = and i32 %0, 768
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %35

31:                                               ; preds = %28
  %32 = or disjoint i32 %0, 768
  %33 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %32, i32 noundef -2147483648, i32 noundef 2147483647, i32 noundef 1)
  %34 = icmp sgt i32 %33, %.214.3
  %spec.select.4 = tail call i32 @llvm.smax.i32(i32 %33, i32 %.214.3)
  %spec.select17.4 = select i1 %34, i32 %32, i32 %.2.3
  br label %35

35:                                               ; preds = %31, %28
  %.214.4 = phi i32 [ %spec.select.4, %31 ], [ %.214.3, %28 ]
  %.2.4 = phi i32 [ %spec.select17.4, %31 ], [ %.2.3, %28 ]
  %36 = and i32 %0, 3072
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %42

38:                                               ; preds = %35
  %39 = or disjoint i32 %0, 3072
  %40 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %39, i32 noundef -2147483648, i32 noundef 2147483647, i32 noundef 1)
  %41 = icmp sgt i32 %40, %.214.4
  %spec.select.5 = tail call i32 @llvm.smax.i32(i32 %40, i32 %.214.4)
  %spec.select17.5 = select i1 %41, i32 %39, i32 %.2.4
  br label %42

42:                                               ; preds = %38, %35
  %.214.5 = phi i32 [ %spec.select.5, %38 ], [ %.214.4, %35 ]
  %.2.5 = phi i32 [ %spec.select17.5, %38 ], [ %.2.4, %35 ]
  %43 = and i32 %0, 12288
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %49

45:                                               ; preds = %42
  %46 = or disjoint i32 %0, 12288
  %47 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %46, i32 noundef -2147483648, i32 noundef 2147483647, i32 noundef 1)
  %48 = icmp sgt i32 %47, %.214.5
  %spec.select.6 = tail call i32 @llvm.smax.i32(i32 %47, i32 %.214.5)
  %spec.select17.6 = select i1 %48, i32 %46, i32 %.2.5
  br label %49

49:                                               ; preds = %45, %42
  %.214.6 = phi i32 [ %spec.select.6, %45 ], [ %.214.5, %42 ]
  %.2.6 = phi i32 [ %spec.select17.6, %45 ], [ %.2.5, %42 ]
  %50 = and i32 %0, 49152
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %56

52:                                               ; preds = %49
  %53 = or disjoint i32 %0, 49152
  %54 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %53, i32 noundef -2147483648, i32 noundef 2147483647, i32 noundef 1)
  %55 = icmp sgt i32 %54, %.214.6
  %spec.select.7 = tail call i32 @llvm.smax.i32(i32 %54, i32 %.214.6)
  %spec.select17.7 = select i1 %55, i32 %53, i32 %.2.6
  br label %56

56:                                               ; preds = %52, %49
  %.214.7 = phi i32 [ %spec.select.7, %52 ], [ %.214.6, %49 ]
  %.2.7 = phi i32 [ %spec.select17.7, %52 ], [ %.2.6, %49 ]
  %57 = and i32 %0, 196608
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %63

59:                                               ; preds = %56
  %60 = or disjoint i32 %0, 196608
  %61 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %60, i32 noundef -2147483648, i32 noundef 2147483647, i32 noundef 1)
  %62 = icmp sgt i32 %61, %.214.7
  %spec.select17.8 = select i1 %62, i32 %60, i32 %.2.7
  br label %63

63:                                               ; preds = %59, %56
  %.2.8 = phi i32 [ %spec.select17.8, %59 ], [ %.2.7, %56 ]
  ret i32 %.2.8
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass