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

; 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.MChainNode = type { ptr, ptr, ptr }
%struct.MObject = type { i32, %union.anon }
%union.anon = type { ptr }
%struct.HandleList = type { %struct.MList, i32, i32, i32, i32 }
%struct.MList = type { i32, ptr }
%struct.MHandle = type { i32, i32, ptr, ptr }
%struct.HandleChainCreate = type { ptr, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local void @mChainNodeDelete(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.MChainNode, ptr %6, i32 0, i32 2
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.MChainNode, ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds %struct.MChainNode, ptr %11, i32 0, i32 2
  store ptr %8, ptr %12, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.MChainNode, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.MChainNode, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.MChainNode, ptr %18, i32 0, i32 1
  store ptr %15, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.MObject, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = icmp eq ptr %20, %23
  br i1 %24, label %25, label %39

25:                                               ; preds = %2
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.MChainNode, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = icmp eq ptr %26, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %25
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mChainClear(ptr noundef %32)
  br label %76

33:                                               ; preds = %25
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.MChainNode, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.MObject, ptr %37, i32 0, i32 1
  store ptr %36, ptr %38, align 8, !tbaa !12
  br label %39

39:                                               ; preds = %33, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.HandleList, ptr %40, i64 -1
  %42 = getelementptr inbounds %struct.HandleList, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.MList, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = getelementptr inbounds ptr, ptr %44, i64 1
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.MHandle, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !17
  store ptr %48, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.HandleChainCreate, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 8, !tbaa !19
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %50, align 8, !tbaa !19
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.HandleChainCreate, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 8, !tbaa !19
  %56 = icmp sge i32 %55, 1024
  br i1 %56, label %57, label %75

57:                                               ; preds = %39
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.HandleChainCreate, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !21
  %61 = getelementptr inbounds %struct.MList, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !22
  %63 = icmp sgt i32 %62, 16
  br i1 %63, label %64, label %72

64:                                               ; preds = %57
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.HandleChainCreate, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !21
  call void @mChainNodeOperate(ptr noundef %65, ptr noundef @MemoryCollect, ptr noundef %68)
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.HandleChainCreate, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !21
  call void @MemoryDefrag(ptr noundef %71)
  br label %72

72:                                               ; preds = %64, %57
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.HandleChainCreate, ptr %73, i32 0, i32 1
  store i32 0, ptr %74, align 8, !tbaa !19
  br label %75

75:                                               ; preds = %72, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %76

76:                                               ; preds = %75, %31
  ret void
}

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

declare void @MemoryCollect(ptr noundef, ptr noundef) #2

declare void @MemoryDefrag(ptr noundef) #2

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 = { 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 16}
!10 = !{!"MChainNode", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"HandleList", !15, i64 0, !16, i64 16, !16, i64 20, !16, i64 24, !16, i64 28}
!15 = !{!"MList", !16, i64 0, !6, i64 8}
!16 = !{!"int", !7, i64 0}
!17 = !{!18, !6, i64 16}
!18 = !{!"MHandle", !16, i64 0, !16, i64 4, !6, i64 8, !6, i64 16}
!19 = !{!20, !16, i64 8}
!20 = !{!"HandleChainCreate", !6, i64 0, !16, i64 8}
!21 = !{!20, !6, i64 0}
!22 = !{!15, !16, 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"

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

; Function Attrs: nounwind uwtable
define dso_local void @mChainNodeDelete(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr %4, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %6, ptr %8, align 8, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp eq ptr %10, %1
  br i1 %11, label %12, label %16

12:                                               ; preds = %2
  %13 = icmp eq ptr %4, %1
  br i1 %13, label %14, label %15

14:                                               ; preds = %12
  tail call void @mChainClear(ptr noundef nonnull %0)
  br label %34

15:                                               ; preds = %12
  store ptr %4, ptr %9, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %15, %2
  %17 = getelementptr inbounds i8, ptr %0, i64 -24
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load i32, ptr %23, align 8, !tbaa !19
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 8, !tbaa !19
  %26 = icmp sgt i32 %24, 1022
  br i1 %26, label %27, label %34

27:                                               ; preds = %16
  %28 = load ptr, ptr %22, align 8, !tbaa !21
  %29 = load i32, ptr %28, align 8, !tbaa !22
  %30 = icmp sgt i32 %29, 16
  br i1 %30, label %31, label %33

31:                                               ; preds = %27
  tail call void @mChainNodeOperate(ptr noundef nonnull %0, ptr noundef nonnull @MemoryCollect, ptr noundef nonnull %28)
  %32 = load ptr, ptr %22, align 8, !tbaa !21
  tail call void @MemoryDefrag(ptr noundef %32) #2
  br label %33

33:                                               ; preds = %31, %27
  store i32 0, ptr %23, align 8, !tbaa !19
  br label %34

34:                                               ; preds = %16, %33, %14
  ret void
}

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

declare void @MemoryCollect(ptr noundef, ptr noundef) #1

declare void @MemoryDefrag(ptr noundef) local_unnamed_addr #1

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 = { 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, !7, i64 16}
!6 = !{!"MChainNode", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!8, !8, i64 0}
!12 = !{!13, !7, i64 8}
!13 = !{!"HandleList", !14, i64 0, !15, i64 16, !15, i64 20, !15, i64 24, !15, i64 28}
!14 = !{!"MList", !15, i64 0, !7, i64 8}
!15 = !{!"int", !8, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !7, i64 16}
!18 = !{!"MHandle", !15, i64 0, !15, i64 4, !7, i64 8, !7, i64 16}
!19 = !{!20, !15, i64 8}
!20 = !{!"HandleChainCreate", !7, i64 0, !15, i64 8}
!21 = !{!20, !7, i64 0}
!22 = !{!14, !15, i64 0}


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