; LLVM IR from HRI-EU/Rcs :: src/RcsCore (Rcs_geometry)

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

declare double @VecNd_normalizeSelf(ptr noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @Math_intersectRayLineseg2D(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca [2 x double], align 16
  %12 = alloca [2 x double], align 16
  %13 = alloca i32, align 4
  %14 = alloca double, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %53, %5
  %20 = load i32, ptr %13, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 2
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %56

23:                                               ; preds = %19
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load i32, ptr %13, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds double, ptr %24, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load i32, ptr %13, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %29, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !11
  %34 = fadd double %28, %33
  %35 = fmul double 5.000000e-01, %34
  %36 = load i32, ptr %13, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [2 x double], ptr %11, i64 0, i64 %37
  store double %35, ptr %38, align 8, !tbaa !11
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load i32, ptr %13, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %39, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !11
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = load i32, ptr %13, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %44, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !11
  %49 = fsub double %43, %48
  %50 = load i32, ptr %13, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [2 x double], ptr %12, i64 0, i64 %51
  store double %49, ptr %52, align 8, !tbaa !11
  br label %53

53:                                               ; preds = %23
  %54 = load i32, ptr %13, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %13, align 4, !tbaa !9
  br label %19, !llvm.loop !13

56:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %57 = getelementptr inbounds [2 x double], ptr %12, i64 0, i64 0
  %58 = call double @VecNd_normalizeSelf(ptr noundef %57, i32 noundef 2)
  store double %58, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds [2 x double], ptr %11, i64 0, i64 0
  %62 = getelementptr inbounds [2 x double], ptr %12, i64 0, i64 0
  %63 = load double, ptr %14, align 8, !tbaa !11
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = call i32 @IntrRay2Segment2_Find(ptr noundef %59, ptr noundef %60, ptr noundef %61, ptr noundef %62, double noundef %63, ptr noundef %64)
  store i32 %65, ptr %15, align 4, !tbaa !9
  %66 = load i32, ptr %15, align 4, !tbaa !9
  %67 = icmp eq i32 %66, 4
  br i1 %67, label %68, label %121

68:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds double, ptr %69, i64 0
  %71 = load double, ptr %70, align 8, !tbaa !11
  %72 = call double @llvm.fabs.f64(double %71)
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds double, ptr %73, i64 1
  %75 = load double, ptr %74, align 8, !tbaa !11
  %76 = call double @llvm.fabs.f64(double %75)
  %77 = fcmp ogt double %72, %76
  %78 = zext i1 %77 to i64
  %79 = select i1 %77, i32 0, i32 1
  store i32 %79, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load i32, ptr %16, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds double, ptr %80, i64 %82
  %84 = load double, ptr %83, align 8, !tbaa !11
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = load i32, ptr %16, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds double, ptr %85, i64 %87
  %89 = load double, ptr %88, align 8, !tbaa !11
  %90 = fsub double %84, %89
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = load i32, ptr %16, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds double, ptr %91, i64 %93
  %95 = load double, ptr %94, align 8, !tbaa !11
  %96 = fdiv double %90, %95
  store double %96, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %97 = load ptr, ptr %9, align 8, !tbaa !5
  %98 = load i32, ptr %16, align 4, !tbaa !9
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds double, ptr %97, i64 %99
  %101 = load double, ptr %100, align 8, !tbaa !11
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = load i32, ptr %16, align 4, !tbaa !9
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds double, ptr %102, i64 %104
  %106 = load double, ptr %105, align 8, !tbaa !11
  %107 = fsub double %101, %106
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  %109 = load i32, ptr %16, align 4, !tbaa !9
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds double, ptr %108, i64 %110
  %112 = load double, ptr %111, align 8, !tbaa !11
  %113 = fdiv double %107, %112
  store double %113, ptr %18, align 8, !tbaa !11
  %114 = load double, ptr %17, align 8, !tbaa !11
  %115 = fcmp olt double %114, 0.000000e+00
  br i1 %115, label %116, label %120

116:                                              ; preds = %68
  %117 = load double, ptr %18, align 8, !tbaa !11
  %118 = fcmp olt double %117, 0.000000e+00
  br i1 %118, label %119, label %120

119:                                              ; preds = %116
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %120

120:                                              ; preds = %119, %116, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %121

121:                                              ; preds = %120, %56
  %122 = load i32, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #4
  ret i32 %122
}

; Function Attrs: nounwind uwtable
declare hidden i32 @IntrRay2Segment2_Find(ptr noundef, ptr noundef, ptr noundef, ptr noundef, double noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

declare double @VecNd_normalizeSelf(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @Math_intersectRayLineseg2D(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = alloca [2 x double], align 16
  %7 = alloca [2 x double], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  %8 = load <2 x double>, ptr %2, align 8, !tbaa !5
  %9 = load <2 x double>, ptr %3, align 8, !tbaa !5
  %10 = fadd <2 x double> %8, %9
  %11 = fmul <2 x double> %10, <double 5.000000e-01, double 5.000000e-01>
  store <2 x double> %11, ptr %6, align 16, !tbaa !5
  %12 = fsub <2 x double> %9, %8
  store <2 x double> %12, ptr %7, align 16, !tbaa !5
  %13 = call double @VecNd_normalizeSelf(ptr noundef nonnull %7, i32 noundef 2) #4
  %14 = call i32 @IntrRay2Segment2_Find(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %6, ptr noundef nonnull %7, double noundef %13, ptr noundef %4)
  %15 = icmp eq i32 %14, 4
  br i1 %15, label %16, label %42

16:                                               ; preds = %5
  %17 = load <2 x double>, ptr %1, align 8, !tbaa !5
  %18 = call <2 x double> @llvm.fabs.v2f64(<2 x double> %17)
  %19 = extractelement <2 x double> %18, i64 0
  %20 = extractelement <2 x double> %18, i64 1
  %21 = fcmp ule double %19, %20
  %22 = zext i1 %21 to i64
  %23 = getelementptr inbounds double, ptr %2, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %0, i64 %22
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds double, ptr %1, i64 %22
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %3, i64 %22
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = insertelement <2 x double> poison, double %30, i64 0
  %32 = insertelement <2 x double> %31, double %24, i64 1
  %33 = insertelement <2 x double> poison, double %26, i64 0
  %34 = shufflevector <2 x double> %33, <2 x double> poison, <2 x i32> zeroinitializer
  %35 = fsub <2 x double> %32, %34
  %36 = insertelement <2 x double> poison, double %28, i64 0
  %37 = shufflevector <2 x double> %36, <2 x double> poison, <2 x i32> zeroinitializer
  %38 = fdiv <2 x double> %35, %37
  %39 = fcmp olt <2 x double> %38, zeroinitializer
  %40 = extractelement <2 x i1> %39, i64 0
  %41 = extractelement <2 x i1> %39, i64 1
  %or.cond = select i1 %41, i1 %40, i1 false
  %spec.select = select i1 %or.cond, i32 0, i32 4
  br label %42

42:                                               ; preds = %16, %5
  %.1 = phi i32 [ %spec.select, %16 ], [ %14, %5 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @IntrRay2Segment2_Find(ptr noundef, ptr noundef, ptr noundef, ptr noundef, double noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fabs.v2f64(<2 x double>) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass