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

; 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.hash_table = type { ptr, i32, i32, i32 }
%struct.bucket = type { i32, i32, i64, ptr }

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

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

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

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

9:                                                ; preds = %72, %2
  br label %10

10:                                               ; preds = %9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.hash_table, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds %struct.bucket, ptr %13, i64 %15
  %17 = getelementptr inbounds %struct.bucket, ptr %16, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = call i32 @numPayloads(ptr noundef %18)
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %10
  %22 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %22, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %73

23:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.hash_table, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds %struct.bucket, ptr %26, i64 %28
  %30 = getelementptr inbounds %struct.bucket, ptr %29, i32 0, i32 2
  %31 = load i64, ptr %30, align 8, !tbaa !16
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.hash_table, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 8, !tbaa !17
  %35 = call i32 @emptySpace(i64 noundef %31, i32 noundef %34)
  store i32 %35, ptr %8, align 4, !tbaa !9
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %23
  %40 = load i32, ptr %8, align 4, !tbaa !9
  br label %42

41:                                               ; preds = %23
  br label %42

42:                                               ; preds = %41, %39
  %43 = phi i32 [ %40, %39 ], [ 1, %41 ]
  %44 = add i32 %36, %43
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.hash_table, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 4, !tbaa !18
  %48 = urem i32 %44, %47
  store i32 %48, ptr %8, align 4, !tbaa !9
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.hash_table, ptr %51, i32 0, i32 2
  %53 = load i32, ptr %52, align 4, !tbaa !18
  %54 = call i32 @bucketDistance(i32 noundef %49, i32 noundef %50, i32 noundef %53)
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = add i32 %55, %54
  store i32 %56, ptr %6, align 4, !tbaa !9
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.hash_table, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !18
  %61 = sub i32 %60, 1
  %62 = icmp uge i32 %57, %61
  br i1 %62, label %63, label %68

63:                                               ; preds = %42
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.hash_table, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 4, !tbaa !18
  %67 = add i32 %66, 1
  store i32 %67, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %70

68:                                               ; preds = %42
  %69 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %69, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  br label %70

70:                                               ; preds = %68, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %71 = load i32, ptr %7, align 4
  switch i32 %71, label %73 [
    i32 0, label %72
  ]

72:                                               ; preds = %70
  br label %9

73:                                               ; preds = %70, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

; Function Attrs: nounwind uwtable
declare hidden i32 @numPayloads(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @bucketDistance(i32 noundef, i32 noundef, i32 noundef) #0

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 = { 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, !6, i64 0}
!12 = !{!"hash_table", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!13 = !{!14, !6, i64 16}
!14 = !{!"bucket", !10, i64 0, !10, i64 4, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !15, i64 8}
!17 = !{!12, !10, i64 16}
!18 = !{!12, !10, i64 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.bucket = type { i32, i32, i64, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @linearProbe(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  br label %5

5:                                                ; preds = %12, %2
  %.020 = phi i32 [ %1, %2 ], [ %21, %12 ]
  %.019 = phi i32 [ 0, %2 ], [ %23, %12 ]
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = zext i32 %.020 to i64
  %8 = getelementptr inbounds %struct.bucket, ptr %6, i64 %7, i32 3
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = tail call i32 @numPayloads(ptr noundef %9)
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.split.loop.exit, label %12

12:                                               ; preds = %5
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.bucket, ptr %13, i64 %7, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !14
  %16 = load i32, ptr %3, align 8, !tbaa !15
  %17 = tail call i32 @emptySpace(i64 noundef %15, i32 noundef %16)
  %18 = tail call i32 @llvm.umax.i32(i32 %17, i32 1)
  %19 = add i32 %18, %.020
  %20 = load i32, ptr %4, align 4, !tbaa !16
  %21 = urem i32 %19, %20
  %22 = tail call i32 @bucketDistance(i32 noundef %.020, i32 noundef %21, i32 noundef %20)
  %23 = add i32 %22, %.019
  %24 = load i32, ptr %4, align 4, !tbaa !16
  %25 = add i32 %24, -1
  %.not = icmp ult i32 %23, %25
  br i1 %.not, label %5, label %.split.loop.exit23

.split.loop.exit23:                               ; preds = %12
  %26 = add i32 %24, 1
  br label %.split.loop.exit

.split.loop.exit:                                 ; preds = %5, %.split.loop.exit23
  %.2 = phi i32 [ %26, %.split.loop.exit23 ], [ %.020, %5 ]
  ret i32 %.2
}

; Function Attrs: nounwind uwtable
declare hidden i32 @numPayloads(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @bucketDistance(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #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 speculatable willreturn memory(none) }

!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, !7, i64 0}
!6 = !{!"hash_table", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 16}
!12 = !{!"bucket", !10, i64 0, !10, i64 4, !13, i64 8, !7, i64 16}
!13 = !{!"long", !8, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!6, !10, i64 16}
!16 = !{!6, !10, i64 12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass