; LLVM IR from themisvaltinos/Partitioned-Hash-Join :: modules/helpers (helpers)

; 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @compareUints(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @distinctCount(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %9 = load i64, ptr %4, align 8, !tbaa !9
  %10 = mul i64 %9, 8
  %11 = call noalias ptr @malloc(i64 noundef %10) #6
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %25, %2
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = load i64, ptr %4, align 8, !tbaa !9
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %28

17:                                               ; preds = %12
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = getelementptr inbounds i64, ptr %18, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = getelementptr inbounds i64, ptr %22, i64 %23
  store i64 %21, ptr %24, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %17
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = add i64 %26, 1
  store i64 %27, ptr %6, align 8, !tbaa !9
  br label %12, !llvm.loop !11

28:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 1, ptr %7, align 8, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %4, align 8, !tbaa !9
  call void @qsort(ptr noundef %29, i64 noundef %30, i64 noundef 8, ptr noundef @compareUints)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 1, ptr %8, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %51, %28
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = load i64, ptr %4, align 8, !tbaa !9
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %54

36:                                               ; preds = %31
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = getelementptr inbounds i64, ptr %37, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = sub i64 %42, 1
  %44 = getelementptr inbounds i64, ptr %41, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = icmp ne i64 %40, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %36
  %48 = load i64, ptr %7, align 8, !tbaa !9
  %49 = add i64 %48, 1
  store i64 %49, ptr %7, align 8, !tbaa !9
  br label %50

50:                                               ; preds = %47, %36
  br label %51

51:                                               ; preds = %50
  %52 = load i64, ptr %8, align 8, !tbaa !9
  %53 = add i64 %52, 1
  store i64 %53, ptr %8, align 8, !tbaa !9
  br label %31, !llvm.loop !13

54:                                               ; preds = %35
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %55) #5
  %56 = load i64, ptr %7, align 8, !tbaa !9
  %57 = trunc i64 %56 to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret i32 %57
}

declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #4

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

!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 = !{!"long", !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"

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @compareUints(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @distinctCount(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #2 {
  %3 = shl i64 %1, 3
  %4 = tail call noalias ptr @malloc(i64 noundef %3) #6
  %.not28 = icmp eq i64 %1, 0
  br i1 %.not28, label %._crit_edge.thread, label %._crit_edge

._crit_edge.thread:                               ; preds = %2
  tail call void @qsort(ptr noundef %4, i64 noundef %1, i64 noundef 8, ptr noundef nonnull @compareUints) #7
  br label %._crit_edge27

._crit_edge:                                      ; preds = %2
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %0, i64 %3, i1 false), !tbaa !5
  tail call void @qsort(ptr noundef %4, i64 noundef %1, i64 noundef 8, ptr noundef nonnull @compareUints) #7
  %.not29 = icmp eq i64 %1, 1
  br i1 %.not29, label %._crit_edge27, label %.lr.ph26.preheader

.lr.ph26.preheader:                               ; preds = %._crit_edge
  %5 = add i64 %1, -1
  %min.iters.check = icmp ult i64 %1, 5
  br i1 %min.iters.check, label %.lr.ph26.preheader34, label %vector.ph

.lr.ph26.preheader34:                             ; preds = %middle.block, %.lr.ph26.preheader
  %.024.ph = phi i64 [ 1, %.lr.ph26.preheader ], [ %ind.end, %middle.block ]
  %.01923.ph = phi i32 [ 1, %.lr.ph26.preheader ], [ %17, %middle.block ]
  br label %.lr.ph26

vector.ph:                                        ; preds = %.lr.ph26.preheader
  %n.vec = and i64 %5, -4
  %ind.end = or disjoint i64 %n.vec, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i32> [ <i32 1, i32 0>, %vector.ph ], [ %14, %vector.body ]
  %vec.phi30 = phi <2 x i32> [ zeroinitializer, %vector.ph ], [ %15, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %6 = getelementptr inbounds i64, ptr %4, i64 %offset.idx
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %wide.load = load <2 x i64>, ptr %6, align 8, !tbaa !5
  %wide.load31 = load <2 x i64>, ptr %7, align 8, !tbaa !5
  %8 = getelementptr i8, ptr %6, i64 -8
  %9 = getelementptr i8, ptr %6, i64 8
  %wide.load32 = load <2 x i64>, ptr %8, align 8, !tbaa !5
  %wide.load33 = load <2 x i64>, ptr %9, align 8, !tbaa !5
  %10 = icmp ne <2 x i64> %wide.load, %wide.load32
  %11 = icmp ne <2 x i64> %wide.load31, %wide.load33
  %12 = zext <2 x i1> %10 to <2 x i32>
  %13 = zext <2 x i1> %11 to <2 x i32>
  %14 = add <2 x i32> %vec.phi, %12
  %15 = add <2 x i32> %vec.phi30, %13
  %index.next = add nuw i64 %index, 4
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i32> %15, %14
  %17 = tail call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %5, %n.vec
  br i1 %cmp.n, label %._crit_edge27, label %.lr.ph26.preheader34

._crit_edge27:                                    ; preds = %.lr.ph26, %middle.block, %._crit_edge.thread, %._crit_edge
  %.019.lcssa = phi i32 [ 1, %._crit_edge ], [ 1, %._crit_edge.thread ], [ %17, %middle.block ], [ %spec.select, %.lr.ph26 ]
  tail call void @free(ptr noundef %4) #7
  ret i32 %.019.lcssa

.lr.ph26:                                         ; preds = %.lr.ph26.preheader34, %.lr.ph26
  %.024 = phi i64 [ %23, %.lr.ph26 ], [ %.024.ph, %.lr.ph26.preheader34 ]
  %.01923 = phi i32 [ %spec.select, %.lr.ph26 ], [ %.01923.ph, %.lr.ph26.preheader34 ]
  %18 = getelementptr inbounds i64, ptr %4, i64 %.024
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = getelementptr i8, ptr %18, i64 -8
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %.not = icmp ne i64 %19, %21
  %22 = zext i1 %.not to i32
  %spec.select = add i32 %.01923, %22
  %23 = add nuw i64 %.024, 1
  %exitcond.not = icmp eq i64 %23, %1
  br i1 %exitcond.not, label %._crit_edge27, label %.lr.ph26, !llvm.loop !13
}

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v2i32(<2 x i32>) #5

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #1 = { 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 #2 = { 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 #3 = { nofree "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { 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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass