; LLVM IR from Slingshot-Physics/slingshot-community :: common/geometry/src/volume.ll (ZN8geometry6volumeENS_5types7shape_tE)

; 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.geometry::types::shape_t" = type { i32, %union.anon }
%union.anon = type { %"struct.geometry::types::shapeCube_t" }
%"struct.geometry::types::shapeCube_t" = type { float, float, float }
%"struct.geometry::types::shapeSphere_t" = type { float }
%"struct.geometry::types::shapeCapsule_t" = type { float, float }
%"struct.geometry::types::shapeCylinder_t" = type { float, float }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZN8geometry6volumeENS_5types11shapeCube_tE(<2 x float>, float) #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: mustprogress uwtable
declare dso_local noundef float @_ZN8geometry6volumeENS_5types13shapeSphere_tE(float) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN8geometry6volumeENS_5types14shapeCapsule_tE(<2 x float>) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN8geometry6volumeENS_5types15shapeCylinder_tE(<2 x float>) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN8geometry6volumeENS_5types7shape_tE(i64 %0, <2 x float> %1) #3 {
  %3 = alloca %"struct.geometry::types::shape_t", align 4
  %4 = alloca float, align 4
  %5 = alloca %"struct.geometry::types::shapeCube_t", align 4
  %6 = alloca { <2 x float>, float }, align 4
  %7 = alloca %"struct.geometry::types::shapeSphere_t", align 4
  %8 = alloca %"struct.geometry::types::shapeCapsule_t", align 4
  %9 = alloca %"struct.geometry::types::shapeCylinder_t", align 4
  %10 = getelementptr inbounds { i64, <2 x float> }, ptr %3, i32 0, i32 0
  store i64 %0, ptr %10, align 4
  %11 = getelementptr inbounds { i64, <2 x float> }, ptr %3, i32 0, i32 1
  store <2 x float> %1, ptr %11, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store float 0.000000e+00, ptr %4, align 4, !tbaa !5
  %12 = getelementptr inbounds %"struct.geometry::types::shape_t", ptr %3, i32 0, i32 0
  %13 = load i32, ptr %12, align 4, !tbaa !9
  switch i32 %13, label %34 [
    i32 0, label %14
    i32 4, label %21
    i32 7, label %26
    i32 1, label %30
    i32 404, label %34
  ]

14:                                               ; preds = %2
  %15 = getelementptr inbounds %"struct.geometry::types::shape_t", ptr %3, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %15, i64 12, i1 false), !tbaa.struct !12
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %5, i64 12, i1 false)
  %16 = getelementptr inbounds { <2 x float>, float }, ptr %6, i32 0, i32 0
  %17 = load <2 x float>, ptr %16, align 4
  %18 = getelementptr inbounds { <2 x float>, float }, ptr %6, i32 0, i32 1
  %19 = load float, ptr %18, align 4
  %20 = call noundef float @_ZN8geometry6volumeENS_5types11shapeCube_tE(<2 x float> %17, float %19)
  store float %20, ptr %4, align 4, !tbaa !5
  br label %34

21:                                               ; preds = %2
  %22 = getelementptr inbounds %"struct.geometry::types::shape_t", ptr %3, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %22, i64 4, i1 false), !tbaa.struct !13
  %23 = getelementptr inbounds %"struct.geometry::types::shapeSphere_t", ptr %7, i32 0, i32 0
  %24 = load float, ptr %23, align 4
  %25 = call noundef float @_ZN8geometry6volumeENS_5types13shapeSphere_tE(float %24)
  store float %25, ptr %4, align 4, !tbaa !5
  br label %34

26:                                               ; preds = %2
  %27 = getelementptr inbounds %"struct.geometry::types::shape_t", ptr %3, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %27, i64 8, i1 false), !tbaa.struct !14
  %28 = load <2 x float>, ptr %8, align 4
  %29 = call noundef float @_ZN8geometry6volumeENS_5types14shapeCapsule_tE(<2 x float> %28)
  store float %29, ptr %4, align 4, !tbaa !5
  br label %34

30:                                               ; preds = %2
  %31 = getelementptr inbounds %"struct.geometry::types::shape_t", ptr %3, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %31, i64 8, i1 false), !tbaa.struct !14
  %32 = load <2 x float>, ptr %9, align 4
  %33 = call noundef float @_ZN8geometry6volumeENS_5types15shapeCylinder_tE(<2 x float> %32)
  store float %33, ptr %4, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %30, %26, %21, %14, %2, %2
  %35 = load float, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  ret float %35
}

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

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

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #3 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN8geometry5types7shape_tE", !11, i64 0, !7, i64 4}
!11 = !{!"_ZTSN8geometry5types11enumShape_tE", !7, i64 0}
!12 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5}
!13 = !{i64 0, i64 4, !5}
!14 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}


; 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.geometry::types::shape_t" = type { i32, %union.anon }
%union.anon = type { %"struct.geometry::types::shapeCube_t" }
%"struct.geometry::types::shapeCube_t" = type { float, float, float }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZN8geometry6volumeENS_5types11shapeCube_tE(<2 x float>, float) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN8geometry6volumeENS_5types13shapeSphere_tE(float) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN8geometry6volumeENS_5types14shapeCapsule_tE(<2 x float>) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN8geometry6volumeENS_5types15shapeCylinder_tE(<2 x float>) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN8geometry6volumeENS_5types7shape_tE(i64 %0, <2 x float> %1) local_unnamed_addr #2 {
  %3 = alloca %"struct.geometry::types::shape_t", align 8
  store i64 %0, ptr %3, align 8
  %.8.sroa_idx23 = getelementptr inbounds i8, ptr %3, i64 8
  store <2 x float> %1, ptr %.8.sroa_idx23, align 8
  %4 = trunc i64 %0 to i32
  switch i32 %4, label %17 [
    i32 0, label %5
    i32 4, label %8
    i32 7, label %13
    i32 1, label %15
  ]

5:                                                ; preds = %2
  %6 = extractelement <2 x float> %1, i64 1
  %.4.sroa_idx20 = getelementptr inbounds i8, ptr %3, i64 4
  %.4..4..4..4..sroa.04.0.copyload = load <2 x float>, ptr %.4.sroa_idx20, align 4
  %7 = tail call noundef float @_ZN8geometry6volumeENS_5types11shapeCube_tE(<2 x float> %.4..4..4..4..sroa.04.0.copyload, float %6)
  br label %17

8:                                                ; preds = %2
  %9 = lshr i64 %0, 32
  %10 = trunc nuw i64 %9 to i32
  %11 = bitcast i32 %10 to float
  %12 = tail call noundef float @_ZN8geometry6volumeENS_5types13shapeSphere_tE(float %11)
  br label %17

13:                                               ; preds = %2
  %.4.sroa_idx21 = getelementptr inbounds i8, ptr %3, i64 4
  %.4..4..4..4..sroa.01.0.copyload = load <2 x float>, ptr %.4.sroa_idx21, align 4
  %14 = tail call noundef float @_ZN8geometry6volumeENS_5types14shapeCapsule_tE(<2 x float> %.4..4..4..4..sroa.01.0.copyload)
  br label %17

15:                                               ; preds = %2
  %.4.sroa_idx22 = getelementptr inbounds i8, ptr %3, i64 4
  %.4..4..4..4..sroa.0.0.copyload = load <2 x float>, ptr %.4.sroa_idx22, align 4
  %16 = tail call noundef float @_ZN8geometry6volumeENS_5types15shapeCylinder_tE(<2 x float> %.4..4..4..4..sroa.0.0.copyload)
  br label %17

17:                                               ; preds = %15, %13, %8, %5, %2
  %.0 = phi float [ 0.000000e+00, %2 ], [ %16, %15 ], [ %14, %13 ], [ %12, %8 ], [ %7, %5 ]
  ret float %.0
}

attributes #0 = { mustprogress 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 #1 = { mustprogress 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 #2 = { mustprogress 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)"}


; Effective O3 passes: BDCEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass