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

; 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 double @dzsum1_(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 double, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca double, align 8
  %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 8, 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 8, ptr %13) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.doublecomplex, ptr %15, i32 -1
  store ptr %16, ptr %6, align 8, !tbaa !5
  store double 0.000000e+00, ptr %10, align 8, !tbaa !9
  store double 0.000000e+00, ptr %13, align 8, !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 %22

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

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

26:                                               ; preds = %22
  br label %66

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

36:                                               ; preds = %59, %27
  %37 = load i64, ptr %9, align 8, !tbaa !11
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %39, label %44

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

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

49:                                               ; preds = %44, %39
  %50 = phi i32 [ %43, %39 ], [ %48, %44 ]
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %63

52:                                               ; preds = %49
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i64, ptr %11, align 8, !tbaa !11
  %55 = getelementptr inbounds %struct.doublecomplex, ptr %53, i64 %54
  %56 = call double @z_abs(ptr noundef %55)
  %57 = load double, ptr %13, align 8, !tbaa !9
  %58 = fadd double %57, %56
  store double %58, ptr %13, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %52
  %60 = load i64, ptr %9, align 8, !tbaa !11
  %61 = load i64, ptr %11, align 8, !tbaa !11
  %62 = add nsw i64 %61, %60
  store i64 %62, ptr %11, align 8, !tbaa !11
  br label %36, !llvm.loop !13

63:                                               ; preds = %49
  %64 = load double, ptr %13, align 8, !tbaa !9
  store double %64, ptr %10, align 8, !tbaa !9
  %65 = load double, ptr %10, align 8, !tbaa !9
  store double %65, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %86

66:                                               ; preds = %26
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load i64, ptr %67, align 8, !tbaa !11
  store i64 %68, ptr %9, align 8, !tbaa !11
  store i64 1, ptr %11, align 8, !tbaa !11
  br label %69

69:                                               ; preds = %80, %66
  %70 = load i64, ptr %11, align 8, !tbaa !11
  %71 = load i64, ptr %9, align 8, !tbaa !11
  %72 = icmp sle i64 %70, %71
  br i1 %72, label %73, label %83

73:                                               ; preds = %69
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load i64, ptr %11, align 8, !tbaa !11
  %76 = getelementptr inbounds %struct.doublecomplex, ptr %74, i64 %75
  %77 = call double @z_abs(ptr noundef %76)
  %78 = load double, ptr %13, align 8, !tbaa !9
  %79 = fadd double %78, %77
  store double %79, ptr %13, align 8, !tbaa !9
  br label %80

80:                                               ; preds = %73
  %81 = load i64, ptr %11, align 8, !tbaa !11
  %82 = add nsw i64 %81, 1
  store i64 %82, ptr %11, align 8, !tbaa !11
  br label %69, !llvm.loop !15

83:                                               ; preds = %69
  %84 = load double, ptr %13, align 8, !tbaa !9
  store double %84, ptr %10, align 8, !tbaa !9
  %85 = load double, ptr %10, align 8, !tbaa !9
  store double %85, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %86

86:                                               ; preds = %83, %63, %20
  call void @llvm.lifetime.end.p0(i64 8, 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 8, 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
  %87 = load double, ptr %4, align 8
  ret double %87
}

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

declare double @z_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 = !{!"double", !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.doublecomplex = type { double, double }

; Function Attrs: nounwind uwtable
define dso_local double @dzsum1_(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 -16
  %5 = load i64, ptr %0, align 8, !tbaa !5
  %6 = icmp slt i64 %5, 1
  br i1 %6, label %.loopexit, 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.ph41, 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
  %.in35 = select i1 %12, i1 %13, i1 %14
  br i1 %.in35, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %10, %.lr.ph
  %.037 = phi double [ %17, %.lr.ph ], [ 0.000000e+00, %10 ]
  %.03036 = phi i64 [ %18, %.lr.ph ], [ 1, %10 ]
  %15 = getelementptr inbounds %struct.doublecomplex, ptr %4, i64 %.03036
  %16 = tail call double @z_abs(ptr noundef nonnull %15) #2
  %17 = fadd double %.037, %16
  %18 = add nsw i64 %.03036, %8
  %19 = icmp sge i64 %18, %11
  %20 = icmp sle i64 %18, %11
  %.in = select i1 %12, i1 %19, i1 %20
  br i1 %.in, label %.lr.ph, label %.loopexit, !llvm.loop !9

.lr.ph41:                                         ; preds = %7, %.lr.ph41
  %.140 = phi double [ %23, %.lr.ph41 ], [ 0.000000e+00, %7 ]
  %.13139 = phi i64 [ %24, %.lr.ph41 ], [ 1, %7 ]
  %21 = getelementptr inbounds %struct.doublecomplex, ptr %4, i64 %.13139
  %22 = tail call double @z_abs(ptr noundef nonnull %21) #2
  %23 = fadd double %.140, %22
  %24 = add nuw i64 %.13139, 1
  %exitcond.not = icmp eq i64 %.13139, %5
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph41, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph41, %10, %3
  %.029 = phi double [ 0.000000e+00, %3 ], [ 0.000000e+00, %10 ], [ %23, %.lr.ph41 ], [ %17, %.lr.ph ]
  ret double %.029
}

declare double @z_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