; LLVM IR from pmwkaa/monotone :: monotone/engine/engine (write)

; 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.Runtime = type { %struct.ExceptionMgr, %struct.Error, ptr }
%struct.ExceptionMgr = type { ptr }
%struct.Error = type { [256 x i8], i32, ptr, ptr, i32, ptr, ptr }
%struct.Log = type { %struct.Buf, %struct.LogWrite, %struct.Iov }
%struct.Buf = type { ptr, ptr, ptr }
%struct.LogWrite = type <{ i32, i64, i8, i32, i32 }>
%struct.Iov = type { %struct.Buf, i32, i32 }
%struct.Exception = type { ptr, i8, ptr, [1 x %struct.__jmp_buf_tag] }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }
%struct.Event = type <{ i64, i8, i8, i32, [0 x i8] }>
%struct.Ref = type { ptr, %struct.Lockage, %struct.Slice }
%struct.Lockage = type { [2 x %struct.Lock], ptr, ptr }
%struct.Lock = type { i64, i32, i32 }
%struct.Slice = type { i64, i64, %struct.RbtreeNode }
%struct.RbtreeNode = type { ptr, ptr, ptr, i8 }
%struct.Part = type { %struct.Id, i32, i64, i64, i8, ptr, %struct.Memtable, %struct.Memtable, %struct.File, %struct.Index, %struct.Buf, ptr, ptr, ptr, %struct.List }
%struct.Id = type { i64, i64 }
%struct.Memtable = type { ptr, %struct.Rbtree, i32, i32, i32, i64, i64, i64, %struct.List, i32, %struct.Heap }
%struct.Rbtree = type { ptr }
%struct.Heap = type { ptr, ptr, i32, ptr }
%struct.File = type { i32, i64, %struct.Str, %struct.List }
%struct.Str = type { ptr, ptr, i8 }
%struct.Index = type <{ i32, i32, i32, i32, %struct.Id, i32, i32, i64, i64, i64, i64, i32, i64, i64, i64, i32, i64, i8, i8, [4 x i32] }>
%struct.List = type { ptr, ptr }
%struct.LogOp = type { ptr, ptr, ptr }

@mn_runtime = external thread_local global %struct.Runtime, align 8

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @log_init(ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

; Function Attrs: nounwind returns_twice
declare i32 @_setjmp(ptr noundef) #3

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden ptr @log_add(ptr noundef) #4

declare ptr @engine_lock(ptr noundef, i64 noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext) #5

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden void @log_add_event(ptr noundef, ptr noundef, ptr noundef) #4

declare ptr @memtable_set(ptr noundef, ptr noundef) #5

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden zeroext i1 @exception_mgr_leave(ptr noundef, ptr noundef) #6

; Function Attrs: nounwind uwtable
declare hidden void @engine_rollback(ptr noundef, ptr noundef) #7

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @log_free(ptr noundef) #1

; Function Attrs: inlinehint noreturn nounwind uwtable
declare hidden void @exception_mgr_throw(ptr noundef) #8

; Function Attrs: hot nounwind uwtable
declare hidden void @engine_commit(ptr noundef, ptr noundef) #9

; Function Attrs: nounwind uwtable
define dso_local void @engine_write_replay(ptr noundef %0, ptr noundef %1) #7 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.Log, align 8
  %6 = alloca %struct.Exception, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, ptr %5) #10
  call void @log_init(ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 224, ptr %6) #10
  %15 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @mn_runtime)
  %16 = getelementptr inbounds %struct.Runtime, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.ExceptionMgr, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.Exception, ptr %6, i32 0, i32 0
  store ptr %18, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds %struct.Exception, ptr %6, i32 0, i32 1
  store i8 0, ptr %20, align 8, !tbaa !17
  %21 = getelementptr inbounds %struct.Exception, ptr %6, i32 0, i32 2
  store ptr null, ptr %21, align 8, !tbaa !18
  %22 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @mn_runtime)
  %23 = getelementptr inbounds %struct.Runtime, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.ExceptionMgr, ptr %23, i32 0, i32 0
  store ptr %6, ptr %24, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.Exception, ptr %6, i32 0, i32 3
  %26 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], ptr %25, i64 0, i64 0
  %27 = call i32 @_setjmp(ptr noundef %26) #11
  %28 = icmp eq i32 %27, 0
  %29 = zext i1 %28 to i32
  store i32 %29, ptr %7, align 4, !tbaa !19
  %30 = load i32, ptr %7, align 4, !tbaa !19
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %95

32:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #10
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = call ptr @log_write_first(ptr noundef %33)
  store ptr %34, ptr %8, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %85, %32
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %89

38:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #10
  %39 = call ptr @log_add(ptr noundef %5) #12
  store ptr %39, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #10
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Event, ptr %41, i32 0, i32 0
  %43 = load i64, ptr %42, align 1, !tbaa !20
  %44 = call ptr @engine_lock(ptr noundef %40, i64 noundef %43, i32 noundef 1, i1 noundef zeroext false, i1 noundef zeroext true)
  store ptr %44, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #10
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Ref, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !22
  store ptr %47, ptr %11, align 8, !tbaa !5
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Part, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 8, !tbaa !27
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %64

52:                                               ; preds = %38
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Part, ptr %53, i32 0, i32 9
  %55 = getelementptr inbounds %struct.Index, ptr %54, i32 0, i32 16
  %56 = load i64, ptr %55, align 8, !tbaa !38
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.LogWrite, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 1, !tbaa !39
  %60 = icmp uge i64 %56, %59
  br i1 %60, label %61, label %64

61:                                               ; preds = %52
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  call void @engine_unlock(ptr noundef %62, ptr noundef %63, i32 noundef 1)
  call void @log_pushback(ptr noundef %5) #12
  store i32 4, ptr %12, align 4
  br label %82

64:                                               ; preds = %52, %38
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.LogOp, ptr %66, i32 0, i32 2
  store ptr %65, ptr %67, align 8, !tbaa !41
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #10
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Part, ptr %68, i32 0, i32 5
  %70 = load ptr, ptr %69, align 8, !tbaa !43
  store ptr %70, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #10
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Memtable, ptr %71, i32 0, i32 10
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = call ptr @event_copy(ptr noundef %72, ptr noundef %73)
  store ptr %74, ptr %14, align 8, !tbaa !5
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = load ptr, ptr %14, align 8, !tbaa !5
  call void @log_add_event(ptr noundef %5, ptr noundef %75, ptr noundef %76) #12
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = load ptr, ptr %14, align 8, !tbaa !5
  %79 = call ptr @memtable_set(ptr noundef %77, ptr noundef %78)
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.LogOp, ptr %80, i32 0, i32 1
  store ptr %79, ptr %81, align 8, !tbaa !44
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #10
  store i32 0, ptr %12, align 4
  br label %82

82:                                               ; preds = %64, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #10
  %83 = load i32, ptr %12, align 4
  switch i32 %83, label %108 [
    i32 0, label %84
    i32 4, label %85
  ]

84:                                               ; preds = %82
  br label %85

85:                                               ; preds = %84, %82
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = call ptr @log_write_next(ptr noundef %86, ptr noundef %87)
  store ptr %88, ptr %8, align 8, !tbaa !5
  br label %35, !llvm.loop !45

89:                                               ; preds = %35
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.LogWrite, ptr %90, i32 0, i32 1
  %92 = load i64, ptr %91, align 1, !tbaa !39
  %93 = getelementptr inbounds %struct.Log, ptr %5, i32 0, i32 1
  %94 = getelementptr inbounds %struct.LogWrite, ptr %93, i32 0, i32 1
  store i64 %92, ptr %94, align 4, !tbaa !47
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #10
  br label %95

95:                                               ; preds = %89, %2
  %96 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @mn_runtime)
  %97 = getelementptr inbounds %struct.Runtime, ptr %96, i32 0, i32 0
  %98 = call zeroext i1 @exception_mgr_leave(ptr noundef %97, ptr noundef %6)
  br i1 %98, label %99, label %103

99:                                               ; preds = %95
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  call void @engine_rollback(ptr noundef %100, ptr noundef %5)
  call void @log_free(ptr noundef %5)
  %101 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @mn_runtime)
  %102 = getelementptr inbounds %struct.Runtime, ptr %101, i32 0, i32 0
  call void @exception_mgr_throw(ptr noundef %102) #13
  unreachable

103:                                              ; preds = %95
  %104 = load ptr, ptr %3, align 8, !tbaa !5
  call void @engine_commit(ptr noundef %104, ptr noundef %5) #12
  call void @log_free(ptr noundef %5)
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.LogWrite, ptr %105, i32 0, i32 1
  %107 = load i64, ptr %106, align 1, !tbaa !39
  call void @config_lsn_follow(i64 noundef %107)
  call void @llvm.lifetime.end.p0(i64 224, ptr %6) #10
  call void @llvm.lifetime.end.p0(i64 80, ptr %5) #10
  ret void

108:                                              ; preds = %82
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @log_write_first(ptr noundef) #1

declare void @engine_unlock(ptr noundef, ptr noundef, i32 noundef) #5

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden void @log_pushback(ptr noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @event_copy(ptr noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @log_write_next(ptr noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @config_lsn_follow(i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { nounwind returns_twice "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 #4 = { hot inlinehint 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 #5 = { "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 #6 = { alwaysinline 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 #7 = { 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 #8 = { inlinehint noreturn 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 #9 = { hot 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 #10 = { nounwind }
attributes #11 = { nounwind returns_twice }
attributes #12 = { hot }
attributes #13 = { noreturn }

!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 0}
!10 = !{!"Runtime", !11, i64 0, !12, i64 8, !6, i64 312}
!11 = !{!"ExceptionMgr", !6, i64 0}
!12 = !{!"Error", !7, i64 0, !13, i64 256, !6, i64 264, !6, i64 272, !13, i64 280, !6, i64 288, !6, i64 296}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"Exception", !6, i64 0, !16, i64 8, !6, i64 16, !7, i64 24}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!15, !16, i64 8}
!18 = !{!15, !6, i64 16}
!19 = !{!13, !13, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = !{!23, !6, i64 0}
!23 = !{!"Ref", !6, i64 0, !24, i64 8, !25, i64 56}
!24 = !{!"Lockage", !7, i64 0, !6, i64 32, !6, i64 40}
!25 = !{!"Slice", !21, i64 0, !21, i64 8, !26, i64 16}
!26 = !{!"RbtreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24}
!27 = !{!28, !13, i64 16}
!28 = !{!"Part", !29, i64 0, !13, i64 16, !21, i64 24, !21, i64 32, !16, i64 40, !6, i64 48, !30, i64 56, !30, i64 168, !34, i64 280, !36, i64 336, !37, i64 472, !6, i64 496, !6, i64 504, !6, i64 512, !32, i64 520}
!29 = !{!"Id", !21, i64 0, !21, i64 8}
!30 = !{!"Memtable", !6, i64 0, !31, i64 8, !13, i64 16, !13, i64 20, !13, i64 24, !21, i64 32, !21, i64 40, !21, i64 48, !32, i64 56, !13, i64 72, !33, i64 80}
!31 = !{!"Rbtree", !6, i64 0}
!32 = !{!"List", !6, i64 0, !6, i64 8}
!33 = !{!"Heap", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24}
!34 = !{!"File", !13, i64 0, !21, i64 8, !35, i64 16, !32, i64 40}
!35 = !{!"Str", !6, i64 0, !6, i64 8, !16, i64 16}
!36 = !{!"Index", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !29, i64 16, !13, i64 32, !13, i64 36, !21, i64 40, !21, i64 48, !21, i64 56, !21, i64 64, !13, i64 72, !21, i64 76, !21, i64 84, !21, i64 92, !13, i64 100, !21, i64 104, !7, i64 112, !7, i64 113, !7, i64 114}
!37 = !{!"Buf", !6, i64 0, !6, i64 8, !6, i64 16}
!38 = !{!28, !21, i64 440}
!39 = !{!40, !21, i64 4}
!40 = !{!"LogWrite", !13, i64 0, !21, i64 4, !7, i64 12, !13, i64 13, !13, i64 17}
!41 = !{!42, !6, i64 16}
!42 = !{!"LogOp", !6, i64 0, !6, i64 8, !6, i64 16}
!43 = !{!28, !6, i64 48}
!44 = !{!42, !6, i64 8}
!45 = distinct !{!45, !46}
!46 = !{!"llvm.loop.mustprogress"}
!47 = !{!48, !21, i64 28}
!48 = !{!"Log", !37, i64 0, !40, i64 24, !49, i64 48}
!49 = !{!"Iov", !37, i64 0, !13, i64 24, !13, i64 28}


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

%struct.Runtime = type { %struct.ExceptionMgr, %struct.Error, ptr }
%struct.ExceptionMgr = type { ptr }
%struct.Error = type { [256 x i8], i32, ptr, ptr, i32, ptr, ptr }
%struct.Log = type { %struct.Buf, %struct.LogWrite, %struct.Iov }
%struct.Buf = type { ptr, ptr, ptr }
%struct.LogWrite = type <{ i32, i64, i8, i32, i32 }>
%struct.Iov = type { %struct.Buf, i32, i32 }
%struct.Exception = type { ptr, i8, ptr, [1 x %struct.__jmp_buf_tag] }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

@mn_runtime = external thread_local global %struct.Runtime, align 8

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @log_init(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

; Function Attrs: nounwind returns_twice
declare i32 @_setjmp(ptr noundef) local_unnamed_addr #3

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden ptr @log_add(ptr noundef) local_unnamed_addr #4

declare ptr @engine_lock(ptr noundef, i64 noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext) local_unnamed_addr #5

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden void @log_add_event(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare ptr @memtable_set(ptr noundef, ptr noundef) local_unnamed_addr #5

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden zeroext i1 @exception_mgr_leave(ptr noundef, ptr noundef) local_unnamed_addr #6

; Function Attrs: nounwind uwtable
declare hidden void @engine_rollback(ptr noundef, ptr noundef) local_unnamed_addr #7

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @log_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint noreturn nounwind uwtable
declare hidden void @exception_mgr_throw(ptr noundef) local_unnamed_addr #8

; Function Attrs: hot nounwind uwtable
declare hidden void @engine_commit(ptr noundef, ptr noundef) local_unnamed_addr #9

; Function Attrs: nounwind uwtable
define dso_local void @engine_write_replay(ptr noundef %0, ptr noundef %1) local_unnamed_addr #7 {
  %3 = alloca %struct.Log, align 8
  %4 = alloca %struct.Exception, align 8
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %3) #10
  call void @log_init(ptr noundef nonnull %3)
  call void @llvm.lifetime.start.p0(i64 224, ptr nonnull %4) #10
  %5 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @mn_runtime)
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %6, ptr %4, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  store i8 0, ptr %7, align 8, !tbaa !16
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr null, ptr %8, align 8, !tbaa !17
  store ptr %4, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %4, i64 24
  %10 = call i32 @_setjmp(ptr noundef nonnull %9) #11
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %40

12:                                               ; preds = %2
  %13 = call ptr @log_write_first(ptr noundef %1)
  %.not28 = icmp eq ptr %13, null
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %12
  %14 = getelementptr inbounds i8, ptr %1, i64 4
  br label %15

15:                                               ; preds = %.lr.ph, %35
  %.029 = phi ptr [ %13, %.lr.ph ], [ %36, %35 ]
  %16 = call ptr @log_add(ptr noundef nonnull %3) #12
  %17 = load i64, ptr %.029, align 1, !tbaa !18
  %18 = call ptr @engine_lock(ptr noundef %0, i64 noundef %17, i32 noundef 1, i1 noundef zeroext false, i1 noundef zeroext true) #10
  %19 = load ptr, ptr %18, align 8, !tbaa !20
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  %21 = load i32, ptr %20, align 8, !tbaa !25
  %.not26 = icmp eq i32 %21, 0
  br i1 %.not26, label %27, label %22

22:                                               ; preds = %15
  %23 = getelementptr inbounds i8, ptr %19, i64 440
  %24 = load i64, ptr %23, align 8, !tbaa !36
  %25 = load i64, ptr %14, align 1, !tbaa !37
  %.not27 = icmp ult i64 %24, %25
  br i1 %.not27, label %27, label %26

26:                                               ; preds = %22
  call void @engine_unlock(ptr noundef %0, ptr noundef nonnull %18, i32 noundef 1) #10
  call void @log_pushback(ptr noundef nonnull %3) #12
  br label %35

27:                                               ; preds = %22, %15
  %28 = getelementptr inbounds i8, ptr %16, i64 16
  store ptr %18, ptr %28, align 8, !tbaa !39
  %29 = getelementptr inbounds i8, ptr %19, i64 48
  %30 = load ptr, ptr %29, align 8, !tbaa !41
  %31 = getelementptr inbounds i8, ptr %30, i64 80
  %32 = call ptr @event_copy(ptr noundef nonnull %31, ptr noundef nonnull %.029)
  call void @log_add_event(ptr noundef nonnull %3, ptr noundef %16, ptr noundef %32) #12
  %33 = call ptr @memtable_set(ptr noundef %30, ptr noundef %32) #10
  %34 = getelementptr inbounds i8, ptr %16, i64 8
  store ptr %33, ptr %34, align 8, !tbaa !42
  br label %35

35:                                               ; preds = %27, %26
  %36 = call ptr @log_write_next(ptr noundef %1, ptr noundef nonnull %.029)
  %.not = icmp eq ptr %36, null
  br i1 %.not, label %._crit_edge, label %15, !llvm.loop !43

._crit_edge:                                      ; preds = %35, %12
  %37 = getelementptr inbounds i8, ptr %1, i64 4
  %38 = load i64, ptr %37, align 1, !tbaa !37
  %39 = getelementptr inbounds i8, ptr %3, i64 28
  store i64 %38, ptr %39, align 4, !tbaa !45
  br label %40

40:                                               ; preds = %._crit_edge, %2
  %41 = call zeroext i1 @exception_mgr_leave(ptr noundef nonnull %5, ptr noundef nonnull %4)
  br i1 %41, label %42, label %43

42:                                               ; preds = %40
  call void @engine_rollback(ptr noundef %0, ptr noundef nonnull %3)
  call void @log_free(ptr noundef nonnull %3)
  call void @exception_mgr_throw(ptr noundef nonnull %5) #13
  unreachable

43:                                               ; preds = %40
  call void @engine_commit(ptr noundef %0, ptr noundef nonnull %3) #12
  call void @log_free(ptr noundef nonnull %3)
  %44 = getelementptr inbounds i8, ptr %1, i64 4
  %45 = load i64, ptr %44, align 1, !tbaa !37
  call void @config_lsn_follow(i64 noundef %45)
  call void @llvm.lifetime.end.p0(i64 224, ptr nonnull %4) #10
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %3) #10
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @log_write_first(ptr noundef) local_unnamed_addr #1

declare void @engine_unlock(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #5

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden void @log_pushback(ptr noundef) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @event_copy(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @log_write_next(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @config_lsn_follow(i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind returns_twice "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 #4 = { hot inlinehint 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 #5 = { "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 #6 = { alwaysinline 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 #7 = { 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 #8 = { inlinehint noreturn 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 #9 = { hot 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 #10 = { nounwind }
attributes #11 = { nounwind returns_twice }
attributes #12 = { hot }
attributes #13 = { noreturn }

!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, !8, i64 0}
!6 = !{!"Runtime", !7, i64 0, !11, i64 8, !8, i64 312}
!7 = !{!"ExceptionMgr", !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"Error", !9, i64 0, !12, i64 256, !8, i64 264, !8, i64 272, !12, i64 280, !8, i64 288, !8, i64 296}
!12 = !{!"int", !9, i64 0}
!13 = !{!14, !8, i64 0}
!14 = !{!"Exception", !8, i64 0, !15, i64 8, !8, i64 16, !9, i64 24}
!15 = !{!"_Bool", !9, i64 0}
!16 = !{!14, !15, i64 8}
!17 = !{!14, !8, i64 16}
!18 = !{!19, !19, i64 0}
!19 = !{!"long", !9, i64 0}
!20 = !{!21, !8, i64 0}
!21 = !{!"Ref", !8, i64 0, !22, i64 8, !23, i64 56}
!22 = !{!"Lockage", !9, i64 0, !8, i64 32, !8, i64 40}
!23 = !{!"Slice", !19, i64 0, !19, i64 8, !24, i64 16}
!24 = !{!"RbtreeNode", !8, i64 0, !8, i64 8, !8, i64 16, !9, i64 24}
!25 = !{!26, !12, i64 16}
!26 = !{!"Part", !27, i64 0, !12, i64 16, !19, i64 24, !19, i64 32, !15, i64 40, !8, i64 48, !28, i64 56, !28, i64 168, !32, i64 280, !34, i64 336, !35, i64 472, !8, i64 496, !8, i64 504, !8, i64 512, !30, i64 520}
!27 = !{!"Id", !19, i64 0, !19, i64 8}
!28 = !{!"Memtable", !8, i64 0, !29, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !19, i64 32, !19, i64 40, !19, i64 48, !30, i64 56, !12, i64 72, !31, i64 80}
!29 = !{!"Rbtree", !8, i64 0}
!30 = !{!"List", !8, i64 0, !8, i64 8}
!31 = !{!"Heap", !8, i64 0, !8, i64 8, !12, i64 16, !8, i64 24}
!32 = !{!"File", !12, i64 0, !19, i64 8, !33, i64 16, !30, i64 40}
!33 = !{!"Str", !8, i64 0, !8, i64 8, !15, i64 16}
!34 = !{!"Index", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !27, i64 16, !12, i64 32, !12, i64 36, !19, i64 40, !19, i64 48, !19, i64 56, !19, i64 64, !12, i64 72, !19, i64 76, !19, i64 84, !19, i64 92, !12, i64 100, !19, i64 104, !9, i64 112, !9, i64 113, !9, i64 114}
!35 = !{!"Buf", !8, i64 0, !8, i64 8, !8, i64 16}
!36 = !{!26, !19, i64 440}
!37 = !{!38, !19, i64 4}
!38 = !{!"LogWrite", !12, i64 0, !19, i64 4, !9, i64 12, !12, i64 13, !12, i64 17}
!39 = !{!40, !8, i64 16}
!40 = !{!"LogOp", !8, i64 0, !8, i64 8, !8, i64 16}
!41 = !{!26, !8, i64 48}
!42 = !{!40, !8, i64 8}
!43 = distinct !{!43, !44}
!44 = !{!"llvm.loop.mustprogress"}
!45 = !{!46, !19, i64 28}
!46 = !{!"Log", !35, i64 0, !38, i64 24, !47, i64 48}
!47 = !{!"Iov", !35, i64 0, !12, i64 24, !12, i64 28}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass