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

; 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.CgmVec3 = type { %struct.anon.0 }
%struct.anon.0 = type { float, float, float }
%struct.CgmSphere = type { %union.anon.7, float }
%union.anon.7 = type { %struct.anon.8 }
%struct.anon.8 = type { float, float, float }
%struct.CgmHoop3d = type { %union.CgmVec3, %union.CgmVec3, %union.CgmVec3, 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>, float } @CgmVec3_sub(<2 x float>, float, <2 x float>, float) #2

; Function Attrs: nounwind uwtable
declare dso_local { <2 x float>, float } @CgmHoop3d_closest_pt(ptr noundef, <2 x float>, float) #2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @cgm_3d_sphere_vs_sphere(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @cgm_3d_sphere_vs_hoop(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %union.CgmVec3, align 4
  %10 = alloca { <2 x float>, float }, align 4
  %11 = alloca { <2 x float>, float }, align 8
  %12 = alloca %union.CgmVec3, align 4
  %13 = alloca { <2 x float>, float }, align 4
  %14 = alloca { <2 x float>, float }, align 4
  %15 = alloca { <2 x float>, float }, align 8
  %16 = alloca %struct.CgmSphere, 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
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %9) #3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.CgmSphere, ptr %18, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %19, i64 12, i1 false)
  %20 = getelementptr inbounds { <2 x float>, float }, ptr %10, i32 0, i32 0
  %21 = load <2 x float>, ptr %20, align 4
  %22 = getelementptr inbounds { <2 x float>, float }, ptr %10, i32 0, i32 1
  %23 = load float, ptr %22, align 4
  %24 = call { <2 x float>, float } @CgmHoop3d_closest_pt(ptr noundef %17, <2 x float> %21, float %23)
  %25 = getelementptr inbounds %union.CgmVec3, ptr %9, i32 0, i32 0
  store { <2 x float>, float } %24, ptr %11, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %25, ptr align 8 %11, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 12, ptr %12) #3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.CgmSphere, ptr %26, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %9, i64 12, i1 false)
  %28 = getelementptr inbounds { <2 x float>, float }, ptr %13, i32 0, i32 0
  %29 = load <2 x float>, ptr %28, align 4
  %30 = getelementptr inbounds { <2 x float>, float }, ptr %13, i32 0, i32 1
  %31 = load float, ptr %30, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %27, i64 12, i1 false)
  %32 = getelementptr inbounds { <2 x float>, float }, ptr %14, i32 0, i32 0
  %33 = load <2 x float>, ptr %32, align 4
  %34 = getelementptr inbounds { <2 x float>, float }, ptr %14, i32 0, i32 1
  %35 = load float, ptr %34, align 4
  %36 = call { <2 x float>, float } @CgmVec3_sub(<2 x float> %29, float %31, <2 x float> %33, float %35)
  %37 = getelementptr inbounds %union.CgmVec3, ptr %12, i32 0, i32 0
  store { <2 x float>, float } %36, ptr %15, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %37, ptr align 8 %15, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %16) #3
  %38 = getelementptr inbounds %struct.CgmSphere, ptr %16, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %38, ptr align 4 %9, i64 12, i1 false), !tbaa.struct !9
  %39 = getelementptr inbounds %struct.CgmSphere, ptr %16, i32 0, i32 1
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.CgmHoop3d, ptr %40, i32 0, i32 4
  %42 = load float, ptr %41, align 4, !tbaa !11
  store float %42, ptr %39, align 4, !tbaa !14
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = call zeroext i8 @cgm_3d_sphere_vs_sphere(ptr noundef %43, ptr noundef %16, ptr noundef %44, ptr noundef %45)
  call void @llvm.lifetime.end.p0(i64 16, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %9) #3
  ret i8 %46
}

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 }

!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 = !{i64 0, i64 12, !10}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !13, i64 40}
!12 = !{!"CgmHoop3d", !7, i64 0, !7, i64 12, !7, i64 24, !13, i64 36, !13, i64 40}
!13 = !{!"float", !7, i64 0}
!14 = !{!15, !13, i64 12}
!15 = !{!"CgmSphere", !7, i64 0, !13, i64 12}


; 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.CgmSphere = type { %union.anon.7, float }
%union.anon.7 = type { %struct.anon.8 }
%struct.anon.8 = type { float, 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 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>, float } @CgmVec3_sub(<2 x float>, float, <2 x float>, float) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @cgm_3d_sphere_vs_sphere(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @cgm_3d_sphere_vs_hoop(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = alloca %struct.CgmSphere, align 8
  %.sroa.010.0.copyload = load <2 x float>, ptr %0, align 4
  %.sroa.211.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.211.0.copyload = load float, ptr %.sroa.211.0..sroa_idx, align 4
  %6 = tail call { <2 x float>, float } @CgmHoop3d_closest_pt(ptr noundef %1, <2 x float> %.sroa.010.0.copyload, float %.sroa.211.0.copyload)
  %.fca.0.extract6 = extractvalue { <2 x float>, float } %6, 0
  %.fca.1.extract7 = extractvalue { <2 x float>, float } %6, 1
  %.sroa.01.0.copyload = load <2 x float>, ptr %0, align 4
  %.sroa.22.0.copyload = load float, ptr %.sroa.211.0..sroa_idx, align 4
  %7 = tail call { <2 x float>, float } @CgmVec3_sub(<2 x float> %.fca.0.extract6, float %.fca.1.extract7, <2 x float> %.sroa.01.0.copyload, float %.sroa.22.0.copyload)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #2
  store <2 x float> %.fca.0.extract6, ptr %5, align 8
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 8
  store float %.fca.1.extract7, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %5, i64 12
  %9 = getelementptr inbounds i8, ptr %1, i64 40
  %10 = load float, ptr %9, align 4, !tbaa !8
  store float %10, ptr %8, align 4, !tbaa !11
  %11 = call zeroext i8 @cgm_3d_sphere_vs_sphere(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef %2, ptr noundef %3)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #2
  ret i8 %11
}

attributes #0 = { mustprogress nocallback nofree nosync 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" }
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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 40}
!9 = !{!"CgmHoop3d", !6, i64 0, !6, i64 12, !6, i64 24, !10, i64 36, !10, i64 40}
!10 = !{!"float", !6, i64 0}
!11 = !{!12, !10, i64 12}
!12 = !{!"CgmSphere", !6, i64 0, !10, i64 12}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass