; LLVM IR from OpenMathLib/OpenBLAS :: lapack-netlib/SRC (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 i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  %15 = alloca { double, double }, align 8
  %16 = alloca { double, double }, align 8
  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 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.doublecomplex, ptr %17, i32 -1
  store ptr %18, 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
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = icmp sle i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %3
  %23 = load double, ptr %10, align 8, !tbaa !9
  store double %23, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %108

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

28:                                               ; preds = %24
  br label %78

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

38:                                               ; preds = %71, %29
  %39 = load i32, ptr %9, align 4, !tbaa !11
  %40 = icmp slt i32 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %38
  %42 = load i32, ptr %11, align 4, !tbaa !11
  %43 = load i32, ptr %8, align 4, !tbaa !11
  %44 = icmp sge i32 %42, %43
  %45 = zext i1 %44 to i32
  br label %51

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

51:                                               ; preds = %46, %41
  %52 = phi i32 [ %45, %41 ], [ %50, %46 ]
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %75

54:                                               ; preds = %51
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load i32, ptr %11, align 4, !tbaa !11
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds %struct.doublecomplex, ptr %55, i64 %57
  %59 = call { double, double } @Cd(ptr noundef %58)
  %60 = extractvalue { double, double } %59, 0
  %61 = extractvalue { double, double } %59, 1
  %62 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 0
  %63 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 1
  store double %60, ptr %62, align 8
  store double %61, ptr %63, align 8
  %64 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 0
  %65 = load double, ptr %64, align 8
  %66 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 1
  %67 = load double, ptr %66, align 8
  %68 = call double @cabs(double noundef %65, double noundef %67) #4
  %69 = load double, ptr %13, align 8, !tbaa !9
  %70 = fadd double %69, %68
  store double %70, ptr %13, align 8, !tbaa !9
  br label %71

71:                                               ; preds = %54
  %72 = load i32, ptr %9, align 4, !tbaa !11
  %73 = load i32, ptr %11, align 4, !tbaa !11
  %74 = add nsw i32 %73, %72
  store i32 %74, ptr %11, align 4, !tbaa !11
  br label %38, !llvm.loop !13

75:                                               ; preds = %51
  %76 = load double, ptr %13, align 8, !tbaa !9
  store double %76, ptr %10, align 8, !tbaa !9
  %77 = load double, ptr %10, align 8, !tbaa !9
  store double %77, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %108

78:                                               ; preds = %28
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load i32, ptr %79, align 4, !tbaa !11
  store i32 %80, ptr %9, align 4, !tbaa !11
  store i32 1, ptr %11, align 4, !tbaa !11
  br label %81

81:                                               ; preds = %102, %78
  %82 = load i32, ptr %11, align 4, !tbaa !11
  %83 = load i32, ptr %9, align 4, !tbaa !11
  %84 = icmp sle i32 %82, %83
  br i1 %84, label %85, label %105

85:                                               ; preds = %81
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = load i32, ptr %11, align 4, !tbaa !11
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds %struct.doublecomplex, ptr %86, i64 %88
  %90 = call { double, double } @Cd(ptr noundef %89)
  %91 = extractvalue { double, double } %90, 0
  %92 = extractvalue { double, double } %90, 1
  %93 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 0
  %94 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 1
  store double %91, ptr %93, align 8
  store double %92, ptr %94, align 8
  %95 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 0
  %96 = load double, ptr %95, align 8
  %97 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 1
  %98 = load double, ptr %97, align 8
  %99 = call double @cabs(double noundef %96, double noundef %98) #4
  %100 = load double, ptr %13, align 8, !tbaa !9
  %101 = fadd double %100, %99
  store double %101, ptr %13, align 8, !tbaa !9
  br label %102

102:                                              ; preds = %85
  %103 = load i32, ptr %11, align 4, !tbaa !11
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %11, align 4, !tbaa !11
  br label %81, !llvm.loop !15

105:                                              ; preds = %81
  %106 = load double, ptr %13, align 8, !tbaa !9
  store double %106, ptr %10, align 8, !tbaa !9
  %107 = load double, ptr %10, align 8, !tbaa !9
  store double %107, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %108

108:                                              ; preds = %105, %75, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %109 = load double, ptr %4, align 8
  ret double %109
}

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

; Function Attrs: nounwind
declare double @cabs(double noundef, double noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden { double, double } @Cd(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 = { nounwind "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 = { inlinehint 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 #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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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 i32, ptr %0, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 1
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %3
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %.lr.ph43.preheader, label %11

.lr.ph43.preheader:                               ; preds = %7
  %10 = add nuw i32 %5, 1
  %wide.trip.count = zext i32 %10 to i64
  br label %.lr.ph43

11:                                               ; preds = %7
  %12 = mul nsw i32 %8, %5
  %13 = icmp slt i32 %8, 0
  %14 = icmp slt i32 %12, 2
  %15 = icmp sgt i32 %12, 0
  %.in37 = select i1 %13, i1 %14, i1 %15
  br i1 %.in37, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %11
  %16 = sext i32 %8 to i64
  %17 = sext i32 %12 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.03139 = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %23, %.lr.ph ]
  %18 = getelementptr inbounds %struct.doublecomplex, ptr %4, i64 %indvars.iv
  %19 = tail call { double, double } @Cd(ptr noundef nonnull %18)
  %20 = extractvalue { double, double } %19, 0
  %21 = extractvalue { double, double } %19, 1
  %22 = tail call double @cabs(double noundef %20, double noundef %21) #3
  %23 = fadd double %.03139, %22
  %indvars.iv.next = add nsw i64 %indvars.iv, %16
  %24 = icmp sge i64 %indvars.iv.next, %17
  %25 = icmp sle i64 %indvars.iv.next, %17
  %.in = select i1 %13, i1 %24, i1 %25
  br i1 %.in, label %.lr.ph, label %.loopexit, !llvm.loop !9

.lr.ph43:                                         ; preds = %.lr.ph43.preheader, %.lr.ph43
  %indvars.iv48 = phi i64 [ 1, %.lr.ph43.preheader ], [ %indvars.iv.next49, %.lr.ph43 ]
  %.142 = phi double [ 0.000000e+00, %.lr.ph43.preheader ], [ %31, %.lr.ph43 ]
  %26 = getelementptr inbounds %struct.doublecomplex, ptr %4, i64 %indvars.iv48
  %27 = tail call { double, double } @Cd(ptr noundef nonnull %26)
  %28 = extractvalue { double, double } %27, 0
  %29 = extractvalue { double, double } %27, 1
  %30 = tail call double @cabs(double noundef %28, double noundef %29) #3
  %31 = fadd double %.142, %30
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next49, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph43, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph43, %11, %3
  %.0 = phi double [ 0.000000e+00, %3 ], [ 0.000000e+00, %11 ], [ %31, %.lr.ph43 ], [ %23, %.lr.ph ]
  ret double %.0
}

; Function Attrs: nofree nounwind
declare double @cabs(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden { double, double } @Cd(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 = { nofree nounwind "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 = { inlinehint 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 #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 = !{!"int", !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