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

; 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.Str = type { ptr, ptr, i8 }
%struct.Guard = type { ptr, ptr, ptr }
%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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

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

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @guard_runner(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @engine_drop(ptr noundef, i64 noundef, i1 noundef zeroext, i32 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @engine_refresh(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i1 noundef zeroext) #3

; Function Attrs: nounwind uwtable
define dso_local void @engine_rebalance(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.Str, align 8
  %6 = alloca %struct.Guard, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %42, %2
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #5
  call void @str_init(ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #5
  %13 = getelementptr inbounds %struct.Guard, ptr %6, i32 0, i32 0
  store ptr @str_free, ptr %13, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.Guard, ptr %6, i32 0, i32 1
  store ptr %5, ptr %14, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.Guard, ptr %6, i32 0, i32 2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %16 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @mn_runtime)
  %17 = getelementptr inbounds %struct.Runtime, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds %struct.ExceptionMgr, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  store ptr %19, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Exception, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  store ptr %22, ptr %8, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Exception, ptr %23, i32 0, i32 2
  store ptr %6, ptr %24, align 8, !tbaa !17
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %25, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %26, ptr %15, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = call zeroext i1 @engine_rebalance_next(ptr noundef %27, ptr noundef %10, ptr noundef %5)
  br i1 %28, label %30, label %29

29:                                               ; preds = %12
  store i32 2, ptr %11, align 4
  br label %40

30:                                               ; preds = %12
  %31 = call zeroext i1 @str_empty(ptr noundef %5)
  br i1 %31, label %32, label %35

32:                                               ; preds = %30
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load i64, ptr %10, align 8, !tbaa !21
  call void @engine_drop(ptr noundef %33, i64 noundef %34, i1 noundef zeroext true, i32 noundef 9)
  br label %39

35:                                               ; preds = %30
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i64, ptr %10, align 8, !tbaa !21
  call void @engine_refresh(ptr noundef %36, ptr noundef %37, i64 noundef %38, ptr noundef %5, i1 noundef zeroext true)
  br label %39

39:                                               ; preds = %35, %32
  store i32 0, ptr %11, align 4
  br label %40

40:                                               ; preds = %39, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @guard_runner(ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  %41 = load i32, ptr %11, align 4
  switch i32 %41, label %44 [
    i32 0, label %42
    i32 2, label %43
  ]

42:                                               ; preds = %40
  br label %12

43:                                               ; preds = %40
  ret void

44:                                               ; preds = %40
  unreachable
}

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

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @engine_rebalance_next(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @str_empty(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 = { 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 = { 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 = !{!"Guard", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !6, i64 0}
!13 = !{!"Runtime", !14, i64 0, !15, i64 8, !6, i64 312}
!14 = !{!"ExceptionMgr", !6, i64 0}
!15 = !{!"Error", !7, i64 0, !16, i64 256, !6, i64 264, !6, i64 272, !16, i64 280, !6, i64 288, !6, i64 296}
!16 = !{!"int", !7, i64 0}
!17 = !{!18, !6, i64 16}
!18 = !{!"Exception", !6, i64 0, !19, i64 8, !6, i64 16, !7, i64 24}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!10, !6, i64 16}
!21 = !{!22, !22, i64 0}
!22 = !{!"long", !7, i64 0}


; 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.Str = type { ptr, ptr, i8 }
%struct.Guard = type { ptr, ptr, ptr }

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

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

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

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @guard_runner(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @engine_drop(ptr noundef, i64 noundef, i1 noundef zeroext, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @engine_refresh(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @engine_rebalance(ptr noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.Str, align 8
  %4 = alloca %struct.Guard, align 8
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @str_init(ptr noundef nonnull %3)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #5
  store ptr @str_free, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %3, ptr %6, align 8, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %4, i64 16
  %8 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @mn_runtime)
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  store ptr %4, ptr %10, align 8, !tbaa !16
  store ptr %11, ptr %7, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %12 = call zeroext i1 @engine_rebalance_next(ptr noundef %0, ptr noundef nonnull %5, ptr noundef nonnull %3)
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %17
  %13 = call zeroext i1 @str_empty(ptr noundef nonnull %3)
  %14 = load i64, ptr %5, align 8, !tbaa !20
  br i1 %13, label %15, label %16

15:                                               ; preds = %.lr.ph
  call void @engine_drop(ptr noundef %0, i64 noundef %14, i1 noundef zeroext true, i32 noundef 9)
  br label %17

16:                                               ; preds = %.lr.ph
  call void @engine_refresh(ptr noundef %0, ptr noundef %1, i64 noundef %14, ptr noundef nonnull %3, i1 noundef zeroext true)
  br label %17

17:                                               ; preds = %15, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  call void @guard_runner(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @str_init(ptr noundef nonnull %3)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #5
  store ptr @str_free, ptr %4, align 8, !tbaa !5
  store ptr %3, ptr %6, align 8, !tbaa !10
  %18 = load ptr, ptr %8, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  store ptr %4, ptr %19, align 8, !tbaa !16
  store ptr %20, ptr %7, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %21 = call zeroext i1 @engine_rebalance_next(ptr noundef %0, ptr noundef nonnull %5, ptr noundef nonnull %3)
  br i1 %21, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %17, %2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  call void @guard_runner(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  ret void
}

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

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @engine_rebalance_next(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @str_empty(ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 = { 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 = { 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 = !{!"Guard", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !7, i64 0}
!12 = !{!"Runtime", !13, i64 0, !14, i64 8, !7, i64 312}
!13 = !{!"ExceptionMgr", !7, i64 0}
!14 = !{!"Error", !8, i64 0, !15, i64 256, !7, i64 264, !7, i64 272, !15, i64 280, !7, i64 288, !7, i64 296}
!15 = !{!"int", !8, i64 0}
!16 = !{!17, !7, i64 16}
!17 = !{!"Exception", !7, i64 0, !18, i64 8, !7, i64 16, !8, i64 24}
!18 = !{!"_Bool", !8, i64 0}
!19 = !{!6, !7, i64 16}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !8, i64 0}


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