; LLVM IR from yuikns/panther :: ann/test/rand.ll (Z13annCoGaussPtsPPdiid)

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

; 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 hidden noundef double @_ZL11annRanGaussv() #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z13annCoGaussPtsPPdiid(ptr noundef %0, i32 noundef %1, i32 noundef %2, double noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store double %3, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %14 = load double, ptr %8, align 8, !tbaa !11
  %15 = load double, ptr %8, align 8, !tbaa !11
  %16 = fneg double %14
  %17 = call double @llvm.fmuladd.f64(double %16, double %15, double 1.000000e+00)
  %18 = call double @sqrt(double noundef %17) #5
  store double %18, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %58, %4
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %61

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %25 = call noundef double @_ZL11annRanGaussv()
  store double %25, ptr %12, align 8, !tbaa !11
  %26 = load double, ptr %12, align 8, !tbaa !11
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %27, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds double, ptr %31, i64 0
  store double %26, ptr %32, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 1, ptr %13, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %54, %24
  %34 = load i32, ptr %13, align 4, !tbaa !9
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %57

38:                                               ; preds = %33
  %39 = load double, ptr %8, align 8, !tbaa !11
  %40 = load double, ptr %12, align 8, !tbaa !11
  %41 = load double, ptr %9, align 8, !tbaa !11
  %42 = call noundef double @_ZL11annRanGaussv()
  %43 = fmul double %41, %42
  %44 = call double @llvm.fmuladd.f64(double %39, double %40, double %43)
  store double %44, ptr %12, align 8, !tbaa !11
  %45 = load double, ptr %12, align 8, !tbaa !11
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %46, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %50, i64 %52
  store double %45, ptr %53, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %38
  %55 = load i32, ptr %13, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %13, align 4, !tbaa !9
  br label %33, !llvm.loop !13

57:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %10, align 4, !tbaa !9
  br label %19, !llvm.loop !15

61:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret void
}

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

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

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 = { 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 "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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef double @_ZL11annRanGaussv() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z13annCoGaussPtsPPdiid(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, double noundef %3) local_unnamed_addr #0 {
  %5 = fneg double %3
  %6 = tail call double @llvm.fmuladd.f64(double %5, double %3, double 1.000000e+00)
  %7 = tail call double @sqrt(double noundef %6) #3
  %8 = icmp sgt i32 %1, 0
  br i1 %8, label %.lr.ph23, label %._crit_edge24

.lr.ph23:                                         ; preds = %4
  %9 = icmp sgt i32 %2, 1
  %wide.trip.count35 = zext nneg i32 %1 to i64
  br i1 %9, label %.lr.ph.us.preheader, label %.lr.ph23.split

.lr.ph.us.preheader:                              ; preds = %.lr.ph23
  %wide.trip.count30 = zext nneg i32 %2 to i64
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv32 = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next33, %._crit_edge.us ]
  %10 = tail call noundef double @_ZL11annRanGaussv()
  %11 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv32
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  store double %10, ptr %12, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %.lr.ph.us, %13
  %indvars.iv27 = phi i64 [ 1, %.lr.ph.us ], [ %indvars.iv.next28, %13 ]
  %.01719.us = phi double [ %10, %.lr.ph.us ], [ %16, %13 ]
  %14 = tail call noundef double @_ZL11annRanGaussv()
  %15 = fmul double %7, %14
  %16 = tail call double @llvm.fmuladd.f64(double %3, double %.01719.us, double %15)
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  %18 = getelementptr inbounds double, ptr %17, i64 %indvars.iv27
  store double %16, ptr %18, align 8, !tbaa !9
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %exitcond31.not = icmp eq i64 %indvars.iv.next28, %wide.trip.count30
  br i1 %exitcond31.not, label %._crit_edge.us, label %13, !llvm.loop !11

._crit_edge.us:                                   ; preds = %13
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond36.not = icmp eq i64 %indvars.iv.next33, %wide.trip.count35
  br i1 %exitcond36.not, label %._crit_edge24, label %.lr.ph.us, !llvm.loop !13

._crit_edge24:                                    ; preds = %.lr.ph23.split, %._crit_edge.us, %4
  ret void

.lr.ph23.split:                                   ; preds = %.lr.ph23, %.lr.ph23.split
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph23.split ], [ 0, %.lr.ph23 ]
  %19 = tail call noundef double @_ZL11annRanGaussv()
  %20 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  store double %19, ptr %21, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count35
  br i1 %exitcond.not, label %._crit_edge24, label %.lr.ph23.split, !llvm.loop !13
}

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

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

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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