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

; 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.HandleMemory = type { i32, i32, i32, i32, ptr, i32, i32, ptr, i32 }

@.str = external hidden unnamed_addr constant [84 x i8], align 1
@__FUNCTION__.mMemoryCreate = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @mMemoryBlockCreate(i32 noundef, i32 noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @endMemory(ptr noundef) #2

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

24:                                               ; preds = %3
  br label %25

25:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = icmp sgt i32 %26, 0
  %28 = zext i1 %27 to i32
  store i32 %28, ptr %10, align 4, !tbaa !5
  %29 = load i32, ptr %10, align 4, !tbaa !5
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %33

31:                                               ; preds = %25
  %32 = load i32, ptr %10, align 4, !tbaa !5
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %32, i32 noundef -1, ptr noundef @.str, i32 noundef 421, ptr noundef @__FUNCTION__.mMemoryCreate, ptr noundef @.str.4)
  br label %33

33:                                               ; preds = %31, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %36, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %100

37:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %38 = load ptr, ptr %9, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.MHandle, ptr %38, i32 0, i32 3
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  store ptr %40, ptr %12, align 8, !tbaa !9
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = icmp slt i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %37
  store i32 64, ptr %7, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %43, %37
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = load ptr, ptr %12, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.HandleMemory, ptr %46, i32 0, i32 1
  store i32 %45, ptr %47, align 4, !tbaa !17
  %48 = load ptr, ptr %12, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.HandleMemory, ptr %48, i32 0, i32 0
  store i32 0, ptr %49, align 8, !tbaa !19
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = load ptr, ptr %12, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.HandleMemory, ptr %51, i32 0, i32 2
  store i32 %50, ptr %52, align 8, !tbaa !20
  %53 = load ptr, ptr %12, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.HandleMemory, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !20
  %56 = load ptr, ptr %8, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.MList, ptr %56, i32 0, i32 0
  store i32 %55, ptr %57, align 8, !tbaa !21
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = mul i64 %59, 8
  %61 = call noalias ptr @malloc(i64 noundef %60) #6
  %62 = load ptr, ptr %8, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.MList, ptr %62, i32 0, i32 1
  store ptr %61, ptr %63, align 8, !tbaa !22
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = icmp slt i32 %64, 0
  br i1 %65, label %66, label %74

66:                                               ; preds = %44
  %67 = load ptr, ptr %8, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.MList, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !22
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = mul i64 %71, 8
  call void @llvm.memset.p0.i64(ptr align 8 %69, i8 0, i64 %72, i1 false)
  %73 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %73, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %99

74:                                               ; preds = %44
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = add nsw i32 %75, 15
  %77 = ashr i32 %76, 4
  %78 = shl i32 %77, 4
  store i32 %78, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %94, %74
  %80 = load i32, ptr %13, align 4, !tbaa !5
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = icmp slt i32 %80, %81
  br i1 %82, label %84, label %83

83:                                               ; preds = %79
  store i32 4, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %97

84:                                               ; preds = %79
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = load i32, ptr %7, align 4, !tbaa !5
  %87 = call ptr @mMemoryBlockCreate(i32 noundef %85, i32 noundef %86)
  %88 = load ptr, ptr %8, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.MList, ptr %88, i32 0, i32 1
  %90 = load ptr, ptr %89, align 8, !tbaa !22
  %91 = load i32, ptr %13, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds ptr, ptr %90, i64 %92
  store ptr %87, ptr %93, align 8, !tbaa !9
  br label %94

94:                                               ; preds = %84
  %95 = load i32, ptr %13, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %13, align 4, !tbaa !5
  br label %79, !llvm.loop !23

97:                                               ; preds = %83
  %98 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %98, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %99

99:                                               ; preds = %97, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %100

100:                                              ; preds = %99, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %101 = load ptr, ptr %4, align 8
  ret ptr %101
}

declare ptr @ObjectAlloc(i32 noundef) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { nounwind 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { nounwind 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 = !{!"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 4}
!15 = !{!"MHandle", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!16 = !{!15, !10, i64 16}
!17 = !{!18, !6, i64 4}
!18 = !{!"HandleMemory", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !10, i64 16, !6, i64 24, !6, i64 28, !10, i64 32, !6, i64 40}
!19 = !{!18, !6, i64 0}
!20 = !{!18, !6, i64 8}
!21 = !{!13, !6, i64 0}
!22 = !{!13, !10, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; 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 [84 x i8], align 1
@__FUNCTION__.mMemoryCreate = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @mMemoryBlockCreate(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @endMemory(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @mMemoryCreate(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = tail call ptr @ObjectAlloc(i32 noundef 16) #4
  %5 = getelementptr inbounds i8, ptr %4, i64 -4
  store i32 628699680, ptr %5, align 4, !tbaa !5
  %6 = tail call ptr @GetHandle(ptr noundef %4, i32 noundef 48, i32 noundef 628699680, ptr noundef nonnull @endMemory) #4
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  store volatile i32 1, ptr %7, align 4, !tbaa !12
  %8 = icmp slt i32 %0, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %3
  %10 = icmp sgt i32 %1, 0
  br i1 %10, label %11, label %.loopexit

11:                                               ; preds = %9
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 421, ptr noundef nonnull @__FUNCTION__.mMemoryCreate, ptr noundef nonnull @.str.4) #4
  br label %.loopexit

12:                                               ; preds = %3
  %13 = getelementptr inbounds i8, ptr %6, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = icmp slt i32 %2, 0
  %spec.store.select = select i1 %15, i32 64, i32 %2
  %16 = getelementptr inbounds i8, ptr %14, i64 4
  store i32 %spec.store.select, ptr %16, align 4, !tbaa !15
  store i32 0, ptr %14, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %14, i64 8
  store i32 %0, ptr %17, align 8, !tbaa !18
  store i32 %0, ptr %4, align 8, !tbaa !19
  %18 = zext nneg i32 %0 to i64
  %19 = shl nuw nsw i64 %18, 3
  %20 = tail call noalias ptr @malloc(i64 noundef %19) #5
  %21 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %20, ptr %21, align 8, !tbaa !20
  %22 = icmp slt i32 %1, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %12
  tail call void @llvm.memset.p0.i64(ptr align 8 %20, i8 0, i64 %19, i1 false)
  br label %.loopexit

24:                                               ; preds = %12
  %25 = add nuw nsw i32 %1, 15
  %26 = and i32 %25, 2147483632
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %24, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %24 ]
  %27 = tail call ptr @mMemoryBlockCreate(i32 noundef %26, i32 noundef %spec.store.select)
  %28 = load ptr, ptr %21, align 8, !tbaa !20
  %29 = getelementptr inbounds ptr, ptr %28, i64 %indvars.iv
  store ptr %27, ptr %29, align 8, !tbaa !21
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %18
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !22

.loopexit:                                        ; preds = %.lr.ph, %24, %23, %9, %11
  ret ptr %4
}

declare ptr @ObjectAlloc(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { nounwind 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, !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 4}
!13 = !{!"MHandle", !8, i64 0, !8, i64 4, !11, i64 8, !11, i64 16}
!14 = !{!13, !11, i64 16}
!15 = !{!16, !8, i64 4}
!16 = !{!"HandleMemory", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !11, i64 16, !8, i64 24, !8, i64 28, !11, i64 32, !8, i64 40}
!17 = !{!16, !8, i64 0}
!18 = !{!16, !8, i64 8}
!19 = !{!7, !8, i64 0}
!20 = !{!7, !11, i64 8}
!21 = !{!11, !11, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass