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

; 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.HandleMemoryAlloc = type { ptr, [256 x i32] }

@morn_memory_handle = external dso_local global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [78 x i8], align 1
@__FUNCTION__.MemoryFree = external hidden unnamed_addr constant [11 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [44 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

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

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local void @MemoryFree(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %18 = load ptr, ptr @morn_memory_handle, align 8, !tbaa !5
  store ptr %18, ptr %9, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  %22 = zext i1 %21 to i32
  store i32 %22, ptr %10, align 4, !tbaa !9
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %19
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %26, i32 noundef -1, ptr noundef @.str.2, i32 noundef 358, ptr noundef @__FUNCTION__.MemoryFree, ptr noundef @.str.5, ptr noundef %27)
  br label %28

28:                                               ; preds = %25, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.HandleMemoryAlloc, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = call ptr @m_MapRead(ptr noundef %33, ptr noundef %5, i32 noundef -1, ptr noundef inttoptr (i64 8 to ptr), ptr noundef null)
  store ptr %34, ptr %11, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  %38 = zext i1 %37 to i32
  store i32 %38, ptr %12, align 4, !tbaa !9
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %35
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %42, i32 noundef -1, ptr noundef @.str.2, i32 noundef 360, ptr noundef @__FUNCTION__.MemoryFree, ptr noundef @.str.5, ptr noundef %43)
  br label %44

44:                                               ; preds = %41, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds i32, ptr %47, i64 2
  store ptr %48, ptr %13, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %50 = load ptr, ptr %13, align 8, !tbaa !5
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds i32, ptr %51, i64 1
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %50, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !13
  %57 = sext i8 %56 to i32
  store i32 %57, ptr %14, align 4, !tbaa !9
  %58 = load i32, ptr %14, align 4, !tbaa !9
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %65

60:                                               ; preds = %49
  %61 = load i32, ptr %14, align 4, !tbaa !9
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = getelementptr inbounds i32, ptr %63, i64 2
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %61, i32 noundef -1, ptr noundef @.str.2, i32 noundef 362, ptr noundef @__FUNCTION__.MemoryFree, ptr noundef @.str.6, ptr noundef %62, ptr noundef %64)
  br label %65

65:                                               ; preds = %60, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %68, ptr %15, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %67
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %70 = load ptr, ptr %15, align 8, !tbaa !5
  %71 = getelementptr inbounds i64, ptr %70, i64 -1
  %72 = load i64, ptr %71, align 8, !tbaa !14
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = getelementptr inbounds i32, ptr %73, i64 0
  %75 = load i32, ptr %74, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = icmp ne i64 %72, %76
  %78 = zext i1 %77 to i32
  store i32 %78, ptr %16, align 4, !tbaa !9
  %79 = load i32, ptr %16, align 4, !tbaa !9
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %86

81:                                               ; preds = %69
  %82 = load i32, ptr %16, align 4, !tbaa !9
  %83 = load ptr, ptr %15, align 8, !tbaa !5
  %84 = load ptr, ptr %15, align 8, !tbaa !5
  %85 = getelementptr inbounds i64, ptr %84, i64 -1
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %82, i32 noundef -1, ptr noundef @.str.2, i32 noundef 365, ptr noundef @__FUNCTION__.MemoryFree, ptr noundef @.str.7, ptr noundef %83, ptr noundef %85)
  br label %86

86:                                               ; preds = %81, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  br label %89

89:                                               ; preds = %88
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %90 = load ptr, ptr %15, align 8, !tbaa !5
  %91 = load ptr, ptr %11, align 8, !tbaa !5
  %92 = getelementptr inbounds i32, ptr %91, i64 0
  %93 = load i32, ptr %92, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i64, ptr %90, i64 %94
  %96 = load i64, ptr %95, align 8, !tbaa !14
  %97 = load ptr, ptr %11, align 8, !tbaa !5
  %98 = getelementptr inbounds i32, ptr %97, i64 0
  %99 = load i32, ptr %98, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  %101 = icmp ne i64 %96, %100
  %102 = zext i1 %101 to i32
  store i32 %102, ptr %17, align 4, !tbaa !9
  %103 = load i32, ptr %17, align 4, !tbaa !9
  %104 = icmp ne i32 %103, 0
  br i1 %104, label %105, label %114

105:                                              ; preds = %89
  %106 = load i32, ptr %17, align 4, !tbaa !9
  %107 = load ptr, ptr %15, align 8, !tbaa !5
  %108 = load ptr, ptr %15, align 8, !tbaa !5
  %109 = load ptr, ptr %11, align 8, !tbaa !5
  %110 = getelementptr inbounds i32, ptr %109, i64 0
  %111 = load i32, ptr %110, align 4, !tbaa !9
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds i64, ptr %108, i64 %112
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %106, i32 noundef -1, ptr noundef @.str.2, i32 noundef 366, ptr noundef @__FUNCTION__.MemoryFree, ptr noundef @.str.7, ptr noundef %107, ptr noundef %113)
  br label %114

114:                                              ; preds = %105, %89
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %115

115:                                              ; preds = %114
  br label %116

116:                                              ; preds = %115
  %117 = load ptr, ptr %13, align 8, !tbaa !5
  %118 = load ptr, ptr %11, align 8, !tbaa !5
  %119 = getelementptr inbounds i32, ptr %118, i64 1
  %120 = load i32, ptr %119, align 4, !tbaa !9
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds i8, ptr %117, i64 %121
  %123 = load ptr, ptr %6, align 8, !tbaa !5
  %124 = load i32, ptr %7, align 4, !tbaa !9
  %125 = load ptr, ptr %8, align 8, !tbaa !5
  %126 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %122, ptr noundef @.str.8, ptr noundef %123, i32 noundef %124, ptr noundef %125) #4
  %127 = load ptr, ptr %15, align 8, !tbaa !5
  %128 = getelementptr inbounds i64, ptr %127, i64 -1
  call void @m_Free(ptr noundef %128)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

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

declare ptr @m_MapRead(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { "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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"HandleMemoryAlloc", !6, i64 0, !7, i64 8}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}


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

@morn_memory_handle = external dso_local local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [78 x i8], align 1
@__FUNCTION__.MemoryFree = external hidden unnamed_addr constant [11 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [44 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @MemoryFree(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr @morn_memory_handle, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %4
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str.2, i32 noundef 358, ptr noundef nonnull @__FUNCTION__.MemoryFree, ptr noundef nonnull @.str.5, ptr noundef %0) #3
  br label %9

9:                                                ; preds = %8, %4
  %10 = load ptr, ptr %6, align 8, !tbaa !9
  %11 = call ptr @m_MapRead(ptr noundef %10, ptr noundef nonnull %5, i32 noundef -1, ptr noundef nonnull inttoptr (i64 8 to ptr), ptr noundef null) #3
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %15

13:                                               ; preds = %9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str.2, i32 noundef 360, ptr noundef nonnull @__FUNCTION__.MemoryFree, ptr noundef nonnull @.str.5, ptr noundef %14) #3
  br label %15

15:                                               ; preds = %13, %9
  %16 = getelementptr inbounds i8, ptr %11, i64 8
  %17 = getelementptr inbounds i8, ptr %11, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %16, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !13
  %.not = icmp eq i8 %21, 0
  br i1 %.not, label %25, label %22

22:                                               ; preds = %15
  %23 = sext i8 %21 to i32
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %23, i32 noundef -1, ptr noundef nonnull @.str.2, i32 noundef 362, ptr noundef nonnull @__FUNCTION__.MemoryFree, ptr noundef nonnull @.str.6, ptr noundef %24, ptr noundef nonnull %16) #3
  br label %25

25:                                               ; preds = %22, %15
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 -8
  %28 = load i64, ptr %27, align 8, !tbaa !14
  %29 = load i32, ptr %11, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %.not32 = icmp eq i64 %28, %30
  br i1 %.not32, label %32, label %31

31:                                               ; preds = %25
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str.2, i32 noundef 365, ptr noundef nonnull @__FUNCTION__.MemoryFree, ptr noundef nonnull @.str.7, ptr noundef nonnull %26, ptr noundef nonnull %27) #3
  %.pre = load i32, ptr %11, align 4, !tbaa !11
  %.pre34 = sext i32 %.pre to i64
  br label %32

32:                                               ; preds = %31, %25
  %.pre-phi = phi i64 [ %.pre34, %31 ], [ %28, %25 ]
  %33 = getelementptr inbounds i64, ptr %26, i64 %.pre-phi
  %34 = load i64, ptr %33, align 8, !tbaa !14
  %.not33 = icmp eq i64 %34, %.pre-phi
  br i1 %.not33, label %36, label %35

35:                                               ; preds = %32
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str.2, i32 noundef 366, ptr noundef nonnull @__FUNCTION__.MemoryFree, ptr noundef nonnull @.str.7, ptr noundef nonnull %26, ptr noundef nonnull %33) #3
  br label %36

36:                                               ; preds = %35, %32
  %37 = load i32, ptr %17, align 4, !tbaa !11
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %16, i64 %38
  %40 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %39, ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %1, i32 noundef %2, ptr noundef %3) #3
  call void @m_Free(ptr noundef nonnull %27)
  ret void
}

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

declare ptr @m_MapRead(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { nofree 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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"HandleMemoryAlloc", !6, i64 0, !7, i64 8}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}


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