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

%struct.HTr = type { [3 x double], [3 x [3 x double]] }

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

declare void @Vec3d_sub(ptr noundef, ptr noundef, ptr noundef) #1

declare double @Vec3d_sqrDistance(ptr noundef, ptr noundef) #1

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

declare double @Vec3d_normalizeSelf(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local double @Math_distPointConvexPolygon2D(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local double @Math_sqrDistPointConvexPolygon(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca double, align 8
  %14 = alloca [3 x double], align 16
  %15 = alloca [3 x double], align 16
  %16 = alloca double, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %14) #3
  %17 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 0
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  call void @Vec3d_invTransform(ptr noundef %17, ptr noundef %18, ptr noundef %19)
  call void @llvm.lifetime.start.p0(i64 24, ptr %15) #3
  %20 = getelementptr inbounds [3 x double], ptr %15, i64 0, i64 2
  store double 0.000000e+00, ptr %20, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %21 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 0
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = getelementptr inbounds [3 x double], ptr %15, i64 0, i64 0
  %25 = call double @Math_distPointConvexPolygon2D(ptr noundef %21, ptr noundef %22, i32 noundef %23, ptr noundef %24, ptr noundef null)
  store double %25, ptr %16, align 8, !tbaa !11
  %26 = load double, ptr %16, align 8, !tbaa !11
  %27 = fcmp oge double %26, 0.000000e+00
  br i1 %27, label %28, label %40

28:                                               ; preds = %6
  %29 = getelementptr inbounds [3 x double], ptr %15, i64 0, i64 0
  %30 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 0
  %31 = call double @Vec3d_sqrDistance(ptr noundef %29, ptr noundef %30)
  store double %31, ptr %13, align 8, !tbaa !11
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds [3 x double], ptr %15, i64 0, i64 0
  call void @Vec3d_transform(ptr noundef %32, ptr noundef %33, ptr noundef %34)
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  call void @Vec3d_sub(ptr noundef %35, ptr noundef %36, ptr noundef %37)
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = call double @Vec3d_normalizeSelf(ptr noundef %38)
  br label %63

40:                                               ; preds = %6
  %41 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 2
  %42 = load double, ptr %41, align 16, !tbaa !11
  %43 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 2
  %44 = load double, ptr %43, align 16, !tbaa !11
  %45 = fmul double %42, %44
  store double %45, ptr %13, align 8, !tbaa !11
  %46 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 0
  %47 = load double, ptr %46, align 16, !tbaa !11
  %48 = getelementptr inbounds [3 x double], ptr %15, i64 0, i64 0
  store double %47, ptr %48, align 16, !tbaa !11
  %49 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 1
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds [3 x double], ptr %15, i64 0, i64 1
  store double %50, ptr %51, align 8, !tbaa !11
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds [3 x double], ptr %15, i64 0, i64 0
  call void @Vec3d_transform(ptr noundef %52, ptr noundef %53, ptr noundef %54)
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.HTr, ptr %56, i32 0, i32 1
  %58 = getelementptr inbounds [3 x [3 x double]], ptr %57, i64 0, i64 2
  %59 = getelementptr inbounds [3 x double], ptr %58, i64 0, i64 0
  %60 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 2
  %61 = load double, ptr %60, align 16, !tbaa !11
  %62 = call double @Math_dsign(double noundef %61)
  call void @Vec3d_constMul(ptr noundef %55, ptr noundef %59, double noundef %62)
  br label %63

63:                                               ; preds = %40, %28
  %64 = load double, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  ret double %64
}

declare void @Vec3d_invTransform(ptr noundef, ptr noundef, ptr noundef) #1

declare void @Vec3d_transform(ptr noundef, ptr noundef, ptr noundef) #1

declare void @Vec3d_constMul(ptr noundef, ptr noundef, double noundef) #1

declare double @Math_dsign(double noundef) #1

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 = { 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 = { 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}


; 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

declare void @Vec3d_sub(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare double @Vec3d_sqrDistance(ptr noundef, ptr noundef) local_unnamed_addr #1

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

declare double @Vec3d_normalizeSelf(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local double @Math_sqrDistPointConvexPolygon(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #2 {
  %7 = alloca [3 x double], align 16
  %8 = alloca [3 x double], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #3
  call void @Vec3d_invTransform(ptr noundef nonnull %7, ptr noundef %1, ptr noundef %0) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %8) #3
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  store double 0.000000e+00, ptr %9, align 16, !tbaa !5
  %10 = call double @Math_distPointConvexPolygon2D(ptr noundef nonnull %7, ptr noundef %2, i32 noundef %3, ptr noundef nonnull %8, ptr noundef null)
  %11 = fcmp ult double %10, 0.000000e+00
  br i1 %11, label %15, label %12

12:                                               ; preds = %6
  %13 = call double @Vec3d_sqrDistance(ptr noundef nonnull %8, ptr noundef nonnull %7) #3
  call void @Vec3d_transform(ptr noundef %4, ptr noundef %1, ptr noundef nonnull %8) #3
  call void @Vec3d_sub(ptr noundef %5, ptr noundef %0, ptr noundef %4) #3
  %14 = call double @Vec3d_normalizeSelf(ptr noundef %5) #3
  br label %23

15:                                               ; preds = %6
  %16 = getelementptr inbounds i8, ptr %7, i64 16
  %17 = load double, ptr %16, align 16, !tbaa !5
  %18 = fmul double %17, %17
  %19 = load <2 x double>, ptr %7, align 16, !tbaa !5
  store <2 x double> %19, ptr %8, align 16, !tbaa !5
  call void @Vec3d_transform(ptr noundef %4, ptr noundef %1, ptr noundef nonnull %8) #3
  %20 = getelementptr inbounds i8, ptr %1, i64 72
  %21 = load double, ptr %16, align 16, !tbaa !5
  %22 = call double @Math_dsign(double noundef %21) #3
  call void @Vec3d_constMul(ptr noundef %5, ptr noundef nonnull %20, double noundef %22) #3
  br label %23

23:                                               ; preds = %15, %12
  %.0 = phi double [ %13, %12 ], [ %18, %15 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #3
  ret double %.0
}

declare void @Vec3d_invTransform(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @Vec3d_transform(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @Vec3d_constMul(ptr noundef, ptr noundef, double noundef) local_unnamed_addr #1

declare double @Math_dsign(double noundef) local_unnamed_addr #1

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 = { 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,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass