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

; 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.CgmCapsule3d = type { %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 } @CgmRay3d_get_projected_pt(ptr noundef, float noundef, <2 x float>, float) #2

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

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

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

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 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{i64 0, i64 12, !12}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !10, i64 28}
!14 = !{!"CgmCapsule3d", !7, i64 0, !7, i64 12, !10, i64 24, !10, i64 28}
!15 = !{!16, !10, i64 12}
!16 = !{!"CgmSphere", !7, i64 0, !10, 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 } @CgmRay3d_get_projected_pt(ptr noundef, float noundef, <2 x float>, float) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @cgm_3d_ray_vs_capsule(ptr noundef %0, float noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = alloca %struct.CgmSphere, align 8
  %.sroa.08.0.copyload = load <2 x float>, ptr %2, align 4
  %.sroa.29.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 8
  %.sroa.29.0.copyload = load float, ptr %.sroa.29.0..sroa_idx, align 4
  %7 = tail call { <2 x float>, float } @CgmRay3d_get_projected_pt(ptr noundef %0, float noundef %1, <2 x float> %.sroa.08.0.copyload, float %.sroa.29.0.copyload)
  %.fca.0.extract4 = extractvalue { <2 x float>, float } %7, 0
  %.fca.1.extract5 = extractvalue { <2 x float>, float } %7, 1
  %8 = tail call { <2 x float>, float } @CgmCapsule3d_get_projected_pt(ptr noundef nonnull %2, <2 x float> %.fca.0.extract4, float %.fca.1.extract5)
  %.fca.0.extract = extractvalue { <2 x float>, float } %8, 0
  %.fca.1.extract = extractvalue { <2 x float>, float } %8, 1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #2
  store <2 x float> %.fca.0.extract, ptr %6, align 8
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 8
  store float %.fca.1.extract, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %6, i64 12
  %10 = getelementptr inbounds i8, ptr %2, i64 28
  %11 = load float, ptr %10, align 4, !tbaa !8
  store float %11, ptr %9, align 4, !tbaa !11
  %12 = call zeroext i8 @cgm_3d_ray_vs_sphere(ptr noundef %0, float noundef %1, ptr noundef nonnull %6, ptr noundef %3, ptr noundef %4)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #2
  ret i8 %12
}

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 28}
!9 = !{!"CgmCapsule3d", !6, i64 0, !6, i64 12, !10, i64 24, !10, i64 28}
!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