; LLVM IR from mbrenman/TetrisPlayground :: agents/HeuristicAgent.ll (ZN14HeuristicAgentC2EPd)

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

%class.Agent = type { ptr }
%class.HeuristicAgent = type { %class.Agent, [6 x double] }

@_ZTV14HeuristicAgent = external dso_local unnamed_addr constant { [5 x ptr] }, align 8

declare void @_ZN5AgentC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0

declare void @_ZN5AgentC1Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN5AgentD1Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1

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

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

; Function Attrs: nounwind
declare void @_ZN5AgentD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14HeuristicAgentC2EPd(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %class.Agent, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8
  call void @_ZN5AgentC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %11)
  store ptr getelementptr inbounds inrange(-16, 24) ({ [5 x ptr] }, ptr @_ZTV14HeuristicAgent, i32 0, i32 0, i32 2), ptr %11, align 8, !tbaa !9
  invoke void @_ZN5AgentC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %5)
          to label %12 unwind label %17

12:                                               ; preds = %2
  call void @_ZN5AgentD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store double 0.000000e+00, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %13

13:                                               ; preds = %34, %12
  %14 = load i32, ptr %9, align 4, !tbaa !13
  %15 = icmp slt i32 %14, 6
  br i1 %15, label %21, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %37

17:                                               ; preds = %2
  %18 = landingpad { ptr, i32 }
          cleanup
  %19 = extractvalue { ptr, i32 } %18, 0
  store ptr %19, ptr %6, align 8
  %20 = extractvalue { ptr, i32 } %18, 1
  store i32 %20, ptr %7, align 4
  call void @_ZN5AgentD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %11) #5
  br label %60

21:                                               ; preds = %13
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i32, ptr %9, align 4, !tbaa !13
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %22, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !11
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %27, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !11
  %32 = load double, ptr %8, align 8, !tbaa !11
  %33 = call double @llvm.fmuladd.f64(double %26, double %31, double %32)
  store double %33, ptr %8, align 8, !tbaa !11
  br label %34

34:                                               ; preds = %21
  %35 = load i32, ptr %9, align 4, !tbaa !13
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %9, align 4, !tbaa !13
  br label %13, !llvm.loop !15

37:                                               ; preds = %16
  %38 = load double, ptr %8, align 8, !tbaa !11
  %39 = call double @sqrt(double noundef %38) #5
  store double %39, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !13
  br label %40

40:                                               ; preds = %56, %37
  %41 = load i32, ptr %10, align 4, !tbaa !13
  %42 = icmp slt i32 %41, 6
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %59

44:                                               ; preds = %40
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %10, align 4, !tbaa !13
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %45, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = load double, ptr %8, align 8, !tbaa !11
  %51 = fdiv double %49, %50
  %52 = getelementptr inbounds %class.HeuristicAgent, ptr %11, i32 0, i32 1
  %53 = load i32, ptr %10, align 4, !tbaa !13
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [6 x double], ptr %52, i64 0, i64 %54
  store double %51, ptr %55, align 8, !tbaa !11
  br label %56

56:                                               ; preds = %44
  %57 = load i32, ptr %10, align 4, !tbaa !13
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %10, align 4, !tbaa !13
  br label %40, !llvm.loop !17

59:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  ret void

60:                                               ; preds = %17
  %61 = load ptr, ptr %6, align 8
  %62 = load i32, ptr %7, align 4
  %63 = insertvalue { ptr, i32 } poison, ptr %61, 0
  %64 = insertvalue { ptr, i32 } %63, i32 %62, 1
  resume { ptr, i32 } %64
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #4

; Function Attrs: nounwind
declare double @sqrt(double noundef) #1

attributes #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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

%class.Agent = type { ptr }

@_ZTV14HeuristicAgent = external dso_local unnamed_addr constant { [5 x ptr] }, align 8

declare void @_ZN5AgentC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0

declare void @_ZN5AgentC1Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN5AgentD1Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1

; Function Attrs: nounwind
declare void @_ZN5AgentD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14HeuristicAgentC2EPd(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr nocapture noundef readonly %1) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %class.Agent, align 8
  tail call void @_ZN5AgentC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  store ptr getelementptr inbounds inrange(-16, 24) (i8, ptr @_ZTV14HeuristicAgent, i64 16), ptr %0, align 8, !tbaa !5
  invoke void @_ZN5AgentC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %3)
          to label %4 unwind label %41

4:                                                ; preds = %2
  call void @_ZN5AgentD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %3) #5
  %5 = load double, ptr %1, align 8, !tbaa !8
  %6 = call double @llvm.fmuladd.f64(double %5, double %5, double 0.000000e+00)
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load double, ptr %7, align 8, !tbaa !8
  %9 = call double @llvm.fmuladd.f64(double %8, double %8, double %6)
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load double, ptr %10, align 8, !tbaa !8
  %12 = call double @llvm.fmuladd.f64(double %11, double %11, double %9)
  %13 = getelementptr inbounds i8, ptr %1, i64 24
  %14 = load double, ptr %13, align 8, !tbaa !8
  %15 = call double @llvm.fmuladd.f64(double %14, double %14, double %12)
  %16 = getelementptr inbounds i8, ptr %1, i64 32
  %17 = load double, ptr %16, align 8, !tbaa !8
  %18 = call double @llvm.fmuladd.f64(double %17, double %17, double %15)
  %19 = getelementptr inbounds i8, ptr %1, i64 40
  %20 = load double, ptr %19, align 8, !tbaa !8
  %21 = call double @llvm.fmuladd.f64(double %20, double %20, double %18)
  %22 = call double @sqrt(double noundef %21) #5
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = load double, ptr %1, align 8, !tbaa !8
  %25 = fdiv double %24, %22
  store double %25, ptr %23, align 8, !tbaa !8
  %26 = load double, ptr %7, align 8, !tbaa !8
  %27 = fdiv double %26, %22
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  store double %27, ptr %28, align 8, !tbaa !8
  %29 = load double, ptr %10, align 8, !tbaa !8
  %30 = fdiv double %29, %22
  %31 = getelementptr inbounds i8, ptr %0, i64 24
  store double %30, ptr %31, align 8, !tbaa !8
  %32 = load double, ptr %13, align 8, !tbaa !8
  %33 = fdiv double %32, %22
  %34 = getelementptr inbounds i8, ptr %0, i64 32
  store double %33, ptr %34, align 8, !tbaa !8
  %35 = load double, ptr %16, align 8, !tbaa !8
  %36 = fdiv double %35, %22
  %37 = getelementptr inbounds i8, ptr %0, i64 40
  store double %36, ptr %37, align 8, !tbaa !8
  %38 = load double, ptr %19, align 8, !tbaa !8
  %39 = fdiv double %38, %22
  %40 = getelementptr inbounds i8, ptr %0, i64 48
  store double %39, ptr %40, align 8, !tbaa !8
  ret void

41:                                               ; preds = %2
  %42 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN5AgentD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) #5
  resume { ptr, i32 } %42
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #4

attributes #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 = { 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 #2 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { mustprogress nofree nounwind willreturn memory(write) "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 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"double", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass