; LLVM IR from mvr/jiggle :: src (AABB)

; 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.jgAABB = type { %struct.jgVector2, %struct.jgVector2, i8 }
%struct.jgVector2 = type { float, float }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
define dso_local void @jgAABBExpandToInclude(ptr dead_on_unwind noalias writable sret(%struct.jgAABB) align 4 %0, ptr noundef byval(%struct.jgAABB) align 8 %1, <2 x float> %2) #1 {
  %4 = alloca %struct.jgVector2, align 4
  store <2 x float> %2, ptr %4, align 4
  %5 = getelementptr inbounds %struct.jgAABB, ptr %1, i32 0, i32 2
  %6 = load i8, ptr %5, align 8, !tbaa !5, !range !12, !noundef !13
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %59

8:                                                ; preds = %3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 8 %1, i64 20, i1 false), !tbaa.struct !14
  %9 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 0
  %10 = load float, ptr %9, align 4, !tbaa !17
  %11 = getelementptr inbounds %struct.jgAABB, ptr %1, i32 0, i32 0
  %12 = getelementptr inbounds %struct.jgVector2, ptr %11, i32 0, i32 0
  %13 = load float, ptr %12, align 8, !tbaa !18
  %14 = fcmp olt float %10, %13
  br i1 %14, label %15, label %20

15:                                               ; preds = %8
  %16 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 0
  %17 = load float, ptr %16, align 4, !tbaa !17
  %18 = getelementptr inbounds %struct.jgAABB, ptr %0, i32 0, i32 0
  %19 = getelementptr inbounds %struct.jgVector2, ptr %18, i32 0, i32 0
  store float %17, ptr %19, align 4, !tbaa !18
  br label %33

20:                                               ; preds = %8
  %21 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 0
  %22 = load float, ptr %21, align 4, !tbaa !17
  %23 = getelementptr inbounds %struct.jgAABB, ptr %1, i32 0, i32 1
  %24 = getelementptr inbounds %struct.jgVector2, ptr %23, i32 0, i32 0
  %25 = load float, ptr %24, align 8, !tbaa !19
  %26 = fcmp ogt float %22, %25
  br i1 %26, label %27, label %32

27:                                               ; preds = %20
  %28 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 0
  %29 = load float, ptr %28, align 4, !tbaa !17
  %30 = getelementptr inbounds %struct.jgAABB, ptr %0, i32 0, i32 1
  %31 = getelementptr inbounds %struct.jgVector2, ptr %30, i32 0, i32 0
  store float %29, ptr %31, align 4, !tbaa !19
  br label %32

32:                                               ; preds = %27, %20
  br label %33

33:                                               ; preds = %32, %15
  %34 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 1
  %35 = load float, ptr %34, align 4, !tbaa !20
  %36 = getelementptr inbounds %struct.jgAABB, ptr %1, i32 0, i32 0
  %37 = getelementptr inbounds %struct.jgVector2, ptr %36, i32 0, i32 1
  %38 = load float, ptr %37, align 4, !tbaa !21
  %39 = fcmp olt float %35, %38
  br i1 %39, label %40, label %45

40:                                               ; preds = %33
  %41 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 1
  %42 = load float, ptr %41, align 4, !tbaa !20
  %43 = getelementptr inbounds %struct.jgAABB, ptr %0, i32 0, i32 0
  %44 = getelementptr inbounds %struct.jgVector2, ptr %43, i32 0, i32 1
  store float %42, ptr %44, align 4, !tbaa !21
  br label %58

45:                                               ; preds = %33
  %46 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 1
  %47 = load float, ptr %46, align 4, !tbaa !20
  %48 = getelementptr inbounds %struct.jgAABB, ptr %1, i32 0, i32 1
  %49 = getelementptr inbounds %struct.jgVector2, ptr %48, i32 0, i32 1
  %50 = load float, ptr %49, align 4, !tbaa !22
  %51 = fcmp ogt float %47, %50
  br i1 %51, label %52, label %57

52:                                               ; preds = %45
  %53 = getelementptr inbounds %struct.jgVector2, ptr %4, i32 0, i32 1
  %54 = load float, ptr %53, align 4, !tbaa !20
  %55 = getelementptr inbounds %struct.jgAABB, ptr %0, i32 0, i32 1
  %56 = getelementptr inbounds %struct.jgVector2, ptr %55, i32 0, i32 1
  store float %54, ptr %56, align 4, !tbaa !22
  br label %57

57:                                               ; preds = %52, %45
  br label %58

58:                                               ; preds = %57, %40
  br label %63

59:                                               ; preds = %3
  %60 = getelementptr inbounds %struct.jgAABB, ptr %0, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %60, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !23
  %61 = getelementptr inbounds %struct.jgAABB, ptr %0, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %61, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !23
  %62 = getelementptr inbounds %struct.jgAABB, ptr %0, i32 0, i32 2
  store i8 1, ptr %62, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %59, %58
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="64" "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, !11, i64 16}
!6 = !{!"jgAABB", !7, i64 0, !7, i64 8, !11, i64 16}
!7 = !{!"jgVector2", !8, i64 0, !8, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"_Bool", !9, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15, i64 12, i64 4, !15, i64 16, i64 1, !16}
!15 = !{!8, !8, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!7, !8, i64 0}
!18 = !{!6, !8, i64 0}
!19 = !{!6, !8, i64 8}
!20 = !{!7, !8, i64 4}
!21 = !{!6, !8, i64 4}
!22 = !{!6, !8, i64 12}
!23 = !{i64 0, i64 4, !15, i64 4, i64 4, !15}


; 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.jgAABB = type { %struct.jgVector2, %struct.jgVector2, i8 }
%struct.jgVector2 = type { float, float }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @jgAABBExpandToInclude(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.jgAABB) align 4 %0, ptr nocapture noundef readonly byval(%struct.jgAABB) align 8 %1, <2 x float> %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  %5 = load i8, ptr %4, align 8, !tbaa !5, !range !12, !noundef !13
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %7, label %28

7:                                                ; preds = %3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(20) %0, ptr noundef nonnull align 8 dereferenceable(20) %1, i64 20, i1 false), !tbaa.struct !14
  %.sroa.0.0.vec.extract = extractelement <2 x float> %2, i64 0
  %8 = load float, ptr %1, align 8, !tbaa !17
  %9 = fcmp olt float %.sroa.0.0.vec.extract, %8
  br i1 %9, label %.sink.split, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load float, ptr %11, align 8, !tbaa !18
  %13 = fcmp ogt float %.sroa.0.0.vec.extract, %12
  br i1 %13, label %14, label %16

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  br label %.sink.split

.sink.split:                                      ; preds = %7, %14
  %.sink = phi ptr [ %15, %14 ], [ %0, %7 ]
  store float %.sroa.0.0.vec.extract, ptr %.sink, align 4, !tbaa !15
  br label %16

16:                                               ; preds = %.sink.split, %10
  %.sroa.0.4.vec.extract = extractelement <2 x float> %2, i64 1
  %17 = getelementptr inbounds i8, ptr %1, i64 4
  %18 = load float, ptr %17, align 4, !tbaa !19
  %19 = fcmp olt float %.sroa.0.4.vec.extract, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %0, i64 4
  store float %.sroa.0.4.vec.extract, ptr %21, align 4, !tbaa !19
  br label %31

22:                                               ; preds = %16
  %23 = getelementptr inbounds i8, ptr %1, i64 12
  %24 = load float, ptr %23, align 4, !tbaa !20
  %25 = fcmp ogt float %.sroa.0.4.vec.extract, %24
  br i1 %25, label %26, label %31

26:                                               ; preds = %22
  %27 = getelementptr inbounds i8, ptr %0, i64 12
  store float %.sroa.0.4.vec.extract, ptr %27, align 4, !tbaa !20
  br label %31

28:                                               ; preds = %3
  store <2 x float> %2, ptr %0, align 4
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  store <2 x float> %2, ptr %29, align 4
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  store i8 1, ptr %30, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %20, %26, %22, %28
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable "min-legal-vector-width"="64" "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, !11, i64 16}
!6 = !{!"jgAABB", !7, i64 0, !7, i64 8, !11, i64 16}
!7 = !{!"jgVector2", !8, i64 0, !8, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"_Bool", !9, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15, i64 12, i64 4, !15, i64 16, i64 1, !16}
!15 = !{!8, !8, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!6, !8, i64 0}
!18 = !{!6, !8, i64 8}
!19 = !{!6, !8, i64 4}
!20 = !{!6, !8, i64 12}


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