; LLVM IR from heroseh/cgm :: cgm (cgm_2d_aabb_vs_pt)

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

%union.CgmVec2 = type { %struct.anon }
%struct.anon = type { float, float }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.copysign.f32(float, float) #2

; Function Attrs: nounwind uwtable
declare dso_local <2 x float> @CgmVec2_sub(<2 x float>, <2 x float>) #3

; Function Attrs: nounwind uwtable
declare dso_local <2 x float> @CgmVec2_abs(<2 x float>) #3

; Function Attrs: nounwind uwtable
declare dso_local <2 x float> @CgmAabb2d_half_size(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local <2 x float> @CgmAabb2d_center(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @cgm_2d_aabb_vs_pt(ptr noundef %0, <2 x float> %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca i8, align 1
  %6 = alloca %union.CgmVec2, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %union.CgmVec2, align 4
  %11 = alloca %union.CgmVec2, align 4
  %12 = alloca %union.CgmVec2, align 4
  %13 = alloca %union.CgmVec2, align 4
  %14 = alloca %union.CgmVec2, align 4
  %15 = alloca i32, align 4
  %16 = alloca %union.CgmVec2, align 4
  %17 = alloca %union.CgmVec2, align 4
  %18 = getelementptr inbounds %union.CgmVec2, ptr %6, i32 0, i32 0
  store <2 x float> %1, ptr %18, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = call <2 x float> @CgmAabb2d_center(ptr noundef %19)
  %21 = getelementptr inbounds %union.CgmVec2, ptr %11, i32 0, i32 0
  store <2 x float> %20, ptr %21, align 4
  %22 = getelementptr inbounds %union.CgmVec2, ptr %6, i32 0, i32 0
  %23 = load <2 x float>, ptr %22, align 4
  %24 = getelementptr inbounds %union.CgmVec2, ptr %11, i32 0, i32 0
  %25 = load <2 x float>, ptr %24, align 4
  %26 = call <2 x float> @CgmVec2_sub(<2 x float> %23, <2 x float> %25)
  %27 = getelementptr inbounds %union.CgmVec2, ptr %10, i32 0, i32 0
  store <2 x float> %26, ptr %27, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call <2 x float> @CgmAabb2d_half_size(ptr noundef %28)
  %30 = getelementptr inbounds %union.CgmVec2, ptr %13, i32 0, i32 0
  store <2 x float> %29, ptr %30, align 4
  %31 = getelementptr inbounds %union.CgmVec2, ptr %10, i32 0, i32 0
  %32 = load <2 x float>, ptr %31, align 4
  %33 = call <2 x float> @CgmVec2_abs(<2 x float> %32)
  %34 = getelementptr inbounds %union.CgmVec2, ptr %14, i32 0, i32 0
  store <2 x float> %33, ptr %34, align 4
  %35 = getelementptr inbounds %union.CgmVec2, ptr %13, i32 0, i32 0
  %36 = load <2 x float>, ptr %35, align 4
  %37 = getelementptr inbounds %union.CgmVec2, ptr %14, i32 0, i32 0
  %38 = load <2 x float>, ptr %37, align 4
  %39 = call <2 x float> @CgmVec2_sub(<2 x float> %36, <2 x float> %38)
  %40 = getelementptr inbounds %union.CgmVec2, ptr %12, i32 0, i32 0
  store <2 x float> %39, ptr %40, align 4
  %41 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 0
  %42 = load float, ptr %41, align 4, !tbaa !9
  %43 = fcmp olt float %42, 0.000000e+00
  br i1 %43, label %48, label %44

44:                                               ; preds = %4
  %45 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 1
  %46 = load float, ptr %45, align 4, !tbaa !9
  %47 = fcmp olt float %46, 0.000000e+00
  br i1 %47, label %48, label %49

48:                                               ; preds = %44, %4
  store i8 0, ptr %5, align 1
  store i32 1, ptr %15, align 4
  br label %92

49:                                               ; preds = %44
  %50 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 0
  %51 = load float, ptr %50, align 4, !tbaa !9
  %52 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 1
  %53 = load float, ptr %52, align 4, !tbaa !9
  %54 = fcmp olt float %51, %53
  br i1 %54, label %55, label %73

55:                                               ; preds = %49
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %62

58:                                               ; preds = %55
  %59 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 0
  %60 = load float, ptr %59, align 4, !tbaa !9
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  store float %60, ptr %61, align 4, !tbaa !10
  br label %62

62:                                               ; preds = %58, %55
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %72

65:                                               ; preds = %62
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.anon, ptr %16, i32 0, i32 0
  %68 = getelementptr inbounds %struct.anon, ptr %10, i32 0, i32 0
  %69 = load float, ptr %68, align 4, !tbaa !9
  %70 = call float @llvm.copysign.f32(float 1.000000e+00, float %69)
  store float %70, ptr %67, align 4, !tbaa !12
  %71 = getelementptr inbounds %struct.anon, ptr %16, i32 0, i32 1
  store float 0.000000e+00, ptr %71, align 4, !tbaa !14
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %66, ptr align 4 %16, i64 8, i1 false), !tbaa.struct !15
  br label %72

72:                                               ; preds = %65, %62
  br label %91

73:                                               ; preds = %49
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %80

76:                                               ; preds = %73
  %77 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 1
  %78 = load float, ptr %77, align 4, !tbaa !9
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  store float %78, ptr %79, align 4, !tbaa !10
  br label %80

80:                                               ; preds = %76, %73
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %90

83:                                               ; preds = %80
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.anon, ptr %17, i32 0, i32 0
  store float 0.000000e+00, ptr %85, align 4, !tbaa !12
  %86 = getelementptr inbounds %struct.anon, ptr %17, i32 0, i32 1
  %87 = getelementptr inbounds %struct.anon, ptr %10, i32 0, i32 1
  %88 = load float, ptr %87, align 4, !tbaa !9
  %89 = call float @llvm.copysign.f32(float 1.000000e+00, float %88)
  store float %89, ptr %86, align 4, !tbaa !14
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %84, ptr align 4 %17, i64 8, i1 false), !tbaa.struct !15
  br label %90

90:                                               ; preds = %83, %80
  br label %91

91:                                               ; preds = %90, %72
  store i8 1, ptr %5, align 1
  store i32 1, ptr %15, align 4
  br label %92

92:                                               ; preds = %91, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %93 = load i8, ptr %5, align 1
  ret i8 %93
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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" }
attributes #4 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"float", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"", !11, i64 0, !11, i64 4}
!14 = !{!13, !11, i64 4}
!15 = !{i64 0, i64 8, !9}


; 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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.copysign.f32(float, float) #0

; Function Attrs: nounwind uwtable
declare dso_local <2 x float> @CgmVec2_sub(<2 x float>, <2 x float>) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local <2 x float> @CgmVec2_abs(<2 x float>) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local <2 x float> @CgmAabb2d_half_size(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local <2 x float> @CgmAabb2d_center(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @cgm_2d_aabb_vs_pt(ptr noundef %0, <2 x float> %1, ptr noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #1 {
  %5 = tail call <2 x float> @CgmAabb2d_center(ptr noundef %0)
  %6 = tail call <2 x float> @CgmVec2_sub(<2 x float> %1, <2 x float> %5)
  %7 = tail call <2 x float> @CgmAabb2d_half_size(ptr noundef %0)
  %8 = tail call <2 x float> @CgmVec2_abs(<2 x float> %6)
  %9 = tail call <2 x float> @CgmVec2_sub(<2 x float> %7, <2 x float> %8)
  %.sroa.07.0.vec.extract = extractelement <2 x float> %9, i64 0
  %10 = fcmp olt float %.sroa.07.0.vec.extract, 0.000000e+00
  %.sroa.07.4.vec.extract15 = extractelement <2 x float> %9, i64 1
  %11 = fcmp olt float %.sroa.07.4.vec.extract15, 0.000000e+00
  %or.cond = select i1 %10, i1 true, i1 %11
  br i1 %or.cond, label %24, label %12

12:                                               ; preds = %4
  %13 = fcmp olt float %.sroa.07.0.vec.extract, %.sroa.07.4.vec.extract15
  %.not33 = icmp eq ptr %3, null
  br i1 %13, label %14, label %19

14:                                               ; preds = %12
  br i1 %.not33, label %16, label %15

15:                                               ; preds = %14
  store float %.sroa.07.0.vec.extract, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %15, %14
  %.not34 = icmp eq ptr %2, null
  br i1 %.not34, label %24, label %17

17:                                               ; preds = %16
  %.sroa.017.0.vec.extract = extractelement <2 x float> %6, i64 0
  %18 = tail call float @llvm.copysign.f32(float 1.000000e+00, float %.sroa.017.0.vec.extract)
  br label %.sink.split

19:                                               ; preds = %12
  br i1 %.not33, label %21, label %20

20:                                               ; preds = %19
  store float %.sroa.07.4.vec.extract15, ptr %3, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %20, %19
  %.not32 = icmp eq ptr %2, null
  br i1 %.not32, label %24, label %22

22:                                               ; preds = %21
  %.sroa.017.4.vec.extract = extractelement <2 x float> %6, i64 1
  %23 = tail call float @llvm.copysign.f32(float 1.000000e+00, float %.sroa.017.4.vec.extract)
  br label %.sink.split

.sink.split:                                      ; preds = %22, %17
  %.sink35 = phi float [ %18, %17 ], [ 0.000000e+00, %22 ]
  %.sink = phi float [ 0.000000e+00, %17 ], [ %23, %22 ]
  store float %.sink35, ptr %2, align 4
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 4
  store float %.sink, ptr %.sroa.24.0..sroa_idx, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %.sink.split, %16, %21, %4
  %.0 = phi i8 [ 0, %4 ], [ 1, %21 ], [ 1, %16 ], [ 1, %.sink.split ]
  ret i8 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


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