; LLVM IR from OpenMathLib/OpenBLAS :: lapack-netlib/SRC (dlassq)

; 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: nounwind uwtable
define dso_local void @dlassq_(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds double, ptr %16, i32 -1
  store ptr %17, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %21, label %103

21:                                               ; preds = %5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = sub nsw i32 %23, 1
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = mul nsw i32 %24, %26
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %11, align 4, !tbaa !9
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load i32, ptr %29, align 4, !tbaa !9
  store i32 %30, ptr %12, align 4, !tbaa !9
  store i32 1, ptr %15, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %98, %21
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %34, label %39

34:                                               ; preds = %31
  %35 = load i32, ptr %15, align 4, !tbaa !9
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = icmp sge i32 %35, %36
  %38 = zext i1 %37 to i32
  br label %44

39:                                               ; preds = %31
  %40 = load i32, ptr %15, align 4, !tbaa !9
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = icmp sle i32 %40, %41
  %43 = zext i1 %42 to i32
  br label %44

44:                                               ; preds = %39, %34
  %45 = phi i32 [ %38, %34 ], [ %43, %39 ]
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %102

47:                                               ; preds = %44
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load i32, ptr %15, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %48, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !11
  store double %52, ptr %13, align 8, !tbaa !11
  %53 = load double, ptr %13, align 8, !tbaa !11
  %54 = fcmp oge double %53, 0.000000e+00
  br i1 %54, label %55, label %57

55:                                               ; preds = %47
  %56 = load double, ptr %13, align 8, !tbaa !11
  br label %60

57:                                               ; preds = %47
  %58 = load double, ptr %13, align 8, !tbaa !11
  %59 = fneg double %58
  br label %60

60:                                               ; preds = %57, %55
  %61 = phi double [ %56, %55 ], [ %59, %57 ]
  store double %61, ptr %14, align 8, !tbaa !11
  %62 = load double, ptr %14, align 8, !tbaa !11
  %63 = fcmp ogt double %62, 0.000000e+00
  br i1 %63, label %67, label %64

64:                                               ; preds = %60
  %65 = call i32 @disnan_(ptr noundef %14)
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %97

67:                                               ; preds = %64, %60
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load double, ptr %68, align 8, !tbaa !11
  %70 = load double, ptr %14, align 8, !tbaa !11
  %71 = fcmp olt double %69, %70
  br i1 %71, label %72, label %86

72:                                               ; preds = %67
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = load double, ptr %73, align 8, !tbaa !11
  %75 = load double, ptr %14, align 8, !tbaa !11
  %76 = fdiv double %74, %75
  store double %76, ptr %13, align 8, !tbaa !11
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load double, ptr %77, align 8, !tbaa !11
  %79 = load double, ptr %13, align 8, !tbaa !11
  %80 = load double, ptr %13, align 8, !tbaa !11
  %81 = fmul double %79, %80
  %82 = call double @llvm.fmuladd.f64(double %78, double %81, double 1.000000e+00)
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  store double %82, ptr %83, align 8, !tbaa !11
  %84 = load double, ptr %14, align 8, !tbaa !11
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  store double %84, ptr %85, align 8, !tbaa !11
  br label %96

86:                                               ; preds = %67
  %87 = load double, ptr %14, align 8, !tbaa !11
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  %89 = load double, ptr %88, align 8, !tbaa !11
  %90 = fdiv double %87, %89
  store double %90, ptr %13, align 8, !tbaa !11
  %91 = load double, ptr %13, align 8, !tbaa !11
  %92 = load double, ptr %13, align 8, !tbaa !11
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = load double, ptr %93, align 8, !tbaa !11
  %95 = call double @llvm.fmuladd.f64(double %91, double %92, double %94)
  store double %95, ptr %93, align 8, !tbaa !11
  br label %96

96:                                               ; preds = %86, %72
  br label %97

97:                                               ; preds = %96, %64
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %12, align 4, !tbaa !9
  %100 = load i32, ptr %15, align 4, !tbaa !9
  %101 = add nsw i32 %100, %99
  store i32 %101, ptr %15, align 4, !tbaa !9
  br label %31, !llvm.loop !13

102:                                              ; preds = %44
  br label %103

103:                                              ; preds = %102, %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  ret void
}

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

declare i32 @disnan_(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

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

attributes #0 = { 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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/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"}


; 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: nounwind uwtable
define dso_local void @dlassq_(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %6 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %7 = getelementptr inbounds i8, ptr %1, i64 -8
  %8 = load i32, ptr %0, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %10, label %.loopexit

10:                                               ; preds = %5
  %11 = add nsw i32 %8, -1
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = mul nsw i32 %12, %11
  %14 = icmp slt i32 %12, 0
  %15 = icmp slt i32 %13, 1
  %16 = icmp sgt i32 %13, -1
  %.in31 = select i1 %14, i1 %15, i1 %16
  br i1 %.in31, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %10
  %17 = add nsw i32 %13, 1
  %18 = sext i32 %12 to i64
  %19 = sext i32 %13 to i64
  %20 = sext i32 %17 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %41
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %41 ]
  %21 = getelementptr inbounds double, ptr %7, i64 %indvars.iv
  %22 = load double, ptr %21, align 8, !tbaa !9
  %23 = fcmp oge double %22, 0.000000e+00
  %24 = fneg double %22
  %25 = select i1 %23, double %22, double %24
  store double %25, ptr %6, align 8, !tbaa !9
  %26 = fcmp ogt double %25, 0.000000e+00
  br i1 %26, label %29, label %27

27:                                               ; preds = %.lr.ph
  %28 = call i32 @disnan_(ptr noundef nonnull %6) #4
  %.not = icmp eq i32 %28, 0
  br i1 %.not, label %41, label %._crit_edge

._crit_edge:                                      ; preds = %27
  %.pre = load double, ptr %6, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %._crit_edge, %.lr.ph
  %30 = phi double [ %.pre, %._crit_edge ], [ %25, %.lr.ph ]
  %31 = load double, ptr %3, align 8, !tbaa !9
  %32 = fcmp olt double %31, %30
  %33 = load double, ptr %4, align 8, !tbaa !9
  br i1 %32, label %34, label %38

34:                                               ; preds = %29
  %35 = fdiv double %31, %30
  %36 = fmul double %35, %35
  %37 = call double @llvm.fmuladd.f64(double %33, double %36, double 1.000000e+00)
  store double %37, ptr %4, align 8, !tbaa !9
  store double %30, ptr %3, align 8, !tbaa !9
  br label %41

38:                                               ; preds = %29
  %39 = fdiv double %30, %31
  %40 = call double @llvm.fmuladd.f64(double %39, double %39, double %33)
  store double %40, ptr %4, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %27, %38, %34
  %indvars.iv.next = add nsw i64 %indvars.iv, %18
  %42 = icmp sgt i64 %indvars.iv.next, %19
  %43 = icmp sle i64 %indvars.iv.next, %20
  %.in = select i1 %14, i1 %42, i1 %43
  br i1 %.in, label %.lr.ph, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %41, %10, %5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  ret void
}

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

declare i32 @disnan_(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

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

attributes #0 = { 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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