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

42:                                               ; preds = %74, %7
  %43 = load i64, ptr %22, align 8, !tbaa !9
  %44 = load i64, ptr %19, align 8, !tbaa !9
  %45 = icmp sle i64 %43, %44
  br i1 %45, label %46, label %77

46:                                               ; preds = %42
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i64, ptr %47, align 8, !tbaa !9
  store i64 %48, ptr %20, align 8, !tbaa !9
  store i64 1, ptr %21, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %70, %46
  %50 = load i64, ptr %21, align 8, !tbaa !9
  %51 = load i64, ptr %20, align 8, !tbaa !9
  %52 = icmp sle i64 %50, %51
  br i1 %52, label %53, label %73

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

70:                                               ; preds = %53
  %71 = load i64, ptr %21, align 8, !tbaa !9
  %72 = add nsw i64 %71, 1
  store i64 %72, ptr %21, align 8, !tbaa !9
  br label %49, !llvm.loop !15

73:                                               ; preds = %49
  br label %74

74:                                               ; preds = %73
  %75 = load i64, ptr %22, align 8, !tbaa !9
  %76 = add nsw i64 %75, 1
  store i64 %76, ptr %22, align 8, !tbaa !9
  br label %42, !llvm.loop !17

77:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  ret i32 0
}

; 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 = !{!"long", !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 noundef i32 @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 i64, ptr %3, align 8, !tbaa !5
  %9 = xor i64 %8, -1
  %10 = getelementptr inbounds float, ptr %2, i64 %9
  %11 = load i64, ptr %5, align 8, !tbaa !5
  %12 = xor i64 %11, -1
  %13 = getelementptr inbounds double, ptr %4, i64 %12
  store i64 0, ptr %6, align 8, !tbaa !5
  %14 = load i64, ptr %1, align 8, !tbaa !5
  %.not30 = icmp slt i64 %14, 1
  br i1 %.not30, label %._crit_edge34, label %.lr.ph33

.lr.ph33:                                         ; preds = %7
  %15 = load i64, ptr %0, align 8, !tbaa !5
  %.not2526 = icmp slt i64 %15, 1
  br i1 %.not2526, label %._crit_edge34, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph33
  %min.iters.check = icmp ult i64 %15, 4
  %n.vec = and i64 %15, 9223372036854775804
  %ind.end = or disjoint i64 %n.vec, 1
  %cmp.n = icmp eq i64 %15, %n.vec
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %._crit_edge
  %.031 = phi i64 [ %28, %._crit_edge ], [ 1, %.lr.ph.preheader ]
  %16 = mul nsw i64 %.031, %8
  %invariant.gep = getelementptr float, ptr %10, i64 %16
  %17 = mul nsw i64 %.031, %11
  %invariant.gep28 = getelementptr double, ptr %13, i64 %17
  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
  %18 = getelementptr float, ptr %invariant.gep, i64 %offset.idx
  %19 = getelementptr i8, ptr %18, i64 8
  %wide.load = load <2 x float>, ptr %18, align 4, !tbaa !9
  %wide.load37 = load <2 x float>, ptr %19, align 4, !tbaa !9
  %20 = fpext <2 x float> %wide.load to <2 x double>
  %21 = fpext <2 x float> %wide.load37 to <2 x double>
  %22 = getelementptr double, ptr %invariant.gep28, i64 %offset.idx
  %23 = getelementptr i8, ptr %22, i64 16
  store <2 x double> %20, ptr %22, align 8, !tbaa !11
  store <2 x double> %21, ptr %23, align 8, !tbaa !11
  %index.next = add nuw i64 %index, 4
  %24 = icmp eq i64 %index.next, %n.vec
  br i1 %24, 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
  %.02427.ph = phi i64 [ 1, %.lr.ph ], [ %ind.end, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.02427 = phi i64 [ %27, %scalar.ph ], [ %.02427.ph, %scalar.ph.preheader ]
  %gep = getelementptr float, ptr %invariant.gep, i64 %.02427
  %25 = load float, ptr %gep, align 4, !tbaa !9
  %26 = fpext float %25 to double
  %gep29 = getelementptr double, ptr %invariant.gep28, i64 %.02427
  store double %26, ptr %gep29, align 8, !tbaa !11
  %27 = add nuw i64 %.02427, 1
  %exitcond.not = icmp eq i64 %.02427, %15
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %scalar.ph, %middle.block
  %28 = add nuw i64 %.031, 1
  %exitcond36.not = icmp eq i64 %.031, %14
  br i1 %exitcond36.not, label %._crit_edge34, label %.lr.ph, !llvm.loop !18

._crit_edge34:                                    ; preds = %._crit_edge, %.lr.ph33, %7
  ret i32 0
}

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 = !{!"long", !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: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass