; LLVM IR from YuchenHHH/Sparse-linear-systems :: Source (cs_norm)

; 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.cs_sparse = type { i64, i64, i64, ptr, ptr, ptr, i64 }

; Function Attrs: nounwind uwtable
define dso_local double @cs_norm(ptr noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store double 0.000000e+00, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %24

14:                                               ; preds = %1
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.cs_sparse, ptr %15, i32 0, i32 6
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = icmp eq i64 %17, -1
  br i1 %18, label %19, label %24

19:                                               ; preds = %14
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.cs_sparse, ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = icmp ne ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %19, %14, %1
  store double -1.000000e+00, ptr %2, align 8
  store i32 1, ptr %11, align 4
  br label %78

25:                                               ; preds = %19
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.cs_sparse, ptr %26, i32 0, i32 2
  %28 = load i64, ptr %27, align 8, !tbaa !15
  store i64 %28, ptr %6, align 8, !tbaa !16
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.cs_sparse, ptr %29, i32 0, i32 3
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  store ptr %31, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.cs_sparse, ptr %32, i32 0, i32 5
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  store ptr %34, ptr %8, align 8, !tbaa !5
  store i64 0, ptr %5, align 8, !tbaa !16
  br label %35

35:                                               ; preds = %73, %25
  %36 = load i64, ptr %5, align 8, !tbaa !16
  %37 = load i64, ptr %6, align 8, !tbaa !16
  %38 = icmp slt i64 %36, %37
  br i1 %38, label %39, label %76

39:                                               ; preds = %35
  store double 0.000000e+00, ptr %10, align 8, !tbaa !9
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %5, align 8, !tbaa !16
  %42 = getelementptr inbounds i64, ptr %40, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !16
  store i64 %43, ptr %4, align 8, !tbaa !16
  br label %44

44:                                               ; preds = %60, %39
  %45 = load i64, ptr %4, align 8, !tbaa !16
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i64, ptr %5, align 8, !tbaa !16
  %48 = add nsw i64 %47, 1
  %49 = getelementptr inbounds i64, ptr %46, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !16
  %51 = icmp slt i64 %45, %50
  br i1 %51, label %52, label %63

52:                                               ; preds = %44
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i64, ptr %4, align 8, !tbaa !16
  %55 = getelementptr inbounds double, ptr %53, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !9
  %57 = call double @llvm.fabs.f64(double %56)
  %58 = load double, ptr %10, align 8, !tbaa !9
  %59 = fadd double %58, %57
  store double %59, ptr %10, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %52
  %61 = load i64, ptr %4, align 8, !tbaa !16
  %62 = add nsw i64 %61, 1
  store i64 %62, ptr %4, align 8, !tbaa !16
  br label %44, !llvm.loop !18

63:                                               ; preds = %44
  %64 = load double, ptr %9, align 8, !tbaa !9
  %65 = load double, ptr %10, align 8, !tbaa !9
  %66 = fcmp ogt double %64, %65
  br i1 %66, label %67, label %69

67:                                               ; preds = %63
  %68 = load double, ptr %9, align 8, !tbaa !9
  br label %71

69:                                               ; preds = %63
  %70 = load double, ptr %10, align 8, !tbaa !9
  br label %71

71:                                               ; preds = %69, %67
  %72 = phi double [ %68, %67 ], [ %70, %69 ]
  store double %72, ptr %9, align 8, !tbaa !9
  br label %73

73:                                               ; preds = %71
  %74 = load i64, ptr %5, align 8, !tbaa !16
  %75 = add nsw i64 %74, 1
  store i64 %75, ptr %5, align 8, !tbaa !16
  br label %35, !llvm.loop !20

76:                                               ; preds = %35
  %77 = load double, ptr %9, align 8, !tbaa !9
  store double %77, ptr %2, align 8
  store i32 1, ptr %11, align 4
  br label %78

78:                                               ; preds = %76, %24
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %79 = load double, ptr %2, align 8
  ret double %79
}

; 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.fabs.f64(double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !13, i64 48}
!12 = !{!"cs_sparse", !13, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !13, i64 48}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 40}
!15 = !{!12, !13, i64 16}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !6, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local double @cs_norm(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i64 %4, -1
  br i1 %5, label %6, label %.loopexit

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %.not29 = icmp eq ptr %8, null
  br i1 %.not29, label %.loopexit, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i64, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = icmp sgt i64 %11, 0
  br i1 %14, label %.lr.ph36.preheader, label %.loopexit

.lr.ph36.preheader:                               ; preds = %9
  %.pre = load i64, ptr %13, align 8, !tbaa !14
  %invariant.gep = getelementptr i8, ptr %8, i64 8
  %invariant.gep47 = getelementptr i8, ptr %8, i64 16
  %invariant.gep49 = getelementptr i8, ptr %8, i64 24
  br label %.lr.ph36

.lr.ph36:                                         ; preds = %.lr.ph36.preheader, %._crit_edge
  %15 = phi i64 [ %18, %._crit_edge ], [ %.pre, %.lr.ph36.preheader ]
  %.02334 = phi double [ %43, %._crit_edge ], [ 0.000000e+00, %.lr.ph36.preheader ]
  %.02633 = phi i64 [ %16, %._crit_edge ], [ 0, %.lr.ph36.preheader ]
  %16 = add nuw nsw i64 %.02633, 1
  %17 = getelementptr inbounds i64, ptr %13, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !14
  %19 = icmp slt i64 %15, %18
  br i1 %19, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph36
  %20 = sub i64 %18, %15
  %xtraiter = and i64 %20, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.031.prol = phi double [ %24, %.lr.ph.prol ], [ 0.000000e+00, %.lr.ph.preheader ]
  %.02530.prol = phi i64 [ %25, %.lr.ph.prol ], [ %15, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %21 = getelementptr inbounds double, ptr %8, i64 %.02530.prol
  %22 = load double, ptr %21, align 8, !tbaa !15
  %23 = tail call double @llvm.fabs.f64(double %22)
  %24 = fadd double %.031.prol, %23
  %25 = add nsw i64 %.02530.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !17

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa.unr = phi double [ poison, %.lr.ph.preheader ], [ %24, %.lr.ph.prol ]
  %.031.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %24, %.lr.ph.prol ]
  %.02530.unr = phi i64 [ %15, %.lr.ph.preheader ], [ %25, %.lr.ph.prol ]
  %26 = sub i64 %15, %18
  %27 = icmp ugt i64 %26, -4
  br i1 %27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.031 = phi double [ %40, %.lr.ph ], [ %.031.unr, %.lr.ph.prol.loopexit ]
  %.02530 = phi i64 [ %41, %.lr.ph ], [ %.02530.unr, %.lr.ph.prol.loopexit ]
  %28 = getelementptr inbounds double, ptr %8, i64 %.02530
  %29 = load double, ptr %28, align 8, !tbaa !15
  %30 = tail call double @llvm.fabs.f64(double %29)
  %31 = fadd double %.031, %30
  %gep = getelementptr double, ptr %invariant.gep, i64 %.02530
  %32 = load double, ptr %gep, align 8, !tbaa !15
  %33 = tail call double @llvm.fabs.f64(double %32)
  %34 = fadd double %31, %33
  %gep48 = getelementptr double, ptr %invariant.gep47, i64 %.02530
  %35 = load double, ptr %gep48, align 8, !tbaa !15
  %36 = tail call double @llvm.fabs.f64(double %35)
  %37 = fadd double %34, %36
  %gep50 = getelementptr double, ptr %invariant.gep49, i64 %.02530
  %38 = load double, ptr %gep50, align 8, !tbaa !15
  %39 = tail call double @llvm.fabs.f64(double %38)
  %40 = fadd double %37, %39
  %41 = add nsw i64 %.02530, 4
  %exitcond.not.3 = icmp eq i64 %41, %18
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %.lr.ph36
  %.0.lcssa = phi double [ 0.000000e+00, %.lr.ph36 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %40, %.lr.ph ]
  %42 = fcmp ogt double %.02334, %.0.lcssa
  %43 = select i1 %42, double %.02334, double %.0.lcssa
  %exitcond39.not = icmp eq i64 %16, %11
  br i1 %exitcond39.not, label %.loopexit, label %.lr.ph36, !llvm.loop !21

.loopexit:                                        ; preds = %._crit_edge, %9, %1, %2, %6
  %.024 = phi double [ -1.000000e+00, %6 ], [ -1.000000e+00, %2 ], [ -1.000000e+00, %1 ], [ 0.000000e+00, %9 ], [ %43, %._crit_edge ]
  ret double %.024
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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) }

!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, !7, i64 48}
!6 = !{!"cs_sparse", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 40}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !10, i64 24}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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