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

%struct.row_ids = type { i32, i32, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local void @addRowID(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %25

8:                                                ; preds = %2
  %9 = call ptr @memAlloc(i32 noundef 16, i32 noundef 1, i1 noundef zeroext false, ptr noundef null)
  %10 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %9, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !9
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.row_ids, ptr %12, i32 0, i32 0
  store i32 0, ptr %13, align 8, !tbaa !11
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.row_ids, ptr %15, i32 0, i32 1
  store i32 512, ptr %16, align 4, !tbaa !13
  %17 = load ptr, ptr %4, align 8, !tbaa !9
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.row_ids, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = call ptr @memAlloc(i32 noundef 4, i32 noundef %20, i1 noundef zeroext false, ptr noundef null)
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.row_ids, ptr %23, i32 0, i32 2
  store ptr %21, ptr %24, align 8, !tbaa !14
  br label %54

25:                                               ; preds = %2
  %26 = load ptr, ptr %4, align 8, !tbaa !9
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.row_ids, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = load ptr, ptr %4, align 8, !tbaa !9
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.row_ids, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = icmp eq i32 %29, %33
  br i1 %34, label %35, label %53

35:                                               ; preds = %25
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.row_ids, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = mul i32 %39, 2
  store i32 %40, ptr %38, align 4, !tbaa !13
  %41 = load ptr, ptr %4, align 8, !tbaa !9
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.row_ids, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !13
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.row_ids, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = call ptr @memAlloc(i32 noundef 4, i32 noundef %44, i1 noundef zeroext false, ptr noundef %48)
  %50 = load ptr, ptr %4, align 8, !tbaa !9
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.row_ids, ptr %51, i32 0, i32 2
  store ptr %49, ptr %52, align 8, !tbaa !14
  br label %53

53:                                               ; preds = %35, %25
  br label %54

54:                                               ; preds = %53, %8
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = load ptr, ptr %4, align 8, !tbaa !9
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.row_ids, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  %60 = load ptr, ptr %4, align 8, !tbaa !9
  %61 = load ptr, ptr %60, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.row_ids, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 8, !tbaa !11
  %64 = add i32 %63, 1
  store i32 %64, ptr %62, align 8, !tbaa !11
  %65 = zext i32 %63 to i64
  %66 = getelementptr inbounds i32, ptr %59, i64 %65
  store i32 %55, ptr %66, align 4, !tbaa !5
  ret void
}

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

!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 = !{!"int", !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 = !{!12, !6, i64 0}
!12 = !{!"row_ids", !6, i64 0, !6, i64 4, !10, i64 8}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !10, i64 8}


; 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
declare dso_local ptr @memAlloc(i32 noundef, i32 noundef, i1 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @addRowID(i32 noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %9

5:                                                ; preds = %2
  %6 = tail call ptr @memAlloc(i32 noundef 16, i32 noundef 1, i1 noundef zeroext false, ptr noundef null)
  store ptr %6, ptr %1, align 8, !tbaa !5
  store i32 0, ptr %6, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 512, ptr %7, align 4, !tbaa !12
  %8 = tail call ptr @memAlloc(i32 noundef 4, i32 noundef 512, i1 noundef zeroext false, ptr noundef null)
  br label %.sink.split

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %3, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = load i32, ptr %3, align 8, !tbaa !9
  %13 = icmp eq i32 %11, %12
  br i1 %13, label %14, label %21

14:                                               ; preds = %9
  %15 = shl i32 %11, 1
  store i32 %15, ptr %10, align 4, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = tail call ptr @memAlloc(i32 noundef 4, i32 noundef %15, i1 noundef zeroext false, ptr noundef %17)
  br label %.sink.split

.sink.split:                                      ; preds = %5, %14
  %.sink = phi ptr [ %18, %14 ], [ %8, %5 ]
  %19 = load ptr, ptr %1, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  store ptr %.sink, ptr %20, align 8, !tbaa !13
  br label %21

21:                                               ; preds = %.sink.split, %9
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load i32, ptr %22, align 8, !tbaa !9
  %26 = add i32 %25, 1
  store i32 %26, ptr %22, align 8, !tbaa !9
  %27 = zext i32 %25 to i64
  %28 = getelementptr inbounds i32, ptr %24, i64 %27
  store i32 %0, ptr %28, align 4, !tbaa !14
  ret void
}

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

!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, !11, i64 0}
!10 = !{!"row_ids", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !6, i64 8}
!14 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass