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

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

%"class.vmath::vec3" = type { float, float, float }
%class.FluidSource = type { ptr, %"class.vmath::vec3", %"class.vmath::vec3", i8, i8, i32 }

; Function Attrs: nounwind
declare void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12)) 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: inlinehint mustprogress uwtable
declare dso_local void @_ZN5vmath9normalizeERKNS_4vec3E(ptr dead_on_unwind noalias writable sret(%"class.vmath::vec3") align 4, ptr noundef nonnull align 4 dereferenceable(12)) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef float @_ZN5vmath6lengthERKNS_4vec3E(ptr noundef nonnull align 4 dereferenceable(12)) #2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11FluidSource12setDirectionEN5vmath4vec3E(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1) #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"class.vmath::vec3", align 4
  %8 = alloca %"class.vmath::vec3", align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %10 = call noundef float @_ZN5vmath6lengthERKNS_4vec3E(ptr noundef nonnull align 4 dereferenceable(12) %1)
  store float %10, ptr %5, align 4, !tbaa !9
  %11 = load float, ptr %5, align 4, !tbaa !9
  %12 = fcmp ogt float %11, 0.000000e+00
  br i1 %12, label %14, label %13

13:                                               ; preds = %2
  store i32 1, ptr %6, align 4
  br label %20

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 12, ptr %7) #6
  call void @_ZN5vmath9normalizeERKNS_4vec3E(ptr dead_on_unwind writable sret(%"class.vmath::vec3") align 4 %7, ptr noundef nonnull align 4 dereferenceable(12) %1)
  %15 = getelementptr inbounds %class.FluidSource, ptr %9, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %7, i64 12, i1 false), !tbaa.struct !11
  call void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12) %7) #6
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 12, ptr %8) #6
  %16 = getelementptr inbounds %class.FluidSource, ptr %9, i32 0, i32 1
  %17 = call noundef float @_ZN5vmath6lengthERKNS_4vec3E(ptr noundef nonnull align 4 dereferenceable(12) %16)
  %18 = getelementptr inbounds %class.FluidSource, ptr %9, i32 0, i32 2
  call void @_ZN5vmathmlEfRKNS_4vec3E(ptr dead_on_unwind writable sret(%"class.vmath::vec3") align 4 %8, float noundef %17, ptr noundef nonnull align 4 dereferenceable(12) %18)
  %19 = getelementptr inbounds %class.FluidSource, ptr %9, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %19, ptr align 4 %8, i64 12, i1 false), !tbaa.struct !11
  call void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12) %8) #6
  call void @llvm.lifetime.end.p0(i64 12, ptr %8) #6
  store i32 0, ptr %6, align 4
  br label %20

20:                                               ; preds = %14, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  %21 = load i32, ptr %6, align 4
  switch i32 %21, label %23 [
    i32 0, label %22
    i32 1, label %22
  ]

22:                                               ; preds = %20, %20
  ret void

23:                                               ; preds = %20
  unreachable
}

declare void @_ZN5vmathmlEfRKNS_4vec3E(ptr dead_on_unwind writable sret(%"class.vmath::vec3") align 4, float noundef, ptr noundef nonnull align 4 dereferenceable(12)) #5

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


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

; Function Attrs: nounwind
declare void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12)) 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: inlinehint mustprogress uwtable
declare dso_local void @_ZN5vmath9normalizeERKNS_4vec3E(ptr dead_on_unwind noalias writable sret(%"class.vmath::vec3") align 4, ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef float @_ZN5vmath6lengthERKNS_4vec3E(ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11FluidSource12setDirectionEN5vmath4vec3E(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull %1) local_unnamed_addr #4 align 2 {
  %3 = alloca %"class.vmath::vec3", align 4
  %4 = alloca %"class.vmath::vec3", align 4
  %5 = tail call noundef float @_ZN5vmath6lengthERKNS_4vec3E(ptr noundef nonnull align 4 dereferenceable(12) %1)
  %6 = fcmp ogt float %5, 0.000000e+00
  br i1 %6, label %7, label %11

7:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #6
  call void @_ZN5vmath9normalizeERKNS_4vec3E(ptr dead_on_unwind nonnull writable sret(%"class.vmath::vec3") align 4 %3, ptr noundef nonnull align 4 dereferenceable(12) %1)
  %8 = getelementptr inbounds i8, ptr %0, i64 20
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %8, ptr noundef nonnull align 4 dereferenceable(12) %3, i64 12, i1 false), !tbaa.struct !5
  call void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12) %3) #6
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #6
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = call noundef float @_ZN5vmath6lengthERKNS_4vec3E(ptr noundef nonnull align 4 dereferenceable(12) %9)
  call void @_ZN5vmathmlEfRKNS_4vec3E(ptr dead_on_unwind nonnull writable sret(%"class.vmath::vec3") align 4 %4, float noundef %10, ptr noundef nonnull align 4 dereferenceable(12) %8)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(12) %9, ptr noundef nonnull align 4 dereferenceable(12) %4, i64 12, i1 false), !tbaa.struct !5
  call void @_ZN5vmath4vec3D1Ev(ptr noundef nonnull align 4 dereferenceable(12) %4) #6
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #6
  br label %11

11:                                               ; preds = %2, %7
  ret void
}

declare void @_ZN5vmathmlEfRKNS_4vec3E(ptr dead_on_unwind writable sret(%"class.vmath::vec3") align 4, float noundef, ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #5

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 #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"}


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