; LLVM IR from niuyishuai/PDCABB :: LAPACK_BLAS/BLAS/SRC (dnrm2)

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

21:                                               ; preds = %3
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = icmp slt i64 %23, 1
  br i1 %24, label %25, label %26

25:                                               ; preds = %21, %3
  store double 0.000000e+00, ptr %13, align 8, !tbaa !11
  br label %125

26:                                               ; preds = %21
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = icmp eq i64 %28, 1
  br i1 %29, label %30, label %46

30:                                               ; preds = %26
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds double, ptr %31, i64 1
  %33 = load double, ptr %32, align 8, !tbaa !11
  %34 = fcmp oge double %33, 0.000000e+00
  br i1 %34, label %35, label %39

35:                                               ; preds = %30
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds double, ptr %36, i64 1
  %38 = load double, ptr %37, align 8, !tbaa !11
  br label %44

39:                                               ; preds = %30
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds double, ptr %40, i64 1
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = fneg double %42
  br label %44

44:                                               ; preds = %39, %35
  %45 = phi double [ %38, %35 ], [ %43, %39 ]
  store double %45, ptr %13, align 8, !tbaa !11
  br label %124

46:                                               ; preds = %26
  store double 0.000000e+00, ptr %14, align 8, !tbaa !11
  store double 1.000000e+00, ptr %12, align 8, !tbaa !11
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = sub nsw i64 %48, 1
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load i64, ptr %50, align 8, !tbaa !9
  %52 = mul nsw i64 %49, %51
  %53 = add nsw i64 %52, 1
  store i64 %53, ptr %7, align 8, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i64, ptr %54, align 8, !tbaa !9
  store i64 %55, ptr %8, align 8, !tbaa !9
  store i64 1, ptr %11, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %115, %46
  %57 = load i64, ptr %8, align 8, !tbaa !9
  %58 = icmp slt i64 %57, 0
  br i1 %58, label %59, label %64

59:                                               ; preds = %56
  %60 = load i64, ptr %11, align 8, !tbaa !9
  %61 = load i64, ptr %7, align 8, !tbaa !9
  %62 = icmp sge i64 %60, %61
  %63 = zext i1 %62 to i32
  br label %69

64:                                               ; preds = %56
  %65 = load i64, ptr %11, align 8, !tbaa !9
  %66 = load i64, ptr %7, align 8, !tbaa !9
  %67 = icmp sle i64 %65, %66
  %68 = zext i1 %67 to i32
  br label %69

69:                                               ; preds = %64, %59
  %70 = phi i32 [ %63, %59 ], [ %68, %64 ]
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %119

72:                                               ; preds = %69
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = load i64, ptr %11, align 8, !tbaa !9
  %75 = getelementptr inbounds double, ptr %73, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !11
  %77 = fcmp une double %76, 0.000000e+00
  br i1 %77, label %78, label %114

78:                                               ; preds = %72
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load i64, ptr %11, align 8, !tbaa !9
  %81 = getelementptr inbounds double, ptr %79, i64 %80
  %82 = load double, ptr %81, align 8, !tbaa !11
  store double %82, ptr %10, align 8, !tbaa !11
  %83 = load double, ptr %10, align 8, !tbaa !11
  %84 = fcmp oge double %83, 0.000000e+00
  br i1 %84, label %85, label %87

85:                                               ; preds = %78
  %86 = load double, ptr %10, align 8, !tbaa !11
  br label %90

87:                                               ; preds = %78
  %88 = load double, ptr %10, align 8, !tbaa !11
  %89 = fneg double %88
  br label %90

90:                                               ; preds = %87, %85
  %91 = phi double [ %86, %85 ], [ %89, %87 ]
  store double %91, ptr %15, align 8, !tbaa !11
  %92 = load double, ptr %14, align 8, !tbaa !11
  %93 = load double, ptr %15, align 8, !tbaa !11
  %94 = fcmp olt double %92, %93
  br i1 %94, label %95, label %105

95:                                               ; preds = %90
  %96 = load double, ptr %14, align 8, !tbaa !11
  %97 = load double, ptr %15, align 8, !tbaa !11
  %98 = fdiv double %96, %97
  store double %98, ptr %10, align 8, !tbaa !11
  %99 = load double, ptr %12, align 8, !tbaa !11
  %100 = load double, ptr %10, align 8, !tbaa !11
  %101 = load double, ptr %10, align 8, !tbaa !11
  %102 = fmul double %100, %101
  %103 = call double @llvm.fmuladd.f64(double %99, double %102, double 1.000000e+00)
  store double %103, ptr %12, align 8, !tbaa !11
  %104 = load double, ptr %15, align 8, !tbaa !11
  store double %104, ptr %14, align 8, !tbaa !11
  br label %113

105:                                              ; preds = %90
  %106 = load double, ptr %15, align 8, !tbaa !11
  %107 = load double, ptr %14, align 8, !tbaa !11
  %108 = fdiv double %106, %107
  store double %108, ptr %10, align 8, !tbaa !11
  %109 = load double, ptr %10, align 8, !tbaa !11
  %110 = load double, ptr %10, align 8, !tbaa !11
  %111 = load double, ptr %12, align 8, !tbaa !11
  %112 = call double @llvm.fmuladd.f64(double %109, double %110, double %111)
  store double %112, ptr %12, align 8, !tbaa !11
  br label %113

113:                                              ; preds = %105, %95
  br label %114

114:                                              ; preds = %113, %72
  br label %115

115:                                              ; preds = %114
  %116 = load i64, ptr %8, align 8, !tbaa !9
  %117 = load i64, ptr %11, align 8, !tbaa !9
  %118 = add nsw i64 %117, %116
  store i64 %118, ptr %11, align 8, !tbaa !9
  br label %56, !llvm.loop !13

119:                                              ; preds = %69
  %120 = load double, ptr %14, align 8, !tbaa !11
  %121 = load double, ptr %12, align 8, !tbaa !11
  %122 = call double @sqrt(double noundef %121) #4
  %123 = fmul double %120, %122
  store double %123, ptr %13, align 8, !tbaa !11
  br label %124

124:                                              ; preds = %119, %44
  br label %125

125:                                              ; preds = %124, %25
  %126 = load double, ptr %13, align 8, !tbaa !11
  store double %126, ptr %9, align 8, !tbaa !11
  %127 = load double, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, 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 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret double %127
}

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind
declare double @sqrt(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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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 = !{!"long", !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: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local double @f2c_dnrm2(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 -8
  %5 = load i64, ptr %0, align 8, !tbaa !5
  %6 = icmp slt i64 %5, 1
  br i1 %6, label %39, label %7

7:                                                ; preds = %3
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = icmp slt i64 %8, 1
  br i1 %9, label %39, label %10

10:                                               ; preds = %7
  %11 = icmp eq i64 %5, 1
  br i1 %11, label %12, label %.lr.ph.preheader

12:                                               ; preds = %10
  %13 = load double, ptr %1, align 8, !tbaa !9
  %14 = fcmp ult double %13, 0.000000e+00
  %15 = fneg double %13
  %16 = select i1 %14, double %15, double %13
  br label %39

.lr.ph.preheader:                                 ; preds = %10
  %17 = add nsw i64 %5, -1
  %18 = mul nsw i64 %8, %17
  %19 = add nuw nsw i64 %18, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %35
  %.054 = phi double [ %.1, %35 ], [ 0.000000e+00, %.lr.ph.preheader ]
  %.04153 = phi double [ %.142, %35 ], [ 1.000000e+00, %.lr.ph.preheader ]
  %.04352 = phi i64 [ %36, %35 ], [ 1, %.lr.ph.preheader ]
  %20 = getelementptr inbounds double, ptr %4, i64 %.04352
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fcmp une double %21, 0.000000e+00
  br i1 %22, label %23, label %35

23:                                               ; preds = %.lr.ph
  %24 = fcmp oge double %21, 0.000000e+00
  %25 = fneg double %21
  %26 = select i1 %24, double %21, double %25
  %27 = fcmp olt double %.054, %26
  br i1 %27, label %28, label %32

28:                                               ; preds = %23
  %29 = fdiv double %.054, %26
  %30 = fmul double %29, %29
  %31 = tail call double @llvm.fmuladd.f64(double %.04153, double %30, double 1.000000e+00)
  br label %35

32:                                               ; preds = %23
  %33 = fdiv double %26, %.054
  %34 = tail call double @llvm.fmuladd.f64(double %33, double %33, double %.04153)
  br label %35

35:                                               ; preds = %.lr.ph, %32, %28
  %.142 = phi double [ %31, %28 ], [ %34, %32 ], [ %.04153, %.lr.ph ]
  %.1 = phi double [ %26, %28 ], [ %.054, %32 ], [ %.054, %.lr.ph ]
  %36 = add nuw nsw i64 %.04352, %8
  %.not = icmp sgt i64 %36, %19
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %35
  %37 = tail call double @sqrt(double noundef %.142) #3
  %38 = fmul double %.1, %37
  br label %39

39:                                               ; preds = %3, %7, %12, %._crit_edge
  %.040 = phi double [ %16, %12 ], [ %38, %._crit_edge ], [ 0.000000e+00, %7 ], [ 0.000000e+00, %3 ]
  ret double %.040
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

attributes #0 = { 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!"long", !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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass