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

; 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_Matrix16uniformRandomizeEff = external hidden unnamed_addr constant [17 x i8], align 1

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

; 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 float @llvm.fmuladd.f32(float, float, float) #2

; 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_Matrix16uniformRandomizeEff(ptr noundef nonnull align 8 dereferenceable(49) %0, float noundef %1, float noundef %2) unnamed_addr #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  store float %2, ptr %6, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  %11 = getelementptr inbounds %class.Matrix, ptr %10, i32 0, i32 5
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = icmp ugt i64 %12, 0
  call void @_Z10_my_assertbPKciS0_(i1 noundef zeroext %13, ptr noundef @.str, i32 noundef 61, ptr noundef @__FUNCTION__._ZN10CPU_Matrix16uniformRandomizeEff)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !16
  br label %14

14:                                               ; preds = %49, %3
  %15 = load i64, ptr %7, align 8, !tbaa !16
  %16 = getelementptr inbounds %class.Matrix, ptr %10, i32 0, i32 3
  %17 = load i64, ptr %16, align 8, !tbaa !17
  %18 = icmp ult i64 %15, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %52

20:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 0, ptr %9, align 8, !tbaa !16
  br label %21

21:                                               ; preds = %45, %20
  %22 = load i64, ptr %9, align 8, !tbaa !16
  %23 = getelementptr inbounds %class.Matrix, ptr %10, i32 0, i32 4
  %24 = load i64, ptr %23, align 8, !tbaa !18
  %25 = icmp ult i64 %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %48

27:                                               ; preds = %21
  %28 = load float, ptr %5, align 4, !tbaa !9
  %29 = call i32 @rand() #5
  %30 = sitofp i32 %29 to float
  %31 = fdiv float %30, 0x41E0000000000000
  %32 = load float, ptr %6, align 4, !tbaa !9
  %33 = load float, ptr %5, align 4, !tbaa !9
  %34 = fsub float %32, %33
  %35 = call float @llvm.fmuladd.f32(float %31, float %34, float %28)
  %36 = getelementptr inbounds %class.Matrix, ptr %10, i32 0, i32 6
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  %38 = load i64, ptr %9, align 8, !tbaa !16
  %39 = load i64, ptr %7, align 8, !tbaa !16
  %40 = getelementptr inbounds %class.Matrix, ptr %10, i32 0, i32 4
  %41 = load i64, ptr %40, align 8, !tbaa !18
  %42 = mul i64 %39, %41
  %43 = add i64 %38, %42
  %44 = getelementptr inbounds float, ptr %37, i64 %43
  store float %35, ptr %44, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %27
  %46 = load i64, ptr %9, align 8, !tbaa !16
  %47 = add i64 %46, 1
  store i64 %47, ptr %9, align 8, !tbaa !16
  br label %21, !llvm.loop !20

48:                                               ; preds = %26
  br label %49

49:                                               ; preds = %48
  %50 = load i64, ptr %7, align 8, !tbaa !16
  %51 = add i64 %50, 1
  store i64 %51, ptr %7, align 8, !tbaa !16
  br label %14, !llvm.loop !22

52:                                               ; preds = %19
  ret void
}

; Function Attrs: nounwind
declare i32 @rand() #4

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { 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 #5 = { 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, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !14, i64 32}
!12 = !{!"_ZTS6Matrix", !13, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !6, i64 40, !15, i64 48}
!13 = !{!"_ZTS11DEVICE_NAME", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!12, !14, i64 16}
!18 = !{!12, !14, i64 24}
!19 = !{!12, !6, i64 40}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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_Matrix16uniformRandomizeEff = external hidden unnamed_addr constant [17 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10CPU_Matrix16uniformRandomizeEff(ptr nocapture noundef nonnull readonly align 8 dereferenceable(49) %0, float noundef %1, float noundef %2) unnamed_addr #2 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp ne i64 %5, 0
  tail call void @_Z10_my_assertbPKciS0_(i1 noundef zeroext %6, ptr noundef nonnull @.str, i32 noundef 61, ptr noundef nonnull @__FUNCTION__._ZN10CPU_Matrix16uniformRandomizeEff)
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i64, ptr %7, align 8, !tbaa !13
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %._crit_edge12, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = fsub float %2, %1
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = load i64, ptr %9, align 8, !tbaa !14
  %.not13 = icmp eq i64 %12, 0
  br i1 %.not13, label %._crit_edge12, label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %13 = phi i64 [ %15, %._crit_edge ], [ %8, %.preheader.lr.ph ]
  %14 = phi i64 [ %16, %._crit_edge ], [ 1, %.preheader.lr.ph ]
  %.0911 = phi i64 [ %17, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %.not14 = icmp eq i64 %14, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

._crit_edge12:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %3
  ret void

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i64, ptr %7, align 8, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %15 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %13, %.preheader ]
  %16 = phi i64 [ %24, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %17 = add nuw i64 %.0911, 1
  %18 = icmp ult i64 %17, %15
  br i1 %18, label %.preheader, label %._crit_edge12, !llvm.loop !15

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.010 = phi i64 [ %28, %.lr.ph ], [ 0, %.preheader ]
  %19 = tail call i32 @rand() #4
  %20 = sitofp i32 %19 to float
  %21 = fmul float %20, 0x3E00000000000000
  %22 = tail call float @llvm.fmuladd.f32(float %21, float %10, float %1)
  %23 = load ptr, ptr %11, align 8, !tbaa !18
  %24 = load i64, ptr %9, align 8, !tbaa !14
  %25 = mul i64 %24, %.0911
  %26 = getelementptr float, ptr %23, i64 %.010
  %27 = getelementptr float, ptr %26, i64 %25
  store float %22, ptr %27, align 4, !tbaa !19
  %28 = add nuw i64 %.010, 1
  %29 = icmp ult i64 %28, %24
  br i1 %29, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !21
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #3

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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 "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 #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, !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 = !{!6, !10, i64 16}
!14 = !{!6, !10, i64 24}
!15 = distinct !{!15, !16, !17}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.unswitch.partial.disable"}
!18 = !{!6, !11, i64 40}
!19 = !{!20, !20, i64 0}
!20 = !{!"float", !8, i64 0}
!21 = distinct !{!21, !16}


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