; LLVM IR from nobuyuki83/delfem2 :: examples_cuda/002_MatMat/main.ll (Z10h_multiplyPfPKfS1_j)

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

14:                                               ; preds = %69, %4
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = icmp ult i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %72

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %65, %19
  %21 = load i32, ptr %11, align 4, !tbaa !9
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = icmp ult i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %68

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store float 0.000000e+00, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %52, %25
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp ult i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %55

31:                                               ; preds = %26
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = mul i32 %33, %34
  %36 = load i32, ptr %13, align 4, !tbaa !9
  %37 = add i32 %35, %36
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds float, ptr %32, i64 %38
  %40 = load float, ptr %39, align 4, !tbaa !11
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = load i32, ptr %13, align 4, !tbaa !9
  %44 = mul i32 %42, %43
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = add i32 %44, %45
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds float, ptr %41, i64 %47
  %49 = load float, ptr %48, align 4, !tbaa !11
  %50 = load float, ptr %12, align 4, !tbaa !11
  %51 = call float @llvm.fmuladd.f32(float %40, float %49, float %50)
  store float %51, ptr %12, align 4, !tbaa !11
  br label %52

52:                                               ; preds = %31
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %13, align 4, !tbaa !9
  br label %26, !llvm.loop !13

55:                                               ; preds = %30
  %56 = load float, ptr %12, align 4, !tbaa !11
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = mul i32 %58, %59
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = add i32 %60, %61
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds float, ptr %57, i64 %63
  store float %56, ptr %64, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %65

65:                                               ; preds = %55
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %11, align 4, !tbaa !9
  br label %20, !llvm.loop !15

68:                                               ; preds = %24
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %9, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %9, align 4, !tbaa !9
  br label %14, !llvm.loop !16

72:                                               ; preds = %18
  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 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

attributes #0 = { mustprogress 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !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: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z10h_multiplyPfPKfS1_j(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %.preheader26.preheader

.preheader26.preheader:                           ; preds = %4
  %wide.trip.count35 = zext i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count35, 1
  %5 = icmp eq i32 %3, 1
  %unroll_iter = and i64 %wide.trip.count35, 4294967294
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader26

.preheader26:                                     ; preds = %.preheader26.preheader, %8
  %.02430 = phi i32 [ %9, %8 ], [ 0, %.preheader26.preheader ]
  %6 = mul i32 %.02430, %3
  br label %.preheader

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

.preheader:                                       ; preds = %.preheader26, %21
  %indvars.iv32 = phi i64 [ 0, %.preheader26 ], [ %indvars.iv.next33, %21 ]
  %7 = trunc nuw nsw i64 %indvars.iv32 to i32
  br i1 %5, label %.unr-lcssa, label %.preheader.new

8:                                                ; preds = %21
  %9 = add nuw nsw i32 %.02430, 1
  %exitcond37.not = icmp eq i32 %9, %3
  br i1 %exitcond37.not, label %._crit_edge, label %.preheader26, !llvm.loop !5

.unr-lcssa:                                       ; preds = %.preheader.new, %.preheader
  %.lcssa.ph = phi float [ poison, %.preheader ], [ %47, %.preheader.new ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader ], [ %indvars.iv.next.1, %.preheader.new ]
  %.02227.unr = phi float [ 0.000000e+00, %.preheader ], [ %47, %.preheader.new ]
  br i1 %lcmp.mod.not, label %21, label %.epilog-lcssa

.epilog-lcssa:                                    ; preds = %.unr-lcssa
  %10 = trunc nuw nsw i64 %indvars.iv.unr to i32
  %11 = add i32 %6, %10
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds float, ptr %1, i64 %12
  %14 = load float, ptr %13, align 4, !tbaa !7
  %15 = mul i32 %10, %3
  %16 = add i32 %15, %7
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds float, ptr %2, i64 %17
  %19 = load float, ptr %18, align 4, !tbaa !7
  %20 = tail call float @llvm.fmuladd.f32(float %14, float %19, float %.02227.unr)
  br label %21

21:                                               ; preds = %.unr-lcssa, %.epilog-lcssa
  %.lcssa = phi float [ %.lcssa.ph, %.unr-lcssa ], [ %20, %.epilog-lcssa ]
  %22 = add i32 %6, %7
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds float, ptr %0, i64 %23
  store float %.lcssa, ptr %24, align 4, !tbaa !7
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond36.not = icmp eq i64 %indvars.iv.next33, %wide.trip.count35
  br i1 %exitcond36.not, label %8, label %.preheader, !llvm.loop !11

.preheader.new:                                   ; preds = %.preheader, %.preheader.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.preheader.new ], [ 0, %.preheader ]
  %.02227 = phi float [ %47, %.preheader.new ], [ 0.000000e+00, %.preheader ]
  %niter = phi i64 [ %niter.next.1, %.preheader.new ], [ 0, %.preheader ]
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  %26 = add i32 %6, %25
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds float, ptr %1, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !7
  %30 = mul i32 %25, %3
  %31 = add i32 %30, %7
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds float, ptr %2, i64 %32
  %34 = load float, ptr %33, align 4, !tbaa !7
  %35 = tail call float @llvm.fmuladd.f32(float %29, float %34, float %.02227)
  %36 = trunc i64 %indvars.iv to i32
  %37 = or disjoint i32 %36, 1
  %38 = add i32 %6, %37
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %1, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !7
  %42 = mul i32 %37, %3
  %43 = add i32 %42, %7
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds float, ptr %2, i64 %44
  %46 = load float, ptr %45, align 4, !tbaa !7
  %47 = tail call float @llvm.fmuladd.f32(float %41, float %46, float %35)
  %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 %.unr-lcssa, label %.preheader.new, !llvm.loop !12
}

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

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


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