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

; 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.WorkerMgr = type { i32, ptr }
%struct.Worker = type { %struct.Refresh, ptr, i32, ptr, %struct.Thread }
%struct.Refresh = type { ptr, ptr, ptr, ptr, ptr, ptr, %struct.Merger, ptr }
%struct.Merger = type { ptr, %struct.PartIterator, %struct.MemtableIterator, %struct.MergeIterator, %struct.Writer }
%struct.PartIterator = type { %struct.Iterator, %struct.RegionIterator, %struct.IndexIterator, ptr, ptr, %struct.Reader }
%struct.Iterator = type { ptr, ptr, ptr, ptr }
%struct.RegionIterator = type { %struct.Iterator, ptr, i32, ptr, ptr }
%struct.IndexIterator = type { ptr, ptr, ptr, i32 }
%struct.Reader = type { ptr, ptr, ptr, %struct.Buf, %struct.Buf, %struct.Buf }
%struct.Buf = type { ptr, ptr, ptr }
%struct.MemtableIterator = type { %struct.Iterator, ptr, ptr, i32, ptr, %struct.List }
%struct.List = type { ptr, ptr }
%struct.MergeIterator = type { %struct.Iterator, ptr, %struct.Buf, i32, ptr }
%struct.Writer = type { ptr, %struct.Iov, %struct.RegionWriter, %struct.IndexWriter, ptr, ptr, ptr }
%struct.Iov = type { %struct.Buf, i32, i32 }
%struct.RegionWriter = type { %struct.Buf, %struct.Buf, %struct.Buf, %struct.Buf, ptr, i32, ptr, ptr }
%struct.IndexWriter = type { i8, %struct.Buf, %struct.Buf, ptr, i32, %struct.Buf, ptr, ptr, i8, %struct.Index }
%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.Id = type { i64, i64 }
%struct.Thread = type { i64, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @worker_mgr_start(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  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 4, ptr %5) #4
  %8 = call i32 @config_workers()
  store i32 %8, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %9 = call i32 @config_workers_upload()
  store i32 %9, ptr %6, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = add nsw i32 %10, %11
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.WorkerMgr, ptr %13, i32 0, i32 0
  store i32 %12, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.WorkerMgr, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = sext i32 %17 to i64
  %19 = mul i64 952, %18
  %20 = call ptr @mn_malloc(i64 noundef %19)
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.WorkerMgr, ptr %21, i32 0, i32 1
  store ptr %20, ptr %22, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %42

25:                                               ; preds = %2
  br label %26

26:                                               ; preds = %38, %25
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %41

30:                                               ; preds = %26
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.WorkerMgr, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.Worker, ptr %33, i64 %35
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  call void @worker_init(ptr noundef %36, ptr noundef %37, i32 noundef 0)
  br label %38

38:                                               ; preds = %30
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %7, align 4, !tbaa !9
  br label %26, !llvm.loop !14

41:                                               ; preds = %26
  br label %77

42:                                               ; preds = %2
  br label %43

43:                                               ; preds = %55, %42
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %58

47:                                               ; preds = %43
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.WorkerMgr, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.Worker, ptr %50, i64 %52
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  call void @worker_init(ptr noundef %53, ptr noundef %54, i32 noundef 1)
  br label %55

55:                                               ; preds = %47
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %7, align 4, !tbaa !9
  br label %43, !llvm.loop !16

58:                                               ; preds = %43
  br label %59

59:                                               ; preds = %73, %58
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.WorkerMgr, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 8, !tbaa !11
  %64 = icmp slt i32 %60, %63
  br i1 %64, label %65, label %76

65:                                               ; preds = %59
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.WorkerMgr, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !13
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds %struct.Worker, ptr %68, i64 %70
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  call void @worker_init(ptr noundef %71, ptr noundef %72, i32 noundef 2)
  br label %73

73:                                               ; preds = %65
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %7, align 4, !tbaa !9
  br label %59, !llvm.loop !17

76:                                               ; preds = %59
  br label %77

77:                                               ; preds = %76, %41
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %91, %77
  %79 = load i32, ptr %7, align 4, !tbaa !9
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.WorkerMgr, ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 8, !tbaa !11
  %83 = icmp slt i32 %79, %82
  br i1 %83, label %84, label %94

84:                                               ; preds = %78
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.WorkerMgr, ptr %85, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !13
  %88 = load i32, ptr %7, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds %struct.Worker, ptr %87, i64 %89
  call void @worker_start(ptr noundef %90)
  br label %91

91:                                               ; preds = %84
  %92 = load i32, ptr %7, align 4, !tbaa !9
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %7, align 4, !tbaa !9
  br label %78, !llvm.loop !18

94:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @config_workers() #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @config_workers_upload() #2

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

declare void @worker_init(ptr noundef, ptr noundef, i32 noundef) #3

declare void @worker_start(ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"WorkerMgr", !10, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !15}


; 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.Worker = type { %struct.Refresh, ptr, i32, ptr, %struct.Thread }
%struct.Refresh = type { ptr, ptr, ptr, ptr, ptr, ptr, %struct.Merger, ptr }
%struct.Merger = type { ptr, %struct.PartIterator, %struct.MemtableIterator, %struct.MergeIterator, %struct.Writer }
%struct.PartIterator = type { %struct.Iterator, %struct.RegionIterator, %struct.IndexIterator, ptr, ptr, %struct.Reader }
%struct.Iterator = type { ptr, ptr, ptr, ptr }
%struct.RegionIterator = type { %struct.Iterator, ptr, i32, ptr, ptr }
%struct.IndexIterator = type { ptr, ptr, ptr, i32 }
%struct.Reader = type { ptr, ptr, ptr, %struct.Buf, %struct.Buf, %struct.Buf }
%struct.Buf = type { ptr, ptr, ptr }
%struct.MemtableIterator = type { %struct.Iterator, ptr, ptr, i32, ptr, %struct.List }
%struct.List = type { ptr, ptr }
%struct.MergeIterator = type { %struct.Iterator, ptr, %struct.Buf, i32, ptr }
%struct.Writer = type { ptr, %struct.Iov, %struct.RegionWriter, %struct.IndexWriter, ptr, ptr, ptr }
%struct.Iov = type { %struct.Buf, i32, i32 }
%struct.RegionWriter = type { %struct.Buf, %struct.Buf, %struct.Buf, %struct.Buf, ptr, i32, ptr, ptr }
%struct.IndexWriter = type { i8, %struct.Buf, %struct.Buf, ptr, i32, %struct.Buf, ptr, ptr, i8, %struct.Index }
%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.Id = type { i64, i64 }
%struct.Thread = type { i64, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @worker_mgr_start(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @config_workers()
  %4 = tail call i32 @config_workers_upload()
  %5 = add nsw i32 %4, %3
  store i32 %5, ptr %0, align 8, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = mul nsw i64 %6, 952
  %8 = tail call ptr @mn_malloc(i64 noundef %7)
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %8, ptr %9, align 8, !tbaa !11
  %10 = icmp eq i32 %4, 0
  %11 = icmp sgt i32 %3, 0
  br i1 %10, label %.preheader, label %.preheader30

.preheader30:                                     ; preds = %2
  br i1 %11, label %.lr.ph.preheader, label %.preheader28

.lr.ph.preheader:                                 ; preds = %.preheader30
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %.lr.ph

.preheader:                                       ; preds = %2
  br i1 %11, label %.lr.ph35.preheader, label %.loopexitthread-pre-split

.lr.ph35.preheader:                               ; preds = %.preheader
  %wide.trip.count46 = zext nneg i32 %3 to i64
  br label %.lr.ph35

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %.lr.ph35
  %indvars.iv43 = phi i64 [ 0, %.lr.ph35.preheader ], [ %indvars.iv.next44, %.lr.ph35 ]
  %12 = load ptr, ptr %9, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.Worker, ptr %12, i64 %indvars.iv43
  tail call void @worker_init(ptr noundef %13, ptr noundef %1, i32 noundef 0) #3
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond47.not = icmp eq i64 %indvars.iv.next44, %wide.trip.count46
  br i1 %exitcond47.not, label %.loopexitthread-pre-split, label %.lr.ph35, !llvm.loop !12

.preheader28:                                     ; preds = %.lr.ph, %.preheader30
  %.1.lcssa = phi i32 [ 0, %.preheader30 ], [ %3, %.lr.ph ]
  %14 = load i32, ptr %0, align 8, !tbaa !5
  %15 = icmp slt i32 %.1.lcssa, %14
  br i1 %15, label %.lr.ph33.preheader, label %.loopexit

.lr.ph33.preheader:                               ; preds = %.preheader28
  %16 = zext nneg i32 %.1.lcssa to i64
  br label %.lr.ph33

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %17 = load ptr, ptr %9, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.Worker, ptr %17, i64 %indvars.iv
  tail call void @worker_init(ptr noundef %18, ptr noundef %1, i32 noundef 1) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader28, label %.lr.ph, !llvm.loop !14

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %.lr.ph33
  %indvars.iv40 = phi i64 [ %16, %.lr.ph33.preheader ], [ %indvars.iv.next41, %.lr.ph33 ]
  %19 = load ptr, ptr %9, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.Worker, ptr %19, i64 %indvars.iv40
  tail call void @worker_init(ptr noundef %20, ptr noundef %1, i32 noundef 2) #3
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %21 = load i32, ptr %0, align 8, !tbaa !5
  %22 = trunc nuw i64 %indvars.iv.next41 to i32
  %23 = icmp sgt i32 %21, %22
  br i1 %23, label %.lr.ph33, label %.loopexit, !llvm.loop !15

.loopexitthread-pre-split:                        ; preds = %.lr.ph35, %.preheader
  %.pr = load i32, ptr %0, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph33, %.loopexitthread-pre-split, %.preheader28
  %24 = phi i32 [ %.pr, %.loopexitthread-pre-split ], [ %14, %.preheader28 ], [ %21, %.lr.ph33 ]
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph37, label %._crit_edge

.lr.ph37:                                         ; preds = %.loopexit, %.lr.ph37
  %indvars.iv48 = phi i64 [ %indvars.iv.next49, %.lr.ph37 ], [ 0, %.loopexit ]
  %26 = load ptr, ptr %9, align 8, !tbaa !11
  %27 = getelementptr inbounds %struct.Worker, ptr %26, i64 %indvars.iv48
  tail call void @worker_start(ptr noundef %27) #3
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %28 = load i32, ptr %0, align 8, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = icmp slt i64 %indvars.iv.next49, %29
  br i1 %30, label %.lr.ph37, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph37, %.loopexit
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @config_workers() local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @config_workers_upload() local_unnamed_addr #1

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

declare void @worker_init(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @worker_start(ptr noundef) local_unnamed_addr #2

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


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