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

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

@_maxDepth = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN16TicTacToeMinimax19predictMaxTreeScoreEiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = call noundef i32 @_ZN16TicTacToeMinimax8getStateEi(i32 noundef %16)
  store i32 %17, ptr %10, align 4, !tbaa !5
  %18 = load i32, ptr %10, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 2
  br i1 %19, label %24, label %20

20:                                               ; preds = %4
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = load i32, ptr @_maxDepth, align 4, !tbaa !5
  %23 = icmp sge i32 %21, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %20, %4
  %25 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %25, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %73

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 -2147483648, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 3, ptr %13, align 4, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %9, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %67, %26
  %30 = load i32, ptr %13, align 4, !tbaa !5
  %31 = icmp slt i32 %30, 262144
  br i1 %31, label %32, label %70

32:                                               ; preds = %29
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = load i32, ptr %13, align 4, !tbaa !5
  %35 = and i32 %33, %34
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %67

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %13, align 4, !tbaa !5
  %40 = or i32 %38, %39
  store i32 %40, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %41 = load i32, ptr %14, align 4, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = load i32, ptr %9, align 4, !tbaa !5
  %45 = call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %41, i32 noundef %42, i32 noundef %43, i32 noundef %44)
  store i32 %45, ptr %15, align 4, !tbaa !5
  %46 = load i32, ptr %15, align 4, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = icmp sge i32 %46, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %37
  %50 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %50, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %64

51:                                               ; preds = %37
  %52 = load i32, ptr %15, align 4, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = icmp sgt i32 %52, %53
  br i1 %54, label %55, label %57

55:                                               ; preds = %51
  %56 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %56, ptr %7, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %55, %51
  %58 = load i32, ptr %15, align 4, !tbaa !5
  %59 = load i32, ptr %12, align 4, !tbaa !5
  %60 = icmp sgt i32 %58, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %57
  %62 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %62, ptr %12, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %61, %57
  store i32 0, ptr %11, align 4
  br label %64

64:                                               ; preds = %63, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %65 = load i32, ptr %11, align 4
  switch i32 %65, label %72 [
    i32 0, label %66
  ]

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66, %32
  %68 = load i32, ptr %13, align 4, !tbaa !5
  %69 = shl i32 %68, 2
  store i32 %69, ptr %13, align 4, !tbaa !5
  br label %29, !llvm.loop !9

70:                                               ; preds = %29
  %71 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %71, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %72

72:                                               ; preds = %70, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %73

73:                                               ; preds = %72, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %74 = load i32, ptr %5, align 4
  ret i32 %74
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN16TicTacToeMinimax8getStateEi(i32 noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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"

@_maxDepth = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN16TicTacToeMinimax19predictMaxTreeScoreEiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = tail call noundef i32 @_ZN16TicTacToeMinimax8getStateEi(i32 noundef %0)
  %.not = icmp eq i32 %5, 2
  %6 = load i32, ptr @_maxDepth, align 4
  %.not40 = icmp sgt i32 %6, %3
  %or.cond = select i1 %.not, i1 %.not40, i1 false
  br i1 %or.cond, label %7, label %.loopexit

7:                                                ; preds = %4
  %8 = add nsw i32 %3, 1
  %9 = and i32 %0, 3
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %7
  %12 = or disjoint i32 %0, 3
  %13 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %12, i32 noundef %1, i32 noundef %2, i32 noundef %8)
  %.not41 = icmp slt i32 %13, %2
  %spec.select = tail call i32 @llvm.smax.i32(i32 %13, i32 %1)
  br i1 %.not41, label %14, label %.loopexit

14:                                               ; preds = %11, %7
  %.335 = phi i32 [ %13, %11 ], [ -2147483648, %7 ]
  %.330 = phi i32 [ %spec.select, %11 ], [ %1, %7 ]
  %15 = and i32 %0, 12
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  %18 = or disjoint i32 %0, 12
  %19 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %18, i32 noundef %.330, i32 noundef %2, i32 noundef %8)
  %.not41.1 = icmp slt i32 %19, %2
  %spec.select.1 = tail call i32 @llvm.smax.i32(i32 %19, i32 %.330)
  %.133.1 = tail call i32 @llvm.smax.i32(i32 %19, i32 %.335)
  br i1 %.not41.1, label %20, label %.loopexit

20:                                               ; preds = %17, %14
  %.335.1 = phi i32 [ %.133.1, %17 ], [ %.335, %14 ]
  %.330.1 = phi i32 [ %spec.select.1, %17 ], [ %.330, %14 ]
  %21 = and i32 %0, 48
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = or disjoint i32 %0, 48
  %25 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %24, i32 noundef %.330.1, i32 noundef %2, i32 noundef %8)
  %.not41.2 = icmp slt i32 %25, %2
  %spec.select.2 = tail call i32 @llvm.smax.i32(i32 %25, i32 %.330.1)
  %.133.2 = tail call i32 @llvm.smax.i32(i32 %25, i32 %.335.1)
  br i1 %.not41.2, label %26, label %.loopexit

26:                                               ; preds = %23, %20
  %.335.2 = phi i32 [ %.133.2, %23 ], [ %.335.1, %20 ]
  %.330.2 = phi i32 [ %spec.select.2, %23 ], [ %.330.1, %20 ]
  %27 = and i32 %0, 192
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %32

29:                                               ; preds = %26
  %30 = or disjoint i32 %0, 192
  %31 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %30, i32 noundef %.330.2, i32 noundef %2, i32 noundef %8)
  %.not41.3 = icmp slt i32 %31, %2
  %spec.select.3 = tail call i32 @llvm.smax.i32(i32 %31, i32 %.330.2)
  %.133.3 = tail call i32 @llvm.smax.i32(i32 %31, i32 %.335.2)
  br i1 %.not41.3, label %32, label %.loopexit

32:                                               ; preds = %29, %26
  %.335.3 = phi i32 [ %.133.3, %29 ], [ %.335.2, %26 ]
  %.330.3 = phi i32 [ %spec.select.3, %29 ], [ %.330.2, %26 ]
  %33 = and i32 %0, 768
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %32
  %36 = or disjoint i32 %0, 768
  %37 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %36, i32 noundef %.330.3, i32 noundef %2, i32 noundef %8)
  %.not41.4 = icmp slt i32 %37, %2
  %spec.select.4 = tail call i32 @llvm.smax.i32(i32 %37, i32 %.330.3)
  %.133.4 = tail call i32 @llvm.smax.i32(i32 %37, i32 %.335.3)
  br i1 %.not41.4, label %38, label %.loopexit

38:                                               ; preds = %35, %32
  %.335.4 = phi i32 [ %.133.4, %35 ], [ %.335.3, %32 ]
  %.330.4 = phi i32 [ %spec.select.4, %35 ], [ %.330.3, %32 ]
  %39 = and i32 %0, 3072
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %38
  %42 = or disjoint i32 %0, 3072
  %43 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %42, i32 noundef %.330.4, i32 noundef %2, i32 noundef %8)
  %.not41.5 = icmp slt i32 %43, %2
  %spec.select.5 = tail call i32 @llvm.smax.i32(i32 %43, i32 %.330.4)
  %.133.5 = tail call i32 @llvm.smax.i32(i32 %43, i32 %.335.4)
  br i1 %.not41.5, label %44, label %.loopexit

44:                                               ; preds = %41, %38
  %.335.5 = phi i32 [ %.133.5, %41 ], [ %.335.4, %38 ]
  %.330.5 = phi i32 [ %spec.select.5, %41 ], [ %.330.4, %38 ]
  %45 = and i32 %0, 12288
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %47, label %50

47:                                               ; preds = %44
  %48 = or disjoint i32 %0, 12288
  %49 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %48, i32 noundef %.330.5, i32 noundef %2, i32 noundef %8)
  %.not41.6 = icmp slt i32 %49, %2
  %spec.select.6 = tail call i32 @llvm.smax.i32(i32 %49, i32 %.330.5)
  %.133.6 = tail call i32 @llvm.smax.i32(i32 %49, i32 %.335.5)
  br i1 %.not41.6, label %50, label %.loopexit

50:                                               ; preds = %47, %44
  %.335.6 = phi i32 [ %.133.6, %47 ], [ %.335.5, %44 ]
  %.330.6 = phi i32 [ %spec.select.6, %47 ], [ %.330.5, %44 ]
  %51 = and i32 %0, 49152
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %50
  %54 = or disjoint i32 %0, 49152
  %55 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %54, i32 noundef %.330.6, i32 noundef %2, i32 noundef %8)
  %.not41.7 = icmp slt i32 %55, %2
  %spec.select.7 = tail call i32 @llvm.smax.i32(i32 %55, i32 %.330.6)
  %.133.7 = tail call i32 @llvm.smax.i32(i32 %55, i32 %.335.6)
  br i1 %.not41.7, label %56, label %.loopexit

56:                                               ; preds = %53, %50
  %.335.7 = phi i32 [ %.133.7, %53 ], [ %.335.6, %50 ]
  %.330.7 = phi i32 [ %spec.select.7, %53 ], [ %.330.6, %50 ]
  %57 = and i32 %0, 196608
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %.loopexit

59:                                               ; preds = %56
  %60 = or disjoint i32 %0, 196608
  %61 = tail call noundef i32 @_ZN16TicTacToeMinimax19predictMinTreeScoreEiiii(i32 noundef %60, i32 noundef %.330.7, i32 noundef %2, i32 noundef %8)
  %.not41.8 = icmp slt i32 %61, %2
  %.133.8 = tail call i32 @llvm.smax.i32(i32 %61, i32 %.335.7)
  %spec.select45 = select i1 %.not41.8, i32 %.133.8, i32 %61
  br label %.loopexit

.loopexit:                                        ; preds = %59, %11, %17, %23, %29, %35, %41, %47, %53, %56, %4
  %.4 = phi i32 [ %5, %4 ], [ %13, %11 ], [ %19, %17 ], [ %25, %23 ], [ %31, %29 ], [ %37, %35 ], [ %43, %41 ], [ %49, %47 ], [ %55, %53 ], [ %.335.7, %56 ], [ %spec.select45, %59 ]
  ret i32 %.4
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN16TicTacToeMinimax8getStateEi(i32 noundef) local_unnamed_addr #1

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

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

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 = { 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 = { 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: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass