; LLVM IR from PymZoR/S-curve-Planner :: examples/trapezoid (motionPlanning)

; 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: nounwind uwtable
define dso_local void @computePeriods(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [3 x double], align 16
  %7 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #6
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  store i32 2, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds double, ptr %8, i64 2
  %10 = load double, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 0
  store double %10, ptr %11, align 16, !tbaa !11
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds double, ptr %12, i64 1
  %14 = load double, ptr %13, align 8, !tbaa !11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds double, ptr %15, i64 2
  %17 = load double, ptr %16, align 8, !tbaa !11
  %18 = fmul double %14, %17
  %19 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 1
  store double %18, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds double, ptr %20, i64 0
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = fneg double %22
  %24 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 2
  store double %23, ptr %24, align 16, !tbaa !11
  %25 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 0
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = call double @findRoot(ptr noundef %25, i32 noundef %26)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %28, i64 2
  store double %27, ptr %29, align 8, !tbaa !11
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds double, ptr %30, i64 2
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds double, ptr %33, i64 2
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = fmul double %32, %35
  store double %36, ptr %7, align 8, !tbaa !11
  %37 = load double, ptr %7, align 8, !tbaa !11
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds double, ptr %38, i64 1
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = fcmp ogt double %37, %40
  br i1 %41, label %42, label %57

42:                                               ; preds = %2
  store i32 1, ptr %5, align 4, !tbaa !9
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds double, ptr %43, i64 2
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 0
  store double %45, ptr %46, align 16, !tbaa !11
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds double, ptr %47, i64 1
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fneg double %49
  %51 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 1
  store double %50, ptr %51, align 8, !tbaa !11
  %52 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 0
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = call double @findRoot(ptr noundef %52, i32 noundef %53)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds double, ptr %55, i64 2
  store double %54, ptr %56, align 8, !tbaa !11
  br label %61

57:                                               ; preds = %2
  %58 = load double, ptr %7, align 8, !tbaa !11
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds double, ptr %59, i64 1
  store double %58, ptr %60, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %57, %42
  store i32 1, ptr %5, align 4, !tbaa !9
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds double, ptr %62, i64 2
  %64 = load double, ptr %63, align 8, !tbaa !11
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds double, ptr %65, i64 2
  %67 = load double, ptr %66, align 8, !tbaa !11
  %68 = fmul double %64, %67
  %69 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 0
  store double %68, ptr %69, align 16, !tbaa !11
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds double, ptr %70, i64 2
  %72 = load double, ptr %71, align 8, !tbaa !11
  %73 = call double @pow(double noundef %72, double noundef 2.000000e+00) #6
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds double, ptr %74, i64 2
  %76 = load double, ptr %75, align 8, !tbaa !11
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds double, ptr %77, i64 0
  %79 = load double, ptr %78, align 8, !tbaa !11
  %80 = fneg double %79
  %81 = call double @llvm.fmuladd.f64(double %73, double %76, double %80)
  %82 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 1
  store double %81, ptr %82, align 8, !tbaa !11
  %83 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 0
  %84 = load i32, ptr %5, align 4, !tbaa !9
  %85 = call double @findRoot(ptr noundef %83, i32 noundef %84)
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds double, ptr %86, i64 1
  store double %85, ptr %87, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare double @findRoot(ptr noundef, i32 noundef) #3

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #4

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 "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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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: nounwind uwtable
define dso_local void @computePeriods(ptr nocapture noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = alloca [3 x double], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load double, ptr %4, align 8, !tbaa !5
  store double %5, ptr %3, align 16, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = fmul double %5, %7
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  store double %8, ptr %9, align 8, !tbaa !5
  %10 = load double, ptr %0, align 8, !tbaa !5
  %11 = fneg double %10
  %12 = getelementptr inbounds i8, ptr %3, i64 16
  store double %11, ptr %12, align 16, !tbaa !5
  %13 = call double @findRoot(ptr noundef nonnull %3, i32 noundef 2) #4
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  store double %13, ptr %14, align 8, !tbaa !5
  %15 = load double, ptr %4, align 8, !tbaa !5
  %16 = fmul double %13, %15
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = fcmp ogt double %16, %18
  br i1 %19, label %20, label %23

20:                                               ; preds = %2
  store double %15, ptr %3, align 16, !tbaa !5
  %21 = fneg double %18
  store double %21, ptr %9, align 8, !tbaa !5
  %22 = call double @findRoot(ptr noundef nonnull %3, i32 noundef 1) #4
  store double %22, ptr %14, align 8, !tbaa !5
  %.pre22 = load double, ptr %4, align 8, !tbaa !5
  br label %24

23:                                               ; preds = %2
  store double %16, ptr %17, align 8, !tbaa !5
  %.pre = load double, ptr %14, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %23, %20
  %25 = phi double [ %15, %23 ], [ %.pre22, %20 ]
  %26 = phi double [ %.pre, %23 ], [ %22, %20 ]
  %27 = fmul double %26, %25
  store double %27, ptr %3, align 16, !tbaa !5
  %square = fmul double %26, %26
  %28 = load double, ptr %0, align 8, !tbaa !5
  %29 = fneg double %28
  %30 = call double @llvm.fmuladd.f64(double %square, double %25, double %29)
  store double %30, ptr %9, align 8, !tbaa !5
  %31 = call double @findRoot(ptr noundef nonnull %3, i32 noundef 1) #4
  store double %31, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret void
}

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

declare double @findRoot(ptr noundef, i32 noundef) local_unnamed_addr #2

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

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

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 willreturn memory(argmem: readwrite) }
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 = { mustprogress 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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass