; LLVM IR from mitdbg/deneva :: concurrency_control/row_mvcc.ll (ZN8Row_mvcc8conflictE6TsTypem)

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

%class.Row_mvcc = type { ptr, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64 }
%struct.MVReqEntry = type { ptr, i64, i64, ptr }
%struct.MVHisEntry = type { i64, ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__._ZN8Row_mvcc8conflictE6TsTypem = external hidden unnamed_addr constant [38 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN8Row_mvcc8conflictE6TsTypem(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef %1, i64 noundef %2) #2 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !11
  %14 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %52

17:                                               ; preds = %3
  %18 = load i64, ptr %7, align 8, !tbaa !11
  store i64 %18, ptr %8, align 8, !tbaa !11
  store i64 0, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %19 = getelementptr inbounds %class.Row_mvcc, ptr %14, i32 0, i32 4
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  store ptr %20, ptr %10, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %40, %17
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %44

24:                                               ; preds = %21
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MVReqEntry, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !16
  %28 = load i64, ptr %7, align 8, !tbaa !11
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %30, label %40

30:                                               ; preds = %24
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.MVReqEntry, ptr %31, i32 0, i32 1
  %33 = load i64, ptr %32, align 8, !tbaa !16
  %34 = load i64, ptr %9, align 8, !tbaa !11
  %35 = icmp ugt i64 %33, %34
  br i1 %35, label %36, label %40

36:                                               ; preds = %30
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.MVReqEntry, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !16
  store i64 %39, ptr %9, align 8, !tbaa !11
  br label %40

40:                                               ; preds = %36, %30, %24
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.MVReqEntry, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !18
  store ptr %43, ptr %10, align 8, !tbaa !5
  br label %21, !llvm.loop !19

44:                                               ; preds = %21
  %45 = load i64, ptr %9, align 8, !tbaa !11
  %46 = icmp eq i64 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  store i1 false, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %49

48:                                               ; preds = %44
  store i32 0, ptr %11, align 4
  br label %49

49:                                               ; preds = %48, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %50 = load i32, ptr %11, align 4
  switch i32 %50, label %120 [
    i32 0, label %51
  ]

51:                                               ; preds = %49
  br label %93

52:                                               ; preds = %3
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = icmp eq i32 %53, 2
  br i1 %54, label %55, label %92

55:                                               ; preds = %52
  store i64 0, ptr %8, align 8, !tbaa !11
  %56 = load i64, ptr %7, align 8, !tbaa !11
  store i64 %56, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %57 = getelementptr inbounds %class.Row_mvcc, ptr %14, i32 0, i32 5
  %58 = load ptr, ptr %57, align 8, !tbaa !21
  store ptr %58, ptr %12, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %73, %55
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %77

62:                                               ; preds = %59
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.MVHisEntry, ptr %63, i32 0, i32 0
  %65 = load i64, ptr %64, align 8, !tbaa !22
  %66 = load i64, ptr %7, align 8, !tbaa !11
  %67 = icmp ugt i64 %65, %66
  br i1 %67, label %68, label %72

68:                                               ; preds = %62
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.MVHisEntry, ptr %69, i32 0, i32 0
  %71 = load i64, ptr %70, align 8, !tbaa !22
  store i64 %71, ptr %8, align 8, !tbaa !11
  br label %73

72:                                               ; preds = %62
  br label %77

73:                                               ; preds = %68
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.MVHisEntry, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !24
  store ptr %76, ptr %12, align 8, !tbaa !5
  br label %59, !llvm.loop !25

77:                                               ; preds = %72, %59
  %78 = load i64, ptr %8, align 8, !tbaa !11
  %79 = icmp eq i64 %78, 0
  br i1 %79, label %80, label %81

80:                                               ; preds = %77
  store i1 false, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %89

81:                                               ; preds = %77
  %82 = load i64, ptr %8, align 8, !tbaa !11
  %83 = load i64, ptr %9, align 8, !tbaa !11
  %84 = icmp ugt i64 %82, %83
  br i1 %84, label %85, label %86

85:                                               ; preds = %81
  br label %88

86:                                               ; preds = %81
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 231, ptr noundef @__PRETTY_FUNCTION__._ZN8Row_mvcc8conflictE6TsTypem) #4
  unreachable

87:                                               ; No predecessors!
  br label %88

88:                                               ; preds = %87, %85
  store i32 0, ptr %11, align 4
  br label %89

89:                                               ; preds = %88, %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %90 = load i32, ptr %11, align 4
  switch i32 %90, label %120 [
    i32 0, label %91
  ]

91:                                               ; preds = %89
  br label %92

92:                                               ; preds = %91, %52
  br label %93

93:                                               ; preds = %92, %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %94 = getelementptr inbounds %class.Row_mvcc, ptr %14, i32 0, i32 6
  %95 = load ptr, ptr %94, align 8, !tbaa !26
  store ptr %95, ptr %13, align 8, !tbaa !5
  br label %96

96:                                               ; preds = %114, %93
  %97 = load ptr, ptr %13, align 8, !tbaa !5
  %98 = icmp ne ptr %97, null
  br i1 %98, label %99, label %105

99:                                               ; preds = %96
  %100 = load ptr, ptr %13, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.MVHisEntry, ptr %100, i32 0, i32 0
  %102 = load i64, ptr %101, align 8, !tbaa !22
  %103 = load i64, ptr %9, align 8, !tbaa !11
  %104 = icmp ugt i64 %102, %103
  br label %105

105:                                              ; preds = %99, %96
  %106 = phi i1 [ false, %96 ], [ %104, %99 ]
  br i1 %106, label %107, label %118

107:                                              ; preds = %105
  %108 = load ptr, ptr %13, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.MVHisEntry, ptr %108, i32 0, i32 0
  %110 = load i64, ptr %109, align 8, !tbaa !22
  %111 = load i64, ptr %8, align 8, !tbaa !11
  %112 = icmp ult i64 %110, %111
  br i1 %112, label %113, label %114

113:                                              ; preds = %107
  store i1 false, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %119

114:                                              ; preds = %107
  %115 = load ptr, ptr %13, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.MVHisEntry, ptr %115, i32 0, i32 2
  %117 = load ptr, ptr %116, align 8, !tbaa !24
  store ptr %117, ptr %13, align 8, !tbaa !5
  br label %96, !llvm.loop !27

118:                                              ; preds = %105
  store i1 true, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %119

119:                                              ; preds = %118, %113
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %120

120:                                              ; preds = %119, %89, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %121 = load i1, ptr %4, align 1
  ret i1 %121
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 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 }
attributes #4 = { noreturn 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTS6TsType", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 32}
!14 = !{!"_ZTS8Row_mvcc", !6, i64 0, !15, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96}
!15 = !{!"bool", !7, i64 0}
!16 = !{!17, !12, i64 8}
!17 = !{!"_ZTS10MVReqEntry", !6, i64 0, !12, i64 8, !12, i64 16, !6, i64 24}
!18 = !{!17, !6, i64 24}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!14, !6, i64 40}
!22 = !{!23, !12, i64 0}
!23 = !{!"_ZTS10MVHisEntry", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!24 = !{!23, !6, i64 16}
!25 = distinct !{!25, !20}
!26 = !{!14, !6, i64 48}
!27 = distinct !{!27, !20}


; 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.1 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__._ZN8Row_mvcc8conflictE6TsTypem = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN8Row_mvcc8conflictE6TsTypem(ptr nocapture noundef nonnull readonly align 8 dereferenceable(104) %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #1 align 2 {
  switch i32 %1, label %21 [
    i32 0, label %4
    i32 2, label %11
  ]

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %.03256 = load ptr, ptr %5, align 8, !tbaa !5
  %.not4557 = icmp eq ptr %.03256, null
  br i1 %.not4557, label %.critedge, label %.lr.ph61

.lr.ph61:                                         ; preds = %4, %.lr.ph61
  %.03259 = phi ptr [ %.032, %.lr.ph61 ], [ %.03256, %4 ]
  %.03358 = phi i64 [ %.134, %.lr.ph61 ], [ 0, %4 ]
  %6 = getelementptr inbounds i8, ptr %.03259, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !9
  %8 = icmp ult i64 %7, %2
  %9 = tail call i64 @llvm.umax.i64(i64 %7, i64 %.03358)
  %.134 = select i1 %8, i64 %9, i64 %.03358
  %10 = getelementptr inbounds i8, ptr %.03259, i64 24
  %.032 = load ptr, ptr %10, align 8, !tbaa !5
  %.not45 = icmp eq ptr %.032, null
  br i1 %.not45, label %._crit_edge62, label %.lr.ph61, !llvm.loop !12

._crit_edge62:                                    ; preds = %.lr.ph61
  %.not46 = icmp eq i64 %.134, 0
  br i1 %.not46, label %.critedge, label %21

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %.03050 = load ptr, ptr %12, align 8, !tbaa !5
  %.not51 = icmp eq ptr %.03050, null
  br i1 %.not51, label %.critedge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %11
  %13 = load i64, ptr %.03050, align 8, !tbaa !14
  %14 = icmp ugt i64 %13, %2
  br i1 %14, label %.lr.ph87, label %._crit_edge

.lr.ph87:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %15 = phi i64 [ %17, %.lr.ph ], [ %13, %.lr.ph.preheader ]
  %.0305386 = phi ptr [ %.030, %.lr.ph ], [ %.03050, %.lr.ph.preheader ]
  %16 = getelementptr inbounds i8, ptr %.0305386, i64 16
  %.030 = load ptr, ptr %16, align 8, !tbaa !5
  %.not = icmp eq ptr %.030, null
  br i1 %.not, label %._crit_edge.thread78, label %.lr.ph, !llvm.loop !16

.lr.ph:                                           ; preds = %.lr.ph87
  %17 = load i64, ptr %.030, align 8, !tbaa !14
  %18 = icmp ugt i64 %17, %2
  br i1 %18, label %.lr.ph87, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph.preheader
  %.03552.lcssa = phi i64 [ 0, %.lr.ph.preheader ], [ %15, %.lr.ph ]
  %.not44 = icmp eq i64 %.03552.lcssa, 0
  br i1 %.not44, label %.critedge, label %._crit_edge.thread78

._crit_edge.thread78:                             ; preds = %.lr.ph87, %._crit_edge
  %.035.lcssa81 = phi i64 [ %.03552.lcssa, %._crit_edge ], [ %15, %.lr.ph87 ]
  %19 = icmp ugt i64 %.035.lcssa81, %2
  br i1 %19, label %21, label %20

20:                                               ; preds = %._crit_edge.thread78
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 231, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN8Row_mvcc8conflictE6TsTypem) #3
  unreachable

21:                                               ; preds = %._crit_edge.thread78, %3, %._crit_edge62
  %.136 = phi i64 [ %2, %._crit_edge62 ], [ undef, %3 ], [ %.035.lcssa81, %._crit_edge.thread78 ]
  %.2 = phi i64 [ %.134, %._crit_edge62 ], [ undef, %3 ], [ %2, %._crit_edge.thread78 ]
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  %.064 = load ptr, ptr %22, align 8, !tbaa !5
  %.not4765 = icmp eq ptr %.064, null
  br i1 %.not4765, label %.critedge, label %.lr.ph68

23:                                               ; preds = %27
  %24 = getelementptr inbounds i8, ptr %.066, i64 16
  %.0 = load ptr, ptr %24, align 8, !tbaa !5
  %.not47 = icmp eq ptr %.0, null
  br i1 %.not47, label %.critedge, label %.lr.ph68, !llvm.loop !17

.lr.ph68:                                         ; preds = %21, %23
  %.066 = phi ptr [ %.0, %23 ], [ %.064, %21 ]
  %25 = load i64, ptr %.066, align 8, !tbaa !14
  %26 = icmp ugt i64 %25, %.2
  br i1 %26, label %27, label %.critedge

27:                                               ; preds = %.lr.ph68
  %28 = icmp ult i64 %25, %.136
  br i1 %28, label %.critedge, label %23

.critedge:                                        ; preds = %.lr.ph68, %23, %27, %11, %4, %21, %._crit_edge, %._crit_edge62
  %.3 = phi i1 [ false, %._crit_edge62 ], [ false, %._crit_edge ], [ true, %21 ], [ false, %4 ], [ false, %11 ], [ true, %.lr.ph68 ], [ true, %23 ], [ false, %27 ]
  ret i1 %.3
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #2

attributes #0 = { noreturn nounwind "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 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { noreturn 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++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_ZTS10MVReqEntry", !6, i64 0, !11, i64 8, !11, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !11, i64 0}
!15 = !{!"_ZTS10MVHisEntry", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13}


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