; LLVM IR from cruppstahl/upscaledb :: 3rdparty/libfor (for)

; 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: nounwind uwtable
declare dso_local i32 @for_select_bits(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @for_lower_bound_search_bits(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  store i32 0, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = sub i32 %19, 1
  store i32 %20, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  br label %21

21:                                               ; preds = %50, %6
  %22 = load i32, ptr %15, align 4, !tbaa !9
  %23 = add i32 %22, 1
  %24 = load i32, ptr %16, align 4, !tbaa !9
  %25 = icmp ult i32 %23, %24
  br i1 %25, label %26, label %51

26:                                               ; preds = %21
  %27 = load i32, ptr %15, align 4, !tbaa !9
  %28 = load i32, ptr %16, align 4, !tbaa !9
  %29 = load i32, ptr %15, align 4, !tbaa !9
  %30 = sub i32 %28, %29
  %31 = udiv i32 %30, 2
  %32 = add i32 %27, %31
  store i32 %32, ptr %14, align 4, !tbaa !9
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = load i32, ptr %14, align 4, !tbaa !9
  %37 = call i32 @for_select_bits(ptr noundef %33, i32 noundef %34, i32 noundef %35, i32 noundef %36)
  store i32 %37, ptr %17, align 4, !tbaa !9
  %38 = load i32, ptr %17, align 4, !tbaa !9
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = icmp uge i32 %38, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %26
  %42 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %42, ptr %16, align 4, !tbaa !9
  br label %50

43:                                               ; preds = %26
  %44 = load i32, ptr %17, align 4, !tbaa !9
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = icmp ult i32 %44, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %43
  %48 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %48, ptr %15, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %47, %43
  br label %50

50:                                               ; preds = %49, %41
  br label %21, !llvm.loop !11

51:                                               ; preds = %21
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = load i32, ptr %15, align 4, !tbaa !9
  %56 = call i32 @for_select_bits(ptr noundef %52, i32 noundef %53, i32 noundef %54, i32 noundef %55)
  store i32 %56, ptr %17, align 4, !tbaa !9
  %57 = load i32, ptr %17, align 4, !tbaa !9
  %58 = load i32, ptr %12, align 4, !tbaa !9
  %59 = icmp uge i32 %57, %58
  br i1 %59, label %60, label %64

60:                                               ; preds = %51
  %61 = load i32, ptr %17, align 4, !tbaa !9
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %61, ptr %62, align 4, !tbaa !9
  %63 = load i32, ptr %15, align 4, !tbaa !9
  store i32 %63, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %73

64:                                               ; preds = %51
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = load i32, ptr %16, align 4, !tbaa !9
  %69 = call i32 @for_select_bits(ptr noundef %65, i32 noundef %66, i32 noundef %67, i32 noundef %68)
  store i32 %69, ptr %17, align 4, !tbaa !9
  %70 = load i32, ptr %17, align 4, !tbaa !9
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %70, ptr %71, align 4, !tbaa !9
  %72 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %72, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %73

73:                                               ; preds = %64, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  %74 = load i32, ptr %7, align 4
  ret i32 %74
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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: nounwind uwtable
declare dso_local i32 @for_select_bits(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @for_lower_bound_search_bits(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = add i32 %1, -1
  %8 = icmp ugt i32 %7, 1
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6, %.lr.ph
  %.038 = phi i32 [ %.1, %.lr.ph ], [ %7, %6 ]
  %.03237 = phi i32 [ %.133, %.lr.ph ], [ 0, %6 ]
  %9 = sub i32 %.038, %.03237
  %10 = lshr i32 %9, 1
  %11 = add i32 %10, %.03237
  %12 = tail call i32 @for_select_bits(ptr noundef %0, i32 noundef %2, i32 noundef %3, i32 noundef %11)
  %.not36 = icmp ult i32 %12, %4
  %.133 = select i1 %.not36, i32 %11, i32 %.03237
  %.1 = select i1 %.not36, i32 %.038, i32 %11
  %13 = add i32 %.133, 1
  %14 = icmp ult i32 %13, %.1
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %6
  %.032.lcssa = phi i32 [ 0, %6 ], [ %.133, %.lr.ph ]
  %.0.lcssa = phi i32 [ %7, %6 ], [ %.1, %.lr.ph ]
  %15 = tail call i32 @for_select_bits(ptr noundef %0, i32 noundef %2, i32 noundef %3, i32 noundef %.032.lcssa)
  %.not = icmp ult i32 %15, %4
  br i1 %.not, label %16, label %18

16:                                               ; preds = %._crit_edge
  %17 = tail call i32 @for_select_bits(ptr noundef %0, i32 noundef %2, i32 noundef %3, i32 noundef %.0.lcssa)
  br label %18

18:                                               ; preds = %._crit_edge, %16
  %storemerge = phi i32 [ %17, %16 ], [ %15, %._crit_edge ]
  %.034 = phi i32 [ %.0.lcssa, %16 ], [ %.032.lcssa, %._crit_edge ]
  store i32 %storemerge, ptr %5, align 4, !tbaa !7
  ret i32 %.034
}

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}


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