; LLVM IR from iostapyshyn/gravity :: physics (particle_getcoords)

; 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.particle = type { double, double, double, double, double, [3 x double] }

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local double @particle_getcoords(ptr noundef byval(%struct.particle) align 8 %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  store ptr %2, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store double 1.000000e+00, ptr %6, align 8, !tbaa !9
  %7 = getelementptr inbounds %struct.particle, ptr %0, i32 0, i32 0
  %8 = load double, ptr %7, align 8, !tbaa !11
  %9 = fcmp ogt double %8, 6.400000e+02
  br i1 %9, label %10, label %12

10:                                               ; preds = %3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store double 6.400000e+02, ptr %11, align 8, !tbaa !9
  store double 5.000000e-01, ptr %6, align 8, !tbaa !9
  br label %23

12:                                               ; preds = %3
  %13 = getelementptr inbounds %struct.particle, ptr %0, i32 0, i32 0
  %14 = load double, ptr %13, align 8, !tbaa !11
  %15 = fcmp olt double %14, 0.000000e+00
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  store double 0.000000e+00, ptr %17, align 8, !tbaa !9
  store double 5.000000e-01, ptr %6, align 8, !tbaa !9
  br label %22

18:                                               ; preds = %12
  %19 = getelementptr inbounds %struct.particle, ptr %0, i32 0, i32 0
  %20 = load double, ptr %19, align 8, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  store double %20, ptr %21, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %18, %16
  br label %23

23:                                               ; preds = %22, %10
  %24 = getelementptr inbounds %struct.particle, ptr %0, i32 0, i32 1
  %25 = load double, ptr %24, align 8, !tbaa !13
  %26 = fcmp ogt double %25, 4.800000e+02
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  store double 4.800000e+02, ptr %28, align 8, !tbaa !9
  store double 5.000000e-01, ptr %6, align 8, !tbaa !9
  br label %40

29:                                               ; preds = %23
  %30 = getelementptr inbounds %struct.particle, ptr %0, i32 0, i32 1
  %31 = load double, ptr %30, align 8, !tbaa !13
  %32 = fcmp olt double %31, 0.000000e+00
  br i1 %32, label %33, label %35

33:                                               ; preds = %29
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  store double 0.000000e+00, ptr %34, align 8, !tbaa !9
  store double 5.000000e-01, ptr %6, align 8, !tbaa !9
  br label %39

35:                                               ; preds = %29
  %36 = getelementptr inbounds %struct.particle, ptr %0, i32 0, i32 1
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  store double %37, ptr %38, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %35, %33
  br label %40

40:                                               ; preds = %39, %27
  %41 = load double, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  ret double %41
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind 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 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"particle", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40}
!13 = !{!12, !10, i64 8}


; 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.particle = type { double, double, double, double, double, [3 x double] }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local double @particle_getcoords(ptr nocapture noundef readonly byval(%struct.particle) align 8 %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load double, ptr %0, align 8, !tbaa !5
  %5 = fcmp ogt double %4, 6.400000e+02
  br i1 %5, label %8, label %6

6:                                                ; preds = %3
  %7 = fcmp olt double %4, 0.000000e+00
  %. = select i1 %7, double 0.000000e+00, double %4
  %.10 = select i1 %7, double 5.000000e-01, double 1.000000e+00
  br label %8

8:                                                ; preds = %6, %3
  %.sink = phi double [ 6.400000e+02, %3 ], [ %., %6 ]
  %.0 = phi double [ 5.000000e-01, %3 ], [ %.10, %6 ]
  store double %.sink, ptr %1, align 8, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load double, ptr %9, align 8, !tbaa !11
  %11 = fcmp ogt double %10, 4.800000e+02
  br i1 %11, label %14, label %12

12:                                               ; preds = %8
  %13 = fcmp olt double %10, 0.000000e+00
  %.11 = select i1 %13, double 0.000000e+00, double %10
  %..0 = select i1 %13, double 5.000000e-01, double %.0
  br label %14

14:                                               ; preds = %12, %8
  %.sink9 = phi double [ 4.800000e+02, %8 ], [ %.11, %12 ]
  %.1 = phi double [ 5.000000e-01, %8 ], [ %..0, %12 ]
  store double %.sink9, ptr %2, align 8, !tbaa !10
  ret double %.1
}

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

!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, !7, i64 0}
!6 = !{!"particle", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !8, i64 40}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 8}


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