; LLVM IR from niuyishuai/PDCABB :: LAPACK_BLAS/BLAS/SRC (dzasum)

; 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 @f2c_dzasum(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 double, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca double, align 8
  %13 = 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
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.doublecomplex, ptr %14, i32 -1
  store ptr %15, ptr %6, align 8, !tbaa !5
  store double 0.000000e+00, ptr %9, align 8, !tbaa !9
  store double 0.000000e+00, ptr %12, align 8, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = icmp sle i64 %17, 0
  br i1 %18, label %23, label %19

19:                                               ; preds = %3
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = icmp sle i64 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %19, %3
  %24 = load double, ptr %9, align 8, !tbaa !9
  store double %24, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %74

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

29:                                               ; preds = %25
  br label %54

30:                                               ; preds = %25
  store i64 1, ptr %11, align 8, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %31, align 8, !tbaa !11
  store i64 %32, ptr %8, align 8, !tbaa !11
  store i64 1, ptr %10, align 8, !tbaa !11
  br label %33

33:                                               ; preds = %48, %30
  %34 = load i64, ptr %10, align 8, !tbaa !11
  %35 = load i64, ptr %8, align 8, !tbaa !11
  %36 = icmp sle i64 %34, %35
  br i1 %36, label %37, label %51

37:                                               ; preds = %33
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i64, ptr %11, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.doublecomplex, ptr %38, i64 %39
  %41 = call double @dcabs1_(ptr noundef %40)
  %42 = load double, ptr %12, align 8, !tbaa !9
  %43 = fadd double %42, %41
  store double %43, ptr %12, align 8, !tbaa !9
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i64, ptr %44, align 8, !tbaa !11
  %46 = load i64, ptr %11, align 8, !tbaa !11
  %47 = add nsw i64 %46, %45
  store i64 %47, ptr %11, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %37
  %49 = load i64, ptr %10, align 8, !tbaa !11
  %50 = add nsw i64 %49, 1
  store i64 %50, ptr %10, align 8, !tbaa !11
  br label %33, !llvm.loop !13

51:                                               ; preds = %33
  %52 = load double, ptr %12, align 8, !tbaa !9
  store double %52, ptr %9, align 8, !tbaa !9
  %53 = load double, ptr %9, align 8, !tbaa !9
  store double %53, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %74

54:                                               ; preds = %29
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i64, ptr %55, align 8, !tbaa !11
  store i64 %56, ptr %8, align 8, !tbaa !11
  store i64 1, ptr %10, align 8, !tbaa !11
  br label %57

57:                                               ; preds = %68, %54
  %58 = load i64, ptr %10, align 8, !tbaa !11
  %59 = load i64, ptr %8, align 8, !tbaa !11
  %60 = icmp sle i64 %58, %59
  br i1 %60, label %61, label %71

61:                                               ; preds = %57
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load i64, ptr %10, align 8, !tbaa !11
  %64 = getelementptr inbounds %struct.doublecomplex, ptr %62, i64 %63
  %65 = call double @dcabs1_(ptr noundef %64)
  %66 = load double, ptr %12, align 8, !tbaa !9
  %67 = fadd double %66, %65
  store double %67, ptr %12, align 8, !tbaa !9
  br label %68

68:                                               ; preds = %61
  %69 = load i64, ptr %10, align 8, !tbaa !11
  %70 = add nsw i64 %69, 1
  store i64 %70, ptr %10, align 8, !tbaa !11
  br label %57, !llvm.loop !15

71:                                               ; preds = %57
  %72 = load double, ptr %12, align 8, !tbaa !9
  store double %72, ptr %9, align 8, !tbaa !9
  %73 = load double, ptr %9, align 8, !tbaa !9
  store double %73, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %74

74:                                               ; preds = %71, %51, %23
  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
  %75 = load double, ptr %4, align 8
  ret double %75
}

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

declare double @dcabs1_(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 @f2c_dzasum(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 slt i64 %8, 1
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %7
  %11 = icmp eq i64 %8, 1
  br i1 %11, label %.lr.ph41, label %.lr.ph

.lr.ph:                                           ; preds = %10, %.lr.ph
  %.037 = phi double [ %14, %.lr.ph ], [ 0.000000e+00, %10 ]
  %.02536 = phi i64 [ %16, %.lr.ph ], [ 1, %10 ]
  %.02635 = phi i64 [ %17, %.lr.ph ], [ 1, %10 ]
  %12 = getelementptr inbounds %struct.doublecomplex, ptr %4, i64 %.02536
  %13 = tail call double @dcabs1_(ptr noundef nonnull %12) #2
  %14 = fadd double %.037, %13
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = add nsw i64 %15, %.02536
  %17 = add nuw i64 %.02635, 1
  %exitcond.not = icmp eq i64 %.02635, %5
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !9

.lr.ph41:                                         ; preds = %10, %.lr.ph41
  %.140 = phi double [ %20, %.lr.ph41 ], [ 0.000000e+00, %10 ]
  %.12739 = phi i64 [ %21, %.lr.ph41 ], [ 1, %10 ]
  %18 = getelementptr inbounds %struct.doublecomplex, ptr %4, i64 %.12739
  %19 = tail call double @dcabs1_(ptr noundef nonnull %18) #2
  %20 = fadd double %.140, %19
  %21 = add nuw i64 %.12739, 1
  %exitcond45.not = icmp eq i64 %.12739, %5
  br i1 %exitcond45.not, label %.loopexit, label %.lr.ph41, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph41, %3, %7
  %.028 = phi double [ 0.000000e+00, %7 ], [ 0.000000e+00, %3 ], [ %20, %.lr.ph41 ], [ %14, %.lr.ph ]
  ret double %.028
}

declare double @dcabs1_(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,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass