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

; 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.MVHisEntry = type { i64, ptr, ptr, ptr }
%class.Row_mvcc = type { ptr, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64 }

; 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: mustprogress uwtable
declare dso_local noundef ptr @_ZN8Row_mvcc13get_his_entryEv(ptr noundef nonnull align 8 dereferenceable(104)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Row_mvcc14insert_historyEmP5row_t(ptr noundef nonnull align 8 dereferenceable(104) %0, i64 noundef %1, ptr noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %12 = call noundef ptr @_ZN8Row_mvcc13get_his_entryEv(ptr noundef nonnull align 8 dereferenceable(104) %11)
  store ptr %12, ptr %7, align 8, !tbaa !5
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MVHisEntry, ptr %14, i32 0, i32 0
  store i64 %13, ptr %15, align 8, !tbaa !11
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.MVHisEntry, ptr %17, i32 0, i32 1
  store ptr %16, ptr %18, align 8, !tbaa !13
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %25

21:                                               ; preds = %3
  %22 = getelementptr inbounds %class.Row_mvcc, ptr %11, i32 0, i32 9
  %23 = load i64, ptr %22, align 8, !tbaa !14
  %24 = add i64 %23, 1
  store i64 %24, ptr %22, align 8, !tbaa !14
  br label %29

25:                                               ; preds = %3
  %26 = getelementptr inbounds %class.Row_mvcc, ptr %11, i32 0, i32 10
  %27 = load i64, ptr %26, align 8, !tbaa !17
  %28 = add i64 %27, 1
  store i64 %28, ptr %26, align 8, !tbaa !17
  br label %29

29:                                               ; preds = %25, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  %33 = getelementptr inbounds %class.Row_mvcc, ptr %11, i32 0, i32 5
  br label %36

34:                                               ; preds = %29
  %35 = getelementptr inbounds %class.Row_mvcc, ptr %11, i32 0, i32 6
  br label %36

36:                                               ; preds = %34, %32
  %37 = phi ptr [ %33, %32 ], [ %35, %34 ]
  store ptr %37, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %42

40:                                               ; preds = %36
  %41 = getelementptr inbounds %class.Row_mvcc, ptr %11, i32 0, i32 7
  br label %44

42:                                               ; preds = %36
  %43 = getelementptr inbounds %class.Row_mvcc, ptr %11, i32 0, i32 8
  br label %44

44:                                               ; preds = %42, %40
  %45 = phi ptr [ %41, %40 ], [ %43, %42 ]
  store ptr %45, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  store ptr %47, ptr %10, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %59, %44
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %57

51:                                               ; preds = %48
  %52 = load i64, ptr %5, align 8, !tbaa !9
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.MVHisEntry, ptr %53, i32 0, i32 0
  %55 = load i64, ptr %54, align 8, !tbaa !11
  %56 = icmp ult i64 %52, %55
  br label %57

57:                                               ; preds = %51, %48
  %58 = phi i1 [ false, %48 ], [ %56, %51 ]
  br i1 %58, label %59, label %63

59:                                               ; preds = %57
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MVHisEntry, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !18
  store ptr %62, ptr %10, align 8, !tbaa !5
  br label %48, !llvm.loop !19

63:                                               ; preds = %57
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %97

66:                                               ; preds = %63
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.MVHisEntry, ptr %68, i32 0, i32 2
  store ptr %67, ptr %69, align 8, !tbaa !18
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.MVHisEntry, ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !21
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.MVHisEntry, ptr %73, i32 0, i32 3
  store ptr %72, ptr %74, align 8, !tbaa !21
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.MVHisEntry, ptr %75, i32 0, i32 3
  %77 = load ptr, ptr %76, align 8, !tbaa !21
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %85

79:                                               ; preds = %66
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.MVHisEntry, ptr %81, i32 0, i32 3
  %83 = load ptr, ptr %82, align 8, !tbaa !21
  %84 = getelementptr inbounds %struct.MVHisEntry, ptr %83, i32 0, i32 2
  store ptr %80, ptr %84, align 8, !tbaa !18
  br label %85

85:                                               ; preds = %79, %66
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.MVHisEntry, ptr %87, i32 0, i32 3
  store ptr %86, ptr %88, align 8, !tbaa !21
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = load ptr, ptr %89, align 8, !tbaa !5
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  %92 = icmp eq ptr %90, %91
  br i1 %92, label %93, label %96

93:                                               ; preds = %85
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %94, ptr %95, align 8, !tbaa !5
  br label %96

96:                                               ; preds = %93, %85
  br label %122

97:                                               ; preds = %63
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.MVHisEntry, ptr %98, i32 0, i32 2
  store ptr null, ptr %99, align 8, !tbaa !18
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.MVHisEntry, ptr %100, i32 0, i32 3
  store ptr null, ptr %101, align 8, !tbaa !21
  %102 = load ptr, ptr %9, align 8, !tbaa !5
  %103 = load ptr, ptr %102, align 8, !tbaa !5
  %104 = icmp ne ptr %103, null
  br i1 %104, label %105, label %116

105:                                              ; preds = %97
  %106 = load ptr, ptr %9, align 8, !tbaa !5
  %107 = load ptr, ptr %106, align 8, !tbaa !5
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.MVHisEntry, ptr %108, i32 0, i32 3
  store ptr %107, ptr %109, align 8, !tbaa !21
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  %111 = load ptr, ptr %9, align 8, !tbaa !5
  %112 = load ptr, ptr %111, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.MVHisEntry, ptr %112, i32 0, i32 2
  store ptr %110, ptr %113, align 8, !tbaa !18
  %114 = load ptr, ptr %7, align 8, !tbaa !5
  %115 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %114, ptr %115, align 8, !tbaa !5
  br label %121

116:                                              ; preds = %97
  %117 = load ptr, ptr %7, align 8, !tbaa !5
  %118 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %117, ptr %118, align 8, !tbaa !5
  %119 = load ptr, ptr %7, align 8, !tbaa !5
  %120 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %119, ptr %120, align 8, !tbaa !5
  br label %121

121:                                              ; preds = %116, %105
  br label %122

122:                                              ; preds = %121, %96
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8Row_mvcc13get_his_entryEv(ptr noundef nonnull align 8 dereferenceable(104)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Row_mvcc14insert_historyEmP5row_t(ptr noundef nonnull align 8 dereferenceable(104) %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef ptr @_ZN8Row_mvcc13get_his_entryEv(ptr noundef nonnull align 8 dereferenceable(104) %0)
  store i64 %1, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %2, ptr %5, align 8, !tbaa !11
  %.not = icmp eq ptr %2, null
  %. = select i1 %.not, i64 80, i64 72
  %.55 = select i1 %.not, i64 56, i64 64
  %.56 = select i1 %.not, i64 40, i64 48
  %6 = getelementptr inbounds i8, ptr %0, i64 %.
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %8 = add i64 %7, 1
  store i64 %8, ptr %6, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %0, i64 %.56
  %10 = getelementptr inbounds i8, ptr %0, i64 %.55
  %.047 = load ptr, ptr %9, align 8, !tbaa !13
  %.not4248 = icmp eq ptr %.047, null
  br i1 %.not4248, label %.critedge45, label %.lr.ph

.lr.ph:                                           ; preds = %3, %13
  %.049 = phi ptr [ %.0, %13 ], [ %.047, %3 ]
  %11 = load i64, ptr %.049, align 8, !tbaa !5
  %12 = icmp ugt i64 %11, %1
  br i1 %12, label %13, label %.critedge

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %.049, i64 16
  %.0 = load ptr, ptr %14, align 8, !tbaa !13
  %.not42 = icmp eq ptr %.0, null
  br i1 %.not42, label %.critedge45, label %.lr.ph, !llvm.loop !14

.critedge:                                        ; preds = %.lr.ph
  %15 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %.049, ptr %15, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %.049, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr %17, ptr %18, align 8, !tbaa !17
  %.not44 = icmp eq ptr %17, null
  br i1 %.not44, label %21, label %19

19:                                               ; preds = %.critedge
  %20 = getelementptr inbounds i8, ptr %17, i64 16
  store ptr %4, ptr %20, align 8, !tbaa !16
  br label %21

21:                                               ; preds = %19, %.critedge
  store ptr %4, ptr %16, align 8, !tbaa !17
  %22 = load ptr, ptr %9, align 8, !tbaa !13
  %23 = icmp eq ptr %22, %.049
  br i1 %23, label %.sink.split, label %30

.critedge45:                                      ; preds = %13, %3
  %24 = getelementptr inbounds i8, ptr %4, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %24, i8 0, i64 16, i1 false)
  %25 = load ptr, ptr %10, align 8, !tbaa !13
  %.not43 = icmp eq ptr %25, null
  br i1 %.not43, label %.sink.split.sink.split, label %26

26:                                               ; preds = %.critedge45
  %27 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr %25, ptr %27, align 8, !tbaa !17
  %28 = load ptr, ptr %10, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  br label %.sink.split.sink.split

.sink.split.sink.split:                           ; preds = %.critedge45, %26
  %.sink57 = phi ptr [ %29, %26 ], [ %9, %.critedge45 ]
  store ptr %4, ptr %.sink57, align 8, !tbaa !13
  br label %.sink.split

.sink.split:                                      ; preds = %.sink.split.sink.split, %21
  %.sink = phi ptr [ %9, %21 ], [ %10, %.sink.split.sink.split ]
  store ptr %4, ptr %.sink, align 8, !tbaa !13
  br label %30

30:                                               ; preds = %.sink.split, %21
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 0}
!6 = !{!"_ZTS10MVHisEntry", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!7, !7, i64 0}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !10, i64 16}
!17 = !{!6, !10, i64 24}


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