; LLVM IR from introlab/odas :: src/init (directivity)

; 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.spatialmasks_obj = type { i32, i32, ptr }
%struct.spatialindexes_obj = type { i32, i32, ptr, ptr }

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

; 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 @directivity_spatialindexes(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.spatialmasks_obj, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  store i32 %10, ptr %4, align 4, !tbaa !12
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.spatialmasks_obj, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !13
  store i32 %13, ptr %5, align 4, !tbaa !12
  %14 = load i32, ptr %4, align 4, !tbaa !12
  %15 = load i32, ptr %5, align 4, !tbaa !12
  %16 = call ptr @spatialindexes_construct_zero(i32 noundef %14, i32 noundef %15)
  store ptr %16, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %17

17:                                               ; preds = %77, %1
  %18 = load i32, ptr %6, align 4, !tbaa !12
  %19 = load i32, ptr %4, align 4, !tbaa !12
  %20 = icmp ult i32 %18, %19
  br i1 %20, label %21, label %80

21:                                               ; preds = %17
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.spatialindexes_obj, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load i32, ptr %6, align 4, !tbaa !12
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  store i32 0, ptr %27, align 4, !tbaa !12
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %28

28:                                               ; preds = %73, %21
  %29 = load i32, ptr %7, align 4, !tbaa !12
  %30 = load i32, ptr %5, align 4, !tbaa !12
  %31 = icmp ult i32 %29, %30
  br i1 %31, label %32, label %76

32:                                               ; preds = %28
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.spatialmasks_obj, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = load i32, ptr %6, align 4, !tbaa !12
  %37 = load i32, ptr %5, align 4, !tbaa !12
  %38 = mul i32 %36, %37
  %39 = load i32, ptr %7, align 4, !tbaa !12
  %40 = add i32 %38, %39
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %35, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !17
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 %44, 1
  br i1 %45, label %46, label %72

46:                                               ; preds = %32
  %47 = load i32, ptr %7, align 4, !tbaa !12
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.spatialindexes_obj, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = load i32, ptr %6, align 4, !tbaa !12
  %52 = load i32, ptr %5, align 4, !tbaa !12
  %53 = mul i32 %51, %52
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.spatialindexes_obj, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !14
  %57 = load i32, ptr %6, align 4, !tbaa !12
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %56, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !12
  %61 = add i32 %53, %60
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds i32, ptr %50, i64 %62
  store i32 %47, ptr %63, align 4, !tbaa !12
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.spatialindexes_obj, ptr %64, i32 0, i32 3
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = load i32, ptr %6, align 4, !tbaa !12
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !12
  %71 = add i32 %70, 1
  store i32 %71, ptr %69, align 4, !tbaa !12
  br label %72

72:                                               ; preds = %46, %32
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %7, align 4, !tbaa !12
  %75 = add i32 %74, 1
  store i32 %75, ptr %7, align 4, !tbaa !12
  br label %28, !llvm.loop !19

76:                                               ; preds = %28
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %6, align 4, !tbaa !12
  %79 = add i32 %78, 1
  store i32 %79, ptr %6, align 4, !tbaa !12
  br label %17, !llvm.loop !21

80:                                               ; preds = %17
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %81
}

declare ptr @spatialindexes_construct_zero(i32 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !11, i64 0}
!10 = !{!"spatialmasks_obj", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!15, !6, i64 16}
!15 = !{!"spatialindexes_obj", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!16 = !{!10, !6, i64 8}
!17 = !{!7, !7, i64 0}
!18 = !{!15, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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
define dso_local ptr @directivity_spatialindexes(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !11
  %5 = tail call ptr @spatialindexes_construct_zero(i32 noundef %2, i32 noundef %4) #3
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %._crit_edge30, label %.lr.ph29

.lr.ph29:                                         ; preds = %1
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %.not31 = icmp eq i32 %4, 0
  %8 = getelementptr inbounds i8, ptr %5, i64 8
  br i1 %.not31, label %.lr.ph29.split.preheader, label %.lr.ph29.split.us

.lr.ph29.split.preheader:                         ; preds = %.lr.ph29
  %9 = zext i32 %2 to i64
  %10 = shl nuw nsw i64 %9, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %7, i8 0, i64 %10, i1 false), !tbaa !14
  br label %._crit_edge30

.lr.ph29.split.us:                                ; preds = %.lr.ph29
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %wide.trip.count37 = zext i32 %2 to i64
  %wide.trip.count = zext i32 %4 to i64
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %._crit_edge.us, %.lr.ph29.split.us
  %indvars.iv34 = phi i64 [ %indvars.iv.next35, %._crit_edge.us ], [ 0, %.lr.ph29.split.us ]
  %13 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv34
  store i32 0, ptr %13, align 4, !tbaa !14
  %14 = trunc nuw i64 %indvars.iv34 to i32
  %15 = mul i32 %4, %14
  br label %16

16:                                               ; preds = %.lr.ph.us, %31
  %17 = phi i32 [ 0, %.lr.ph.us ], [ %32, %31 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next, %31 ]
  %18 = trunc nuw i64 %indvars.iv to i32
  %19 = add i32 %15, %18
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %12, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !16
  %23 = icmp eq i8 %22, 1
  br i1 %23, label %24, label %31

24:                                               ; preds = %16
  %25 = load ptr, ptr %8, align 8, !tbaa !17
  %26 = add i32 %17, %15
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr %25, i64 %27
  store i32 %18, ptr %28, align 4, !tbaa !14
  %29 = load i32, ptr %13, align 4, !tbaa !14
  %30 = add i32 %29, 1
  store i32 %30, ptr %13, align 4, !tbaa !14
  br label %31

31:                                               ; preds = %24, %16
  %32 = phi i32 [ %30, %24 ], [ %17, %16 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %16, !llvm.loop !18

._crit_edge.us:                                   ; preds = %31
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  br i1 %exitcond38.not, label %._crit_edge30, label %.lr.ph.us, !llvm.loop !20

._crit_edge30:                                    ; preds = %._crit_edge.us, %.lr.ph29.split.preheader, %1
  ret ptr %5
}

declare ptr @spatialindexes_construct_zero(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"spatialmasks_obj", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!13, !10, i64 16}
!13 = !{!"spatialindexes_obj", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !10, i64 8}
!16 = !{!8, !8, i64 0}
!17 = !{!13, !10, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass