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

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

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @cs_gatxpy(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) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %22

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 %24, label %22

22:                                               ; preds = %17, %3
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %24

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

27:                                               ; preds = %24
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %29

29:                                               ; preds = %27, %24
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %34, label %32

32:                                               ; preds = %29
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %34

34:                                               ; preds = %32, %29
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %48

37:                                               ; preds = %34
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.cs_sparse, ptr %38, i32 0, i32 6
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = icmp eq i64 %40, -1
  br i1 %41, label %42, label %48

42:                                               ; preds = %37
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %49, label %48

48:                                               ; preds = %45, %42, %37, %34
  store i64 0, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %104

49:                                               ; preds = %45
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.cs_sparse, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !12
  store i64 %52, ptr %10, align 8, !tbaa !13
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.cs_sparse, ptr %53, i32 0, i32 3
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  store ptr %55, ptr %11, align 8, !tbaa !5
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.cs_sparse, ptr %56, i32 0, i32 4
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  store ptr %58, ptr %12, align 8, !tbaa !5
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.cs_sparse, ptr %59, i32 0, i32 5
  %61 = load ptr, ptr %60, align 8, !tbaa !16
  store ptr %61, ptr %13, align 8, !tbaa !5
  store i64 0, ptr %9, align 8, !tbaa !13
  br label %62

62:                                               ; preds = %100, %49
  %63 = load i64, ptr %9, align 8, !tbaa !13
  %64 = load i64, ptr %10, align 8, !tbaa !13
  %65 = icmp slt i64 %63, %64
  br i1 %65, label %66, label %103

66:                                               ; preds = %62
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = load i64, ptr %9, align 8, !tbaa !13
  %69 = getelementptr inbounds i64, ptr %67, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !13
  store i64 %70, ptr %8, align 8, !tbaa !13
  br label %71

71:                                               ; preds = %96, %66
  %72 = load i64, ptr %8, align 8, !tbaa !13
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = load i64, ptr %9, align 8, !tbaa !13
  %75 = add nsw i64 %74, 1
  %76 = getelementptr inbounds i64, ptr %73, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !13
  %78 = icmp slt i64 %72, %77
  br i1 %78, label %79, label %99

79:                                               ; preds = %71
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  %81 = load i64, ptr %8, align 8, !tbaa !13
  %82 = getelementptr inbounds double, ptr %80, i64 %81
  %83 = load double, ptr %82, align 8, !tbaa !17
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = load ptr, ptr %12, align 8, !tbaa !5
  %86 = load i64, ptr %8, align 8, !tbaa !13
  %87 = getelementptr inbounds i64, ptr %85, i64 %86
  %88 = load i64, ptr %87, align 8, !tbaa !13
  %89 = getelementptr inbounds double, ptr %84, i64 %88
  %90 = load double, ptr %89, align 8, !tbaa !17
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = load i64, ptr %9, align 8, !tbaa !13
  %93 = getelementptr inbounds double, ptr %91, i64 %92
  %94 = load double, ptr %93, align 8, !tbaa !17
  %95 = call double @llvm.fmuladd.f64(double %83, double %90, double %94)
  store double %95, ptr %93, align 8, !tbaa !17
  br label %96

96:                                               ; preds = %79
  %97 = load i64, ptr %8, align 8, !tbaa !13
  %98 = add nsw i64 %97, 1
  store i64 %98, ptr %8, align 8, !tbaa !13
  br label %71, !llvm.loop !19

99:                                               ; preds = %71
  br label %100

100:                                              ; preds = %99
  %101 = load i64, ptr %9, align 8, !tbaa !13
  %102 = add nsw i64 %101, 1
  store i64 %102, ptr %9, align 8, !tbaa !13
  br label %62, !llvm.loop !21

103:                                              ; preds = %62
  store i64 1, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %104

104:                                              ; preds = %103, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %105 = load i64, ptr %4, align 8
  ret i64 %105
}

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !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"

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local range(i64 0, 2) i64 @cs_gatxpy(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 %8, 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
  br i1 %7, label %10, label %8

8:                                                ; preds = %4, %3
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %10

10:                                               ; preds = %8, %4
  %11 = icmp ne ptr %1, null
  br i1 %11, label %14, label %12

12:                                               ; preds = %10
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %14

14:                                               ; preds = %12, %10
  %15 = icmp ne ptr %2, null
  br i1 %15, label %18, label %16

16:                                               ; preds = %14
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %18

18:                                               ; preds = %16, %14
  br i1 %.not, label %.loopexit36, label %19

19:                                               ; preds = %18
  %20 = getelementptr inbounds i8, ptr %0, i64 48
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = icmp eq i64 %21, -1
  %or.cond = and i1 %11, %22
  %or.cond3 = and i1 %15, %or.cond
  br i1 %or.cond3, label %23, label %.loopexit36

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds i8, ptr %0, i64 24
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %0, i64 40
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = icmp sgt i64 %25, 0
  br i1 %32, label %.lr.ph39.preheader, label %.loopexit36

.lr.ph39.preheader:                               ; preds = %23
  %.pre = load i64, ptr %27, align 8, !tbaa !15
  br label %.lr.ph39

.loopexit:                                        ; preds = %.prol.loopexit, %.lr.ph.new, %.lr.ph39
  %exitcond40.not = icmp eq i64 %34, %25
  br i1 %exitcond40.not, label %.loopexit36, label %.lr.ph39, !llvm.loop !16

.lr.ph39:                                         ; preds = %.lr.ph39.preheader, %.loopexit
  %33 = phi i64 [ %36, %.loopexit ], [ %.pre, %.lr.ph39.preheader ]
  %.03238 = phi i64 [ %34, %.loopexit ], [ 0, %.lr.ph39.preheader ]
  %34 = add nuw nsw i64 %.03238, 1
  %35 = getelementptr inbounds i64, ptr %27, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !15
  %37 = icmp slt i64 %33, %36
  br i1 %37, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph39
  %38 = getelementptr inbounds double, ptr %2, i64 %.03238
  %.promoted = load double, ptr %38, align 8, !tbaa !18
  %39 = sub i64 %36, %33
  %.neg = add i64 %33, 1
  %xtraiter = and i64 %39, 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
  %40 = getelementptr inbounds double, ptr %31, i64 %33
  %41 = load double, ptr %40, align 8, !tbaa !18
  %42 = getelementptr inbounds i64, ptr %29, i64 %33
  %43 = load i64, ptr %42, align 8, !tbaa !15
  %44 = getelementptr inbounds double, ptr %1, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !18
  %46 = tail call double @llvm.fmuladd.f64(double %41, double %45, double %.promoted)
  store double %46, ptr %38, align 8, !tbaa !18
  %47 = add nsw i64 %33, 1
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph
  %.unr = phi double [ %.promoted, %.lr.ph ], [ %46, %.prol.loopexit.unr-lcssa ]
  %.03137.unr = phi i64 [ %33, %.lr.ph ], [ %47, %.prol.loopexit.unr-lcssa ]
  %48 = icmp eq i64 %36, %.neg
  br i1 %48, label %.loopexit, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.prol.loopexit, %.lr.ph.new
  %49 = phi double [ %64, %.lr.ph.new ], [ %.unr, %.prol.loopexit ]
  %.03137 = phi i64 [ %65, %.lr.ph.new ], [ %.03137.unr, %.prol.loopexit ]
  %50 = getelementptr inbounds double, ptr %31, i64 %.03137
  %51 = load double, ptr %50, align 8, !tbaa !18
  %52 = getelementptr inbounds i64, ptr %29, i64 %.03137
  %53 = load i64, ptr %52, align 8, !tbaa !15
  %54 = getelementptr inbounds double, ptr %1, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !18
  %56 = tail call double @llvm.fmuladd.f64(double %51, double %55, double %49)
  store double %56, ptr %38, align 8, !tbaa !18
  %57 = add nsw i64 %.03137, 1
  %58 = getelementptr inbounds double, ptr %31, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !18
  %60 = getelementptr inbounds i64, ptr %29, i64 %57
  %61 = load i64, ptr %60, align 8, !tbaa !15
  %62 = getelementptr inbounds double, ptr %1, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !18
  %64 = tail call double @llvm.fmuladd.f64(double %59, double %63, double %56)
  store double %64, ptr %38, align 8, !tbaa !18
  %65 = add nsw i64 %.03137, 2
  %exitcond.not.1 = icmp eq i64 %65, %36
  br i1 %exitcond.not.1, label %.loopexit, label %.lr.ph.new, !llvm.loop !20

.loopexit36:                                      ; preds = %.loopexit, %23, %18, %19
  %.0 = phi i64 [ 0, %19 ], [ 0, %18 ], [ 1, %23 ], [ 1, %.loopexit ]
  ret i64 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

attributes #0 = { nofree 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 = { 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