; 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.HandleList = type { %struct.MList, i32, i32, i32, i32 }
%struct.MList = type { i32, ptr }
%struct.MHandle = type { i32, i32, ptr, ptr }
%struct.HandleVectorCreate = type { ptr, ptr, [8 x i64], i32, i32, ptr }
%struct.MVector = type { i32, ptr }

@.str = external hidden unnamed_addr constant [78 x i8], align 1
@__FUNCTION__.VectorCreate = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @endVectorCreate(ptr noundef) #0

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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #2

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

; Function Attrs: nounwind uwtable
define dso_local ptr @VectorCreate(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %9 = call ptr @ObjectAlloc(i32 noundef 16)
  store ptr %9, ptr %5, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.HandleList, ptr %10, i64 -1
  %12 = getelementptr inbounds %struct.HandleList, ptr %11, i32 0, i32 4
  store i32 -66353028, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = call ptr @GetHandle(ptr noundef %13, i32 noundef 96, i32 noundef -66353028, ptr noundef @endVectorCreate)
  store ptr %14, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.MHandle, ptr %15, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  store ptr %17, ptr %7, align 8, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = load ptr, ptr %7, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.HandleVectorCreate, ptr %19, i32 0, i32 0
  store ptr %18, ptr %20, align 8, !tbaa !16
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %23, %2
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.MVector, ptr %26, i32 0, i32 0
  store i32 %25, ptr %27, align 8, !tbaa !18
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %49

30:                                               ; preds = %24
  br label %31

31:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = icmp eq ptr %32, null
  br i1 %33, label %38, label %34

34:                                               ; preds = %31
  %35 = load ptr, ptr %4, align 8, !tbaa !9
  %36 = ptrtoint ptr %35 to i64
  %37 = icmp eq i64 %36, -1
  br label %38

38:                                               ; preds = %34, %31
  %39 = phi i1 [ true, %31 ], [ %37, %34 ]
  %40 = xor i1 %39, true
  %41 = zext i1 %40 to i32
  store i32 %41, ptr %8, align 4, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %38
  %45 = load i32, ptr %8, align 4, !tbaa !5
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %45, i32 noundef -1, ptr noundef @.str, i32 noundef 39, ptr noundef @__FUNCTION__.VectorCreate, ptr noundef @.str.2)
  br label %46

46:                                               ; preds = %44, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %81

49:                                               ; preds = %24
  %50 = load ptr, ptr %4, align 8, !tbaa !9
  %51 = icmp eq ptr %50, null
  br i1 %51, label %56, label %52

52:                                               ; preds = %49
  %53 = load ptr, ptr %4, align 8, !tbaa !9
  %54 = ptrtoint ptr %53 to i64
  %55 = icmp eq i64 %54, -1
  br i1 %55, label %56, label %76

56:                                               ; preds = %52, %49
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = mul i64 %58, 4
  %60 = trunc i64 %59 to i32
  %61 = call ptr @mMemoryCreate(i32 noundef 1, i32 noundef %60, i32 noundef 0)
  %62 = load ptr, ptr %7, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.HandleVectorCreate, ptr %62, i32 0, i32 5
  store ptr %61, ptr %63, align 8, !tbaa !20
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = load ptr, ptr %7, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.HandleVectorCreate, ptr %65, i32 0, i32 4
  store i32 %64, ptr %66, align 4, !tbaa !21
  %67 = load ptr, ptr %7, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.HandleVectorCreate, ptr %67, i32 0, i32 5
  %69 = load ptr, ptr %68, align 8, !tbaa !20
  %70 = getelementptr inbounds %struct.MList, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !22
  %72 = getelementptr inbounds ptr, ptr %71, i64 0
  %73 = load ptr, ptr %72, align 8, !tbaa !9
  %74 = load ptr, ptr %5, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.MVector, ptr %74, i32 0, i32 1
  store ptr %73, ptr %75, align 8, !tbaa !23
  br label %80

76:                                               ; preds = %52
  %77 = load ptr, ptr %4, align 8, !tbaa !9
  %78 = load ptr, ptr %5, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.MVector, ptr %78, i32 0, i32 1
  store ptr %77, ptr %79, align 8, !tbaa !23
  br label %80

80:                                               ; preds = %76, %56
  br label %81

81:                                               ; preds = %80, %48
  br label %82

82:                                               ; preds = %81
  %83 = load ptr, ptr %5, align 8, !tbaa !9
  %84 = load ptr, ptr %7, align 8, !tbaa !9
  %85 = getelementptr inbounds %struct.HandleVectorCreate, ptr %84, i32 0, i32 5
  %86 = load ptr, ptr %85, align 8, !tbaa !20
  call void @m_PropertyFunction(ptr noundef %83, ptr noundef @.str.3, ptr noundef @mornMemoryDevice, ptr noundef %86)
  br label %87

87:                                               ; preds = %82
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %89
}

declare ptr @ObjectAlloc(i32 noundef) #2

declare ptr @GetHandle(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #2

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

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

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

attributes #0 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 28}
!12 = !{!"HandleList", !13, i64 0, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28}
!13 = !{!"MList", !6, i64 0, !10, i64 8}
!14 = !{!15, !10, i64 16}
!15 = !{!"MHandle", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!16 = !{!17, !10, i64 0}
!17 = !{!"HandleVectorCreate", !10, i64 0, !10, i64 8, !7, i64 16, !6, i64 80, !6, i64 84, !10, i64 88}
!18 = !{!19, !6, i64 0}
!19 = !{!"MVector", !6, i64 0, !10, i64 8}
!20 = !{!17, !10, i64 88}
!21 = !{!17, !6, i64 84}
!22 = !{!13, !10, i64 8}
!23 = !{!19, !10, 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 = external hidden unnamed_addr constant [78 x i8], align 1
@__FUNCTION__.VectorCreate = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @endVectorCreate(ptr noundef) #0

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @VectorCreate(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @ObjectAlloc(i32 noundef 16) #3
  %4 = getelementptr inbounds i8, ptr %3, i64 -4
  store i32 -66353028, ptr %4, align 4, !tbaa !5
  %5 = tail call ptr @GetHandle(ptr noundef %3, i32 noundef 96, i32 noundef -66353028, ptr noundef nonnull @endVectorCreate) #3
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  store ptr %3, ptr %7, align 8, !tbaa !14
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %0, i32 0)
  store i32 %spec.store.select, ptr %3, align 8, !tbaa !16
  %8 = icmp slt i32 %0, 1
  %magicptr = ptrtoint ptr %1 to i64
  br i1 %8, label %9, label %14

9:                                                ; preds = %2
  switch i64 %magicptr, label %10 [
    i64 -1, label %26
    i64 0, label %26
  ]

10:                                               ; preds = %9
  %11 = icmp ne ptr %1, null
  %12 = icmp ne ptr %1, inttoptr (i64 -1 to ptr)
  %.not28 = and i1 %11, %12
  %13 = zext i1 %.not28 to i32
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %13, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 39, ptr noundef nonnull @__FUNCTION__.VectorCreate, ptr noundef nonnull @.str.2) #3
  br label %26

14:                                               ; preds = %2
  switch i64 %magicptr, label %24 [
    i64 -1, label %15
    i64 0, label %15
  ]

15:                                               ; preds = %14, %14
  %16 = shl i32 %spec.store.select, 2
  %17 = tail call ptr @mMemoryCreate(i32 noundef 1, i32 noundef %16, i32 noundef 0) #3
  %18 = getelementptr inbounds i8, ptr %7, i64 88
  store ptr %17, ptr %18, align 8, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %7, i64 84
  store i32 %spec.store.select, ptr %19, align 4, !tbaa !19
  %20 = getelementptr inbounds i8, ptr %17, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  %22 = load ptr, ptr %21, align 8, !tbaa !21
  %23 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %22, ptr %23, align 8, !tbaa !22
  br label %26

24:                                               ; preds = %14
  %25 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %1, ptr %25, align 8, !tbaa !22
  br label %26

26:                                               ; preds = %10, %9, %9, %24, %15
  %27 = getelementptr inbounds i8, ptr %7, i64 88
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  tail call void @m_PropertyFunction(ptr noundef nonnull %3, ptr noundef nonnull @.str.3, ptr noundef nonnull @mornMemoryDevice, ptr noundef %28) #3
  ret ptr %3
}

declare ptr @ObjectAlloc(i32 noundef) local_unnamed_addr #1

declare ptr @GetHandle(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

attributes #0 = { 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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !8, i64 28}
!6 = !{!"HandleList", !7, i64 0, !8, i64 16, !8, i64 20, !8, i64 24, !8, i64 28}
!7 = !{!"MList", !8, i64 0, !11, i64 8}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!13, !11, i64 16}
!13 = !{!"MHandle", !8, i64 0, !8, i64 4, !11, i64 8, !11, i64 16}
!14 = !{!15, !11, i64 0}
!15 = !{!"HandleVectorCreate", !11, i64 0, !11, i64 8, !9, i64 16, !8, i64 80, !8, i64 84, !11, i64 88}
!16 = !{!17, !8, i64 0}
!17 = !{!"MVector", !8, i64 0, !11, i64 8}
!18 = !{!15, !11, i64 88}
!19 = !{!15, !8, i64 84}
!20 = !{!7, !11, i64 8}
!21 = !{!11, !11, i64 0}
!22 = !{!17, !11, i64 8}


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