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

; 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.Engine = type { %struct.Mutex, %struct.CondVar, %struct.Mapping, %struct.Pipeline, %struct.StorageMgr, ptr, ptr, ptr }
%struct.Mutex = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct.CondVar = type { %union.pthread_cond_t }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }
%struct.Mapping = type { %struct.Rbtree, i32 }
%struct.Rbtree = type { ptr }
%struct.Pipeline = type { %struct.List, i32, ptr }
%struct.List = type { ptr, ptr }
%struct.StorageMgr = type { %struct.List, i32, ptr }
%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.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.Buf = type { ptr, ptr, ptr }
%struct.Event = type <{ i64, i8, i8, i32, [0 x i8] }>

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @ref_of(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: nounwind uwtable
define dso_local void @engine_set_serial(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Engine, ptr %10, i32 0, i32 2
  %12 = call ptr @mapping_max(ptr noundef %11)
  store ptr %12, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %1
  store i32 1, ptr %4, align 4
  br label %63

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call ptr @ref_of(ptr noundef %17)
  store ptr %18, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Ref, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  store ptr %21, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  store i8 0, ptr %7, align 1, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !17
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Part, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !18
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %38

26:                                               ; preds = %16
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Part, ptr %27, i32 0, i32 9
  %29 = getelementptr inbounds %struct.Index, ptr %28, i32 0, i32 11
  %30 = load i32, ptr %29, align 8, !tbaa !30
  %31 = icmp ugt i32 %30, 0
  br i1 %31, label %32, label %38

32:                                               ; preds = %26
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Part, ptr %33, i32 0, i32 9
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Part, ptr %35, i32 0, i32 10
  %37 = call i64 @index_max(ptr noundef %34, ptr noundef %36)
  store i64 %37, ptr %8, align 8, !tbaa !17
  store i8 1, ptr %7, align 1, !tbaa !15
  br label %38

38:                                               ; preds = %32, %26, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Part, ptr %39, i32 0, i32 5
  %41 = load ptr, ptr %40, align 8, !tbaa !31
  %42 = call ptr @memtable_max(ptr noundef %41)
  store ptr %42, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %55

45:                                               ; preds = %38
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Event, ptr %46, i32 0, i32 0
  %48 = load i64, ptr %47, align 1, !tbaa !17
  %49 = load i64, ptr %8, align 8, !tbaa !17
  %50 = icmp uge i64 %48, %49
  br i1 %50, label %51, label %55

51:                                               ; preds = %45
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Event, ptr %52, i32 0, i32 0
  %54 = load i64, ptr %53, align 1, !tbaa !17
  store i64 %54, ptr %8, align 8, !tbaa !17
  store i8 1, ptr %7, align 1, !tbaa !15
  br label %55

55:                                               ; preds = %51, %45, %38
  %56 = load i8, ptr %7, align 1, !tbaa !15, !range !32, !noundef !33
  %57 = trunc i8 %56 to i1
  br i1 %57, label %58, label %61

58:                                               ; preds = %55
  %59 = load i64, ptr %8, align 8, !tbaa !17
  %60 = add i64 %59, 1
  store i64 %60, ptr %8, align 8, !tbaa !17
  br label %61

61:                                               ; preds = %58, %55
  %62 = load i64, ptr %8, align 8, !tbaa !17
  call void @config_ssn_set(i64 noundef %62)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  store i32 0, ptr %4, align 4
  br label %63

63:                                               ; preds = %61, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  %64 = load i32, ptr %4, align 4
  switch i32 %64, label %66 [
    i32 0, label %65
    i32 1, label %65
  ]

65:                                               ; preds = %63, %63
  ret void

66:                                               ; preds = %63
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @mapping_max(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @index_max(ptr noundef, ptr noundef) #3

declare ptr @memtable_max(ptr noundef) #4

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #4 = { "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 = { 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, !6, i64 0}
!10 = !{!"Ref", !6, i64 0, !11, i64 8, !12, i64 56}
!11 = !{!"Lockage", !7, i64 0, !6, i64 32, !6, i64 40}
!12 = !{!"Slice", !13, i64 0, !13, i64 8, !14, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!"RbtreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24}
!15 = !{!16, !16, i64 0}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!13, !13, i64 0}
!18 = !{!19, !21, i64 16}
!19 = !{!"Part", !20, i64 0, !21, i64 16, !13, i64 24, !13, i64 32, !16, i64 40, !6, i64 48, !22, i64 56, !22, i64 168, !26, i64 280, !28, i64 336, !29, i64 472, !6, i64 496, !6, i64 504, !6, i64 512, !24, i64 520}
!20 = !{!"Id", !13, i64 0, !13, i64 8}
!21 = !{!"int", !7, i64 0}
!22 = !{!"Memtable", !6, i64 0, !23, i64 8, !21, i64 16, !21, i64 20, !21, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !24, i64 56, !21, i64 72, !25, i64 80}
!23 = !{!"Rbtree", !6, i64 0}
!24 = !{!"List", !6, i64 0, !6, i64 8}
!25 = !{!"Heap", !6, i64 0, !6, i64 8, !21, i64 16, !6, i64 24}
!26 = !{!"File", !21, i64 0, !13, i64 8, !27, i64 16, !24, i64 40}
!27 = !{!"Str", !6, i64 0, !6, i64 8, !16, i64 16}
!28 = !{!"Index", !21, i64 0, !21, i64 4, !21, i64 8, !21, i64 12, !20, i64 16, !21, i64 32, !21, i64 36, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !21, i64 72, !13, i64 76, !13, i64 84, !13, i64 92, !21, i64 100, !13, i64 104, !7, i64 112, !7, i64 113, !7, i64 114}
!29 = !{!"Buf", !6, i64 0, !6, i64 8, !6, i64 16}
!30 = !{!19, !21, i64 408}
!31 = !{!19, !6, i64 48}
!32 = !{i8 0, i8 2}
!33 = !{}


; 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: alwaysinline nounwind uwtable
declare hidden ptr @ref_of(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @engine_set_serial(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 88
  %3 = tail call ptr @mapping_max(ptr noundef nonnull %2)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %24, label %4

4:                                                ; preds = %1
  %5 = tail call ptr @ref_of(ptr noundef nonnull %3)
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !14
  %.not20 = icmp eq i32 %8, 0
  br i1 %.not20, label %16, label %9

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %6, i64 408
  %11 = load i32, ptr %10, align 8, !tbaa !27
  %.not21 = icmp eq i32 %11, 0
  br i1 %.not21, label %16, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %6, i64 336
  %14 = getelementptr inbounds i8, ptr %6, i64 472
  %15 = tail call i64 @index_max(ptr noundef nonnull %13, ptr noundef nonnull %14)
  br label %16

16:                                               ; preds = %12, %9, %4
  %.015 = phi i8 [ 1, %12 ], [ 0, %9 ], [ 0, %4 ]
  %.0 = phi i64 [ %15, %12 ], [ 0, %9 ], [ 0, %4 ]
  %17 = getelementptr inbounds i8, ptr %6, i64 48
  %18 = load ptr, ptr %17, align 8, !tbaa !28
  %19 = tail call ptr @memtable_max(ptr noundef %18) #5
  %.not22 = icmp eq ptr %19, null
  br i1 %.not22, label %22, label %20

20:                                               ; preds = %16
  %21 = load i64, ptr %19, align 1, !tbaa !29
  %.not23 = icmp ult i64 %21, %.0
  %spec.select = select i1 %.not23, i8 %.015, i8 1
  %spec.select24 = tail call i64 @llvm.umax.i64(i64 %21, i64 %.0)
  br label %22

22:                                               ; preds = %20, %16
  %.116 = phi i8 [ %.015, %16 ], [ %spec.select, %20 ]
  %.1 = phi i64 [ %.0, %16 ], [ %spec.select24, %20 ]
  %23 = zext nneg i8 %.116 to i64
  %spec.select25 = add i64 %.1, %23
  tail call void @config_ssn_set(i64 noundef %spec.select25)
  br label %24

24:                                               ; preds = %1, %22
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @index_max(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @memtable_max(ptr noundef) local_unnamed_addr #3

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

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

attributes #0 = { 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 #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 = { 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 #3 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 0}
!6 = !{!"Ref", !7, i64 0, !10, i64 8, !11, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"Lockage", !8, i64 0, !7, i64 32, !7, i64 40}
!11 = !{!"Slice", !12, i64 0, !12, i64 8, !13, i64 16}
!12 = !{!"long", !8, i64 0}
!13 = !{!"RbtreeNode", !7, i64 0, !7, i64 8, !7, i64 16, !8, i64 24}
!14 = !{!15, !17, i64 16}
!15 = !{!"Part", !16, i64 0, !17, i64 16, !12, i64 24, !12, i64 32, !18, i64 40, !7, i64 48, !19, i64 56, !19, i64 168, !23, i64 280, !25, i64 336, !26, i64 472, !7, i64 496, !7, i64 504, !7, i64 512, !21, i64 520}
!16 = !{!"Id", !12, i64 0, !12, i64 8}
!17 = !{!"int", !8, i64 0}
!18 = !{!"_Bool", !8, i64 0}
!19 = !{!"Memtable", !7, i64 0, !20, i64 8, !17, i64 16, !17, i64 20, !17, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !21, i64 56, !17, i64 72, !22, i64 80}
!20 = !{!"Rbtree", !7, i64 0}
!21 = !{!"List", !7, i64 0, !7, i64 8}
!22 = !{!"Heap", !7, i64 0, !7, i64 8, !17, i64 16, !7, i64 24}
!23 = !{!"File", !17, i64 0, !12, i64 8, !24, i64 16, !21, i64 40}
!24 = !{!"Str", !7, i64 0, !7, i64 8, !18, i64 16}
!25 = !{!"Index", !17, i64 0, !17, i64 4, !17, i64 8, !17, i64 12, !16, i64 16, !17, i64 32, !17, i64 36, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !17, i64 72, !12, i64 76, !12, i64 84, !12, i64 92, !17, i64 100, !12, i64 104, !8, i64 112, !8, i64 113, !8, i64 114}
!26 = !{!"Buf", !7, i64 0, !7, i64 8, !7, i64 16}
!27 = !{!15, !17, i64 408}
!28 = !{!15, !7, i64 48}
!29 = !{!12, !12, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass