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

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

@count = external dso_local global i32, align 4
@array = external dso_local global <{ %struct.particle, %struct.particle, %struct.particle, [117 x %struct.particle] }>, align 16

; Function Attrs: nounwind uwtable
define dso_local void @update() #0 {
  %1 = alloca i32, align 4
  store i32 120, ptr @count, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %2

2:                                                ; preds = %17, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 120
  br i1 %4, label %6, label %5

5:                                                ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %20

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [120 x %struct.particle], ptr @array, i64 0, i64 %8
  %10 = getelementptr inbounds %struct.particle, ptr %9, i32 0, i32 4
  %11 = load double, ptr %10, align 16, !tbaa !9
  %12 = fcmp une double %11, 0.000000e+00
  br i1 %12, label %16, label %13

13:                                               ; preds = %6
  %14 = load i32, ptr @count, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr @count, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %13, %6
  br label %17

17:                                               ; preds = %16
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %1, align 4, !tbaa !5
  br label %2, !llvm.loop !12

20:                                               ; preds = %5
  ret void
}

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 32}
!10 = !{!"particle", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !7, i64 40}
!11 = !{!"double", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

@count = external dso_local local_unnamed_addr global i32, align 4
@array = external dso_local local_unnamed_addr global <{ %struct.particle, %struct.particle, %struct.particle, [117 x %struct.particle] }>, align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @update() local_unnamed_addr #0 {
  store i32 120, ptr @count, align 4, !tbaa !5
  br label %2

1:                                                ; preds = %23
  ret void

2:                                                ; preds = %23, %0
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next.2, %23 ]
  %3 = phi i32 [ 120, %0 ], [ %24, %23 ]
  %4 = getelementptr inbounds [120 x %struct.particle], ptr @array, i64 0, i64 %indvars.iv, i32 4
  %5 = load double, ptr %4, align 16, !tbaa !9
  %6 = fcmp une double %5, 0.000000e+00
  br i1 %6, label %9, label %7

7:                                                ; preds = %2
  %8 = add nsw i32 %3, -1
  store i32 %8, ptr @count, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %2, %7
  %10 = phi i32 [ %3, %2 ], [ %8, %7 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = getelementptr inbounds [120 x %struct.particle], ptr @array, i64 0, i64 %indvars.iv.next, i32 4
  %12 = load double, ptr %11, align 16, !tbaa !9
  %13 = fcmp une double %12, 0.000000e+00
  br i1 %13, label %16, label %14

14:                                               ; preds = %9
  %15 = add nsw i32 %10, -1
  store i32 %15, ptr @count, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %14, %9
  %17 = phi i32 [ %10, %9 ], [ %15, %14 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %18 = getelementptr inbounds [120 x %struct.particle], ptr @array, i64 0, i64 %indvars.iv.next.1, i32 4
  %19 = load double, ptr %18, align 16, !tbaa !9
  %20 = fcmp une double %19, 0.000000e+00
  br i1 %20, label %23, label %21

21:                                               ; preds = %16
  %22 = add nsw i32 %17, -1
  store i32 %22, ptr @count, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %21, %16
  %24 = phi i32 [ %17, %16 ], [ %22, %21 ]
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %exitcond.not.2 = icmp eq i64 %indvars.iv.next.2, 120
  br i1 %exitcond.not.2, label %1, label %2, !llvm.loop !12
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 32}
!10 = !{!"particle", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !7, i64 40}
!11 = !{!"double", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass