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

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

@.str = external hidden unnamed_addr constant [76 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@__FUNCTION__.mChronoDelete = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [28 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 @endChrono(ptr noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @mChronoDelete(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 0
  %13 = zext i1 %12 to i32
  store i32 %13, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %10
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %17, i32 noundef -1, ptr noundef @.str, i32 noundef 112, ptr noundef @__FUNCTION__.mChronoDelete, ptr noundef @.str.4, i32 noundef %18)
  br label %19

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

20:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %21 = call ptr @mMornObject(ptr noundef @.str.2, i32 noundef -1)
  %22 = call ptr @GetHandle(ptr noundef %21, i32 noundef 24, i32 noundef -2033341518, ptr noundef @endChrono)
  store ptr %22, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.MHandle, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  store ptr %25, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.HandleChrono, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  store ptr %28, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %29 = load ptr, ptr %6, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.MObject, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  store ptr %31, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.HandleChrono, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !16
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %65

36:                                               ; preds = %20
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.MObject, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = getelementptr inbounds %struct.MChainNode, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  store ptr %41, ptr %8, align 8, !tbaa !9
  %42 = load ptr, ptr %8, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.ChronoData, ptr %42, i32 0, i32 3
  %44 = load i32, ptr %43, align 8, !tbaa !19
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = icmp eq i32 %44, %45
  br i1 %46, label %54, label %47

47:                                               ; preds = %36
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.ChronoData, ptr %48, i32 0, i32 3
  %50 = load i32, ptr %49, align 8, !tbaa !19
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sub nsw i32 -2, %51
  %53 = icmp eq i32 %50, %52
  br i1 %53, label %54, label %64

54:                                               ; preds = %47, %36
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.ChronoData, ptr %55, i32 0, i32 3
  store i32 -1, ptr %56, align 8, !tbaa !19
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.ChronoData, ptr %57, i32 0, i32 1
  store i32 -1, ptr %58, align 8, !tbaa !22
  %59 = load ptr, ptr %5, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.HandleChrono, ptr %59, i32 0, i32 2
  %61 = load i32, ptr %60, align 4, !tbaa !23
  %62 = load ptr, ptr %8, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.ChronoData, ptr %62, i32 0, i32 2
  store i32 %61, ptr %63, align 4, !tbaa !24
  br label %64

64:                                               ; preds = %54, %47
  store i32 1, ptr %9, align 4
  br label %100

65:                                               ; preds = %20
  br label %66

66:                                               ; preds = %93, %65
  %67 = load ptr, ptr %7, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.MChainNode, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !17
  store ptr %69, ptr %8, align 8, !tbaa !9
  %70 = load ptr, ptr %8, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.ChronoData, ptr %70, i32 0, i32 3
  %72 = load i32, ptr %71, align 8, !tbaa !19
  %73 = load i32, ptr %2, align 4, !tbaa !5
  %74 = icmp eq i32 %72, %73
  br i1 %74, label %82, label %75

75:                                               ; preds = %66
  %76 = load ptr, ptr %8, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.ChronoData, ptr %76, i32 0, i32 3
  %78 = load i32, ptr %77, align 8, !tbaa !19
  %79 = load i32, ptr %2, align 4, !tbaa !5
  %80 = sub nsw i32 -2, %79
  %81 = icmp eq i32 %78, %80
  br i1 %81, label %82, label %89

82:                                               ; preds = %75, %66
  %83 = load ptr, ptr %5, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.HandleChrono, ptr %83, i32 0, i32 1
  %85 = load i32, ptr %84, align 8, !tbaa !16
  %86 = add nsw i32 %85, -1
  store i32 %86, ptr %84, align 8, !tbaa !16
  %87 = load ptr, ptr %6, align 8, !tbaa !9
  %88 = load ptr, ptr %7, align 8, !tbaa !9
  call void @mChainNodeDelete(ptr noundef %87, ptr noundef %88)
  store i32 1, ptr %9, align 4
  br label %100

89:                                               ; preds = %75
  %90 = load ptr, ptr %7, align 8, !tbaa !9
  %91 = getelementptr inbounds %struct.MChainNode, ptr %90, i32 0, i32 2
  %92 = load ptr, ptr %91, align 8, !tbaa !25
  store ptr %92, ptr %7, align 8, !tbaa !9
  br label %93

93:                                               ; preds = %89
  %94 = load ptr, ptr %7, align 8, !tbaa !9
  %95 = load ptr, ptr %6, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.MObject, ptr %95, i32 0, i32 1
  %97 = load ptr, ptr %96, align 8, !tbaa !15
  %98 = icmp ne ptr %94, %97
  br i1 %98, label %66, label %99, !llvm.loop !26

99:                                               ; preds = %93
  store i32 0, ptr %9, align 4
  br label %100

100:                                              ; preds = %99, %82, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %101 = load i32, ptr %9, align 4
  switch i32 %101, label %103 [
    i32 0, label %102
    i32 1, label %102
  ]

102:                                              ; preds = %100, %100
  ret void

103:                                              ; preds = %100
  unreachable
}

declare void @mChainNodeDelete(ptr noundef, 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"MHandle", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!13 = !{!14, !10, i64 0}
!14 = !{!"HandleChrono", !10, i64 0, !6, i64 8, !6, i64 12, !6, i64 16}
!15 = !{!7, !7, i64 0}
!16 = !{!14, !6, i64 8}
!17 = !{!18, !10, i64 0}
!18 = !{!"MChainNode", !10, i64 0, !10, i64 8, !10, i64 16}
!19 = !{!20, !6, i64 16}
!20 = !{!"ChronoData", !21, i64 0, !6, i64 8, !6, i64 12, !6, i64 16}
!21 = !{!"double", !7, i64 0}
!22 = !{!20, !6, i64 8}
!23 = !{!14, !6, i64 12}
!24 = !{!20, !6, i64 12}
!25 = !{!18, !10, i64 16}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}


; 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 [76 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@__FUNCTION__.mChronoDelete = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [28 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @mChronoDelete(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i32 %0, 0
  br i1 %2, label %3, label %4

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

4:                                                ; preds = %3, %1
  %5 = tail call ptr @mMornObject(ptr noundef nonnull @.str.2, i32 noundef -1) #2
  %6 = tail call ptr @GetHandle(ptr noundef %5, i32 noundef 24, i32 noundef -2033341518, ptr noundef nonnull @endChrono) #2
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %8, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %16, label %.preheader

.preheader:                                       ; preds = %4
  %15 = sub nsw i32 -2, %0
  br label %28

16:                                               ; preds = %4
  %17 = load ptr, ptr %11, align 8, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = load i32, ptr %18, align 8, !tbaa !17
  %20 = icmp eq i32 %19, %0
  %21 = sub nsw i32 -2, %0
  %22 = icmp eq i32 %19, %21
  %or.cond = select i1 %20, i1 true, i1 %22
  br i1 %or.cond, label %23, label %.loopexit

23:                                               ; preds = %16
  store i32 -1, ptr %18, align 8, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %17, i64 8
  store i32 -1, ptr %24, align 8, !tbaa !20
  %25 = getelementptr inbounds i8, ptr %8, i64 12
  %26 = load i32, ptr %25, align 4, !tbaa !21
  %27 = getelementptr inbounds i8, ptr %17, i64 12
  store i32 %26, ptr %27, align 4, !tbaa !22
  br label %.loopexit

28:                                               ; preds = %.preheader, %36
  %.0 = phi ptr [ %38, %36 ], [ %11, %.preheader ]
  %29 = load ptr, ptr %.0, align 8, !tbaa !15
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  %31 = load i32, ptr %30, align 8, !tbaa !17
  %32 = icmp eq i32 %31, %0
  %33 = icmp eq i32 %31, %15
  %or.cond33 = select i1 %32, i1 true, i1 %33
  br i1 %or.cond33, label %34, label %36

34:                                               ; preds = %28
  %35 = add nsw i32 %13, -1
  store i32 %35, ptr %12, align 8, !tbaa !14
  tail call void @mChainNodeDelete(ptr noundef %9, ptr noundef nonnull %.0) #2
  br label %.loopexit

36:                                               ; preds = %28
  %37 = getelementptr inbounds i8, ptr %.0, i64 16
  %38 = load ptr, ptr %37, align 8, !tbaa !23
  %.not = icmp eq ptr %38, %11
  br i1 %.not, label %.loopexit, label %28, !llvm.loop !24

.loopexit:                                        ; preds = %36, %23, %16, %34
  ret void
}

declare void @mChainNodeDelete(ptr noundef, 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, !10, i64 16}
!6 = !{!"MHandle", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"HandleChrono", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16}
!13 = !{!8, !8, i64 0}
!14 = !{!12, !7, i64 8}
!15 = !{!16, !10, i64 0}
!16 = !{!"MChainNode", !10, i64 0, !10, i64 8, !10, i64 16}
!17 = !{!18, !7, i64 16}
!18 = !{!"ChronoData", !19, i64 0, !7, i64 8, !7, i64 12, !7, i64 16}
!19 = !{!"double", !8, i64 0}
!20 = !{!18, !7, i64 8}
!21 = !{!12, !7, i64 12}
!22 = !{!18, !7, i64 12}
!23 = !{!16, !10, i64 16}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass