; LLVM IR from moarseniy/CudaFEMproject :: FEMproject/matrix_pack/src/cpu_matrix.ll (ZN10CPU_Matrix17divideElementwiseER6Matrix)

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

%class.Matrix = type <{ ptr, i32, [4 x i8], i64, i64, i64, ptr, i8, [7 x i8] }>

@.str = external hidden unnamed_addr constant [100 x i8], align 1
@__FUNCTION__._ZN10CPU_Matrix17divideElementwiseEf = external hidden unnamed_addr constant [18 x i8], align 1

declare void @_Z10_my_assertbPKciS0_(i1 noundef zeroext, ptr noundef, i32 noundef, ptr noundef) #0

declare noundef i64 @_ZNK6Matrix15get_numElementsEv(ptr noundef nonnull align 8 dereferenceable(49)) #0

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

declare noundef ptr @_ZNK6Matrix8get_dataEv(ptr noundef nonnull align 8 dereferenceable(49)) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10CPU_Matrix17divideElementwiseER6Matrix(ptr noundef nonnull align 8 dereferenceable(49) %0, ptr noundef nonnull align 8 dereferenceable(49) %1) unnamed_addr #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.Matrix, ptr %6, i32 0, i32 5
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = icmp ugt i64 %8, 0
  br i1 %9, label %10, label %16

10:                                               ; preds = %2
  %11 = getelementptr inbounds %class.Matrix, ptr %6, i32 0, i32 5
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call noundef i64 @_ZNK6Matrix15get_numElementsEv(ptr noundef nonnull align 8 dereferenceable(49) %13)
  %15 = icmp eq i64 %12, %14
  br label %16

16:                                               ; preds = %10, %2
  %17 = phi i1 [ false, %2 ], [ %15, %10 ]
  call void @_Z10_my_assertbPKciS0_(i1 noundef zeroext %17, ptr noundef @.str, i32 noundef 120, ptr noundef @__FUNCTION__._ZN10CPU_Matrix17divideElementwiseEf)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !14
  br label %18

18:                                               ; preds = %36, %16
  %19 = load i64, ptr %5, align 8, !tbaa !14
  %20 = getelementptr inbounds %class.Matrix, ptr %6, i32 0, i32 5
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = icmp ult i64 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %39

24:                                               ; preds = %18
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call noundef ptr @_ZNK6Matrix8get_dataEv(ptr noundef nonnull align 8 dereferenceable(49) %25)
  %27 = load i64, ptr %5, align 8, !tbaa !14
  %28 = getelementptr inbounds float, ptr %26, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !15
  %30 = getelementptr inbounds %class.Matrix, ptr %6, i32 0, i32 6
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = load i64, ptr %5, align 8, !tbaa !14
  %33 = getelementptr inbounds float, ptr %31, i64 %32
  %34 = load float, ptr %33, align 4, !tbaa !15
  %35 = fdiv float %34, %29
  store float %35, ptr %33, align 4, !tbaa !15
  br label %36

36:                                               ; preds = %24
  %37 = load i64, ptr %5, align 8, !tbaa !14
  %38 = add i64 %37, 1
  store i64 %38, ptr %5, align 8, !tbaa !14
  br label %18, !llvm.loop !18

39:                                               ; preds = %23
  ret void
}

attributes #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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !12, i64 32}
!10 = !{!"_ZTS6Matrix", !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !6, i64 40, !13, i64 48}
!11 = !{!"_ZTS11DEVICE_NAME", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!10, !6, i64 40}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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 [100 x i8], align 1
@__FUNCTION__._ZN10CPU_Matrix17divideElementwiseEf = external hidden unnamed_addr constant [18 x i8], align 1

declare void @_Z10_my_assertbPKciS0_(i1 noundef zeroext, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare noundef i64 @_ZNK6Matrix15get_numElementsEv(ptr noundef nonnull align 8 dereferenceable(49)) local_unnamed_addr #0

declare noundef ptr @_ZNK6Matrix8get_dataEv(ptr noundef nonnull align 8 dereferenceable(49)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10CPU_Matrix17divideElementwiseER6Matrix(ptr nocapture noundef nonnull readonly align 8 dereferenceable(49) %0, ptr noundef nonnull align 8 dereferenceable(49) %1) unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %8, label %5

5:                                                ; preds = %2
  %6 = tail call noundef i64 @_ZNK6Matrix15get_numElementsEv(ptr noundef nonnull align 8 dereferenceable(49) %1)
  %7 = icmp eq i64 %4, %6
  br label %8

8:                                                ; preds = %5, %2
  %9 = phi i1 [ false, %2 ], [ %7, %5 ]
  tail call void @_Z10_my_assertbPKciS0_(i1 noundef zeroext %9, ptr noundef nonnull @.str, i32 noundef 120, ptr noundef nonnull @__FUNCTION__._ZN10CPU_Matrix17divideElementwiseEf)
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %.not8 = icmp eq i64 %10, 0
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  br label %12

._crit_edge:                                      ; preds = %12, %8
  ret void

12:                                               ; preds = %.lr.ph, %12
  %.07 = phi i64 [ 0, %.lr.ph ], [ %20, %12 ]
  %13 = tail call noundef ptr @_ZNK6Matrix8get_dataEv(ptr noundef nonnull align 8 dereferenceable(49) %1)
  %14 = getelementptr inbounds float, ptr %13, i64 %.07
  %15 = load float, ptr %14, align 4, !tbaa !13
  %16 = load ptr, ptr %11, align 8, !tbaa !15
  %17 = getelementptr inbounds float, ptr %16, i64 %.07
  %18 = load float, ptr %17, align 4, !tbaa !13
  %19 = fdiv float %18, %15
  store float %19, ptr %17, align 4, !tbaa !13
  %20 = add nuw i64 %.07, 1
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %12, label %._crit_edge, !llvm.loop !16
}

attributes #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 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, !10, i64 32}
!6 = !{!"_ZTS6Matrix", !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !12, i64 48}
!7 = !{!"_ZTS11DEVICE_NAME", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = !{!6, !11, i64 40}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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