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

; 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 [2 x i8], align 1

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

48:                                               ; preds = %109, %7
  %49 = load i32, ptr %23, align 4, !tbaa !9
  %50 = load i32, ptr %19, align 4, !tbaa !9
  %51 = icmp sle i32 %49, %50
  br i1 %51, label %52, label %112

52:                                               ; preds = %48
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i32, ptr %53, align 4, !tbaa !9
  store i32 %54, ptr %20, align 4, !tbaa !9
  store i32 1, ptr %22, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %105, %52
  %56 = load i32, ptr %22, align 4, !tbaa !9
  %57 = load i32, ptr %20, align 4, !tbaa !9
  %58 = icmp sle i32 %56, %57
  br i1 %58, label %59, label %108

59:                                               ; preds = %55
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = load i32, ptr %22, align 4, !tbaa !9
  %62 = load i32, ptr %23, align 4, !tbaa !9
  %63 = load i32, ptr %17, align 4, !tbaa !9
  %64 = mul nsw i32 %62, %63
  %65 = add nsw i32 %61, %64
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds double, ptr %60, i64 %66
  %68 = load double, ptr %67, align 8, !tbaa !11
  %69 = load double, ptr %21, align 8, !tbaa !11
  %70 = fneg double %69
  %71 = fcmp olt double %68, %70
  br i1 %71, label %84, label %72

72:                                               ; preds = %59
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = load i32, ptr %22, align 4, !tbaa !9
  %75 = load i32, ptr %23, align 4, !tbaa !9
  %76 = load i32, ptr %17, align 4, !tbaa !9
  %77 = mul nsw i32 %75, %76
  %78 = add nsw i32 %74, %77
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds double, ptr %73, i64 %79
  %81 = load double, ptr %80, align 8, !tbaa !11
  %82 = load double, ptr %21, align 8, !tbaa !11
  %83 = fcmp ogt double %81, %82
  br i1 %83, label %84, label %86

84:                                               ; preds = %72, %59
  %85 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 1, ptr %85, align 4, !tbaa !9
  br label %114

86:                                               ; preds = %72
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = load i32, ptr %22, align 4, !tbaa !9
  %89 = load i32, ptr %23, align 4, !tbaa !9
  %90 = load i32, ptr %17, align 4, !tbaa !9
  %91 = mul nsw i32 %89, %90
  %92 = add nsw i32 %88, %91
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds double, ptr %87, i64 %93
  %95 = load double, ptr %94, align 8, !tbaa !11
  %96 = fptrunc double %95 to float
  %97 = load ptr, ptr %12, align 8, !tbaa !5
  %98 = load i32, ptr %22, align 4, !tbaa !9
  %99 = load i32, ptr %23, align 4, !tbaa !9
  %100 = load i32, ptr %15, align 4, !tbaa !9
  %101 = mul nsw i32 %99, %100
  %102 = add nsw i32 %98, %101
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds float, ptr %97, i64 %103
  store float %96, ptr %104, align 4, !tbaa !13
  br label %105

105:                                              ; preds = %86
  %106 = load i32, ptr %22, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %22, align 4, !tbaa !9
  br label %55, !llvm.loop !15

108:                                              ; preds = %55
  br label %109

109:                                              ; preds = %108
  %110 = load i32, ptr %23, align 4, !tbaa !9
  %111 = add nsw i32 %110, 1
  store i32 %111, ptr %23, align 4, !tbaa !9
  br label %48, !llvm.loop !17

112:                                              ; preds = %48
  %113 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 0, ptr %113, align 4, !tbaa !9
  br label %114

114:                                              ; preds = %112, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, 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
  ret void
}

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

declare float @slamch_(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 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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 [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @dlag2s_(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef readonly %5, ptr nocapture noundef writeonly %6) local_unnamed_addr #0 {
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %narrow = xor i32 %8, -1
  %9 = sext i32 %narrow to i64
  %10 = getelementptr inbounds double, ptr %2, i64 %9
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %narrow37 = xor i32 %11, -1
  %12 = sext i32 %narrow37 to i64
  %13 = getelementptr inbounds float, ptr %4, i64 %12
  %14 = tail call float @slamch_(ptr noundef nonnull @.str) #2
  %15 = fpext float %14 to double
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %.not42 = icmp slt i32 %16, 1
  br i1 %.not42, label %.loopexit, label %.lr.ph45

.lr.ph45:                                         ; preds = %7
  %17 = load i32, ptr %0, align 4, !tbaa !5
  %.not3840 = icmp slt i32 %17, 1
  %18 = fneg double %15
  br i1 %.not3840, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph45
  %19 = add nuw i32 %17, 1
  %20 = sext i32 %8 to i64
  %21 = sext i32 %11 to i64
  %22 = add nuw i32 %16, 1
  %wide.trip.count52 = zext i32 %22 to i64
  %wide.trip.count = zext i32 %19 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %._crit_edge
  %indvars.iv49 = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next50, %._crit_edge ]
  %23 = mul nsw i64 %indvars.iv49, %20
  %24 = mul nsw i64 %indvars.iv49, %21
  %invariant.gep = getelementptr double, ptr %10, i64 %23
  %invariant.gep55 = getelementptr float, ptr %13, i64 %24
  br label %25

25:                                               ; preds = %.lr.ph, %29
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %29 ]
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv
  %26 = load double, ptr %gep, align 8, !tbaa !9
  %27 = fcmp olt double %26, %18
  %28 = fcmp ogt double %26, %15
  %or.cond = or i1 %27, %28
  br i1 %or.cond, label %.loopexit, label %29

29:                                               ; preds = %25
  %30 = fptrunc double %26 to float
  %gep56 = getelementptr float, ptr %invariant.gep55, i64 %indvars.iv
  store float %30, ptr %gep56, align 4, !tbaa !11
  %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 %25, !llvm.loop !13

._crit_edge:                                      ; preds = %29
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond53.not = icmp eq i64 %indvars.iv.next50, %wide.trip.count52
  br i1 %exitcond53.not, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %._crit_edge, %25, %.lr.ph45, %7
  %storemerge = phi i32 [ 0, %7 ], [ 0, %.lr.ph45 ], [ 1, %25 ], [ 0, %._crit_edge ]
  store i32 %storemerge, ptr %6, align 4, !tbaa !5
  ret void
}

declare float @slamch_(ptr noundef) local_unnamed_addr #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 = { "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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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