; LLVM IR from jgaeddert/liquid-dsp :: src/sequence/bench (bsequence_benchmark)

; 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: nounwind uwtable
define dso_local void @bsequence_correlate_bench(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = mul i64 %14, 1000
  store i64 %15, ptr %13, align 8, !tbaa !11
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = udiv i64 %19, %17
  store i64 %20, ptr %18, align 8, !tbaa !11
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = icmp ult i64 %22, 1
  br i1 %23, label %24, label %26

24:                                               ; preds = %4
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 1, ptr %25, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %24, %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = call ptr @bsequence_create(i32 noundef %27)
  store ptr %28, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = call ptr @bsequence_create(i32 noundef %29)
  store ptr %30, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = call i32 @getrusage(i32 noundef 0, ptr noundef %31) #4
  store i64 0, ptr %11, align 8, !tbaa !11
  br label %33

33:                                               ; preds = %68, %26
  %34 = load i64, ptr %11, align 8, !tbaa !11
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load i64, ptr %35, align 8, !tbaa !11
  %37 = icmp ult i64 %34, %36
  br i1 %37, label %38, label %71

38:                                               ; preds = %33
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = call i32 @bsequence_correlate(ptr noundef %39, ptr noundef %40)
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = add nsw i32 %42, %41
  store i32 %43, ptr %12, align 4, !tbaa !9
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = call i32 @bsequence_correlate(ptr noundef %44, ptr noundef %45)
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = sub nsw i32 %47, %46
  store i32 %48, ptr %12, align 4, !tbaa !9
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = call i32 @bsequence_correlate(ptr noundef %49, ptr noundef %50)
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = add nsw i32 %52, %51
  store i32 %53, ptr %12, align 4, !tbaa !9
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = call i32 @bsequence_correlate(ptr noundef %54, ptr noundef %55)
  %57 = load i32, ptr %12, align 4, !tbaa !9
  %58 = sub nsw i32 %57, %56
  store i32 %58, ptr %12, align 4, !tbaa !9
  %59 = load i32, ptr %12, align 4, !tbaa !9
  %60 = icmp sgt i32 %59, 0
  br i1 %60, label %61, label %63

61:                                               ; preds = %38
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  br label %65

63:                                               ; preds = %38
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %63, %61
  %66 = phi ptr [ %62, %61 ], [ %64, %63 ]
  %67 = call i32 @bsequence_push(ptr noundef %66, i32 noundef 1)
  br label %68

68:                                               ; preds = %65
  %69 = load i64, ptr %11, align 8, !tbaa !11
  %70 = add i64 %69, 1
  store i64 %70, ptr %11, align 8, !tbaa !11
  br label %33, !llvm.loop !13

71:                                               ; preds = %33
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = call i32 @getrusage(i32 noundef 0, ptr noundef %72) #4
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load i64, ptr %74, align 8, !tbaa !11
  %76 = mul i64 %75, 4
  store i64 %76, ptr %74, align 8, !tbaa !11
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = call i32 @bsequence_destroy(ptr noundef %77)
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = call i32 @bsequence_destroy(ptr noundef %79)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

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

declare ptr @bsequence_create(i32 noundef) #2

; Function Attrs: nounwind
declare i32 @getrusage(i32 noundef, ptr noundef) #3

declare i32 @bsequence_correlate(ptr noundef, ptr noundef) #2

declare i32 @bsequence_push(ptr noundef, i32 noundef) #2

declare i32 @bsequence_destroy(ptr noundef) #2

; 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 = { "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 "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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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
define dso_local void @bsequence_correlate_bench(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = mul i64 %5, 1000
  %7 = zext i32 %3 to i64
  %8 = udiv i64 %6, %7
  %9 = icmp ult i64 %6, %7
  %spec.select = select i1 %9, i64 1, i64 %8
  store i64 %spec.select, ptr %2, align 8, !tbaa !5
  %10 = tail call ptr @bsequence_create(i32 noundef %3) #3
  %11 = tail call ptr @bsequence_create(i32 noundef %3) #3
  %12 = tail call i32 @getrusage(i32 noundef 0, ptr noundef %0) #3
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i64 %13, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.033 = phi i32 [ %20, %.lr.ph ], [ 0, %4 ]
  %.02932 = phi i64 [ %24, %.lr.ph ], [ 0, %4 ]
  %14 = tail call i32 @bsequence_correlate(ptr noundef %10, ptr noundef %11) #3
  %15 = tail call i32 @bsequence_correlate(ptr noundef %10, ptr noundef %11) #3
  %16 = tail call i32 @bsequence_correlate(ptr noundef %10, ptr noundef %11) #3
  %17 = tail call i32 @bsequence_correlate(ptr noundef %10, ptr noundef %11) #3
  %.neg31 = add i32 %14, %.033
  %18 = add i32 %.neg31, %16
  %19 = add i32 %15, %17
  %20 = sub i32 %18, %19
  %21 = icmp sgt i32 %20, 0
  %22 = select i1 %21, ptr %10, ptr %11
  %23 = tail call i32 @bsequence_push(ptr noundef %22, i32 noundef 1) #3
  %24 = add nuw i64 %.02932, 1
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %4
  %27 = tail call i32 @getrusage(i32 noundef 0, ptr noundef %1) #3
  %28 = load i64, ptr %2, align 8, !tbaa !5
  %29 = shl i64 %28, 2
  store i64 %29, ptr %2, align 8, !tbaa !5
  %30 = tail call i32 @bsequence_destroy(ptr noundef %10) #3
  %31 = tail call i32 @bsequence_destroy(ptr noundef %11) #3
  ret void
}

declare ptr @bsequence_create(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @getrusage(i32 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @bsequence_correlate(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @bsequence_push(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @bsequence_destroy(ptr noundef) local_unnamed_addr #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 = { "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 "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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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