; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_array)

; 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._MArray = type { i32, i16, i16, %union.anon.0 }
%union.anon.0 = type { ptr }
%struct.MHandle = type { i32, i32, ptr, ptr }
%struct.HandleArrayCreate = type { ptr, ptr, [8 x i64], i32, i32, i32, ptr, i32 }
%struct.MMemoryBlock = type { i32, i32, ptr, ptr, ptr, i32 }

@.str = external hidden unnamed_addr constant [77 x i8], align 1
@__FUNCTION__.ArrayCreate = external hidden unnamed_addr constant [12 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 @endArrayCreate(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 @ArrayCreate(i32 noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = call ptr @ObjectAlloc(i32 noundef 16)
  store ptr %11, ptr %7, align 8, !tbaa !9
  %12 = load ptr, ptr %7, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.HandleList, ptr %12, i64 -1
  %14 = getelementptr inbounds %struct.HandleList, ptr %13, i32 0, i32 4
  store i32 -1275154524, ptr %14, align 4, !tbaa !11
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %17, %3
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct._MArray, ptr %20, i32 0, i32 0
  store i32 %19, ptr %21, align 8, !tbaa !14
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %18
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %24, %18
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = trunc i32 %26 to i16
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct._MArray, ptr %28, i32 0, i32 1
  store i16 %27, ptr %29, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %30 = load ptr, ptr %7, align 8, !tbaa !9
  %31 = call ptr @GetHandle(ptr noundef %30, i32 noundef 112, i32 noundef -1275154524, ptr noundef @endArrayCreate)
  store ptr %31, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.MHandle, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  store ptr %34, ptr %9, align 8, !tbaa !9
  %35 = load ptr, ptr %9, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.HandleArrayCreate, ptr %35, i32 0, i32 3
  store i32 1, ptr %36, align 8, !tbaa !20
  %37 = load ptr, ptr %7, align 8, !tbaa !9
  %38 = load ptr, ptr %9, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.HandleArrayCreate, ptr %38, i32 0, i32 0
  store ptr %37, ptr %39, align 8, !tbaa !22
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct._MArray, ptr %40, i32 0, i32 3
  store ptr null, ptr %41, align 8, !tbaa !23
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct._MArray, ptr %42, i32 0, i32 2
  store i16 0, ptr %43, align 2, !tbaa !24
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.HandleArrayCreate, ptr %44, i32 0, i32 6
  store ptr null, ptr %45, align 8, !tbaa !25
  %46 = load ptr, ptr %9, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.HandleArrayCreate, ptr %46, i32 0, i32 4
  store i32 0, ptr %47, align 4, !tbaa !26
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  %49 = icmp eq ptr %48, null
  br i1 %49, label %71, label %50

50:                                               ; preds = %25
  %51 = load ptr, ptr %6, align 8, !tbaa !9
  %52 = ptrtoint ptr %51 to i64
  %53 = icmp eq i64 %52, -1
  br i1 %53, label %71, label %54

54:                                               ; preds = %50
  br label %55

55:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = icmp eq i32 %56, 0
  %58 = zext i1 %57 to i32
  store i32 %58, ptr %10, align 4, !tbaa !5
  %59 = load i32, ptr %10, align 4, !tbaa !5
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %63

61:                                               ; preds = %55
  %62 = load i32, ptr %10, align 4, !tbaa !5
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %62, i32 noundef -1, ptr noundef @.str, i32 noundef 91, ptr noundef @__FUNCTION__.ArrayCreate, ptr noundef @.str.2)
  br label %63

63:                                               ; preds = %61, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  %66 = load ptr, ptr %6, align 8, !tbaa !9
  %67 = load ptr, ptr %7, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct._MArray, ptr %67, i32 0, i32 3
  store ptr %66, ptr %68, align 8, !tbaa !23
  %69 = load ptr, ptr %9, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.HandleArrayCreate, ptr %69, i32 0, i32 3
  store i32 0, ptr %70, align 8, !tbaa !20
  br label %114

71:                                               ; preds = %50, %25
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = icmp sgt i32 %72, 0
  br i1 %73, label %74, label %113

74:                                               ; preds = %71
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = icmp sgt i32 %75, 256
  br i1 %76, label %77, label %79

77:                                               ; preds = %74
  %78 = load i32, ptr %4, align 4, !tbaa !5
  br label %80

79:                                               ; preds = %74
  br label %80

80:                                               ; preds = %79, %77
  %81 = phi i32 [ %78, %77 ], [ 256, %79 ]
  %82 = sext i32 %81 to i64
  %83 = call i64 @mBinaryCeil(i64 noundef %82)
  %84 = trunc i64 %83 to i32
  store i32 %84, ptr %4, align 4, !tbaa !5
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = mul nsw i32 %85, %86
  %88 = call ptr @mMemoryBlockCreate(i32 noundef %87, i32 noundef 0)
  %89 = load ptr, ptr %9, align 8, !tbaa !9
  %90 = getelementptr inbounds %struct.HandleArrayCreate, ptr %89, i32 0, i32 6
  store ptr %88, ptr %90, align 8, !tbaa !25
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = load ptr, ptr %9, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.HandleArrayCreate, ptr %92, i32 0, i32 4
  store i32 %91, ptr %93, align 4, !tbaa !26
  %94 = load i32, ptr %5, align 4, !tbaa !5
  %95 = load ptr, ptr %9, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.HandleArrayCreate, ptr %95, i32 0, i32 5
  store i32 %94, ptr %96, align 8, !tbaa !27
  %97 = load ptr, ptr %9, align 8, !tbaa !9
  %98 = getelementptr inbounds %struct.HandleArrayCreate, ptr %97, i32 0, i32 6
  %99 = load ptr, ptr %98, align 8, !tbaa !25
  %100 = getelementptr inbounds %struct.MMemoryBlock, ptr %99, i32 0, i32 2
  %101 = load ptr, ptr %100, align 8, !tbaa !28
  %102 = load ptr, ptr %7, align 8, !tbaa !9
  %103 = getelementptr inbounds %struct._MArray, ptr %102, i32 0, i32 3
  store ptr %101, ptr %103, align 8, !tbaa !23
  %104 = load i32, ptr %4, align 4, !tbaa !5
  %105 = load ptr, ptr %7, align 8, !tbaa !9
  %106 = getelementptr inbounds %struct._MArray, ptr %105, i32 0, i32 0
  %107 = load i32, ptr %106, align 8, !tbaa !14
  %108 = sub nsw i32 %104, %107
  %109 = and i32 %108, 65535
  %110 = trunc i32 %109 to i16
  %111 = load ptr, ptr %7, align 8, !tbaa !9
  %112 = getelementptr inbounds %struct._MArray, ptr %111, i32 0, i32 2
  store i16 %110, ptr %112, align 2, !tbaa !24
  br label %113

113:                                              ; preds = %80, %71
  br label %114

114:                                              ; preds = %113, %65
  br label %115

115:                                              ; preds = %114
  %116 = load ptr, ptr %7, align 8, !tbaa !9
  call void @m_PropertyFunction(ptr noundef %116, ptr noundef @.str.3, ptr noundef @mornMemoryDevice, ptr noundef null)
  br label %117

117:                                              ; preds = %115
  br label %118

118:                                              ; preds = %117
  %119 = load ptr, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %119
}

declare ptr @ObjectAlloc(i32 noundef) #2

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

declare i64 @mBinaryCeil(i64 noundef) #2

declare ptr @mMemoryBlockCreate(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, !6, i64 0}
!15 = !{!"_MArray", !6, i64 0, !16, i64 4, !16, i64 6, !7, i64 8}
!16 = !{!"short", !7, i64 0}
!17 = !{!15, !16, i64 4}
!18 = !{!19, !10, i64 16}
!19 = !{!"MHandle", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!20 = !{!21, !6, i64 80}
!21 = !{!"HandleArrayCreate", !10, i64 0, !10, i64 8, !7, i64 16, !6, i64 80, !6, i64 84, !6, i64 88, !10, i64 96, !6, i64 104}
!22 = !{!21, !10, i64 0}
!23 = !{!7, !7, i64 0}
!24 = !{!15, !16, i64 6}
!25 = !{!21, !10, i64 96}
!26 = !{!21, !6, i64 84}
!27 = !{!21, !6, i64 88}
!28 = !{!29, !10, i64 8}
!29 = !{!"MMemoryBlock", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !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"

@.str = external hidden unnamed_addr constant [77 x i8], align 1
@__FUNCTION__.ArrayCreate = external hidden unnamed_addr constant [12 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 @endArrayCreate(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 @ArrayCreate(i32 noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @ObjectAlloc(i32 noundef 16) #3
  %5 = getelementptr inbounds i8, ptr %4, i64 -4
  store i32 -1275154524, ptr %5, align 4, !tbaa !5
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %0, i32 0)
  store i32 %spec.store.select, ptr %4, align 8, !tbaa !12
  %spec.store.select3 = tail call i32 @llvm.smax.i32(i32 %1, i32 0)
  %6 = trunc i32 %spec.store.select3 to i16
  %7 = getelementptr inbounds i8, ptr %4, i64 4
  store i16 %6, ptr %7, align 4, !tbaa !15
  %8 = tail call ptr @GetHandle(ptr noundef nonnull %4, i32 noundef 112, i32 noundef -1275154524, ptr noundef nonnull @endArrayCreate) #3
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  %11 = getelementptr inbounds i8, ptr %10, i64 80
  store i32 1, ptr %11, align 8, !tbaa !18
  store ptr %4, ptr %10, align 8, !tbaa !20
  %12 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr null, ptr %12, align 8, !tbaa !21
  %13 = getelementptr inbounds i8, ptr %4, i64 6
  store i16 0, ptr %13, align 2, !tbaa !22
  %14 = getelementptr inbounds i8, ptr %10, i64 96
  store ptr null, ptr %14, align 8, !tbaa !23
  %15 = getelementptr inbounds i8, ptr %10, i64 84
  store i32 0, ptr %15, align 4, !tbaa !24
  %magicptr = ptrtoint ptr %2 to i64
  switch i64 %magicptr, label %16 [
    i64 -1, label %20
    i64 0, label %20
  ]

16:                                               ; preds = %3
  %17 = icmp slt i32 %0, 1
  br i1 %17, label %18, label %19

18:                                               ; preds = %16
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 91, ptr noundef nonnull @__FUNCTION__.ArrayCreate, ptr noundef nonnull @.str.2) #3
  br label %19

19:                                               ; preds = %18, %16
  store ptr %2, ptr %12, align 8, !tbaa !21
  store i32 0, ptr %11, align 8, !tbaa !18
  br label %34

20:                                               ; preds = %3, %3
  %.not = icmp slt i32 %1, 1
  br i1 %.not, label %34, label %21

21:                                               ; preds = %20
  %22 = tail call i32 @llvm.smax.i32(i32 %0, i32 256)
  %23 = zext nneg i32 %22 to i64
  %24 = tail call i64 @mBinaryCeil(i64 noundef %23) #3
  %25 = trunc i64 %24 to i32
  %26 = mul nsw i32 %spec.store.select3, %25
  %27 = tail call ptr @mMemoryBlockCreate(i32 noundef %26, i32 noundef 0) #3
  store ptr %27, ptr %14, align 8, !tbaa !23
  store i32 %25, ptr %15, align 4, !tbaa !24
  %28 = getelementptr inbounds i8, ptr %10, i64 88
  store i32 %spec.store.select3, ptr %28, align 8, !tbaa !25
  %29 = getelementptr inbounds i8, ptr %27, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !26
  store ptr %30, ptr %12, align 8, !tbaa !21
  %31 = load i32, ptr %4, align 8, !tbaa !12
  %32 = sub nsw i32 %25, %31
  %33 = trunc i32 %32 to i16
  store i16 %33, ptr %13, align 2, !tbaa !22
  br label %34

34:                                               ; preds = %19, %21, %20
  tail call void @m_PropertyFunction(ptr noundef nonnull %4, ptr noundef nonnull @.str.3, ptr noundef nonnull @mornMemoryDevice, ptr noundef null) #3
  ret ptr %4
}

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 i64 @mBinaryCeil(i64 noundef) local_unnamed_addr #1

declare ptr @mMemoryBlockCreate(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, !8, i64 0}
!13 = !{!"_MArray", !8, i64 0, !14, i64 4, !14, i64 6, !9, i64 8}
!14 = !{!"short", !9, i64 0}
!15 = !{!13, !14, i64 4}
!16 = !{!17, !11, i64 16}
!17 = !{!"MHandle", !8, i64 0, !8, i64 4, !11, i64 8, !11, i64 16}
!18 = !{!19, !8, i64 80}
!19 = !{!"HandleArrayCreate", !11, i64 0, !11, i64 8, !9, i64 16, !8, i64 80, !8, i64 84, !8, i64 88, !11, i64 96, !8, i64 104}
!20 = !{!19, !11, i64 0}
!21 = !{!9, !9, i64 0}
!22 = !{!13, !14, i64 6}
!23 = !{!19, !11, i64 96}
!24 = !{!19, !8, i64 84}
!25 = !{!19, !8, i64 88}
!26 = !{!27, !11, i64 8}
!27 = !{!"MMemoryBlock", !8, i64 0, !8, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !8, i64 32}


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