; LLVM IR from Slingshot-Physics/slingshot-community :: common/math/src/heap_matrix.ll (ZN10HeapMatrixC2ERKS_)

; 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.HeapMatrix = type { i32, i32, i32, i32, i32, [12 x i8], ptr, [8 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: mustprogress uwtable
declare dso_local void @_ZN10HeapMatrix10InitializeEv(ptr noundef nonnull align 16 dereferenceable(40)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10HeapMatrixC2ERKS_(ptr noundef nonnull align 16 dereferenceable(40) %0, ptr noundef nonnull align 16 dereferenceable(40) %1) unnamed_addr #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 0
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %class.HeapMatrix, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 16, !tbaa !9
  store i32 %9, ptr %6, align 16, !tbaa !9
  %10 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 1
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %class.HeapMatrix, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !12
  store i32 %13, ptr %10, align 4, !tbaa !12
  %14 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 2
  %15 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 0
  %16 = load i32, ptr %15, align 16, !tbaa !9
  %17 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 0
  %18 = load i32, ptr %17, align 16, !tbaa !9
  %19 = urem i32 %18, 4
  %20 = icmp ne i32 %19, 0
  %21 = zext i1 %20 to i32
  %22 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 0
  %23 = load i32, ptr %22, align 16, !tbaa !9
  %24 = urem i32 %23, 4
  %25 = sub i32 4, %24
  %26 = mul i32 %21, %25
  %27 = add i32 %16, %26
  store i32 %27, ptr %14, align 8, !tbaa !13
  %28 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 3
  %29 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !12
  %31 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = icmp ugt i32 %32, 1
  %34 = zext i1 %33 to i32
  %35 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !12
  %37 = urem i32 %36, 4
  %38 = icmp ne i32 %37, 0
  %39 = zext i1 %38 to i32
  %40 = mul nsw i32 %34, %39
  %41 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !12
  %43 = urem i32 %42, 4
  %44 = sub i32 4, %43
  %45 = mul i32 %40, %44
  %46 = add i32 %30, %45
  store i32 %46, ptr %28, align 4, !tbaa !14
  %47 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 4
  %48 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 3
  %49 = load i32, ptr %48, align 4, !tbaa !14
  %50 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !13
  %52 = mul i32 %49, %51
  store i32 %52, ptr %47, align 16, !tbaa !15
  %53 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 4
  %54 = load i32, ptr %53, align 16, !tbaa !15
  %55 = zext i32 %54 to i64
  %56 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %55, i64 4)
  %57 = extractvalue { i64, i1 } %56, 1
  %58 = extractvalue { i64, i1 } %56, 0
  %59 = select i1 %57, i64 -1, i64 %58
  %60 = call noalias noundef nonnull ptr @_Znam(i64 noundef %59) #4
  %61 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 6
  store ptr %60, ptr %61, align 16, !tbaa !16
  call void @_ZN10HeapMatrix10InitializeEv(ptr noundef nonnull align 16 dereferenceable(40) %5)
  %62 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 6
  %63 = load ptr, ptr %62, align 16, !tbaa !16
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %class.HeapMatrix, ptr %64, i32 0, i32 6
  %66 = load ptr, ptr %65, align 16, !tbaa !16
  %67 = getelementptr inbounds %class.HeapMatrix, ptr %5, i32 0, i32 4
  %68 = load i32, ptr %67, align 16, !tbaa !15
  %69 = zext i32 %68 to i64
  %70 = mul i64 4, %69
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %63, ptr align 4 %66, i64 %70, i1 false)
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS10HeapMatrix", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !11, i64 12}
!15 = !{!10, !11, i64 16}
!16 = !{!10, !6, i64 32}


; 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: mustprogress uwtable
declare dso_local void @_ZN10HeapMatrix10InitializeEv(ptr noundef nonnull align 16 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10HeapMatrixC2ERKS_(ptr noundef nonnull align 16 dereferenceable(40) %0, ptr nocapture noundef nonnull readonly align 16 dereferenceable(40) %1) unnamed_addr #1 align 2 {
  %3 = load i32, ptr %1, align 16, !tbaa !5
  store i32 %3, ptr %0, align 16, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !11
  store i32 %6, ptr %4, align 4, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = and i32 %3, 3
  %.not = icmp eq i32 %8, 0
  %9 = sub nuw nsw i32 4, %8
  %10 = select i1 %.not, i32 0, i32 %9
  %11 = add i32 %10, %3
  store i32 %11, ptr %7, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 12
  %13 = icmp ugt i32 %6, 1
  %14 = and i32 %6, 3
  %15 = icmp ne i32 %14, 0
  %mulbool = and i1 %13, %15
  %16 = sub nuw nsw i32 4, %14
  %17 = select i1 %mulbool, i32 %16, i32 0
  %18 = add i32 %17, %6
  store i32 %18, ptr %12, align 4, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = mul i32 %18, %11
  store i32 %20, ptr %19, align 16, !tbaa !14
  %21 = zext i32 %20 to i64
  %22 = shl nuw nsw i64 %21, 2
  %23 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %22) #3
  %24 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %23, ptr %24, align 16, !tbaa !15
  tail call void @_ZN10HeapMatrix10InitializeEv(ptr noundef nonnull align 16 dereferenceable(40) %0)
  %25 = load ptr, ptr %24, align 16, !tbaa !15
  %26 = getelementptr inbounds i8, ptr %1, i64 32
  %27 = load ptr, ptr %26, align 16, !tbaa !15
  %28 = load i32, ptr %19, align 16, !tbaa !14
  %29 = zext i32 %28 to i64
  %30 = shl nuw nsw i64 %29, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %25, ptr align 4 %27, i64 %30, i1 false)
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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, !7, i64 0}
!6 = !{!"_ZTS10HeapMatrix", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 12}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !10, i64 32}


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