; LLVM IR from moarseniy/CudaFEMproject :: deprecated/Linal2/src/Linal2.ll (ZN7MyArray4gradEPFfS_ERS_f)

; 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.MyArray = type { i32, ptr }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN7MyArrayixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7MyArray4gradEPFfS_ERS_f(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(16) %2, float noundef %3) #3 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca i32, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca %class.MyArray, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca float, align 4
  %17 = alloca float, align 4
  %18 = alloca %class.MyArray, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store float %3, ptr %8, align 4, !tbaa !9
  %19 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %20 = load float, ptr %8, align 4, !tbaa !9
  %21 = call noundef float @_ZSt4sqrtf(float noundef %20)
  %22 = fpext float %21 to double
  %23 = fmul double 1.000000e-01, %22
  %24 = fptrunc double %23 to float
  store float %24, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %87, %4
  %26 = load i32, ptr %10, align 4, !tbaa !11
  %27 = getelementptr inbounds %class.MyArray, ptr %19, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !13
  %29 = icmp slt i32 %26, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %99

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %32 = getelementptr inbounds %class.MyArray, ptr %19, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = load i32, ptr %10, align 4, !tbaa !11
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds float, ptr %33, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !9
  store float %37, ptr %11, align 4, !tbaa !9
  %38 = load float, ptr %9, align 4, !tbaa !9
  %39 = getelementptr inbounds %class.MyArray, ptr %19, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load i32, ptr %10, align 4, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds float, ptr %40, i64 %42
  %44 = load float, ptr %43, align 4, !tbaa !9
  %45 = fadd float %44, %38
  store float %45, ptr %43, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN7MyArrayC1ERKS_(ptr noundef nonnull align 8 dereferenceable(16) %13, ptr noundef nonnull align 8 dereferenceable(16) %19)
  %47 = invoke noundef float %46(ptr noundef %13)
          to label %48 unwind label %90

48:                                               ; preds = %31
  call void @_ZN7MyArrayD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %13) #4
  store float %47, ptr %12, align 4, !tbaa !9
  %49 = load float, ptr %11, align 4, !tbaa !9
  %50 = getelementptr inbounds %class.MyArray, ptr %19, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = load i32, ptr %10, align 4, !tbaa !11
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds float, ptr %51, i64 %53
  store float %49, ptr %54, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %55 = getelementptr inbounds %class.MyArray, ptr %19, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = load i32, ptr %10, align 4, !tbaa !11
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds float, ptr %56, i64 %58
  %60 = load float, ptr %59, align 4, !tbaa !9
  store float %60, ptr %16, align 4, !tbaa !9
  %61 = load float, ptr %9, align 4, !tbaa !9
  %62 = getelementptr inbounds %class.MyArray, ptr %19, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  %64 = load i32, ptr %10, align 4, !tbaa !11
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds float, ptr %63, i64 %65
  %67 = load float, ptr %66, align 4, !tbaa !9
  %68 = fsub float %67, %61
  store float %68, ptr %66, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN7MyArrayC1ERKS_(ptr noundef nonnull align 8 dereferenceable(16) %18, ptr noundef nonnull align 8 dereferenceable(16) %19)
  %70 = invoke noundef float %69(ptr noundef %18)
          to label %71 unwind label %94

71:                                               ; preds = %48
  call void @_ZN7MyArrayD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %18) #4
  store float %70, ptr %17, align 4, !tbaa !9
  %72 = load float, ptr %16, align 4, !tbaa !9
  %73 = getelementptr inbounds %class.MyArray, ptr %19, i32 0, i32 1
  %74 = load ptr, ptr %73, align 8, !tbaa !15
  %75 = load i32, ptr %10, align 4, !tbaa !11
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds float, ptr %74, i64 %76
  store float %72, ptr %77, align 4, !tbaa !9
  %78 = load float, ptr %12, align 4, !tbaa !9
  %79 = load float, ptr %17, align 4, !tbaa !9
  %80 = fsub float %78, %79
  %81 = load float, ptr %9, align 4, !tbaa !9
  %82 = fmul float 2.000000e+00, %81
  %83 = fdiv float %80, %82
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = load i32, ptr %10, align 4, !tbaa !11
  %86 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7MyArrayixEi(ptr noundef nonnull align 8 dereferenceable(16) %84, i32 noundef %85)
  store float %83, ptr %86, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %87

87:                                               ; preds = %71
  %88 = load i32, ptr %10, align 4, !tbaa !11
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %10, align 4, !tbaa !11
  br label %25, !llvm.loop !16

90:                                               ; preds = %31
  %91 = landingpad { ptr, i32 }
          cleanup
  %92 = extractvalue { ptr, i32 } %91, 0
  store ptr %92, ptr %14, align 8
  %93 = extractvalue { ptr, i32 } %91, 1
  store i32 %93, ptr %15, align 4
  call void @_ZN7MyArrayD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %13) #4
  br label %98

94:                                               ; preds = %48
  %95 = landingpad { ptr, i32 }
          cleanup
  %96 = extractvalue { ptr, i32 } %95, 0
  store ptr %96, ptr %14, align 8
  %97 = extractvalue { ptr, i32 } %95, 1
  store i32 %97, ptr %15, align 4
  call void @_ZN7MyArrayD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %98

98:                                               ; preds = %94, %90
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %100

99:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void

100:                                              ; preds = %98
  %101 = load ptr, ptr %14, align 8
  %102 = load i32, ptr %15, align 4
  %103 = insertvalue { ptr, i32 } poison, ptr %101, 0
  %104 = insertvalue { ptr, i32 } %103, i32 %102, 1
  resume { ptr, i32 } %104
}

declare i32 @__gxx_personality_v0(...)

declare void @_ZN7MyArrayC1ERKS_(ptr, ptr)

declare void @_ZN7MyArrayD1Ev(ptr)

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 = { inlinehint 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 = { 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 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTS7MyArray", !12, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%class.MyArray = type { i32, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN7MyArrayixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7MyArray4gradEPFfS_ERS_f(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr nocapture noundef readonly %1, ptr noundef nonnull align 8 dereferenceable(16) %2, float noundef %3) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca %class.MyArray, align 8
  %6 = alloca %class.MyArray, align 8
  %7 = tail call noundef float @_ZSt4sqrtf(float noundef %3)
  %8 = fpext float %7 to double
  %9 = fmul double %8, 1.000000e-01
  %10 = fptrunc double %9 to float
  %11 = load i32, ptr %0, align 8, !tbaa !5
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = fmul float %10, 2.000000e+00
  br label %15

._crit_edge:                                      ; preds = %26, %4
  ret void

15:                                               ; preds = %.lr.ph, %26
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %26 ]
  %16 = load ptr, ptr %13, align 8, !tbaa !11
  %17 = getelementptr inbounds float, ptr %16, i64 %indvars.iv
  %18 = load float, ptr %17, align 4, !tbaa !12
  %19 = fadd float %18, %10
  store float %19, ptr %17, align 4, !tbaa !12
  call void @_ZN7MyArrayC1ERKS_(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(16) %0)
  %20 = invoke noundef float %1(ptr noundef nonnull %5)
          to label %21 unwind label %36

21:                                               ; preds = %15
  call void @_ZN7MyArrayD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  %22 = load ptr, ptr %13, align 8, !tbaa !11
  %23 = getelementptr inbounds float, ptr %22, i64 %indvars.iv
  %24 = fsub float %18, %10
  store float %24, ptr %23, align 4, !tbaa !12
  call void @_ZN7MyArrayC1ERKS_(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(16) %0)
  %25 = invoke noundef float %1(ptr noundef nonnull %6)
          to label %26 unwind label %38

26:                                               ; preds = %21
  call void @_ZN7MyArrayD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #3
  %27 = load ptr, ptr %13, align 8, !tbaa !11
  %28 = getelementptr inbounds float, ptr %27, i64 %indvars.iv
  store float %18, ptr %28, align 4, !tbaa !12
  %29 = fsub float %20, %25
  %30 = fdiv float %29, %14
  %31 = trunc nuw nsw i64 %indvars.iv to i32
  %32 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7MyArrayixEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %31)
  store float %30, ptr %32, align 4, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = load i32, ptr %0, align 8, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = icmp slt i64 %indvars.iv.next, %34
  br i1 %35, label %15, label %._crit_edge, !llvm.loop !14

36:                                               ; preds = %15
  %37 = landingpad { ptr, i32 }
          cleanup
  br label %40

38:                                               ; preds = %21
  %39 = landingpad { ptr, i32 }
          cleanup
  br label %40

40:                                               ; preds = %38, %36
  %.sink = phi ptr [ %6, %38 ], [ %5, %36 ]
  %.pn = phi { ptr, i32 } [ %39, %38 ], [ %37, %36 ]
  call void @_ZN7MyArrayD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %.sink) #3
  resume { ptr, i32 } %.pn
}

declare i32 @__gxx_personality_v0(...)

declare void @_ZN7MyArrayC1ERKS_(ptr, ptr) local_unnamed_addr

declare void @_ZN7MyArrayD1Ev(ptr) local_unnamed_addr

attributes #0 = { 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 #1 = { inlinehint 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 = { 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 = { 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 = !{!"_ZTS7MyArray", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass