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

; 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] }>

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #2

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

12:                                               ; preds = %3
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 4
  %15 = load i64, ptr %14, align 8, !tbaa !15
  %16 = icmp ne i64 %13, %15
  br i1 %16, label %17, label %48

17:                                               ; preds = %12, %3
  %18 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 5
  %19 = load i64, ptr %18, align 8, !tbaa !16
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = mul i64 %20, %21
  %23 = icmp ne i64 %19, %22
  br i1 %23, label %24, label %39

24:                                               ; preds = %17
  %25 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 6
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = icmp eq ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @_ZdaPv(ptr noundef %26) #4
  br label %29

29:                                               ; preds = %28, %24
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = mul i64 %30, %31
  %33 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %32, i64 4)
  %34 = extractvalue { i64, i1 } %33, 1
  %35 = extractvalue { i64, i1 } %33, 0
  %36 = select i1 %34, i64 -1, i64 %35
  %37 = call noalias noundef nonnull ptr @_Znam(i64 noundef %36) #5
  %38 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 6
  store ptr %37, ptr %38, align 8, !tbaa !17
  br label %39

39:                                               ; preds = %29, %17
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 3
  store i64 %40, ptr %41, align 8, !tbaa !11
  %42 = load i64, ptr %6, align 8, !tbaa !9
  %43 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 4
  store i64 %42, ptr %43, align 8, !tbaa !15
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = mul i64 %44, %45
  %47 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 5
  store i64 %46, ptr %47, align 8, !tbaa !16
  br label %48

48:                                               ; preds = %39, %12
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nobuiltin allocsize(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 = { nobuiltin 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 #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 = { builtin nounwind }
attributes #5 = { builtin allocsize(0) }

!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, !10, i64 16}
!12 = !{!"_ZTS6Matrix", !13, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !14, i64 48}
!13 = !{!"_ZTS11DEVICE_NAME", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !10, i64 24}
!16 = !{!12, !10, i64 32}
!17 = !{!12, !6, i64 40}


; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10CPU_Matrix6resizeEmm(ptr nocapture noundef nonnull align 8 dereferenceable(49) %0, i64 noundef %1, i64 noundef %2) unnamed_addr #2 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %5, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i64, ptr %6, align 8
  %.not11 = icmp eq i64 %7, %2
  %or.cond = select i1 %.not, i1 %.not11, i1 false
  br i1 %or.cond, label %23, label %8

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %11 = mul i64 %2, %1
  %.not12 = icmp eq i64 %10, %11
  br i1 %.not12, label %22, label %12

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = icmp eq ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  tail call void @_ZdaPv(ptr noundef nonnull %14) #3
  br label %17

17:                                               ; preds = %16, %12
  %18 = icmp ugt i64 %11, 4611686018427387903
  %19 = shl nuw i64 %11, 2
  %20 = select i1 %18, i64 -1, i64 %19
  %21 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %20) #4
  store ptr %21, ptr %13, align 8, !tbaa !14
  br label %22

22:                                               ; preds = %17, %8
  store i64 %1, ptr %4, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !15
  store i64 %11, ptr %9, align 8, !tbaa !13
  br label %23

23:                                               ; preds = %3, %22
  ret void
}

attributes #0 = { nobuiltin allocsize(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 = { nobuiltin 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 #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 = { builtin nounwind }
attributes #4 = { builtin allocsize(0) }

!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 16}
!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 32}
!14 = !{!6, !11, i64 40}
!15 = !{!6, !10, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass