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

; 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"

@.str = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @dla_lin_berr_(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr 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 ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = 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 ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %24, i32 -1
  store ptr %25, ptr %12, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i32, ptr %26, align 4, !tbaa !9
  store i32 %27, ptr %13, align 4, !tbaa !9
  %28 = load i32, ptr %13, align 4, !tbaa !9
  %29 = mul nsw i32 %28, 1
  %30 = add nsw i32 1, %29
  store i32 %30, ptr %14, align 4, !tbaa !9
  %31 = load i32, ptr %14, align 4, !tbaa !9
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = sext i32 %31 to i64
  %34 = sub i64 0, %33
  %35 = getelementptr inbounds double, ptr %32, i64 %34
  store ptr %35, ptr %11, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i32, ptr %36, align 4, !tbaa !9
  store i32 %37, ptr %15, align 4, !tbaa !9
  %38 = load i32, ptr %15, align 4, !tbaa !9
  %39 = mul nsw i32 %38, 1
  %40 = add nsw i32 1, %39
  store i32 %40, ptr %16, align 4, !tbaa !9
  %41 = load i32, ptr %16, align 4, !tbaa !9
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = sext i32 %41 to i64
  %44 = sub i64 0, %43
  %45 = getelementptr inbounds double, ptr %42, i64 %44
  store ptr %45, ptr %10, align 8, !tbaa !5
  %46 = call double @dlamch_(ptr noundef @.str)
  store double %46, ptr %20, align 8, !tbaa !11
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  %50 = sitofp i32 %49 to double
  %51 = load double, ptr %20, align 8, !tbaa !11
  %52 = fmul double %50, %51
  store double %52, ptr %20, align 8, !tbaa !11
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load i32, ptr %53, align 4, !tbaa !9
  store i32 %54, ptr %17, align 4, !tbaa !9
  store i32 1, ptr %22, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %135, %6
  %56 = load i32, ptr %22, align 4, !tbaa !9
  %57 = load i32, ptr %17, align 4, !tbaa !9
  %58 = icmp sle i32 %56, %57
  br i1 %58, label %59, label %138

59:                                               ; preds = %55
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = load i32, ptr %22, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %60, i64 %62
  store double 0.000000e+00, ptr %63, align 8, !tbaa !11
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load i32, ptr %64, align 4, !tbaa !9
  store i32 %65, ptr %18, align 4, !tbaa !9
  store i32 1, ptr %21, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %131, %59
  %67 = load i32, ptr %21, align 4, !tbaa !9
  %68 = load i32, ptr %18, align 4, !tbaa !9
  %69 = icmp sle i32 %67, %68
  br i1 %69, label %70, label %134

70:                                               ; preds = %66
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = load i32, ptr %21, align 4, !tbaa !9
  %73 = load i32, ptr %22, align 4, !tbaa !9
  %74 = load i32, ptr %13, align 4, !tbaa !9
  %75 = mul nsw i32 %73, %74
  %76 = add nsw i32 %72, %75
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds double, ptr %71, i64 %77
  %79 = load double, ptr %78, align 8, !tbaa !11
  %80 = fcmp une double %79, 0.000000e+00
  br i1 %80, label %81, label %130

81:                                               ; preds = %70
  %82 = load double, ptr %20, align 8, !tbaa !11
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = load i32, ptr %21, align 4, !tbaa !9
  %85 = load i32, ptr %22, align 4, !tbaa !9
  %86 = load i32, ptr %15, align 4, !tbaa !9
  %87 = mul nsw i32 %85, %86
  %88 = add nsw i32 %84, %87
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds double, ptr %83, i64 %89
  %91 = load double, ptr %90, align 8, !tbaa !11
  store double %91, ptr %19, align 8, !tbaa !11
  %92 = load double, ptr %19, align 8, !tbaa !11
  %93 = fcmp oge double %92, 0.000000e+00
  br i1 %93, label %94, label %96

94:                                               ; preds = %81
  %95 = load double, ptr %19, align 8, !tbaa !11
  br label %99

96:                                               ; preds = %81
  %97 = load double, ptr %19, align 8, !tbaa !11
  %98 = fneg double %97
  br label %99

99:                                               ; preds = %96, %94
  %100 = phi double [ %95, %94 ], [ %98, %96 ]
  %101 = fadd double %82, %100
  %102 = load ptr, ptr %11, align 8, !tbaa !5
  %103 = load i32, ptr %21, align 4, !tbaa !9
  %104 = load i32, ptr %22, align 4, !tbaa !9
  %105 = load i32, ptr %13, align 4, !tbaa !9
  %106 = mul nsw i32 %104, %105
  %107 = add nsw i32 %103, %106
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds double, ptr %102, i64 %108
  %110 = load double, ptr %109, align 8, !tbaa !11
  %111 = fdiv double %101, %110
  store double %111, ptr %23, align 8, !tbaa !11
  %112 = load ptr, ptr %12, align 8, !tbaa !5
  %113 = load i32, ptr %22, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds double, ptr %112, i64 %114
  %116 = load double, ptr %115, align 8, !tbaa !11
  store double %116, ptr %19, align 8, !tbaa !11
  %117 = load double, ptr %19, align 8, !tbaa !11
  %118 = load double, ptr %23, align 8, !tbaa !11
  %119 = fcmp oge double %117, %118
  br i1 %119, label %120, label %122

120:                                              ; preds = %99
  %121 = load double, ptr %19, align 8, !tbaa !11
  br label %124

122:                                              ; preds = %99
  %123 = load double, ptr %23, align 8, !tbaa !11
  br label %124

124:                                              ; preds = %122, %120
  %125 = phi double [ %121, %120 ], [ %123, %122 ]
  %126 = load ptr, ptr %12, align 8, !tbaa !5
  %127 = load i32, ptr %22, align 4, !tbaa !9
  %128 = sext i32 %127 to i64
  %129 = getelementptr inbounds double, ptr %126, i64 %128
  store double %125, ptr %129, align 8, !tbaa !11
  br label %130

130:                                              ; preds = %124, %70
  br label %131

131:                                              ; preds = %130
  %132 = load i32, ptr %21, align 4, !tbaa !9
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %21, align 4, !tbaa !9
  br label %66, !llvm.loop !13

134:                                              ; preds = %66
  br label %135

135:                                              ; preds = %134
  %136 = load i32, ptr %22, align 4, !tbaa !9
  %137 = add nsw i32 %136, 1
  store i32 %137, ptr %22, align 4, !tbaa !9
  br label %55, !llvm.loop !15

138:                                              ; preds = %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret void
}

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

declare double @dlamch_(ptr noundef) #2

; 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 = { 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"}
!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"

@.str = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @dla_lin_berr_(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = getelementptr inbounds i8, ptr %5, i64 -8
  %8 = load i32, ptr %0, align 4, !tbaa !5
  %narrow = xor i32 %8, -1
  %9 = sext i32 %narrow to i64
  %10 = getelementptr inbounds double, ptr %4, i64 %9
  %11 = getelementptr inbounds double, ptr %3, i64 %9
  %12 = tail call double @dlamch_(ptr noundef nonnull @.str) #3
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  %15 = sitofp i32 %14 to double
  %16 = fmul double %12, %15
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %.not49 = icmp slt i32 %17, 1
  br i1 %.not49, label %._crit_edge53, label %.lr.ph52

.lr.ph52:                                         ; preds = %6
  %18 = load i32, ptr %0, align 4, !tbaa !5
  %.not4647 = icmp slt i32 %18, 1
  br i1 %.not4647, label %.lr.ph52.split.us.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph52
  %19 = add nuw i32 %18, 1
  %20 = sext i32 %8 to i64
  %21 = add nuw i32 %17, 1
  %wide.trip.count59 = zext i32 %21 to i64
  %wide.trip.count = zext i32 %19 to i64
  br label %.lr.ph

.lr.ph52.split.us.preheader:                      ; preds = %.lr.ph52
  %22 = zext nneg i32 %17 to i64
  %23 = shl nuw nsw i64 %22, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %5, i8 0, i64 %23, i1 false), !tbaa !9
  br label %._crit_edge53

.lr.ph:                                           ; preds = %.lr.ph.preheader, %._crit_edge
  %indvars.iv56 = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next57, %._crit_edge ]
  %24 = getelementptr inbounds double, ptr %7, i64 %indvars.iv56
  store double 0.000000e+00, ptr %24, align 8, !tbaa !9
  %25 = mul nsw i64 %indvars.iv56, %20
  br label %26

26:                                               ; preds = %.lr.ph, %42
  %27 = phi double [ 0.000000e+00, %.lr.ph ], [ %43, %42 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %42 ]
  %28 = add nsw i64 %indvars.iv, %25
  %29 = getelementptr inbounds double, ptr %10, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !9
  %31 = fcmp une double %30, 0.000000e+00
  br i1 %31, label %32, label %42

32:                                               ; preds = %26
  %33 = getelementptr inbounds double, ptr %11, i64 %28
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = fcmp oge double %34, 0.000000e+00
  %36 = fneg double %34
  %37 = select i1 %35, double %34, double %36
  %38 = fadd double %16, %37
  %39 = fdiv double %38, %30
  %40 = fcmp oge double %27, %39
  %41 = select i1 %40, double %27, double %39
  store double %41, ptr %24, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %26, %32
  %43 = phi double [ %27, %26 ], [ %41, %32 ]
  %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 %._crit_edge, label %26, !llvm.loop !11

._crit_edge:                                      ; preds = %42
  %indvars.iv.next57 = add nuw nsw i64 %indvars.iv56, 1
  %exitcond60.not = icmp eq i64 %indvars.iv.next57, %wide.trip.count59
  br i1 %exitcond60.not, label %._crit_edge53, label %.lr.ph, !llvm.loop !13

._crit_edge53:                                    ; preds = %._crit_edge, %.lr.ph52.split.us.preheader, %6
  ret void
}

declare double @dlamch_(ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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"}
!13 = distinct !{!13, !12}


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