; LLVM IR from mbrenman/TetrisPlayground :: Train.ll (Z18getCrossoverPlayerP15playerWithScore)

; 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.playerWithScore = type <{ ptr, double, i32, [4 x i8] }>
%class.HeuristicAgent = type { %class.Agent, [6 x double] }
%class.Agent = type { ptr }

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #2

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

; Function Attrs: nounwind
declare i32 @rand() #3

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z18getCrossoverPlayerP15playerWithScore(ptr noundef %0) #4 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca [6 x double], align 16
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %12 = call i32 @rand() #6
  %13 = srem i32 %12, 5
  store i32 %13, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds %struct.playerWithScore, ptr %14, i64 %16
  %18 = getelementptr inbounds %struct.playerWithScore, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  store ptr %19, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %20 = call i32 @rand() #6
  %21 = srem i32 %20, 5
  store i32 %21, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %struct.playerWithScore, ptr %22, i64 %24
  %26 = getelementptr inbounds %struct.playerWithScore, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  store ptr %27, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %60, %1
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = icmp slt i32 %29, 6
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %63

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #6
  %33 = call i32 @rand() #6
  %34 = srem i32 %33, 2
  %35 = icmp ne i32 %34, 0
  %36 = zext i1 %35 to i8
  store i8 %36, ptr %9, align 1, !tbaa !14
  %37 = load i8, ptr %9, align 1, !tbaa !14, !range !16, !noundef !17
  %38 = trunc i8 %37 to i1
  br i1 %38, label %39, label %49

39:                                               ; preds = %32
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %class.HeuristicAgent, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [6 x double], ptr %41, i64 0, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !18
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [6 x double], ptr %3, i64 0, i64 %47
  store double %45, ptr %48, align 8, !tbaa !18
  br label %59

49:                                               ; preds = %32
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %class.HeuristicAgent, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [6 x double], ptr %51, i64 0, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !18
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [6 x double], ptr %3, i64 0, i64 %57
  store double %55, ptr %58, align 8, !tbaa !18
  br label %59

59:                                               ; preds = %49, %39
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #6
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %8, align 4, !tbaa !9
  br label %28, !llvm.loop !19

63:                                               ; preds = %31
  %64 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 56) #7
  %65 = getelementptr inbounds [6 x double], ptr %3, i64 0, i64 0
  invoke void @_ZN14HeuristicAgentC1EPd(ptr noundef nonnull align 8 dereferenceable(56) %64, ptr noundef %65)
          to label %66 unwind label %67

66:                                               ; preds = %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 48, ptr %3) #6
  ret ptr %64

67:                                               ; preds = %63
  %68 = landingpad { ptr, i32 }
          cleanup
  %69 = extractvalue { ptr, i32 } %68, 0
  store ptr %69, ptr %10, align 8
  %70 = extractvalue { ptr, i32 } %68, 1
  store i32 %70, ptr %11, align 4
  call void @_ZdlPvm(ptr noundef %64, i64 noundef 56) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 48, ptr %3) #6
  br label %71

71:                                               ; preds = %67
  %72 = load ptr, ptr %10, align 8
  %73 = load i32, ptr %11, align 4
  %74 = insertvalue { ptr, i32 } poison, ptr %72, 0
  %75 = insertvalue { ptr, i32 } %74, i32 %73, 1
  resume { ptr, i32 } %75
}

declare void @_ZN14HeuristicAgentC1EPd(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) unnamed_addr #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin allocsize(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 = { nobuiltin nounwind "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 "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 #4 = { 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 #5 = { "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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS15playerWithScore", !6, i64 0, !13, i64 8, !10, i64 16}
!13 = !{!"double", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!13, !13, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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"

%struct.playerWithScore = type <{ ptr, double, i32, [4 x i8] }>

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull ptr @_Z18getCrossoverPlayerP15playerWithScore(ptr nocapture noundef readonly %0) local_unnamed_addr #4 personality ptr @__gxx_personality_v0 {
  %2 = alloca [6 x double], align 16
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %2) #6
  %3 = tail call i32 @rand() #6
  %4 = srem i32 %3, 5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds %struct.playerWithScore, ptr %0, i64 %5
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = tail call i32 @rand() #6
  %9 = srem i32 %8, 5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds %struct.playerWithScore, ptr %0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = tail call i32 @rand() #6
  %14 = and i32 %13, 1
  %.not = icmp eq i32 %14, 0
  %spec.select = select i1 %.not, ptr %12, ptr %7
  %.sink.in = getelementptr inbounds i8, ptr %spec.select, i64 8
  %.sink = load double, ptr %.sink.in, align 8, !tbaa !12
  store double %.sink, ptr %2, align 16
  %15 = tail call i32 @rand() #6
  %16 = and i32 %15, 1
  %.not.1 = icmp eq i32 %16, 0
  %.pn = select i1 %.not.1, ptr %12, ptr %7
  %.sink16.in = getelementptr inbounds i8, ptr %.pn, i64 16
  %.sink16 = load double, ptr %.sink16.in, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %2, i64 8
  store double %.sink16, ptr %17, align 8
  %18 = tail call i32 @rand() #6
  %19 = and i32 %18, 1
  %.not.2 = icmp eq i32 %19, 0
  %.pn21 = select i1 %.not.2, ptr %12, ptr %7
  %.sink17.in = getelementptr inbounds i8, ptr %.pn21, i64 24
  %.sink17 = load double, ptr %.sink17.in, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %2, i64 16
  store double %.sink17, ptr %20, align 16
  %21 = tail call i32 @rand() #6
  %22 = and i32 %21, 1
  %.not.3 = icmp eq i32 %22, 0
  %.pn22 = select i1 %.not.3, ptr %12, ptr %7
  %.sink18.in = getelementptr inbounds i8, ptr %.pn22, i64 32
  %.sink18 = load double, ptr %.sink18.in, align 8, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %2, i64 24
  store double %.sink18, ptr %23, align 8
  %24 = tail call i32 @rand() #6
  %25 = and i32 %24, 1
  %.not.4 = icmp eq i32 %25, 0
  %.pn23 = select i1 %.not.4, ptr %12, ptr %7
  %.sink19.in = getelementptr inbounds i8, ptr %.pn23, i64 40
  %.sink19 = load double, ptr %.sink19.in, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %2, i64 32
  store double %.sink19, ptr %26, align 16
  %27 = tail call i32 @rand() #6
  %28 = and i32 %27, 1
  %.not.5 = icmp eq i32 %28, 0
  %.pn25 = select i1 %.not.5, ptr %12, ptr %7
  %.sink20.in = getelementptr inbounds i8, ptr %.pn25, i64 48
  %.sink20 = load double, ptr %.sink20.in, align 8, !tbaa !12
  %29 = getelementptr inbounds i8, ptr %2, i64 40
  store double %.sink20, ptr %29, align 8
  %30 = tail call noalias noundef nonnull dereferenceable(56) ptr @_Znwm(i64 noundef 56) #7
  invoke void @_ZN14HeuristicAgentC1EPd(ptr noundef nonnull align 8 dereferenceable(56) %30, ptr noundef nonnull %2)
          to label %31 unwind label %32

31:                                               ; preds = %1
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %2) #6
  ret ptr %30

32:                                               ; preds = %1
  %33 = landingpad { ptr, i32 }
          cleanup
  call void @_ZdlPvm(ptr noundef nonnull %30, i64 noundef 56) #8
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %2) #6
  resume { ptr, i32 } %33
}

declare void @_ZN14HeuristicAgentC1EPd(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin allocsize(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 = { nobuiltin nounwind "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 "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 #4 = { 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 #5 = { "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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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, !7, i64 0}
!6 = !{!"_ZTS15playerWithScore", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass