; LLVM IR from SourangshuGhosh/Fluid-Simulation-for-Computer-Graphics :: src/aabb.ll (ZN4AABBC2E9GridIndexd)

; 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.GridIndex = type { i32, i32, i32 }
%"class.vmath::vec3" = type { float, float, float }
%class.AABB = type { %"class.vmath::vec3", double, double, double }

declare void @_ZN5vmath4vec3C1Ev(ptr noundef nonnull align 4 dereferenceable(12)) unnamed_addr #0

declare void @_ZN5vmath4vec3C1Efff(ptr noundef nonnull align 4 dereferenceable(12), float noundef, float noundef, float noundef) unnamed_addr #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.start.p0(i64 immarg, ptr nocapture) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12)) unnamed_addr #3

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4AABBC2E9GridIndexd(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 %1, i32 %2, double noundef %3) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca %struct.GridIndex, align 4
  %6 = alloca { i64, i32 }, align 4
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca %"class.vmath::vec3", align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 0
  store i64 %1, ptr %12, align 4
  %13 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 1
  store i32 %2, ptr %13, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %6, i64 12, i1 false)
  store ptr %0, ptr %7, align 8, !tbaa !5
  store double %3, ptr %8, align 8, !tbaa !9
  %14 = load ptr, ptr %7, align 8
  %15 = getelementptr inbounds %class.AABB, ptr %14, i32 0, i32 0
  call void @_ZN5vmath4vec3C1Ev(ptr noundef nonnull align 4 dereferenceable(12) %15)
  %16 = getelementptr inbounds %class.AABB, ptr %14, i32 0, i32 1
  store double 0.000000e+00, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds %class.AABB, ptr %14, i32 0, i32 2
  store double 0.000000e+00, ptr %17, align 8, !tbaa !15
  %18 = getelementptr inbounds %class.AABB, ptr %14, i32 0, i32 3
  store double 0.000000e+00, ptr %18, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 12, ptr %9) #5
  %19 = getelementptr inbounds %struct.GridIndex, ptr %5, i32 0, i32 0
  %20 = load i32, ptr %19, align 4, !tbaa !17
  %21 = sitofp i32 %20 to double
  %22 = load double, ptr %8, align 8, !tbaa !9
  %23 = fmul double %21, %22
  %24 = fptrunc double %23 to float
  %25 = getelementptr inbounds %struct.GridIndex, ptr %5, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !20
  %27 = sitofp i32 %26 to double
  %28 = load double, ptr %8, align 8, !tbaa !9
  %29 = fmul double %27, %28
  %30 = fptrunc double %29 to float
  %31 = getelementptr inbounds %struct.GridIndex, ptr %5, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !21
  %33 = sitofp i32 %32 to double
  %34 = load double, ptr %8, align 8, !tbaa !9
  %35 = fmul double %33, %34
  %36 = fptrunc double %35 to float
  invoke void @_ZN5vmath4vec3C1Efff(ptr noundef nonnull align 4 dereferenceable(12) %9, float noundef %24, float noundef %30, float noundef %36)
          to label %37 unwind label %43

37:                                               ; preds = %4
  %38 = getelementptr inbounds %class.AABB, ptr %14, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %38, ptr align 4 %9, i64 12, i1 false), !tbaa.struct !22
  call void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12) %9) #5
  call void @llvm.lifetime.end.p0(i64 12, ptr %9) #5
  %39 = load double, ptr %8, align 8, !tbaa !9
  %40 = getelementptr inbounds %class.AABB, ptr %14, i32 0, i32 3
  store double %39, ptr %40, align 8, !tbaa !16
  %41 = getelementptr inbounds %class.AABB, ptr %14, i32 0, i32 2
  store double %39, ptr %41, align 8, !tbaa !15
  %42 = getelementptr inbounds %class.AABB, ptr %14, i32 0, i32 1
  store double %39, ptr %42, align 8, !tbaa !11
  ret void

43:                                               ; preds = %4
  %44 = landingpad { ptr, i32 }
          cleanup
  %45 = extractvalue { ptr, i32 } %44, 0
  store ptr %45, ptr %10, align 8
  %46 = extractvalue { ptr, i32 } %44, 1
  store i32 %46, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 12, ptr %9) #5
  call void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12) %15) #5
  br label %47

47:                                               ; preds = %43
  %48 = load ptr, ptr %10, align 8
  %49 = load i32, ptr %11, align 4
  %50 = insertvalue { ptr, i32 } poison, ptr %48, 0
  %51 = insertvalue { ptr, i32 } %50, i32 %49, 1
  resume { ptr, i32 } %51
}

attributes #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 #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind "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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTS4AABB", !13, i64 0, !10, i64 16, !10, i64 24, !10, i64 32}
!13 = !{!"_ZTSN5vmath4vec3E", !14, i64 0, !14, i64 4, !14, i64 8}
!14 = !{!"float", !7, i64 0}
!15 = !{!12, !10, i64 24}
!16 = !{!12, !10, i64 32}
!17 = !{!18, !19, i64 0}
!18 = !{!"_ZTS9GridIndex", !19, i64 0, !19, i64 4, !19, i64 8}
!19 = !{!"int", !7, i64 0}
!20 = !{!18, !19, i64 4}
!21 = !{!18, !19, i64 8}
!22 = !{i64 0, i64 4, !23, i64 4, i64 4, !23, i64 8, i64 4, !23}
!23 = !{!14, !14, i64 0}


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

%"class.vmath::vec3" = type { float, float, float }

declare void @_ZN5vmath4vec3C1Ev(ptr noundef nonnull align 4 dereferenceable(12)) unnamed_addr #0

declare void @_ZN5vmath4vec3C1Efff(ptr noundef nonnull align 4 dereferenceable(12), float noundef, float noundef, float noundef) unnamed_addr #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.start.p0(i64 immarg, ptr nocapture) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12)) unnamed_addr #3

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4AABBC2E9GridIndexd(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 %1, i32 %2, double noundef %3) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca %"class.vmath::vec3", align 4
  %.sroa.06.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.27.0.extract.shift = lshr i64 %1, 32
  %.sroa.27.0.extract.trunc = trunc nuw i64 %.sroa.27.0.extract.shift to i32
  tail call void @_ZN5vmath4vec3C1Ev(ptr noundef nonnull align 4 dereferenceable(12) %0)
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %6, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #6
  %7 = sitofp i32 %.sroa.06.0.extract.trunc to double
  %8 = fmul double %7, %3
  %9 = fptrunc double %8 to float
  %10 = sitofp i32 %.sroa.27.0.extract.trunc to double
  %11 = fmul double %10, %3
  %12 = fptrunc double %11 to float
  %13 = sitofp i32 %2 to double
  %14 = fmul double %13, %3
  %15 = fptrunc double %14 to float
  invoke void @_ZN5vmath4vec3C1Efff(ptr noundef nonnull align 4 dereferenceable(12) %5, float noundef %9, float noundef %12, float noundef %15)
          to label %16 unwind label %19

16:                                               ; preds = %4
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef nonnull align 4 dereferenceable(12) %5, i64 12, i1 false), !tbaa.struct !5
  call void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12) %5) #6
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #6
  store double %3, ptr %17, align 8, !tbaa !10
  store double %3, ptr %18, align 8, !tbaa !14
  store double %3, ptr %6, align 8, !tbaa !15
  ret void

19:                                               ; preds = %4
  %20 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #6
  call void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12) %0) #6
  resume { ptr, i32 } %20
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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


; Effective O3 passes: EarlyCSEPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass