; LLVM IR from sympiler/nasoq :: src/QP/nasoq_utils.ll (ZN5nasoq14max_min_vectorEiPdRdS1_S1_S1_d)

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5nasoq14max_min_vectorEiPdRdS1_S1_S1_d(i32 noundef %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5, double noundef %6) #3 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca double, align 8
  %15 = alloca i32, align 4
  %16 = alloca double, align 8
  %17 = alloca i32, align 4
  %18 = alloca double, align 8
  store i32 %0, ptr %8, align 4, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !9
  store double %6, ptr %14, align 8, !tbaa !11
  %19 = load ptr, ptr %13, align 8, !tbaa !9
  store double 0.000000e+00, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %12, align 8, !tbaa !9
  store double 0.000000e+00, ptr %20, align 8, !tbaa !11
  %21 = call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #4
  %22 = fneg double %21
  %23 = load ptr, ptr %10, align 8, !tbaa !9
  store double %22, ptr %23, align 8, !tbaa !11
  %24 = call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #4
  %25 = load ptr, ptr %11, align 8, !tbaa !9
  store double %24, ptr %25, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %66, %7
  %27 = load i32, ptr %15, align 4, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %69

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %32 = load ptr, ptr %9, align 8, !tbaa !9
  %33 = load i32, ptr %15, 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 = call noundef double @_ZSt3absd(double noundef %36)
  store double %37, ptr %16, align 8, !tbaa !11
  %38 = load double, ptr %16, align 8, !tbaa !11
  %39 = load ptr, ptr %10, align 8, !tbaa !9
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = fcmp ogt double %38, %40
  br i1 %41, label %42, label %45

42:                                               ; preds = %31
  %43 = load double, ptr %16, align 8, !tbaa !11
  %44 = load ptr, ptr %10, align 8, !tbaa !9
  store double %43, ptr %44, align 8, !tbaa !11
  br label %58

45:                                               ; preds = %31
  %46 = load double, ptr %16, align 8, !tbaa !11
  %47 = load ptr, ptr %11, align 8, !tbaa !9
  %48 = load double, ptr %47, align 8, !tbaa !11
  %49 = fcmp olt double %46, %48
  br i1 %49, label %50, label %57

50:                                               ; preds = %45
  %51 = load double, ptr %16, align 8, !tbaa !11
  %52 = load double, ptr %14, align 8, !tbaa !11
  %53 = fcmp ogt double %51, %52
  br i1 %53, label %54, label %57

54:                                               ; preds = %50
  %55 = load double, ptr %16, align 8, !tbaa !11
  %56 = load ptr, ptr %11, align 8, !tbaa !9
  store double %55, ptr %56, align 8, !tbaa !11
  br label %57

57:                                               ; preds = %54, %50, %45
  br label %58

58:                                               ; preds = %57, %42
  %59 = load double, ptr %16, align 8, !tbaa !11
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = sitofp i32 %60 to double
  %62 = fdiv double %59, %61
  %63 = load ptr, ptr %12, align 8, !tbaa !9
  %64 = load double, ptr %63, align 8, !tbaa !11
  %65 = fadd double %64, %62
  store double %65, ptr %63, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %66

66:                                               ; preds = %58
  %67 = load i32, ptr %15, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %15, align 4, !tbaa !5
  br label %26, !llvm.loop !13

69:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 0, ptr %17, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %94, %69
  %71 = load i32, ptr %17, align 4, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = icmp slt i32 %71, %72
  br i1 %73, label %75, label %74

74:                                               ; preds = %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %97

75:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %76 = load ptr, ptr %9, align 8, !tbaa !9
  %77 = load i32, ptr %17, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds double, ptr %76, i64 %78
  %80 = load double, ptr %79, align 8, !tbaa !11
  %81 = call noundef double @_ZSt3absd(double noundef %80)
  %82 = load ptr, ptr %12, align 8, !tbaa !9
  %83 = load double, ptr %82, align 8, !tbaa !11
  %84 = fsub double %81, %83
  store double %84, ptr %18, align 8, !tbaa !11
  %85 = load double, ptr %18, align 8, !tbaa !11
  %86 = load double, ptr %18, align 8, !tbaa !11
  %87 = fmul double %85, %86
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = sitofp i32 %88 to double
  %90 = fdiv double %87, %89
  %91 = load ptr, ptr %13, align 8, !tbaa !9
  %92 = load double, ptr %91, align 8, !tbaa !11
  %93 = fadd double %92, %90
  store double %93, ptr %91, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %94

94:                                               ; preds = %75
  %95 = load i32, ptr %17, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %17, align 4, !tbaa !5
  br label %70, !llvm.loop !15

97:                                               ; preds = %74
  ret i32 0
}

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 = { 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 #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"}
!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 dso_local noundef double @_ZNSt14numeric_limitsIdE3maxEv() local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN5nasoq14max_min_vectorEiPdRdS1_S1_S1_d(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef nonnull align 8 dereferenceable(8) %2, ptr nocapture noundef nonnull align 8 dereferenceable(8) %3, ptr nocapture noundef nonnull align 8 dereferenceable(8) %4, ptr nocapture noundef nonnull align 8 dereferenceable(8) %5, double noundef %6) local_unnamed_addr #0 {
  store double 0.000000e+00, ptr %5, align 8, !tbaa !5
  store double 0.000000e+00, ptr %4, align 8, !tbaa !5
  %8 = tail call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #2
  %9 = fneg double %8
  store double %9, ptr %2, align 8, !tbaa !5
  %10 = tail call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #2
  store double %10, ptr %3, align 8, !tbaa !5
  %11 = icmp sgt i32 %0, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %7
  %12 = uitofp nneg i32 %0 to double
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %14

.preheader:                                       ; preds = %24
  br i1 %11, label %.lr.ph37, label %._crit_edge

.lr.ph37:                                         ; preds = %.preheader
  %13 = uitofp nneg i32 %0 to double
  %wide.trip.count42 = zext nneg i32 %0 to i64
  br label %28

14:                                               ; preds = %.lr.ph, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %24 ]
  %15 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %16 = load double, ptr %15, align 8, !tbaa !5
  %17 = tail call noundef double @_ZSt3absd(double noundef %16)
  %18 = load double, ptr %2, align 8, !tbaa !5
  %19 = fcmp ogt double %17, %18
  br i1 %19, label %.sink.split, label %20

20:                                               ; preds = %14
  %21 = load double, ptr %3, align 8, !tbaa !5
  %22 = fcmp olt double %17, %21
  %23 = fcmp ogt double %17, %6
  %or.cond = and i1 %23, %22
  br i1 %or.cond, label %.sink.split, label %24

.sink.split:                                      ; preds = %20, %14
  %.sink = phi ptr [ %2, %14 ], [ %3, %20 ]
  store double %17, ptr %.sink, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %.sink.split, %20
  %25 = fdiv double %17, %12
  %26 = load double, ptr %4, align 8, !tbaa !5
  %27 = fadd double %25, %26
  store double %27, ptr %4, align 8, !tbaa !5
  %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 %.preheader, label %14, !llvm.loop !9

._crit_edge:                                      ; preds = %28, %7, %.preheader
  ret i32 0

28:                                               ; preds = %.lr.ph37, %28
  %indvars.iv39 = phi i64 [ 0, %.lr.ph37 ], [ %indvars.iv.next40, %28 ]
  %29 = getelementptr inbounds double, ptr %1, i64 %indvars.iv39
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = tail call noundef double @_ZSt3absd(double noundef %30)
  %32 = load double, ptr %4, align 8, !tbaa !5
  %33 = fsub double %31, %32
  %34 = fmul double %33, %33
  %35 = fdiv double %34, %13
  %36 = load double, ptr %5, align 8, !tbaa !5
  %37 = fadd double %36, %35
  store double %37, ptr %5, align 8, !tbaa !5
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next40, %wide.trip.count42
  br i1 %exitcond43.not, label %._crit_edge, label %28, !llvm.loop !11
}

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 = { 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 = { 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"}
!11 = distinct !{!11, !10}


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