; LLVM IR from heroseh/cgm :: cgm (cgm_2d_aabb_vs_swept_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"

%union.CgmVec2 = type { %struct.anon }
%struct.anon = type { float, float }
%union.CgmAabb2d = type { %struct.anon.2 }
%struct.anon.2 = type { float, float, float, float }
%struct.CgmRay2d = type { %union.anon, %union.CgmVec2 }
%union.anon = type { %struct.anon.4 }
%struct.anon.4 = 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: nounwind uwtable
declare dso_local <2 x float> @CgmAabb2d_half_size(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @cgm_2d_aabb_vs_ray(float noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @cgm_2d_aabb_vs_swept_aabb(ptr noundef %0, ptr noundef %1, <2 x float> %2, float noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca i8, align 1
  %8 = alloca %union.CgmVec2, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca float, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca %union.CgmAabb2d, align 4
  %15 = alloca %union.CgmVec2, align 4
  %16 = alloca %struct.CgmRay2d, align 4
  %17 = getelementptr inbounds %union.CgmVec2, ptr %8, i32 0, i32 0
  store <2 x float> %2, ptr %17, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store float %3, ptr %11, align 4, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.anon, ptr %8, i32 0, i32 0
  %19 = load float, ptr %18, align 4, !tbaa !11
  %20 = fcmp oeq float %19, 0.000000e+00
  br i1 %20, label %21, label %26

21:                                               ; preds = %6
  %22 = getelementptr inbounds %struct.anon, ptr %8, i32 0, i32 1
  %23 = load float, ptr %22, align 4, !tbaa !11
  %24 = fcmp oeq float %23, 0.000000e+00
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  store i8 0, ptr %7, align 1
  br label %60

26:                                               ; preds = %21, %6
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #4
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %27, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = call <2 x float> @CgmAabb2d_half_size(ptr noundef %28)
  %30 = getelementptr inbounds %union.CgmVec2, ptr %15, i32 0, i32 0
  store <2 x float> %29, ptr %30, align 4
  %31 = getelementptr inbounds %struct.anon, ptr %15, i32 0, i32 0
  %32 = load float, ptr %31, align 4, !tbaa !11
  %33 = getelementptr inbounds %struct.anon.2, ptr %14, i32 0, i32 0
  %34 = load float, ptr %33, align 4, !tbaa !11
  %35 = fsub float %34, %32
  store float %35, ptr %33, align 4, !tbaa !11
  %36 = getelementptr inbounds %struct.anon, ptr %15, i32 0, i32 1
  %37 = load float, ptr %36, align 4, !tbaa !11
  %38 = getelementptr inbounds %struct.anon.2, ptr %14, i32 0, i32 1
  %39 = load float, ptr %38, align 4, !tbaa !11
  %40 = fsub float %39, %37
  store float %40, ptr %38, align 4, !tbaa !11
  %41 = getelementptr inbounds %struct.anon, ptr %15, i32 0, i32 0
  %42 = load float, ptr %41, align 4, !tbaa !11
  %43 = getelementptr inbounds %struct.anon.2, ptr %14, i32 0, i32 2
  %44 = load float, ptr %43, align 4, !tbaa !11
  %45 = fadd float %44, %42
  store float %45, ptr %43, align 4, !tbaa !11
  %46 = getelementptr inbounds %struct.anon, ptr %15, i32 0, i32 1
  %47 = load float, ptr %46, align 4, !tbaa !11
  %48 = getelementptr inbounds %struct.anon.2, ptr %14, i32 0, i32 3
  %49 = load float, ptr %48, align 4, !tbaa !11
  %50 = fadd float %49, %47
  store float %50, ptr %48, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 16, ptr %16) #4
  %51 = getelementptr inbounds %struct.CgmRay2d, ptr %16, i32 0, i32 0
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = call <2 x float> @CgmAabb2d_center(ptr noundef %52)
  %54 = getelementptr inbounds %union.CgmVec2, ptr %51, i32 0, i32 0
  store <2 x float> %53, ptr %54, align 4
  %55 = getelementptr inbounds %struct.CgmRay2d, ptr %16, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %55, ptr align 4 %8, i64 8, i1 false), !tbaa.struct !13
  %56 = load float, ptr %11, align 4, !tbaa !9
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = call zeroext i8 @cgm_2d_aabb_vs_ray(float noundef %56, ptr noundef %14, ptr noundef %16, ptr noundef %57, ptr noundef %58)
  store i8 %59, ptr %7, align 1
  call void @llvm.lifetime.end.p0(i64 16, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #4
  br label %60

60:                                               ; preds = %26, %25
  %61 = load i8, ptr %7, align 1
  ret i8 %61
}

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


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

%union.CgmAabb2d = type { %struct.anon.2 }
%struct.anon.2 = type { float, float, float, float }
%struct.CgmRay2d = type { %union.anon, %union.CgmVec2 }
%union.anon = type { %struct.anon.4 }
%struct.anon.4 = type { float, float }
%union.CgmVec2 = type { %struct.anon }
%struct.anon = type { float, float }

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

; 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) #1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @cgm_2d_aabb_vs_ray(float noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @cgm_2d_aabb_vs_swept_aabb(ptr nocapture noundef readonly %0, ptr noundef %1, <2 x float> %2, float noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #2 {
  %7 = alloca %union.CgmAabb2d, align 16
  %8 = alloca %struct.CgmRay2d, align 8
  %.sroa.012.0.vec.extract = extractelement <2 x float> %2, i64 0
  %9 = fcmp oeq float %.sroa.012.0.vec.extract, 0.000000e+00
  %.sroa.012.4.vec.extract = extractelement <2 x float> %2, i64 1
  %10 = fcmp oeq float %.sroa.012.4.vec.extract, 0.000000e+00
  %or.cond = select i1 %9, i1 %10, i1 false
  br i1 %or.cond, label %21, label %11

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %7, ptr noundef nonnull align 4 dereferenceable(16) %0, i64 16, i1 false), !tbaa.struct !5
  %12 = tail call <2 x float> @CgmAabb2d_half_size(ptr noundef %1)
  %13 = shufflevector <2 x float> %12, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
  %14 = load <4 x float>, ptr %7, align 16, !tbaa !6
  %15 = fsub <4 x float> %14, %13
  %16 = fadd <4 x float> %14, %13
  %17 = shufflevector <4 x float> %15, <4 x float> %16, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
  store <4 x float> %17, ptr %7, align 16, !tbaa !6
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #4
  %18 = tail call <2 x float> @CgmAabb2d_center(ptr noundef %1)
  store <2 x float> %18, ptr %8, align 8
  %19 = getelementptr inbounds i8, ptr %8, i64 8
  store <2 x float> %2, ptr %19, align 8, !tbaa !6
  %20 = call zeroext i8 @cgm_2d_aabb_vs_ray(float noundef %3, ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef %4, ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  br label %21

21:                                               ; preds = %6, %11
  %.0 = phi i8 [ %20, %11 ], [ 0, %6 ]
  ret i8 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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 = !{i64 0, i64 16, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass