; LLVM IR from MRPT/mrpt :: libs/math/src/CSparse (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 { i32, i32, i32, ptr, ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @cs_gaxpy(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %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 i32, align 4
  %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 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, 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 i32, ptr %19, align 8, !tbaa !9
  %21 = icmp eq i32 %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 i32 0, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %90

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 i32, ptr %31, align 8, !tbaa !12
  store i32 %32, ptr %10, align 4, !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 i32 0, ptr %9, align 4, !tbaa !13
  br label %42

42:                                               ; preds = %86, %29
  %43 = load i32, ptr %9, align 4, !tbaa !13
  %44 = load i32, ptr %10, align 4, !tbaa !13
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %46, label %89

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

52:                                               ; preds = %82, %46
  %53 = load i32, ptr %8, align 4, !tbaa !13
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !13
  %56 = add nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i32, ptr %54, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !13
  %60 = icmp slt i32 %53, %59
  br i1 %60, label %61, label %85

61:                                               ; preds = %52
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = load i32, ptr %8, align 4, !tbaa !13
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds double, ptr %62, i64 %64
  %66 = load double, ptr %65, align 8, !tbaa !17
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load i32, ptr %9, align 4, !tbaa !13
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds double, ptr %67, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !17
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load ptr, ptr %12, align 8, !tbaa !5
  %74 = load i32, ptr %8, align 4, !tbaa !13
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i32, ptr %73, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !13
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds double, ptr %72, i64 %78
  %80 = load double, ptr %79, align 8, !tbaa !17
  %81 = call double @llvm.fmuladd.f64(double %66, double %71, double %80)
  store double %81, ptr %79, align 8, !tbaa !17
  br label %82

82:                                               ; preds = %61
  %83 = load i32, ptr %8, align 4, !tbaa !13
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %8, align 4, !tbaa !13
  br label %52, !llvm.loop !19

85:                                               ; preds = %52
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %9, align 4, !tbaa !13
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %9, align 4, !tbaa !13
  br label %42, !llvm.loop !21

89:                                               ; preds = %42
  store i32 1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %90

90:                                               ; preds = %89, %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 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %91 = load i32, ptr %4, align 4
  ret i32 %91
}

; 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 40}
!10 = !{!"cs_sparse", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !6, i64 24}
!16 = !{!10, !6, i64 32}
!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(i32 0, 2) i32 @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 40
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %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 8
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = icmp sgt i32 %12, 0
  br i1 %19, label %.lr.ph35.preheader, label %.loopexit32

.lr.ph35.preheader:                               ; preds = %10
  %wide.trip.count40 = zext nneg i32 %12 to i64
  %.pre = load i32, ptr %14, align 4, !tbaa !15
  br label %.lr.ph35

.loopexit:                                        ; preds = %.prol.loopexit, %.lr.ph.new, %.lr.ph35
  %exitcond41.not = icmp eq i64 %indvars.iv.next38, %wide.trip.count40
  br i1 %exitcond41.not, label %.loopexit32, label %.lr.ph35, !llvm.loop !16

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

.lr.ph:                                           ; preds = %.lr.ph35
  %24 = getelementptr inbounds double, ptr %1, i64 %indvars.iv37
  %25 = sext i32 %20 to i64
  %wide.trip.count = sext i32 %22 to i64
  %26 = sub nsw i64 %wide.trip.count, %25
  %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 %25
  %28 = load double, ptr %27, align 8, !tbaa !18
  %29 = load double, ptr %24, align 8, !tbaa !18
  %30 = getelementptr inbounds i32, ptr %16, i64 %25
  %31 = load i32, ptr %30, align 4, !tbaa !15
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds double, ptr %2, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !18
  %35 = tail call double @llvm.fmuladd.f64(double %28, double %29, double %34)
  store double %35, ptr %33, align 8, !tbaa !18
  %indvars.iv.next.prol = add nsw i64 %25, 1
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph
  %indvars.iv.unr = phi i64 [ %25, %.lr.ph ], [ %indvars.iv.next.prol, %.prol.loopexit.unr-lcssa ]
  %36 = add nsw i64 %wide.trip.count, -1
  %37 = icmp eq i64 %36, %25
  br i1 %37, label %.loopexit, label %.lr.ph.new

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

.loopexit32:                                      ; preds = %.loopexit, %10, %3, %4
  %.0 = phi i32 [ 0, %4 ], [ 0, %3 ], [ 1, %10 ], [ 1, %.loopexit ]
  ret i32 %.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 40}
!6 = !{!"cs_sparse", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !10, i64 32}
!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