; LLVM IR from jingweizhanghuai/Morn :: src/math (morn_matrix)

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

%struct.MMatrix = type { i32, i32, ptr }
%struct.HandleList = type { %struct.MList, i32, i32, i32, i32 }
%struct.MList = type { i32, ptr }
%struct.MHandle = type { i32, i32, ptr, ptr }
%struct.HandleMatrixCreate = type { ptr, ptr, [8 x i64], i32, i32, i32, ptr, ptr }
%struct.MMemoryBlock = type { i32, i32, ptr, ptr, ptr, i32 }

@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; 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

declare ptr @mMemoryCreate(i32 noundef, i32 noundef, i32 noundef) #1

declare void @m_PropertyFunction(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare void @mornMemoryDevice(ptr noundef, ptr noundef) #1

declare void @mMemoryIndex(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @mMatrixMemory(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.MMatrix, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.MMatrix, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = mul nsw i32 %9, %12
  %14 = sext i32 %13 to i64
  %15 = mul i64 %14, 4
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %3, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.MMatrix, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = getelementptr inbounds ptr, ptr %19, i64 0
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds float, ptr %21, i64 0
  store ptr %22, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.HandleList, ptr %23, i64 -1
  %25 = getelementptr inbounds %struct.HandleList, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.MList, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = getelementptr inbounds ptr, ptr %27, i64 0
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MHandle, ptr %29, i32 0, i32 3
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  store ptr %31, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.HandleMatrixCreate, ptr %32, i32 0, i32 7
  %34 = load ptr, ptr %33, align 8, !tbaa !20
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %48

36:                                               ; preds = %1
  %37 = load i32, ptr %3, align 4, !tbaa !13
  %38 = call ptr @mMemoryCreate(i32 noundef 1, i32 noundef %37, i32 noundef 0)
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.HandleMatrixCreate, ptr %39, i32 0, i32 7
  store ptr %38, ptr %40, align 8, !tbaa !20
  br label %41

41:                                               ; preds = %36
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.HandleMatrixCreate, ptr %43, i32 0, i32 7
  %45 = load ptr, ptr %44, align 8, !tbaa !20
  call void @m_PropertyFunction(ptr noundef %42, ptr noundef @.str.3, ptr noundef @mornMemoryDevice, ptr noundef %45)
  br label %46

46:                                               ; preds = %41
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.HandleMatrixCreate, ptr %49, i32 0, i32 7
  %51 = load ptr, ptr %50, align 8, !tbaa !20
  %52 = getelementptr inbounds %struct.MList, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !22
  %54 = getelementptr inbounds ptr, ptr %53, i64 0
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  store ptr %55, ptr %6, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.MMemoryBlock, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !23
  %59 = load i32, ptr %3, align 4, !tbaa !13
  %60 = icmp ne i32 %58, %59
  br i1 %60, label %61, label %76

61:                                               ; preds = %48
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.HandleMatrixCreate, ptr %62, i32 0, i32 7
  %64 = load ptr, ptr %63, align 8, !tbaa !20
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.MMatrix, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !9
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.MMatrix, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !12
  %71 = sext i32 %70 to i64
  %72 = mul i64 %71, 4
  %73 = trunc i64 %72 to i32
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.HandleMatrixCreate, ptr %74, i32 0, i32 6
  call void @mMemoryIndex(ptr noundef %64, i32 noundef %67, i32 noundef %73, ptr noundef %75, i32 noundef 1)
  br label %76

76:                                               ; preds = %61, %48
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.MMemoryBlock, ptr %77, i32 0, i32 2
  %79 = load ptr, ptr %78, align 8, !tbaa !25
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = icmp ne ptr %79, %80
  br i1 %81, label %82, label %89

82:                                               ; preds = %76
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.MMemoryBlock, ptr %83, i32 0, i32 2
  %85 = load ptr, ptr %84, align 8, !tbaa !25
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = load i32, ptr %3, align 4, !tbaa !13
  %88 = sext i32 %87 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %85, ptr align 4 %86, i64 %88, i1 false)
  br label %89

89:                                               ; preds = %82, %76
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret ptr %90
}

; 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 willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"MMatrix", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 8}
!15 = !{!16, !6, i64 8}
!16 = !{!"HandleList", !17, i64 0, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!17 = !{!"MList", !11, i64 0, !6, i64 8}
!18 = !{!19, !6, i64 16}
!19 = !{!"MHandle", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!20 = !{!21, !6, i64 104}
!21 = !{!"HandleMatrixCreate", !6, i64 0, !6, i64 8, !7, i64 16, !11, i64 80, !11, i64 84, !11, i64 88, !6, i64 96, !6, i64 104}
!22 = !{!17, !6, i64 8}
!23 = !{!24, !11, i64 4}
!24 = !{!"MMemoryBlock", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!25 = !{!24, !6, i64 8}


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

@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

declare ptr @mMemoryCreate(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @m_PropertyFunction(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @mornMemoryDevice(ptr noundef, ptr noundef) #0

declare void @mMemoryIndex(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @mMatrixMemory(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !11
  %5 = shl i32 %2, 2
  %6 = mul i32 %5, %4
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 -24
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %14, i64 104
  %16 = load ptr, ptr %15, align 8, !tbaa !19
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %20

18:                                               ; preds = %1
  %19 = tail call ptr @mMemoryCreate(i32 noundef 1, i32 noundef %6, i32 noundef 0) #3
  store ptr %19, ptr %15, align 8, !tbaa !19
  tail call void @m_PropertyFunction(ptr noundef nonnull %0, ptr noundef nonnull @.str.3, ptr noundef nonnull @mornMemoryDevice, ptr noundef %19) #3
  %.pre = load ptr, ptr %15, align 8, !tbaa !19
  br label %20

20:                                               ; preds = %18, %1
  %21 = phi ptr [ %.pre, %18 ], [ %16, %1 ]
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !21
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %24, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !22
  %.not = icmp eq i32 %26, %6
  br i1 %.not, label %32, label %27

27:                                               ; preds = %20
  %28 = load i32, ptr %0, align 8, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !11
  %30 = shl i32 %29, 2
  %31 = getelementptr inbounds i8, ptr %14, i64 96
  tail call void @mMemoryIndex(ptr noundef nonnull %21, i32 noundef %28, i32 noundef %30, ptr noundef nonnull %31, i32 noundef 1) #3
  br label %32

32:                                               ; preds = %27, %20
  %33 = getelementptr inbounds i8, ptr %24, i64 8
  %34 = load ptr, ptr %33, align 8, !tbaa !24
  %.not22 = icmp eq ptr %34, %9
  br i1 %.not22, label %37, label %35

35:                                               ; preds = %32
  %36 = sext i32 %6 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %34, ptr align 4 %9, i64 %36, i1 false)
  br label %37

37:                                               ; preds = %35, %32
  ret ptr %24
}

; 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 = { "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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"MMatrix", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 8}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !10, i64 8}
!15 = !{!"HandleList", !16, i64 0, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!16 = !{!"MList", !7, i64 0, !10, i64 8}
!17 = !{!18, !10, i64 16}
!18 = !{!"MHandle", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!19 = !{!20, !10, i64 104}
!20 = !{!"HandleMatrixCreate", !10, i64 0, !10, i64 8, !8, i64 16, !7, i64 80, !7, i64 84, !7, i64 88, !10, i64 96, !10, i64 104}
!21 = !{!16, !10, i64 8}
!22 = !{!23, !7, i64 4}
!23 = !{!"MMemoryBlock", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32}
!24 = !{!23, !10, i64 8}


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