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

@.str = external hidden unnamed_addr constant [77 x i8], align 1
@__FUNCTION__.mChainNodeInsert = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = 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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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: nounwind uwtable
define dso_local void @mChainNodeInsert(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %17, label %13

13:                                               ; preds = %10
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = ptrtoint ptr %14 to i64
  %16 = icmp eq i64 %15, -1
  br label %17

17:                                               ; preds = %13, %10
  %18 = phi i1 [ true, %10 ], [ %16, %13 ]
  %19 = zext i1 %18 to i32
  store i32 %19, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %17
  %23 = load i32, ptr %7, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %23, i32 noundef -1, ptr noundef @.str, i32 noundef 68, ptr noundef @__FUNCTION__.mChainNodeInsert, ptr noundef @.str.2)
  br label %24

24:                                               ; preds = %22, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %33, label %29

29:                                               ; preds = %26
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = ptrtoint ptr %30 to i64
  %32 = icmp eq i64 %31, -1
  br i1 %32, label %33, label %42

33:                                               ; preds = %29, %26
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %40, label %36

36:                                               ; preds = %33
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = ptrtoint ptr %37 to i64
  %39 = icmp eq i64 %38, -1
  br label %40

40:                                               ; preds = %36, %33
  %41 = phi i1 [ true, %33 ], [ %39, %36 ]
  br label %42

42:                                               ; preds = %40, %29
  %43 = phi i1 [ false, %29 ], [ %41, %40 ]
  %44 = zext i1 %43 to i32
  store i32 %44, ptr %8, align 4, !tbaa !9
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %42
  %48 = load i32, ptr %8, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %48, i32 noundef -1, ptr noundef @.str, i32 noundef 69, ptr noundef @__FUNCTION__.mChainNodeInsert, ptr noundef @.str.2)
  br label %49

49:                                               ; preds = %47, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = icmp eq ptr %51, null
  br i1 %52, label %57, label %53

53:                                               ; preds = %50
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = ptrtoint ptr %54 to i64
  %56 = icmp eq i64 %55, -1
  br i1 %56, label %57, label %61

57:                                               ; preds = %53, %50
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.MChainNode, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  store ptr %60, ptr %6, align 8, !tbaa !5
  br label %95

61:                                               ; preds = %53
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = icmp eq ptr %62, null
  br i1 %63, label %68, label %64

64:                                               ; preds = %61
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = ptrtoint ptr %65 to i64
  %67 = icmp eq i64 %66, -1
  br i1 %67, label %68, label %72

68:                                               ; preds = %64, %61
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.MChainNode, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !13
  store ptr %71, ptr %4, align 8, !tbaa !5
  br label %94

72:                                               ; preds = %64
  br label %73

73:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.MChainNode, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !11
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = icmp ne ptr %76, %77
  br i1 %78, label %85, label %79

79:                                               ; preds = %73
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.MChainNode, ptr %80, i32 0, i32 1
  %82 = load ptr, ptr %81, align 8, !tbaa !13
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = icmp ne ptr %82, %83
  br label %85

85:                                               ; preds = %79, %73
  %86 = phi i1 [ true, %73 ], [ %84, %79 ]
  %87 = zext i1 %86 to i32
  store i32 %87, ptr %9, align 4, !tbaa !9
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = icmp ne i32 %88, 0
  br i1 %89, label %90, label %92

90:                                               ; preds = %85
  %91 = load i32, ptr %9, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %91, i32 noundef -1, ptr noundef @.str, i32 noundef 76, ptr noundef @__FUNCTION__.mChainNodeInsert, ptr noundef @.str.2)
  br label %92

92:                                               ; preds = %90, %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93, %68
  br label %95

95:                                               ; preds = %94, %57
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.MChainNode, ptr %97, i32 0, i32 2
  store ptr %96, ptr %98, align 8, !tbaa !11
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.MChainNode, ptr %100, i32 0, i32 1
  store ptr %99, ptr %101, align 8, !tbaa !13
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.MChainNode, ptr %103, i32 0, i32 1
  store ptr %102, ptr %104, align 8, !tbaa !13
  %105 = load ptr, ptr %6, align 8, !tbaa !5
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.MChainNode, ptr %106, i32 0, i32 2
  store ptr %105, ptr %107, align 8, !tbaa !11
  ret void
}

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 }

!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 16}
!12 = !{!"MChainNode", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}


; 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__.mChainNodeInsert = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = 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
define dso_local void @mChainNodeInsert(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %magicptr = ptrtoint ptr %1 to i64
  switch i64 %magicptr, label %9 [
    i64 -1, label %4
    i64 0, label %4
  ]

4:                                                ; preds = %3, %3
  %5 = icmp eq ptr %1, null
  %6 = icmp eq ptr %1, inttoptr (i64 -1 to ptr)
  %7 = or i1 %5, %6
  %8 = zext i1 %7 to i32
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %8, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 68, ptr noundef nonnull @__FUNCTION__.mChainNodeInsert, ptr noundef nonnull @.str.2) #2
  br label %9

9:                                                ; preds = %3, %4
  %magicptr40 = ptrtoint ptr %0 to i64
  switch i64 %magicptr40, label %..thread_crit_edge [
    i64 -1, label %10
    i64 0, label %10
  ]

..thread_crit_edge:                               ; preds = %9
  %.pre = ptrtoint ptr %2 to i64
  br label %.thread

10:                                               ; preds = %9, %9
  %magicptr44 = ptrtoint ptr %2 to i64
  switch i64 %magicptr44, label %.thread [
    i64 -1, label %11
    i64 0, label %11
  ]

11:                                               ; preds = %10, %10
  %12 = icmp eq ptr %2, null
  %13 = icmp eq ptr %2, inttoptr (i64 -1 to ptr)
  %14 = or i1 %12, %13
  %15 = zext i1 %14 to i32
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %15, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 69, ptr noundef nonnull @__FUNCTION__.mChainNodeInsert, ptr noundef nonnull @.str.2) #2
  br label %.thread

.thread:                                          ; preds = %..thread_crit_edge, %10, %11
  %magicptr41.pre-phi = phi i64 [ %.pre, %..thread_crit_edge ], [ %magicptr44, %10 ], [ %magicptr44, %11 ]
  switch i64 %magicptr41.pre-phi, label %19 [
    i64 -1, label %16
    i64 0, label %16
  ]

16:                                               ; preds = %.thread, %.thread
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  br label %29

19:                                               ; preds = %.thread
  switch i64 %magicptr40, label %23 [
    i64 -1, label %20
    i64 0, label %20
  ]

20:                                               ; preds = %19, %19
  %21 = getelementptr inbounds i8, ptr %2, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !10
  br label %29

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %.not = icmp eq ptr %25, %2
  br i1 %.not, label %26, label %.thread43

26:                                               ; preds = %23
  %27 = getelementptr inbounds i8, ptr %2, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !10
  %.not45 = icmp eq ptr %28, %0
  br i1 %.not45, label %29, label %.thread43

.thread43:                                        ; preds = %23, %26
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 76, ptr noundef nonnull @__FUNCTION__.mChainNodeInsert, ptr noundef nonnull @.str.2) #2
  br label %29

29:                                               ; preds = %26, %.thread43, %20, %16
  %.037 = phi ptr [ %18, %16 ], [ %2, %20 ], [ %2, %.thread43 ], [ %2, %26 ]
  %.0 = phi ptr [ %0, %16 ], [ %22, %20 ], [ %0, %.thread43 ], [ %0, %26 ]
  %30 = getelementptr inbounds i8, ptr %.0, i64 16
  store ptr %1, ptr %30, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %.037, i64 8
  store ptr %1, ptr %31, align 8, !tbaa !10
  %32 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %.0, ptr %32, align 8, !tbaa !10
  %33 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr %.037, ptr %33, align 8, !tbaa !5
  ret void
}

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 = { 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}


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