; LLVM IR from thuhcsi/Crystal.TTVS :: Xface/XFace/src/XMath/Matrix4.ll (ZN5XMath7Matrix4mlERKS0_)

; 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.XMath::Matrix4" = type { [16 x float] }

; 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: mustprogress uwtable
define dso_local void @_ZN5XMath7Matrix4mlERKS0_(ptr dead_on_unwind noalias writable sret(%"class.XMath::Matrix4") align 4 %0, ptr noundef nonnull align 4 dereferenceable(64) %1, ptr noundef nonnull align 4 dereferenceable(64) %2) #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i1, align 1
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8
  store i1 false, ptr %7, align 1
  call void @_ZN5XMath7Matrix4C1Ev(ptr noundef nonnull align 4 dereferenceable(64) %0)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %66, %3
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 4
  br i1 %17, label %18, label %69

18:                                               ; preds = %15
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %62, %18
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 4
  br i1 %21, label %22, label %65

22:                                               ; preds = %19
  store double 0.000000e+00, ptr %8, align 8, !tbaa !11
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %46, %22
  %24 = load i32, ptr %11, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 4
  br i1 %25, label %26, label %53

26:                                               ; preds = %23
  %27 = getelementptr inbounds %"class.XMath::Matrix4", ptr %14, i32 0, i32 0
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = mul nsw i32 %29, 4
  %31 = add nsw i32 %28, %30
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [16 x float], ptr %27, i64 0, i64 %32
  %34 = load float, ptr %33, align 4, !tbaa !13
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = mul nsw i32 %36, 4
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = add nsw i32 %37, %38
  %40 = invoke noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %35, i32 noundef %39)
          to label %41 unwind label %49

41:                                               ; preds = %26
  %42 = fmul float %34, %40
  %43 = fpext float %42 to double
  %44 = load double, ptr %8, align 8, !tbaa !11
  %45 = fadd double %44, %43
  store double %45, ptr %8, align 8, !tbaa !11
  br label %46

46:                                               ; preds = %41
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %11, align 4, !tbaa !9
  br label %23, !llvm.loop !15

49:                                               ; preds = %53, %26
  %50 = landingpad { ptr, i32 }
          cleanup
  %51 = extractvalue { ptr, i32 } %50, 0
  store ptr %51, ptr %12, align 8
  %52 = extractvalue { ptr, i32 } %50, 1
  store i32 %52, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @_ZN5XMath7Matrix4D2Ev(ptr noundef nonnull align 4 dereferenceable(64) %0) #3
  br label %73

53:                                               ; preds = %23
  %54 = load double, ptr %8, align 8, !tbaa !11
  %55 = fptrunc double %54 to float
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = mul nsw i32 %57, 4
  %59 = add nsw i32 %56, %58
  %60 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %0, i32 noundef %59)
          to label %61 unwind label %49

61:                                               ; preds = %53
  store float %55, ptr %60, align 4, !tbaa !13
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %10, align 4, !tbaa !9
  br label %19, !llvm.loop !17

65:                                               ; preds = %19
  br label %66

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

69:                                               ; preds = %15
  store i1 true, ptr %7, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %70 = load i1, ptr %7, align 1
  br i1 %70, label %72, label %71

71:                                               ; preds = %69
  call void @_ZN5XMath7Matrix4D2Ev(ptr noundef nonnull align 4 dereferenceable(64) %0) #3
  br label %72

72:                                               ; preds = %71, %69
  ret void

73:                                               ; preds = %49
  %74 = load ptr, ptr %12, align 8
  %75 = load i32, ptr %13, align 4
  %76 = insertvalue { ptr, i32 } poison, ptr %74, 0
  %77 = insertvalue { ptr, i32 } %76, i32 %75, 1
  resume { ptr, i32 } %77
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64), i32 noundef) #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64), i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5XMath7Matrix4D2Ev(ptr noundef nonnull align 4 dereferenceable(64)) unnamed_addr #2 align 2

declare void @_ZN5XMath7Matrix4C1Ev(ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


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

%"class.XMath::Matrix4" = type { [16 x float] }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5XMath7Matrix4mlERKS0_(ptr dead_on_unwind noalias writable sret(%"class.XMath::Matrix4") align 4 %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(64) %1, ptr noundef nonnull align 4 dereferenceable(64) %2) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN5XMath7Matrix4C1Ev(ptr noundef nonnull align 4 dereferenceable(64) %0)
  br label %.preheader19

.preheader19:                                     ; preds = %3, %.preheader19
  %indvars.iv = phi i64 [ 0, %3 ], [ %indvars.iv.next, %.preheader19 ]
  %4 = getelementptr inbounds [16 x float], ptr %1, i64 0, i64 %indvars.iv
  %5 = load float, ptr %4, align 4, !tbaa !5
  %6 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 0)
  %7 = fmul float %5, %6
  %8 = fpext float %7 to double
  %9 = fadd double %8, 0.000000e+00
  %10 = add nuw nsw i64 %indvars.iv, 4
  %11 = getelementptr inbounds [16 x float], ptr %1, i64 0, i64 %10
  %12 = load float, ptr %11, align 4, !tbaa !5
  %13 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 1)
  %14 = fmul float %12, %13
  %15 = fpext float %14 to double
  %16 = fadd double %9, %15
  %17 = add nuw nsw i64 %indvars.iv, 8
  %18 = getelementptr inbounds [16 x float], ptr %1, i64 0, i64 %17
  %19 = load float, ptr %18, align 4, !tbaa !5
  %20 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 2)
  %21 = fmul float %19, %20
  %22 = fpext float %21 to double
  %23 = fadd double %16, %22
  %24 = add nuw nsw i64 %indvars.iv, 12
  %25 = getelementptr inbounds [16 x float], ptr %1, i64 0, i64 %24
  %26 = load float, ptr %25, align 4, !tbaa !5
  %27 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 3)
  %28 = fmul float %26, %27
  %29 = fpext float %28 to double
  %30 = fadd double %23, %29
  %31 = fptrunc double %30 to float
  %32 = trunc nuw nsw i64 %indvars.iv to i32
  %33 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %0, i32 noundef %32)
  store float %31, ptr %33, align 4, !tbaa !5
  %34 = load float, ptr %4, align 4, !tbaa !5
  %35 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 4)
  %36 = fmul float %34, %35
  %37 = fpext float %36 to double
  %38 = fadd double %37, 0.000000e+00
  %39 = load float, ptr %11, align 4, !tbaa !5
  %40 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 5)
  %41 = fmul float %39, %40
  %42 = fpext float %41 to double
  %43 = fadd double %38, %42
  %44 = load float, ptr %18, align 4, !tbaa !5
  %45 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 6)
  %46 = fmul float %44, %45
  %47 = fpext float %46 to double
  %48 = fadd double %43, %47
  %49 = load float, ptr %25, align 4, !tbaa !5
  %50 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 7)
  %51 = fmul float %49, %50
  %52 = fpext float %51 to double
  %53 = fadd double %48, %52
  %54 = fptrunc double %53 to float
  %55 = trunc nuw nsw i64 %10 to i32
  %56 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %0, i32 noundef %55)
  store float %54, ptr %56, align 4, !tbaa !5
  %57 = load float, ptr %4, align 4, !tbaa !5
  %58 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 8)
  %59 = fmul float %57, %58
  %60 = fpext float %59 to double
  %61 = fadd double %60, 0.000000e+00
  %62 = load float, ptr %11, align 4, !tbaa !5
  %63 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 9)
  %64 = fmul float %62, %63
  %65 = fpext float %64 to double
  %66 = fadd double %61, %65
  %67 = load float, ptr %18, align 4, !tbaa !5
  %68 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 10)
  %69 = fmul float %67, %68
  %70 = fpext float %69 to double
  %71 = fadd double %66, %70
  %72 = load float, ptr %25, align 4, !tbaa !5
  %73 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 11)
  %74 = fmul float %72, %73
  %75 = fpext float %74 to double
  %76 = fadd double %71, %75
  %77 = fptrunc double %76 to float
  %78 = trunc nuw nsw i64 %17 to i32
  %79 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %0, i32 noundef %78)
  store float %77, ptr %79, align 4, !tbaa !5
  %80 = load float, ptr %4, align 4, !tbaa !5
  %81 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 12)
  %82 = fmul float %80, %81
  %83 = fpext float %82 to double
  %84 = fadd double %83, 0.000000e+00
  %85 = load float, ptr %11, align 4, !tbaa !5
  %86 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 13)
  %87 = fmul float %85, %86
  %88 = fpext float %87 to double
  %89 = fadd double %84, %88
  %90 = load float, ptr %18, align 4, !tbaa !5
  %91 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 14)
  %92 = fmul float %90, %91
  %93 = fpext float %92 to double
  %94 = fadd double %89, %93
  %95 = load float, ptr %25, align 4, !tbaa !5
  %96 = tail call noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %2, i32 noundef 15)
  %97 = fmul float %95, %96
  %98 = fpext float %97 to double
  %99 = fadd double %94, %98
  %100 = fptrunc double %99 to float
  %101 = trunc nuw nsw i64 %24 to i32
  %102 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64) %0, i32 noundef %101)
  store float %100, ptr %102, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 4
  br i1 %exitcond.not, label %103, label %.preheader19, !llvm.loop !9

103:                                              ; preds = %.preheader19
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64), i32 noundef) local_unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN5XMath7Matrix4ixEi(ptr noundef nonnull align 4 dereferenceable(64), i32 noundef) local_unnamed_addr #1 align 2

declare void @_ZN5XMath7Matrix4C1Ev(ptr) local_unnamed_addr

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

!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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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