; LLVM IR from cruppstahl/upscaledb :: 3rdparty/simdcomp (simdfor)

; 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 @simdselectFOR(i32 noundef, ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @simdsearchwithlengthFOR(i32 noundef %0, ptr 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 ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %17 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %17, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 0, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  br label %18

18:                                               ; preds = %45, %6
  %19 = load i32, ptr %13, align 4, !tbaa !5
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %21, label %46

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %22 = load i32, ptr %13, align 4, !tbaa !5
  %23 = sdiv i32 %22, 2
  store i32 %23, ptr %16, align 4, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = load i32, ptr %14, align 4, !tbaa !5
  %28 = load i32, ptr %16, align 4, !tbaa !5
  %29 = add nsw i32 %27, %28
  %30 = call i32 @simdselectFOR(i32 noundef %24, ptr noundef %25, i32 noundef %26, i32 noundef %29)
  store i32 %30, ptr %15, align 4, !tbaa !5
  %31 = load i32, ptr %15, align 4, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !5
  %33 = icmp ult i32 %31, %32
  br i1 %33, label %34, label %43

34:                                               ; preds = %21
  %35 = load i32, ptr %16, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  %37 = load i32, ptr %14, align 4, !tbaa !5
  %38 = add nsw i32 %37, %36
  store i32 %38, ptr %14, align 4, !tbaa !5
  %39 = load i32, ptr %16, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  %41 = load i32, ptr %13, align 4, !tbaa !5
  %42 = sub nsw i32 %41, %40
  store i32 %42, ptr %13, align 4, !tbaa !5
  br label %45

43:                                               ; preds = %21
  %44 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %44, ptr %13, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %43, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  br label %18, !llvm.loop !11

46:                                               ; preds = %18
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = load i32, ptr %14, align 4, !tbaa !5
  %51 = call i32 @simdselectFOR(i32 noundef %47, ptr noundef %48, i32 noundef %49, i32 noundef %50)
  %52 = load ptr, ptr %12, align 8, !tbaa !9
  store i32 %51, ptr %52, align 4, !tbaa !5
  %53 = load i32, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  ret i32 %53
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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 @simdselectFOR(i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

.lr.ph:                                           ; preds = %6, %.lr.ph
  %.023 = phi i32 [ %.1, %.lr.ph ], [ %3, %6 ]
  %.02022 = phi i32 [ %.121, %.lr.ph ], [ 0, %6 ]
  %8 = lshr i32 %.023, 1
  %9 = add nuw nsw i32 %8, %.02022
  %10 = tail call i32 @simdselectFOR(i32 noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %9)
  %11 = icmp ult i32 %10, %4
  %12 = add nuw nsw i32 %8, 1
  %13 = sub nsw i32 %.023, %12
  %14 = select i1 %11, i32 %12, i32 0
  %.121 = add nuw nsw i32 %14, %.02022
  %.1 = select i1 %11, i32 %13, i32 %8
  %15 = icmp sgt i32 %.1, 0
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %6
  %.020.lcssa = phi i32 [ 0, %6 ], [ %.121, %.lr.ph ]
  %16 = tail call i32 @simdselectFOR(i32 noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %.020.lcssa)
  store i32 %16, ptr %5, align 4, !tbaa !7
  ret i32 %.020.lcssa
}

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