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

; 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 speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #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: mustprogress uwtable
define dso_local void @_ZN7MyArrayC2Eiff(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, float noundef %2, float noundef %3) unnamed_addr #3 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca %class.MyArray, align 8
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !11
  store float %3, ptr %8, align 4, !tbaa !11
  %12 = load ptr, ptr %5, align 8
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %4
  call void @_ZN7MyArrayC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %9)
  call void @_ZN7MyArrayD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %9) #4
  br label %62

16:                                               ; preds = %4
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = getelementptr inbounds %class.MyArray, ptr %12, i32 0, i32 0
  store i32 %17, ptr %18, align 8, !tbaa !13
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %20, i64 4)
  %22 = extractvalue { i64, i1 } %21, 1
  %23 = extractvalue { i64, i1 } %21, 0
  %24 = select i1 %22, i64 -1, i64 %23
  %25 = call noalias noundef nonnull ptr @_Znam(i64 noundef %24) #5
  %26 = getelementptr inbounds %class.MyArray, ptr %12, i32 0, i32 1
  store ptr %25, ptr %26, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %27 = load float, ptr %8, align 4, !tbaa !11
  %28 = load float, ptr %7, align 4, !tbaa !11
  %29 = fsub float %27, %28
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = sub nsw i32 %30, 1
  %32 = sitofp i32 %31 to float
  %33 = fdiv float %29, %32
  store float %33, ptr %10, align 4, !tbaa !11
  %34 = load float, ptr %7, align 4, !tbaa !11
  %35 = getelementptr inbounds %class.MyArray, ptr %12, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = getelementptr inbounds float, ptr %36, i64 0
  store float %34, ptr %37, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 1, ptr %11, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %58, %16
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %61

43:                                               ; preds = %38
  %44 = getelementptr inbounds %class.MyArray, ptr %12, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = sub nsw i32 %46, 1
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds float, ptr %45, i64 %48
  %50 = load float, ptr %49, align 4, !tbaa !11
  %51 = load float, ptr %10, align 4, !tbaa !11
  %52 = fadd float %50, %51
  %53 = getelementptr inbounds %class.MyArray, ptr %12, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = load i32, ptr %11, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds float, ptr %54, i64 %56
  store float %52, ptr %57, align 4, !tbaa !11
  br label %58

58:                                               ; preds = %43
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %11, align 4, !tbaa !9
  br label %38, !llvm.loop !16

61:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %62

62:                                               ; preds = %61, %15
  ret void
}

declare void @_ZN7MyArrayC1Ev(ptr)

declare void @_ZN7MyArrayD1Ev(ptr)

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

!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, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS7MyArray", !10, 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7MyArrayC2Eiff(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(16) %0, i32 noundef %1, float noundef %2, float noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca %class.MyArray, align 8
  %6 = icmp eq i32 %1, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %4
  call void @_ZN7MyArrayC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %5)
  call void @_ZN7MyArrayD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #2
  br label %.loopexit

8:                                                ; preds = %4
  store i32 %1, ptr %0, align 8, !tbaa !5
  %9 = zext i32 %1 to i64
  %10 = icmp slt i32 %1, 0
  %11 = shl nuw nsw i64 %9, 2
  %12 = select i1 %10, i64 -1, i64 %11
  %13 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %12) #3
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %13, ptr %14, align 8, !tbaa !11
  %15 = fsub float %3, %2
  %16 = add nsw i32 %1, -1
  %17 = sitofp i32 %16 to float
  %18 = fdiv float %15, %17
  store float %2, ptr %13, align 4, !tbaa !12
  %19 = icmp sgt i32 %1, 1
  br i1 %19, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %8
  %load_initial = load float, ptr %13, align 4
  %20 = add nsw i64 %9, -1
  %21 = add nsw i64 %9, -2
  %xtraiter = and i64 %20, 3
  %22 = icmp ult i64 %21, 3
  br i1 %22, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %20, -4
  %invariant.gep = getelementptr i8, ptr %13, i64 4
  %invariant.gep16 = getelementptr i8, ptr %13, i64 8
  %invariant.gep18 = getelementptr i8, ptr %13, i64 12
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %store_forwarded = phi float [ %load_initial, %.lr.ph.preheader.new ], [ %27, %.lr.ph ]
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %23 = getelementptr float, ptr %13, i64 %indvars.iv
  %24 = fadd float %18, %store_forwarded
  store float %24, ptr %23, align 4, !tbaa !12
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv
  %25 = fadd float %18, %24
  store float %25, ptr %gep, align 4, !tbaa !12
  %gep17 = getelementptr float, ptr %invariant.gep16, i64 %indvars.iv
  %26 = fadd float %18, %25
  store float %26, ptr %gep17, align 4, !tbaa !12
  %gep19 = getelementptr float, ptr %invariant.gep18, i64 %indvars.iv
  %27 = fadd float %18, %26
  store float %27, ptr %gep19, align 4, !tbaa !12
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !14

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph, %.lr.ph.preheader
  %store_forwarded.unr = phi float [ %load_initial, %.lr.ph.preheader ], [ %27, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil
  %store_forwarded.epil = phi float [ %29, %.lr.ph.epil ], [ %store_forwarded.unr, %.loopexit.loopexit.unr-lcssa ]
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %28 = getelementptr float, ptr %13, i64 %indvars.iv.epil
  %29 = fadd float %18, %store_forwarded.epil
  store float %29, ptr %28, align 4, !tbaa !12
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.lr.ph.epil, !llvm.loop !16

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil, %8, %7
  ret void
}

declare void @_ZN7MyArrayC1Ev(ptr) local_unnamed_addr

declare void @_ZN7MyArrayD1Ev(ptr) local_unnamed_addr

attributes #0 = { 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 #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 }
attributes #3 = { builtin allocsize(0) }

!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"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass