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

; 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.HandleBtreeCreate = type { ptr }
%struct.MBtreeNode = type { ptr, ptr, ptr, ptr }

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

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.MHandle, ptr %19, i32 0, i32 0
  %21 = load volatile i32, ptr %20, align 8, !tbaa !14
  %22 = icmp ne i32 %21, 348559339
  %23 = zext i1 %22 to i32
  store i32 %23, ptr %8, align 4, !tbaa !9
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %18
  %27 = load i32, ptr %8, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %27, i32 noundef -1, ptr noundef @.str, i32 noundef 36, ptr noundef @__FUNCTION__.mBtreeNode, ptr noundef @.str.1)
  br label %28

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

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.MHandle, ptr %31, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  store ptr %33, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.HandleBtreeCreate, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %42

38:                                               ; preds = %30
  %39 = call ptr @mMemoryCreate(i32 noundef -1, i32 noundef -1, i32 noundef 0)
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.HandleBtreeCreate, ptr %40, i32 0, i32 0
  store ptr %39, ptr %41, align 8, !tbaa !17
  br label %42

42:                                               ; preds = %38, %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.HandleBtreeCreate, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = call ptr @mMemoryWrite(ptr noundef %45, ptr noundef null, i32 noundef 32)
  store ptr %46, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %47, i8 0, i64 32, i1 false)
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.HandleBtreeCreate, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = call ptr @mMemoryWrite(ptr noundef %50, ptr noundef %51, i32 noundef %52)
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.MBtreeNode, ptr %54, i32 0, i32 0
  store ptr %53, ptr %55, align 8, !tbaa !19
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret ptr %56
}

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { "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 nounwind willreturn memory(argmem: write) }
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 8}
!12 = !{!"HandleList", !13, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!13 = !{!"MList", !10, i64 0, !6, i64 8}
!14 = !{!15, !10, i64 0}
!15 = !{!"MHandle", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!16 = !{!15, !6, i64 16}
!17 = !{!18, !6, i64 0}
!18 = !{!"HandleBtreeCreate", !6, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"MBtreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}


; 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__.mBtreeNode = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @mBtreeNode(ptr nocapture noundef readonly %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 -24
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = load volatile i32, ptr %7, align 8, !tbaa !13
  %.not = icmp eq i32 %8, 348559339
  br i1 %.not, label %10, label %9

9:                                                ; preds = %3
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 36, ptr noundef nonnull @__FUNCTION__.mBtreeNode, ptr noundef nonnull @.str.1) #3
  br label %10

10:                                               ; preds = %9, %3
  %11 = getelementptr inbounds i8, ptr %7, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %17

15:                                               ; preds = %10
  %16 = tail call ptr @mMemoryCreate(i32 noundef -1, i32 noundef -1, i32 noundef 0) #3
  store ptr %16, ptr %12, align 8, !tbaa !16
  br label %17

17:                                               ; preds = %15, %10
  %18 = phi ptr [ %16, %15 ], [ %13, %10 ]
  %19 = tail call ptr @mMemoryWrite(ptr noundef %18, ptr noundef null, i32 noundef 32) #3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %19, i8 0, i64 32, i1 false)
  %20 = load ptr, ptr %12, align 8, !tbaa !16
  %21 = tail call ptr @mMemoryWrite(ptr noundef %20, ptr noundef %1, i32 noundef %2) #3
  store ptr %21, ptr %19, align 8, !tbaa !18
  ret ptr %19
}

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !11, i64 8}
!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 = !{!11, !11, i64 0}
!13 = !{!14, !8, i64 0}
!14 = !{!"MHandle", !8, i64 0, !8, i64 4, !11, i64 8, !11, i64 16}
!15 = !{!14, !11, i64 16}
!16 = !{!17, !11, i64 0}
!17 = !{!"HandleBtreeCreate", !11, i64 0}
!18 = !{!19, !11, i64 0}
!19 = !{!"MBtreeNode", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}


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