; LLVM IR from sympiler/nasoq :: src/QP/nasoq_utils.ll (ZN5nasoq21max_min_sparse_matrixEPKNS_12sympiler_CSCERdS3_S3_S3_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"

%"struct.nasoq::sympiler_CSC" = type { i64, i64, i64, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5nasoq21max_min_sparse_matrixEPKNS_12sympiler_CSCERdS3_S3_S3_d(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(8) %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, double noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca double, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca double, align 8
  %16 = alloca i32, align 4
  %17 = alloca double, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  store double %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.nasoq::sympiler_CSC", ptr %18, i32 0, i32 2
  %20 = load i64, ptr %19, align 8, !tbaa !11
  store i64 %20, ptr %13, align 8, !tbaa !15
  %21 = call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #4
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  store double %21, ptr %22, align 8, !tbaa !9
  %23 = call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #4
  %24 = fneg double %23
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  store double %24, ptr %25, align 8, !tbaa !9
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  store double 0.000000e+00, ptr %26, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !16
  br label %27

27:                                               ; preds = %70, %6
  %28 = load i32, ptr %14, align 4, !tbaa !16
  %29 = sext i32 %28 to i64
  %30 = load i64, ptr %13, align 8, !tbaa !15
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %73

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.nasoq::sympiler_CSC", ptr %34, i32 0, i32 6
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = load i32, ptr %14, align 4, !tbaa !16
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %36, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !9
  %41 = call noundef double @_ZSt3absd(double noundef %40)
  store double %41, ptr %15, align 8, !tbaa !9
  %42 = load double, ptr %15, align 8, !tbaa !9
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = fcmp ogt double %42, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %33
  %47 = load double, ptr %15, align 8, !tbaa !9
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  store double %47, ptr %48, align 8, !tbaa !9
  br label %62

49:                                               ; preds = %33
  %50 = load double, ptr %15, align 8, !tbaa !9
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load double, ptr %51, align 8, !tbaa !9
  %53 = fcmp olt double %50, %52
  br i1 %53, label %54, label %61

54:                                               ; preds = %49
  %55 = load double, ptr %15, align 8, !tbaa !9
  %56 = load double, ptr %12, align 8, !tbaa !9
  %57 = fcmp ogt double %55, %56
  br i1 %57, label %58, label %61

58:                                               ; preds = %54
  %59 = load double, ptr %15, align 8, !tbaa !9
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  store double %59, ptr %60, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %58, %54, %49
  br label %62

62:                                               ; preds = %61, %46
  %63 = load double, ptr %15, align 8, !tbaa !9
  %64 = load i64, ptr %13, align 8, !tbaa !15
  %65 = uitofp i64 %64 to double
  %66 = fdiv double %63, %65
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load double, ptr %67, align 8, !tbaa !9
  %69 = fadd double %68, %66
  store double %69, ptr %67, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %70

70:                                               ; preds = %62
  %71 = load i32, ptr %14, align 4, !tbaa !16
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %14, align 4, !tbaa !16
  br label %27, !llvm.loop !18

73:                                               ; preds = %32
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  store double 0.000000e+00, ptr %74, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  store i32 0, ptr %16, align 4, !tbaa !16
  br label %75

75:                                               ; preds = %102, %73
  %76 = load i32, ptr %16, align 4, !tbaa !16
  %77 = sext i32 %76 to i64
  %78 = load i64, ptr %13, align 8, !tbaa !15
  %79 = icmp ult i64 %77, %78
  br i1 %79, label %81, label %80

80:                                               ; preds = %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %105

81:                                               ; preds = %75
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %"struct.nasoq::sympiler_CSC", ptr %82, i32 0, i32 6
  %84 = load ptr, ptr %83, align 8, !tbaa !17
  %85 = load i32, ptr %16, align 4, !tbaa !16
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds double, ptr %84, i64 %86
  %88 = load double, ptr %87, align 8, !tbaa !9
  %89 = call noundef double @_ZSt3absd(double noundef %88)
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  %91 = load double, ptr %90, align 8, !tbaa !9
  %92 = fsub double %89, %91
  store double %92, ptr %17, align 8, !tbaa !9
  %93 = load double, ptr %17, align 8, !tbaa !9
  %94 = load double, ptr %17, align 8, !tbaa !9
  %95 = fmul double %93, %94
  %96 = load i64, ptr %13, align 8, !tbaa !15
  %97 = uitofp i64 %96 to double
  %98 = fdiv double %95, %97
  %99 = load ptr, ptr %11, align 8, !tbaa !5
  %100 = load double, ptr %99, align 8, !tbaa !9
  %101 = fadd double %100, %98
  store double %101, ptr %99, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  br label %102

102:                                              ; preds = %81
  %103 = load i32, ptr %16, align 4, !tbaa !16
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %16, align 4, !tbaa !16
  br label %75, !llvm.loop !20

105:                                              ; preds = %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  ret i32 1
}

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

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"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 = !{!12, !13, i64 16}
!12 = !{!"_ZTSN5nasoq12sympiler_CSCE", !13, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !14, i64 64, !14, i64 68, !14, i64 72, !14, i64 76, !14, i64 80, !14, i64 84}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!12, !6, i64 48}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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
define dso_local noundef i32 @_ZN5nasoq21max_min_sparse_matrixEPKNS_12sympiler_CSCERdS3_S3_S3_d(ptr nocapture noundef readonly %0, ptr nocapture noundef nonnull align 8 dereferenceable(8) %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, double noundef %5) local_unnamed_addr #0 {
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = tail call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #2
  store double %9, ptr %2, align 8, !tbaa !12
  %10 = tail call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #2
  %11 = fneg double %10
  store double %11, ptr %1, align 8, !tbaa !12
  store double 0.000000e+00, ptr %3, align 8, !tbaa !12
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %6
  store double 0.000000e+00, ptr %4, align 8, !tbaa !12
  br label %._crit_edge42

.lr.ph:                                           ; preds = %6
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = uitofp i64 %8 to double
  br label %16

.lr.ph41:                                         ; preds = %27
  store double 0.000000e+00, ptr %4, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  %15 = uitofp i64 %8 to double
  br label %31

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

23:                                               ; preds = %16
  %24 = load double, ptr %2, align 8, !tbaa !12
  %25 = fcmp olt double %20, %24
  %26 = fcmp ogt double %20, %5
  %or.cond = and i1 %26, %25
  br i1 %or.cond, label %.sink.split, label %27

.sink.split:                                      ; preds = %23, %16
  %.sink = phi ptr [ %1, %16 ], [ %2, %23 ]
  store double %20, ptr %.sink, align 8, !tbaa !12
  br label %27

27:                                               ; preds = %.sink.split, %23
  %28 = fdiv double %20, %13
  %29 = load double, ptr %3, align 8, !tbaa !12
  %30 = fadd double %28, %29
  store double %30, ptr %3, align 8, !tbaa !12
  %indvars.iv.next = add nuw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %8
  br i1 %exitcond.not, label %.lr.ph41, label %16, !llvm.loop !15

._crit_edge42:                                    ; preds = %31, %._crit_edge.thread
  ret i32 1

31:                                               ; preds = %.lr.ph41, %31
  %indvars.iv45 = phi i64 [ 0, %.lr.ph41 ], [ %indvars.iv.next46, %31 ]
  %32 = load ptr, ptr %14, align 8, !tbaa !14
  %33 = getelementptr inbounds double, ptr %32, i64 %indvars.iv45
  %34 = load double, ptr %33, align 8, !tbaa !12
  %35 = tail call noundef double @_ZSt3absd(double noundef %34)
  %36 = load double, ptr %3, align 8, !tbaa !12
  %37 = fsub double %35, %36
  %38 = fmul double %37, %37
  %39 = fdiv double %38, %15
  %40 = load double, ptr %4, align 8, !tbaa !12
  %41 = fadd double %40, %39
  store double %41, ptr %4, align 8, !tbaa !12
  %indvars.iv.next46 = add nuw i64 %indvars.iv45, 1
  %exitcond48.not = icmp eq i64 %indvars.iv.next46, %8
  br i1 %exitcond48.not, label %._crit_edge42, label %31, !llvm.loop !17
}

; 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

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, !7, i64 16}
!6 = !{!"_ZTSN5nasoq12sympiler_CSCE", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !8, i64 0}
!14 = !{!6, !10, i64 48}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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