; LLVM IR from garethcmurphy/Interstellar-Jet-MHD-Simulation :: src/locate.ll (Z6locatedPdPii)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6locatedPdPii(double noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store double %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i64 0, ptr %11, align 8, !tbaa !13
  %13 = load i32, ptr %8, align 4, !tbaa !11
  %14 = add nsw i32 %13, 1
  %15 = sext i32 %14 to i64
  store i64 %15, ptr %9, align 8, !tbaa !13
  %16 = load ptr, ptr %6, align 8, !tbaa !9
  %17 = load i32, ptr %8, align 4, !tbaa !11
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds double, ptr %16, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds double, ptr %21, i64 1
  %23 = load double, ptr %22, align 8, !tbaa !5
  %24 = fcmp ogt double %20, %23
  %25 = zext i1 %24 to i32
  store i32 %25, ptr %12, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %49, %4
  %27 = load i64, ptr %9, align 8, !tbaa !13
  %28 = load i64, ptr %11, align 8, !tbaa !13
  %29 = sub i64 %27, %28
  %30 = icmp ugt i64 %29, 1
  br i1 %30, label %31, label %50

31:                                               ; preds = %26
  %32 = load i64, ptr %9, align 8, !tbaa !13
  %33 = load i64, ptr %11, align 8, !tbaa !13
  %34 = add i64 %32, %33
  %35 = lshr i64 %34, 1
  store i64 %35, ptr %10, align 8, !tbaa !13
  %36 = load double, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  %38 = load i64, ptr %10, align 8, !tbaa !13
  %39 = getelementptr inbounds double, ptr %37, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !5
  %41 = fcmp ogt double %36, %40
  %42 = zext i1 %41 to i32
  %43 = load i32, ptr %12, align 4, !tbaa !11
  %44 = icmp eq i32 %42, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %31
  %46 = load i64, ptr %10, align 8, !tbaa !13
  store i64 %46, ptr %11, align 8, !tbaa !13
  br label %49

47:                                               ; preds = %31
  %48 = load i64, ptr %10, align 8, !tbaa !13
  store i64 %48, ptr %9, align 8, !tbaa !13
  br label %49

49:                                               ; preds = %47, %45
  br label %26, !llvm.loop !15

50:                                               ; preds = %26
  %51 = load i64, ptr %11, align 8, !tbaa !13
  %52 = trunc i64 %51 to i32
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %52, ptr %53, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  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 = { mustprogress 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z6locatedPdPii(double noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = add nsw i32 %3, 1
  %6 = icmp ugt i32 %5, 1
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %7 = sext i32 %5 to i64
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = sext i32 %3 to i64
  %11 = getelementptr inbounds double, ptr %1, i64 %10
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = fcmp ule double %12, %9
  br label %14

14:                                               ; preds = %.lr.ph, %14
  %.018 = phi i64 [ %7, %.lr.ph ], [ %.0., %14 ]
  %.01517 = phi i64 [ 0, %.lr.ph ], [ %..015, %14 ]
  %15 = add i64 %.018, %.01517
  %16 = lshr i64 %15, 1
  %17 = getelementptr inbounds double, ptr %1, i64 %16
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = fcmp olt double %18, %0
  %20 = xor i1 %13, %19
  %..015 = select i1 %20, i64 %16, i64 %.01517
  %.0. = select i1 %20, i64 %.018, i64 %16
  %21 = sub i64 %.0., %..015
  %22 = icmp ugt i64 %21, 1
  br i1 %22, label %14, label %._crit_edge.loopexit, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %14
  %23 = trunc i64 %..015 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %.015.lcssa = phi i32 [ 0, %4 ], [ %23, %._crit_edge.loopexit ]
  store i32 %.015.lcssa, ptr %2, align 4, !tbaa !11
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind 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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass