; LLVM IR from artvns/SimpleFvm :: simplefvm/src/MeshLoader/MeshTemplates (MeshTemplateP)

; 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.meshloader::MeshTemplateP" = type { ptr, ptr, i64, i64 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10meshloader13MeshTemplateP14createTemplateEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @_ZN10meshloader13MeshTemplateP12createMatrixEv(ptr noundef nonnull align 8 dereferenceable(32) %6)
  call void @_ZN10meshloader13MeshTemplateP20initializeWithZeroesEv(ptr noundef nonnull align 8 dereferenceable(32) %6)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %47, %1
  %8 = load i64, ptr %3, align 8, !tbaa !9
  %9 = getelementptr inbounds %"class.meshloader::MeshTemplateP", ptr %6, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = call noundef i64 @_ZNK10meshloader10BaseMatrix13getRowsAmountEv(ptr noundef nonnull align 8 dereferenceable(40) %10)
  %12 = icmp ult i64 %8, %11
  br i1 %12, label %14, label %13

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

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

15:                                               ; preds = %43, %14
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds %"class.meshloader::MeshTemplateP", ptr %6, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = call noundef i64 @_ZNK10meshloader10BaseMatrix13getColsAmountEv(ptr noundef nonnull align 8 dereferenceable(40) %18)
  %20 = icmp ult i64 %16, %19
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %15
  %23 = getelementptr inbounds %"class.meshloader::MeshTemplateP", ptr %6, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = load i64, ptr %3, align 8, !tbaa !9
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = call noundef signext i8 @_ZNK10meshloader10BaseMatrix8getValueEmm(ptr noundef nonnull align 8 dereferenceable(40) %24, i64 noundef %25, i64 noundef %26)
  %28 = sext i8 %27 to i32
  %29 = icmp ne i32 48, %28
  br i1 %29, label %30, label %42

30:                                               ; preds = %22
  %31 = getelementptr inbounds %"class.meshloader::MeshTemplateP", ptr %6, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load i64, ptr %3, align 8, !tbaa !9
  %34 = add i64 %33, 1
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = add i64 %35, 1
  %37 = getelementptr inbounds %"class.meshloader::MeshTemplateP", ptr %6, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load i64, ptr %3, align 8, !tbaa !9
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = call noundef signext i8 @_ZNK10meshloader10BaseMatrix8getValueEmm(ptr noundef nonnull align 8 dereferenceable(40) %38, i64 noundef %39, i64 noundef %40)
  call void @_ZN10meshloader10BaseMatrix8setValueEmmc(ptr noundef nonnull align 8 dereferenceable(40) %32, i64 noundef %34, i64 noundef %36, i8 noundef signext %41)
  br label %42

42:                                               ; preds = %30, %22
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %5, align 8, !tbaa !9
  br label %15, !llvm.loop !14

46:                                               ; preds = %21
  br label %47

47:                                               ; preds = %46
  %48 = load i64, ptr %3, align 8, !tbaa !9
  %49 = add i64 %48, 1
  store i64 %49, ptr %3, align 8, !tbaa !9
  br label %7, !llvm.loop !16

50:                                               ; preds = %13
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10meshloader13MeshTemplateP12createMatrixEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10meshloader13MeshTemplateP20initializeWithZeroesEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

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

declare noundef i64 @_ZNK10meshloader10BaseMatrix13getRowsAmountEv(ptr noundef nonnull align 8 dereferenceable(40)) #2

declare noundef i64 @_ZNK10meshloader10BaseMatrix13getColsAmountEv(ptr noundef nonnull align 8 dereferenceable(40)) #2

declare noundef signext i8 @_ZNK10meshloader10BaseMatrix8getValueEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #2

declare void @_ZN10meshloader10BaseMatrix8setValueEmmc(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef, i8 noundef signext) #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 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 = { "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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN10meshloader13MeshTemplatePE", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 uwtable
define dso_local void @_ZN10meshloader13MeshTemplateP14createTemplateEv(ptr noundef nonnull align 8 dereferenceable(32) %0) local_unnamed_addr #0 align 2 {
  tail call void @_ZN10meshloader13MeshTemplateP12createMatrixEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  tail call void @_ZN10meshloader13MeshTemplateP20initializeWithZeroesEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = tail call noundef i64 @_ZNK10meshloader10BaseMatrix13getRowsAmountEv(ptr noundef nonnull align 8 dereferenceable(40) %2)
  %.not14 = icmp eq i64 %3, 0
  br i1 %.not14, label %._crit_edge13, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %.01012 = phi i64 [ 0, %.preheader.lr.ph ], [ %.pre, %._crit_edge ]
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = tail call noundef i64 @_ZNK10meshloader10BaseMatrix13getColsAmountEv(ptr noundef nonnull align 8 dereferenceable(40) %5)
  %.not15 = icmp eq i64 %6, 0
  %.pre = add nuw i64 %.01012, 1
  br i1 %.not15, label %._crit_edge, label %.lr.ph

._crit_edge13:                                    ; preds = %._crit_edge, %1
  ret void

._crit_edge:                                      ; preds = %17, %.preheader
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = tail call noundef i64 @_ZNK10meshloader10BaseMatrix13getRowsAmountEv(ptr noundef nonnull align 8 dereferenceable(40) %7)
  %9 = icmp ult i64 %.pre, %8
  br i1 %9, label %.preheader, label %._crit_edge13, !llvm.loop !11

.lr.ph:                                           ; preds = %.preheader, %17
  %.011 = phi i64 [ %.pre-phi18, %17 ], [ 0, %.preheader ]
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = tail call noundef signext i8 @_ZNK10meshloader10BaseMatrix8getValueEmm(ptr noundef nonnull align 8 dereferenceable(40) %10, i64 noundef %.01012, i64 noundef %.011)
  %.not = icmp eq i8 %11, 48
  br i1 %.not, label %._crit_edge16, label %12

._crit_edge16:                                    ; preds = %.lr.ph
  %.pre17 = add nuw i64 %.011, 1
  br label %17

12:                                               ; preds = %.lr.ph
  %13 = load ptr, ptr %4, align 8, !tbaa !13
  %14 = add nuw i64 %.011, 1
  %15 = load ptr, ptr %0, align 8, !tbaa !5
  %16 = tail call noundef signext i8 @_ZNK10meshloader10BaseMatrix8getValueEmm(ptr noundef nonnull align 8 dereferenceable(40) %15, i64 noundef %.01012, i64 noundef %.011)
  tail call void @_ZN10meshloader10BaseMatrix8setValueEmmc(ptr noundef nonnull align 8 dereferenceable(40) %13, i64 noundef %.pre, i64 noundef %14, i8 noundef signext %16)
  br label %17

17:                                               ; preds = %._crit_edge16, %12
  %.pre-phi18 = phi i64 [ %.pre17, %._crit_edge16 ], [ %14, %12 ]
  %18 = load ptr, ptr %0, align 8, !tbaa !5
  %19 = tail call noundef i64 @_ZNK10meshloader10BaseMatrix13getColsAmountEv(ptr noundef nonnull align 8 dereferenceable(40) %18)
  %20 = icmp ult i64 %.pre-phi18, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10meshloader13MeshTemplateP12createMatrixEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10meshloader13MeshTemplateP20initializeWithZeroesEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

declare noundef i64 @_ZNK10meshloader10BaseMatrix13getRowsAmountEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1

declare noundef i64 @_ZNK10meshloader10BaseMatrix13getColsAmountEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1

declare noundef signext i8 @_ZNK10meshloader10BaseMatrix8getValueEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) local_unnamed_addr #1

declare void @_ZN10meshloader10BaseMatrix8setValueEmmc(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef, i8 noundef signext) local_unnamed_addr #1

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 = { "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, !7, i64 0}
!6 = !{!"_ZTSN10meshloader13MeshTemplatePE", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 8}
!14 = distinct !{!14, !12}


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