; LLVM IR from sympiler/nasoq :: src/common/Norm.ll (ZN5nasoq9error_maxEiPdS0_)

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) #1

; 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 dso_local noundef zeroext i1 @_ZSt8isfinited(double noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN5nasoq9error_maxEiPdS0_(i32 noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0.000000e+00, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %68, %3
  %13 = load i32, ptr %10, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %11, align 4
  br label %71

17:                                               ; preds = %12
  %18 = load ptr, ptr %7, align 8, !tbaa !9
  %19 = load i32, ptr %10, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %18, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = call noundef zeroext i1 @_ZSt8isfinited(double noundef %22)
  br i1 %23, label %24, label %38

24:                                               ; preds = %17
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = load i32, ptr %10, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds double, ptr %25, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !11
  %30 = call noundef zeroext i1 @_ZSt8isfinited(double noundef %29)
  br i1 %30, label %31, label %38

31:                                               ; preds = %24
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = load i32, ptr %10, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %32, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !11
  %37 = fcmp oeq double %36, 0.000000e+00
  br i1 %37, label %38, label %39

38:                                               ; preds = %31, %24, %17
  store double -1.000000e+00, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %71

39:                                               ; preds = %31
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = load i32, ptr %10, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %40, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = load ptr, ptr %7, align 8, !tbaa !9
  %46 = load i32, ptr %10, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %45, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fsub double %44, %49
  %51 = call noundef double @_ZSt3absd(double noundef %50)
  %52 = load ptr, ptr %6, align 8, !tbaa !9
  %53 = load i32, ptr %10, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %52, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !11
  %57 = call noundef double @_ZSt3absd(double noundef %56)
  %58 = fdiv double %51, %57
  store double %58, ptr %8, align 8, !tbaa !11
  %59 = load double, ptr %8, align 8, !tbaa !11
  %60 = load double, ptr %9, align 8, !tbaa !11
  %61 = fcmp ogt double %59, %60
  br i1 %61, label %62, label %64

62:                                               ; preds = %39
  %63 = load double, ptr %8, align 8, !tbaa !11
  br label %66

64:                                               ; preds = %39
  %65 = load double, ptr %9, align 8, !tbaa !11
  br label %66

66:                                               ; preds = %64, %62
  %67 = phi double [ %63, %62 ], [ %65, %64 ]
  store double %67, ptr %9, align 8, !tbaa !11
  br label %68

68:                                               ; preds = %66
  %69 = load i32, ptr %10, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %10, align 4, !tbaa !5
  br label %12, !llvm.loop !13

71:                                               ; preds = %38, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %72 = load i32, ptr %11, align 4
  switch i32 %72, label %75 [
    i32 2, label %73
  ]

73:                                               ; preds = %71
  %74 = load double, ptr %9, align 8, !tbaa !11
  store double %74, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %75

75:                                               ; preds = %73, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %76 = load double, ptr %4, align 8
  ret double %76
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 = { 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 }

!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 = !{!"int", !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"

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZSt8isfinited(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN5nasoq9error_maxEiPdS0_(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %.not25 = icmp sgt i32 %0, 0
  br i1 %.not25, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %14 ]
  %.02226 = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %22, %14 ]
  %4 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = tail call noundef zeroext i1 @_ZSt8isfinited(double noundef %5)
  br i1 %6, label %7, label %.critedge

7:                                                ; preds = %.lr.ph
  %8 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = tail call noundef zeroext i1 @_ZSt8isfinited(double noundef %9)
  br i1 %10, label %11, label %.critedge

11:                                               ; preds = %7
  %12 = load double, ptr %8, align 8, !tbaa !5
  %13 = fcmp oeq double %12, 0.000000e+00
  br i1 %13, label %.critedge, label %14

14:                                               ; preds = %11
  %15 = load double, ptr %4, align 8, !tbaa !5
  %16 = fsub double %12, %15
  %17 = tail call noundef double @_ZSt3absd(double noundef %16)
  %18 = load double, ptr %8, align 8, !tbaa !5
  %19 = tail call noundef double @_ZSt3absd(double noundef %18)
  %20 = fdiv double %17, %19
  %21 = fcmp ogt double %20, %.02226
  %22 = select i1 %21, double %20, double %.02226
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %7, %11, %14, %3
  %.1 = phi double [ 0.000000e+00, %3 ], [ %22, %14 ], [ -1.000000e+00, %11 ], [ -1.000000e+00, %7 ], [ -1.000000e+00, %.lr.ph ]
  ret double %.1
}

attributes #0 = { inlinehint 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 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" }

!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: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass