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

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

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

20:                                               ; preds = %3
  %21 = load float, ptr %10, align 4, !tbaa !9
  %22 = fpext float %21 to double
  store double %22, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %93

23:                                               ; preds = %3
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = icmp eq i64 %25, 1
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  br label %70

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = mul nsw i64 %30, %32
  store i64 %33, ptr %12, align 8, !tbaa !11
  %34 = load i64, ptr %12, align 8, !tbaa !11
  store i64 %34, ptr %8, align 8, !tbaa !11
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load i64, ptr %35, align 8, !tbaa !11
  store i64 %36, ptr %9, align 8, !tbaa !11
  store i64 1, ptr %11, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %62, %28
  %38 = load i64, ptr %9, align 8, !tbaa !11
  %39 = icmp slt i64 %38, 0
  br i1 %39, label %40, label %45

40:                                               ; preds = %37
  %41 = load i64, ptr %11, align 8, !tbaa !11
  %42 = load i64, ptr %8, align 8, !tbaa !11
  %43 = icmp sge i64 %41, %42
  %44 = zext i1 %43 to i32
  br label %50

45:                                               ; preds = %37
  %46 = load i64, ptr %11, align 8, !tbaa !11
  %47 = load i64, ptr %8, align 8, !tbaa !11
  %48 = icmp sle i64 %46, %47
  %49 = zext i1 %48 to i32
  br label %50

50:                                               ; preds = %45, %40
  %51 = phi i32 [ %44, %40 ], [ %49, %45 ]
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %66

53:                                               ; preds = %50
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i64, ptr %11, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.complex, ptr %54, i64 %55
  %57 = call double @c_abs(ptr noundef %56)
  %58 = load float, ptr %13, align 4, !tbaa !9
  %59 = fpext float %58 to double
  %60 = fadd double %59, %57
  %61 = fptrunc double %60 to float
  store float %61, ptr %13, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %53
  %63 = load i64, ptr %9, align 8, !tbaa !11
  %64 = load i64, ptr %11, align 8, !tbaa !11
  %65 = add nsw i64 %64, %63
  store i64 %65, ptr %11, align 8, !tbaa !11
  br label %37, !llvm.loop !13

66:                                               ; preds = %50
  %67 = load float, ptr %13, align 4, !tbaa !9
  store float %67, ptr %10, align 4, !tbaa !9
  %68 = load float, ptr %10, align 4, !tbaa !9
  %69 = fpext float %68 to double
  store double %69, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %93

70:                                               ; preds = %27
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load i64, ptr %71, align 8, !tbaa !11
  store i64 %72, ptr %9, align 8, !tbaa !11
  store i64 1, ptr %11, align 8, !tbaa !11
  br label %73

73:                                               ; preds = %86, %70
  %74 = load i64, ptr %11, align 8, !tbaa !11
  %75 = load i64, ptr %9, align 8, !tbaa !11
  %76 = icmp sle i64 %74, %75
  br i1 %76, label %77, label %89

77:                                               ; preds = %73
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load i64, ptr %11, align 8, !tbaa !11
  %80 = getelementptr inbounds %struct.complex, ptr %78, i64 %79
  %81 = call double @c_abs(ptr noundef %80)
  %82 = load float, ptr %13, align 4, !tbaa !9
  %83 = fpext float %82 to double
  %84 = fadd double %83, %81
  %85 = fptrunc double %84 to float
  store float %85, ptr %13, align 4, !tbaa !9
  br label %86

86:                                               ; preds = %77
  %87 = load i64, ptr %11, align 8, !tbaa !11
  %88 = add nsw i64 %87, 1
  store i64 %88, ptr %11, align 8, !tbaa !11
  br label %73, !llvm.loop !15

89:                                               ; preds = %73
  %90 = load float, ptr %13, align 4, !tbaa !9
  store float %90, ptr %10, align 4, !tbaa !9
  %91 = load float, ptr %10, align 4, !tbaa !9
  %92 = fpext float %91 to double
  store double %92, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %93

93:                                               ; preds = %89, %66, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %94 = load double, ptr %4, align 8
  ret double %94
}

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

declare double @c_abs(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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

; Function Attrs: nounwind uwtable
define dso_local double @scsum1_(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 -8
  %5 = load i64, ptr %0, align 8, !tbaa !5
  %6 = icmp slt i64 %5, 1
  br i1 %6, label %._crit_edge, label %7

7:                                                ; preds = %3
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = icmp eq i64 %8, 1
  br i1 %9, label %.lr.ph40, label %10

10:                                               ; preds = %7
  %11 = mul nsw i64 %8, %5
  %12 = icmp slt i64 %8, 0
  %13 = icmp slt i64 %11, 2
  %14 = icmp sgt i64 %11, 0
  %.in34 = select i1 %12, i1 %13, i1 %14
  br i1 %.in34, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %10, %.lr.ph
  %.036 = phi float [ %19, %.lr.ph ], [ 0.000000e+00, %10 ]
  %.03035 = phi i64 [ %20, %.lr.ph ], [ 1, %10 ]
  %15 = getelementptr inbounds %struct.complex, ptr %4, i64 %.03035
  %16 = tail call double @c_abs(ptr noundef nonnull %15) #2
  %17 = fpext float %.036 to double
  %18 = fadd double %16, %17
  %19 = fptrunc double %18 to float
  %20 = add nsw i64 %.03035, %8
  %21 = icmp sge i64 %20, %11
  %22 = icmp sle i64 %20, %11
  %.in = select i1 %12, i1 %21, i1 %22
  br i1 %.in, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %23 = fpext float %19 to double
  br label %._crit_edge

.lr.ph40:                                         ; preds = %7, %.lr.ph40
  %.139 = phi float [ %28, %.lr.ph40 ], [ 0.000000e+00, %7 ]
  %.13138 = phi i64 [ %29, %.lr.ph40 ], [ 1, %7 ]
  %24 = getelementptr inbounds %struct.complex, ptr %4, i64 %.13138
  %25 = tail call double @c_abs(ptr noundef nonnull %24) #2
  %26 = fpext float %.139 to double
  %27 = fadd double %25, %26
  %28 = fptrunc double %27 to float
  %29 = add nuw i64 %.13138, 1
  %exitcond.not = icmp eq i64 %.13138, %5
  br i1 %exitcond.not, label %._crit_edge41, label %.lr.ph40, !llvm.loop !11

._crit_edge41:                                    ; preds = %.lr.ph40
  %30 = fpext float %28 to double
  br label %._crit_edge

._crit_edge:                                      ; preds = %10, %._crit_edge.loopexit, %3, %._crit_edge41
  %.029 = phi double [ %30, %._crit_edge41 ], [ 0.000000e+00, %3 ], [ 0.000000e+00, %10 ], [ %23, %._crit_edge.loopexit ]
  ret double %.029
}

declare double @c_abs(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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass