; LLVM IR from mnovak42/hepemshow :: Simulation/src/Geometry.ll (ZN8Geometry22CalculateDistanceToOutEPdS0_PP3BoxPiS4_)

; 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.Geometry = type { i32, double, double, double, double, double, double, double, ptr, ptr, ptr, ptr, ptr }

; 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: mustprogress uwtable
define dso_local noundef double @_ZN8Geometry22CalculateDistanceToOutEPdS0_PP3BoxPiS4_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #1 align 2 {
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  %21 = alloca double, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  %22 = load ptr, ptr %8, align 8
  %23 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 8
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %24, ptr %25, align 8, !tbaa !5
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 -1, ptr %26, align 4, !tbaa !13
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 -1, ptr %27, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %28, i64 0
  %30 = load double, ptr %29, align 8, !tbaa !14
  store double %30, ptr %14, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %31 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 9
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = call noundef double @_ZNK3Box13DistanceToOutEPdS0_(ptr noundef nonnull align 8 dereferenceable(80) %32, ptr noundef %33, ptr noundef %34)
  store double %35, ptr %15, align 8, !tbaa !14
  %36 = load double, ptr %15, align 8, !tbaa !14
  %37 = fcmp oeq double %36, 0.000000e+00
  br i1 %37, label %38, label %39

38:                                               ; preds = %6
  store double 1.000000e+20, ptr %7, align 8
  store i32 1, ptr %16, align 4
  br label %129

39:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %40 = load double, ptr %14, align 8, !tbaa !14
  %41 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 4
  %42 = load double, ptr %41, align 8, !tbaa !16
  %43 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %42, double %40)
  %44 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 3
  %45 = load double, ptr %44, align 8, !tbaa !17
  %46 = fdiv double %43, %45
  %47 = fptosi double %46 to i32
  store i32 %47, ptr %17, align 4, !tbaa !13
  %48 = load i32, ptr %17, align 4, !tbaa !13
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 %48, ptr %49, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %50 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 4
  %51 = load double, ptr %50, align 8, !tbaa !16
  %52 = load i32, ptr %17, align 4, !tbaa !13
  %53 = sitofp i32 %52 to double
  %54 = fadd double %53, 5.000000e-01
  %55 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 3
  %56 = load double, ptr %55, align 8, !tbaa !17
  %57 = fmul double %54, %56
  %58 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %51, double %57)
  store double %58, ptr %18, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %59 = load double, ptr %14, align 8, !tbaa !14
  %60 = load double, ptr %18, align 8, !tbaa !14
  %61 = fsub double %59, %60
  store double %61, ptr %19, align 8, !tbaa !14
  %62 = load double, ptr %19, align 8, !tbaa !14
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds double, ptr %63, i64 0
  store double %62, ptr %64, align 8, !tbaa !14
  %65 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 10
  %66 = load ptr, ptr %65, align 8, !tbaa !18
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = call noundef double @_ZNK3Box13DistanceToOutEPdS0_(ptr noundef nonnull align 8 dereferenceable(80) %66, ptr noundef %67, ptr noundef %68)
  %70 = fcmp oeq double %69, 0.000000e+00
  br i1 %70, label %71, label %72

71:                                               ; preds = %39
  store double 0.000000e+00, ptr %7, align 8
  store i32 1, ptr %16, align 4
  br label %128

72:                                               ; preds = %39
  %73 = load double, ptr %19, align 8, !tbaa !14
  %74 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 3
  %75 = load double, ptr %74, align 8, !tbaa !17
  %76 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %75, double %73)
  %77 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 1
  %78 = load double, ptr %77, align 8, !tbaa !19
  %79 = fcmp olt double %76, %78
  br i1 %79, label %84, label %80

80:                                               ; preds = %72
  %81 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 2
  %82 = load double, ptr %81, align 8, !tbaa !20
  %83 = fcmp oeq double %82, 0.000000e+00
  br i1 %83, label %84, label %105

84:                                               ; preds = %80, %72
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %85 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 3
  %86 = load double, ptr %85, align 8, !tbaa !17
  %87 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 1
  %88 = load double, ptr %87, align 8, !tbaa !19
  %89 = fsub double %86, %88
  %90 = fmul double -5.000000e-01, %89
  store double %90, ptr %20, align 8, !tbaa !14
  %91 = load double, ptr %19, align 8, !tbaa !14
  %92 = load double, ptr %20, align 8, !tbaa !14
  %93 = fsub double %91, %92
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  %95 = getelementptr inbounds double, ptr %94, i64 0
  store double %93, ptr %95, align 8, !tbaa !14
  %96 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 11
  %97 = load ptr, ptr %96, align 8, !tbaa !21
  %98 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %97, ptr %98, align 8, !tbaa !5
  %99 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 0, ptr %99, align 4, !tbaa !13
  %100 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 11
  %101 = load ptr, ptr %100, align 8, !tbaa !21
  %102 = load ptr, ptr %9, align 8, !tbaa !5
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  %104 = call noundef double @_ZNK3Box13DistanceToOutEPdS0_(ptr noundef nonnull align 8 dereferenceable(80) %101, ptr noundef %102, ptr noundef %103)
  store double %104, ptr %7, align 8
  store i32 1, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  br label %128

105:                                              ; preds = %80
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  %106 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 3
  %107 = load double, ptr %106, align 8, !tbaa !17
  %108 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 2
  %109 = load double, ptr %108, align 8, !tbaa !20
  %110 = fsub double %107, %109
  %111 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 1
  %112 = load double, ptr %111, align 8, !tbaa !19
  %113 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %110, double %112)
  store double %113, ptr %21, align 8, !tbaa !14
  %114 = load double, ptr %19, align 8, !tbaa !14
  %115 = load double, ptr %21, align 8, !tbaa !14
  %116 = fsub double %114, %115
  %117 = load ptr, ptr %9, align 8, !tbaa !5
  %118 = getelementptr inbounds double, ptr %117, i64 0
  store double %116, ptr %118, align 8, !tbaa !14
  %119 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 12
  %120 = load ptr, ptr %119, align 8, !tbaa !22
  %121 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %120, ptr %121, align 8, !tbaa !5
  %122 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 1, ptr %122, align 4, !tbaa !13
  %123 = getelementptr inbounds %class.Geometry, ptr %22, i32 0, i32 12
  %124 = load ptr, ptr %123, align 8, !tbaa !22
  %125 = load ptr, ptr %9, align 8, !tbaa !5
  %126 = load ptr, ptr %10, align 8, !tbaa !5
  %127 = call noundef double @_ZNK3Box13DistanceToOutEPdS0_(ptr noundef nonnull align 8 dereferenceable(80) %124, ptr noundef %125, ptr noundef %126)
  store double %127, ptr %7, align 8
  store i32 1, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  br label %128

128:                                              ; preds = %105, %84, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %129

129:                                              ; preds = %128, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %130 = load double, ptr %7, align 8
  ret double %130
}

declare noundef double @_ZNK3Box13DistanceToOutEPdS0_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 speculatable willreturn memory(none) }
attributes #4 = { 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, !6, i64 64}
!10 = !{!"_ZTS8Geometry", !11, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !6, i64 72}
!16 = !{!10, !12, i64 32}
!17 = !{!10, !12, i64 24}
!18 = !{!10, !6, i64 80}
!19 = !{!10, !12, i64 8}
!20 = !{!10, !12, i64 16}
!21 = !{!10, !6, i64 88}
!22 = !{!10, !6, i64 96}


; 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 uwtable
define dso_local noundef double @_ZN8Geometry22CalculateDistanceToOutEPdS0_PP3BoxPiS4_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(104) %0, ptr noundef %1, ptr noundef %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 align 2 {
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %8, ptr %3, align 8, !tbaa !12
  store i32 -1, ptr %4, align 4, !tbaa !13
  store i32 -1, ptr %5, align 4, !tbaa !13
  %9 = load double, ptr %1, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %0, i64 72
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = tail call noundef double @_ZNK3Box13DistanceToOutEPdS0_(ptr noundef nonnull align 8 dereferenceable(80) %11, ptr noundef nonnull %1, ptr noundef %2)
  %13 = fcmp oeq double %12, 0.000000e+00
  br i1 %13, label %52, label %14

14:                                               ; preds = %6
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  %16 = load double, ptr %15, align 8, !tbaa !16
  %17 = tail call double @llvm.fmuladd.f64(double %16, double 5.000000e-01, double %9)
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  %19 = load double, ptr %18, align 8, !tbaa !17
  %20 = fdiv double %17, %19
  %21 = fptosi double %20 to i32
  store i32 %21, ptr %4, align 4, !tbaa !13
  %22 = sitofp i32 %21 to double
  %23 = fadd double %22, 5.000000e-01
  %24 = fmul double %19, %23
  %25 = tail call double @llvm.fmuladd.f64(double %16, double -5.000000e-01, double %24)
  %26 = fsub double %9, %25
  store double %26, ptr %1, align 8, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %0, i64 80
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = tail call noundef double @_ZNK3Box13DistanceToOutEPdS0_(ptr noundef nonnull align 8 dereferenceable(80) %28, ptr noundef nonnull %1, ptr noundef %2)
  %30 = fcmp oeq double %29, 0.000000e+00
  br i1 %30, label %52, label %31

31:                                               ; preds = %14
  %32 = load double, ptr %18, align 8, !tbaa !17
  %33 = tail call double @llvm.fmuladd.f64(double %32, double 5.000000e-01, double %26)
  %34 = getelementptr inbounds i8, ptr %0, i64 8
  %35 = load double, ptr %34, align 8, !tbaa !19
  %36 = fcmp olt double %33, %35
  br i1 %36, label %41, label %37

37:                                               ; preds = %31
  %38 = getelementptr inbounds i8, ptr %0, i64 16
  %39 = load double, ptr %38, align 8, !tbaa !20
  %40 = fcmp oeq double %39, 0.000000e+00
  br i1 %40, label %41, label %45

41:                                               ; preds = %37, %31
  %42 = fsub double %32, %35
  %43 = fmul double %42, 5.000000e-01
  %44 = fadd double %26, %43
  br label %.sink.split

45:                                               ; preds = %37
  %46 = fsub double %32, %39
  %47 = tail call double @llvm.fmuladd.f64(double %46, double -5.000000e-01, double %35)
  %48 = fsub double %26, %47
  br label %.sink.split

.sink.split:                                      ; preds = %45, %41
  %.sink38 = phi double [ %44, %41 ], [ %48, %45 ]
  %.sink = phi i64 [ 88, %41 ], [ 96, %45 ]
  %.sink35 = phi i32 [ 0, %41 ], [ 1, %45 ]
  store double %.sink38, ptr %1, align 8, !tbaa !14
  %49 = getelementptr inbounds i8, ptr %0, i64 %.sink
  %50 = load ptr, ptr %49, align 8, !tbaa !12
  store ptr %50, ptr %3, align 8, !tbaa !12
  store i32 %.sink35, ptr %5, align 4, !tbaa !13
  %51 = tail call noundef double @_ZNK3Box13DistanceToOutEPdS0_(ptr noundef nonnull align 8 dereferenceable(80) %50, ptr noundef nonnull %1, ptr noundef %2)
  br label %52

52:                                               ; preds = %.sink.split, %14, %6
  %.1 = phi double [ 1.000000e+20, %6 ], [ 0.000000e+00, %14 ], [ %51, %.sink.split ]
  ret double %.1
}

declare noundef double @_ZNK3Box13DistanceToOutEPdS0_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

attributes #0 = { 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 #1 = { "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !11, i64 64}
!6 = !{!"_ZTS8Geometry", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!6, !11, i64 72}
!16 = !{!6, !10, i64 32}
!17 = !{!6, !10, i64 24}
!18 = !{!6, !11, i64 80}
!19 = !{!6, !10, i64 8}
!20 = !{!6, !10, i64 16}


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