; LLVM IR from clunietp/libgmsd :: src (matrix)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @matrix_cols(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @matrix_rows(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @check_(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @matrix_crow(ptr noundef, i64 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @matrix_row(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @matrix_cwise_add_scalar(ptr noundef %0, ptr noundef %1, float noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store float %2, ptr %6, align 4, !tbaa !9
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call zeroext i1 @check_(ptr noundef %12, ptr noundef %13)
  br i1 %14, label %16, label %15

15:                                               ; preds = %3
  store i32 1, ptr %11, align 4
  br label %52

16:                                               ; preds = %3
  store i64 0, ptr %7, align 8, !tbaa !11
  br label %17

17:                                               ; preds = %48, %16
  %18 = load i64, ptr %7, align 8, !tbaa !11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i64 @matrix_rows(ptr noundef %19)
  %21 = icmp ult i64 %18, %20
  br i1 %21, label %22, label %51

22:                                               ; preds = %17
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i64, ptr %7, align 8, !tbaa !11
  %25 = call ptr @matrix_crow(ptr noundef %23, i64 noundef %24)
  store ptr %25, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load i64, ptr %7, align 8, !tbaa !11
  %28 = call ptr @matrix_row(ptr noundef %26, i64 noundef %27)
  store ptr %28, ptr %10, align 8, !tbaa !5
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %40, %22
  %30 = load i64, ptr %8, align 8, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = call i64 @matrix_cols(ptr noundef %31)
  %33 = icmp ult i64 %30, %32
  br i1 %33, label %34, label %47

34:                                               ; preds = %29
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load float, ptr %35, align 4, !tbaa !9
  %37 = load float, ptr %6, align 4, !tbaa !9
  %38 = fadd float %36, %37
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  store float %38, ptr %39, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %34
  %41 = load i64, ptr %8, align 8, !tbaa !11
  %42 = add i64 %41, 1
  store i64 %42, ptr %8, align 8, !tbaa !11
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds float, ptr %43, i32 1
  store ptr %44, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds float, ptr %45, i32 1
  store ptr %46, ptr %10, align 8, !tbaa !5
  br label %29, !llvm.loop !13

47:                                               ; preds = %29
  br label %48

48:                                               ; preds = %47
  %49 = load i64, ptr %7, align 8, !tbaa !11
  %50 = add i64 %49, 1
  store i64 %50, ptr %7, align 8, !tbaa !11
  br label %17, !llvm.loop !15

51:                                               ; preds = %17
  store i32 0, ptr %11, align 4
  br label %52

52:                                               ; preds = %51, %15
  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
  %53 = load i32, ptr %11, align 4
  switch i32 %53, label %55 [
    i32 0, label %54
    i32 1, label %54
  ]

54:                                               ; preds = %52, %52
  ret void

55:                                               ; preds = %52
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { 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 #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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !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: inlinehint nounwind uwtable
declare hidden i64 @matrix_cols(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @matrix_rows(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @check_(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @matrix_crow(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @matrix_row(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @matrix_cwise_add_scalar(ptr noundef %0, ptr noundef %1, float noundef %2) local_unnamed_addr #1 {
  %4 = tail call zeroext i1 @check_(ptr noundef %0, ptr noundef %1)
  br i1 %4, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %3
  %5 = tail call i64 @matrix_rows(ptr noundef %1)
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %.loopexit, label %.lr.ph23

.lr.ph23:                                         ; preds = %.preheader, %._crit_edge
  %.01822 = phi i64 [ %16, %._crit_edge ], [ 0, %.preheader ]
  %6 = tail call ptr @matrix_crow(ptr noundef %1, i64 noundef %.01822)
  %7 = tail call ptr @matrix_row(ptr noundef %0, i64 noundef %.01822)
  %8 = tail call i64 @matrix_cols(ptr noundef %1)
  %.not24 = icmp eq i64 %8, 0
  br i1 %.not24, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph23, %.lr.ph
  %.021 = phi ptr [ %13, %.lr.ph ], [ %7, %.lr.ph23 ]
  %.01620 = phi ptr [ %12, %.lr.ph ], [ %6, %.lr.ph23 ]
  %.01719 = phi i64 [ %11, %.lr.ph ], [ 0, %.lr.ph23 ]
  %9 = load float, ptr %.01620, align 4, !tbaa !5
  %10 = fadd float %9, %2
  store float %10, ptr %.021, align 4, !tbaa !5
  %11 = add nuw i64 %.01719, 1
  %12 = getelementptr inbounds i8, ptr %.01620, i64 4
  %13 = getelementptr inbounds i8, ptr %.021, i64 4
  %14 = tail call i64 @matrix_cols(ptr noundef %1)
  %15 = icmp ult i64 %11, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph23
  %16 = add nuw i64 %.01822, 1
  %17 = tail call i64 @matrix_rows(ptr noundef %1)
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %.lr.ph23, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %._crit_edge, %.preheader, %3
  ret void
}

attributes #0 = { inlinehint 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 = { 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" }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass