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

; 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.doublecomplex = type { double, double }

; Function Attrs: nounwind uwtable
define dso_local i32 @zlassq_(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca double, align 8
  %15 = alloca i64, align 8
  %16 = alloca double, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.doublecomplex, ptr %17, i32 -1
  store ptr %18, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = icmp sgt i64 %20, 0
  br i1 %21, label %22, label %156

22:                                               ; preds = %5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = sub nsw i64 %24, 1
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = mul nsw i64 %25, %27
  %29 = add nsw i64 %28, 1
  store i64 %29, ptr %11, align 8, !tbaa !9
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load i64, ptr %30, align 8, !tbaa !9
  store i64 %31, ptr %12, align 8, !tbaa !9
  store i64 1, ptr %15, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %151, %22
  %33 = load i64, ptr %12, align 8, !tbaa !9
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %35, label %40

35:                                               ; preds = %32
  %36 = load i64, ptr %15, align 8, !tbaa !9
  %37 = load i64, ptr %11, align 8, !tbaa !9
  %38 = icmp sge i64 %36, %37
  %39 = zext i1 %38 to i32
  br label %45

40:                                               ; preds = %32
  %41 = load i64, ptr %15, align 8, !tbaa !9
  %42 = load i64, ptr %11, align 8, !tbaa !9
  %43 = icmp sle i64 %41, %42
  %44 = zext i1 %43 to i32
  br label %45

45:                                               ; preds = %40, %35
  %46 = phi i32 [ %39, %35 ], [ %44, %40 ]
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %155

48:                                               ; preds = %45
  %49 = load i64, ptr %15, align 8, !tbaa !9
  store i64 %49, ptr %13, align 8, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i64, ptr %13, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.doublecomplex, ptr %50, i64 %51
  %53 = getelementptr inbounds %struct.doublecomplex, ptr %52, i32 0, i32 0
  %54 = load double, ptr %53, align 8, !tbaa !11
  %55 = fcmp une double %54, 0.000000e+00
  br i1 %55, label %56, label %101

56:                                               ; preds = %48
  %57 = load i64, ptr %15, align 8, !tbaa !9
  store i64 %57, ptr %13, align 8, !tbaa !9
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i64, ptr %13, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.doublecomplex, ptr %58, i64 %59
  %61 = getelementptr inbounds %struct.doublecomplex, ptr %60, i32 0, i32 0
  %62 = load double, ptr %61, align 8, !tbaa !11
  store double %62, ptr %14, align 8, !tbaa !14
  %63 = load double, ptr %14, align 8, !tbaa !14
  %64 = fcmp oge double %63, 0.000000e+00
  br i1 %64, label %65, label %67

65:                                               ; preds = %56
  %66 = load double, ptr %14, align 8, !tbaa !14
  br label %70

67:                                               ; preds = %56
  %68 = load double, ptr %14, align 8, !tbaa !14
  %69 = fneg double %68
  br label %70

70:                                               ; preds = %67, %65
  %71 = phi double [ %66, %65 ], [ %69, %67 ]
  store double %71, ptr %16, align 8, !tbaa !14
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = load double, ptr %72, align 8, !tbaa !14
  %74 = load double, ptr %16, align 8, !tbaa !14
  %75 = fcmp olt double %73, %74
  br i1 %75, label %76, label %90

76:                                               ; preds = %70
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load double, ptr %77, align 8, !tbaa !14
  %79 = load double, ptr %16, align 8, !tbaa !14
  %80 = fdiv double %78, %79
  store double %80, ptr %14, align 8, !tbaa !14
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = load double, ptr %81, align 8, !tbaa !14
  %83 = load double, ptr %14, align 8, !tbaa !14
  %84 = load double, ptr %14, align 8, !tbaa !14
  %85 = fmul double %83, %84
  %86 = call double @llvm.fmuladd.f64(double %82, double %85, double 1.000000e+00)
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  store double %86, ptr %87, align 8, !tbaa !14
  %88 = load double, ptr %16, align 8, !tbaa !14
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  store double %88, ptr %89, align 8, !tbaa !14
  br label %100

90:                                               ; preds = %70
  %91 = load double, ptr %16, align 8, !tbaa !14
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = load double, ptr %92, align 8, !tbaa !14
  %94 = fdiv double %91, %93
  store double %94, ptr %14, align 8, !tbaa !14
  %95 = load double, ptr %14, align 8, !tbaa !14
  %96 = load double, ptr %14, align 8, !tbaa !14
  %97 = load ptr, ptr %10, align 8, !tbaa !5
  %98 = load double, ptr %97, align 8, !tbaa !14
  %99 = call double @llvm.fmuladd.f64(double %95, double %96, double %98)
  store double %99, ptr %97, align 8, !tbaa !14
  br label %100

100:                                              ; preds = %90, %76
  br label %101

101:                                              ; preds = %100, %48
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = load i64, ptr %15, align 8, !tbaa !9
  %104 = getelementptr inbounds %struct.doublecomplex, ptr %102, i64 %103
  %105 = call double @d_imag(ptr noundef %104)
  %106 = fcmp une double %105, 0.000000e+00
  br i1 %106, label %107, label %150

107:                                              ; preds = %101
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  %109 = load i64, ptr %15, align 8, !tbaa !9
  %110 = getelementptr inbounds %struct.doublecomplex, ptr %108, i64 %109
  %111 = call double @d_imag(ptr noundef %110)
  store double %111, ptr %14, align 8, !tbaa !14
  %112 = load double, ptr %14, align 8, !tbaa !14
  %113 = fcmp oge double %112, 0.000000e+00
  br i1 %113, label %114, label %116

114:                                              ; preds = %107
  %115 = load double, ptr %14, align 8, !tbaa !14
  br label %119

116:                                              ; preds = %107
  %117 = load double, ptr %14, align 8, !tbaa !14
  %118 = fneg double %117
  br label %119

119:                                              ; preds = %116, %114
  %120 = phi double [ %115, %114 ], [ %118, %116 ]
  store double %120, ptr %16, align 8, !tbaa !14
  %121 = load ptr, ptr %9, align 8, !tbaa !5
  %122 = load double, ptr %121, align 8, !tbaa !14
  %123 = load double, ptr %16, align 8, !tbaa !14
  %124 = fcmp olt double %122, %123
  br i1 %124, label %125, label %139

125:                                              ; preds = %119
  %126 = load ptr, ptr %9, align 8, !tbaa !5
  %127 = load double, ptr %126, align 8, !tbaa !14
  %128 = load double, ptr %16, align 8, !tbaa !14
  %129 = fdiv double %127, %128
  store double %129, ptr %14, align 8, !tbaa !14
  %130 = load ptr, ptr %10, align 8, !tbaa !5
  %131 = load double, ptr %130, align 8, !tbaa !14
  %132 = load double, ptr %14, align 8, !tbaa !14
  %133 = load double, ptr %14, align 8, !tbaa !14
  %134 = fmul double %132, %133
  %135 = call double @llvm.fmuladd.f64(double %131, double %134, double 1.000000e+00)
  %136 = load ptr, ptr %10, align 8, !tbaa !5
  store double %135, ptr %136, align 8, !tbaa !14
  %137 = load double, ptr %16, align 8, !tbaa !14
  %138 = load ptr, ptr %9, align 8, !tbaa !5
  store double %137, ptr %138, align 8, !tbaa !14
  br label %149

139:                                              ; preds = %119
  %140 = load double, ptr %16, align 8, !tbaa !14
  %141 = load ptr, ptr %9, align 8, !tbaa !5
  %142 = load double, ptr %141, align 8, !tbaa !14
  %143 = fdiv double %140, %142
  store double %143, ptr %14, align 8, !tbaa !14
  %144 = load double, ptr %14, align 8, !tbaa !14
  %145 = load double, ptr %14, align 8, !tbaa !14
  %146 = load ptr, ptr %10, align 8, !tbaa !5
  %147 = load double, ptr %146, align 8, !tbaa !14
  %148 = call double @llvm.fmuladd.f64(double %144, double %145, double %147)
  store double %148, ptr %146, align 8, !tbaa !14
  br label %149

149:                                              ; preds = %139, %125
  br label %150

150:                                              ; preds = %149, %101
  br label %151

151:                                              ; preds = %150
  %152 = load i64, ptr %12, align 8, !tbaa !9
  %153 = load i64, ptr %15, align 8, !tbaa !9
  %154 = add nsw i64 %153, %152
  store i64 %154, ptr %15, align 8, !tbaa !9
  br label %32, !llvm.loop !15

155:                                              ; preds = %45
  br label %156

156:                                              ; preds = %155, %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

declare double @d_imag(ptr noundef) #3

; 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { "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 #4 = { 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 8}
!13 = !{!"double", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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.doublecomplex = type { double, double }

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @zlassq_(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %1, i64 -16
  %7 = load i64, ptr %0, align 8, !tbaa !5
  %8 = icmp sgt i64 %7, 0
  br i1 %8, label %9, label %.loopexit

9:                                                ; preds = %5
  %10 = add nsw i64 %7, -1
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = mul nsw i64 %11, %10
  %13 = add nsw i64 %12, 1
  %14 = icmp slt i64 %11, 0
  %15 = icmp slt i64 %12, 1
  %16 = icmp sgt i64 %12, -1
  %.in66 = select i1 %14, i1 %15, i1 %16
  br i1 %.in66, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %9, %52
  %.067 = phi i64 [ %53, %52 ], [ 1, %9 ]
  %17 = getelementptr inbounds %struct.doublecomplex, ptr %6, i64 %.067
  %18 = load double, ptr %17, align 8, !tbaa !9
  %19 = fcmp une double %18, 0.000000e+00
  br i1 %19, label %20, label %34

20:                                               ; preds = %.lr.ph
  %21 = fcmp oge double %18, 0.000000e+00
  %22 = fneg double %18
  %23 = select i1 %21, double %18, double %22
  %24 = load double, ptr %3, align 8, !tbaa !12
  %25 = fcmp olt double %24, %23
  %26 = load double, ptr %4, align 8, !tbaa !12
  br i1 %25, label %27, label %31

27:                                               ; preds = %20
  %28 = fdiv double %24, %23
  %29 = fmul double %28, %28
  %30 = tail call double @llvm.fmuladd.f64(double %26, double %29, double 1.000000e+00)
  store double %30, ptr %4, align 8, !tbaa !12
  store double %23, ptr %3, align 8, !tbaa !12
  br label %34

31:                                               ; preds = %20
  %32 = fdiv double %23, %24
  %33 = tail call double @llvm.fmuladd.f64(double %32, double %32, double %26)
  store double %33, ptr %4, align 8, !tbaa !12
  br label %34

34:                                               ; preds = %27, %31, %.lr.ph
  %35 = tail call double @d_imag(ptr noundef nonnull %17) #3
  %36 = fcmp une double %35, 0.000000e+00
  br i1 %36, label %37, label %52

37:                                               ; preds = %34
  %38 = tail call double @d_imag(ptr noundef nonnull %17) #3
  %39 = fcmp oge double %38, 0.000000e+00
  %40 = fneg double %38
  %41 = select i1 %39, double %38, double %40
  %42 = load double, ptr %3, align 8, !tbaa !12
  %43 = fcmp olt double %42, %41
  %44 = load double, ptr %4, align 8, !tbaa !12
  br i1 %43, label %45, label %49

45:                                               ; preds = %37
  %46 = fdiv double %42, %41
  %47 = fmul double %46, %46
  %48 = tail call double @llvm.fmuladd.f64(double %44, double %47, double 1.000000e+00)
  store double %48, ptr %4, align 8, !tbaa !12
  store double %41, ptr %3, align 8, !tbaa !12
  br label %52

49:                                               ; preds = %37
  %50 = fdiv double %41, %42
  %51 = tail call double @llvm.fmuladd.f64(double %50, double %50, double %44)
  store double %51, ptr %4, align 8, !tbaa !12
  br label %52

52:                                               ; preds = %34, %49, %45
  %53 = add nsw i64 %.067, %11
  %54 = icmp sgt i64 %53, %12
  %55 = icmp sle i64 %53, %13
  %.in = select i1 %14, i1 %54, i1 %55
  br i1 %.in, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %52, %9, %5
  ret i32 0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

declare double @d_imag(ptr noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"double", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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