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

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

46:                                               ; preds = %80, %7
  %47 = load i32, ptr %22, align 4, !tbaa !9
  %48 = load i32, ptr %19, align 4, !tbaa !9
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %50, label %83

50:                                               ; preds = %46
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load i32, ptr %51, align 4, !tbaa !9
  store i32 %52, ptr %20, align 4, !tbaa !9
  store i32 1, ptr %21, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %76, %50
  %54 = load i32, ptr %21, align 4, !tbaa !9
  %55 = load i32, ptr %20, align 4, !tbaa !9
  %56 = icmp sle i32 %54, %55
  br i1 %56, label %57, label %79

57:                                               ; preds = %53
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = load i32, ptr %21, align 4, !tbaa !9
  %60 = load i32, ptr %22, align 4, !tbaa !9
  %61 = load i32, ptr %15, align 4, !tbaa !9
  %62 = mul nsw i32 %60, %61
  %63 = add nsw i32 %59, %62
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds float, ptr %58, i64 %64
  %66 = load float, ptr %65, align 4, !tbaa !11
  %67 = fpext float %66 to double
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = load i32, ptr %21, align 4, !tbaa !9
  %70 = load i32, ptr %22, align 4, !tbaa !9
  %71 = load i32, ptr %17, align 4, !tbaa !9
  %72 = mul nsw i32 %70, %71
  %73 = add nsw i32 %69, %72
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds double, ptr %68, i64 %74
  store double %67, ptr %75, align 8, !tbaa !13
  br label %76

76:                                               ; preds = %57
  %77 = load i32, ptr %21, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %21, align 4, !tbaa !9
  br label %53, !llvm.loop !15

79:                                               ; preds = %53
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %22, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %22, align 4, !tbaa !9
  br label %46, !llvm.loop !17

83:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  ret void
}

; 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 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 = { 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 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @slag2d_(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 float, ptr %2, i64 %9
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %narrow25 = xor i32 %11, -1
  %12 = sext i32 %narrow25 to i64
  %13 = getelementptr inbounds double, ptr %4, i64 %12
  store i32 0, ptr %6, align 4, !tbaa !5
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %.not29 = icmp slt i32 %14, 1
  br i1 %.not29, label %._crit_edge33, label %.lr.ph32

.lr.ph32:                                         ; preds = %7
  %15 = load i32, ptr %0, align 4, !tbaa !5
  %.not2627 = icmp slt i32 %15, 1
  br i1 %.not2627, label %._crit_edge33, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph32
  %16 = add nuw i32 %15, 1
  %17 = sext i32 %8 to i64
  %18 = sext i32 %11 to i64
  %19 = add nuw i32 %14, 1
  %wide.trip.count39 = zext i32 %19 to i64
  %wide.trip.count = zext i32 %16 to i64
  %20 = zext nneg i32 %15 to i64
  %min.iters.check = icmp ult i32 %15, 4
  %n.vec = and i64 %20, 2147483644
  %ind.end = or disjoint i64 %n.vec, 1
  %cmp.n = icmp eq i64 %n.vec, %20
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %._crit_edge
  %indvars.iv36 = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next37, %._crit_edge ]
  %21 = mul nsw i64 %indvars.iv36, %17
  %22 = mul nsw i64 %indvars.iv36, %18
  %invariant.gep = getelementptr float, ptr %10, i64 %21
  %invariant.gep41 = getelementptr double, ptr %13, i64 %22
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.lr.ph, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.lr.ph ]
  %offset.idx = or disjoint i64 %index, 1
  %23 = getelementptr float, ptr %invariant.gep, i64 %offset.idx
  %24 = getelementptr i8, ptr %23, i64 8
  %wide.load = load <2 x float>, ptr %23, align 4, !tbaa !9
  %wide.load43 = load <2 x float>, ptr %24, align 4, !tbaa !9
  %25 = fpext <2 x float> %wide.load to <2 x double>
  %26 = fpext <2 x float> %wide.load43 to <2 x double>
  %27 = getelementptr double, ptr %invariant.gep41, i64 %offset.idx
  %28 = getelementptr i8, ptr %27, i64 16
  store <2 x double> %25, ptr %27, align 8, !tbaa !11
  store <2 x double> %26, ptr %28, align 8, !tbaa !11
  %index.next = add nuw i64 %index, 4
  %29 = icmp eq i64 %index.next, %n.vec
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph ], [ %ind.end, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv
  %30 = load float, ptr %gep, align 4, !tbaa !9
  %31 = fpext float %30 to double
  %gep42 = getelementptr double, ptr %invariant.gep41, i64 %indvars.iv
  store double %31, ptr %gep42, align 8, !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 %scalar.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %scalar.ph, %middle.block
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond40.not = icmp eq i64 %indvars.iv.next37, %wide.trip.count39
  br i1 %exitcond40.not, label %._crit_edge33, label %.lr.ph, !llvm.loop !18

._crit_edge33:                                    ; preds = %._crit_edge, %.lr.ph32, %7
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(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" }

!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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !14, !16, !15}
!18 = distinct !{!18, !14}


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