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

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

@morn_object = external dso_local thread_local global ptr, align 8
@morn_object_map = external dso_local global ptr, align 8

; 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 ptr @m_ObjectCreate(ptr noundef, i32 noundef) #1

declare ptr @mChainCreate(...) #2

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #3

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

10:                                               ; preds = %2
  %11 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @morn_object)
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %17

14:                                               ; preds = %10
  %15 = call ptr @m_ObjectCreate(ptr noundef null, i32 noundef -1)
  %16 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @morn_object)
  store ptr %15, ptr %16, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %14, %10
  %18 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @morn_object)
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %19, ptr %3, align 8
  br label %51

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr null, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr @morn_object_map, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %25

23:                                               ; preds = %20
  %24 = call ptr (...) @mChainCreate()
  store ptr %24, ptr @morn_object_map, align 8, !tbaa !5
  br label %30

25:                                               ; preds = %20
  %26 = load ptr, ptr @morn_object_map, align 8, !tbaa !5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = call ptr @mornMapRead(ptr noundef %26, ptr noundef %27, i32 noundef %28, ptr noundef null, ptr noundef null)
  store ptr %29, ptr %6, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %25, %23
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %48

33:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = ptrtoint ptr %34 to i64
  %36 = add nsw i64 %35, 0
  %37 = inttoptr i64 %36 to ptr
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = trunc i64 %39 to i32
  %41 = call ptr @m_ObjectCreate(ptr noundef %37, i32 noundef %40)
  store ptr %41, ptr %7, align 8, !tbaa !5
  %42 = load ptr, ptr @morn_object_map, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = call ptr @mornMapWrite(ptr noundef %42, ptr noundef %43, i32 noundef %44, ptr noundef null, i32 noundef 8)
  store ptr %45, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %46, ptr %47, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %48

48:                                               ; preds = %33, %30
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  store ptr %50, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %51

51:                                               ; preds = %48, %17
  %52 = load ptr, ptr %3, align 8
  ret ptr %52
}

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 = { "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 nosync nounwind speculatable willreturn memory(none) }
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}


; 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_object = external dso_local thread_local local_unnamed_addr global ptr, align 8
@morn_object_map = external dso_local local_unnamed_addr global ptr, align 8

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

declare ptr @mChainCreate(...) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @mMornObject(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %4, label %10

4:                                                ; preds = %2
  %5 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @morn_object)
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %21

8:                                                ; preds = %4
  %9 = tail call ptr @m_ObjectCreate(ptr noundef null, i32 noundef -1)
  store ptr %9, ptr %5, align 8, !tbaa !5
  br label %21

10:                                               ; preds = %2
  %11 = load ptr, ptr @morn_object_map, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %.thread, label %14

.thread:                                          ; preds = %10
  %13 = tail call ptr (...) @mChainCreate() #3
  store ptr %13, ptr @morn_object_map, align 8, !tbaa !5
  br label %17

14:                                               ; preds = %10
  %15 = tail call ptr @mornMapRead(ptr noundef nonnull %11, ptr noundef nonnull %0, i32 noundef %1, ptr noundef null, ptr noundef null) #3
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %._crit_edge

._crit_edge:                                      ; preds = %14
  %.0.pre = load ptr, ptr %15, align 8, !tbaa !5
  br label %21

17:                                               ; preds = %.thread, %14
  %18 = tail call ptr @m_ObjectCreate(ptr noundef nonnull %0, i32 noundef %1)
  %19 = load ptr, ptr @morn_object_map, align 8, !tbaa !5
  %20 = tail call ptr @mornMapWrite(ptr noundef %19, ptr noundef nonnull %0, i32 noundef %1, ptr noundef null, i32 noundef 8) #3
  store ptr %18, ptr %20, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %._crit_edge, %17, %4, %8
  %.0 = phi ptr [ %9, %8 ], [ %6, %4 ], [ %18, %17 ], [ %.0.pre, %._crit_edge ]
  ret ptr %.0
}

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 = { mustprogress 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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