; LLVM IR from steevo87/thermalvis :: src/core/timing.ll (ZN12timeAnalyzer14calcParametersEv)

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

%struct.timeAnalyzer = type { i32, [1024 x double], double, double, %struct.timeval }
%struct.timeval = type { i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN12timeAnalyzer14calcParametersEv(ptr noundef nonnull align 8 dereferenceable(8232) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 0
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %67

10:                                               ; preds = %1
  %11 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 2
  store double 0.000000e+00, ptr %11, align 8, !tbaa !15
  %12 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 3
  store double 0.000000e+00, ptr %12, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !17
  br label %13

13:                                               ; preds = %32, %10
  %14 = load i32, ptr %3, align 4, !tbaa !17
  %15 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %13
  %20 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 1
  %21 = load i32, ptr %3, align 4, !tbaa !17
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1024 x double], ptr %20, i64 0, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !18
  %25 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = sitofp i32 %26 to double
  %28 = fdiv double %24, %27
  %29 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 2
  %30 = load double, ptr %29, align 8, !tbaa !15
  %31 = fadd double %30, %28
  store double %31, ptr %29, align 8, !tbaa !15
  br label %32

32:                                               ; preds = %19
  %33 = load i32, ptr %3, align 4, !tbaa !17
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %3, align 4, !tbaa !17
  br label %13, !llvm.loop !19

35:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !17
  br label %36

36:                                               ; preds = %59, %35
  %37 = load i32, ptr %4, align 4, !tbaa !17
  %38 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !9
  %40 = icmp slt i32 %37, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %62

42:                                               ; preds = %36
  %43 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 1
  %44 = load i32, ptr %4, align 4, !tbaa !17
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1024 x double], ptr %43, i64 0, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !18
  %48 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 2
  %49 = load double, ptr %48, align 8, !tbaa !15
  %50 = fsub double %47, %49
  %51 = call double @pow(double noundef %50, double noundef 2.000000e+00) #3
  %52 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !9
  %54 = sitofp i32 %53 to double
  %55 = fdiv double %51, %54
  %56 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 3
  %57 = load double, ptr %56, align 8, !tbaa !16
  %58 = fadd double %57, %55
  store double %58, ptr %56, align 8, !tbaa !16
  br label %59

59:                                               ; preds = %42
  %60 = load i32, ptr %4, align 4, !tbaa !17
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %4, align 4, !tbaa !17
  br label %36, !llvm.loop !21

62:                                               ; preds = %41
  %63 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 3
  %64 = load double, ptr %63, align 8, !tbaa !16
  %65 = call double @pow(double noundef %64, double noundef 5.000000e-01) #3
  %66 = getelementptr inbounds %struct.timeAnalyzer, ptr %5, i32 0, i32 3
  store double %65, ptr %66, align 8, !tbaa !16
  br label %67

67:                                               ; preds = %62, %9
  ret void
}

; 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: nounwind
declare double @pow(double noundef, double noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 0}
!10 = !{!"_ZTS12timeAnalyzer", !11, i64 0, !7, i64 8, !12, i64 8200, !12, i64 8208, !13, i64 8216}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"_ZTS7timeval", !14, i64 0, !14, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !12, i64 8200}
!16 = !{!10, !12, i64 8208}
!17 = !{!11, !11, i64 0}
!18 = !{!12, !12, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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 void @_ZN12timeAnalyzer14calcParametersEv(ptr nocapture noundef nonnull align 8 dereferenceable(8232) %0) local_unnamed_addr #0 align 2 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %56, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8200
  %6 = getelementptr inbounds i8, ptr %0, i64 8208
  %7 = icmp sgt i32 %2, 0
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %5, i8 0, i64 16, i1 false)
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = uitofp nneg i32 %2 to double
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %10 = icmp ult i32 %2, 4
  br i1 %10, label %.preheader.unr-lcssa, label %.lr.ph.new

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

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

.epil.preheader:                                  ; preds = %.preheader.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.preheader.unr-lcssa ]
  %11 = phi double [ %15, %.epil.preheader ], [ %.unr, %.preheader.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.preheader.unr-lcssa ]
  %12 = getelementptr inbounds [1024 x double], ptr %8, i64 0, i64 %indvars.iv.epil
  %13 = load double, ptr %12, align 8, !tbaa !13
  %14 = fdiv double %13, %9
  %15 = fadd double %11, %14
  store double %15, ptr %5, align 8, !tbaa !14
  %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 %.preheader, label %.epil.preheader, !llvm.loop !15

.preheader:                                       ; preds = %.epil.preheader, %.preheader.unr-lcssa
  %.lcssa20 = phi double [ %.lcssa20.ph, %.preheader.unr-lcssa ], [ %15, %.epil.preheader ]
  br i1 %7, label %.lr.ph11, label %._crit_edge

.lr.ph11:                                         ; preds = %.preheader
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = uitofp nneg i32 %2 to double
  %xtraiter23 = and i64 %wide.trip.count, 1
  %18 = icmp eq i32 %2, 1
  br i1 %18, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph11.new

.lr.ph11.new:                                     ; preds = %.lr.ph11
  %unroll_iter28 = and i64 %wide.trip.count, 2147483646
  br label %44

19:                                               ; preds = %19, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %19 ]
  %20 = phi double [ 0.000000e+00, %.lr.ph.new ], [ %36, %19 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %19 ]
  %21 = getelementptr inbounds [1024 x double], ptr %8, i64 0, i64 %indvars.iv
  %22 = load double, ptr %21, align 8, !tbaa !13
  %23 = fdiv double %22, %9
  %24 = fadd double %20, %23
  store double %24, ptr %5, align 8, !tbaa !14
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %25 = getelementptr inbounds [1024 x double], ptr %8, i64 0, i64 %indvars.iv.next
  %26 = load double, ptr %25, align 8, !tbaa !13
  %27 = fdiv double %26, %9
  %28 = fadd double %24, %27
  store double %28, ptr %5, align 8, !tbaa !14
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %29 = getelementptr inbounds [1024 x double], ptr %8, i64 0, i64 %indvars.iv.next.1
  %30 = load double, ptr %29, align 8, !tbaa !13
  %31 = fdiv double %30, %9
  %32 = fadd double %28, %31
  store double %32, ptr %5, align 8, !tbaa !14
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %33 = getelementptr inbounds [1024 x double], ptr %8, i64 0, i64 %indvars.iv.next.2
  %34 = load double, ptr %33, align 8, !tbaa !13
  %35 = fdiv double %34, %9
  %36 = fadd double %32, %35
  store double %36, ptr %5, align 8, !tbaa !14
  %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 %.preheader.unr-lcssa, label %19, !llvm.loop !17

._crit_edge.loopexit.unr-lcssa:                   ; preds = %44, %.lr.ph11
  %.lcssa.ph = phi double [ poison, %.lr.ph11 ], [ %55, %44 ]
  %indvars.iv13.unr = phi i64 [ 0, %.lr.ph11 ], [ %indvars.iv.next14.1, %44 ]
  %.unr25 = phi double [ 0.000000e+00, %.lr.ph11 ], [ %55, %44 ]
  %lcmp.mod26.not = icmp eq i64 %xtraiter23, 0
  br i1 %lcmp.mod26.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %37 = getelementptr inbounds [1024 x double], ptr %16, i64 0, i64 %indvars.iv13.unr
  %38 = load double, ptr %37, align 8, !tbaa !13
  %39 = fsub double %38, %.lcssa20
  %square.epil = fmul double %39, %39
  %40 = fdiv double %square.epil, %17
  %41 = fadd double %.unr25, %40
  store double %41, ptr %6, align 8, !tbaa !19
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %4, %.preheader
  %42 = phi double [ 0.000000e+00, %.preheader ], [ 0.000000e+00, %4 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %41, %._crit_edge.loopexit.epilog-lcssa ]
  %43 = tail call double @pow(double noundef %42, double noundef 5.000000e-01) #3
  store double %43, ptr %6, align 8, !tbaa !19
  br label %56

44:                                               ; preds = %44, %.lr.ph11.new
  %indvars.iv13 = phi i64 [ 0, %.lr.ph11.new ], [ %indvars.iv.next14.1, %44 ]
  %45 = phi double [ 0.000000e+00, %.lr.ph11.new ], [ %55, %44 ]
  %niter29 = phi i64 [ 0, %.lr.ph11.new ], [ %niter29.next.1, %44 ]
  %46 = getelementptr inbounds [1024 x double], ptr %16, i64 0, i64 %indvars.iv13
  %47 = load double, ptr %46, align 8, !tbaa !13
  %48 = fsub double %47, %.lcssa20
  %square = fmul double %48, %48
  %49 = fdiv double %square, %17
  %50 = fadd double %45, %49
  store double %50, ptr %6, align 8, !tbaa !19
  %indvars.iv.next14 = or disjoint i64 %indvars.iv13, 1
  %51 = getelementptr inbounds [1024 x double], ptr %16, i64 0, i64 %indvars.iv.next14
  %52 = load double, ptr %51, align 8, !tbaa !13
  %53 = fsub double %52, %.lcssa20
  %square.1 = fmul double %53, %53
  %54 = fdiv double %square.1, %17
  %55 = fadd double %50, %54
  store double %55, ptr %6, align 8, !tbaa !19
  %indvars.iv.next14.1 = add nuw nsw i64 %indvars.iv13, 2
  %niter29.next.1 = add i64 %niter29, 2
  %niter29.ncmp.1 = icmp eq i64 %niter29.next.1, %unroll_iter28
  br i1 %niter29.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %44, !llvm.loop !20

56:                                               ; preds = %1, %._crit_edge
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"_ZTS12timeAnalyzer", !7, i64 0, !8, i64 8, !10, i64 8200, !10, i64 8208, !11, i64 8216}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"_ZTS7timeval", !12, i64 0, !12, i64 8}
!12 = !{!"long", !8, i64 0}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !10, i64 8200}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !10, i64 8208}
!20 = distinct !{!20, !18}


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