; 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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @Math_interpolatePolygon2D(ptr noundef %0, ptr noundef %1, i32 noundef %2, double noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store double %3, ptr %8, align 8, !tbaa !11
  %19 = load double, ptr %8, align 8, !tbaa !11
  %20 = fcmp ole double %19, 0.000000e+00
  br i1 %20, label %24, label %21

21:                                               ; preds = %4
  %22 = load double, ptr %8, align 8, !tbaa !11
  %23 = fcmp oge double %22, 1.000000e+00
  br i1 %23, label %24, label %37

24:                                               ; preds = %21, %4
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds [2 x double], ptr %25, i64 0
  %27 = getelementptr inbounds [2 x double], ptr %26, i64 0, i64 0
  %28 = load double, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %29, i64 0
  store double %28, ptr %30, align 8, !tbaa !11
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds [2 x double], ptr %31, i64 0
  %33 = getelementptr inbounds [2 x double], ptr %32, i64 0, i64 1
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds double, ptr %35, i64 1
  store double %34, ptr %36, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %24, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = call double @Math_lengthPolygon2D(ptr noundef %38, i32 noundef %39)
  store double %40, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store double 0.000000e+00, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %139, %37
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = icmp ult i32 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  store i32 2, ptr %12, align 4
  br label %142

46:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = sub i32 %48, 1
  %50 = icmp eq i32 %47, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %46
  br label %55

52:                                               ; preds = %46
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = add i32 %53, 1
  br label %55

55:                                               ; preds = %52, %51
  %56 = phi i32 [ 0, %51 ], [ %54, %52 ]
  store i32 %56, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load i32, ptr %13, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds [2 x double], ptr %57, i64 %59
  %61 = getelementptr inbounds [2 x double], ptr %60, i64 0, i64 0
  %62 = load double, ptr %61, align 8, !tbaa !11
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds [2 x double], ptr %63, i64 %65
  %67 = getelementptr inbounds [2 x double], ptr %66, i64 0, i64 0
  %68 = load double, ptr %67, align 8, !tbaa !11
  %69 = fsub double %62, %68
  store double %69, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load i32, ptr %13, align 4, !tbaa !9
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds [2 x double], ptr %70, i64 %72
  %74 = getelementptr inbounds [2 x double], ptr %73, i64 0, i64 1
  %75 = load double, ptr %74, align 8, !tbaa !11
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds [2 x double], ptr %76, i64 %78
  %80 = getelementptr inbounds [2 x double], ptr %79, i64 0, i64 1
  %81 = load double, ptr %80, align 8, !tbaa !11
  %82 = fsub double %75, %81
  store double %82, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %83 = load double, ptr %10, align 8, !tbaa !11
  %84 = load double, ptr %9, align 8, !tbaa !11
  %85 = fdiv double %83, %84
  store double %85, ptr %16, align 8, !tbaa !11
  %86 = load double, ptr %14, align 8, !tbaa !11
  %87 = load double, ptr %14, align 8, !tbaa !11
  %88 = load double, ptr %15, align 8, !tbaa !11
  %89 = load double, ptr %15, align 8, !tbaa !11
  %90 = fmul double %88, %89
  %91 = call double @llvm.fmuladd.f64(double %86, double %87, double %90)
  %92 = call double @sqrt(double noundef %91) #4
  %93 = load double, ptr %10, align 8, !tbaa !11
  %94 = fadd double %93, %92
  store double %94, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %95 = load double, ptr %10, align 8, !tbaa !11
  %96 = load double, ptr %9, align 8, !tbaa !11
  %97 = fdiv double %95, %96
  store double %97, ptr %17, align 8, !tbaa !11
  %98 = load double, ptr %8, align 8, !tbaa !11
  %99 = load double, ptr %16, align 8, !tbaa !11
  %100 = fcmp ogt double %98, %99
  br i1 %100, label %101, label %135

101:                                              ; preds = %55
  %102 = load double, ptr %8, align 8, !tbaa !11
  %103 = load double, ptr %17, align 8, !tbaa !11
  %104 = fcmp ole double %102, %103
  br i1 %104, label %105, label %135

105:                                              ; preds = %101
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %106 = load double, ptr %8, align 8, !tbaa !11
  %107 = load double, ptr %16, align 8, !tbaa !11
  %108 = fsub double %106, %107
  %109 = load double, ptr %17, align 8, !tbaa !11
  %110 = load double, ptr %16, align 8, !tbaa !11
  %111 = fsub double %109, %110
  %112 = fdiv double %108, %111
  store double %112, ptr %18, align 8, !tbaa !11
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = load i32, ptr %11, align 4, !tbaa !9
  %115 = zext i32 %114 to i64
  %116 = getelementptr inbounds [2 x double], ptr %113, i64 %115
  %117 = getelementptr inbounds [2 x double], ptr %116, i64 0, i64 0
  %118 = load double, ptr %117, align 8, !tbaa !11
  %119 = load double, ptr %18, align 8, !tbaa !11
  %120 = load double, ptr %14, align 8, !tbaa !11
  %121 = call double @llvm.fmuladd.f64(double %119, double %120, double %118)
  %122 = load ptr, ptr %5, align 8, !tbaa !5
  %123 = getelementptr inbounds double, ptr %122, i64 0
  store double %121, ptr %123, align 8, !tbaa !11
  %124 = load ptr, ptr %6, align 8, !tbaa !5
  %125 = load i32, ptr %11, align 4, !tbaa !9
  %126 = zext i32 %125 to i64
  %127 = getelementptr inbounds [2 x double], ptr %124, i64 %126
  %128 = getelementptr inbounds [2 x double], ptr %127, i64 0, i64 1
  %129 = load double, ptr %128, align 8, !tbaa !11
  %130 = load double, ptr %18, align 8, !tbaa !11
  %131 = load double, ptr %15, align 8, !tbaa !11
  %132 = call double @llvm.fmuladd.f64(double %130, double %131, double %129)
  %133 = load ptr, ptr %5, align 8, !tbaa !5
  %134 = getelementptr inbounds double, ptr %133, i64 1
  store double %132, ptr %134, align 8, !tbaa !11
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %136

135:                                              ; preds = %101, %55
  store i32 0, ptr %12, align 4
  br label %136

136:                                              ; preds = %135, %105
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  %137 = load i32, ptr %12, align 4
  switch i32 %137, label %142 [
    i32 0, label %138
  ]

138:                                              ; preds = %136
  br label %139

139:                                              ; preds = %138
  %140 = load i32, ptr %11, align 4, !tbaa !9
  %141 = add i32 %140, 1
  store i32 %141, ptr %11, align 4, !tbaa !9
  br label %41, !llvm.loop !13

142:                                              ; preds = %136, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %143 = load i32, ptr %12, align 4
  switch i32 %143, label %157 [
    i32 2, label %144
  ]

144:                                              ; preds = %142
  %145 = load ptr, ptr %6, align 8, !tbaa !5
  %146 = getelementptr inbounds [2 x double], ptr %145, i64 0
  %147 = getelementptr inbounds [2 x double], ptr %146, i64 0, i64 0
  %148 = load double, ptr %147, align 8, !tbaa !11
  %149 = load ptr, ptr %5, align 8, !tbaa !5
  %150 = getelementptr inbounds double, ptr %149, i64 0
  store double %148, ptr %150, align 8, !tbaa !11
  %151 = load ptr, ptr %6, align 8, !tbaa !5
  %152 = getelementptr inbounds [2 x double], ptr %151, i64 0
  %153 = getelementptr inbounds [2 x double], ptr %152, i64 0, i64 1
  %154 = load double, ptr %153, align 8, !tbaa !11
  %155 = load ptr, ptr %5, align 8, !tbaa !5
  %156 = getelementptr inbounds double, ptr %155, i64 1
  store double %154, ptr %156, align 8, !tbaa !11
  store i32 0, ptr %12, align 4
  br label %157

157:                                              ; preds = %144, %142
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %158 = load i32, ptr %12, align 4
  switch i32 %158, label %160 [
    i32 0, label %159
    i32 1, label %159
  ]

159:                                              ; preds = %157, %157
  ret void

160:                                              ; preds = %157
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = !{!"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: nounwind uwtable
declare dso_local double @Math_lengthPolygon2D(ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @Math_interpolatePolygon2D(ptr nocapture noundef writeonly %0, ptr noundef %1, i32 noundef %2, double noundef %3) local_unnamed_addr #0 {
  %5 = fcmp ole double %3, 0.000000e+00
  %6 = fcmp oge double %3, 1.000000e+00
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %7, label %12

7:                                                ; preds = %4
  %8 = load double, ptr %1, align 8, !tbaa !5
  store double %8, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  store double %10, ptr %11, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %4, %7
  %13 = tail call double @Math_lengthPolygon2D(ptr noundef %1, i32 noundef %2)
  %14 = add i32 %2, -1
  %15 = zext i32 %14 to i64
  %wide.trip.count = zext i32 %2 to i64
  br label %16

16:                                               ; preds = %17, %12
  %indvars.iv = phi i64 [ %indvars.iv.next, %17 ], [ 0, %12 ]
  %.0 = phi double [ %34, %17 ], [ 0.000000e+00, %12 ]
  %exitcond.not = icmp eq i64 %indvars.iv, %wide.trip.count
  br i1 %exitcond.not, label %.critedge64, label %17

17:                                               ; preds = %16
  %18 = icmp eq i64 %indvars.iv, %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = and i64 %indvars.iv.next, 4294967295
  %20 = select i1 %18, i64 0, i64 %19
  %21 = getelementptr inbounds [2 x double], ptr %1, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds [2 x double], ptr %1, i64 %indvars.iv
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = fsub double %22, %24
  %26 = getelementptr inbounds i8, ptr %21, i64 8
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %23, i64 8
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = fsub double %27, %29
  %31 = fdiv double %.0, %13
  %32 = fmul double %30, %30
  %33 = tail call double @llvm.fmuladd.f64(double %25, double %25, double %32)
  %sqrt = tail call double @llvm.sqrt.f64(double %33)
  %34 = fadd double %.0, %sqrt
  %35 = fdiv double %34, %13
  %36 = fcmp uge double %31, %3
  %37 = fcmp ult double %35, %3
  %or.cond62 = select i1 %36, i1 true, i1 %37
  br i1 %or.cond62, label %16, label %.critedge, !llvm.loop !9

.critedge:                                        ; preds = %17
  %38 = getelementptr inbounds i8, ptr %23, i64 8
  %39 = fsub double %3, %31
  %40 = fsub double %35, %31
  %41 = fdiv double %39, %40
  %42 = tail call double @llvm.fmuladd.f64(double %41, double %25, double %24)
  store double %42, ptr %0, align 8, !tbaa !5
  %43 = load double, ptr %38, align 8, !tbaa !5
  %44 = tail call double @llvm.fmuladd.f64(double %41, double %30, double %43)
  br label %48

.critedge64:                                      ; preds = %16
  %45 = load double, ptr %1, align 8, !tbaa !5
  store double %45, ptr %0, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %1, i64 8
  %47 = load double, ptr %46, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %.critedge, %.critedge64
  %.sink = phi double [ %44, %.critedge ], [ %47, %.critedge64 ]
  %49 = getelementptr inbounds i8, ptr %0, i64 8
  store double %.sink, ptr %49, align 8, !tbaa !5
  ret void
}

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

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass