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

; 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

declare ptr @memAlloc(i32 noundef, i32 noundef, i1 noundef zeroext, ptr 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 uwtable
define dso_local ptr @mergeHistograms(ptr noundef %0, i32 noundef %1, i8 noundef zeroext %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %13 = load i8, ptr %6, align 1, !tbaa !11
  %14 = zext i8 %13 to i32
  %15 = shl i32 1, %14
  store i32 %15, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = call ptr @memAlloc(i32 noundef 4, i32 noundef %16, i1 noundef zeroext true, ptr noundef null)
  store ptr %17, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %49, %3
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = icmp ult i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %52

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %45, %23
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp ult i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %48

29:                                               ; preds = %24
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds ptr, ptr %30, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %34, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %39, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = add i32 %43, %38
  store i32 %44, ptr %42, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %29
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = add i32 %46, 1
  store i32 %47, ptr %11, align 4, !tbaa !9
  br label %24, !llvm.loop !12

48:                                               ; preds = %28
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = add i32 %50, 1
  store i32 %51, ptr %9, align 4, !tbaa !9
  br label %18, !llvm.loop !14

52:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %64, %52
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = icmp ult i32 %54, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %53
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %67

58:                                               ; preds = %53
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds ptr, ptr %59, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  call void @free(ptr noundef %63) #4
  br label %64

64:                                               ; preds = %58
  %65 = load i32, ptr %12, align 4, !tbaa !9
  %66 = add i32 %65, 1
  store i32 %66, ptr %12, align 4, !tbaa !9
  br label %53, !llvm.loop !15

67:                                               ; preds = %57
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %68) #4
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret ptr %69
}

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

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


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

declare ptr @memAlloc(i32 noundef, i32 noundef, i1 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @mergeHistograms(ptr nocapture noundef %0, i32 noundef %1, i8 noundef zeroext %2) local_unnamed_addr #1 {
  %4 = zext nneg i8 %2 to i32
  %5 = shl nuw i32 1, %4
  %6 = tail call ptr @memAlloc(i32 noundef 4, i32 noundef %5, i1 noundef zeroext true, ptr noundef null) #3
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.preheader22.preheader

.preheader22.preheader:                           ; preds = %3
  %wide.trip.count31 = zext i32 %1 to i64
  %wide.trip.count = zext i32 %5 to i64
  %7 = shl nuw nsw i64 %wide.trip.count, 2
  %scevgep = getelementptr i8, ptr %6, i64 %7
  %min.iters.check = icmp ult i8 %2, 3
  %n.vec = and i64 %wide.trip.count, 4294967288
  %xtraiter = and i64 %wide.trip.count, 3
  %8 = icmp ult i8 %2, 2
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader22

.preheader22:                                     ; preds = %.preheader22.preheader, %middle.block
  %indvars.iv28 = phi i64 [ 0, %.preheader22.preheader ], [ %indvars.iv.next29, %middle.block ]
  %9 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv28
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

scalar.ph.preheader:                              ; preds = %vector.memcheck, %.preheader22
  br i1 %8, label %middle.block.loopexit.unr-lcssa, label %scalar.ph

vector.memcheck:                                  ; preds = %.preheader22
  %scevgep38 = getelementptr i8, ptr %10, i64 %7
  %bound0 = icmp ult ptr %6, %scevgep38
  %bound1 = icmp ult ptr %10, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.memcheck ]
  %11 = getelementptr inbounds i32, ptr %10, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load = load <4 x i32>, ptr %11, align 4, !tbaa !9, !alias.scope !11
  %wide.load39 = load <4 x i32>, ptr %12, align 4, !tbaa !9, !alias.scope !11
  %13 = getelementptr inbounds i32, ptr %6, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %wide.load40 = load <4 x i32>, ptr %13, align 4, !tbaa !9, !alias.scope !14, !noalias !11
  %wide.load41 = load <4 x i32>, ptr %14, align 4, !tbaa !9, !alias.scope !14, !noalias !11
  %15 = add <4 x i32> %wide.load40, %wide.load
  %16 = add <4 x i32> %wide.load41, %wide.load39
  store <4 x i32> %15, ptr %13, align 4, !tbaa !9, !alias.scope !14, !noalias !11
  store <4 x i32> %16, ptr %14, align 4, !tbaa !9, !alias.scope !14, !noalias !11
  %index.next = add nuw i64 %index, 8
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, label %middle.block, label %vector.body, !llvm.loop !16

.preheader:                                       ; preds = %middle.block
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count36 = zext i32 %1 to i64
  br label %.lr.ph

middle.block.loopexit.unr-lcssa:                  ; preds = %scalar.ph, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %scalar.ph.preheader ], [ %indvars.iv.next.3, %scalar.ph ]
  br i1 %lcmp.mod.not, label %middle.block, label %scalar.ph.epil

scalar.ph.epil:                                   ; preds = %middle.block.loopexit.unr-lcssa, %scalar.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %scalar.ph.epil ], [ %indvars.iv.unr, %middle.block.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %scalar.ph.epil ], [ 0, %middle.block.loopexit.unr-lcssa ]
  %18 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.epil
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv.epil
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = add i32 %21, %19
  store i32 %22, ptr %20, align 4, !tbaa !9
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %middle.block, label %scalar.ph.epil, !llvm.loop !20

middle.block:                                     ; preds = %vector.body, %middle.block.loopexit.unr-lcssa, %scalar.ph.epil
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %exitcond32.not = icmp eq i64 %indvars.iv.next29, %wide.trip.count31
  br i1 %exitcond32.not, label %.preheader, label %.preheader22, !llvm.loop !22

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ 0, %scalar.ph.preheader ]
  %niter = phi i64 [ %niter.next.3, %scalar.ph ], [ 0, %scalar.ph.preheader ]
  %23 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = add i32 %26, %24
  store i32 %27, ptr %25, align 4, !tbaa !9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %28 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv.next
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = add i32 %31, %29
  store i32 %32, ptr %30, align 4, !tbaa !9
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %33 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next.1
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv.next.1
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = add i32 %36, %34
  store i32 %37, ptr %35, align 4, !tbaa !9
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %38 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next.2
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv.next.2
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = add i32 %41, %39
  store i32 %42, ptr %40, align 4, !tbaa !9
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add nuw i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %middle.block.loopexit.unr-lcssa, label %scalar.ph, !llvm.loop !23

._crit_edge:                                      ; preds = %.lr.ph, %3, %.preheader
  tail call void @free(ptr noundef %0) #3
  ret ptr %6

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv33 = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next34, %.lr.ph ]
  %43 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv33
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  tail call void @free(ptr noundef %44) #3
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next34, %wide.trip.count36
  br i1 %exitcond37.not, label %._crit_edge, label %.lr.ph, !llvm.loop !24
}

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

attributes #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 = { 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 = { 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 #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 = !{!"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 = distinct !{!12, !13}
!13 = distinct !{!13, !"LVerDomain"}
!14 = !{!15}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = distinct !{!22, !17}
!23 = distinct !{!23, !17, !18}
!24 = distinct !{!24, !17}


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