; LLVM IR from gmedders/pimd :: lib/nhc.ll (ZN5parts3nhc9invariantEmPKdRS1_)

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

@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@__PRETTY_FUNCTION__._ZN5parts3nhc9invariantEmPKdRS1_ = external hidden unnamed_addr constant [69 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN5parts3nhc9invariantEmPKdRS1_(i64 noundef %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  %11 = load i64, ptr %4, align 8, !tbaa !5
  %12 = icmp ugt i64 %11, 1
  br i1 %12, label %13, label %16

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = icmp ne ptr %14, null
  br label %16

16:                                               ; preds = %13, %3
  %17 = phi i1 [ false, %3 ], [ %15, %13 ]
  br i1 %17, label %18, label %19

18:                                               ; preds = %16
  br label %21

19:                                               ; preds = %16
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 96, ptr noundef @__PRETTY_FUNCTION__._ZN5parts3nhc9invariantEmPKdRS1_) #3
  unreachable

20:                                               ; No predecessors!
  br label %21

21:                                               ; preds = %20, %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %22, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %23 = load ptr, ptr %7, align 8, !tbaa !9
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %23, i64 %24
  store ptr %25, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %30, %21
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = add i64 %27, -1
  store i64 %28, ptr %4, align 8, !tbaa !5
  %29 = icmp ne i64 %27, 0
  br i1 %29, label %30, label %47

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = getelementptr inbounds double, ptr %33, i32 1
  store ptr %34, ptr %8, align 8, !tbaa !9
  %35 = load double, ptr %33, align 8, !tbaa !11
  %36 = fmul double %32, %35
  store double %36, ptr %10, align 8, !tbaa !11
  %37 = load double, ptr %10, align 8, !tbaa !11
  %38 = load double, ptr %10, align 8, !tbaa !11
  %39 = fmul double %37, %38
  %40 = fdiv double %39, 2.000000e+00
  %41 = load ptr, ptr %7, align 8, !tbaa !9
  %42 = getelementptr inbounds double, ptr %41, i32 1
  store ptr %42, ptr %7, align 8, !tbaa !9
  %43 = load double, ptr %41, align 8, !tbaa !11
  %44 = fadd double %40, %43
  %45 = load double, ptr %9, align 8, !tbaa !11
  %46 = fadd double %45, %44
  store double %46, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %26, !llvm.loop !13

47:                                               ; preds = %26
  %48 = load double, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret double %48
}

attributes #0 = { noreturn 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 #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 = { noreturn nounwind }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@__PRETTY_FUNCTION__._ZN5parts3nhc9invariantEmPKdRS1_ = external hidden unnamed_addr constant [69 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN5parts3nhc9invariantEmPKdRS1_(i64 noundef %0, ptr noundef readonly %1, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %2) local_unnamed_addr #1 {
  %4 = icmp ugt i64 %0, 1
  %5 = icmp ne ptr %1, null
  %6 = and i1 %4, %5
  br i1 %6, label %8, label %7

7:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 96, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5parts3nhc9invariantEmPKdRS1_) #2
  unreachable

8:                                                ; preds = %3
  %9 = getelementptr inbounds double, ptr %1, i64 %0
  %10 = load double, ptr %2, align 8, !tbaa !5
  %xtraiter = and i64 %0, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.loopexit.unr-lcssa

.prol.loopexit.unr-lcssa:                         ; preds = %8
  %11 = add nsw i64 %0, -1
  %12 = getelementptr inbounds i8, ptr %9, i64 8
  %13 = load double, ptr %9, align 8, !tbaa !5
  %14 = fmul double %10, %13
  %15 = fmul double %14, %14
  %16 = fmul double %15, 5.000000e-01
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = load double, ptr %1, align 8, !tbaa !5
  %19 = fadd double %18, %16
  %20 = fadd double %19, 0.000000e+00
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %8
  %.lcssa.unr = phi double [ poison, %8 ], [ %20, %.prol.loopexit.unr-lcssa ]
  %.020.unr = phi i64 [ %0, %8 ], [ %11, %.prol.loopexit.unr-lcssa ]
  %.01219.unr = phi double [ 0.000000e+00, %8 ], [ %20, %.prol.loopexit.unr-lcssa ]
  %.01318.unr = phi ptr [ %9, %8 ], [ %12, %.prol.loopexit.unr-lcssa ]
  %.01417.unr = phi ptr [ %1, %8 ], [ %17, %.prol.loopexit.unr-lcssa ]
  %21 = icmp eq i64 %0, 1
  br i1 %21, label %.unr-lcssa, label %.new

.new:                                             ; preds = %.prol.loopexit, %.new
  %.020 = phi i64 [ %31, %.new ], [ %.020.unr, %.prol.loopexit ]
  %.01219 = phi double [ %40, %.new ], [ %.01219.unr, %.prol.loopexit ]
  %.01318 = phi ptr [ %32, %.new ], [ %.01318.unr, %.prol.loopexit ]
  %.01417 = phi ptr [ %37, %.new ], [ %.01417.unr, %.prol.loopexit ]
  %22 = getelementptr inbounds i8, ptr %.01318, i64 8
  %23 = load double, ptr %.01318, align 8, !tbaa !5
  %24 = fmul double %10, %23
  %25 = fmul double %24, %24
  %26 = fmul double %25, 5.000000e-01
  %27 = getelementptr inbounds i8, ptr %.01417, i64 8
  %28 = load double, ptr %.01417, align 8, !tbaa !5
  %29 = fadd double %28, %26
  %30 = fadd double %.01219, %29
  %31 = add i64 %.020, -2
  %32 = getelementptr inbounds i8, ptr %.01318, i64 16
  %33 = load double, ptr %22, align 8, !tbaa !5
  %34 = fmul double %10, %33
  %35 = fmul double %34, %34
  %36 = fmul double %35, 5.000000e-01
  %37 = getelementptr inbounds i8, ptr %.01417, i64 16
  %38 = load double, ptr %27, align 8, !tbaa !5
  %39 = fadd double %38, %36
  %40 = fadd double %30, %39
  %.not.1 = icmp eq i64 %31, 0
  br i1 %.not.1, label %.unr-lcssa, label %.new, !llvm.loop !9

.unr-lcssa:                                       ; preds = %.new, %.prol.loopexit
  %.lcssa = phi double [ %.lcssa.unr, %.prol.loopexit ], [ %40, %.new ]
  ret double %.lcssa
}

attributes #0 = { noreturn 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 #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 = { noreturn 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass