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

; 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 i64 @cs_gaxpy(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, 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 i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, 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 %5, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %28

17:                                               ; preds = %3
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.cs_sparse, ptr %18, i32 0, i32 6
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = icmp eq i64 %20, -1
  br i1 %21, label %22, label %28

22:                                               ; preds = %17
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %28

25:                                               ; preds = %22
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %25, %22, %17, %3
  store i64 0, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %84

29:                                               ; preds = %25
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.cs_sparse, ptr %30, i32 0, i32 2
  %32 = load i64, ptr %31, align 8, !tbaa !12
  store i64 %32, ptr %10, align 8, !tbaa !13
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.cs_sparse, ptr %33, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  store ptr %35, ptr %11, align 8, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.cs_sparse, ptr %36, i32 0, i32 4
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  store ptr %38, ptr %12, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.cs_sparse, ptr %39, i32 0, i32 5
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  store ptr %41, ptr %13, align 8, !tbaa !5
  store i64 0, ptr %9, align 8, !tbaa !13
  br label %42

42:                                               ; preds = %80, %29
  %43 = load i64, ptr %9, align 8, !tbaa !13
  %44 = load i64, ptr %10, align 8, !tbaa !13
  %45 = icmp slt i64 %43, %44
  br i1 %45, label %46, label %83

46:                                               ; preds = %42
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = load i64, ptr %9, align 8, !tbaa !13
  %49 = getelementptr inbounds i64, ptr %47, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !13
  store i64 %50, ptr %8, align 8, !tbaa !13
  br label %51

51:                                               ; preds = %76, %46
  %52 = load i64, ptr %8, align 8, !tbaa !13
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load i64, ptr %9, align 8, !tbaa !13
  %55 = add nsw i64 %54, 1
  %56 = getelementptr inbounds i64, ptr %53, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !13
  %58 = icmp slt i64 %52, %57
  br i1 %58, label %59, label %79

59:                                               ; preds = %51
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = load i64, ptr %8, align 8, !tbaa !13
  %62 = getelementptr inbounds double, ptr %60, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !17
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load i64, ptr %9, align 8, !tbaa !13
  %66 = getelementptr inbounds double, ptr %64, i64 %65
  %67 = load double, ptr %66, align 8, !tbaa !17
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = load i64, ptr %8, align 8, !tbaa !13
  %71 = getelementptr inbounds i64, ptr %69, i64 %70
  %72 = load i64, ptr %71, align 8, !tbaa !13
  %73 = getelementptr inbounds double, ptr %68, i64 %72
  %74 = load double, ptr %73, align 8, !tbaa !17
  %75 = call double @llvm.fmuladd.f64(double %63, double %67, double %74)
  store double %75, ptr %73, align 8, !tbaa !17
  br label %76

76:                                               ; preds = %59
  %77 = load i64, ptr %8, align 8, !tbaa !13
  %78 = add nsw i64 %77, 1
  store i64 %78, ptr %8, align 8, !tbaa !13
  br label %51, !llvm.loop !19

79:                                               ; preds = %51
  br label %80

80:                                               ; preds = %79
  %81 = load i64, ptr %9, align 8, !tbaa !13
  %82 = add nsw i64 %81, 1
  store i64 %82, ptr %9, align 8, !tbaa !13
  br label %42, !llvm.loop !21

83:                                               ; preds = %42
  store i64 1, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %84

84:                                               ; preds = %83, %28
  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
  %85 = load i64, ptr %4, align 8
  ret i64 %85
}

; 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.fmuladd.f64(double, double, 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, !11, i64 48}
!10 = !{!"cs_sparse", !11, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !6, i64 32}
!16 = !{!10, !6, i64 40}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i64 0, 2) i64 @cs_gaxpy(ptr noundef readonly %0, ptr noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit32, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i64 %6, -1
  %8 = icmp ne ptr %1, null
  %or.cond = and i1 %8, %7
  %9 = icmp ne ptr %2, null
  %or.cond3 = and i1 %9, %or.cond
  br i1 %or.cond3, label %10, label %.loopexit32

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = icmp sgt i64 %12, 0
  br i1 %19, label %.lr.ph35.preheader, label %.loopexit32

.lr.ph35.preheader:                               ; preds = %10
  %.pre = load i64, ptr %14, align 8, !tbaa !15
  br label %.lr.ph35

.loopexit:                                        ; preds = %.prol.loopexit, %.lr.ph.new, %.lr.ph35
  %exitcond36.not = icmp eq i64 %21, %12
  br i1 %exitcond36.not, label %.loopexit32, label %.lr.ph35, !llvm.loop !16

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %.loopexit
  %20 = phi i64 [ %23, %.loopexit ], [ %.pre, %.lr.ph35.preheader ]
  %.02834 = phi i64 [ %21, %.loopexit ], [ 0, %.lr.ph35.preheader ]
  %21 = add nuw nsw i64 %.02834, 1
  %22 = getelementptr inbounds i64, ptr %14, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !15
  %24 = icmp slt i64 %20, %23
  br i1 %24, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph35
  %25 = getelementptr inbounds double, ptr %1, i64 %.02834
  %26 = sub i64 %23, %20
  %.neg = add i64 %20, 1
  %xtraiter = and i64 %26, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.loopexit.unr-lcssa

.prol.loopexit.unr-lcssa:                         ; preds = %.lr.ph
  %27 = getelementptr inbounds double, ptr %18, i64 %20
  %28 = load double, ptr %27, align 8, !tbaa !18
  %29 = load double, ptr %25, align 8, !tbaa !18
  %30 = getelementptr inbounds i64, ptr %16, i64 %20
  %31 = load i64, ptr %30, align 8, !tbaa !15
  %32 = getelementptr inbounds double, ptr %2, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !18
  %34 = tail call double @llvm.fmuladd.f64(double %28, double %29, double %33)
  store double %34, ptr %32, align 8, !tbaa !18
  %35 = add nsw i64 %20, 1
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph
  %.02733.unr = phi i64 [ %20, %.lr.ph ], [ %35, %.prol.loopexit.unr-lcssa ]
  %36 = icmp eq i64 %23, %.neg
  br i1 %36, label %.loopexit, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.prol.loopexit, %.lr.ph.new
  %.02733 = phi i64 [ %54, %.lr.ph.new ], [ %.02733.unr, %.prol.loopexit ]
  %37 = getelementptr inbounds double, ptr %18, i64 %.02733
  %38 = load double, ptr %37, align 8, !tbaa !18
  %39 = load double, ptr %25, align 8, !tbaa !18
  %40 = getelementptr inbounds i64, ptr %16, i64 %.02733
  %41 = load i64, ptr %40, align 8, !tbaa !15
  %42 = getelementptr inbounds double, ptr %2, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !18
  %44 = tail call double @llvm.fmuladd.f64(double %38, double %39, double %43)
  store double %44, ptr %42, align 8, !tbaa !18
  %45 = add nsw i64 %.02733, 1
  %46 = getelementptr inbounds double, ptr %18, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !18
  %48 = load double, ptr %25, align 8, !tbaa !18
  %49 = getelementptr inbounds i64, ptr %16, i64 %45
  %50 = load i64, ptr %49, align 8, !tbaa !15
  %51 = getelementptr inbounds double, ptr %2, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !18
  %53 = tail call double @llvm.fmuladd.f64(double %47, double %48, double %52)
  store double %53, ptr %51, align 8, !tbaa !18
  %54 = add nsw i64 %.02733, 2
  %exitcond.not.1 = icmp eq i64 %54, %23
  br i1 %exitcond.not.1, label %.loopexit, label %.lr.ph.new, !llvm.loop !20

.loopexit32:                                      ; preds = %.loopexit, %10, %3, %4
  %.0 = phi i64 [ 0, %4 ], [ 0, %3 ], [ 1, %10 ], [ 1, %.loopexit ]
  ret i64 %.0
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, 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, !7, i64 16}
!12 = !{!6, !10, i64 24}
!13 = !{!6, !10, i64 32}
!14 = !{!6, !10, i64 40}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !8, i64 0}
!20 = distinct !{!20, !17}


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