; LLVM IR from Tencent-RoboticsX/jbdl :: src/jbdl/experimental/qpoases/src/Matrices.ll (ZNK7qpOASES11DenseMatrix9duplicateEv)

; 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.qpOASES::DenseMatrix" = type { ptr, i32, i32, i32, ptr, %"class.qpOASES::Matrix.base" }
%"class.qpOASES::Matrix.base" = type <{ ptr, i32 }>

; 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 nounwind uwtable
declare dso_local noundef i32 @_ZNK7qpOASES6Matrix16needToFreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(12)) #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK7qpOASES11DenseMatrix9duplicateEv(ptr noundef nonnull align 8 dereferenceable(32) %0) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #7
  store ptr null, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = getelementptr i8, ptr %8, i64 -24
  %10 = load i64, ptr %9, align 8
  %11 = getelementptr inbounds i8, ptr %7, i64 %10
  %12 = call noundef i32 @_ZNK7qpOASES6Matrix16needToFreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(12) %11)
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %14, label %54

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  %15 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 2
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = mul nsw i32 %16, %18
  %20 = sext i32 %19 to i64
  %21 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %20, i64 8)
  %22 = extractvalue { i64, i1 } %21, 1
  %23 = extractvalue { i64, i1 } %21, 0
  %24 = select i1 %22, i64 -1, i64 %23
  %25 = call noalias noundef nonnull ptr @_Znam(i64 noundef %24) #8
  store ptr %25, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 4
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 1
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = mul nsw i32 %30, %32
  %34 = zext i32 %33 to i64
  %35 = mul i64 %34, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %26, ptr align 8 %28, i64 %35, i1 false)
  %36 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 48) #8
  %37 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 2
  %40 = load i32, ptr %39, align 4, !tbaa !14
  %41 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 2
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  invoke void @_ZN7qpOASES11DenseMatrixC1EiiiPd(ptr noundef nonnull align 8 dereferenceable(32) %36, i32 noundef %38, i32 noundef %40, i32 noundef %42, ptr noundef %43)
          to label %44 unwind label %50

44:                                               ; preds = %14
  store ptr %36, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  %47 = getelementptr i8, ptr %46, i64 -24
  %48 = load i64, ptr %47, align 8
  %49 = getelementptr inbounds i8, ptr %45, i64 %48
  call void @_ZN7qpOASES6Matrix12doFreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(12) %49)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  br label %69

50:                                               ; preds = %14
  %51 = landingpad { ptr, i32 }
          cleanup
  %52 = extractvalue { ptr, i32 } %51, 0
  store ptr %52, ptr %5, align 8
  %53 = extractvalue { ptr, i32 } %51, 1
  store i32 %53, ptr %6, align 4
  call void @_ZdlPvm(ptr noundef %36, i64 noundef 48) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  br label %79

54:                                               ; preds = %1
  %55 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 48) #8
  %56 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 1
  %57 = load i32, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !14
  %60 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 2
  %61 = load i32, ptr %60, align 4, !tbaa !14
  %62 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 4
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  invoke void @_ZN7qpOASES11DenseMatrixC1EiiiPd(ptr noundef nonnull align 8 dereferenceable(32) %55, i32 noundef %57, i32 noundef %59, i32 noundef %61, ptr noundef %63)
          to label %64 unwind label %65

64:                                               ; preds = %54
  store ptr %55, ptr %3, align 8, !tbaa !5
  br label %69

65:                                               ; preds = %54
  %66 = landingpad { ptr, i32 }
          cleanup
  %67 = extractvalue { ptr, i32 } %66, 0
  store ptr %67, ptr %5, align 8
  %68 = extractvalue { ptr, i32 } %66, 1
  store i32 %68, ptr %6, align 4
  call void @_ZdlPvm(ptr noundef %55, i64 noundef 48) #9
  br label %79

69:                                               ; preds = %64, %44
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = icmp eq ptr %70, null
  br i1 %71, label %77, label %72

72:                                               ; preds = %69
  %73 = load ptr, ptr %70, align 8, !tbaa !9
  %74 = getelementptr i8, ptr %73, i64 -24
  %75 = load i64, ptr %74, align 8
  %76 = getelementptr inbounds i8, ptr %70, i64 %75
  br label %77

77:                                               ; preds = %72, %69
  %78 = phi ptr [ %76, %72 ], [ null, %69 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #7
  ret ptr %78

79:                                               ; preds = %65, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #7
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr %5, align 8
  %82 = load i32, ptr %6, align 4
  %83 = insertvalue { ptr, i32 } poison, ptr %81, 0
  %84 = insertvalue { ptr, i32 } %83, i32 %82, 1
  resume { ptr, i32 } %84
}

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

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

; 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) #6

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7qpOASES11DenseMatrixC1EiiiPd(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef, i32 noundef, ptr noundef) unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7qpOASES6Matrix12doFreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(12)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 #6 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { nounwind }
attributes #8 = { builtin allocsize(0) }
attributes #9 = { builtin 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTSN7qpOASES11DenseMatrixE", !13, i64 8, !13, i64 12, !13, i64 16, !6, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 12}
!15 = !{!12, !6, i64 24}


; 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 nounwind uwtable
declare dso_local noundef i32 @_ZNK7qpOASES6Matrix16needToFreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(12)) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull ptr @_ZNK7qpOASES11DenseMatrix9duplicateEv(ptr noundef nonnull align 8 dereferenceable(32) %0) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr i8, ptr %2, i64 -24
  %4 = load i64, ptr %3, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 %4
  %6 = tail call noundef i32 @_ZNK7qpOASES6Matrix16needToFreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(12) %5)
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %31

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !8
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %13 = mul nsw i32 %12, %10
  %14 = sext i32 %13 to i64
  %15 = icmp slt i32 %13, 0
  %16 = shl nsw i64 %14, 3
  %17 = select i1 %15, i64 -1, i64 %16
  %18 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %17) #5
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = zext i32 %13 to i64
  %22 = shl nuw nsw i64 %21, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %18, ptr align 8 %20, i64 %22, i1 false)
  %23 = tail call noalias noundef nonnull dereferenceable(48) ptr @_Znwm(i64 noundef 48) #5
  invoke void @_ZN7qpOASES11DenseMatrixC1EiiiPd(ptr noundef nonnull align 8 dereferenceable(32) %23, i32 noundef %10, i32 noundef %12, i32 noundef %12, ptr noundef nonnull %18)
          to label %24 unwind label %29

24:                                               ; preds = %8
  %25 = load ptr, ptr %23, align 8, !tbaa !5
  %26 = getelementptr i8, ptr %25, i64 -24
  %27 = load i64, ptr %26, align 8
  %28 = getelementptr inbounds i8, ptr %23, i64 %27
  tail call void @_ZN7qpOASES6Matrix12doFreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(12) %28)
  br label %41

29:                                               ; preds = %8
  %30 = landingpad { ptr, i32 }
          cleanup
  br label %46

31:                                               ; preds = %1
  %32 = tail call noalias noundef nonnull dereferenceable(48) ptr @_Znwm(i64 noundef 48) #5
  %33 = getelementptr inbounds i8, ptr %0, i64 8
  %34 = load i32, ptr %33, align 8, !tbaa !8
  %35 = getelementptr inbounds i8, ptr %0, i64 12
  %36 = load i32, ptr %35, align 4, !tbaa !13
  %37 = getelementptr inbounds i8, ptr %0, i64 24
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  invoke void @_ZN7qpOASES11DenseMatrixC1EiiiPd(ptr noundef nonnull align 8 dereferenceable(32) %32, i32 noundef %34, i32 noundef %36, i32 noundef %36, ptr noundef %38)
          to label %41 unwind label %39

39:                                               ; preds = %31
  %40 = landingpad { ptr, i32 }
          cleanup
  br label %46

41:                                               ; preds = %31, %24
  %.07 = phi ptr [ %23, %24 ], [ %32, %31 ]
  %42 = load ptr, ptr %.07, align 8, !tbaa !5
  %43 = getelementptr i8, ptr %42, i64 -24
  %44 = load i64, ptr %43, align 8
  %45 = getelementptr inbounds i8, ptr %.07, i64 %44
  ret ptr %45

46:                                               ; preds = %39, %29
  %.sink = phi ptr [ %32, %39 ], [ %23, %29 ]
  %.pn = phi { ptr, i32 } [ %40, %39 ], [ %30, %29 ]
  tail call void @_ZdlPvm(ptr noundef nonnull %.sink, i64 noundef 48) #6
  resume { ptr, i32 } %.pn
}

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

; 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) #4

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7qpOASES11DenseMatrixC1EiiiPd(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef, i32 noundef, ptr noundef) unnamed_addr #2 align 2

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

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


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