; LLVM IR from niuyishuai/PDCABB :: LAPACK_BLAS/LAPACK (clag2z)

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

%struct.complex = type { float, float }
%struct.doublecomplex = type { double, double }

; Function Attrs: nounwind uwtable
define dso_local i32 @clag2z_(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
  %23 = alloca i64, align 8
  %24 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #2
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  %26 = load i64, ptr %25, align 8, !tbaa !9
  store i64 %26, ptr %15, align 8, !tbaa !9
  %27 = load i64, ptr %15, align 8, !tbaa !9
  %28 = add nsw i64 1, %27
  store i64 %28, ptr %16, align 8, !tbaa !9
  %29 = load i64, ptr %16, align 8, !tbaa !9
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = sub i64 0, %29
  %32 = getelementptr inbounds %struct.complex, ptr %30, i64 %31
  store ptr %32, ptr %10, align 8, !tbaa !5
  %33 = load ptr, ptr %13, align 8, !tbaa !5
  %34 = load i64, ptr %33, align 8, !tbaa !9
  store i64 %34, ptr %17, align 8, !tbaa !9
  %35 = load i64, ptr %17, align 8, !tbaa !9
  %36 = add nsw i64 1, %35
  store i64 %36, ptr %18, align 8, !tbaa !9
  %37 = load i64, ptr %18, align 8, !tbaa !9
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = sub i64 0, %37
  %40 = getelementptr inbounds %struct.doublecomplex, ptr %38, i64 %39
  store ptr %40, ptr %12, align 8, !tbaa !5
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  store i64 0, ptr %41, align 8, !tbaa !9
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i64, ptr %42, align 8, !tbaa !9
  store i64 %43, ptr %19, align 8, !tbaa !9
  store i64 1, ptr %24, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %90, %7
  %45 = load i64, ptr %24, align 8, !tbaa !9
  %46 = load i64, ptr %19, align 8, !tbaa !9
  %47 = icmp sle i64 %45, %46
  br i1 %47, label %48, label %93

48:                                               ; preds = %44
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i64, ptr %49, align 8, !tbaa !9
  store i64 %50, ptr %20, align 8, !tbaa !9
  store i64 1, ptr %23, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %86, %48
  %52 = load i64, ptr %23, align 8, !tbaa !9
  %53 = load i64, ptr %20, align 8, !tbaa !9
  %54 = icmp sle i64 %52, %53
  br i1 %54, label %55, label %89

55:                                               ; preds = %51
  %56 = load i64, ptr %23, align 8, !tbaa !9
  %57 = load i64, ptr %24, align 8, !tbaa !9
  %58 = load i64, ptr %17, align 8, !tbaa !9
  %59 = mul nsw i64 %57, %58
  %60 = add nsw i64 %56, %59
  store i64 %60, ptr %21, align 8, !tbaa !9
  %61 = load i64, ptr %23, align 8, !tbaa !9
  %62 = load i64, ptr %24, align 8, !tbaa !9
  %63 = load i64, ptr %15, align 8, !tbaa !9
  %64 = mul nsw i64 %62, %63
  %65 = add nsw i64 %61, %64
  store i64 %65, ptr %22, align 8, !tbaa !9
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load i64, ptr %22, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.complex, ptr %66, i64 %67
  %69 = getelementptr inbounds %struct.complex, ptr %68, i32 0, i32 0
  %70 = load float, ptr %69, align 4, !tbaa !11
  %71 = fpext float %70 to double
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  %73 = load i64, ptr %21, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.doublecomplex, ptr %72, i64 %73
  %75 = getelementptr inbounds %struct.doublecomplex, ptr %74, i32 0, i32 0
  store double %71, ptr %75, align 8, !tbaa !14
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = load i64, ptr %22, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.complex, ptr %76, i64 %77
  %79 = getelementptr inbounds %struct.complex, ptr %78, i32 0, i32 1
  %80 = load float, ptr %79, align 4, !tbaa !17
  %81 = fpext float %80 to double
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  %83 = load i64, ptr %21, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.doublecomplex, ptr %82, i64 %83
  %85 = getelementptr inbounds %struct.doublecomplex, ptr %84, i32 0, i32 1
  store double %81, ptr %85, align 8, !tbaa !18
  br label %86

86:                                               ; preds = %55
  %87 = load i64, ptr %23, align 8, !tbaa !9
  %88 = add nsw i64 %87, 1
  store i64 %88, ptr %23, align 8, !tbaa !9
  br label %51, !llvm.loop !19

89:                                               ; preds = %51
  br label %90

90:                                               ; preds = %89
  %91 = load i64, ptr %24, align 8, !tbaa !9
  %92 = add nsw i64 %91, 1
  store i64 %92, ptr %24, align 8, !tbaa !9
  br label %44, !llvm.loop !21

93:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #2
  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, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 4}
!13 = !{!"float", !7, i64 0}
!14 = !{!15, !16, i64 0}
!15 = !{!"", !16, i64 0, !16, i64 8}
!16 = !{!"double", !7, i64 0}
!17 = !{!12, !13, i64 4}
!18 = !{!15, !16, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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

%struct.complex = type { float, float }
%struct.doublecomplex = type { double, double }

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef i32 @clag2z_(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 %struct.complex, ptr %2, i64 %9
  %11 = load i64, ptr %5, align 8, !tbaa !5
  %12 = xor i64 %11, -1
  %13 = getelementptr inbounds %struct.doublecomplex, ptr %4, i64 %12
  store i64 0, ptr %6, align 8, !tbaa !5
  %14 = load i64, ptr %1, align 8, !tbaa !5
  %.not36 = icmp slt i64 %14, 1
  br i1 %.not36, label %._crit_edge40, label %.lr.ph39

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

.lr.ph.preheader:                                 ; preds = %.lr.ph39
  %min.iters.check = icmp eq i64 %15, 1
  %n.vec = and i64 %15, 9223372036854775806
  %ind.end = or i64 %15, 1
  %cmp.n = icmp eq i64 %15, %n.vec
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %._crit_edge
  %.037 = phi i64 [ %26, %._crit_edge ], [ 1, %.lr.ph.preheader ]
  %16 = mul nsw i64 %.037, %11
  %17 = mul nsw i64 %.037, %8
  %invariant.gep = getelementptr %struct.complex, ptr %10, i64 %17
  %invariant.gep34 = getelementptr %struct.doublecomplex, ptr %13, i64 %16
  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 %struct.complex, ptr %invariant.gep, i64 %offset.idx
  %wide.vec = load <4 x float>, ptr %18, align 4, !tbaa !9
  %strided.vec = shufflevector <4 x float> %wide.vec, <4 x float> poison, <2 x i32> <i32 0, i32 2>
  %strided.vec43 = shufflevector <4 x float> %wide.vec, <4 x float> poison, <2 x i32> <i32 1, i32 3>
  %19 = fpext <2 x float> %strided.vec to <2 x double>
  %20 = fpext <2 x float> %strided.vec43 to <2 x double>
  %21 = getelementptr %struct.doublecomplex, ptr %invariant.gep34, i64 %offset.idx
  %interleaved.vec = shufflevector <2 x double> %19, <2 x double> %20, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  store <4 x double> %interleaved.vec, ptr %21, align 8, !tbaa !11
  %index.next = add nuw i64 %index, 2
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, 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
  %.03033.ph = phi i64 [ 1, %.lr.ph ], [ %ind.end, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.03033 = phi i64 [ %25, %scalar.ph ], [ %.03033.ph, %scalar.ph.preheader ]
  %gep = getelementptr %struct.complex, ptr %invariant.gep, i64 %.03033
  %gep35 = getelementptr %struct.doublecomplex, ptr %invariant.gep34, i64 %.03033
  %23 = load <2 x float>, ptr %gep, align 4, !tbaa !9
  %24 = fpext <2 x float> %23 to <2 x double>
  store <2 x double> %24, ptr %gep35, align 8, !tbaa !11
  %25 = add nuw i64 %.03033, 1
  %exitcond.not = icmp eq i64 %.03033, %15
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %scalar.ph, %middle.block
  %26 = add nuw i64 %.037, 1
  %exitcond42.not = icmp eq i64 %.037, %14
  br i1 %exitcond42.not, label %._crit_edge40, label %.lr.ph, !llvm.loop !18

._crit_edge40:                                    ; preds = %._crit_edge, %.lr.ph39, %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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass