; LLVM IR from unum-cloud/usearch :: c (test)

; 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.usearch_init_options_t = type { i32, ptr, i32, i64, i64, i64, i64, i8 }

@.str.5 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @expect(i1 noundef zeroext, ptr noundef) #0

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @create_vectors(i64 noundef, i64 noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @create_options(ptr dead_on_unwind noalias writable sret(%struct.usearch_init_options_t) align 8, i64 noundef) #0

declare ptr @usearch_init(ptr noundef, ptr noundef) #1

declare void @usearch_free(ptr noundef, ptr noundef) #1

declare i64 @usearch_size(ptr noundef, ptr noundef) #1

declare i64 @usearch_capacity(ptr noundef, ptr noundef) #1

declare void @usearch_reserve(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @test_add_vector(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.usearch_init_options_t, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i64 noundef %13, i64 noundef %14)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr null, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr %6) #4
  %16 = load i64, ptr %4, align 8, !tbaa !5
  call void @create_options(ptr dead_on_unwind writable sret(%struct.usearch_init_options_t) align 8 %6, i64 noundef %16)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %17 = call ptr @usearch_init(ptr noundef %6, ptr noundef %5)
  store ptr %17, ptr %7, align 8, !tbaa !9
  %18 = load ptr, ptr %7, align 8, !tbaa !9
  %19 = load i64, ptr %3, align 8, !tbaa !5
  call void @usearch_reserve(ptr noundef %18, i64 noundef %19, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = call ptr @create_vectors(i64 noundef %20, i64 noundef %21)
  store ptr %22, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %41, %2
  %24 = load i64, ptr %9, align 8, !tbaa !5
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %44

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %29 = load i64, ptr %9, align 8, !tbaa !5
  store i64 %29, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !9
  %31 = load i64, ptr %10, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = load i64, ptr %9, align 8, !tbaa !5
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = mul i64 %33, %34
  %36 = getelementptr inbounds float, ptr %32, i64 %35
  call void @usearch_add(ptr noundef %30, i64 noundef %31, ptr noundef %36, i32 noundef 1, ptr noundef %5)
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  %38 = icmp ne ptr %37, null
  %39 = xor i1 %38, true
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  call void @expect(i1 noundef zeroext %39, ptr noundef %40)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %41

41:                                               ; preds = %28
  %42 = load i64, ptr %9, align 8, !tbaa !5
  %43 = add i64 %42, 1
  store i64 %43, ptr %9, align 8, !tbaa !5
  br label %23, !llvm.loop !11

44:                                               ; preds = %27
  %45 = load ptr, ptr %7, align 8, !tbaa !9
  %46 = call i64 @usearch_size(ptr noundef %45, ptr noundef %5)
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = icmp eq i64 %46, %47
  %49 = load ptr, ptr %5, align 8, !tbaa !9
  call void @expect(i1 noundef zeroext %48, ptr noundef %49)
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = call i64 @usearch_capacity(ptr noundef %50, ptr noundef %5)
  %52 = load i64, ptr %3, align 8, !tbaa !5
  %53 = icmp uge i64 %51, %52
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  call void @expect(i1 noundef zeroext %53, ptr noundef %54)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %66, %44
  %56 = load i64, ptr %11, align 8, !tbaa !5
  %57 = load i64, ptr %3, align 8, !tbaa !5
  %58 = icmp ult i64 %56, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %69

60:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %61 = load i64, ptr %11, align 8, !tbaa !5
  store i64 %61, ptr %12, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !9
  %63 = load i64, ptr %12, align 8, !tbaa !5
  %64 = call zeroext i1 @usearch_contains(ptr noundef %62, i64 noundef %63, ptr noundef %5)
  %65 = load ptr, ptr %5, align 8, !tbaa !9
  call void @expect(i1 noundef zeroext %64, ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %66

66:                                               ; preds = %60
  %67 = load i64, ptr %11, align 8, !tbaa !5
  %68 = add i64 %67, 1
  store i64 %68, ptr %11, align 8, !tbaa !5
  br label %55, !llvm.loop !13

69:                                               ; preds = %59
  %70 = load ptr, ptr %7, align 8, !tbaa !9
  %71 = call zeroext i1 @usearch_contains(ptr noundef %70, i64 noundef -1, ptr noundef %5)
  %72 = xor i1 %71, true
  %73 = load ptr, ptr %5, align 8, !tbaa !9
  call void @expect(i1 noundef zeroext %72, ptr noundef %73)
  %74 = load ptr, ptr %8, align 8, !tbaa !9
  call void @free(ptr noundef %74) #4
  %75 = load ptr, ptr %7, align 8, !tbaa !9
  call void @usearch_free(ptr noundef %75, ptr noundef %5)
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

declare void @usearch_add(ptr noundef, i64 noundef, ptr noundef, i32 noundef, ptr noundef) #1

declare zeroext i1 @usearch_contains(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !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"}
!13 = distinct !{!13, !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"

%struct.usearch_init_options_t = type { i32, ptr, i32, i64, i64, i64, i64, i8 }

@.str.5 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @expect(i1 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @create_vectors(i64 noundef, i64 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @create_options(ptr dead_on_unwind noalias writable sret(%struct.usearch_init_options_t) align 8, i64 noundef) local_unnamed_addr #0

declare ptr @usearch_init(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @usearch_free(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i64 @usearch_size(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i64 @usearch_capacity(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @usearch_reserve(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @test_add_vector(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  %4 = alloca %struct.usearch_init_options_t, align 8
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i64 noundef %0, i64 noundef %1)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #5
  call void @create_options(ptr dead_on_unwind nonnull writable sret(%struct.usearch_init_options_t) align 8 %4, i64 noundef %1)
  %6 = call ptr @usearch_init(ptr noundef nonnull %4, ptr noundef nonnull %3) #5
  call void @usearch_reserve(ptr noundef %6, i64 noundef %0, ptr noundef nonnull %3) #5
  %7 = call ptr @create_vectors(i64 noundef %0, i64 noundef %1)
  %.not35 = icmp eq i64 %0, 0
  br i1 %.not35, label %._crit_edge34.critedge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %8 = call i64 @usearch_size(ptr noundef %6, ptr noundef nonnull %3) #5
  %9 = icmp eq i64 %8, %0
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  call void @expect(i1 noundef zeroext %9, ptr noundef %10)
  %11 = call i64 @usearch_capacity(ptr noundef %6, ptr noundef nonnull %3) #5
  %12 = icmp uge i64 %11, %0
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  call void @expect(i1 noundef zeroext %12, ptr noundef %13)
  br label %.lr.ph33

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.030 = phi i64 [ %17, %.lr.ph ], [ 0, %2 ]
  %14 = mul i64 %.030, %1
  %15 = getelementptr inbounds float, ptr %7, i64 %14
  call void @usearch_add(ptr noundef %6, i64 noundef %.030, ptr noundef %15, i32 noundef 1, ptr noundef nonnull %3) #5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %16, null
  call void @expect(i1 noundef zeroext %.not, ptr noundef %16)
  %17 = add nuw i64 %.030, 1
  %exitcond.not = icmp eq i64 %17, %0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge34.critedge:                           ; preds = %2
  %18 = call i64 @usearch_size(ptr noundef %6, ptr noundef nonnull %3) #5
  %19 = icmp eq i64 %18, %0
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  call void @expect(i1 noundef zeroext %19, ptr noundef %20)
  %21 = call i64 @usearch_capacity(ptr noundef %6, ptr noundef nonnull %3) #5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  call void @expect(i1 noundef zeroext true, ptr noundef %22)
  br label %._crit_edge34

._crit_edge34:                                    ; preds = %.lr.ph33, %._crit_edge34.critedge
  %23 = call zeroext i1 @usearch_contains(ptr noundef %6, i64 noundef -1, ptr noundef nonnull %3) #5
  %24 = xor i1 %23, true
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  call void @expect(i1 noundef zeroext %24, ptr noundef %25)
  call void @free(ptr noundef %7) #5
  call void @usearch_free(ptr noundef %6, ptr noundef nonnull %3) #5
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  ret void

.lr.ph33:                                         ; preds = %._crit_edge, %.lr.ph33
  %.02831 = phi i64 [ %29, %.lr.ph33 ], [ 0, %._crit_edge ]
  %27 = call zeroext i1 @usearch_contains(ptr noundef %6, i64 noundef %.02831, ptr noundef nonnull %3) #5
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  call void @expect(i1 noundef zeroext %27, ptr noundef %28)
  %29 = add nuw i64 %.02831, 1
  %exitcond37.not = icmp eq i64 %29, %0
  br i1 %exitcond37.not, label %._crit_edge34, label %.lr.ph33, !llvm.loop !11
}

declare void @usearch_add(ptr noundef, i64 noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare zeroext i1 @usearch_contains(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

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 = { nofree 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #4 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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