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

; 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.query = type { i32, i32, i32, i32, [16 x %struct.join_predicate], [16 x %struct.filter_predicate], [16 x %struct.column] }
%struct.join_predicate = type { %struct.column, %struct.column }
%struct.column = type { i32, i32, i32 }
%struct.filter_predicate = type { %struct.column, i32, i32 }
%struct.relation = type { ptr, i64, i64 }
%struct.row_ids = type { i32, i32, ptr }

; 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 @calculateChecksums(ptr noundef %0, ptr noundef %1, ptr noundef %2, i1 noundef zeroext %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %15 = zext i1 %3 to i8
  store i8 %15, ptr %8, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.query, ptr %16, i32 0, i32 3
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = call ptr @memAlloc(i32 noundef 8, i32 noundef %18, i1 noundef zeroext true, ptr noundef null)
  store ptr %19, ptr %9, align 8, !tbaa !5
  %20 = load i8, ptr %8, align 1, !tbaa !9, !range !14, !noundef !15
  %21 = trunc i8 %20 to i1
  br i1 %21, label %108, label %22

22:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !16
  br label %23

23:                                               ; preds = %104, %22
  %24 = load i32, ptr %10, align 4, !tbaa !16
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.query, ptr %25, i32 0, i32 3
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = icmp ult i32 %24, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %23
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %107

30:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.query, ptr %32, i32 0, i32 6
  %34 = load i32, ptr %10, align 4, !tbaa !16
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [16 x %struct.column], ptr %33, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.column, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 4, !tbaa !17
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds ptr, ptr %31, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  store ptr %41, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.relation, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !19
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.query, ptr %45, i32 0, i32 6
  %47 = load i32, ptr %10, align 4, !tbaa !16
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds [16 x %struct.column], ptr %46, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.column, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 4, !tbaa !22
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %44, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  store ptr %54, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !16
  br label %55

55:                                               ; preds = %100, %30
  %56 = load i32, ptr %14, align 4, !tbaa !16
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.query, ptr %58, i32 0, i32 6
  %60 = load i32, ptr %10, align 4, !tbaa !16
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds [16 x %struct.column], ptr %59, i64 0, i64 %61
  %63 = getelementptr inbounds %struct.column, ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 4, !tbaa !23
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds ptr, ptr %57, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.row_ids, ptr %67, i32 0, i32 0
  %69 = load i32, ptr %68, align 8, !tbaa !24
  %70 = icmp ult i32 %56, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %55
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %103

72:                                               ; preds = %55
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.query, ptr %75, i32 0, i32 6
  %77 = load i32, ptr %10, align 4, !tbaa !16
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds [16 x %struct.column], ptr %76, i64 0, i64 %78
  %80 = getelementptr inbounds %struct.column, ptr %79, i32 0, i32 1
  %81 = load i32, ptr %80, align 4, !tbaa !23
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds ptr, ptr %74, i64 %82
  %84 = load ptr, ptr %83, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.row_ids, ptr %84, i32 0, i32 2
  %86 = load ptr, ptr %85, align 8, !tbaa !26
  %87 = load i32, ptr %14, align 4, !tbaa !16
  %88 = zext i32 %87 to i64
  %89 = getelementptr inbounds i32, ptr %86, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !16
  %91 = zext i32 %90 to i64
  %92 = getelementptr inbounds i64, ptr %73, i64 %91
  %93 = load i64, ptr %92, align 8, !tbaa !27
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  %95 = load i32, ptr %10, align 4, !tbaa !16
  %96 = zext i32 %95 to i64
  %97 = getelementptr inbounds i64, ptr %94, i64 %96
  %98 = load i64, ptr %97, align 8, !tbaa !27
  %99 = add i64 %98, %93
  store i64 %99, ptr %97, align 8, !tbaa !27
  br label %100

100:                                              ; preds = %72
  %101 = load i32, ptr %14, align 4, !tbaa !16
  %102 = add i32 %101, 1
  store i32 %102, ptr %14, align 4, !tbaa !16
  br label %55, !llvm.loop !28

103:                                              ; preds = %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %10, align 4, !tbaa !16
  %106 = add i32 %105, 1
  store i32 %106, ptr %10, align 4, !tbaa !16
  br label %23, !llvm.loop !30

107:                                              ; preds = %29
  br label %108

108:                                              ; preds = %107, %4
  %109 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret ptr %109
}

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 }

!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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !13, i64 12}
!12 = !{!"query", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !7, i64 16, !7, i64 400, !7, i64 720}
!13 = !{!"int", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!13, !13, i64 0}
!17 = !{!18, !13, i64 0}
!18 = !{!"column", !13, i64 0, !13, i64 4, !13, i64 8}
!19 = !{!20, !6, i64 0}
!20 = !{!"relation", !6, i64 0, !21, i64 8, !21, i64 16}
!21 = !{!"long", !7, i64 0}
!22 = !{!18, !13, i64 8}
!23 = !{!18, !13, i64 4}
!24 = !{!25, !13, i64 0}
!25 = !{!"row_ids", !13, i64 0, !13, i64 4, !6, i64 8}
!26 = !{!25, !6, i64 8}
!27 = !{!21, !21, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = distinct !{!30, !29}


; 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.column = type { i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local ptr @calculateChecksums(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, i1 noundef zeroext %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %2, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = tail call ptr @memAlloc(i32 noundef 8, i32 noundef %6, i1 noundef zeroext true, ptr noundef null) #2
  br i1 %3, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %4
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %.loopexit, label %.lr.ph26

.lr.ph26:                                         ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %2, i64 720
  %wide.trip.count32 = zext i32 %8 to i64
  br label %10

10:                                               ; preds = %.lr.ph26, %._crit_edge
  %indvars.iv29 = phi i64 [ 0, %.lr.ph26 ], [ %indvars.iv.next30, %._crit_edge ]
  %11 = getelementptr inbounds [16 x %struct.column], ptr %9, i64 0, i64 %indvars.iv29
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds ptr, ptr %1, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %11, i64 8
  %18 = load i32, ptr %17, align 4, !tbaa !17
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds ptr, ptr %16, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %11, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !18
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %0, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = load i32, ptr %26, align 8, !tbaa !19
  %.not27 = icmp eq i32 %27, 0
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10
  %28 = getelementptr inbounds i8, ptr %26, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !21
  %30 = getelementptr inbounds i64, ptr %7, i64 %indvars.iv29
  %.promoted = load i64, ptr %30, align 8, !tbaa !22
  %wide.trip.count = zext i32 %27 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %31 = icmp ult i32 %27, 4
  br i1 %31, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %39

._crit_edge.loopexit.unr-lcssa:                   ; preds = %39, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %39 ]
  %.unr = phi i64 [ %.promoted, %.lr.ph ], [ %64, %39 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %32 = phi i64 [ %38, %.epil.preheader ], [ %.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %33 = getelementptr inbounds i32, ptr %29, i64 %indvars.iv.epil
  %34 = load i32, ptr %33, align 4, !tbaa !23
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds i64, ptr %21, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !22
  %38 = add i64 %32, %37
  store i64 %38, ptr %30, align 8, !tbaa !22
  %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 %._crit_edge, label %.epil.preheader, !llvm.loop !24

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %10
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next30, %wide.trip.count32
  br i1 %exitcond33.not, label %.loopexit, label %10, !llvm.loop !26

39:                                               ; preds = %39, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %39 ]
  %40 = phi i64 [ %.promoted, %.lr.ph.new ], [ %64, %39 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %39 ]
  %41 = getelementptr inbounds i32, ptr %29, i64 %indvars.iv
  %42 = load i32, ptr %41, align 4, !tbaa !23
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds i64, ptr %21, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !22
  %46 = add i64 %40, %45
  store i64 %46, ptr %30, align 8, !tbaa !22
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %47 = getelementptr inbounds i32, ptr %29, i64 %indvars.iv.next
  %48 = load i32, ptr %47, align 4, !tbaa !23
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds i64, ptr %21, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !22
  %52 = add i64 %46, %51
  store i64 %52, ptr %30, align 8, !tbaa !22
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %53 = getelementptr inbounds i32, ptr %29, i64 %indvars.iv.next.1
  %54 = load i32, ptr %53, align 4, !tbaa !23
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds i64, ptr %21, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !22
  %58 = add i64 %52, %57
  store i64 %58, ptr %30, align 8, !tbaa !22
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %59 = getelementptr inbounds i32, ptr %29, i64 %indvars.iv.next.2
  %60 = load i32, ptr %59, align 4, !tbaa !23
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds i64, ptr %21, i64 %61
  %63 = load i64, ptr %62, align 8, !tbaa !22
  %64 = add i64 %58, %63
  store i64 %64, ptr %30, align 8, !tbaa !22
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %39, !llvm.loop !28

.loopexit:                                        ; preds = %._crit_edge, %.preheader, %4
  ret ptr %7
}

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 = { 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, !7, i64 12}
!6 = !{!"query", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !8, i64 400, !8, i64 720}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"column", !7, i64 0, !7, i64 4, !7, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"relation", !13, i64 0, !16, i64 8, !16, i64 16}
!16 = !{!"long", !8, i64 0}
!17 = !{!11, !7, i64 8}
!18 = !{!11, !7, i64 4}
!19 = !{!20, !7, i64 0}
!20 = !{!"row_ids", !7, i64 0, !7, i64 4, !13, i64 8}
!21 = !{!20, !13, i64 8}
!22 = !{!16, !16, i64 0}
!23 = !{!7, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.unroll.disable"}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = distinct !{!28, !27}


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