; LLVM IR from sp-nitech/SPTK :: third_party/WORLD/matlabfunctions.ll (ZN4sptk5world10matlab_stdEPKdi)

; 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
define dso_local noundef double @_ZN4sptk5world10matlab_stdEPKdi(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 0.000000e+00, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %22, %2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds double, ptr %15, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !11
  %20 = load double, ptr %5, align 8, !tbaa !11
  %21 = fadd double %20, %19
  store double %21, ptr %5, align 8, !tbaa !11
  br label %22

22:                                               ; preds = %14
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !13

25:                                               ; preds = %13
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = sitofp i32 %26 to double
  %28 = load double, ptr %5, align 8, !tbaa !11
  %29 = fdiv double %28, %27
  store double %29, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %46, %25
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %49

35:                                               ; preds = %30
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %36, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = load double, ptr %5, align 8, !tbaa !11
  %42 = fsub double %40, %41
  %43 = call double @pow(double noundef %42, double noundef 2.000000e+00) #3
  %44 = load double, ptr %7, align 8, !tbaa !11
  %45 = fadd double %44, %43
  store double %45, ptr %7, align 8, !tbaa !11
  br label %46

46:                                               ; preds = %35
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %8, align 4, !tbaa !9
  br label %30, !llvm.loop !15

49:                                               ; preds = %34
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  %52 = sitofp i32 %51 to double
  %53 = load double, ptr %7, align 8, !tbaa !11
  %54 = fdiv double %53, %52
  store double %54, ptr %7, align 8, !tbaa !11
  %55 = load double, ptr %7, align 8, !tbaa !11
  %56 = call double @sqrt(double noundef %55) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret double %56
}

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #2

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

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 = { 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 #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 = !{!"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 nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local noundef double @_ZN4sptk5world10matlab_stdEPKdi(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 0
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge27

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 7
  %4 = icmp ult i32 %1, 8
  br i1 %4, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483640
  br label %.lr.ph

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa39.ph = phi double [ poison, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.7, %.lr.ph ]
  %.01921.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.unr-lcssa ]
  %.01921.epil = phi double [ %7, %.lr.ph.epil ], [ %.01921.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.unr-lcssa ]
  %5 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.epil
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = fadd double %.01921.epil, %6
  %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 %._crit_edge, label %.lr.ph.epil, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.unr-lcssa
  %.lcssa39 = phi double [ %.lcssa39.ph, %._crit_edge.unr-lcssa ], [ %7, %.lr.ph.epil ]
  %8 = sitofp i32 %1 to double
  %9 = fdiv double %.lcssa39, %8
  br i1 %3, label %.lr.ph26.preheader, label %._crit_edge27

.lr.ph26.preheader:                               ; preds = %._crit_edge
  %xtraiter41 = and i64 %wide.trip.count, 3
  %10 = icmp ult i32 %1, 4
  br i1 %10, label %._crit_edge27.loopexit.unr-lcssa, label %.lr.ph26.preheader.new

.lr.ph26.preheader.new:                           ; preds = %.lr.ph26.preheader
  %unroll_iter45 = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph26

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.7, %.lr.ph ]
  %.01921 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %34, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %11 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = fadd double %.01921, %12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %14 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fadd double %13, %15
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %17 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next.1
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = fadd double %16, %18
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %20 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next.2
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fadd double %19, %21
  %indvars.iv.next.3 = or disjoint i64 %indvars.iv, 4
  %23 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next.3
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = fadd double %22, %24
  %indvars.iv.next.4 = or disjoint i64 %indvars.iv, 5
  %26 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next.4
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = fadd double %25, %27
  %indvars.iv.next.5 = or disjoint i64 %indvars.iv, 6
  %29 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next.5
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = fadd double %28, %30
  %indvars.iv.next.6 = or disjoint i64 %indvars.iv, 7
  %32 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next.6
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = fadd double %31, %33
  %indvars.iv.next.7 = add nuw nsw i64 %indvars.iv, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !11

._crit_edge27.loopexit.unr-lcssa:                 ; preds = %.lr.ph26, %.lr.ph26.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph26.preheader ], [ %58, %.lr.ph26 ]
  %indvars.iv31.unr = phi i64 [ 0, %.lr.ph26.preheader ], [ %indvars.iv.next32.3, %.lr.ph26 ]
  %.01723.unr = phi double [ 0.000000e+00, %.lr.ph26.preheader ], [ %58, %.lr.ph26 ]
  %lcmp.mod43.not = icmp eq i64 %xtraiter41, 0
  br i1 %lcmp.mod43.not, label %._crit_edge27, label %.lr.ph26.epil

.lr.ph26.epil:                                    ; preds = %._crit_edge27.loopexit.unr-lcssa, %.lr.ph26.epil
  %indvars.iv31.epil = phi i64 [ %indvars.iv.next32.epil, %.lr.ph26.epil ], [ %indvars.iv31.unr, %._crit_edge27.loopexit.unr-lcssa ]
  %.01723.epil = phi double [ %38, %.lr.ph26.epil ], [ %.01723.unr, %._crit_edge27.loopexit.unr-lcssa ]
  %epil.iter42 = phi i64 [ %epil.iter42.next, %.lr.ph26.epil ], [ 0, %._crit_edge27.loopexit.unr-lcssa ]
  %35 = getelementptr inbounds double, ptr %0, i64 %indvars.iv31.epil
  %36 = load double, ptr %35, align 8, !tbaa !5
  %37 = fsub double %36, %9
  %square.epil = fmul double %37, %37
  %38 = fadd double %.01723.epil, %square.epil
  %indvars.iv.next32.epil = add nuw nsw i64 %indvars.iv31.epil, 1
  %epil.iter42.next = add i64 %epil.iter42, 1
  %epil.iter42.cmp.not = icmp eq i64 %epil.iter42.next, %xtraiter41
  br i1 %epil.iter42.cmp.not, label %._crit_edge27, label %.lr.ph26.epil, !llvm.loop !13

._crit_edge27:                                    ; preds = %._crit_edge27.loopexit.unr-lcssa, %.lr.ph26.epil, %2, %._crit_edge
  %.017.lcssa = phi double [ 0.000000e+00, %._crit_edge ], [ 0.000000e+00, %2 ], [ %.lcssa.ph, %._crit_edge27.loopexit.unr-lcssa ], [ %38, %.lr.ph26.epil ]
  %39 = add nsw i32 %1, -1
  %40 = sitofp i32 %39 to double
  %41 = fdiv double %.017.lcssa, %40
  %42 = tail call double @sqrt(double noundef %41) #2
  ret double %42

.lr.ph26:                                         ; preds = %.lr.ph26, %.lr.ph26.preheader.new
  %indvars.iv31 = phi i64 [ 0, %.lr.ph26.preheader.new ], [ %indvars.iv.next32.3, %.lr.ph26 ]
  %.01723 = phi double [ 0.000000e+00, %.lr.ph26.preheader.new ], [ %58, %.lr.ph26 ]
  %niter46 = phi i64 [ 0, %.lr.ph26.preheader.new ], [ %niter46.next.3, %.lr.ph26 ]
  %43 = getelementptr inbounds double, ptr %0, i64 %indvars.iv31
  %44 = load double, ptr %43, align 8, !tbaa !5
  %45 = fsub double %44, %9
  %square = fmul double %45, %45
  %46 = fadd double %.01723, %square
  %indvars.iv.next32 = or disjoint i64 %indvars.iv31, 1
  %47 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next32
  %48 = load double, ptr %47, align 8, !tbaa !5
  %49 = fsub double %48, %9
  %square.1 = fmul double %49, %49
  %50 = fadd double %46, %square.1
  %indvars.iv.next32.1 = or disjoint i64 %indvars.iv31, 2
  %51 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next32.1
  %52 = load double, ptr %51, align 8, !tbaa !5
  %53 = fsub double %52, %9
  %square.2 = fmul double %53, %53
  %54 = fadd double %50, %square.2
  %indvars.iv.next32.2 = or disjoint i64 %indvars.iv31, 3
  %55 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next32.2
  %56 = load double, ptr %55, align 8, !tbaa !5
  %57 = fsub double %56, %9
  %square.3 = fmul double %57, %57
  %58 = fadd double %54, %square.3
  %indvars.iv.next32.3 = add nuw nsw i64 %indvars.iv31, 4
  %niter46.next.3 = add i64 %niter46, 4
  %niter46.ncmp.3 = icmp eq i64 %niter46.next.3, %unroll_iter45
  br i1 %niter46.ncmp.3, label %._crit_edge27.loopexit.unr-lcssa, label %.lr.ph26, !llvm.loop !14
}

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

attributes #0 = { mustprogress nofree nounwind memory(write, argmem: readwrite) 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 = { 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.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !12}


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