; LLVM IR from erthink/libmdbx :: src (osal)

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

; 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: cold nounwind optsize uwtable
define dso_local void @osal_jitter(i1 noundef zeroext %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = zext i1 %0 to i8
  store i8 %6, ptr %2, align 1, !tbaa !5
  br label %7

7:                                                ; preds = %36, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %8 = call i64 @llvm.x86.rdtsc()
  %9 = trunc i64 %8 to i32
  %10 = mul i32 5296013, %9
  store i32 %10, ptr %3, align 4, !tbaa !9
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = lshr i32 %11, 11
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = xor i32 %13, %12
  store i32 %14, ptr %3, align 4, !tbaa !9
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = mul i32 %15, 25810541
  store i32 %16, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = load i8, ptr %2, align 1, !tbaa !5, !range !11, !noundef !12
  %19 = trunc i8 %18 to i1
  %20 = zext i1 %19 to i64
  %21 = select i1 %19, i32 29, i32 43
  %22 = urem i32 %17, %21
  store i32 %22, ptr %4, align 4, !tbaa !9
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 14
  br i1 %24, label %25, label %26

25:                                               ; preds = %7
  store i32 2, ptr %5, align 4
  br label %34

26:                                               ; preds = %7
  %27 = call i32 @sched_yield() #2
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = icmp sgt i32 %28, 28
  br i1 %29, label %30, label %33

30:                                               ; preds = %26
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = call i32 @usleep(i32 noundef %31)
  br label %33

33:                                               ; preds = %30, %26
  store i32 0, ptr %5, align 4
  br label %34

34:                                               ; preds = %33, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  %35 = load i32, ptr %5, align 4
  switch i32 %35, label %38 [
    i32 0, label %36
    i32 2, label %37
  ]

36:                                               ; preds = %34
  br label %7

37:                                               ; preds = %34
  ret void

38:                                               ; preds = %34
  unreachable
}

; Function Attrs: nounwind
declare i64 @llvm.x86.rdtsc() #2

; Function Attrs: nounwind
declare i32 @sched_yield() #3

declare i32 @usleep(i32 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { cold nounwind optsize 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 }
attributes #3 = { nounwind "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" }

!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 = !{!"_Bool", !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 = !{i8 0, i8 2}
!12 = !{}


; 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: cold nounwind optsize uwtable
define dso_local void @osal_jitter(i1 noundef zeroext %0) local_unnamed_addr #0 {
  %2 = tail call i64 @llvm.x86.rdtsc()
  %3 = trunc i64 %2 to i32
  %4 = mul i32 %3, 5296013
  %5 = lshr i32 %4, 11
  %6 = xor i32 %5, %4
  %7 = mul i32 %6, 25810541
  %8 = select i1 %0, i32 29, i32 43
  %9 = urem i32 %7, %8
  %10 = icmp ult i32 %9, 14
  br i1 %10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %16
  %11 = phi i32 [ %23, %16 ], [ %9, %1 ]
  %12 = tail call i32 @sched_yield() #1
  %13 = icmp ugt i32 %11, 28
  br i1 %13, label %14, label %16

14:                                               ; preds = %.lr.ph
  %15 = tail call i32 @usleep(i32 noundef %11) #1
  br label %16

16:                                               ; preds = %.lr.ph, %14
  %17 = tail call i64 @llvm.x86.rdtsc()
  %18 = trunc i64 %17 to i32
  %19 = mul i32 %18, 5296013
  %20 = lshr i32 %19, 11
  %21 = xor i32 %20, %19
  %22 = mul i32 %21, 25810541
  %23 = urem i32 %22, %8
  %24 = icmp ult i32 %23, 14
  br i1 %24, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %16, %1
  ret void
}

; Function Attrs: nounwind
declare i64 @llvm.x86.rdtsc() #1

; Function Attrs: nounwind
declare i32 @sched_yield() local_unnamed_addr #2

declare i32 @usleep(i32 noundef) local_unnamed_addr #3

attributes #0 = { cold nounwind optsize 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 }
attributes #2 = { nounwind "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" }

!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)"}


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