; LLVM IR from libxsmm/libxsmm :: src (generator_spgemm_csr_asparse_reg)

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

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_analyse_sparse_nnz(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 1, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %17 = load ptr, ptr %8, align 8, !tbaa !9
  %18 = getelementptr inbounds double, ptr %17, i64 0
  %19 = load double, ptr %18, align 8, !tbaa !11
  %20 = call double @llvm.fabs.f64(double %19)
  %21 = load ptr, ptr %10, align 8, !tbaa !9
  %22 = getelementptr inbounds double, ptr %21, i64 0
  store double %20, ptr %22, align 8, !tbaa !11
  %23 = load ptr, ptr %11, align 8, !tbaa !9
  %24 = getelementptr inbounds i32, ptr %23, i64 0
  store i32 0, ptr %24, align 4, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  %26 = getelementptr inbounds double, ptr %25, i64 0
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = fcmp ogt double %27, 0.000000e+00
  %29 = zext i1 %28 to i64
  %30 = select i1 %28, i32 1, i32 -1
  %31 = load ptr, ptr %12, align 8, !tbaa !9
  %32 = getelementptr inbounds i32, ptr %31, i64 0
  store i32 %30, ptr %32, align 4, !tbaa !5
  store i32 1, ptr %15, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %111, %6
  %34 = load i32, ptr %15, align 4, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = icmp ult i32 %34, %35
  br i1 %36, label %37, label %114

37:                                               ; preds = %33
  store i32 0, ptr %14, align 4, !tbaa !5
  store i32 0, ptr %16, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %75, %37
  %39 = load i32, ptr %16, align 4, !tbaa !5
  %40 = load i32, ptr %13, align 4, !tbaa !5
  %41 = icmp ult i32 %39, %40
  br i1 %41, label %42, label %78

42:                                               ; preds = %38
  %43 = load ptr, ptr %10, align 8, !tbaa !9
  %44 = load i32, ptr %16, align 4, !tbaa !5
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %43, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !11
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = load i32, ptr %15, align 4, !tbaa !5
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %48, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !11
  %53 = call double @llvm.fabs.f64(double %52)
  %54 = fcmp olt double %47, %53
  br i1 %54, label %74, label %55

55:                                               ; preds = %42
  %56 = load ptr, ptr %10, align 8, !tbaa !9
  %57 = load i32, ptr %16, align 4, !tbaa !5
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %56, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !11
  %61 = load ptr, ptr %8, align 8, !tbaa !9
  %62 = load i32, ptr %15, align 4, !tbaa !5
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds double, ptr %61, i64 %63
  %65 = load double, ptr %64, align 8, !tbaa !11
  %66 = call double @llvm.fabs.f64(double %65)
  %67 = fcmp ogt double %60, %66
  br i1 %67, label %74, label %68

68:                                               ; preds = %55
  %69 = load i32, ptr %16, align 4, !tbaa !5
  %70 = load ptr, ptr %11, align 8, !tbaa !9
  %71 = load i32, ptr %15, align 4, !tbaa !5
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr %70, i64 %72
  store i32 %69, ptr %73, align 4, !tbaa !5
  store i32 1, ptr %14, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %68, %55, %42
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %16, align 4, !tbaa !5
  %77 = add i32 %76, 1
  store i32 %77, ptr %16, align 4, !tbaa !5
  br label %38, !llvm.loop !13

78:                                               ; preds = %38
  %79 = load i32, ptr %14, align 4, !tbaa !5
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %98, label %81

81:                                               ; preds = %78
  %82 = load ptr, ptr %8, align 8, !tbaa !9
  %83 = load i32, ptr %15, align 4, !tbaa !5
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds double, ptr %82, i64 %84
  %86 = load double, ptr %85, align 8, !tbaa !11
  %87 = call double @llvm.fabs.f64(double %86)
  %88 = load ptr, ptr %10, align 8, !tbaa !9
  %89 = load i32, ptr %13, align 4, !tbaa !5
  %90 = zext i32 %89 to i64
  %91 = getelementptr inbounds double, ptr %88, i64 %90
  store double %87, ptr %91, align 8, !tbaa !11
  %92 = load i32, ptr %13, align 4, !tbaa !5
  %93 = add i32 %92, 1
  store i32 %93, ptr %13, align 4, !tbaa !5
  %94 = load ptr, ptr %11, align 8, !tbaa !9
  %95 = load i32, ptr %15, align 4, !tbaa !5
  %96 = zext i32 %95 to i64
  %97 = getelementptr inbounds i32, ptr %94, i64 %96
  store i32 %92, ptr %97, align 4, !tbaa !5
  br label %98

98:                                               ; preds = %81, %78
  %99 = load ptr, ptr %8, align 8, !tbaa !9
  %100 = load i32, ptr %15, align 4, !tbaa !5
  %101 = zext i32 %100 to i64
  %102 = getelementptr inbounds double, ptr %99, i64 %101
  %103 = load double, ptr %102, align 8, !tbaa !11
  %104 = fcmp ogt double %103, 0.000000e+00
  %105 = zext i1 %104 to i64
  %106 = select i1 %104, i32 1, i32 -1
  %107 = load ptr, ptr %12, align 8, !tbaa !9
  %108 = load i32, ptr %15, align 4, !tbaa !5
  %109 = zext i32 %108 to i64
  %110 = getelementptr inbounds i32, ptr %107, i64 %109
  store i32 %106, ptr %110, align 4, !tbaa !5
  br label %111

111:                                              ; preds = %98
  %112 = load i32, ptr %15, align 4, !tbaa !5
  %113 = add i32 %112, 1
  store i32 %113, ptr %15, align 4, !tbaa !5
  br label %33, !llvm.loop !15

114:                                              ; preds = %33
  %115 = load i32, ptr %13, align 4, !tbaa !5
  %116 = load ptr, ptr %9, align 8, !tbaa !9
  store i32 %115, ptr %116, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret void
}

; 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @libxsmm_analyse_sparse_nnz(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = load double, ptr %1, align 8, !tbaa !5
  %8 = tail call double @llvm.fabs.f64(double %7)
  store double %8, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !9
  %9 = load double, ptr %1, align 8, !tbaa !5
  %10 = fcmp ogt double %9, 0.000000e+00
  %11 = select i1 %10, i32 1, i32 -1
  store i32 %11, ptr %5, align 4, !tbaa !9
  %12 = icmp ugt i32 %0, 1
  br i1 %12, label %.preheader.preheader, label %._crit_edge45

.preheader.preheader:                             ; preds = %6
  %wide.trip.count52 = zext i32 %0 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %40
  %indvars.iv49 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next50, %40 ]
  %.03743 = phi i32 [ 1, %.preheader.preheader ], [ %.138, %40 ]
  %.not47 = icmp eq i32 %.03743, 0
  br i1 %.not47, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %13 = getelementptr inbounds double, ptr %1, i64 %indvars.iv49
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = tail call double @llvm.fabs.f64(double %14)
  %16 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv49
  %wide.trip.count = zext i32 %.03743 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %17 = icmp eq i32 %.03743, 1
  br i1 %17, label %._crit_edge.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %18

18:                                               ; preds = %28, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %28 ]
  %.03641 = phi i32 [ 0, %.lr.ph.new ], [ %.1.1, %28 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %28 ]
  %19 = getelementptr inbounds double, ptr %3, i64 %indvars.iv
  %20 = load double, ptr %19, align 8, !tbaa !5
  %or.cond = fcmp ueq double %20, %15
  br i1 %or.cond, label %21, label %23

21:                                               ; preds = %18
  %22 = trunc nuw i64 %indvars.iv to i32
  store i32 %22, ptr %16, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %18, %21
  %.1 = phi i32 [ %.03641, %18 ], [ 1, %21 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %24 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next
  %25 = load double, ptr %24, align 8, !tbaa !5
  %or.cond.1 = fcmp ueq double %25, %15
  br i1 %or.cond.1, label %26, label %28

26:                                               ; preds = %23
  %27 = trunc nuw i64 %indvars.iv.next to i32
  store i32 %27, ptr %16, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %26, %23
  %.1.1 = phi i32 [ %.1, %23 ], [ 1, %26 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %18, !llvm.loop !11

._crit_edge.unr-lcssa:                            ; preds = %28, %.lr.ph
  %.1.lcssa.ph = phi i32 [ poison, %.lr.ph ], [ %.1.1, %28 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %28 ]
  %.03641.unr = phi i32 [ 0, %.lr.ph ], [ %.1.1, %28 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.unr-lcssa
  %29 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.unr
  %30 = load double, ptr %29, align 8, !tbaa !5
  %or.cond.epil = fcmp ueq double %30, %15
  br i1 %or.cond.epil, label %31, label %._crit_edge

31:                                               ; preds = %.epil.preheader
  %32 = trunc nuw i64 %indvars.iv.unr to i32
  store i32 %32, ptr %16, align 4, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %.epil.preheader, %31, %._crit_edge.unr-lcssa
  %.1.lcssa = phi i32 [ %.1.lcssa.ph, %._crit_edge.unr-lcssa ], [ %.03641.unr, %.epil.preheader ], [ 1, %31 ]
  %.not = icmp eq i32 %.1.lcssa, 0
  br i1 %.not, label %._crit_edge.thread, label %40

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge
  %33 = getelementptr inbounds double, ptr %1, i64 %indvars.iv49
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = tail call double @llvm.fabs.f64(double %34)
  %36 = zext i32 %.03743 to i64
  %37 = getelementptr inbounds double, ptr %3, i64 %36
  store double %35, ptr %37, align 8, !tbaa !5
  %38 = add i32 %.03743, 1
  %39 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv49
  store i32 %.03743, ptr %39, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %.138 = phi i32 [ %.03743, %._crit_edge ], [ %38, %._crit_edge.thread ]
  %41 = getelementptr inbounds double, ptr %1, i64 %indvars.iv49
  %42 = load double, ptr %41, align 8, !tbaa !5
  %43 = fcmp ogt double %42, 0.000000e+00
  %44 = select i1 %43, i32 1, i32 -1
  %45 = getelementptr inbounds i32, ptr %5, i64 %indvars.iv49
  store i32 %44, ptr %45, align 4, !tbaa !9
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond53.not = icmp eq i64 %indvars.iv.next50, %wide.trip.count52
  br i1 %exitcond53.not, label %._crit_edge45, label %.preheader, !llvm.loop !13

._crit_edge45:                                    ; preds = %40, %6
  %.037.lcssa = phi i32 [ 1, %6 ], [ %.138, %40 ]
  store i32 %.037.lcssa, ptr %2, align 4, !tbaa !9
  ret void
}

; 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(argmem: readwrite) 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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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